From cdb157f58af55e3f9728bc3ea10e71e83a299e7a Mon Sep 17 00:00:00 2001 From: Charles Lombardo Date: Sun, 9 Apr 2023 15:18:28 -0400 Subject: [PATCH] citra_android: Night mode fixes (#6416) --- .../citra/citra_emu/ui/main/MainActivity.java | 2 ++ .../org/citra/citra_emu/utils/ThemeUtil.java | 17 ++++++++++++----- .../app/src/main/res/layout/fragment_grid.xml | 3 ++- 3 files changed, 16 insertions(+), 6 deletions(-) diff --git a/src/android/app/src/main/java/org/citra/citra_emu/ui/main/MainActivity.java b/src/android/app/src/main/java/org/citra/citra_emu/ui/main/MainActivity.java index b2833d1ac..c9b28daf9 100644 --- a/src/android/app/src/main/java/org/citra/citra_emu/ui/main/MainActivity.java +++ b/src/android/app/src/main/java/org/citra/citra_emu/ui/main/MainActivity.java @@ -169,6 +169,8 @@ public final class MainActivity extends AppCompatActivity implements MainView { protected void onResume() { super.onResume(); mPresenter.addDirIfNeeded(new AddDirectoryHelper(this)); + + ThemeUtil.setSystemBarMode(this, ThemeUtil.getIsLightMode(getResources())); } // TODO: Replace with a ButterKnife injection. diff --git a/src/android/app/src/main/java/org/citra/citra_emu/utils/ThemeUtil.java b/src/android/app/src/main/java/org/citra/citra_emu/utils/ThemeUtil.java index fbccc9df1..d8c193665 100644 --- a/src/android/app/src/main/java/org/citra/citra_emu/utils/ThemeUtil.java +++ b/src/android/app/src/main/java/org/citra/citra_emu/utils/ThemeUtil.java @@ -3,6 +3,7 @@ package org.citra.citra_emu.utils; import android.app.Activity; import android.content.SharedPreferences; import android.content.res.Configuration; +import android.content.res.Resources; import android.graphics.Color; import android.os.Build; import android.preference.PreferenceManager; @@ -41,11 +42,7 @@ public class ThemeUtil { break; } - int systemReportedThemeMode = activity.getResources().getConfiguration().uiMode & Configuration.UI_MODE_NIGHT_MASK; - WindowInsetsControllerCompat windowController = WindowCompat.getInsetsController(activity.getWindow(), activity.getWindow().getDecorView()); - windowController.setAppearanceLightStatusBars(systemReportedThemeMode == Configuration.UI_MODE_NIGHT_NO); - windowController.setAppearanceLightNavigationBars(systemReportedThemeMode == Configuration.UI_MODE_NIGHT_NO); - + setSystemBarMode(activity, getIsLightMode(activity.getResources())); setNavigationBarColor(activity, MaterialColors.getColor(activity.getWindow().getDecorView(), R.attr.colorSurface)); } @@ -53,6 +50,12 @@ public class ThemeUtil { applyTheme(mPreferences.getInt(SettingsFile.KEY_DESIGN, 0), activity); } + public static void setSystemBarMode(AppCompatActivity activity, boolean isLightMode) { + WindowInsetsControllerCompat windowController = WindowCompat.getInsetsController(activity.getWindow(), activity.getWindow().getDecorView()); + windowController.setAppearanceLightStatusBars(isLightMode); + windowController.setAppearanceLightNavigationBars(isLightMode); + } + public static void setNavigationBarColor(@NonNull Activity activity, @ColorInt int color) { int gestureType = InsetsHelper.getSystemGestureType(activity.getApplicationContext()); int orientation = activity.getResources().getConfiguration().orientation; @@ -80,4 +83,8 @@ public class ThemeUtil { return Color.argb(Math.round(alphaFactor * Color.alpha(color)), Color.red(color), Color.green(color), Color.blue(color)); } + + public static boolean getIsLightMode(Resources resources) { + return (resources.getConfiguration().uiMode & Configuration.UI_MODE_NIGHT_MASK) == Configuration.UI_MODE_NIGHT_NO; + } } diff --git a/src/android/app/src/main/res/layout/fragment_grid.xml b/src/android/app/src/main/res/layout/fragment_grid.xml index 3be511789..e7b2770be 100644 --- a/src/android/app/src/main/res/layout/fragment_grid.xml +++ b/src/android/app/src/main/res/layout/fragment_grid.xml @@ -2,7 +2,8 @@ + android:layout_height="match_parent" + android:background="?attr/colorSurface">