Update theming for more keys popup

This commit is contained in:
Aleksandras Kostarevas 2024-01-07 14:26:09 +02:00
parent ebb70b9c12
commit b75933b321
7 changed files with 28 additions and 4 deletions

View File

@ -421,6 +421,7 @@
<attr name="keyTextShadowColor" format="color" /> <attr name="keyTextShadowColor" format="color" />
<!-- Color to use for the label in a key when in inactivated state. --> <!-- Color to use for the label in a key when in inactivated state. -->
<attr name="keyTextInactivatedColor" format="color" /> <attr name="keyTextInactivatedColor" format="color" />
<attr name="keyPressedTextColor" format="color" />
<!-- Color to use for the label in a key that has followFunctionalTextColor keyLabelFlags. --> <!-- Color to use for the label in a key that has followFunctionalTextColor keyLabelFlags. -->
<attr name="functionalTextColor" format="color" /> <attr name="functionalTextColor" format="color" />
<!-- Key hint letter (= one character hint label) color --> <!-- Key hint letter (= one character hint label) color -->

View File

@ -665,6 +665,10 @@ public class Key implements Comparable<Key> {
if ((mLabelFlags & LABEL_FLAGS_FOLLOW_FUNCTIONAL_TEXT_COLOR) != 0) { if ((mLabelFlags & LABEL_FLAGS_FOLLOW_FUNCTIONAL_TEXT_COLOR) != 0) {
return params.mFunctionalTextColor; return params.mFunctionalTextColor;
} }
if (mPressed) {
return params.mPressedTextColor;
}
return isShiftedLetterActivated() ? params.mTextInactivatedColor : params.mTextColor; return isShiftedLetterActivated() ? params.mTextInactivatedColor : params.mTextColor;
} }

View File

@ -176,6 +176,11 @@ public class KeyboardView extends View {
R.styleable.Keyboard_Key, defStyle, R.style.KeyboardView); R.styleable.Keyboard_Key, defStyle, R.style.KeyboardView);
mDefaultKeyLabelFlags = keyAttr.getInt(R.styleable.Keyboard_Key_keyLabelFlags, 0); mDefaultKeyLabelFlags = keyAttr.getInt(R.styleable.Keyboard_Key_keyLabelFlags, 0);
mKeyVisualAttributes = KeyVisualAttributes.newInstance(keyAttr, mDrawableProvider); mKeyVisualAttributes = KeyVisualAttributes.newInstance(keyAttr, mDrawableProvider);
if(isMoreKeys && mKeyVisualAttributes != null) {
mKeyVisualAttributes.mTextColor = mDrawableProvider.getMoreKeysTextColor();
}
keyAttr.recycle(); keyAttr.recycle();
mPaint.setAntiAlias(true); mPaint.setAntiAlias(true);

View File

@ -37,6 +37,7 @@ public final class KeyDrawParams {
public int mTextColor; public int mTextColor;
public int mTextInactivatedColor; public int mTextInactivatedColor;
public int mPressedTextColor;
public int mTextShadowColor; public int mTextShadowColor;
public int mFunctionalTextColor; public int mFunctionalTextColor;
public int mHintLetterColor; public int mHintLetterColor;
@ -66,6 +67,7 @@ public final class KeyDrawParams {
mTextColor = copyFrom.mTextColor; mTextColor = copyFrom.mTextColor;
mTextInactivatedColor = copyFrom.mTextInactivatedColor; mTextInactivatedColor = copyFrom.mTextInactivatedColor;
mPressedTextColor = copyFrom.mPressedTextColor;
mTextShadowColor = copyFrom.mTextShadowColor; mTextShadowColor = copyFrom.mTextShadowColor;
mFunctionalTextColor = copyFrom.mFunctionalTextColor; mFunctionalTextColor = copyFrom.mFunctionalTextColor;
mHintLetterColor = copyFrom.mHintLetterColor; mHintLetterColor = copyFrom.mHintLetterColor;
@ -103,6 +105,7 @@ public final class KeyDrawParams {
mTextColor = selectColor(attr.mTextColor, mTextColor); mTextColor = selectColor(attr.mTextColor, mTextColor);
mTextInactivatedColor = selectColor(attr.mTextInactivatedColor, mTextInactivatedColor); mTextInactivatedColor = selectColor(attr.mTextInactivatedColor, mTextInactivatedColor);
mPressedTextColor = selectColor(attr.mPressedTextColor, mPressedTextColor);
mTextShadowColor = selectColor(attr.mTextShadowColor, mTextShadowColor); mTextShadowColor = selectColor(attr.mTextShadowColor, mTextShadowColor);
mFunctionalTextColor = selectColor(attr.mFunctionalTextColor, mFunctionalTextColor); mFunctionalTextColor = selectColor(attr.mFunctionalTextColor, mFunctionalTextColor);
mHintLetterColor = selectColor(attr.mHintLetterColor, mHintLetterColor); mHintLetterColor = selectColor(attr.mHintLetterColor, mHintLetterColor);

View File

@ -41,8 +41,9 @@ public final class KeyVisualAttributes {
public final float mHintLabelRatio; public final float mHintLabelRatio;
public final float mPreviewTextRatio; public final float mPreviewTextRatio;
public final int mTextColor; public int mTextColor;
public final int mTextInactivatedColor; public final int mTextInactivatedColor;
public final int mPressedTextColor;
public final int mTextShadowColor; public final int mTextShadowColor;
public final int mFunctionalTextColor; public final int mFunctionalTextColor;
public final int mHintLetterColor; public final int mHintLetterColor;
@ -130,6 +131,8 @@ public final class KeyVisualAttributes {
R.styleable.Keyboard_Key_keyTextColor, 0, keyAttr, provider); R.styleable.Keyboard_Key_keyTextColor, 0, keyAttr, provider);
mTextInactivatedColor = DynamicThemeProvider.Companion.getColorOrDefault( mTextInactivatedColor = DynamicThemeProvider.Companion.getColorOrDefault(
R.styleable.Keyboard_Key_keyTextInactivatedColor, 0, keyAttr, provider); R.styleable.Keyboard_Key_keyTextInactivatedColor, 0, keyAttr, provider);
mPressedTextColor = DynamicThemeProvider.Companion.getColorOrDefault(
R.styleable.Keyboard_Key_keyPressedTextColor, 0, keyAttr, provider);
mTextShadowColor = DynamicThemeProvider.Companion.getColorOrDefault( mTextShadowColor = DynamicThemeProvider.Companion.getColorOrDefault(
R.styleable.Keyboard_Key_keyTextShadowColor, 0, keyAttr, provider); R.styleable.Keyboard_Key_keyTextShadowColor, 0, keyAttr, provider);
mFunctionalTextColor = DynamicThemeProvider.Companion.getColorOrDefault( mFunctionalTextColor = DynamicThemeProvider.Companion.getColorOrDefault(

View File

@ -31,6 +31,7 @@ class BasicThemeProvider(val context: Context, val overrideColorScheme: ColorSch
override val keyFeedback: Drawable override val keyFeedback: Drawable
override val moreKeysTextColor: Int
override val moreKeysKeyboardBackground: Drawable override val moreKeysKeyboardBackground: Drawable
override val popupKey: Drawable override val popupKey: Drawable
@ -107,6 +108,10 @@ class BasicThemeProvider(val context: Context, val overrideColorScheme: ColorSch
val surface = colorScheme.background.toArgb() val surface = colorScheme.background.toArgb()
val outline = colorScheme.outline.toArgb() val outline = colorScheme.outline.toArgb()
val primaryContainer = colorScheme.primaryContainer.toArgb()
val onPrimaryContainer = colorScheme.onPrimaryContainer.toArgb()
val onPrimary = colorScheme.onPrimary.toArgb()
val onSecondary = colorScheme.onSecondary.toArgb() val onSecondary = colorScheme.onSecondary.toArgb()
val onBackground = colorScheme.onBackground.toArgb() val onBackground = colorScheme.onBackground.toArgb()
val onBackgroundHalf = colorScheme.onBackground.copy(alpha = 0.5f).toArgb() val onBackgroundHalf = colorScheme.onBackground.copy(alpha = 0.5f).toArgb()
@ -115,6 +120,7 @@ class BasicThemeProvider(val context: Context, val overrideColorScheme: ColorSch
colors[R.styleable.Keyboard_Key_keyTextColor] = onBackground colors[R.styleable.Keyboard_Key_keyTextColor] = onBackground
colors[R.styleable.Keyboard_Key_keyTextInactivatedColor] = onBackgroundHalf colors[R.styleable.Keyboard_Key_keyTextInactivatedColor] = onBackgroundHalf
colors[R.styleable.Keyboard_Key_keyPressedTextColor] = onPrimary
colors[R.styleable.Keyboard_Key_keyTextShadowColor] = 0 colors[R.styleable.Keyboard_Key_keyTextShadowColor] = 0
colors[R.styleable.Keyboard_Key_functionalTextColor] = onBackground colors[R.styleable.Keyboard_Key_functionalTextColor] = onBackground
colors[R.styleable.Keyboard_Key_keyHintLetterColor] = onBackgroundHalf colors[R.styleable.Keyboard_Key_keyHintLetterColor] = onBackgroundHalf
@ -208,10 +214,11 @@ class BasicThemeProvider(val context: Context, val overrideColorScheme: ColorSch
setPadding(0, 0, 0, dp(50.dp).roundToInt()) setPadding(0, 0, 0, dp(50.dp).roundToInt())
} }
moreKeysKeyboardBackground = coloredRoundedRectangle(surface, dp(8.dp)) moreKeysTextColor = onPrimaryContainer
moreKeysKeyboardBackground = coloredRoundedRectangle(primaryContainer, dp(8.dp))
popupKey = StateListDrawable().apply { popupKey = StateListDrawable().apply {
addStateWithHighlightLayerOnPressed(highlight, intArrayOf(), addStateWithHighlightLayerOnPressed(primary, intArrayOf(),
coloredRoundedRectangle(surface, dp(8.dp)) coloredRoundedRectangle(primaryContainer, dp(8.dp))
) )
} }
} }

View File

@ -13,6 +13,7 @@ interface DynamicThemeProvider {
val keyFeedback: Drawable val keyFeedback: Drawable
val moreKeysTextColor: Int
val moreKeysKeyboardBackground: Drawable val moreKeysKeyboardBackground: Drawable
val popupKey: Drawable val popupKey: Drawable