diff options
| author | 2023-04-20 18:01:09 -0400 | |
|---|---|---|
| committer | 2023-06-03 00:05:54 -0700 | |
| commit | d9684a2010c1e4643ba7882b2616823814a45342 (patch) | |
| tree | b049de2679584c00b8b7848331646e768d86df08 /src/android/app | |
| parent | android: Add theme picker (diff) | |
| download | yuzu-d9684a2010c1e4643ba7882b2616823814a45342.tar.gz yuzu-d9684a2010c1e4643ba7882b2616823814a45342.tar.xz yuzu-d9684a2010c1e4643ba7882b2616823814a45342.zip | |
android: Add theme mode picker
Diffstat (limited to 'src/android/app')
5 files changed, 76 insertions, 11 deletions
diff --git a/src/android/app/src/main/java/org/yuzu/yuzu_emu/features/settings/model/Settings.kt b/src/android/app/src/main/java/org/yuzu/yuzu_emu/features/settings/model/Settings.kt index b00110e91..2cf9d704e 100644 --- a/src/android/app/src/main/java/org/yuzu/yuzu_emu/features/settings/model/Settings.kt +++ b/src/android/app/src/main/java/org/yuzu/yuzu_emu/features/settings/model/Settings.kt | |||
| @@ -136,6 +136,7 @@ class Settings { | |||
| 136 | 136 | ||
| 137 | const val PREF_FIRST_APP_LAUNCH = "FirstApplicationLaunch" | 137 | const val PREF_FIRST_APP_LAUNCH = "FirstApplicationLaunch" |
| 138 | const val PREF_THEME = "Theme" | 138 | const val PREF_THEME = "Theme" |
| 139 | const val PREF_THEME_MODE = "ThemeMode" | ||
| 139 | 140 | ||
| 140 | private val configFileSectionsMap: MutableMap<String, List<String>> = HashMap() | 141 | private val configFileSectionsMap: MutableMap<String, List<String>> = HashMap() |
| 141 | 142 | ||
diff --git a/src/android/app/src/main/java/org/yuzu/yuzu_emu/features/settings/ui/SettingsFragmentPresenter.kt b/src/android/app/src/main/java/org/yuzu/yuzu_emu/features/settings/ui/SettingsFragmentPresenter.kt index b49a8bbec..d8fa321ad 100644 --- a/src/android/app/src/main/java/org/yuzu/yuzu_emu/features/settings/ui/SettingsFragmentPresenter.kt +++ b/src/android/app/src/main/java/org/yuzu/yuzu_emu/features/settings/ui/SettingsFragmentPresenter.kt | |||
| @@ -16,6 +16,7 @@ import org.yuzu.yuzu_emu.features.settings.model.IntSetting | |||
| 16 | import org.yuzu.yuzu_emu.features.settings.model.Settings | 16 | import org.yuzu.yuzu_emu.features.settings.model.Settings |
| 17 | import org.yuzu.yuzu_emu.features.settings.model.view.* | 17 | import org.yuzu.yuzu_emu.features.settings.model.view.* |
| 18 | import org.yuzu.yuzu_emu.features.settings.utils.SettingsFile | 18 | import org.yuzu.yuzu_emu.features.settings.utils.SettingsFile |
| 19 | import org.yuzu.yuzu_emu.utils.ThemeHelper | ||
| 19 | 20 | ||
| 20 | class SettingsFragmentPresenter(private val fragmentView: SettingsFragmentView) { | 21 | class SettingsFragmentPresenter(private val fragmentView: SettingsFragmentView) { |
| 21 | private var menuTag: String? = null | 22 | private var menuTag: String? = null |
| @@ -355,6 +356,30 @@ class SettingsFragmentPresenter(private val fragmentView: SettingsFragmentView) | |||
| 355 | ) | 356 | ) |
| 356 | ) | 357 | ) |
| 357 | } | 358 | } |
| 359 | |||
| 360 | val themeMode: AbstractIntSetting = object : AbstractIntSetting { | ||
| 361 | override var int: Int | ||
| 362 | get() = preferences.getInt(Settings.PREF_THEME_MODE, -1) | ||
| 363 | set(value) { | ||
| 364 | preferences.edit().putInt(Settings.PREF_THEME_MODE, value).apply() | ||
| 365 | ThemeHelper.setThemeMode(settingsActivity) | ||
| 366 | } | ||
| 367 | override val key: String? = null | ||
| 368 | override val section: String? = null | ||
| 369 | override val isRuntimeEditable: Boolean = true | ||
| 370 | override val valueAsString: String | ||
| 371 | get() = preferences.getInt(Settings.PREF_THEME_MODE, -1).toString() | ||
| 372 | } | ||
| 373 | |||
| 374 | add( | ||
| 375 | SingleChoiceSetting( | ||
| 376 | themeMode, | ||
| 377 | R.string.change_theme_mode, | ||
| 378 | 0, | ||
| 379 | R.array.themeModeEntries, | ||
| 380 | R.array.themeModeValues | ||
| 381 | ) | ||
| 382 | ) | ||
| 358 | } | 383 | } |
| 359 | } | 384 | } |
| 360 | } | 385 | } |
diff --git a/src/android/app/src/main/java/org/yuzu/yuzu_emu/utils/ThemeHelper.kt b/src/android/app/src/main/java/org/yuzu/yuzu_emu/utils/ThemeHelper.kt index 72e2fb75e..467978e6d 100644 --- a/src/android/app/src/main/java/org/yuzu/yuzu_emu/utils/ThemeHelper.kt +++ b/src/android/app/src/main/java/org/yuzu/yuzu_emu/utils/ThemeHelper.kt | |||
| @@ -8,8 +8,10 @@ import android.content.res.Configuration | |||
| 8 | import android.graphics.Color | 8 | import android.graphics.Color |
| 9 | import androidx.annotation.ColorInt | 9 | import androidx.annotation.ColorInt |
| 10 | import androidx.appcompat.app.AppCompatActivity | 10 | import androidx.appcompat.app.AppCompatActivity |
| 11 | import androidx.appcompat.app.AppCompatDelegate | ||
| 11 | import androidx.core.content.ContextCompat | 12 | import androidx.core.content.ContextCompat |
| 12 | import androidx.core.view.WindowCompat | 13 | import androidx.core.view.WindowCompat |
| 14 | import androidx.core.view.WindowInsetsControllerCompat | ||
| 13 | import androidx.preference.PreferenceManager | 15 | import androidx.preference.PreferenceManager |
| 14 | import org.yuzu.yuzu_emu.R | 16 | import org.yuzu.yuzu_emu.R |
| 15 | import org.yuzu.yuzu_emu.YuzuApplication | 17 | import org.yuzu.yuzu_emu.YuzuApplication |
| @@ -26,21 +28,11 @@ object ThemeHelper { | |||
| 26 | @JvmStatic | 28 | @JvmStatic |
| 27 | fun setTheme(activity: AppCompatActivity) { | 29 | fun setTheme(activity: AppCompatActivity) { |
| 28 | val preferences = PreferenceManager.getDefaultSharedPreferences(YuzuApplication.appContext) | 30 | val preferences = PreferenceManager.getDefaultSharedPreferences(YuzuApplication.appContext) |
| 31 | setThemeMode(activity) | ||
| 29 | when (preferences.getInt(Settings.PREF_THEME, 0)) { | 32 | when (preferences.getInt(Settings.PREF_THEME, 0)) { |
| 30 | DEFAULT -> activity.setTheme(R.style.Theme_Yuzu_Main) | 33 | DEFAULT -> activity.setTheme(R.style.Theme_Yuzu_Main) |
| 31 | MATERIAL_YOU -> activity.setTheme(R.style.Theme_Yuzu_Main_MaterialYou) | 34 | MATERIAL_YOU -> activity.setTheme(R.style.Theme_Yuzu_Main_MaterialYou) |
| 32 | } | 35 | } |
| 33 | |||
| 34 | val windowController = WindowCompat.getInsetsController( | ||
| 35 | activity.window, | ||
| 36 | activity.window.decorView | ||
| 37 | ) | ||
| 38 | val isLightMode = | ||
| 39 | (activity.resources.configuration.uiMode and Configuration.UI_MODE_NIGHT_MASK) == Configuration.UI_MODE_NIGHT_NO | ||
| 40 | windowController.isAppearanceLightStatusBars = isLightMode | ||
| 41 | windowController.isAppearanceLightNavigationBars = isLightMode | ||
| 42 | |||
| 43 | activity.window.statusBarColor = ContextCompat.getColor(activity, android.R.color.transparent) | ||
| 44 | } | 36 | } |
| 45 | 37 | ||
| 46 | @JvmStatic | 38 | @JvmStatic |
| @@ -80,4 +72,34 @@ object ThemeHelper { | |||
| 80 | activity.recreate() | 72 | activity.recreate() |
| 81 | } | 73 | } |
| 82 | } | 74 | } |
| 75 | |||
| 76 | fun setThemeMode(activity: AppCompatActivity) { | ||
| 77 | val themeMode = PreferenceManager.getDefaultSharedPreferences(activity.applicationContext) | ||
| 78 | .getInt(Settings.PREF_THEME_MODE, AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM) | ||
| 79 | activity.delegate.localNightMode = themeMode | ||
| 80 | val windowController = WindowCompat.getInsetsController( | ||
| 81 | activity.window, | ||
| 82 | activity.window.decorView | ||
| 83 | ) | ||
| 84 | val systemReportedThemeMode = | ||
| 85 | activity.resources.configuration.uiMode and Configuration.UI_MODE_NIGHT_MASK | ||
| 86 | when (themeMode) { | ||
| 87 | AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM -> when (systemReportedThemeMode) { | ||
| 88 | Configuration.UI_MODE_NIGHT_NO -> setLightModeSystemBars(windowController) | ||
| 89 | Configuration.UI_MODE_NIGHT_YES -> setDarkModeSystemBars(windowController) | ||
| 90 | } | ||
| 91 | AppCompatDelegate.MODE_NIGHT_NO -> setLightModeSystemBars(windowController) | ||
| 92 | AppCompatDelegate.MODE_NIGHT_YES -> setDarkModeSystemBars(windowController) | ||
| 93 | } | ||
| 94 | } | ||
| 95 | |||
| 96 | private fun setLightModeSystemBars(windowController: WindowInsetsControllerCompat) { | ||
| 97 | windowController.isAppearanceLightStatusBars = true | ||
| 98 | windowController.isAppearanceLightNavigationBars = true | ||
| 99 | } | ||
| 100 | |||
| 101 | private fun setDarkModeSystemBars(windowController: WindowInsetsControllerCompat) { | ||
| 102 | windowController.isAppearanceLightStatusBars = false | ||
| 103 | windowController.isAppearanceLightNavigationBars = false | ||
| 104 | } | ||
| 83 | } | 105 | } |
diff --git a/src/android/app/src/main/res/values/arrays.xml b/src/android/app/src/main/res/values/arrays.xml index a98ccd985..ce9a576c2 100644 --- a/src/android/app/src/main/res/values/arrays.xml +++ b/src/android/app/src/main/res/values/arrays.xml | |||
| @@ -199,4 +199,15 @@ | |||
| 199 | <item>1</item> | 199 | <item>1</item> |
| 200 | </integer-array> | 200 | </integer-array> |
| 201 | 201 | ||
| 202 | <string-array name="themeModeEntries"> | ||
| 203 | <item>@string/theme_mode_follow_system</item> | ||
| 204 | <item>@string/theme_mode_light</item> | ||
| 205 | <item>@string/theme_mode_dark</item> | ||
| 206 | </string-array> | ||
| 207 | <integer-array name="themeModeValues"> | ||
| 208 | <item>-1</item> | ||
| 209 | <item>1</item> | ||
| 210 | <item>2</item> | ||
| 211 | </integer-array> | ||
| 212 | |||
| 202 | </resources> | 213 | </resources> |
diff --git a/src/android/app/src/main/res/values/strings.xml b/src/android/app/src/main/res/values/strings.xml index 90c94d67f..28c9af7bd 100644 --- a/src/android/app/src/main/res/values/strings.xml +++ b/src/android/app/src/main/res/values/strings.xml | |||
| @@ -235,4 +235,10 @@ | |||
| 235 | <string name="theme_default">Default</string> | 235 | <string name="theme_default">Default</string> |
| 236 | <string name="theme_material_you">Material You</string> | 236 | <string name="theme_material_you">Material You</string> |
| 237 | 237 | ||
| 238 | <!-- Theme Modes --> | ||
| 239 | <string name="change_theme_mode">Change Theme Mode</string> | ||
| 240 | <string name="theme_mode_follow_system">Follow System</string> | ||
| 241 | <string name="theme_mode_light">Light</string> | ||
| 242 | <string name="theme_mode_dark">Dark</string> | ||
| 243 | |||
| 238 | </resources> | 244 | </resources> |