From 9359f10d6f21533ea5c3d02d86025f2475f22071 Mon Sep 17 00:00:00 2001 From: Helium314 Date: Fri, 21 Jul 2023 17:13:14 +0200 Subject: [PATCH] fix bad interactions of navbar color and custom theme --- .../openboard/inputmethod/latin/LatinIME.java | 25 ++------------ .../settings/AppearanceSettingsFragment.kt | 4 +-- .../inputmethod/latin/settings/Settings.java | 33 +++++++++++++++---- .../latin/settings/SettingsValues.java | 8 +++-- 4 files changed, 37 insertions(+), 33 deletions(-) diff --git a/app/src/main/java/org/dslul/openboard/inputmethod/latin/LatinIME.java b/app/src/main/java/org/dslul/openboard/inputmethod/latin/LatinIME.java index e90f248e3..38f320c37 100644 --- a/app/src/main/java/org/dslul/openboard/inputmethod/latin/LatinIME.java +++ b/app/src/main/java/org/dslul/openboard/inputmethod/latin/LatinIME.java @@ -2018,30 +2018,11 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen } // slightly modified from Simple Keyboard: https://github.com/rkkr/simple-keyboard/blob/master/app/src/main/java/rkr/simplekeyboard/inputmethod/latin/LatinIME.java - // todo: this is currently broken, make it work again (and consider dayNight themes) - /* - final int background; // need to return correct background color for navBar, other colors not used - if (KeyboardTheme.THEME_VARIANT_LIGHT.equals(KeyboardTheme.getThemeVariant(keyboardThemeId))) { - background = Color.rgb(236, 239, 241); - } else if (keyboardThemeId == KeyboardTheme.THEME_ID_LXX_DARK) { - background = Color.rgb(38, 50, 56); - } else { - // dark border is 13/13/13, but that's ok - background = Color.BLACK; - } - - */ private void setNavigationBarColor() { final SettingsValues settingsValues = mSettings.getCurrent(); - if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP || !settingsValues.mNavBarColor) + if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP || !settingsValues.mCustomNavBarColor) return; - final int color; - if (settingsValues.mCustomTheme) { - final int c = settingsValues.mCustomBackgroundColor; - // slightly adjust so color is same as keyboard background - color = Color.rgb((int) (Color.red(c) * 0.925), (int) (Color.green(c) * 0.9379), (int) (Color.blue(c) * 0.945)); - } else - color = settingsValues.mCustomBackgroundColor; + final int color = settingsValues.mNavBarColor; final Window window = getWindow().getWindow(); if (window == null) return; @@ -2061,7 +2042,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen private void clearNavigationBarColor() { final SettingsValues settingsValues = mSettings.getCurrent(); - if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP || !settingsValues.mNavBarColor) + if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP || !settingsValues.mCustomNavBarColor) return; final Window window = getWindow().getWindow(); if (window == null) { diff --git a/app/src/main/java/org/dslul/openboard/inputmethod/latin/settings/AppearanceSettingsFragment.kt b/app/src/main/java/org/dslul/openboard/inputmethod/latin/settings/AppearanceSettingsFragment.kt index 4bad0725f..6648fd646 100644 --- a/app/src/main/java/org/dslul/openboard/inputmethod/latin/settings/AppearanceSettingsFragment.kt +++ b/app/src/main/java/org/dslul/openboard/inputmethod/latin/settings/AppearanceSettingsFragment.kt @@ -121,8 +121,8 @@ class AppearanceSettingsFragment : SubScreenFragment(), Preference.OnPreferenceC isChecked = !isLegacyFamily && KeyboardTheme.getIsAmoledMode(selectedThemeId) } dayNightPref?.apply { - isEnabled = !isLegacyFamily - isChecked = !isLegacyFamily && KeyboardTheme.getIsDayNight(selectedThemeId) + isEnabled = !isLegacyFamily && !KeyboardTheme.getIsCustom(selectedThemeId) + isChecked = !isLegacyFamily && !KeyboardTheme.getIsCustom(selectedThemeId) && KeyboardTheme.getIsDayNight(selectedThemeId) } userColorsPref.apply { isEnabled = KeyboardTheme.getIsCustom(selectedThemeId) diff --git a/app/src/main/java/org/dslul/openboard/inputmethod/latin/settings/Settings.java b/app/src/main/java/org/dslul/openboard/inputmethod/latin/settings/Settings.java index 07d518cfd..bcae1ebc0 100644 --- a/app/src/main/java/org/dslul/openboard/inputmethod/latin/settings/Settings.java +++ b/app/src/main/java/org/dslul/openboard/inputmethod/latin/settings/Settings.java @@ -542,7 +542,7 @@ public final class Settings implements SharedPreferences.OnSharedPreferenceChang return null; } - public static CustomColors getCustomColors(final SharedPreferences prefs) { + public static Colors getColors(final Configuration configuration, final SharedPreferences prefs) { final int keyboardThemeId = KeyboardTheme.getThemeForParameters( prefs.getString(Settings.PREF_THEME_FAMILY, ""), prefs.getString(Settings.PREF_THEME_VARIANT, ""), @@ -551,7 +551,7 @@ public final class Settings implements SharedPreferences.OnSharedPreferenceChang prefs.getBoolean(Settings.PREF_THEME_AMOLED_MODE, false) ); if (!KeyboardTheme.getIsCustom(keyboardThemeId)) - return new CustomColors(); + return new Colors(keyboardThemeId, configuration.uiMode & Configuration.UI_MODE_NIGHT_MASK); // we have a custom theme, which is user only (at the moment) final int accent = prefs.getInt(Settings.PREF_THEME_USER_COLOR_ACCENT, Color.BLUE); @@ -560,7 +560,7 @@ public final class Settings implements SharedPreferences.OnSharedPreferenceChang final int hintTextColor = prefs.getInt(Settings.PREF_THEME_USER_COLOR_HINT_TEXT, Color.WHITE); final int background = prefs.getInt(Settings.PREF_THEME_USER_COLOR_BACKGROUND, Color.DKGRAY); - return new CustomColors(accent, background, keyBgColor, keyBgColor, keyBgColor, keyTextColor, hintTextColor); + return new Colors(accent, background, keyBgColor, keyBgColor, keyBgColor, keyTextColor, hintTextColor); } } @@ -568,8 +568,9 @@ public final class Settings implements SharedPreferences.OnSharedPreferenceChang // class for forwarding custom colors to SettingsValues // (kotlin data class could be 3 lines...) // actually this could contain the color filters too, which would allow more flexibility (only do if needed) -class CustomColors { +class Colors { boolean isCustom; + int navBar; int accent; int background; int keyBackground; @@ -577,7 +578,7 @@ class CustomColors { int spaceBar; int keyText; int keyHintText; - public CustomColors(int acc, int bg, int k, int fun, int space, int kt, int kht) { + public Colors(int acc, int bg, int k, int fun, int space, int kt, int kht) { isCustom = true; accent = acc; background = bg; @@ -586,9 +587,29 @@ class CustomColors { spaceBar = space; keyText = kt; keyHintText = kht; + // slightly adjust color so it matches keyboard background (actually it's a little off) + // todo: remove this weird not-really-white? i.e. set actually white background + // then the default themes could simply be replaced by a set of colors... + // but: this needs to work for the auto-theme too! + navBar = Color.rgb((int) (Color.red(background) * 0.925), (int) (Color.green(background) * 0.9379), (int) (Color.blue(background) * 0.945)); } - public CustomColors() { + public Colors(int themeId, int nightModeFlags) { isCustom = false; + if (KeyboardTheme.getIsDayNight(themeId)) { + if (nightModeFlags == Configuration.UI_MODE_NIGHT_NO) + navBar = Color.rgb(236, 239, 241); + else if (themeId == KeyboardTheme.THEME_ID_LXX_DARK) + navBar = Color.rgb(38, 50, 56); + else + navBar = Color.BLACK; + } else if (KeyboardTheme.THEME_VARIANT_LIGHT.equals(KeyboardTheme.getThemeVariant(themeId))) { + navBar = Color.rgb(236, 239, 241); + } else if (themeId == KeyboardTheme.THEME_ID_LXX_DARK) { + navBar = Color.rgb(38, 50, 56); + } else { + // dark border is 13/13/13, but that's ok + navBar = Color.BLACK; + } accent = 0; background = 0; keyBackground = 0; diff --git a/app/src/main/java/org/dslul/openboard/inputmethod/latin/settings/SettingsValues.java b/app/src/main/java/org/dslul/openboard/inputmethod/latin/settings/SettingsValues.java index 668441f97..dce30b26b 100644 --- a/app/src/main/java/org/dslul/openboard/inputmethod/latin/settings/SettingsValues.java +++ b/app/src/main/java/org/dslul/openboard/inputmethod/latin/settings/SettingsValues.java @@ -109,7 +109,7 @@ public class SettingsValues { public final int mScreenMetrics; public final boolean mAddToPersonalDictionary; public final boolean mUseContactsDictionary; - public final boolean mNavBarColor; + public final boolean mCustomNavBarColor; // From the input box @Nonnull @@ -137,6 +137,7 @@ public class SettingsValues { public final ColorFilter mCustomHintTextColorFilter; public final int mCustomThemeColorAccent; public final int mCustomKeyTextColor; + public final int mNavBarColor; // Debug settings public final boolean mIsInternal; @@ -264,7 +265,8 @@ public class SettingsValues { mOneHandedModeGravity = Settings.readOneHandedModeGravity(prefs); mSecondaryLocale = Settings.getSecondaryLocale(prefs, RichInputMethodManager.getInstance().getCurrentSubtypeLocale().toString()); - final CustomColors colors = Settings.getCustomColors(prefs); + final Colors colors = Settings.getColors(context.getResources().getConfiguration(), prefs); + mNavBarColor = colors.navBar; mCustomTheme = colors.isCustom; mCustomThemeColorAccent = colors.accent; mCustomKeyTextColor = colors.keyText; @@ -285,7 +287,7 @@ public class SettingsValues { mAddToPersonalDictionary = prefs.getBoolean(Settings.PREF_ADD_TO_PERSONAL_DICTIONARY, false); mUseContactsDictionary = prefs.getBoolean(AndroidSpellCheckerService.PREF_USE_CONTACTS_KEY, false); - mNavBarColor = prefs.getBoolean(Settings.PREF_NAVBAR_COLOR, false); + mCustomNavBarColor = prefs.getBoolean(Settings.PREF_NAVBAR_COLOR, false); } public boolean isMetricsLoggingEnabled() {