mirror of
https://github.com/Helium314/HeliBoard.git
synced 2025-05-20 17:00:30 +00:00
tune colors a little
This commit is contained in:
parent
d9ebf2866c
commit
20aa6cf057
5 changed files with 49 additions and 31 deletions
|
@ -167,7 +167,7 @@ public final class EmojiPalettesView extends LinearLayout
|
||||||
iconView.setBackgroundColor(mCategoryPageIndicatorBackground);
|
iconView.setBackgroundColor(mCategoryPageIndicatorBackground);
|
||||||
final Colors colors = Settings.getInstance().getCurrent().mColors;
|
final Colors colors = Settings.getInstance().getCurrent().mColors;
|
||||||
if (colors.isCustom) {
|
if (colors.isCustom) {
|
||||||
iconView.getBackground().setColorFilter(colors.backgroundFilter);
|
iconView.getBackground().setColorFilter(colors.adjustedBackgroundFilter);
|
||||||
iconView.setColorFilter(colors.keyTextFilter);
|
iconView.setColorFilter(colors.keyTextFilter);
|
||||||
}
|
}
|
||||||
iconView.setImageResource(mEmojiCategory.getCategoryTabIcon(categoryId));
|
iconView.setImageResource(mEmojiCategory.getCategoryTabIcon(categoryId));
|
||||||
|
@ -280,8 +280,7 @@ public final class EmojiPalettesView extends LinearLayout
|
||||||
DrawableCompat.setTintMode(mSpacebar.getBackground(), PorterDuff.Mode.MULTIPLY);
|
DrawableCompat.setTintMode(mSpacebar.getBackground(), PorterDuff.Mode.MULTIPLY);
|
||||||
DrawableCompat.setTintMode(mDeleteKey.getBackground(), PorterDuff.Mode.MULTIPLY);
|
DrawableCompat.setTintMode(mDeleteKey.getBackground(), PorterDuff.Mode.MULTIPLY);
|
||||||
getBackground().setColorFilter(colors.backgroundFilter);
|
getBackground().setColorFilter(colors.backgroundFilter);
|
||||||
mEmojiCategoryPageIndicatorView.setColors(colors.accent, colors.background);
|
mEmojiCategoryPageIndicatorView.setColors(colors.accent, colors.adjustedBackground);
|
||||||
findViewById(R.id.emoji_tab_strip).getBackground().setColorFilter(colors.adjustedBackgroundFilter);
|
|
||||||
}
|
}
|
||||||
mEmojiLayoutParams.setKeyProperties(mSpacebar);
|
mEmojiLayoutParams.setKeyProperties(mSpacebar);
|
||||||
mSpacebarIcon = findViewById(R.id.emoji_keyboard_space_icon);
|
mSpacebarIcon = findViewById(R.id.emoji_keyboard_space_icon);
|
||||||
|
|
|
@ -7,7 +7,6 @@ import android.graphics.ColorFilter;
|
||||||
|
|
||||||
import androidx.core.graphics.BlendModeColorFilterCompat;
|
import androidx.core.graphics.BlendModeColorFilterCompat;
|
||||||
import androidx.core.graphics.BlendModeCompat;
|
import androidx.core.graphics.BlendModeCompat;
|
||||||
import androidx.core.graphics.ColorUtils;
|
|
||||||
|
|
||||||
import org.dslul.openboard.inputmethod.keyboard.KeyboardTheme;
|
import org.dslul.openboard.inputmethod.keyboard.KeyboardTheme;
|
||||||
|
|
||||||
|
@ -22,6 +21,7 @@ public class Colors {
|
||||||
public final int spaceBar;
|
public final int spaceBar;
|
||||||
public final int keyText;
|
public final int keyText;
|
||||||
public final int keyHintText;
|
public final int keyHintText;
|
||||||
|
public int adjustedBackground;
|
||||||
// todo (later): 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 backgroundFilter;
|
||||||
public ColorFilter adjustedBackgroundFilter;
|
public ColorFilter adjustedBackgroundFilter;
|
||||||
|
@ -37,8 +37,7 @@ public class Colors {
|
||||||
public ColorStateList functionalKeyStateList;
|
public ColorStateList functionalKeyStateList;
|
||||||
public ColorStateList actionKeyStateList;
|
public ColorStateList actionKeyStateList;
|
||||||
public ColorStateList spaceBarStateList;
|
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) {
|
public Colors(int _accent, int _background, int _keyBackground, int _functionalKey, int _spaceBar, int _keyText, int _keyHintText) {
|
||||||
isCustom = true;
|
isCustom = true;
|
||||||
|
@ -81,7 +80,9 @@ public class Colors {
|
||||||
|
|
||||||
public void createColorFilters(final boolean hasKeyBorders) {
|
public void createColorFilters(final boolean hasKeyBorders) {
|
||||||
final int[][] states = new int[][] {
|
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}, // pressed
|
||||||
new int[] { -android.R.attr.state_pressed}, // not pressed
|
new int[] { -android.R.attr.state_pressed}, // not pressed
|
||||||
};
|
};
|
||||||
|
@ -89,11 +90,15 @@ public class Colors {
|
||||||
backgroundFilter = BlendModeColorFilterCompat.createBlendModeColorFilterCompat(background, BlendModeCompat.MODULATE);
|
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
|
// 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);
|
if (isDarkColor(background)) {
|
||||||
adjustedBackgroundStateList = new ColorStateList(states, new int[] { brightenOrDarken(adjustedBackground, true), adjustedBackground });
|
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);
|
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) {
|
if (hasKeyBorders) {
|
||||||
keyBackgroundFilter = BlendModeColorFilterCompat.createBlendModeColorFilterCompat(keyBackground, BlendModeCompat.MODULATE);
|
keyBackgroundFilter = BlendModeColorFilterCompat.createBlendModeColorFilterCompat(keyBackground, BlendModeCompat.MODULATE);
|
||||||
functionalKeyBackgroundFilter = BlendModeColorFilterCompat.createBlendModeColorFilterCompat(functionalKey, BlendModeCompat.MODULATE);
|
functionalKeyBackgroundFilter = BlendModeColorFilterCompat.createBlendModeColorFilterCompat(functionalKey, BlendModeCompat.MODULATE);
|
||||||
|
@ -123,27 +128,28 @@ public class Colors {
|
||||||
: null;
|
: null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isBrightColor(int color) {
|
public static boolean isBrightColor(final int color) {
|
||||||
if (android.R.color.transparent == color) {
|
if (android.R.color.transparent == color) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
// See http://www.nbdtech.com/Blog/archive/2008/04/27/Calculating-the-Perceived-Brightness-of-a-Color.aspx
|
return getBrightnessSquared(color) >= 210*210;
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// todo (later): what needs to be public?
|
private static boolean isDarkColor(final int color) {
|
||||||
public static boolean isDarkColor(int color) {
|
|
||||||
if (android.R.color.transparent == color) {
|
if (android.R.color.transparent == color) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
// See http://www.nbdtech.com/Blog/archive/2008/04/27/Calculating-the-Perceived-Brightness-of-a-Color.aspx
|
return getBrightnessSquared(color) < 50*50;
|
||||||
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);
|
private static int brighten(final int color) {
|
||||||
return brightnessSquared < 50*50;
|
// 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) {
|
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 if (isBrightColor(color)) return darken(color);
|
||||||
else return brighten(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) {
|
private static int getBrightnessSquared(final int color) {
|
||||||
return ColorUtils.blendARGB(color, Color.BLACK, 0.1f);
|
// 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);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -184,8 +184,10 @@ public final class SuggestionStripView extends RelativeLayout implements OnClick
|
||||||
|
|
||||||
final Colors colors = Settings.getInstance().getCurrent().mColors;
|
final Colors colors = Settings.getInstance().getCurrent().mColors;
|
||||||
if (colors.isCustom) {
|
if (colors.isCustom) {
|
||||||
mStripVisibilityGroup.mSuggestionStripView.getBackground().setColorFilter(colors.adjustedBackgroundFilter);
|
getBackground().setColorFilter(colors.backgroundFilter);
|
||||||
mClipboardKey.setColorFilter(colors.keyText);
|
mClipboardKey.setColorFilter(colors.keyText);
|
||||||
|
mVoiceKey.setColorFilter(colors.keyText);
|
||||||
|
mOtherKey.setColorFilter(colors.keyText);
|
||||||
} else mClipboardKey.clearColorFilter();
|
} else mClipboardKey.clearColorFilter();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2,5 +2,5 @@
|
||||||
|
|
||||||
<shape xmlns:android="http://schemas.android.com/apk/res/android"
|
<shape xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
android:shape="rectangle">
|
android:shape="rectangle">
|
||||||
<solid android:color="@color/keyboard_background_lxx_base" />
|
<solid android:color="@color/suggested_word_background_selected_lxx_base" />
|
||||||
</shape>
|
</shape>
|
|
@ -116,7 +116,7 @@
|
||||||
<color name="morekey_normal_lxx_base">@android:color/white</color>
|
<color name="morekey_normal_lxx_base">@android:color/white</color>
|
||||||
<color name="morekey_pressed_lxx_base">#F4F4F5</color>
|
<color name="morekey_pressed_lxx_base">#F4F4F5</color>
|
||||||
<color name="suggested_word_background_selected_lxx_base">#F4F4F5</color>
|
<color name="suggested_word_background_selected_lxx_base">#F4F4F5</color>
|
||||||
<color name="emoji_tab_page_indicator_background_lxx_base">#F4F4F5</color>
|
<color name="emoji_tab_page_indicator_background_lxx_base">@android:color/white</color>
|
||||||
|
|
||||||
<!-- Color resources for LXX_Base_Border theme.
|
<!-- Color resources for LXX_Base_Border theme.
|
||||||
15%:0x26 70%:0xB3 75%:0xC0 80%:0xCC 85%:0xD9 90%:0xE6 -->
|
15%:0x26 70%:0xB3 75%:0xC0 80%:0xCC 85%:0xD9 90%:0xE6 -->
|
||||||
|
@ -125,7 +125,7 @@
|
||||||
<color name="key_background_pressed_lxx_base_border">#F4F4F5</color>
|
<color name="key_background_pressed_lxx_base_border">#F4F4F5</color>
|
||||||
<color name="key_background_functional_lxx_base_border">@android:color/white</color>
|
<color name="key_background_functional_lxx_base_border">@android:color/white</color>
|
||||||
<color name="key_bottom_bevel_lxx_base">#A9ABAD</color>
|
<color name="key_bottom_bevel_lxx_base">#A9ABAD</color>
|
||||||
<color name="emoji_tab_page_indicator_background_lxx_base_border">#F4F4F5</color>
|
<color name="emoji_tab_page_indicator_background_lxx_base_border">@android:color/white</color>
|
||||||
|
|
||||||
<!-- Color resources for setup wizard and tutorial -->
|
<!-- Color resources for setup wizard and tutorial -->
|
||||||
<color name="setup_background">#FFEBEBEB</color>
|
<color name="setup_background">#FFEBEBEB</color>
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue