convert Colors to kotlin, move some theme-dependent logic inside colors

This commit is contained in:
Helium314 2023-09-06 12:15:22 +02:00
parent a0d37dc3ab
commit efffc02fed
21 changed files with 254 additions and 312 deletions

View file

@ -567,9 +567,6 @@ public final class KeyboardSwitcher implements KeyboardState.SwitchActions {
isHardwareAcceleratedDrawingEnabled);
mClipboardHistoryView.setKeyboardActionListener(mLatinIME);
// set background color here, otherwise there is a narrow white line between keyboard and suggestion strip
mKeyboardViewWrapper.getBackground().setColorFilter(Settings.getInstance().getCurrent().mColors.backgroundFilter);
return mCurrentInputView;
}

View file

@ -214,6 +214,7 @@ public final class KeyboardTheme implements Comparable<KeyboardTheme> {
// todo (later): material you, system accent, ...
public static Colors getThemeColors(final String themeColors, final String themeStyle, final Context context, final SharedPreferences prefs) {
final boolean hasBorders = prefs.getBoolean(Settings.PREF_THEME_KEY_BORDERS, false);
switch (themeColors) {
case THEME_USER:
final int accent = prefs.getInt(Settings.PREF_THEME_USER_COLOR_ACCENT, Color.BLUE);
@ -221,17 +222,18 @@ public final class KeyboardTheme implements Comparable<KeyboardTheme> {
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 Colors.newColors(themeStyle, accent, background, keyBgColor, ColorUtilKt.brightenOrDarken(keyBgColor, true), keyBgColor, keyTextColor, hintTextColor);
return new Colors(themeStyle, hasBorders, accent, background, keyBgColor, ColorUtilKt.brightenOrDarken(keyBgColor, true), keyBgColor, keyTextColor, hintTextColor);
case THEME_USER_DARK:
final int accent2 = prefs.getInt(Settings.PREF_THEME_USER_DARK_COLOR_ACCENT, Color.BLUE);
final int keyBgColor2 = prefs.getInt(Settings.PREF_THEME_USER_DARK_COLOR_KEYS, Color.LTGRAY);
final int keyTextColor2 = prefs.getInt(Settings.PREF_THEME_USER_DARK_COLOR_TEXT, Color.WHITE);
final int hintTextColor2 = prefs.getInt(Settings.PREF_THEME_USER_DARK_COLOR_HINT_TEXT, Color.WHITE);
final int background2 = prefs.getInt(Settings.PREF_THEME_USER_DARK_COLOR_BACKGROUND, Color.DKGRAY);
return Colors.newColors(themeStyle, accent2, background2, keyBgColor2, ColorUtilKt.brightenOrDarken(keyBgColor2, true), keyBgColor2, keyTextColor2, hintTextColor2);
return new Colors(themeStyle, hasBorders, accent2, background2, keyBgColor2, ColorUtilKt.brightenOrDarken(keyBgColor2, true), keyBgColor2, keyTextColor2, hintTextColor2);
case THEME_DARK:
return Colors.newColors(
return new Colors(
themeStyle,
hasBorders,
ContextCompat.getColor(context, R.color.gesture_trail_color_lxx_dark),
// colors taken from the drawable
Color.parseColor("#263238"),
@ -242,8 +244,9 @@ public final class KeyboardTheme implements Comparable<KeyboardTheme> {
ContextCompat.getColor(context, R.color.key_hint_letter_color_lxx_dark)
);
case THEME_HOLO_WHITE:
return Colors.newColors(
return new Colors(
themeStyle,
hasBorders,
Color.parseColor("#FFFFFF"),
// colors taken from the drawable
Color.parseColor("#282828"),
@ -254,8 +257,9 @@ public final class KeyboardTheme implements Comparable<KeyboardTheme> {
Color.parseColor("#282828")
);
case THEME_DARKER:
return Colors.newColors(
return new Colors(
themeStyle,
hasBorders,
ContextCompat.getColor(context, R.color.gesture_trail_color_lxx_dark),
ContextCompat.getColor(context, R.color.keyboard_background_lxx_dark_border),
ContextCompat.getColor(context, R.color.key_background_normal_lxx_dark_border),
@ -265,8 +269,9 @@ public final class KeyboardTheme implements Comparable<KeyboardTheme> {
ContextCompat.getColor(context, R.color.key_hint_letter_color_lxx_dark)
);
case THEME_BLACK:
return Colors.newColors(
return new Colors(
themeStyle,
hasBorders,
ContextCompat.getColor(context, R.color.gesture_trail_color_lxx_dark),
ContextCompat.getColor(context, R.color.background_amoled_black),
ContextCompat.getColor(context, R.color.background_amoled_dark),
@ -277,8 +282,9 @@ public final class KeyboardTheme implements Comparable<KeyboardTheme> {
);
case THEME_LIGHT:
default:
return Colors.newColors(
return new Colors(
themeStyle,
hasBorders,
ContextCompat.getColor(context, R.color.gesture_trail_color_lxx_light),
ContextCompat.getColor(context, R.color.keyboard_background_lxx_light_border),
ContextCompat.getColor(context, R.color.key_background_normal_lxx_light_border),

View file

@ -39,9 +39,9 @@ import org.dslul.openboard.inputmethod.keyboard.emoji.EmojiPageKeyboardView;
import org.dslul.openboard.inputmethod.keyboard.internal.KeyDrawParams;
import org.dslul.openboard.inputmethod.keyboard.internal.KeyVisualAttributes;
import org.dslul.openboard.inputmethod.latin.R;
import org.dslul.openboard.inputmethod.latin.common.BackgroundType;
import org.dslul.openboard.inputmethod.latin.common.Colors;
import org.dslul.openboard.inputmethod.latin.common.Constants;
import org.dslul.openboard.inputmethod.latin.common.HoloColors;
import org.dslul.openboard.inputmethod.latin.settings.Settings;
import org.dslul.openboard.inputmethod.latin.suggestions.MoreSuggestionsView;
import org.dslul.openboard.inputmethod.latin.utils.TypefaceUtils;
@ -141,20 +141,19 @@ public class KeyboardView extends View {
final TypedArray keyboardViewAttr = context.obtainStyledAttributes(attrs,
R.styleable.KeyboardView, defStyle, R.style.KeyboardView);
mKeyBackground = keyboardViewAttr.getDrawable(R.styleable.KeyboardView_keyBackground).mutate();
mKeyBackground.getPadding(mKeyBackgroundPadding);
final Drawable functionalKeyBackground = keyboardViewAttr.getDrawable(
R.styleable.KeyboardView_functionalKeyBackground);
mFunctionalKeyBackground = (functionalKeyBackground != null) ? functionalKeyBackground.mutate()
: keyboardViewAttr.getDrawable(R.styleable.KeyboardView_keyBackground).mutate();
final Drawable spacebarBackground = keyboardViewAttr.getDrawable(
R.styleable.KeyboardView_spacebarBackground);
mSpacebarBackground = (spacebarBackground != null) ? spacebarBackground.mutate()
: keyboardViewAttr.getDrawable(R.styleable.KeyboardView_keyBackground).mutate();
if (mColors instanceof HoloColors) // todo: this logic should be in Colors, not here
mActionKeyBackground = mFunctionalKeyBackground;
if (this instanceof EmojiPageKeyboardView || this instanceof MoreSuggestionsView)
mKeyBackground = mColors.getDrawable(BackgroundType.BACKGROUND, keyboardViewAttr);
else if (this instanceof MoreKeysKeyboardView)
mKeyBackground = mColors.getDrawable(BackgroundType.ADJUSTED_BACKGROUND, keyboardViewAttr);
else
mActionKeyBackground = keyboardViewAttr.getDrawable(R.styleable.KeyboardView_keyBackground).mutate();
mKeyBackground = mColors.getDrawable(BackgroundType.KEY, keyboardViewAttr);
mKeyBackground.getPadding(mKeyBackgroundPadding);
mFunctionalKeyBackground = mColors.getDrawable(BackgroundType.FUNCTIONAL, keyboardViewAttr);
mSpacebarBackground = mColors.getDrawable(BackgroundType.SPACE, keyboardViewAttr);
if (this instanceof MoreKeysKeyboardView && mColors.getThemeStyle().equals(KeyboardTheme.THEME_STYLE_HOLO)) // todo: this logic should be in Colors
mActionKeyBackground = mColors.getDrawable(BackgroundType.ADJUSTED_BACKGROUND, keyboardViewAttr);
else
mActionKeyBackground = mColors.getDrawable(BackgroundType.ACTION, keyboardViewAttr);
mSpacebarIconWidthRatio = keyboardViewAttr.getFloat(
R.styleable.KeyboardView_spacebarIconWidthRatio, 1.0f);
@ -179,31 +178,7 @@ public class KeyboardView extends View {
keyAttr.recycle();
mPaint.setAntiAlias(true);
if (this instanceof EmojiPageKeyboardView || this instanceof MoreSuggestionsView) {
mColors.setBackgroundColor(mKeyBackground, Colors.TYPE_BACKGROUND);
} else if (this instanceof MoreKeysKeyboardView) {
mColors.setBackgroundColor(mKeyBackground, Colors.TYPE_ADJUSTED_BACKGROUND);
} else {
mColors.setBackgroundColor(mKeyBackground, Colors.TYPE_KEY);
}
mColors.setBackgroundColor(mActionKeyBackground, Colors.TYPE_ACTION);
mColors.setBackgroundColor(mSpacebarBackground, Colors.TYPE_SPACE);
if (this instanceof MoreKeysKeyboardView)
mColors.setBackgroundColor(mFunctionalKeyBackground, Colors.TYPE_ADJUSTED_BACKGROUND);
else
mColors.setBackgroundColor(mFunctionalKeyBackground, Colors.TYPE_FUNCTIONAL);
if (this.getClass() == MoreKeysKeyboardView.class)
getBackground().setColorFilter(mColors.adjustedBackgroundFilter);
else {
// todo: this should only be applied to specific keyboards, check original version for which one
// and actually this again is something that maybe should be done in Colors
final Drawable keyboardBackground = mColors.getKeyboardBackground();
if (!(this instanceof MoreSuggestionsView) && keyboardBackground != null)
setBackground(keyboardBackground);
else
getBackground().setColorFilter(mColors.backgroundFilter);
}
mColors.setKeyboardBackground(this);
}
@Nullable
@ -623,8 +598,8 @@ public class KeyboardView extends View {
}
private void setKeyIconColor(Key key, Drawable icon, Keyboard keyboard) {
if (key.isAccentColored() && !(mColors instanceof HoloColors)) { // todo: this logic should not be here
icon.setColorFilter(mColors.actionKeyIconColorFilter);
if (key.isAccentColored() && !(mColors.getThemeStyle().equals(KeyboardTheme.THEME_STYLE_HOLO))) { // todo: this logic should not be here
icon.setColorFilter(mColors.getActionKeyIconColorFilter());
} 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
@ -633,14 +608,14 @@ public class KeyboardView extends View {
|| keyboard.mId.mElementId == KeyboardId.ELEMENT_ALPHABET_AUTOMATIC_SHIFTED
|| keyboard.mId.mElementId == KeyboardId.ELEMENT_ALPHABET_SHIFT_LOCK_SHIFTED
)
icon.setColorFilter(mColors.accent, PorterDuff.Mode.SRC_ATOP); // accent if shifted, needs SRC_ATOP because of underlying drawable
icon.setColorFilter(mColors.getAccent(), PorterDuff.Mode.SRC_ATOP); // accent if shifted, needs SRC_ATOP because of underlying drawable
else
icon.setColorFilter(mColors.keyTextFilter); // key text if not shifted
icon.setColorFilter(mColors.getKeyTextFilter()); // key text if not shifted
} else if (key.getBackgroundType() != Key.BACKGROUND_TYPE_NORMAL) {
icon.setColorFilter(mColors.keyTextFilter);
icon.setColorFilter(mColors.getKeyTextFilter());
} else if (this instanceof MoreKeysKeyboardView) {
// set color filter for long press comma key, should not trigger anywhere else
icon.setColorFilter(mColors.keyTextFilter);
icon.setColorFilter(mColors.getKeyTextFilter());
}
}

View file

@ -58,7 +58,6 @@ import org.dslul.openboard.inputmethod.latin.SuggestedWords;
import org.dslul.openboard.inputmethod.latin.common.Colors;
import org.dslul.openboard.inputmethod.latin.common.Constants;
import org.dslul.openboard.inputmethod.latin.common.CoordinateUtils;
import org.dslul.openboard.inputmethod.latin.common.HoloColors;
import org.dslul.openboard.inputmethod.latin.settings.DebugSettings;
import org.dslul.openboard.inputmethod.latin.settings.Settings;
import org.dslul.openboard.inputmethod.latin.utils.DeviceProtectedUtils;
@ -219,10 +218,10 @@ public final class MainKeyboardView extends KeyboardView implements DrawingProxy
mLanguageOnSpacebarTextRatio = mainKeyboardViewAttr.getFraction(
R.styleable.MainKeyboardView_languageOnSpacebarTextRatio, 1, 1, 1.0f);
final Colors colors = Settings.getInstance().getCurrent().mColors;
if (colors instanceof HoloColors) // todo: this logic should be in Colors
mLanguageOnSpacebarTextColor = colors.keyText;
if (colors.getThemeStyle().equals(KeyboardTheme.THEME_STYLE_HOLO)) // todo: this logic should be in Colors
mLanguageOnSpacebarTextColor = colors.getKeyText();
else
mLanguageOnSpacebarTextColor = colors.keyHintText; //mainKeyboardViewAttr.getColor(R.styleable.MainKeyboardView_languageOnSpacebarTextColor, 0);
mLanguageOnSpacebarTextColor = colors.getKeyHintText(); //mainKeyboardViewAttr.getColor(R.styleable.MainKeyboardView_languageOnSpacebarTextColor, 0);
mLanguageOnSpacebarTextShadowRadius = mainKeyboardViewAttr.getFloat(
R.styleable.MainKeyboardView_languageOnSpacebarTextShadowRadius,
LANGUAGE_ON_SPACEBAR_TEXT_SHADOW_RADIUS_DISABLED);

View file

@ -9,11 +9,11 @@ import android.view.ViewGroup
import android.widget.ImageView
import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView
import org.dslul.openboard.inputmethod.keyboard.KeyboardTheme
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.common.Colors
import org.dslul.openboard.inputmethod.latin.common.HoloColors
import org.dslul.openboard.inputmethod.latin.common.BackgroundType
import org.dslul.openboard.inputmethod.latin.settings.Settings
class ClipboardAdapter(
@ -56,7 +56,7 @@ class ClipboardAdapter(
setOnTouchListener(this@ViewHolder)
setOnLongClickListener(this@ViewHolder)
setBackgroundResource(itemBackgroundId)
Settings.getInstance().current.mColors.setBackgroundColor(background, Colors.TYPE_KEY)
Settings.getInstance().current.mColors.setBackgroundColor(background, BackgroundType.KEY)
}
pinnedIconView = view.findViewById<ImageView>(R.id.clipboard_entry_pinned_icon).apply {
visibility = View.GONE
@ -69,7 +69,7 @@ class ClipboardAdapter(
}
clipboardLayoutParams.setItemProperties(view)
val colors = Settings.getInstance().current.mColors
if (colors is HoloColors) // todo: this logic should be in Colors, not here
if (colors.themeStyle == KeyboardTheme.THEME_STYLE_HOLO) // todo: this logic should be in Colors, not here
pinnedIconView.colorFilter = colors.accentColorFilter
}

View file

@ -63,7 +63,7 @@ class ClipboardHistoryRecyclerView @JvmOverloads constructor(
init {
paint.color = dividerColor
paint.strokeWidth = dividerHeight.toFloat()
paint.colorFilter = Settings.getInstance().current.mColors.backgroundFilter
paint.colorFilter = Settings.getInstance().current.mColors.getThatBackgroundFilter()
}
override fun onDrawOver(canvas: Canvas, parent: RecyclerView, state: State) {

View file

@ -1,6 +1,7 @@
package org.dslul.openboard.inputmethod.keyboard.clipboard
import android.content.Context
import android.graphics.Color
import android.util.AttributeSet
import android.util.TypedValue
import android.view.MotionEvent
@ -16,7 +17,7 @@ import org.dslul.openboard.inputmethod.keyboard.internal.KeyVisualAttributes
import org.dslul.openboard.inputmethod.keyboard.internal.KeyboardIconsSet
import org.dslul.openboard.inputmethod.latin.ClipboardHistoryManager
import org.dslul.openboard.inputmethod.latin.R
import org.dslul.openboard.inputmethod.latin.common.Colors
import org.dslul.openboard.inputmethod.latin.common.BackgroundType
import org.dslul.openboard.inputmethod.latin.common.Constants
import org.dslul.openboard.inputmethod.latin.settings.Settings
import org.dslul.openboard.inputmethod.latin.utils.ResourceUtils
@ -48,8 +49,8 @@ class ClipboardHistoryView @JvmOverloads constructor(
R.styleable.ClipboardHistoryView, defStyle, R.style.ClipboardHistoryView)
pinIconId = clipboardViewAttr.getResourceId(
R.styleable.ClipboardHistoryView_iconPinnedClip, 0)
dividerColor = clipboardViewAttr.getColor(
R.styleable.ClipboardHistoryView_dividerBackground, 0)
// todo: remove the divider completely?
dividerColor = Color.TRANSPARENT //clipboardViewAttr.getColor(R.styleable.ClipboardHistoryView_dividerBackground, 0)
clipboardViewAttr.recycle()
val keyboardViewAttr = context.obtainStyledAttributes(attrs,
R.styleable.KeyboardView, defStyle, R.style.KeyboardView)
@ -74,6 +75,8 @@ class ClipboardHistoryView @JvmOverloads constructor(
override fun onFinishInflate() {
super.onFinishInflate()
val colors = Settings.getInstance().current.mColors
colors.setKeyboardBackground(this)
clipboardAdapter = ClipboardAdapter(clipboardLayoutParams, this).apply {
itemBackgroundId = keyBackgroundId
pinnedIconResId = pinIconId
@ -100,21 +103,15 @@ class ClipboardHistoryView @JvmOverloads constructor(
clearKey = findViewById<ImageButton>(R.id.clipboard_clear).apply {
setOnTouchListener(this@ClipboardHistoryView)
setOnClickListener(this@ClipboardHistoryView)
colorFilter = colors.keyTextFilter
}
val colors = Settings.getInstance().current.mColors
clearKey.colorFilter = colors.keyTextFilter
val colorBackground = colors.keyboardBackground
if (colorBackground != null)
background = colorBackground
else
background.colorFilter = colors.backgroundFilter
}
private fun setupAlphabetKey(key: TextView?, label: String, params: KeyDrawParams) {
key?.apply {
text = label
typeface = params.mTypeface
Settings.getInstance().current.mColors.setBackgroundColor(this.background, Colors.TYPE_FUNCTIONAL)
Settings.getInstance().current.mColors.setBackgroundColor(this.background, BackgroundType.FUNCTIONAL)
setTextColor(params.mFunctionalTextColor)
setTextSize(TypedValue.COMPLEX_UNIT_PX, params.mLabelSize.toFloat())
}

View file

@ -19,7 +19,6 @@ package org.dslul.openboard.inputmethod.keyboard.emoji;
import android.content.Context;
import android.content.res.Resources;
import android.content.res.TypedArray;
import android.graphics.drawable.Drawable;
import android.util.AttributeSet;
import android.util.TypedValue;
import android.view.LayoutInflater;
@ -47,6 +46,7 @@ import org.dslul.openboard.inputmethod.keyboard.internal.KeyboardIconsSet;
import org.dslul.openboard.inputmethod.latin.AudioAndHapticFeedbackManager;
import org.dslul.openboard.inputmethod.latin.R;
import org.dslul.openboard.inputmethod.latin.RichInputMethodSubtype;
import org.dslul.openboard.inputmethod.latin.common.BackgroundType;
import org.dslul.openboard.inputmethod.latin.common.Colors;
import org.dslul.openboard.inputmethod.latin.common.Constants;
import org.dslul.openboard.inputmethod.latin.settings.Settings;
@ -133,7 +133,7 @@ public final class EmojiPalettesView extends LinearLayout
R.styleable.EmojiPalettesView_categoryIndicatorBackground, 0);
mCategoryPageIndicatorColor = emojiPalettesViewAttr.getColor(
R.styleable.EmojiPalettesView_categoryPageIndicatorColor, 0);
mCategoryPageIndicatorBackground = Settings.getInstance().getCurrent().mColors.adjustedBackground; //emojiPalettesViewAttr.getColor(R.styleable.EmojiPalettesView_categoryPageIndicatorBackground, 0);
mCategoryPageIndicatorBackground = Settings.getInstance().getCurrent().mColors.getAdjustedBackground(); //emojiPalettesViewAttr.getColor(R.styleable.EmojiPalettesView_categoryPageIndicatorBackground, 0);
emojiPalettesViewAttr.recycle();
mDeleteKeyOnTouchListener = new DeleteKeyOnTouchListener();
mEmojiLayoutManager = new LinearLayoutManager(context, LinearLayoutManager.VERTICAL, false);
@ -161,9 +161,7 @@ public final class EmojiPalettesView extends LinearLayout
// TODO: Replace background color with its own setting rather than using the
// category page indicator background as a workaround.
iconView.setBackgroundColor(mCategoryPageIndicatorBackground);
// todo: this doesn't get applied for holo, what could cause this?
// very interesting: in onTabChanged it's applied
iconView.setColorFilter(Settings.getInstance().getCurrent().mColors.keyTextFilter);
iconView.setColorFilter(Settings.getInstance().getCurrent().mColors.getKeyTextFilter());
iconView.setImageResource(mEmojiCategory.getCategoryTabIcon(categoryId));
iconView.setContentDescription(mEmojiCategory.getAccessibilityDescription(categoryId));
tspec.setIndicator(iconView);
@ -190,7 +188,7 @@ public final class EmojiPalettesView extends LinearLayout
tabWidget.setBackgroundResource(mCategoryIndicatorDrawableResId);
tabWidget.setLeftStripDrawable(mCategoryIndicatorBackgroundResId);
tabWidget.setRightStripDrawable(mCategoryIndicatorBackgroundResId);
tabWidget.setBackgroundColor(colors.accent);
tabWidget.setBackgroundColor(colors.getAccent());
}
mEmojiPalettesAdapter = new EmojiPalettesAdapter(mEmojiCategory, this);
@ -272,15 +270,11 @@ public final class EmojiPalettesView extends LinearLayout
mEmojiLayoutParams.setKeyProperties(mSpacebar);
mSpacebarIcon = findViewById(R.id.emoji_keyboard_space_icon);
colors.setBackgroundColor(mAlphabetKeyLeft.getBackground(), Colors.TYPE_FUNCTIONAL);
colors.setBackgroundColor(mDeleteKey.getBackground(), Colors.TYPE_FUNCTIONAL);
colors.setBackgroundColor(mSpacebar.getBackground(), Colors.TYPE_SPACE);
final Drawable background = colors.getKeyboardBackground();
if (background != null)
setBackground(background);
else
getBackground().setColorFilter(colors.backgroundFilter);
mEmojiCategoryPageIndicatorView.setColors(colors.accent, colors.adjustedBackground);
colors.setBackgroundColor(mAlphabetKeyLeft.getBackground(), BackgroundType.FUNCTIONAL);
colors.setBackgroundColor(mDeleteKey.getBackground(), BackgroundType.FUNCTIONAL);
colors.setBackgroundColor(mSpacebar.getBackground(), BackgroundType.SPACE);
colors.setBackgroundColor(getBackground(), BackgroundType.BACKGROUND); // only set color, not drawable (issues in keyboardWrapper otherwise)
mEmojiCategoryPageIndicatorView.setColors(colors.getAccent(), colors.getAdjustedBackground());
}
@Override
@ -302,10 +296,10 @@ public final class EmojiPalettesView extends LinearLayout
}
final Colors colors = Settings.getInstance().getCurrent().mColors;
if (mCurrentTab != null)
mCurrentTab.setColorFilter(colors.keyTextFilter);
mCurrentTab.setColorFilter(colors.getKeyTextFilter());
mCurrentTab = (ImageView) mTabHost.getCurrentTabView();
// mCurrentTab.setColorFilter(colors.accentColorFilter); // todo (later): doesn't work properly, because enabled drawable is blue -> adjust
mCurrentTab.setColorFilter(colors.accent);
mCurrentTab.setColorFilter(colors.getAccent());
}
/**

View file

@ -65,10 +65,10 @@ public class GestureFloatingTextDrawingPreview extends AbstractDrawingPreview {
final Colors colors = Settings.getInstance().getCurrent().mColors;
mGesturePreviewTextSize = mainKeyboardViewAttr.getDimensionPixelSize(
R.styleable.MainKeyboardView_gestureFloatingPreviewTextSize, 0);
mGesturePreviewTextColor = colors.keyText; //mainKeyboardViewAttr.getColor(R.styleable.MainKeyboardView_gestureFloatingPreviewTextColor, 0);
mGesturePreviewTextColor = colors.getKeyText(); //mainKeyboardViewAttr.getColor(R.styleable.MainKeyboardView_gestureFloatingPreviewTextColor, 0);
mGesturePreviewTextOffset = mainKeyboardViewAttr.getDimensionPixelOffset(
R.styleable.MainKeyboardView_gestureFloatingPreviewTextOffset, 0);
mGesturePreviewColor = colors.adjustedBackground; //mainKeyboardViewAttr.getColor(R.styleable.MainKeyboardView_gestureFloatingPreviewColor, 0);
mGesturePreviewColor = colors.getAdjustedBackground(); //mainKeyboardViewAttr.getColor(R.styleable.MainKeyboardView_gestureFloatingPreviewColor, 0);
mGesturePreviewHorizontalPadding = mainKeyboardViewAttr.getDimension(
R.styleable.MainKeyboardView_gestureFloatingPreviewHorizontalPadding, 0.0f);
mGesturePreviewVerticalPadding = mainKeyboardViewAttr.getDimension(

View file

@ -52,7 +52,7 @@ final class GestureTrailDrawingParams {
public final int mTrailLingerDuration;
public GestureTrailDrawingParams(final TypedArray mainKeyboardViewAttr) {
mTrailColor = Settings.getInstance().getCurrent().mColors.accent; //mainKeyboardViewAttr.getColor(R.styleable.MainKeyboardView_gestureTrailColor, 0);
mTrailColor = Settings.getInstance().getCurrent().mColors.getAccent(); //mainKeyboardViewAttr.getColor(R.styleable.MainKeyboardView_gestureTrailColor, 0);
mTrailStartWidth = mainKeyboardViewAttr.getDimension(
R.styleable.MainKeyboardView_gestureTrailStartWidth, 0.0f);
mTrailEndWidth = mainKeyboardViewAttr.getDimension(

View file

@ -118,7 +118,7 @@ public final class KeyPreviewChoreographer {
final boolean hasMoreKeys = (key.getMoreKeys() != null);
keyPreviewView.setPreviewBackground(hasMoreKeys, keyPreviewPosition);
final Colors colors = Settings.getInstance().getCurrent().mColors;
keyPreviewView.getBackground().setColorFilter(colors.adjustedBackgroundFilter);
keyPreviewView.getBackground().setColorFilter(colors.getAdjustedBackgroundFilter());
// The key preview is placed vertically above the top edge of the parent key with an
// arbitrary offset.
final int previewY = key.getY() - previewHeight + key.getHeight() - mParams.mPreviewOffset

View file

@ -128,19 +128,19 @@ public final class KeyVisualAttributes {
R.styleable.Keyboard_Key_keyPreviewTextRatio);
final Colors colors = Settings.getInstance().getCurrent().mColors;
mTextColor = colors.keyText; //keyAttr.getColor(R.styleable.Keyboard_Key_keyTextColor, 0);
mTextColor = colors.getKeyText(); //keyAttr.getColor(R.styleable.Keyboard_Key_keyTextColor, 0);
mTextInactivatedColor = keyAttr.getColor(R.styleable.Keyboard_Key_keyTextInactivatedColor, 0);
mTextShadowColor = keyAttr.getColor(R.styleable.Keyboard_Key_keyTextShadowColor, 0);
// todo: maybe a separate color?
mFunctionalTextColor = colors.keyText; //keyAttr.getColor(R.styleable.Keyboard_Key_functionalTextColor, 0);
mHintLetterColor = colors.keyHintText; //keyAttr.getColor(R.styleable.Keyboard_Key_keyHintLetterColor, 0);
mHintLabelColor = colors.keyText; //keyAttr.getColor(R.styleable.Keyboard_Key_keyHintLabelColor, 0);
mFunctionalTextColor = colors.getKeyText(); //keyAttr.getColor(R.styleable.Keyboard_Key_functionalTextColor, 0);
mHintLetterColor = colors.getKeyHintText(); //keyAttr.getColor(R.styleable.Keyboard_Key_keyHintLetterColor, 0);
mHintLabelColor = colors.getKeyText(); //keyAttr.getColor(R.styleable.Keyboard_Key_keyHintLabelColor, 0);
mShiftedLetterHintInactivatedColor = keyAttr.getColor(
R.styleable.Keyboard_Key_keyShiftedLetterHintInactivatedColor, 0);
mShiftedLetterHintActivatedColor = keyAttr.getColor(
R.styleable.Keyboard_Key_keyShiftedLetterHintActivatedColor, 0);
// todo: maybe a separate color?
mPreviewTextColor = colors.keyText; //keyAttr.getColor(R.styleable.Keyboard_Key_keyPreviewTextColor, 0);
mPreviewTextColor = colors.getKeyText(); //keyAttr.getColor(R.styleable.Keyboard_Key_keyPreviewTextColor, 0);
mHintLabelVerticalAdjustment = ResourceUtils.getFraction(keyAttr,
R.styleable.Keyboard_Key_keyHintLabelVerticalAdjustment, 0.0f);

View file

@ -46,7 +46,7 @@ public final class SlidingKeyInputDrawingPreview extends AbstractDrawingPreview
private final Paint mPaint = new Paint();
public SlidingKeyInputDrawingPreview(final TypedArray mainKeyboardViewAttr) {
final int previewColor = Settings.getInstance().getCurrent().mColors.accent; //mainKeyboardViewAttr.getColor(R.styleable.MainKeyboardView_slidingKeyInputPreviewColor, 0);
final int previewColor = Settings.getInstance().getCurrent().mColors.getAccent(); //mainKeyboardViewAttr.getColor(R.styleable.MainKeyboardView_slidingKeyInputPreviewColor, 0);
final float previewRadius = mainKeyboardViewAttr.getDimension(
R.styleable.MainKeyboardView_slidingKeyInputPreviewWidth, 0) / 2.0f;
final int PERCENTAGE_INT = 100;

View file

@ -2,13 +2,14 @@ package org.dslul.openboard.inputmethod.latin
import android.annotation.SuppressLint
import android.content.Context
import android.graphics.Color
import android.util.AttributeSet
import android.view.Gravity
import android.view.View
import android.widget.FrameLayout
import android.widget.ImageButton
import org.dslul.openboard.inputmethod.keyboard.KeyboardActionListener
import org.dslul.openboard.inputmethod.latin.common.Colors
import org.dslul.openboard.inputmethod.latin.common.BackgroundType
import org.dslul.openboard.inputmethod.latin.common.Constants
import org.dslul.openboard.inputmethod.latin.settings.Settings
@ -57,8 +58,8 @@ class KeyboardWrapperView @JvmOverloads constructor(
val colors = Settings.getInstance().current.mColors
stopOneHandedModeBtn.colorFilter = colors.keyTextFilter
switchOneHandedModeBtn.colorFilter = colors.keyTextFilter
colors.setBackgroundColor(stopOneHandedModeBtn.background, Colors.TYPE_BACKGROUND)
colors.setBackgroundColor(switchOneHandedModeBtn.background, Colors.TYPE_BACKGROUND)
colors.setBackgroundColor(stopOneHandedModeBtn.background, BackgroundType.BACKGROUND)
colors.setBackgroundColor(switchOneHandedModeBtn.background, BackgroundType.BACKGROUND)
}
@SuppressLint("RtlHardcoded")
@ -92,6 +93,7 @@ class KeyboardWrapperView @JvmOverloads constructor(
override fun onLayout(changed: Boolean, left: Int, top: Int, right: Int, bottom: Int) {
if (!oneHandedModeEnabled) {
super.onLayout(changed, left, top, right, bottom)
Settings.getInstance().current.mColors.setKeyboardBackground(keyboardView) // otherwise issue in clipboard view after switching oneHandedMode
return
}
@ -120,7 +122,7 @@ class KeyboardWrapperView @JvmOverloads constructor(
buttonsLeft + (spareWidth + switchOneHandedModeBtn.measuredWidth) / 2,
2 * stopOneHandedModeBtn.measuredHeight + switchOneHandedModeBtn.measuredHeight
)
Settings.getInstance().current.mColors.keyboardBackground?.let { background = it }
Settings.getInstance().current.mColors.setKeyboardBackground(this)
}
init {
@ -130,12 +132,7 @@ class KeyboardWrapperView @JvmOverloads constructor(
iconSwitchOneHandedModeId = keyboardAttr.getResourceId(R.styleable.Keyboard_iconSwitchOneHandedMode, 0)
keyboardAttr.recycle()
val themeAttr = context.obtainStyledAttributes(attrs,
R.styleable.KeyboardTheme, defStyle, 0)
val keyboardViewStyleId = themeAttr.getResourceId(R.styleable.KeyboardTheme_mainKeyboardViewStyle, 0)
themeAttr.recycle()
val styleAttr = context.obtainStyledAttributes(keyboardViewStyleId, intArrayOf(android.R.attr.background))
setBackgroundResource(styleAttr.getResourceId(0, 0))
styleAttr.recycle()
setBackgroundColor(Color.WHITE)
Settings.getInstance().current.mColors.setKeyboardBackground(this)
}
}

View file

@ -2020,7 +2020,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
final SettingsValues settingsValues = mSettings.getCurrent();
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP || !settingsValues.mCustomNavBarColor)
return;
final int color = settingsValues.mColors.navBar;
final int color = settingsValues.mColors.getNavBar();
final Window window = getWindow().getWindow();
if (window == null)
return;

View file

@ -1,161 +0,0 @@
package org.dslul.openboard.inputmethod.latin.common;
import static org.dslul.openboard.inputmethod.latin.utils.ColorUtilKt.*;
import android.content.res.ColorStateList;
import android.graphics.Color;
import android.graphics.ColorFilter;
import android.graphics.PorterDuff;
import android.graphics.drawable.Drawable;
import androidx.annotation.Nullable;
import androidx.core.graphics.BlendModeColorFilterCompat;
import androidx.core.graphics.BlendModeCompat;
import androidx.core.graphics.drawable.DrawableCompat;
import org.dslul.openboard.inputmethod.keyboard.KeyboardTheme;
// todo: maybe kotlin? would make it much shorter and more readable
public class Colors {
public int navBar;
public final int accent;
public final int background;
public final int keyBackground;
public final int functionalKey;
public final int spaceBar;
public final int keyText;
public final int keyHintText;
public int adjustedBackground;
public int adjustedKeyText;
// todo (later): evaluate which colors, colorFilters and colorStateLists area actually necessary
public ColorFilter backgroundFilter;
public ColorFilter adjustedBackgroundFilter;
public ColorFilter keyBackgroundFilter;
public ColorFilter functionalKeyBackgroundFilter;
public ColorFilter spaceBarFilter;
public ColorFilter keyTextFilter;
public ColorFilter accentColorFilter;
public ColorFilter actionKeyIconColorFilter;
private ColorStateList backgroundStateList;
private ColorStateList keyStateList;
private ColorStateList functionalKeyStateList;
private ColorStateList actionKeyStateList;
private ColorStateList spaceBarStateList;
private ColorStateList adjustedBackgroundStateList;
public static Colors newColors(String themeStyle, int accent, int background, int keyBackground, int functionalKey, int spaceBar, int keyText, int keyHintText) {
if (themeStyle.equals(KeyboardTheme.THEME_STYLE_HOLO))
return new HoloColors(accent, background, keyBackground, functionalKey, spaceBar, keyText, keyHintText);
return new Colors(accent, background, keyBackground, functionalKey, spaceBar, keyText, keyHintText);
}
protected Colors(int _accent, int _background, int _keyBackground, int _functionalKey, int _spaceBar, int _keyText, int _keyHintText) {
accent = _accent;
background = _background;
keyBackground = _keyBackground;
functionalKey = _functionalKey;
spaceBar = _spaceBar;
keyText = _keyText;
keyHintText = _keyHintText;
navBar = background;
}
/** set background colors including state list to the drawable */
// todo: this can be used for setting more complicated filters
// may be necessary for reproducing holo theme (extend Colors and override this in sth like HoloColors?)
public void setBackgroundColor(final Drawable background, final int type) {
final ColorStateList list;
switch (type) {
case TYPE_KEY:
list = keyStateList;
break;
case TYPE_SPACE:
list = spaceBarStateList;
break;
case TYPE_ADJUSTED_BACKGROUND:
list = adjustedBackgroundStateList;
break;
case TYPE_ACTION:
list = actionKeyStateList;
break;
case TYPE_FUNCTIONAL:
list = functionalKeyStateList;
break;
case TYPE_BACKGROUND:
default:
list = backgroundStateList;
}
DrawableCompat.setTintMode(background, PorterDuff.Mode.MULTIPLY);
DrawableCompat.setTintList(background, list);
}
@Nullable
public Drawable getKeyboardBackground() {
return null;
}
public static final int TYPE_BACKGROUND = 0;
public static final int TYPE_KEY = 1;
public static final int TYPE_FUNCTIONAL = 2;
public static final int TYPE_ACTION = 3;
public static final int TYPE_SPACE = 4;
public static final int TYPE_ADJUSTED_BACKGROUND = 5;
public void createColorFilters(final boolean hasKeyBorders) {
final int[][] states = new int[][] {
// are other states used?
// looks like only microphone ("shortcut") key can ever be disabled, but then it's not shown anyway...
// checkable/checked is only used for sticky shift key in old holo theme, but drawables not used in new version
// active is used for action key
// empty is used for emoji and spacers
new int[] { android.R.attr.state_pressed}, // pressed
new int[] { -android.R.attr.state_pressed}, // not pressed
};
// todo (idea): make better use of the states?
// could also use / create StateListDrawables in colors (though that's a style than a color...)
// this would better allow choosing e.g. cornered/rounded drawables for moreKeys or moreSuggestions
backgroundFilter = BlendModeColorFilterCompat.createBlendModeColorFilterCompat(background, BlendModeCompat.MODULATE);
adjustedKeyText = brightenOrDarken(keyText, true);
// color to be used if exact background color would be bad contrast, e.g. more keys popup or no border space bar
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);
if (hasKeyBorders) {
keyBackgroundFilter = BlendModeColorFilterCompat.createBlendModeColorFilterCompat(keyBackground, BlendModeCompat.MODULATE);
functionalKeyBackgroundFilter = BlendModeColorFilterCompat.createBlendModeColorFilterCompat(functionalKey, BlendModeCompat.MODULATE);
spaceBarFilter = BlendModeColorFilterCompat.createBlendModeColorFilterCompat(spaceBar, BlendModeCompat.MODULATE);
backgroundStateList = new ColorStateList(states, new int[] { brightenOrDarken(background, true), background });
keyStateList = new ColorStateList(states, new int[] { brightenOrDarken(keyBackground, true), keyBackground });
functionalKeyStateList = new ColorStateList(states, new int[] { brightenOrDarken(functionalKey, true), functionalKey });
actionKeyStateList = new ColorStateList(states, new int[] { brightenOrDarken(accent, true), accent });
spaceBarStateList = new ColorStateList(states, new int[] { brightenOrDarken(spaceBar, true), spaceBar });
} else {
// need to set color to background if key borders are disabled, or there will be ugly keys
keyBackgroundFilter = backgroundFilter;
functionalKeyBackgroundFilter = keyBackgroundFilter;
spaceBarFilter = keyBackgroundFilter;
backgroundStateList = new ColorStateList(states, new int[] { brightenOrDarken(background, true), background });
keyStateList = backgroundStateList;
functionalKeyStateList = backgroundStateList;
actionKeyStateList = new ColorStateList(states, new int[] { brightenOrDarken(accent, true), accent });
spaceBarStateList = adjustedBackgroundStateList;
}
keyTextFilter = BlendModeColorFilterCompat.createBlendModeColorFilterCompat(keyText, BlendModeCompat.SRC_ATOP);
accentColorFilter = BlendModeColorFilterCompat.createBlendModeColorFilterCompat(accent, BlendModeCompat.MODULATE);
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;
}
}

View file

@ -0,0 +1,164 @@
package org.dslul.openboard.inputmethod.latin.common
import android.content.res.ColorStateList
import android.content.res.TypedArray
import android.graphics.Color
import android.graphics.ColorFilter
import android.graphics.PorterDuff
import android.graphics.drawable.Drawable
import android.graphics.drawable.GradientDrawable
import android.view.View
import androidx.core.graphics.BlendModeColorFilterCompat
import androidx.core.graphics.BlendModeCompat
import androidx.core.graphics.drawable.DrawableCompat
import org.dslul.openboard.inputmethod.keyboard.KeyboardTheme
import org.dslul.openboard.inputmethod.keyboard.MoreKeysKeyboardView
import org.dslul.openboard.inputmethod.latin.R
import org.dslul.openboard.inputmethod.latin.suggestions.MoreSuggestionsView
import org.dslul.openboard.inputmethod.latin.utils.*
class Colors (
val themeStyle: String,
val hasKeyBorders: Boolean,
val accent: Int,
val background: Int,
val keyBackground: Int,
val functionalKey: Int,
val spaceBar: Int,
val keyText: Int,
val keyHintText: Int
) {
val navBar: Int
val adjustedBackground: Int
val adjustedKeyText: Int
// todo (later): evaluate which colors, colorFilters and colorStateLists are actually necessary
// also, ideally the color filters would be private and chosen internally depending on type
val backgroundFilter: ColorFilter
// workaround for error in ClipboardHistoryRecyclerView
// java.lang.IllegalAccessError: Field 'org.dslul.openboard.inputmethod.latin.common.Colors.backgroundFilter' is inaccessible to class 'org.dslul.openboard.inputmethod.keyboard.clipboard.ClipboardHistoryRecyclerView$BottomDividerItemDecoration'
// this should not happen, maybe it's a bug in kotlin? because it also doesn't recognize if the filter is accessed there, and wants to set it private
fun getThatBackgroundFilter() = backgroundFilter
val adjustedBackgroundFilter: ColorFilter
val keyBackgroundFilter: ColorFilter
val functionalKeyBackgroundFilter: ColorFilter
val spaceBarFilter: ColorFilter
val keyTextFilter: ColorFilter
val accentColorFilter: ColorFilter
val actionKeyIconColorFilter: ColorFilter?
private val backgroundStateList: ColorStateList
private val keyStateList: ColorStateList
private val functionalKeyStateList: ColorStateList
private val actionKeyStateList: ColorStateList
private val spaceBarStateList: ColorStateList
private val adjustedBackgroundStateList: ColorStateList
val keyboardBackground: Drawable?
init {
if (themeStyle == KeyboardTheme.THEME_STYLE_HOLO) {
val darkerBackground = adjustLuminosityAndKeepAlpha(background, -0.2f)
navBar = darkerBackground
keyboardBackground = GradientDrawable(GradientDrawable.Orientation.TOP_BOTTOM, intArrayOf(background, darkerBackground))
} else {
navBar = background
keyboardBackground = null
}
// create color filters, todo: maybe better / simplify
val states = arrayOf(intArrayOf(android.R.attr.state_pressed), intArrayOf(-android.R.attr.state_pressed))
fun stateList(pressed: Int, normal: Int) =
ColorStateList(states, intArrayOf(pressed, normal))
// todo (idea): make better use of the states?
// could also use / create StateListDrawables in colors (though that's a style than a color...)
// this would better allow choosing e.g. cornered/rounded drawables for moreKeys or moreSuggestions
backgroundFilter = colorFilter(background)
adjustedKeyText = brightenOrDarken(keyText, true)
// color to be used if exact background color would be bad contrast, e.g. more keys popup or no border space bar
if (isDarkColor(background)) {
adjustedBackground = brighten(background)
adjustedBackgroundStateList = stateList(brighten(adjustedBackground), adjustedBackground)
} else {
adjustedBackground = darken(background)
adjustedBackgroundStateList = stateList(darken(adjustedBackground), adjustedBackground)
}
adjustedBackgroundFilter = colorFilter(adjustedBackground)
if (hasKeyBorders) {
keyBackgroundFilter = colorFilter(keyBackground)
functionalKeyBackgroundFilter = colorFilter(functionalKey)
spaceBarFilter = colorFilter(spaceBar)
backgroundStateList = stateList(brightenOrDarken(background, true), background)
keyStateList = stateList(brightenOrDarken(keyBackground, true), keyBackground)
functionalKeyStateList = stateList(brightenOrDarken(functionalKey, true), functionalKey)
actionKeyStateList = if (themeStyle == KeyboardTheme.THEME_STYLE_HOLO) functionalKeyStateList
else stateList(brightenOrDarken(accent, true), accent)
spaceBarStateList = stateList(brightenOrDarken(spaceBar, true), spaceBar)
} else {
// need to set color to background if key borders are disabled, or there will be ugly keys
keyBackgroundFilter = backgroundFilter
functionalKeyBackgroundFilter = keyBackgroundFilter
spaceBarFilter = keyBackgroundFilter
backgroundStateList = stateList(brightenOrDarken(background, true), background)
keyStateList = backgroundStateList
functionalKeyStateList = backgroundStateList
actionKeyStateList = if (themeStyle == KeyboardTheme.THEME_STYLE_HOLO) functionalKeyStateList
else stateList(brightenOrDarken(accent, true), accent)
spaceBarStateList = adjustedBackgroundStateList
}
keyTextFilter = colorFilter(keyText, BlendModeCompat.SRC_ATOP)
accentColorFilter = colorFilter(accent)
actionKeyIconColorFilter =
if (isBrightColor(accent)) // the white icon may not have enough contrast, and can't be adjusted by the user
colorFilter(Color.DKGRAY, BlendModeCompat.SRC_ATOP)
else null
}
/** set background colors including state list to the drawable */
fun setBackgroundColor(background: Drawable, type: BackgroundType) {
val colorStateList = when (type) {
BackgroundType.BACKGROUND -> backgroundStateList
BackgroundType.KEY -> keyStateList
BackgroundType.FUNCTIONAL -> functionalKeyStateList
BackgroundType.ACTION -> actionKeyStateList
BackgroundType.SPACE -> spaceBarStateList
BackgroundType.ADJUSTED_BACKGROUND -> adjustedBackgroundStateList
}
DrawableCompat.setTintMode(background, PorterDuff.Mode.MULTIPLY)
DrawableCompat.setTintList(background, colorStateList)
}
// using !! for the color filter because null is only returned for unsupported modes, which are not used
private fun colorFilter(color: Int, mode: BlendModeCompat = BlendModeCompat.MODULATE): ColorFilter =
BlendModeColorFilterCompat.createBlendModeColorFilterCompat(color, mode)!!
fun getDrawable(type: BackgroundType, attr: TypedArray): Drawable {
val drawable = when (type) {
BackgroundType.KEY, BackgroundType.ADJUSTED_BACKGROUND, BackgroundType.BACKGROUND ->
attr.getDrawable(R.styleable.KeyboardView_keyBackground)?.mutate()
BackgroundType.FUNCTIONAL -> attr.getDrawable(R.styleable.KeyboardView_functionalKeyBackground)?.mutate()
BackgroundType.SPACE -> attr.getDrawable(R.styleable.KeyboardView_spacebarBackground)?.mutate()
BackgroundType.ACTION -> if (themeStyle == KeyboardTheme.THEME_STYLE_HOLO)
attr.getDrawable(R.styleable.KeyboardView_functionalKeyBackground)?.mutate()
else attr.getDrawable(R.styleable.KeyboardView_keyBackground)?.mutate()
} ?: attr.getDrawable(R.styleable.KeyboardView_keyBackground)?.mutate()!! // keyBackground always exists
setBackgroundColor(drawable, type)
return drawable
}
fun setKeyboardBackground(view: View) {
when (view) {
is MoreSuggestionsView -> view.background.colorFilter = backgroundFilter
is MoreKeysKeyboardView -> view.background.colorFilter = adjustedBackgroundFilter
else -> if (keyboardBackground != null) view.background = keyboardBackground
else view.background.colorFilter = backgroundFilter
}
}
}
enum class BackgroundType {
BACKGROUND, KEY, FUNCTIONAL, ACTION, SPACE, ADJUSTED_BACKGROUND
}

View file

@ -1,26 +0,0 @@
package org.dslul.openboard.inputmethod.latin.common;
import static org.dslul.openboard.inputmethod.latin.utils.ColorUtilKt.adjustLuminosityAndKeepAlpha;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.GradientDrawable;
public class HoloColors extends Colors {
private final Drawable keyboardBackground = new GradientDrawable(
GradientDrawable.Orientation.TOP_BOTTOM,
new int[] { background, adjustLuminosityAndKeepAlpha(background, -0.2f) }
);
protected HoloColors(int _accent, int _background, int _keyBackground, int _functionalKey, int _spaceBar, int _keyText, int _keyHintText) {
super(_accent, _background, _keyBackground, _functionalKey, _spaceBar, _keyText, _keyHintText);
navBar = adjustLuminosityAndKeepAlpha(background, -0.2f);
}
@Override
public Drawable getKeyboardBackground() {
// thanks a lot google for omitting something extremely exotic like a "subtract" color
// filter that could be simply applied on top of a brighter version of keyboard_background_holo
return keyboardBackground;
}
}

View file

@ -255,7 +255,6 @@ public class SettingsValues {
mSecondaryLocales = Settings.getSecondaryLocales(prefs, SubtypeSettingsKt.getSelectedSubtype(prefs).getLocale());
mColors = Settings.getColorsForCurrentTheme(context, prefs);
mColors.createColorFilters(prefs.getBoolean(Settings.PREF_THEME_KEY_BORDERS, false));
mAddToPersonalDictionary = prefs.getBoolean(Settings.PREF_ADD_TO_PERSONAL_DICTIONARY, false);
mUseContactsDictionary = prefs.getBoolean(AndroidSpellCheckerService.PREF_USE_CONTACTS_KEY, false);

View file

@ -131,10 +131,10 @@ final class SuggestionStripLayoutHelper {
R.styleable.SuggestionStripView_alphaObsoleted, 1.0f);
final Colors colors = Settings.getInstance().getCurrent().mColors;
mColorValidTypedWord = colors.adjustedKeyText; //a.getColor(R.styleable.SuggestionStripView_colorValidTypedWord, 0);
mColorTypedWord = colors.adjustedKeyText; //a.getColor(R.styleable.SuggestionStripView_colorTypedWord, 0);
mColorAutoCorrect = colors.keyText; //a.getColor(R.styleable.SuggestionStripView_colorAutoCorrect, 0);
mColorSuggested = colors.adjustedKeyText; //a.getColor(R.styleable.SuggestionStripView_colorSuggested, 0);
mColorValidTypedWord = colors.getAdjustedKeyText(); //a.getColor(R.styleable.SuggestionStripView_colorValidTypedWord, 0);
mColorTypedWord = colors.getAdjustedKeyText(); //a.getColor(R.styleable.SuggestionStripView_colorTypedWord, 0);
mColorAutoCorrect = colors.getKeyText(); //a.getColor(R.styleable.SuggestionStripView_colorAutoCorrect, 0);
mColorSuggested = colors.getAdjustedKeyText(); //a.getColor(R.styleable.SuggestionStripView_colorSuggested, 0);
mSuggestionsCountInStrip = a.getInt(
R.styleable.SuggestionStripView_suggestionsCountInStrip,

View file

@ -48,6 +48,7 @@ import org.dslul.openboard.inputmethod.latin.BuildConfig;
import org.dslul.openboard.inputmethod.latin.R;
import org.dslul.openboard.inputmethod.latin.SuggestedWords;
import org.dslul.openboard.inputmethod.latin.SuggestedWords.SuggestedWordInfo;
import org.dslul.openboard.inputmethod.latin.common.BackgroundType;
import org.dslul.openboard.inputmethod.latin.common.Colors;
import org.dslul.openboard.inputmethod.latin.common.Constants;
import org.dslul.openboard.inputmethod.latin.define.DebugFlags;
@ -147,7 +148,7 @@ public final class SuggestionStripView extends RelativeLayout implements OnClick
word.setContentDescription(getResources().getString(R.string.spoken_empty_suggestion));
word.setOnClickListener(this);
word.setOnLongClickListener(this);
colors.setBackgroundColor(word.getBackground(), Colors.TYPE_BACKGROUND);
colors.setBackgroundColor(word.getBackground(), BackgroundType.BACKGROUND);
mWordViews.add(word);
final View divider = inflater.inflate(R.layout.suggestion_divider, null);
mDividerViews.add(divider);
@ -185,10 +186,10 @@ public final class SuggestionStripView extends RelativeLayout implements OnClick
mOtherKey.setImageDrawable(iconIncognito);
colors.setBackgroundColor(getBackground(), Colors.TYPE_BACKGROUND);
mClipboardKey.setColorFilter(colors.keyText);
mVoiceKey.setColorFilter(colors.keyText);
mOtherKey.setColorFilter(colors.keyText);
colors.setBackgroundColor(getBackground(), BackgroundType.BACKGROUND);
mClipboardKey.setColorFilter(colors.getKeyText());
mVoiceKey.setColorFilter(colors.getKeyText());
mOtherKey.setColorFilter(colors.getKeyText());
}
/**