mirror of
https://github.com/Helium314/HeliBoard.git
synced 2025-05-20 17:00:30 +00:00
improve coloring of some key icons
This commit is contained in:
parent
7facfd07ef
commit
ac2564e50a
3 changed files with 38 additions and 17 deletions
|
@ -44,6 +44,7 @@ import org.dslul.openboard.inputmethod.latin.common.StringUtils;
|
|||
import org.dslul.openboard.inputmethod.latin.settings.Settings;
|
||||
import org.dslul.openboard.inputmethod.latin.settings.SettingsValues;
|
||||
import org.dslul.openboard.inputmethod.latin.suggestions.MoreSuggestionsView;
|
||||
import org.dslul.openboard.inputmethod.latin.utils.ColorUtils;
|
||||
import org.dslul.openboard.inputmethod.latin.utils.TypefaceUtils;
|
||||
|
||||
import java.util.HashSet;
|
||||
|
@ -548,9 +549,22 @@ public class KeyboardView extends View {
|
|||
iconY = (keyHeight - iconHeight) / 2; // Align vertically center.
|
||||
}
|
||||
final int iconX = (keyWidth - iconWidth) / 2; // Align horizontally center.
|
||||
if (mCustomTheme && key.getBackgroundType() != Key.BACKGROUND_TYPE_NORMAL && !key.isActionKey() && !key.isShift())
|
||||
// no color for shift (because of state indicator) and accent color keys (action and popup)
|
||||
icon.setColorFilter(keyTextColorFilter);
|
||||
if (mCustomTheme) {
|
||||
if (key.isActionKey()) {
|
||||
// the white icon may not have enough contrast, and can't be adjusted by the user
|
||||
if (ColorUtils.isBrightColor(Settings.getInstance().getCurrent().mCustomThemeColorAccent))
|
||||
icon.setColorFilter(Color.DKGRAY, PorterDuff.Mode.SRC_ATOP);
|
||||
else
|
||||
icon.clearColorFilter();
|
||||
} else if (key.isShift()) {
|
||||
if (keyboard.mId.mElementId == KeyboardId.ELEMENT_ALPHABET_MANUAL_SHIFTED || keyboard.mId.mElementId == KeyboardId.ELEMENT_ALPHABET_SHIFT_LOCKED)
|
||||
icon.setColorFilter(accentColorFilter);
|
||||
else
|
||||
icon.setColorFilter(keyTextColorFilter);
|
||||
} else if (key.getBackgroundType() != Key.BACKGROUND_TYPE_NORMAL) {
|
||||
icon.setColorFilter(keyTextColorFilter);
|
||||
}
|
||||
}
|
||||
drawIcon(canvas, icon, iconX, iconY, iconWidth, iconHeight);
|
||||
}
|
||||
|
||||
|
|
|
@ -25,7 +25,6 @@ import android.content.Intent;
|
|||
import android.content.IntentFilter;
|
||||
import android.content.res.Configuration;
|
||||
import android.content.res.Resources;
|
||||
import android.graphics.Color;
|
||||
import android.inputmethodservice.InputMethodService;
|
||||
import android.media.AudioManager;
|
||||
import android.os.Build;
|
||||
|
@ -102,6 +101,7 @@ import javax.annotation.Nonnull;
|
|||
import static org.dslul.openboard.inputmethod.latin.common.Constants.ImeOption.FORCE_ASCII;
|
||||
import static org.dslul.openboard.inputmethod.latin.common.Constants.ImeOption.NO_MICROPHONE;
|
||||
import static org.dslul.openboard.inputmethod.latin.common.Constants.ImeOption.NO_MICROPHONE_COMPAT;
|
||||
import static org.dslul.openboard.inputmethod.latin.utils.ColorUtils.isBrightColor;
|
||||
|
||||
/**
|
||||
* Input method implementation for Qwerty'ish keyboard.
|
||||
|
@ -2056,17 +2056,4 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
|
|||
view.setSystemUiVisibility(mOriginalNavBarFlags);
|
||||
}
|
||||
|
||||
private static boolean isBrightColor(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
|
||||
boolean bright = false;
|
||||
int[] rgb = {Color.red(color), Color.green(color), Color.blue(color)};
|
||||
int brightness = (int) Math.sqrt(rgb[0] * rgb[0] * .241 + rgb[1] * rgb[1] * .691 + rgb[2] * rgb[2] * .068);
|
||||
if (brightness >= 210) {
|
||||
bright = true;
|
||||
}
|
||||
return bright;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,20 @@
|
|||
package org.dslul.openboard.inputmethod.latin.utils;
|
||||
|
||||
import android.graphics.Color;
|
||||
|
||||
public class ColorUtils {
|
||||
public static boolean isBrightColor(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
|
||||
boolean bright = false;
|
||||
int[] rgb = {Color.red(color), Color.green(color), Color.blue(color)};
|
||||
int brightness = (int) Math.sqrt(rgb[0] * rgb[0] * .241 + rgb[1] * rgb[1] * .691 + rgb[2] * rgb[2] * .068);
|
||||
if (brightness >= 210) {
|
||||
bright = true;
|
||||
}
|
||||
return bright;
|
||||
}
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue