From 099095e3a360cd239106a63e0aecede1acf900ee Mon Sep 17 00:00:00 2001 From: Helium314 Date: Sun, 30 Jul 2023 09:57:43 +0200 Subject: [PATCH] slightly adjust colors, adjust some todos --- .../openboard/inputmethod/keyboard/KeyboardTheme.java | 4 +++- .../openboard/inputmethod/keyboard/KeyboardView.java | 11 ++++++++--- .../openboard/inputmethod/latin/common/Colors.java | 7 +++---- 3 files changed, 14 insertions(+), 8 deletions(-) diff --git a/app/src/main/java/org/dslul/openboard/inputmethod/keyboard/KeyboardTheme.java b/app/src/main/java/org/dslul/openboard/inputmethod/keyboard/KeyboardTheme.java index 2edf8eab8..63f7908f1 100644 --- a/app/src/main/java/org/dslul/openboard/inputmethod/keyboard/KeyboardTheme.java +++ b/app/src/main/java/org/dslul/openboard/inputmethod/keyboard/KeyboardTheme.java @@ -361,6 +361,7 @@ public final class KeyboardTheme implements Comparable { public static final String THEME_BLACK = "black"; public static final String THEME_USER = "user"; + // todo: copies of original themes might need adjustments, though maybe it's only Colors that needs to be adjusted public static Colors getCustomTheme(String theme, Context context, SharedPreferences prefs) { switch (theme) { case THEME_USER: @@ -369,10 +370,11 @@ public final class KeyboardTheme implements Comparable { final int keyTextColor = prefs.getInt(Settings.PREF_THEME_USER_COLOR_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); - return new Colors(accent, background, keyBgColor, Colors.darken(keyBgColor), keyBgColor, keyTextColor, hintTextColor); + return new Colors(accent, background, keyBgColor, Colors.brightenOrDarken(keyBgColor, true), keyBgColor, keyTextColor, hintTextColor); case THEME_DARK: return new Colors( ContextCompat.getColor(context, R.color.gesture_trail_color_lxx_dark), + // colors taken from the drawable Color.parseColor("#263238"), Color.parseColor("#364248"), Color.parseColor("#2d393f"), diff --git a/app/src/main/java/org/dslul/openboard/inputmethod/keyboard/KeyboardView.java b/app/src/main/java/org/dslul/openboard/inputmethod/keyboard/KeyboardView.java index 7183359f7..868c4ef60 100644 --- a/app/src/main/java/org/dslul/openboard/inputmethod/keyboard/KeyboardView.java +++ b/app/src/main/java/org/dslul/openboard/inputmethod/keyboard/KeyboardView.java @@ -176,7 +176,10 @@ public class KeyboardView extends View { DrawableCompat.setTintMode(mKeyBackground, PorterDuff.Mode.MULTIPLY); DrawableCompat.setTintMode(mSpacebarBackground, PorterDuff.Mode.MULTIPLY); DrawableCompat.setTintMode(mFunctionalKeyBackground, PorterDuff.Mode.MULTIPLY); - getBackground().setColorFilter(mColors.backgroundFilter); + if (this.getClass() == MoreKeysKeyboardView.class) + getBackground().setColorFilter(mColors.adjustedBackgroundFilter); + else + getBackground().setColorFilter(mColors.backgroundFilter); } } @@ -613,12 +616,14 @@ public class KeyboardView extends View { if (isAccentColoredKey(key)) { icon.setColorFilter(mColors.actionKeyIconColorFilter); } else if (key.isShift() && keyboard != null) { + // todo (idea): replace shift icon with white one and use the normal multiply filters + // this could allow different shift icon with nicer coloring if (keyboard.mId.mElementId == KeyboardId.ELEMENT_ALPHABET_MANUAL_SHIFTED || keyboard.mId.mElementId == KeyboardId.ELEMENT_ALPHABET_SHIFT_LOCKED || keyboard.mId.mElementId == KeyboardId.ELEMENT_ALPHABET_AUTOMATIC_SHIFTED || keyboard.mId.mElementId == KeyboardId.ELEMENT_ALPHABET_SHIFT_LOCK_SHIFTED ) - icon.setColorFilter(mColors.accentColorFilter); // accent if shifted + icon.setColorFilter(mColors.accent, PorterDuff.Mode.SRC_ATOP); // accent if shifted, needs SRC_ATOP because of underlying drawable else icon.setColorFilter(mColors.keyTextFilter); // key text if not shifted } else if (key.getBackgroundType() != Key.BACKGROUND_TYPE_NORMAL) { @@ -640,7 +645,7 @@ public class KeyboardView extends View { } else if (key.isFunctional()) { // shift, 123, delete,... DrawableCompat.setTintList(background, mColors.functionalKeyStateList); } else if (this.getClass() == MoreKeysKeyboardView.class) { // more keys popup (except on action key, which is handled above) - DrawableCompat.setTintList(background, mColors.backgroundStateList); + DrawableCompat.setTintList(background, mColors.adjustedBackgroundStateList); } else if (key.getBackgroundType() == Key.BACKGROUND_TYPE_NORMAL) { // normal keys DrawableCompat.setTintList(background, mColors.keyStateList); } else if (keyboard.mId.mElementId >= 10 && keyboard.mId.mElementId <= 26) { // emoji keyboard keys diff --git a/app/src/main/java/org/dslul/openboard/inputmethod/latin/common/Colors.java b/app/src/main/java/org/dslul/openboard/inputmethod/latin/common/Colors.java index e8d4c44da..c7b32a3bc 100644 --- a/app/src/main/java/org/dslul/openboard/inputmethod/latin/common/Colors.java +++ b/app/src/main/java/org/dslul/openboard/inputmethod/latin/common/Colors.java @@ -22,7 +22,7 @@ public class Colors { public final int spaceBar; public final int keyText; public final int keyHintText; - // todo: evaluate which colors, colorFilters and colorStateLists area actually necessary + // todo (later): evaluate which colors, colorFilters and colorStateLists area actually necessary public ColorFilter backgroundFilter; public ColorFilter adjustedBackgroundFilter; public ColorFilter keyBackgroundFilter; @@ -81,15 +81,14 @@ public class Colors { public void createColorFilters(final boolean hasKeyBorders) { final int[][] states = new int[][] { -// new int[] { android.R.attr.state_checked}, // checked -> todo: when is this happening? there are more states, but when are they used? +// new int[] { android.R.attr.state_checked}, // checked -> todo (later): when is this happening? there are more states, but when are they used? new int[] { android.R.attr.state_pressed}, // pressed new int[] { -android.R.attr.state_pressed}, // not pressed }; backgroundFilter = BlendModeColorFilterCompat.createBlendModeColorFilterCompat(background, BlendModeCompat.MODULATE); - // todo: use adjusted? or is this just for space bar in no border theme? - // maybe for morekeys popup, but then need to set background color there too + // color to be used if exact background color would be bad contrast, e.g. more keys popup or no border space bar final int adjustedBackground = brightenOrDarken(background, true); adjustedBackgroundStateList = new ColorStateList(states, new int[] { brightenOrDarken(adjustedBackground, true), adjustedBackground }); adjustedBackgroundFilter = BlendModeColorFilterCompat.createBlendModeColorFilterCompat(adjustedBackground, BlendModeCompat.MODULATE);