From d7178ed16e192fc5a64554526c8deb45c7eb3fe0 Mon Sep 17 00:00:00 2001 From: Charles Lombardo Date: Sun, 23 Apr 2023 18:46:05 -0400 Subject: android: Add black backgrounds toggle --- .../yuzu_emu/features/settings/model/Settings.kt | 1 + .../settings/ui/SettingsFragmentPresenter.kt | 23 ++++++++++++++++++++++ .../java/org/yuzu/yuzu_emu/utils/ThemeHelper.kt | 3 +++ .../app/src/main/res/layout/activity_settings.xml | 3 ++- .../app/src/main/res/values-night/themes.xml | 9 +++++++++ src/android/app/src/main/res/values/strings.xml | 4 ++++ 6 files changed, 42 insertions(+), 1 deletion(-) create mode 100644 src/android/app/src/main/res/values-night/themes.xml (limited to 'src/android/app') 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 2cf9d704e..b71291609 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 @@ -137,6 +137,7 @@ class Settings { const val PREF_FIRST_APP_LAUNCH = "FirstApplicationLaunch" const val PREF_THEME = "Theme" const val PREF_THEME_MODE = "ThemeMode" + const val PREF_BLACK_BACKGROUNDS = "BlackBackgrounds" private val configFileSectionsMap: MutableMap> = HashMap() 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 d8fa321ad..1aae96bc3 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 @@ -10,6 +10,7 @@ import androidx.appcompat.app.AppCompatActivity import androidx.preference.PreferenceManager import org.yuzu.yuzu_emu.R import org.yuzu.yuzu_emu.YuzuApplication +import org.yuzu.yuzu_emu.features.settings.model.AbstractBooleanSetting import org.yuzu.yuzu_emu.features.settings.model.AbstractIntSetting import org.yuzu.yuzu_emu.features.settings.model.AbstractSetting import org.yuzu.yuzu_emu.features.settings.model.IntSetting @@ -380,6 +381,28 @@ class SettingsFragmentPresenter(private val fragmentView: SettingsFragmentView) R.array.themeModeValues ) ) + + val blackBackgrounds: AbstractBooleanSetting = object : AbstractBooleanSetting { + override var boolean: Boolean + get() = preferences.getBoolean(Settings.PREF_BLACK_BACKGROUNDS, false) + set(value) { + preferences.edit().putBoolean(Settings.PREF_BLACK_BACKGROUNDS, value).apply() + settingsActivity.recreate() + } + override val key: String? = null + override val section: String? = null + override val isRuntimeEditable: Boolean = true + override val valueAsString: String + get() = preferences.getBoolean(Settings.PREF_BLACK_BACKGROUNDS, false).toString() + } + + add( + SwitchSetting( + blackBackgrounds, + R.string.use_black_backgrounds, + R.string.use_black_backgrounds_description + ) + ) } } } 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 467978e6d..7c8f1d80b 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 @@ -33,6 +33,9 @@ object ThemeHelper { DEFAULT -> activity.setTheme(R.style.Theme_Yuzu_Main) MATERIAL_YOU -> activity.setTheme(R.style.Theme_Yuzu_Main_MaterialYou) } + if (preferences.getBoolean(Settings.PREF_BLACK_BACKGROUNDS, false)) { + activity.setTheme(R.style.ThemeOverlay_Yuzu_Dark) + } } @JvmStatic diff --git a/src/android/app/src/main/res/layout/activity_settings.xml b/src/android/app/src/main/res/layout/activity_settings.xml index dc23200ea..2745599f4 100644 --- a/src/android/app/src/main/res/layout/activity_settings.xml +++ b/src/android/app/src/main/res/layout/activity_settings.xml @@ -4,7 +4,8 @@ xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" android:layout_width="match_parent" - android:layout_height="match_parent"> + android:layout_height="match_parent" + android:background="?attr/colorSurface"> + + + + + diff --git a/src/android/app/src/main/res/values/strings.xml b/src/android/app/src/main/res/values/strings.xml index 28c9af7bd..d37ffba0d 100644 --- a/src/android/app/src/main/res/values/strings.xml +++ b/src/android/app/src/main/res/values/strings.xml @@ -241,4 +241,8 @@ Light Dark + + Use Black Backgrounds + When using the dark theme, apply black backgrounds. + -- cgit v1.2.3