Merge pull request #10801 from 8bitDream/fix_aspect

android: Fix aspect ratio when rotating screen
This commit is contained in:
bunnei 2023-06-16 11:45:32 -07:00 committed by GitHub
commit 4112031c81
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 20 additions and 28 deletions

View file

@ -53,6 +53,7 @@ SPDX-License-Identifier: GPL-3.0-or-later
<activity <activity
android:name="org.yuzu.yuzu_emu.activities.EmulationActivity" android:name="org.yuzu.yuzu_emu.activities.EmulationActivity"
android:theme="@style/Theme.Yuzu.Main" android:theme="@style/Theme.Yuzu.Main"
android:screenOrientation="userLandscape"
android:supportsPictureInPicture="true" android:supportsPictureInPicture="true"
android:configChanges="orientation|screenSize|smallestScreenSize|screenLayout|uiMode" android:configChanges="orientation|screenSize|smallestScreenSize|screenLayout|uiMode"
android:exported="true"> android:exported="true">

View file

@ -85,20 +85,7 @@ class EmulationFragment : Fragment(), SurfaceHolder.Callback {
onReturnFromSettings = context.activityResultRegistry.register( onReturnFromSettings = context.activityResultRegistry.register(
"SettingsResult", "SettingsResult",
ActivityResultContracts.StartActivityForResult() ActivityResultContracts.StartActivityForResult()
) { ) { updateScreenLayout() }
binding.surfaceEmulation.setAspectRatio(
when (IntSetting.RENDERER_ASPECT_RATIO.int) {
0 -> Rational(16, 9)
1 -> Rational(4, 3)
2 -> Rational(21, 9)
3 -> Rational(16, 10)
4 -> null // Stretch
else -> Rational(16, 9)
}
)
emulationActivity?.buildPictureInPictureParams()
updateScreenLayout()
}
} else { } else {
throw IllegalStateException("EmulationFragment must have EmulationActivity parent") throw IllegalStateException("EmulationFragment must have EmulationActivity parent")
} }
@ -242,17 +229,6 @@ class EmulationFragment : Fragment(), SurfaceHolder.Callback {
DirectoryInitialization.start(requireContext()) DirectoryInitialization.start(requireContext())
} }
binding.surfaceEmulation.setAspectRatio(
when (IntSetting.RENDERER_ASPECT_RATIO.int) {
0 -> Rational(16, 9)
1 -> Rational(4, 3)
2 -> Rational(21, 9)
3 -> Rational(16, 10)
4 -> null // Stretch
else -> Rational(16, 9)
}
)
updateScreenLayout() updateScreenLayout()
emulationState.run(emulationActivity!!.isActivityRecreated) emulationState.run(emulationActivity!!.isActivityRecreated)
@ -315,7 +291,7 @@ class EmulationFragment : Fragment(), SurfaceHolder.Callback {
} }
@SuppressLint("SourceLockedOrientationActivity") @SuppressLint("SourceLockedOrientationActivity")
private fun updateScreenLayout() { private fun updateOrientation() {
emulationActivity?.let { emulationActivity?.let {
it.requestedOrientation = when (IntSetting.RENDERER_SCREEN_LAYOUT.int) { it.requestedOrientation = when (IntSetting.RENDERER_SCREEN_LAYOUT.int) {
Settings.LayoutOption_MobileLandscape -> Settings.LayoutOption_MobileLandscape ->
@ -326,7 +302,21 @@ class EmulationFragment : Fragment(), SurfaceHolder.Callback {
else -> ActivityInfo.SCREEN_ORIENTATION_USER_LANDSCAPE else -> ActivityInfo.SCREEN_ORIENTATION_USER_LANDSCAPE
} }
} }
onConfigurationChanged(resources.configuration) }
private fun updateScreenLayout() {
binding.surfaceEmulation.setAspectRatio(
when (IntSetting.RENDERER_ASPECT_RATIO.int) {
0 -> Rational(16, 9)
1 -> Rational(4, 3)
2 -> Rational(21, 9)
3 -> Rational(16, 10)
4 -> null // Stretch
else -> Rational(16, 9)
}
)
emulationActivity?.buildPictureInPictureParams()
updateOrientation()
} }
private fun updateFoldableLayout( private fun updateFoldableLayout(
@ -359,7 +349,8 @@ class EmulationFragment : Fragment(), SurfaceHolder.Callback {
binding.overlayContainer.layoutParams.height = ViewGroup.LayoutParams.MATCH_PARENT binding.overlayContainer.layoutParams.height = ViewGroup.LayoutParams.MATCH_PARENT
binding.inGameMenu.layoutParams.height = ViewGroup.LayoutParams.MATCH_PARENT binding.inGameMenu.layoutParams.height = ViewGroup.LayoutParams.MATCH_PARENT
isInFoldableLayout = false isInFoldableLayout = false
updateScreenLayout() updateOrientation()
onConfigurationChanged(resources.configuration)
} }
binding.emulationContainer.requestLayout() binding.emulationContainer.requestLayout()
binding.inputContainer.requestLayout() binding.inputContainer.requestLayout()