mirror of
https://github.com/Helium314/HeliBoard.git
synced 2025-04-24 16:46:35 +00:00
set color state lists inside Colors
This commit is contained in:
parent
556ff23b98
commit
59ce1a1cb3
6 changed files with 62 additions and 40 deletions
|
@ -32,8 +32,6 @@ import android.text.TextUtils;
|
|||
import android.util.AttributeSet;
|
||||
import android.view.View;
|
||||
|
||||
import androidx.core.graphics.drawable.DrawableCompat;
|
||||
|
||||
import org.dslul.openboard.inputmethod.keyboard.emoji.EmojiPageKeyboardView;
|
||||
import org.dslul.openboard.inputmethod.keyboard.internal.KeyDrawParams;
|
||||
import org.dslul.openboard.inputmethod.keyboard.internal.KeyVisualAttributes;
|
||||
|
@ -179,20 +177,17 @@ public class KeyboardView extends View {
|
|||
|
||||
mColors = Settings.getInstance().getCurrent().mColors;
|
||||
if (mColors.isCustom) {
|
||||
DrawableCompat.setTintMode(mKeyBackground, PorterDuff.Mode.MULTIPLY);
|
||||
if (this.getClass() == MoreKeysKeyboardView.class) {
|
||||
DrawableCompat.setTintList(mKeyBackground, mColors.adjustedBackgroundStateList);
|
||||
} else if (this.getClass() == EmojiPageKeyboardView.class || this.getClass() == MoreSuggestionsView.class) {
|
||||
DrawableCompat.setTintList(mKeyBackground, mColors.backgroundStateList);
|
||||
final Class<?> c = this.getClass();
|
||||
if (c == MoreKeysKeyboardView.class) {
|
||||
mColors.setBackgroundColor(mKeyBackground, Colors.TYPE_ADJUSTED_BACKGROUND);
|
||||
} else if (c == EmojiPageKeyboardView.class || c == MoreSuggestionsView.class) {
|
||||
mColors.setBackgroundColor(mKeyBackground, Colors.TYPE_BACKGROUND);
|
||||
} else {
|
||||
DrawableCompat.setTintList(mKeyBackground, mColors.keyStateList);
|
||||
mColors.setBackgroundColor(mKeyBackground, Colors.TYPE_KEY);
|
||||
}
|
||||
DrawableCompat.setTintMode(mActionKeyBackground, PorterDuff.Mode.MULTIPLY);
|
||||
DrawableCompat.setTintList(mActionKeyBackground, mColors.actionKeyStateList);
|
||||
DrawableCompat.setTintMode(mSpacebarBackground, PorterDuff.Mode.MULTIPLY);
|
||||
DrawableCompat.setTintList(mSpacebarBackground, mColors.spaceBarStateList);
|
||||
DrawableCompat.setTintMode(mFunctionalKeyBackground, PorterDuff.Mode.MULTIPLY);
|
||||
DrawableCompat.setTintList(mFunctionalKeyBackground, mColors.functionalKeyStateList);
|
||||
mColors.setBackgroundColor(mActionKeyBackground, Colors.TYPE_ACTION);
|
||||
mColors.setBackgroundColor(mSpacebarBackground, Colors.TYPE_SPACE);
|
||||
mColors.setBackgroundColor(mFunctionalKeyBackground, Colors.TYPE_FUNCTIONAL);
|
||||
if (this.getClass() == MoreKeysKeyboardView.class)
|
||||
getBackground().setColorFilter(mColors.adjustedBackgroundFilter);
|
||||
else
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
package org.dslul.openboard.inputmethod.keyboard.clipboard
|
||||
|
||||
import android.graphics.PorterDuff
|
||||
import android.graphics.Typeface
|
||||
import android.util.TypedValue
|
||||
import android.view.LayoutInflater
|
||||
|
@ -9,11 +8,11 @@ import android.view.View
|
|||
import android.view.ViewGroup
|
||||
import android.widget.ImageView
|
||||
import android.widget.TextView
|
||||
import androidx.core.graphics.drawable.DrawableCompat
|
||||
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.common.Colors
|
||||
import org.dslul.openboard.inputmethod.latin.settings.Settings
|
||||
|
||||
class ClipboardAdapter(
|
||||
|
@ -58,8 +57,7 @@ class ClipboardAdapter(
|
|||
setBackgroundResource(itemBackgroundId)
|
||||
val colors = Settings.getInstance().current.mColors
|
||||
if (colors.isCustom) {
|
||||
DrawableCompat.setTintList(background, colors.keyStateList)
|
||||
DrawableCompat.setTintMode(background, PorterDuff.Mode.MULTIPLY)
|
||||
colors.setBackgroundColor(background, Colors.TYPE_KEY)
|
||||
}
|
||||
}
|
||||
pinnedIconView = view.findViewById<ImageView>(R.id.clipboard_entry_pinned_icon).apply {
|
||||
|
|
|
@ -9,7 +9,6 @@ import android.widget.FrameLayout
|
|||
import android.widget.ImageButton
|
||||
import android.widget.LinearLayout
|
||||
import android.widget.TextView
|
||||
import androidx.core.graphics.drawable.DrawableCompat
|
||||
import androidx.recyclerview.widget.StaggeredGridLayoutManager
|
||||
import org.dslul.openboard.inputmethod.keyboard.KeyboardActionListener
|
||||
import org.dslul.openboard.inputmethod.keyboard.internal.KeyDrawParams
|
||||
|
@ -17,6 +16,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.Constants
|
||||
import org.dslul.openboard.inputmethod.latin.settings.Settings
|
||||
import org.dslul.openboard.inputmethod.latin.utils.ResourceUtils
|
||||
|
@ -117,7 +117,7 @@ class ClipboardHistoryView @JvmOverloads constructor(
|
|||
val colors = Settings.getInstance().current.mColors
|
||||
if (colors.isCustom) {
|
||||
setTextColor(colors.keyText)
|
||||
DrawableCompat.setTintList(this.background, colors.functionalKeyStateList)
|
||||
colors.setBackgroundColor(this.background, Colors.TYPE_FUNCTIONAL)
|
||||
} else
|
||||
setTextColor(params.mFunctionalTextColor)
|
||||
setTextSize(TypedValue.COMPLEX_UNIT_PX, params.mLabelSize.toFloat())
|
||||
|
|
|
@ -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.PorterDuff;
|
||||
import android.util.AttributeSet;
|
||||
import android.util.TypedValue;
|
||||
import android.view.LayoutInflater;
|
||||
|
@ -276,12 +275,9 @@ public final class EmojiPalettesView extends LinearLayout
|
|||
|
||||
final Colors colors = Settings.getInstance().getCurrent().mColors;
|
||||
if (colors.isCustom) {
|
||||
DrawableCompat.setTintList(mAlphabetKeyLeft.getBackground(), colors.functionalKeyStateList);
|
||||
DrawableCompat.setTintList(mSpacebar.getBackground(), colors.spaceBarStateList);
|
||||
DrawableCompat.setTintList(mDeleteKey.getBackground(), colors.functionalKeyStateList);
|
||||
DrawableCompat.setTintMode(mAlphabetKeyLeft.getBackground(), PorterDuff.Mode.MULTIPLY);
|
||||
DrawableCompat.setTintMode(mSpacebar.getBackground(), PorterDuff.Mode.MULTIPLY);
|
||||
DrawableCompat.setTintMode(mDeleteKey.getBackground(), PorterDuff.Mode.MULTIPLY);
|
||||
colors.setBackgroundColor(mAlphabetKeyLeft.getBackground(), Colors.TYPE_FUNCTIONAL);
|
||||
colors.setBackgroundColor(mDeleteKey.getBackground(), Colors.TYPE_FUNCTIONAL);
|
||||
colors.setBackgroundColor(mSpacebar.getBackground(), Colors.TYPE_SPACE);
|
||||
getBackground().setColorFilter(colors.backgroundFilter);
|
||||
mEmojiCategoryPageIndicatorView.setColors(colors.accent, colors.adjustedBackground);
|
||||
}
|
||||
|
|
|
@ -3,13 +3,14 @@ package org.dslul.openboard.inputmethod.latin.common;
|
|||
import android.content.res.ColorStateList;
|
||||
import android.graphics.Color;
|
||||
import android.graphics.ColorFilter;
|
||||
import android.graphics.PorterDuff;
|
||||
import android.graphics.drawable.Drawable;
|
||||
|
||||
import androidx.core.graphics.BlendModeColorFilterCompat;
|
||||
import androidx.core.graphics.BlendModeCompat;
|
||||
import androidx.annotation.ColorInt;
|
||||
import androidx.core.graphics.ColorUtils;
|
||||
|
||||
import org.dslul.openboard.inputmethod.keyboard.KeyboardTheme;
|
||||
import androidx.core.graphics.drawable.DrawableCompat;
|
||||
|
||||
// todo: maybe kotlin? would make it much shorter and more readable
|
||||
public class Colors {
|
||||
|
@ -35,12 +36,12 @@ public class Colors {
|
|||
public ColorFilter accentColorFilter;
|
||||
public ColorFilter actionKeyIconColorFilter;
|
||||
|
||||
public ColorStateList backgroundStateList;
|
||||
public ColorStateList keyStateList;
|
||||
public ColorStateList functionalKeyStateList;
|
||||
public ColorStateList actionKeyStateList;
|
||||
public ColorStateList spaceBarStateList;
|
||||
public ColorStateList adjustedBackgroundStateList;
|
||||
private ColorStateList backgroundStateList;
|
||||
private ColorStateList keyStateList;
|
||||
private ColorStateList functionalKeyStateList;
|
||||
private ColorStateList actionKeyStateList;
|
||||
private ColorStateList spaceBarStateList;
|
||||
private ColorStateList adjustedBackgroundStateList;
|
||||
|
||||
public Colors(int _accent, int _background, int _keyBackground, int _functionalKey, int _spaceBar, int _keyText, int _keyHintText) {
|
||||
isCustom = true;
|
||||
|
@ -68,6 +69,42 @@ public class Colors {
|
|||
keyHintText = 0;
|
||||
}
|
||||
|
||||
/** 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);
|
||||
}
|
||||
|
||||
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?
|
||||
|
|
|
@ -22,14 +22,12 @@ import android.content.Context;
|
|||
import android.content.res.Resources;
|
||||
import android.content.res.TypedArray;
|
||||
import android.graphics.Color;
|
||||
import android.graphics.PorterDuff;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.util.AttributeSet;
|
||||
import android.util.TypedValue;
|
||||
import android.view.GestureDetector;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
import android.view.MotionEvent;
|
||||
import android.view.View;
|
||||
import android.view.View.OnClickListener;
|
||||
|
@ -41,7 +39,6 @@ import android.widget.ImageButton;
|
|||
import android.widget.PopupMenu;
|
||||
import android.widget.RelativeLayout;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import org.dslul.openboard.inputmethod.accessibility.AccessibilityUtils;
|
||||
import org.dslul.openboard.inputmethod.keyboard.Keyboard;
|
||||
|
@ -196,8 +193,7 @@ public final class SuggestionStripView extends RelativeLayout implements OnClick
|
|||
// it seems to work in other places, e.g. for btn_keyboard_spacebar_lxx_base... though maybe that's the weirdly nested layer list?
|
||||
// todo (later): when fixing this, revert changes in themes-lxx-base[-border] (in todo)
|
||||
// this would allow having a different background shape in pressed state
|
||||
DrawableCompat.setTintList(getBackground(), colors.backgroundStateList);
|
||||
DrawableCompat.setTintMode(getBackground(), PorterDuff.Mode.MULTIPLY);
|
||||
colors.setBackgroundColor(getBackground(), Colors.TYPE_BACKGROUND);
|
||||
|
||||
mClipboardKey.setColorFilter(colors.keyText);
|
||||
mVoiceKey.setColorFilter(colors.keyText);
|
||||
|
|
Loading…
Add table
Reference in a new issue