diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index a5f3218f..9bf670ce 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -67,7 +67,8 @@ = Build.VERSION_CODES.S) + setPictureInPictureParams(PictureInPictureParams.Builder().setAutoEnterEnabled(true).build()) + binding.gameView.holder.addCallback(this) binding.gameView.setAspectRatio( @@ -343,6 +349,23 @@ class EmulationActivity : AppCompatActivity(), SurfaceHolder.Callback, View.OnTo } } + override fun onPictureInPictureModeChanged(isInPictureInPictureMode: Boolean, newConfig: Configuration) { + super.onPictureInPictureModeChanged(isInPictureInPictureMode, newConfig) + if (isInPictureInPictureMode) { + binding.onScreenControllerView.isGone = true + binding.onScreenControllerToggle.isGone = true + } else { + binding.onScreenControllerView.apply { + controllerType = inputHandler.getFirstControllerType() + isGone = controllerType == ControllerType.None || !appSettings.onScreenControl + } + binding.onScreenControllerToggle.apply { + isGone = binding.onScreenControllerView.isGone + } + } + } + + /** * Stop the currently executing ROM and replace it with the one specified in the new intent */ @@ -354,6 +377,11 @@ class EmulationActivity : AppCompatActivity(), SurfaceHolder.Callback, View.OnTo } } + override fun onUserLeaveHint() { + if (Build.VERSION.SDK_INT < Build.VERSION_CODES.S) + enterPictureInPictureMode(PictureInPictureParams.Builder().build()) + } + override fun onDestroy() { super.onDestroy() shouldFinish = false @@ -519,7 +547,7 @@ class EmulationActivity : AppCompatActivity(), SurfaceHolder.Callback, View.OnTo return ((major shl 22) or (minor shl 12) or (patch)).toInt() } - val insetsOrMarginHandler = View.OnApplyWindowInsetsListener { view, insets -> + private val insetsOrMarginHandler = View.OnApplyWindowInsetsListener { view, insets -> insets.displayCutout?.let { val defaultHorizontalMargin = view.resources.getDimensionPixelSize(R.dimen.onScreenItemHorizontalMargin) val left = if (it.safeInsetLeft == 0) defaultHorizontalMargin else it.safeInsetLeft