android: Rebuild PiP parameters on change

This commit is contained in:
Abandoned Cart 2023-06-02 20:07:27 -04:00
commit 74cabd0ff0
4 changed files with 32 additions and 16 deletions

View file

@ -100,6 +100,8 @@ class EmulationActivity : AppCompatActivity(), SensorEventListener {
// Set these options now so that the SurfaceView the game renders into is the right size. // Set these options now so that the SurfaceView the game renders into is the right size.
enableFullscreenImmersive() enableFullscreenImmersive()
pictureInPictureParamsBuilder = getPictureInPictureActionsBuilder()
setContentView(R.layout.activity_emulation) setContentView(R.layout.activity_emulation)
window.decorView.setBackgroundColor(getColor(android.R.color.black)) window.decorView.setBackgroundColor(getColor(android.R.color.black))
@ -166,8 +168,8 @@ class EmulationActivity : AppCompatActivity(), SensorEventListener {
getAdjustedRotation() getAdjustedRotation()
) )
if (BooleanSetting.PICTURE_IN_PICTURE.boolean) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
pictureInPictureParamsBuilder = getPictureInPictureBuilder() pictureInPictureParamsBuilder.setAutoEnterEnabled(BooleanSetting.PICTURE_IN_PICTURE.boolean)
setPictureInPictureParams(pictureInPictureParamsBuilder.build()) setPictureInPictureParams(pictureInPictureParamsBuilder.build())
} }
} }
@ -314,30 +316,23 @@ class EmulationActivity : AppCompatActivity(), SensorEventListener {
} }
} }
private fun getPictureInPictureBuilder() : PictureInPictureParams.Builder { private fun getPictureInPictureActionsBuilder() : PictureInPictureParams.Builder {
val pictureInPictureParamsBuilder = PictureInPictureParams.Builder()
val pictureInPictureActions : MutableList<RemoteAction> = mutableListOf() val pictureInPictureActions : MutableList<RemoteAction> = mutableListOf()
val pendingFlags = PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_IMMUTABLE val pendingFlags = PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_IMMUTABLE
val pauseIcon = Icon.createWithResource(this, R.drawable.ic_pause) val pauseIcon = Icon.createWithResource(this, R.drawable.ic_pip_pause)
val pausePendingIntent = PendingIntent.getBroadcast(this, R.drawable.ic_pause, Intent(actionPause), pendingFlags) 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) val pauseRemoteAction = RemoteAction(pauseIcon, getString(R.string.pause), getString(R.string.pause), pausePendingIntent)
pictureInPictureActions.add(pauseRemoteAction) pictureInPictureActions.add(pauseRemoteAction)
val playIcon = Icon.createWithResource(this, R.drawable.ic_play) val playIcon = Icon.createWithResource(this, R.drawable.ic_pip_play)
val playPendingIntent = PendingIntent.getBroadcast(this, R.drawable.ic_play, Intent(actionPlay), pendingFlags) 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) val playRemoteAction = RemoteAction(playIcon, getString(R.string.play), getString(R.string.play), playPendingIntent)
pictureInPictureActions.add(playRemoteAction) pictureInPictureActions.add(playRemoteAction)
pictureInPictureParamsBuilder.setActions(pictureInPictureActions) return PictureInPictureParams.Builder().apply {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) { setActions(pictureInPictureActions)
pictureInPictureParamsBuilder.setAutoEnterEnabled(true)
} }
setPictureInPictureParams(pictureInPictureParamsBuilder.build())
return pictureInPictureParamsBuilder
} }
private var pictureInPictureReceiver = object : BroadcastReceiver() { private var pictureInPictureReceiver = object : BroadcastReceiver() {

View file

@ -180,6 +180,9 @@ class EmulationFragment : Fragment(), SurfaceHolder.Callback {
} }
fun onPictureInPictureEnter() { fun onPictureInPictureEnter() {
if (binding.drawerLayout.isOpen) {
binding.drawerLayout.close()
}
if (EmulationMenuSettings.showOverlay) { if (EmulationMenuSettings.showOverlay) {
binding.surfaceInputOverlay.post { binding.surfaceInputOverlay.isVisible = false } binding.surfaceInputOverlay.post { binding.surfaceInputOverlay.isVisible = false }
} }

View 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>

View 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>