From 20aa6cf0576fb9c60fa2fd10ae97f567d0161cd2 Mon Sep 17 00:00:00 2001 From: Helium314 Date: Sun, 30 Jul 2023 20:58:46 +0200 Subject: [PATCH] tune colors a little --- .../keyboard/emoji/EmojiPalettesView.java | 5 +- .../inputmethod/latin/common/Colors.java | 65 ++++++++++++------- .../suggestions/SuggestionStripView.java | 4 +- .../keyboard_suggest_strip_lxx_base.xml | 2 +- app/src/main/res/values/colors.xml | 4 +- 5 files changed, 49 insertions(+), 31 deletions(-) diff --git a/app/src/main/java/org/dslul/openboard/inputmethod/keyboard/emoji/EmojiPalettesView.java b/app/src/main/java/org/dslul/openboard/inputmethod/keyboard/emoji/EmojiPalettesView.java index 38f147662..63614d2d1 100644 --- a/app/src/main/java/org/dslul/openboard/inputmethod/keyboard/emoji/EmojiPalettesView.java +++ b/app/src/main/java/org/dslul/openboard/inputmethod/keyboard/emoji/EmojiPalettesView.java @@ -167,7 +167,7 @@ public final class EmojiPalettesView extends LinearLayout iconView.setBackgroundColor(mCategoryPageIndicatorBackground); final Colors colors = Settings.getInstance().getCurrent().mColors; if (colors.isCustom) { - iconView.getBackground().setColorFilter(colors.backgroundFilter); + iconView.getBackground().setColorFilter(colors.adjustedBackgroundFilter); iconView.setColorFilter(colors.keyTextFilter); } iconView.setImageResource(mEmojiCategory.getCategoryTabIcon(categoryId)); @@ -280,8 +280,7 @@ public final class EmojiPalettesView extends LinearLayout DrawableCompat.setTintMode(mSpacebar.getBackground(), PorterDuff.Mode.MULTIPLY); DrawableCompat.setTintMode(mDeleteKey.getBackground(), PorterDuff.Mode.MULTIPLY); getBackground().setColorFilter(colors.backgroundFilter); - mEmojiCategoryPageIndicatorView.setColors(colors.accent, colors.background); - findViewById(R.id.emoji_tab_strip).getBackground().setColorFilter(colors.adjustedBackgroundFilter); + mEmojiCategoryPageIndicatorView.setColors(colors.accent, colors.adjustedBackground); } mEmojiLayoutParams.setKeyProperties(mSpacebar); mSpacebarIcon = findViewById(R.id.emoji_keyboard_space_icon); 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 c7b32a3bc..731aae362 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 @@ -7,7 +7,6 @@ import android.graphics.ColorFilter; import androidx.core.graphics.BlendModeColorFilterCompat; import androidx.core.graphics.BlendModeCompat; -import androidx.core.graphics.ColorUtils; import org.dslul.openboard.inputmethod.keyboard.KeyboardTheme; @@ -22,6 +21,7 @@ public class Colors { public final int spaceBar; public final int keyText; public final int keyHintText; + public int adjustedBackground; // todo (later): evaluate which colors, colorFilters and colorStateLists area actually necessary public ColorFilter backgroundFilter; public ColorFilter adjustedBackgroundFilter; @@ -37,8 +37,7 @@ public class Colors { public ColorStateList functionalKeyStateList; public ColorStateList actionKeyStateList; public ColorStateList spaceBarStateList; - public ColorStateList adjustedBackgroundStateList; // todo (later): use in MoreKeys popup, without breaking when the selection has a radius set - + public ColorStateList adjustedBackgroundStateList; public Colors(int _accent, int _background, int _keyBackground, int _functionalKey, int _spaceBar, int _keyText, int _keyHintText) { isCustom = true; @@ -81,7 +80,9 @@ public class Colors { public void createColorFilters(final boolean hasKeyBorders) { final int[][] states = new int[][] { -// new int[] { android.R.attr.state_checked}, // checked -> todo (later): when is this happening? there are more states, but when are they used? + // are other states used? + // looks like only microphone ("shortcut") key can ever be disabled, but then it's not shown anyway... + // and checked seems unused new int[] { android.R.attr.state_pressed}, // pressed new int[] { -android.R.attr.state_pressed}, // not pressed }; @@ -89,11 +90,15 @@ public class Colors { backgroundFilter = BlendModeColorFilterCompat.createBlendModeColorFilterCompat(background, BlendModeCompat.MODULATE); // 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 }); + if (isDarkColor(background)) { + adjustedBackground = brighten(background); + adjustedBackgroundStateList = new ColorStateList(states, new int[] { brighten(adjustedBackground), adjustedBackground }); + } else { + adjustedBackground = darken(background); + adjustedBackgroundStateList = new ColorStateList(states, new int[] { darken(adjustedBackground), adjustedBackground }); + } adjustedBackgroundFilter = BlendModeColorFilterCompat.createBlendModeColorFilterCompat(adjustedBackground, BlendModeCompat.MODULATE); - // todo (later): for bright colors there often is no need for 2 states, could just have one (because keys will darken anyway) -> test! if (hasKeyBorders) { keyBackgroundFilter = BlendModeColorFilterCompat.createBlendModeColorFilterCompat(keyBackground, BlendModeCompat.MODULATE); functionalKeyBackgroundFilter = BlendModeColorFilterCompat.createBlendModeColorFilterCompat(functionalKey, BlendModeCompat.MODULATE); @@ -123,27 +128,28 @@ public class Colors { : null; } - public static boolean isBrightColor(int color) { + public static boolean isBrightColor(final int color) { if (android.R.color.transparent == color) { return true; } - // See http://www.nbdtech.com/Blog/archive/2008/04/27/Calculating-the-Perceived-Brightness-of-a-Color.aspx - int[] rgb = {Color.red(color), Color.green(color), Color.blue(color)}; - // we are only interested whether brightness is greater, so no need for sqrt - int brightnessSquared = (int) (rgb[0] * rgb[0] * .241 + rgb[1] * rgb[1] * .691 + rgb[2] * rgb[2] * .068); - return brightnessSquared >= 210*210; + return getBrightnessSquared(color) >= 210*210; } - // todo (later): what needs to be public? - public static boolean isDarkColor(int color) { + private static boolean isDarkColor(final int color) { if (android.R.color.transparent == color) { return true; } - // See http://www.nbdtech.com/Blog/archive/2008/04/27/Calculating-the-Perceived-Brightness-of-a-Color.aspx - int[] rgb = {Color.red(color), Color.green(color), Color.blue(color)}; - // we are only interested whether brightness is greater, so no need for sqrt - int brightnessSquared = (int) (rgb[0] * rgb[0] * .241 + rgb[1] * rgb[1] * .691 + rgb[2] * rgb[2] * .068); - return brightnessSquared < 50*50; + return getBrightnessSquared(color) < 50*50; + } + + private static int brighten(final int color) { + // brighten is stronger, because often the drawables get darker when pressed + // todo (maybe): remove the darker pressed colors to have more consistent behavior? + return blendARGB(color, Color.WHITE, 0.14f); + } + + private static int darken(final int color) { + return blendARGB(color, Color.BLACK, 0.11f); } public static int brightenOrDarken(final int color, final boolean preferDarken) { @@ -153,11 +159,22 @@ public class Colors { } else if (isBrightColor(color)) return darken(color); else return brighten(color); } - public static int brighten(final int color) { - return ColorUtils.blendARGB(color, Color.WHITE, 0.2f); // brighten is stronger, because often the drawables get darker when pressed + + // taken from androidx ColorUtils, modified to keep alpha of color1 + private static int blendARGB(int color1, int color2, float ratio) { + final float inverseRatio = 1 - ratio; + float a = Color.alpha(color1); + float r = Color.red(color1) * inverseRatio + Color.red(color2) * ratio; + float g = Color.green(color1) * inverseRatio + Color.green(color2) * ratio; + float b = Color.blue(color1) * inverseRatio + Color.blue(color2) * ratio; + return Color.argb((int) a, (int) r, (int) g, (int) b); } - public static int darken(final int color) { - return ColorUtils.blendARGB(color, Color.BLACK, 0.1f); + private static int getBrightnessSquared(final int color) { + // See http://www.nbdtech.com/Blog/archive/2008/04/27/Calculating-the-Perceived-Brightness-of-a-Color.aspx + int[] rgb = {Color.red(color), Color.green(color), Color.blue(color)}; + // we are only interested whether brightness is greater, so no need for sqrt + return (int) (rgb[0] * rgb[0] * .241 + rgb[1] * rgb[1] * .691 + rgb[2] * rgb[2] * .068); } + } diff --git a/app/src/main/java/org/dslul/openboard/inputmethod/latin/suggestions/SuggestionStripView.java b/app/src/main/java/org/dslul/openboard/inputmethod/latin/suggestions/SuggestionStripView.java index 2b4b8538e..80d570564 100644 --- a/app/src/main/java/org/dslul/openboard/inputmethod/latin/suggestions/SuggestionStripView.java +++ b/app/src/main/java/org/dslul/openboard/inputmethod/latin/suggestions/SuggestionStripView.java @@ -184,8 +184,10 @@ public final class SuggestionStripView extends RelativeLayout implements OnClick final Colors colors = Settings.getInstance().getCurrent().mColors; if (colors.isCustom) { - mStripVisibilityGroup.mSuggestionStripView.getBackground().setColorFilter(colors.adjustedBackgroundFilter); + getBackground().setColorFilter(colors.backgroundFilter); mClipboardKey.setColorFilter(colors.keyText); + mVoiceKey.setColorFilter(colors.keyText); + mOtherKey.setColorFilter(colors.keyText); } else mClipboardKey.clearColorFilter(); } diff --git a/app/src/main/res/drawable/keyboard_suggest_strip_lxx_base.xml b/app/src/main/res/drawable/keyboard_suggest_strip_lxx_base.xml index a4e695fb1..895f065f8 100644 --- a/app/src/main/res/drawable/keyboard_suggest_strip_lxx_base.xml +++ b/app/src/main/res/drawable/keyboard_suggest_strip_lxx_base.xml @@ -2,5 +2,5 @@ - + \ No newline at end of file diff --git a/app/src/main/res/values/colors.xml b/app/src/main/res/values/colors.xml index ccbd2c185..d364f1005 100644 --- a/app/src/main/res/values/colors.xml +++ b/app/src/main/res/values/colors.xml @@ -116,7 +116,7 @@ @android:color/white #F4F4F5 #F4F4F5 - #F4F4F5 + @android:color/white @@ -125,7 +125,7 @@ #F4F4F5 @android:color/white #A9ABAD - #F4F4F5 + @android:color/white #FFEBEBEB