fix bad interactions of navbar color and custom theme

This commit is contained in:
Helium314 2023-07-21 17:13:14 +02:00
parent ca2b671f26
commit 9359f10d6f
4 changed files with 37 additions and 33 deletions

View file

@ -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 // 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() { private void setNavigationBarColor() {
final SettingsValues settingsValues = mSettings.getCurrent(); 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; return;
final int color; final int color = settingsValues.mNavBarColor;
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 Window window = getWindow().getWindow(); final Window window = getWindow().getWindow();
if (window == null) if (window == null)
return; return;
@ -2061,7 +2042,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
private void clearNavigationBarColor() { private void clearNavigationBarColor() {
final SettingsValues settingsValues = mSettings.getCurrent(); 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; return;
final Window window = getWindow().getWindow(); final Window window = getWindow().getWindow();
if (window == null) { if (window == null) {

View file

@ -121,8 +121,8 @@ class AppearanceSettingsFragment : SubScreenFragment(), Preference.OnPreferenceC
isChecked = !isLegacyFamily && KeyboardTheme.getIsAmoledMode(selectedThemeId) isChecked = !isLegacyFamily && KeyboardTheme.getIsAmoledMode(selectedThemeId)
} }
dayNightPref?.apply { dayNightPref?.apply {
isEnabled = !isLegacyFamily isEnabled = !isLegacyFamily && !KeyboardTheme.getIsCustom(selectedThemeId)
isChecked = !isLegacyFamily && KeyboardTheme.getIsDayNight(selectedThemeId) isChecked = !isLegacyFamily && !KeyboardTheme.getIsCustom(selectedThemeId) && KeyboardTheme.getIsDayNight(selectedThemeId)
} }
userColorsPref.apply { userColorsPref.apply {
isEnabled = KeyboardTheme.getIsCustom(selectedThemeId) isEnabled = KeyboardTheme.getIsCustom(selectedThemeId)

View file

@ -542,7 +542,7 @@ public final class Settings implements SharedPreferences.OnSharedPreferenceChang
return null; return null;
} }
public static CustomColors getCustomColors(final SharedPreferences prefs) { public static Colors getColors(final Configuration configuration, final SharedPreferences prefs) {
final int keyboardThemeId = KeyboardTheme.getThemeForParameters( final int keyboardThemeId = KeyboardTheme.getThemeForParameters(
prefs.getString(Settings.PREF_THEME_FAMILY, ""), prefs.getString(Settings.PREF_THEME_FAMILY, ""),
prefs.getString(Settings.PREF_THEME_VARIANT, ""), 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) prefs.getBoolean(Settings.PREF_THEME_AMOLED_MODE, false)
); );
if (!KeyboardTheme.getIsCustom(keyboardThemeId)) 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) // 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); 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 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); 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 // class for forwarding custom colors to SettingsValues
// (kotlin data class could be 3 lines...) // (kotlin data class could be 3 lines...)
// actually this could contain the color filters too, which would allow more flexibility (only do if needed) // actually this could contain the color filters too, which would allow more flexibility (only do if needed)
class CustomColors { class Colors {
boolean isCustom; boolean isCustom;
int navBar;
int accent; int accent;
int background; int background;
int keyBackground; int keyBackground;
@ -577,7 +578,7 @@ class CustomColors {
int spaceBar; int spaceBar;
int keyText; int keyText;
int keyHintText; 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; isCustom = true;
accent = acc; accent = acc;
background = bg; background = bg;
@ -586,9 +587,29 @@ class CustomColors {
spaceBar = space; spaceBar = space;
keyText = kt; keyText = kt;
keyHintText = kht; 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; 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; accent = 0;
background = 0; background = 0;
keyBackground = 0; keyBackground = 0;

View file

@ -109,7 +109,7 @@ public class SettingsValues {
public final int mScreenMetrics; public final int mScreenMetrics;
public final boolean mAddToPersonalDictionary; public final boolean mAddToPersonalDictionary;
public final boolean mUseContactsDictionary; public final boolean mUseContactsDictionary;
public final boolean mNavBarColor; public final boolean mCustomNavBarColor;
// From the input box // From the input box
@Nonnull @Nonnull
@ -137,6 +137,7 @@ public class SettingsValues {
public final ColorFilter mCustomHintTextColorFilter; public final ColorFilter mCustomHintTextColorFilter;
public final int mCustomThemeColorAccent; public final int mCustomThemeColorAccent;
public final int mCustomKeyTextColor; public final int mCustomKeyTextColor;
public final int mNavBarColor;
// Debug settings // Debug settings
public final boolean mIsInternal; public final boolean mIsInternal;
@ -264,7 +265,8 @@ public class SettingsValues {
mOneHandedModeGravity = Settings.readOneHandedModeGravity(prefs); mOneHandedModeGravity = Settings.readOneHandedModeGravity(prefs);
mSecondaryLocale = Settings.getSecondaryLocale(prefs, RichInputMethodManager.getInstance().getCurrentSubtypeLocale().toString()); 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; mCustomTheme = colors.isCustom;
mCustomThemeColorAccent = colors.accent; mCustomThemeColorAccent = colors.accent;
mCustomKeyTextColor = colors.keyText; mCustomKeyTextColor = colors.keyText;
@ -285,7 +287,7 @@ public class SettingsValues {
mAddToPersonalDictionary = prefs.getBoolean(Settings.PREF_ADD_TO_PERSONAL_DICTIONARY, false); mAddToPersonalDictionary = prefs.getBoolean(Settings.PREF_ADD_TO_PERSONAL_DICTIONARY, false);
mUseContactsDictionary = prefs.getBoolean(AndroidSpellCheckerService.PREF_USE_CONTACTS_KEY, 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() { public boolean isMetricsLoggingEnabled() {