mirror of
https://github.com/Helium314/HeliBoard.git
synced 2025-04-26 09:36:50 +00:00
fix a bunch of minor issues with custom themes
This commit is contained in:
parent
3c060ddfa5
commit
6fafac914b
6 changed files with 141 additions and 57 deletions
|
@ -1108,7 +1108,7 @@ public class Key implements Comparable<Key> {
|
|||
@Nonnull final Drawable functionalKeyBackground,
|
||||
@Nonnull final Drawable spacebarBackground) {
|
||||
final Drawable background;
|
||||
if (mBackgroundType == BACKGROUND_TYPE_FUNCTIONAL || mBackgroundType == BACKGROUND_TYPE_STICKY_OFF || mBackgroundType == BACKGROUND_TYPE_STICKY_ON) {
|
||||
if (isFunctional()) {
|
||||
background = functionalKeyBackground;
|
||||
} else if (mBackgroundType == BACKGROUND_TYPE_SPACEBAR) {
|
||||
background = spacebarBackground;
|
||||
|
@ -1140,4 +1140,10 @@ public class Key implements Comparable<Key> {
|
|||
public boolean isPressed() {
|
||||
return mPressed;
|
||||
}
|
||||
|
||||
public boolean isFunctional() {
|
||||
return mBackgroundType == BACKGROUND_TYPE_FUNCTIONAL
|
||||
|| mBackgroundType == BACKGROUND_TYPE_STICKY_OFF
|
||||
|| mBackgroundType == BACKGROUND_TYPE_STICKY_ON;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -34,12 +34,11 @@ import android.view.View;
|
|||
|
||||
import org.dslul.openboard.inputmethod.keyboard.internal.KeyDrawParams;
|
||||
import org.dslul.openboard.inputmethod.keyboard.internal.KeyVisualAttributes;
|
||||
import org.dslul.openboard.inputmethod.keyboard.internal.KeyboardIconsSet;
|
||||
import org.dslul.openboard.inputmethod.latin.R;
|
||||
import org.dslul.openboard.inputmethod.latin.common.Colors;
|
||||
import org.dslul.openboard.inputmethod.latin.common.Constants;
|
||||
import org.dslul.openboard.inputmethod.latin.common.StringUtils;
|
||||
import org.dslul.openboard.inputmethod.latin.settings.Settings;
|
||||
import org.dslul.openboard.inputmethod.latin.suggestions.MoreSuggestionsView;
|
||||
import org.dslul.openboard.inputmethod.latin.utils.TypefaceUtils;
|
||||
|
||||
import java.util.HashSet;
|
||||
|
@ -172,11 +171,8 @@ public class KeyboardView extends View {
|
|||
mPaint.setAntiAlias(true);
|
||||
|
||||
mColors = Settings.getInstance().getCurrent().mColors;
|
||||
if (mColors.isCustom) {
|
||||
if (mColors.isCustom)
|
||||
getBackground().setColorFilter(mColors.backgroundFilter);
|
||||
mSpacebarBackground.setColorFilter(mColors.spaceBarFilter); // todo: consider pressed state
|
||||
mFunctionalKeyBackground.setColorFilter(mColors.functionalKeyBackgroundFilter); // todo: consider pressed state
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
|
@ -381,14 +377,8 @@ public class KeyboardView extends View {
|
|||
bgX = -padding.left;
|
||||
bgY = -padding.top;
|
||||
}
|
||||
if (mColors.isCustom) {
|
||||
// color filter is applied to background, which is re-used
|
||||
// action key and normal key share the same background drawable, so we need to select the correct color filter
|
||||
if (key.isActionKey())
|
||||
background.setColorFilter(mColors.accentColorFilter);
|
||||
else if (key.getBackgroundType() == Key.BACKGROUND_TYPE_NORMAL)
|
||||
background.setColorFilter(mColors.keyBackgroundFilter);
|
||||
}
|
||||
if (mColors.isCustom)
|
||||
setCustomKeyBackgroundColor(key, getKeyboard(), background);
|
||||
background.setBounds(0, 0, bgWidth, bgHeight);
|
||||
canvas.translate(bgX, bgY);
|
||||
background.draw(canvas);
|
||||
|
@ -440,18 +430,10 @@ public class KeyboardView extends View {
|
|||
}
|
||||
|
||||
if (key.isEnabled()) {
|
||||
paint.setColor(key.selectTextColor(params));
|
||||
if (mColors.isCustom) {
|
||||
// set key color only if not in emoji keyboard range
|
||||
if (keyboard != null
|
||||
&& (this.getClass() == MoreSuggestionsView.class
|
||||
? !StringUtils.probablyContainsEmoji(key.getLabel()) // doesn't contain emoji (MoreSuggestionsView can have letters and emojis)
|
||||
: (keyboard.mId.mElementId < 10 || keyboard.mId.mElementId > 26) // not showing emoji keyboard (no emojis visible on main keyboard otherwise)
|
||||
))
|
||||
paint.setColorFilter(mColors.keyTextFilter);
|
||||
else
|
||||
paint.setColorFilter(null);
|
||||
}
|
||||
if (mColors.isCustom)
|
||||
paint.setColor(mColors.keyText);
|
||||
else
|
||||
paint.setColor(key.selectTextColor(params));
|
||||
// Set a drop shadow for the text if the shadow radius is positive value.
|
||||
if (mKeyTextShadowRadius > 0.0f) {
|
||||
paint.setShadowLayer(mKeyTextShadowRadius, 0.0f, 0.0f, params.mTextShadowColor);
|
||||
|
@ -474,9 +456,10 @@ public class KeyboardView extends View {
|
|||
final String hintLabel = key.getHintLabel();
|
||||
if (hintLabel != null && mShowsHints) {
|
||||
paint.setTextSize(key.selectHintTextSize(params));
|
||||
paint.setColor(key.selectHintTextColor(params));
|
||||
if (mColors.isCustom)
|
||||
paint.setColorFilter(mColors.keyHintTextFilter);
|
||||
paint.setColor(mColors.keyHintText);
|
||||
else
|
||||
paint.setColor(key.selectHintTextColor(params));
|
||||
// TODO: Should add a way to specify type face for hint letters
|
||||
paint.setTypeface(Typeface.DEFAULT_BOLD);
|
||||
blendAlpha(paint, params.mAnimAlpha);
|
||||
|
@ -529,23 +512,10 @@ public class KeyboardView extends View {
|
|||
iconY = (keyHeight - iconHeight) / 2; // Align vertically center.
|
||||
}
|
||||
final int iconX = (keyWidth - iconWidth) / 2; // Align horizontally center.
|
||||
if (mColors.isCustom) {
|
||||
if (key.isActionKey()) {
|
||||
// the white icon may not have enough contrast, and can't be adjusted by the user
|
||||
icon.setColorFilter(mColors.actionKeyIconColorFilter);
|
||||
} else if (key.isShift()) {
|
||||
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);
|
||||
else
|
||||
icon.setColorFilter(mColors.keyTextFilter);
|
||||
} else if (key.getBackgroundType() != Key.BACKGROUND_TYPE_NORMAL) {
|
||||
icon.setColorFilter(mColors.keyTextFilter);
|
||||
}
|
||||
}
|
||||
if (mColors.isCustom)
|
||||
setCustomKeyIconColor(key, icon, keyboard);
|
||||
else
|
||||
icon.clearColorFilter();
|
||||
drawIcon(canvas, icon, iconX, iconY, iconWidth, iconHeight);
|
||||
}
|
||||
|
||||
|
@ -633,4 +603,70 @@ public class KeyboardView extends View {
|
|||
public void deallocateMemory() {
|
||||
freeOffscreenBuffer();
|
||||
}
|
||||
|
||||
private void setCustomKeyIconColor(Key key, Drawable icon, Keyboard keyboard) {
|
||||
if (isAccentColoredKey(key)) {
|
||||
icon.setColorFilter(mColors.actionKeyIconColorFilter);
|
||||
} else if (key.isShift() && keyboard != null) {
|
||||
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
|
||||
else
|
||||
icon.setColorFilter(mColors.keyTextFilter); // key text if not shifted
|
||||
} else if (key.getBackgroundType() != Key.BACKGROUND_TYPE_NORMAL) {
|
||||
icon.setColorFilter(mColors.keyTextFilter);
|
||||
} else if (this.getClass() == MoreKeysKeyboardView.class) {
|
||||
// set color filter for long press comma key, should not trigger anywhere else
|
||||
icon.setColorFilter(mColors.keyTextFilter);
|
||||
}
|
||||
}
|
||||
|
||||
private void setCustomKeyBackgroundColor(Key key, Keyboard keyboard, Drawable background) {
|
||||
// color filter is applied to background, which is re-used
|
||||
// action key and normal key share the same background drawable, so we need to select the correct color filter
|
||||
if (isAccentColoredKey(key)) { // action key and its popup keys
|
||||
if (key.isPressed())
|
||||
background.setColorFilter(mColors.accentPressedColorFilter);
|
||||
else
|
||||
background.setColorFilter(mColors.accentColorFilter);
|
||||
} else if (key.getBackgroundType() == Key.BACKGROUND_TYPE_SPACEBAR) { // space
|
||||
if (key.isPressed())
|
||||
background.setColorFilter(mColors.spaceBarPressedFilter);
|
||||
else
|
||||
background.setColorFilter(mColors.spaceBarFilter);
|
||||
} else if (key.isFunctional()) { // shift, 123, delete,...
|
||||
if (key.isPressed())
|
||||
background.setColorFilter(mColors.functionalKeyPressedBackgroundFilter);
|
||||
else
|
||||
background.setColorFilter(mColors.functionalKeyBackgroundFilter);
|
||||
} else if (this.getClass() == MoreKeysKeyboardView.class) { // more keys popup (except on action key, which is handled above)
|
||||
if (key.isPressed())
|
||||
background.setColorFilter(mColors.backgroundPressedFilter);
|
||||
else
|
||||
background.setColorFilter(mColors.backgroundFilter);
|
||||
} else if (key.getBackgroundType() == Key.BACKGROUND_TYPE_NORMAL) { // normal keys
|
||||
if (key.isPressed())
|
||||
background.setColorFilter(mColors.keyPressedBackgroundFilter);
|
||||
else
|
||||
background.setColorFilter(mColors.keyBackgroundFilter);
|
||||
} else if (keyboard.mId.mElementId >= 10 && keyboard.mId.mElementId <= 26) { // emoji keyboard keys
|
||||
if (key.isPressed())
|
||||
background.setColorFilter(mColors.backgroundPressedFilter);
|
||||
else
|
||||
background.setColorFilter(mColors.backgroundFilter);
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isAccentColoredKey(Key key) {
|
||||
if (key.isActionKey()) return true;
|
||||
if (this.getClass() != MoreKeysKeyboardView.class) return false;
|
||||
final String iconName = KeyboardIconsSet.getIconName(key.getIconId());
|
||||
return iconName.equals(KeyboardIconsSet.NAME_NEXT_KEY)
|
||||
|| iconName.equals(KeyboardIconsSet.NAME_CLIPBOARD_ACTION_KEY)
|
||||
|| iconName.equals(KeyboardIconsSet.NAME_EMOJI_ACTION_KEY);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -13,6 +13,7 @@ import androidx.recyclerview.widget.RecyclerView
|
|||
import org.dslul.openboard.inputmethod.latin.ClipboardHistoryEntry
|
||||
import org.dslul.openboard.inputmethod.latin.ClipboardHistoryManager
|
||||
import org.dslul.openboard.inputmethod.latin.R
|
||||
import org.dslul.openboard.inputmethod.latin.settings.Settings
|
||||
|
||||
class ClipboardAdapter(
|
||||
val clipboardLayoutParams: ClipboardLayoutParams,
|
||||
|
@ -77,8 +78,11 @@ class ClipboardAdapter(
|
|||
|
||||
override fun onTouch(view: View, event: MotionEvent): Boolean {
|
||||
if (event.actionMasked != MotionEvent.ACTION_DOWN) {
|
||||
if (event.actionMasked == MotionEvent.ACTION_UP)
|
||||
view.background.colorFilter = Settings.getInstance().current.mColors.keyBackgroundFilter
|
||||
return false
|
||||
}
|
||||
view.background.colorFilter = Settings.getInstance().current.mColors.keyPressedBackgroundFilter
|
||||
keyEventListener.onKeyDown(view.tag as Long)
|
||||
return false
|
||||
}
|
||||
|
|
|
@ -183,12 +183,18 @@ class ClipboardHistoryView @JvmOverloads constructor(
|
|||
|
||||
override fun onTouch(view: View, event: MotionEvent): Boolean {
|
||||
if (event.actionMasked != MotionEvent.ACTION_DOWN) {
|
||||
if (view == alphabetKey && event.actionMasked != MotionEvent.ACTION_UP)
|
||||
alphabetKey.background.colorFilter = Settings.getInstance().current.mColors.functionalKeyBackgroundFilter
|
||||
|
||||
return false
|
||||
}
|
||||
when (view) {
|
||||
alphabetKey -> keyboardActionListener?.onPressKey(
|
||||
alphabetKey -> {
|
||||
alphabetKey.background.colorFilter = Settings.getInstance().current.mColors.functionalKeyPressedBackgroundFilter
|
||||
keyboardActionListener?.onPressKey(
|
||||
Constants.CODE_ALPHA_FROM_CLIPBOARD, 0 /* repeatCount */,
|
||||
true /* isSinglePointer */)
|
||||
}
|
||||
clearKey -> keyboardActionListener?.onPressKey(
|
||||
Constants.CODE_UNSPECIFIED, 0 /* repeatCount */,
|
||||
true /* isSinglePointer */)
|
||||
|
|
|
@ -55,6 +55,9 @@ import org.dslul.openboard.inputmethod.latin.utils.ResourceUtils;
|
|||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import static org.dslul.openboard.inputmethod.latin.common.Constants.CODE_ALPHA_FROM_EMOJI;
|
||||
import static org.dslul.openboard.inputmethod.latin.common.Constants.CODE_DELETE;
|
||||
import static org.dslul.openboard.inputmethod.latin.common.Constants.CODE_SPACE;
|
||||
import static org.dslul.openboard.inputmethod.latin.common.Constants.NOT_A_COORDINATE;
|
||||
|
||||
/**
|
||||
|
@ -317,7 +320,20 @@ public final class EmojiPalettesView extends LinearLayout
|
|||
*/
|
||||
@Override
|
||||
public boolean onTouch(final View v, final MotionEvent event) {
|
||||
if (event.getActionMasked() != MotionEvent.ACTION_DOWN) {
|
||||
final int eventCode = event.getActionMasked();
|
||||
if (eventCode != MotionEvent.ACTION_DOWN) {
|
||||
if (eventCode == MotionEvent.ACTION_UP) {
|
||||
final Object tag = v.getTag();
|
||||
if (!(tag instanceof Integer))
|
||||
return false;
|
||||
final int code = (Integer) tag;
|
||||
if (code == CODE_SPACE)
|
||||
v.getBackground().setColorFilter(Settings.getInstance().getCurrent().mColors.spaceBarFilter);
|
||||
else if (code == CODE_DELETE)
|
||||
v.getBackground().setColorFilter(Settings.getInstance().getCurrent().mColors.functionalKeyBackgroundFilter);
|
||||
else if (code == CODE_ALPHA_FROM_EMOJI)
|
||||
v.getBackground().setColorFilter(Settings.getInstance().getCurrent().mColors.functionalKeyBackgroundFilter);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
final Object tag = v.getTag();
|
||||
|
@ -325,6 +341,12 @@ public final class EmojiPalettesView extends LinearLayout
|
|||
return false;
|
||||
}
|
||||
final int code = (Integer) tag;
|
||||
if (code == CODE_SPACE)
|
||||
v.getBackground().setColorFilter(Settings.getInstance().getCurrent().mColors.spaceBarPressedFilter);
|
||||
else if (code == CODE_DELETE)
|
||||
v.getBackground().setColorFilter(Settings.getInstance().getCurrent().mColors.functionalKeyPressedBackgroundFilter);
|
||||
else if (code == CODE_ALPHA_FROM_EMOJI)
|
||||
v.getBackground().setColorFilter(Settings.getInstance().getCurrent().mColors.functionalKeyPressedBackgroundFilter);
|
||||
mKeyboardActionListener.onPressKey(
|
||||
code, 0 /* repeatCount */, true /* isSinglePointer */);
|
||||
// It's important to return false here. Otherwise, {@link #onClick} and touch-down visual
|
||||
|
|
|
@ -6,9 +6,9 @@ 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;
|
||||
import org.dslul.openboard.inputmethod.latin.settings.Settings;
|
||||
|
||||
public class Colors {
|
||||
|
||||
|
@ -22,6 +22,7 @@ public class Colors {
|
|||
public final int keyText;
|
||||
public final int keyHintText;
|
||||
public ColorFilter backgroundFilter;
|
||||
public ColorFilter backgroundPressedFilter;
|
||||
public ColorFilter keyBackgroundFilter;
|
||||
public ColorFilter keyPressedBackgroundFilter;
|
||||
public ColorFilter functionalKeyBackgroundFilter;
|
||||
|
@ -31,6 +32,7 @@ public class Colors {
|
|||
public ColorFilter keyTextFilter; // todo: really necessary?
|
||||
public ColorFilter keyHintTextFilter; // todo: really? color alone should be sufficient i think... test!
|
||||
public ColorFilter accentColorFilter; // todo: really necessary?
|
||||
public ColorFilter accentPressedColorFilter;
|
||||
public ColorFilter actionKeyIconColorFilter;
|
||||
|
||||
public Colors(int acc, int bg, int k, int fun, int space, int kt, int kht) {
|
||||
|
@ -73,33 +75,41 @@ public class Colors {
|
|||
|
||||
public void createColorFilters(final boolean hasKeyBorders) {
|
||||
backgroundFilter = BlendModeColorFilterCompat.createBlendModeColorFilterCompat(background, BlendModeCompat.MODULATE);
|
||||
backgroundPressedFilter = isDarkColor(background)
|
||||
// todo: below is not working, but why?
|
||||
// ? BlendModeColorFilterCompat.createBlendModeColorFilterCompat(ColorUtils.blendARGB(background, Color.WHITE, 0.1f), BlendModeCompat.MODULATE)
|
||||
? BlendModeColorFilterCompat.createBlendModeColorFilterCompat(background, BlendModeCompat.SCREEN)
|
||||
: backgroundFilter;
|
||||
if (hasKeyBorders) {
|
||||
keyBackgroundFilter = BlendModeColorFilterCompat.createBlendModeColorFilterCompat(keyBackground, BlendModeCompat.MODULATE);
|
||||
functionalKeyBackgroundFilter = BlendModeColorFilterCompat.createBlendModeColorFilterCompat(functionalKey, BlendModeCompat.MODULATE);
|
||||
spaceBarFilter = BlendModeColorFilterCompat.createBlendModeColorFilterCompat(spaceBar, BlendModeCompat.MODULATE);
|
||||
keyPressedBackgroundFilter = isDarkColor(keyBackground)
|
||||
? BlendModeColorFilterCompat.createBlendModeColorFilterCompat(keyBackground, BlendModeCompat.SCREEN)
|
||||
? BlendModeColorFilterCompat.createBlendModeColorFilterCompat(ColorUtils.blendARGB(keyBackground, Color.WHITE, 0.1f), BlendModeCompat.MODULATE)
|
||||
: keyBackgroundFilter;
|
||||
functionalKeyPressedBackgroundFilter = isDarkColor(functionalKey)
|
||||
? BlendModeColorFilterCompat.createBlendModeColorFilterCompat(functionalKey, BlendModeCompat.SCREEN)
|
||||
? BlendModeColorFilterCompat.createBlendModeColorFilterCompat(ColorUtils.blendARGB(functionalKey, Color.WHITE, 0.1f), BlendModeCompat.MODULATE)
|
||||
: functionalKeyBackgroundFilter;
|
||||
spaceBarPressedFilter = isDarkColor(spaceBar)
|
||||
? BlendModeColorFilterCompat.createBlendModeColorFilterCompat(spaceBar, BlendModeCompat.SCREEN)
|
||||
? BlendModeColorFilterCompat.createBlendModeColorFilterCompat(ColorUtils.blendARGB(spaceBar, Color.WHITE, 0.1f), BlendModeCompat.MODULATE)
|
||||
: spaceBarFilter;
|
||||
} else {
|
||||
// need to set color to background if key borders are disabled, or there will be ugly keys
|
||||
keyBackgroundFilter = backgroundFilter;
|
||||
functionalKeyBackgroundFilter = backgroundFilter;
|
||||
spaceBarFilter = backgroundFilter;
|
||||
keyPressedBackgroundFilter = isDarkColor(background)
|
||||
? BlendModeColorFilterCompat.createBlendModeColorFilterCompat(background, BlendModeCompat.SCREEN)
|
||||
: keyBackgroundFilter;
|
||||
functionalKeyBackgroundFilter = keyBackgroundFilter;
|
||||
spaceBarFilter = keyBackgroundFilter;
|
||||
keyPressedBackgroundFilter = backgroundPressedFilter;
|
||||
functionalKeyPressedBackgroundFilter = keyBackgroundFilter;
|
||||
spaceBarPressedFilter = keyBackgroundFilter;
|
||||
}
|
||||
// todo: some of these should be modulate (once the base theme is done)
|
||||
// especially the accent pressed filter should use modulate/screen
|
||||
keyTextFilter = BlendModeColorFilterCompat.createBlendModeColorFilterCompat(keyText, BlendModeCompat.SRC_ATOP);
|
||||
keyHintTextFilter = BlendModeColorFilterCompat.createBlendModeColorFilterCompat(keyHintText, BlendModeCompat.SRC_ATOP);
|
||||
accentColorFilter = BlendModeColorFilterCompat.createBlendModeColorFilterCompat(accent, BlendModeCompat.SRC_ATOP);
|
||||
accentPressedColorFilter = isDarkColor(accent)
|
||||
? BlendModeColorFilterCompat.createBlendModeColorFilterCompat(ColorUtils.blendARGB(accent, Color.WHITE, 0.1f), BlendModeCompat.SRC_ATOP)
|
||||
: BlendModeColorFilterCompat.createBlendModeColorFilterCompat(ColorUtils.blendARGB(accent, Color.BLACK, 0.1f), BlendModeCompat.SRC_ATOP);
|
||||
actionKeyIconColorFilter = isBrightColor(accent) // the white icon may not have enough contrast, and can't be adjusted by the user
|
||||
? BlendModeColorFilterCompat.createBlendModeColorFilterCompat(Color.DKGRAY, BlendModeCompat.SRC_ATOP)
|
||||
: null;
|
||||
|
|
Loading…
Add table
Reference in a new issue