Update moreKeys for Enter key with some actions

This commit is contained in:
Aleksandras Kostarevas 2024-06-21 23:49:31 +03:00
parent bf47b3f17c
commit 4bada6e34d
12 changed files with 64 additions and 33 deletions

View File

@ -327,6 +327,13 @@
<attr name="keyHintLabel" format="string" />
<!-- The vertical adjustment of key hint label in proportion to its height. -->
<attr name="keyHintLabelVerticalAdjustment" format="fraction" />
<!-- Whether or not keyboard should use action drawables -->
<attr name="isAction" format="boolean" />
<!-- Whether or not keyboard should use moreKey drawables -->
<attr name="isMoreKey" format="boolean" />
<!-- The key label flags. -->
<attr name="keyLabelFlags" format="integer">
<!-- This should be aligned with
@ -420,6 +427,7 @@
<!-- Color to use for the label in a key when in inactivated state. -->
<attr name="keyTextInactivatedColor" format="color" />
<attr name="keyPressedTextColor" format="color" />
<attr name="actionKeyTextColor" format="color" />
<!-- Color to use for the label in a key that has followFunctionalTextColor keyLabelFlags. -->
<attr name="functionalTextColor" format="color" />
<!-- Key hint letter (= one character hint label) color -->

View File

@ -121,6 +121,7 @@
<item name="divider">@drawable/more_keys_divider</item>
<item name="keyTypeface">normal</item>
<item name="verticalCorrection">@dimen/config_more_keys_keyboard_vertical_correction_holo</item>
<item name="isMoreKey">true</item>
</style>
<style
name="MoreKeysKeyboardView.LXX_Dark.Action"
@ -130,6 +131,7 @@
<item name="keyBackground">@drawable/btn_keyboard_key_popup_action_lxx_dark</item>
<item name="divider">@null</item>
<item name="keyLabelFlags">keepBackgroundAspectRatio</item>
<item name="isAction">true</item>
</style>
<style
name="SuggestionStripView.LXX_Dark"

View File

@ -121,6 +121,7 @@
<item name="divider">@drawable/more_keys_divider</item>
<item name="keyTypeface">normal</item>
<item name="verticalCorrection">@dimen/config_more_keys_keyboard_vertical_correction_holo</item>
<item name="isMoreKey">true</item>
</style>
<style
name="MoreKeysKeyboardView.LXX_Light.Action"
@ -130,6 +131,7 @@
<item name="keyBackground">@drawable/btn_keyboard_key_popup_action_lxx_light</item>
<item name="divider">@null</item>
<item name="keyLabelFlags">keepBackgroundAspectRatio</item>
<item name="isAction">true</item>
</style>
<style
name="SuggestionStripView.LXX_Light"

View File

@ -77,24 +77,11 @@
latin:keyActionFlags="isRepeatable|noKeyPreview"
latin:backgroundType="functional" />
<!-- emojiKeyStyle must be defined before including @xml/key_syles_enter. -->
<switch>
<case latin:keyboardTheme="ICS|KLP">
<key-style
latin:styleName="emojiKeyStyle"
latin:keySpec="!icon/emoji_action_key|!code/key_emoji"
latin:keyActionFlags="noKeyPreview"
latin:backgroundType="action" />
</case>
<!-- keyboardTheme="LXXLight|LXXDark" -->
<default>
<key-style
latin:styleName="emojiKeyStyle"
latin:keySpec="!icon/emoji_action_key|!code/key_emoji"
latin:keyLabelFlags="keepBackgroundAspectRatio"
latin:keyActionFlags="noKeyPreview"
latin:backgroundType="action" />
</default>
</switch>
<key-style
latin:styleName="emojiKeyStyle"
latin:keySpec="!icon/emoji_action_key|!code/key_emoji"
latin:keyActionFlags="noKeyPreview"
latin:backgroundType="action" />
<include
latin:keyboardLayout="@xml/key_styles_enter" />
<!-- TODO: Currently there is no way to specify icon alignment per theme. -->

View File

@ -677,6 +677,10 @@ public class Key implements Comparable<Key> {
}
public final int selectTextColor(final KeyDrawParams params) {
if (isActionKey()) {
return params.mActionKeyTextColor;
}
if ((mLabelFlags & LABEL_FLAGS_FOLLOW_FUNCTIONAL_TEXT_COLOR) != 0) {
return params.mFunctionalTextColor;
}

View File

@ -30,6 +30,7 @@ import android.graphics.drawable.Drawable;
import android.graphics.drawable.NinePatchDrawable;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.util.Log;
import android.view.ContextThemeWrapper;
import android.view.View;
@ -137,19 +138,25 @@ public class KeyboardView extends View {
final TypedArray keyboardViewAttr = context.obtainStyledAttributes(attrs,
R.styleable.KeyboardView, defStyle, R.style.KeyboardView);
final TypedArray keyAttr = context.obtainStyledAttributes(attrs,
R.styleable.Keyboard_Key, defStyle, R.style.KeyboardView);
assert(context instanceof ContextThemeWrapper);
assert(((ContextThemeWrapper) context).getBaseContext() instanceof DynamicThemeProviderOwner);
mDrawableProvider = ((DynamicThemeProviderOwner) ((ContextThemeWrapper) context).getBaseContext()).getDrawableProvider();
boolean isMoreKeys = defStyle == R.attr.moreKeysKeyboardViewStyle || defStyle == R.attr.moreKeysKeyboardViewForActionStyle;
boolean isMoreKeys = keyAttr.getBoolean(R.styleable.Keyboard_Key_isMoreKey, false);
boolean isMoreKeysAction = keyAttr.getBoolean(R.styleable.Keyboard_Key_isAction, false);
mKeyboardBackground = isMoreKeys ?
mDrawableProvider.getMoreKeysKeyboardBackground() : mDrawableProvider.getKeyboardBackground();
mKeyboardBackground = isMoreKeysAction ? null :
isMoreKeys ? mDrawableProvider.getMoreKeysKeyboardBackground() :
mDrawableProvider.getKeyboardBackground();
setBackground(mKeyboardBackground);
mKeyBackground = isMoreKeys ?
mDrawableProvider.getPopupKey() : mDrawableProvider.getKeyBackground();
mKeyBackground = isMoreKeysAction ? mDrawableProvider.getActionPopupKey() :
isMoreKeys ? mDrawableProvider.getPopupKey() :
mDrawableProvider.getKeyBackground();
mKeyBackground.getPadding(mKeyBackgroundPadding);
mFunctionalKeyBackground = mKeyBackground;
@ -172,12 +179,10 @@ public class KeyboardView extends View {
R.styleable.KeyboardView_verticalCorrection, 0.0f);
keyboardViewAttr.recycle();
final TypedArray keyAttr = context.obtainStyledAttributes(attrs,
R.styleable.Keyboard_Key, defStyle, R.style.KeyboardView);
mDefaultKeyLabelFlags = keyAttr.getInt(R.styleable.Keyboard_Key_keyLabelFlags, 0);
mKeyVisualAttributes = KeyVisualAttributes.newInstance(keyAttr, mDrawableProvider);
if(isMoreKeys && mKeyVisualAttributes != null) {
if((isMoreKeys || isMoreKeysAction) && mKeyVisualAttributes != null) {
mKeyVisualAttributes.mTextColor = mDrawableProvider.getMoreKeysTextColor();
}
@ -382,12 +387,8 @@ public class KeyboardView extends View {
if (key.needsToKeepBackgroundAspectRatio(mDefaultKeyLabelFlags)
// HACK: To disable expanding normal/functional key background.
&& !key.hasCustomActionLabel()) {
final int intrinsicWidth = background.getIntrinsicWidth();
final int intrinsicHeight = background.getIntrinsicHeight();
final float minScale = Math.min(
keyWidth / (float)intrinsicWidth, keyHeight / (float)intrinsicHeight);
bgWidth = (int)(intrinsicWidth * minScale);
bgHeight = (int)(intrinsicHeight * minScale);
bgWidth = Math.min(keyWidth, keyHeight);
bgHeight = Math.min(keyWidth, keyHeight);
bgX = (keyWidth - bgWidth) / 2;
bgY = (keyHeight - bgHeight) / 2;
} else {
@ -535,6 +536,8 @@ public class KeyboardView extends View {
iconY = (keyHeight - iconHeight) / 2; // Align vertically center.
}
final int iconX = (keyWidth - iconWidth) / 2; // Align horizontally center.
icon.setTint(key.selectTextColor(params));
drawIcon(canvas, icon, iconX, iconY, iconWidth, iconHeight);
}

View File

@ -39,6 +39,7 @@ public final class KeyDrawParams {
public int mTextInactivatedColor;
public int mPressedTextColor;
public int mTextShadowColor;
public int mActionKeyTextColor;
public int mFunctionalTextColor;
public int mHintLetterColor;
public int mHintLabelColor;
@ -69,6 +70,7 @@ public final class KeyDrawParams {
mTextInactivatedColor = copyFrom.mTextInactivatedColor;
mPressedTextColor = copyFrom.mPressedTextColor;
mTextShadowColor = copyFrom.mTextShadowColor;
mActionKeyTextColor = copyFrom.mActionKeyTextColor;
mFunctionalTextColor = copyFrom.mFunctionalTextColor;
mHintLetterColor = copyFrom.mHintLetterColor;
mHintLabelColor = copyFrom.mHintLabelColor;
@ -107,6 +109,7 @@ public final class KeyDrawParams {
mTextInactivatedColor = selectColor(attr.mTextInactivatedColor, mTextInactivatedColor);
mPressedTextColor = selectColor(attr.mPressedTextColor, mPressedTextColor);
mTextShadowColor = selectColor(attr.mTextShadowColor, mTextShadowColor);
mActionKeyTextColor = selectColor(attr.mActionKeyTextColor, mActionKeyTextColor);
mFunctionalTextColor = selectColor(attr.mFunctionalTextColor, mFunctionalTextColor);
mHintLetterColor = selectColor(attr.mHintLetterColor, mHintLetterColor);
mHintLabelColor = selectColor(attr.mHintLabelColor, mHintLabelColor);

View File

@ -45,6 +45,7 @@ public final class KeyVisualAttributes {
public final int mTextInactivatedColor;
public final int mPressedTextColor;
public final int mTextShadowColor;
public final int mActionKeyTextColor;
public final int mFunctionalTextColor;
public final int mHintLetterColor;
public final int mHintLabelColor;
@ -135,6 +136,8 @@ public final class KeyVisualAttributes {
R.styleable.Keyboard_Key_keyPressedTextColor, 0, keyAttr, provider);
mTextShadowColor = DynamicThemeProvider.Companion.getColorOrDefault(
R.styleable.Keyboard_Key_keyTextShadowColor, 0, keyAttr, provider);
mActionKeyTextColor = DynamicThemeProvider.Companion.getColorOrDefault(
R.styleable.Keyboard_Key_actionKeyTextColor, 0, keyAttr, provider);
mFunctionalTextColor = DynamicThemeProvider.Companion.getColorOrDefault(
R.styleable.Keyboard_Key_functionalTextColor, 0, keyAttr, provider);
mHintLetterColor = DynamicThemeProvider.Companion.getColorOrDefault(

View File

@ -16,6 +16,8 @@
package org.futo.inputmethod.keyboard.internal;
import org.futo.inputmethod.latin.uix.actions.ActionRegistry;
import java.util.HashMap;
import java.util.Locale;
@ -480,7 +482,7 @@ public final class KeyboardTextsTable {
/* morekeys_single_quote */ "!fixedColumnOrder!5,!text/single_quotes,!text/single_angle_quotes",
/* morekeys_double_quote */ "!fixedColumnOrder!5,!text/double_quotes,!text/double_angle_quotes",
/* morekeys_tablet_double_quote */ "!fixedColumnOrder!6,!text/double_quotes,!text/single_quotes,!text/double_angle_quotes,!text/single_angle_quotes",
/* keyspec_emoji_action_key */ "!icon/emoji_action_key|!code/key_emoji",
/* keyspec_emoji_action_key */ ActionRegistry.INSTANCE.getEnterActions(),
};
/* Locale af: Afrikaans */

View File

@ -76,6 +76,7 @@ class BasicThemeProvider(val context: Context, val overrideColorScheme: ColorSch
override val moreKeysTextColor: Int
override val moreKeysKeyboardBackground: Drawable
override val popupKey: Drawable
override val actionPopupKey: Drawable
private val colors: HashMap<Int, Int> = HashMap()
override fun getColor(i: Int): Int? {
@ -237,6 +238,7 @@ class BasicThemeProvider(val context: Context, val overrideColorScheme: ColorSch
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_actionKeyTextColor] = enterKeyForeground
colors[R.styleable.Keyboard_Key_functionalTextColor] = onBackground
colors[R.styleable.Keyboard_Key_keyHintLetterColor] = onBackgroundHalf
colors[R.styleable.Keyboard_Key_keyHintLabelColor] = onBackgroundHalf
@ -413,6 +415,13 @@ class BasicThemeProvider(val context: Context, val overrideColorScheme: ColorSch
coloredRoundedRectangle(primaryContainer, dp(8.dp))
)
}
actionPopupKey = StateListDrawable().apply {
addStateWithHighlightLayerOnPressed(primary, intArrayOf(),
coloredRoundedRectangle(primaryContainer, dp(128.dp)),
128.dp
)
}
}
}

View File

@ -16,6 +16,7 @@ interface DynamicThemeProvider {
val moreKeysTextColor: Int
val moreKeysKeyboardBackground: Drawable
val popupKey: Drawable
val actionPopupKey: Drawable
@ColorInt
fun getColor(i: Int): Int?

View File

@ -27,6 +27,13 @@ val AllActions = listOf(
object ActionRegistry {
val EnterActions = "!fixedColumnOrder!4,!needsDividers!," +
listOf(SwitchLanguageAction, TextEditAction, ClipboardHistoryAction, EmojiAction, UndoAction, RedoAction).map {
AllActions.indexOf(it)
}.joinToString(separator = ",") {
"!icon/action_primary_$it|!code/action_$it"
}
fun stringToActions(string: String, defaults: List<Action>): List<Action> {
return string.split(",").mapNotNull { idx ->
idx.toIntOrNull()?.let { AllActions.getOrNull(it) }