android: Rebuild PiP parameters on change
This commit is contained in:
parent
b03052843b
commit
74cabd0ff0
4 changed files with 32 additions and 16 deletions
|
@ -100,6 +100,8 @@ class EmulationActivity : AppCompatActivity(), SensorEventListener {
|
|||
// Set these options now so that the SurfaceView the game renders into is the right size.
|
||||
enableFullscreenImmersive()
|
||||
|
||||
pictureInPictureParamsBuilder = getPictureInPictureActionsBuilder()
|
||||
|
||||
setContentView(R.layout.activity_emulation)
|
||||
window.decorView.setBackgroundColor(getColor(android.R.color.black))
|
||||
|
||||
|
@ -166,8 +168,8 @@ class EmulationActivity : AppCompatActivity(), SensorEventListener {
|
|||
getAdjustedRotation()
|
||||
)
|
||||
|
||||
if (BooleanSetting.PICTURE_IN_PICTURE.boolean) {
|
||||
pictureInPictureParamsBuilder = getPictureInPictureBuilder()
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
|
||||
pictureInPictureParamsBuilder.setAutoEnterEnabled(BooleanSetting.PICTURE_IN_PICTURE.boolean)
|
||||
setPictureInPictureParams(pictureInPictureParamsBuilder.build())
|
||||
}
|
||||
}
|
||||
|
@ -314,30 +316,23 @@ class EmulationActivity : AppCompatActivity(), SensorEventListener {
|
|||
}
|
||||
}
|
||||
|
||||
private fun getPictureInPictureBuilder() : PictureInPictureParams.Builder {
|
||||
val pictureInPictureParamsBuilder = PictureInPictureParams.Builder()
|
||||
|
||||
private fun getPictureInPictureActionsBuilder() : PictureInPictureParams.Builder {
|
||||
val pictureInPictureActions : MutableList<RemoteAction> = mutableListOf()
|
||||
val pendingFlags = PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_IMMUTABLE
|
||||
|
||||
val pauseIcon = Icon.createWithResource(this, R.drawable.ic_pause)
|
||||
val pausePendingIntent = PendingIntent.getBroadcast(this, R.drawable.ic_pause, Intent(actionPause), pendingFlags)
|
||||
val pauseIcon = Icon.createWithResource(this, R.drawable.ic_pip_pause)
|
||||
val pausePendingIntent = PendingIntent.getBroadcast(this, R.drawable.ic_pip_pause, Intent(actionPause), pendingFlags)
|
||||
val pauseRemoteAction = RemoteAction(pauseIcon, getString(R.string.pause), getString(R.string.pause), pausePendingIntent)
|
||||
pictureInPictureActions.add(pauseRemoteAction)
|
||||
|
||||
val playIcon = Icon.createWithResource(this, R.drawable.ic_play)
|
||||
val playPendingIntent = PendingIntent.getBroadcast(this, R.drawable.ic_play, Intent(actionPlay), pendingFlags)
|
||||
val playIcon = Icon.createWithResource(this, R.drawable.ic_pip_play)
|
||||
val playPendingIntent = PendingIntent.getBroadcast(this, R.drawable.ic_pip_play, Intent(actionPlay), pendingFlags)
|
||||
val playRemoteAction = RemoteAction(playIcon, getString(R.string.play), getString(R.string.play), playPendingIntent)
|
||||
pictureInPictureActions.add(playRemoteAction)
|
||||
|
||||
pictureInPictureParamsBuilder.setActions(pictureInPictureActions)
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
|
||||
pictureInPictureParamsBuilder.setAutoEnterEnabled(true)
|
||||
return PictureInPictureParams.Builder().apply {
|
||||
setActions(pictureInPictureActions)
|
||||
}
|
||||
|
||||
setPictureInPictureParams(pictureInPictureParamsBuilder.build())
|
||||
|
||||
return pictureInPictureParamsBuilder
|
||||
}
|
||||
|
||||
private var pictureInPictureReceiver = object : BroadcastReceiver() {
|
||||
|
|
|
@ -180,6 +180,9 @@ class EmulationFragment : Fragment(), SurfaceHolder.Callback {
|
|||
}
|
||||
|
||||
fun onPictureInPictureEnter() {
|
||||
if (binding.drawerLayout.isOpen) {
|
||||
binding.drawerLayout.close()
|
||||
}
|
||||
if (EmulationMenuSettings.showOverlay) {
|
||||
binding.surfaceInputOverlay.post { binding.surfaceInputOverlay.isVisible = false }
|
||||
}
|
||||
|
|
9
src/android/app/src/main/res/drawable/ic_pip_pause.xml
Normal file
9
src/android/app/src/main/res/drawable/ic_pip_pause.xml
Normal file
|
@ -0,0 +1,9 @@
|
|||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportHeight="24"
|
||||
android:viewportWidth="24">
|
||||
<path
|
||||
android:fillColor="@android:color/white"
|
||||
android:pathData="M6,19h4L10,5L6,5v14zM14,5v14h4L18,5h-4z" />
|
||||
</vector>
|
9
src/android/app/src/main/res/drawable/ic_pip_play.xml
Normal file
9
src/android/app/src/main/res/drawable/ic_pip_play.xml
Normal file
|
@ -0,0 +1,9 @@
|
|||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportHeight="24"
|
||||
android:viewportWidth="24">
|
||||
<path
|
||||
android:fillColor="@android:color/white"
|
||||
android:pathData="M8,5v14l11,-7z" />
|
||||
</vector>
|
Loading…
Add table
Reference in a new issue