From 93025c95f2ce4baed37a7b587236f12ef667c540 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20N=C3=BCsse?= Date: Sun, 14 Jul 2024 00:54:57 +0200 Subject: [PATCH] android: implement device rotation options (#182) * android: implement device rotation options * fix naming * move orientation-setting to different section --- .../citra_emu/activities/EmulationActivity.kt | 14 +++++++++++--- .../features/settings/model/IntSetting.kt | 5 ++++- .../settings/ui/SettingsFragmentPresenter.kt | 14 ++++++++++++++ src/android/app/src/main/res/values/arrays.xml | 15 +++++++++++++++ src/android/app/src/main/res/values/strings.xml | 10 ++++++++++ 5 files changed, 54 insertions(+), 4 deletions(-) diff --git a/src/android/app/src/main/java/org/citra/citra_emu/activities/EmulationActivity.kt b/src/android/app/src/main/java/org/citra/citra_emu/activities/EmulationActivity.kt index 6b9c89c9d..68e173e7c 100644 --- a/src/android/app/src/main/java/org/citra/citra_emu/activities/EmulationActivity.kt +++ b/src/android/app/src/main/java/org/citra/citra_emu/activities/EmulationActivity.kt @@ -35,6 +35,8 @@ import org.citra.citra_emu.display.ScreenAdjustmentUtil import org.citra.citra_emu.features.hotkeys.HotkeyUtility import org.citra.citra_emu.features.settings.model.SettingsViewModel import org.citra.citra_emu.features.settings.model.view.InputBindingSetting +import org.citra.citra_emu.features.settings.model.IntSetting +import org.citra.citra_emu.features.settings.model.Settings import org.citra.citra_emu.fragments.MessageDialogFragment import org.citra.citra_emu.utils.ControllerMappingHelper import org.citra.citra_emu.utils.FileBrowserHelper @@ -60,7 +62,10 @@ class EmulationActivity : AppCompatActivity() { override fun onCreate(savedInstanceState: Bundle?) { ThemeUtil.setTheme(this) - settingsViewModel.settings.loadSettings() + isActivityRecreated = savedInstanceState != null + if (!isActivityRecreated) { + settingsViewModel.settings.loadSettings() + } super.onCreate(savedInstanceState) @@ -74,8 +79,6 @@ class EmulationActivity : AppCompatActivity() { val navController = navHostFragment.navController navController.setGraph(R.navigation.emulation_navigation, intent.extras) - isActivityRecreated = savedInstanceState != null - // Set these options now so that the SurfaceView the game renders into is the right size. enableFullscreenImmersive() @@ -175,6 +178,11 @@ class EmulationActivity : AppCompatActivity() { controller.systemBarsBehavior = WindowInsetsControllerCompat.BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE } + + + val orientation = settingsViewModel.settings.getSection(Settings.SECTION_RENDERER) + ?.getSetting(IntSetting.DEVICE_ORIENTATION.key) as IntSetting + this.requestedOrientation = orientation.int } // Gets button presses diff --git a/src/android/app/src/main/java/org/citra/citra_emu/features/settings/model/IntSetting.kt b/src/android/app/src/main/java/org/citra/citra_emu/features/settings/model/IntSetting.kt index 378c0eb05..7e921cc3c 100644 --- a/src/android/app/src/main/java/org/citra/citra_emu/features/settings/model/IntSetting.kt +++ b/src/android/app/src/main/java/org/citra/citra_emu/features/settings/model/IntSetting.kt @@ -4,6 +4,8 @@ package org.citra.citra_emu.features.settings.model +import android.content.pm.ActivityInfo + enum class IntSetting( override val key: String, override val section: String, @@ -41,7 +43,8 @@ enum class IntSetting( DEBUG_RENDERER("renderer_debug", Settings.SECTION_DEBUG, 0), TEXTURE_FILTER("texture_filter", Settings.SECTION_RENDERER, 0), USE_FRAME_LIMIT("use_frame_limit", Settings.SECTION_RENDERER, 1), - DELAY_RENDER_THREAD_US("delay_game_render_thread_us", Settings.SECTION_RENDERER, 0); + DELAY_RENDER_THREAD_US("delay_game_render_thread_us", Settings.SECTION_RENDERER, 0), + DEVICE_ORIENTATION("default_device_orientation", Settings.SECTION_RENDERER, ActivityInfo.SCREEN_ORIENTATION_USER); override var int: Int = defaultValue diff --git a/src/android/app/src/main/java/org/citra/citra_emu/features/settings/ui/SettingsFragmentPresenter.kt b/src/android/app/src/main/java/org/citra/citra_emu/features/settings/ui/SettingsFragmentPresenter.kt index f949950bc..7d43031ae 100644 --- a/src/android/app/src/main/java/org/citra/citra_emu/features/settings/ui/SettingsFragmentPresenter.kt +++ b/src/android/app/src/main/java/org/citra/citra_emu/features/settings/ui/SettingsFragmentPresenter.kt @@ -173,6 +173,20 @@ class SettingsFragmentPresenter(private val fragmentView: SettingsFragmentView) private fun addGeneralSettings(sl: ArrayList) { settingsActivity.setToolbarTitle(settingsActivity.getString(R.string.preferences_general)) sl.apply { + add(HeaderSetting(R.string.graphics_ui)) + add( + SingleChoiceSetting( + IntSetting.DEVICE_ORIENTATION, + R.string.device_orientation_title, + R.string.device_orientation_description, + R.array.deviceOrientationEntries, + R.array.deviceOrientationValues, + IntSetting.DEVICE_ORIENTATION.key, + IntSetting.DEVICE_ORIENTATION.defaultValue, + ) + ) + + add(HeaderSetting(R.string.emulator_speed)) add( SwitchSetting( IntSetting.USE_FRAME_LIMIT, diff --git a/src/android/app/src/main/res/values/arrays.xml b/src/android/app/src/main/res/values/arrays.xml index cd542bae8..5f71b7cb5 100644 --- a/src/android/app/src/main/res/values/arrays.xml +++ b/src/android/app/src/main/res/values/arrays.xml @@ -191,6 +191,21 @@ 2 + + @string/device_orientation_system + @string/device_orientation_landscape + @string/device_orientation_portrait + @string/device_orientation_auto + + + + + 2 + 6 + 7 + 4 + + @string/system_region_jpn @string/system_region_usa diff --git a/src/android/app/src/main/res/values/strings.xml b/src/android/app/src/main/res/values/strings.xml index a01418870..e1f9f75a3 100644 --- a/src/android/app/src/main/res/values/strings.xml +++ b/src/android/app/src/main/res/values/strings.xml @@ -204,6 +204,8 @@ Flip + UI + Speed Renderer Graphics API Enable SPIR-V shader generation @@ -465,6 +467,14 @@ Black Backgrounds When using the dark theme, apply black backgrounds. + + Screen Orientation + How should your games be displayed? + Follow System Setting + Landscape + Portrait + Automatic + Device Clock Simulated Clock