|
|
|
@ -8,8 +8,10 @@ import android.content.res.Configuration |
|
|
|
import android.graphics.Color |
|
|
|
import androidx.annotation.ColorInt |
|
|
|
import androidx.appcompat.app.AppCompatActivity |
|
|
|
import androidx.appcompat.app.AppCompatDelegate |
|
|
|
import androidx.core.content.ContextCompat |
|
|
|
import androidx.core.view.WindowCompat |
|
|
|
import androidx.core.view.WindowInsetsControllerCompat |
|
|
|
import androidx.preference.PreferenceManager |
|
|
|
import org.yuzu.yuzu_emu.R |
|
|
|
import org.yuzu.yuzu_emu.YuzuApplication |
|
|
|
@ -26,21 +28,11 @@ object ThemeHelper { |
|
|
|
@JvmStatic |
|
|
|
fun setTheme(activity: AppCompatActivity) { |
|
|
|
val preferences = PreferenceManager.getDefaultSharedPreferences(YuzuApplication.appContext) |
|
|
|
setThemeMode(activity) |
|
|
|
when (preferences.getInt(Settings.PREF_THEME, 0)) { |
|
|
|
DEFAULT -> activity.setTheme(R.style.Theme_Yuzu_Main) |
|
|
|
MATERIAL_YOU -> activity.setTheme(R.style.Theme_Yuzu_Main_MaterialYou) |
|
|
|
} |
|
|
|
|
|
|
|
val windowController = WindowCompat.getInsetsController( |
|
|
|
activity.window, |
|
|
|
activity.window.decorView |
|
|
|
) |
|
|
|
val isLightMode = |
|
|
|
(activity.resources.configuration.uiMode and Configuration.UI_MODE_NIGHT_MASK) == Configuration.UI_MODE_NIGHT_NO |
|
|
|
windowController.isAppearanceLightStatusBars = isLightMode |
|
|
|
windowController.isAppearanceLightNavigationBars = isLightMode |
|
|
|
|
|
|
|
activity.window.statusBarColor = ContextCompat.getColor(activity, android.R.color.transparent) |
|
|
|
} |
|
|
|
|
|
|
|
@JvmStatic |
|
|
|
@ -80,4 +72,34 @@ object ThemeHelper { |
|
|
|
activity.recreate() |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
fun setThemeMode(activity: AppCompatActivity) { |
|
|
|
val themeMode = PreferenceManager.getDefaultSharedPreferences(activity.applicationContext) |
|
|
|
.getInt(Settings.PREF_THEME_MODE, AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM) |
|
|
|
activity.delegate.localNightMode = themeMode |
|
|
|
val windowController = WindowCompat.getInsetsController( |
|
|
|
activity.window, |
|
|
|
activity.window.decorView |
|
|
|
) |
|
|
|
val systemReportedThemeMode = |
|
|
|
activity.resources.configuration.uiMode and Configuration.UI_MODE_NIGHT_MASK |
|
|
|
when (themeMode) { |
|
|
|
AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM -> when (systemReportedThemeMode) { |
|
|
|
Configuration.UI_MODE_NIGHT_NO -> setLightModeSystemBars(windowController) |
|
|
|
Configuration.UI_MODE_NIGHT_YES -> setDarkModeSystemBars(windowController) |
|
|
|
} |
|
|
|
AppCompatDelegate.MODE_NIGHT_NO -> setLightModeSystemBars(windowController) |
|
|
|
AppCompatDelegate.MODE_NIGHT_YES -> setDarkModeSystemBars(windowController) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
private fun setLightModeSystemBars(windowController: WindowInsetsControllerCompat) { |
|
|
|
windowController.isAppearanceLightStatusBars = true |
|
|
|
windowController.isAppearanceLightNavigationBars = true |
|
|
|
} |
|
|
|
|
|
|
|
private fun setDarkModeSystemBars(windowController: WindowInsetsControllerCompat) { |
|
|
|
windowController.isAppearanceLightStatusBars = false |
|
|
|
windowController.isAppearanceLightNavigationBars = false |
|
|
|
} |
|
|
|
} |