Style text color and replace certain icons

This commit is contained in:
Aleksandras Kostarevas 2023-08-19 13:55:02 +03:00
parent 0b3af718b8
commit 996f09eb9d
12 changed files with 186 additions and 43 deletions

View File

@ -0,0 +1,27 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="26dp"
android:height="26dp"
android:viewportWidth="26"
android:viewportHeight="26">
<path
android:pathData="M22,5L9,5L2,13L9,21L22,21C23.105,21 24,20.105 24,19L24,7C24,5.895 23.105,5 22,5ZZ"
android:strokeLineJoin="round"
android:strokeWidth="2"
android:fillColor="#00000000"
android:strokeColor="#FFFFFF"
android:strokeLineCap="round"/>
<path
android:pathData="M19,10L13,16"
android:strokeLineJoin="round"
android:strokeWidth="2"
android:fillColor="#00000000"
android:strokeColor="#FFFFFF"
android:strokeLineCap="round"/>
<path
android:pathData="M13,10L19,16"
android:strokeLineJoin="round"
android:strokeWidth="2"
android:fillColor="#00000000"
android:strokeColor="#FFFFFF"
android:strokeLineCap="round"/>
</vector>

View File

@ -0,0 +1,27 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="26dp"
android:height="26dp"
android:viewportWidth="26"
android:viewportHeight="26">
<path
android:pathData="M3,13a10,10 0,1 0,20 0a10,10 0,1 0,-20 0z"
android:strokeLineJoin="round"
android:strokeWidth="2"
android:fillColor="#00000000"
android:strokeColor="#FFFFFF"
android:strokeLineCap="round"/>
<path
android:pathData="M3,13L23,13"
android:strokeLineJoin="round"
android:strokeWidth="2"
android:fillColor="#00000000"
android:strokeColor="#FFFFFF"
android:strokeLineCap="round"/>
<path
android:pathData="M13,3C15.501,5.738 16.923,9.292 17,13C16.923,16.708 15.501,20.262 13,23C10.499,20.262 9.077,16.708 9,13C9.077,9.292 10.499,5.738 13,3ZZ"
android:strokeLineJoin="round"
android:strokeWidth="2"
android:fillColor="#00000000"
android:strokeColor="#FFFFFF"
android:strokeLineCap="round"/>
</vector>

View File

@ -0,0 +1,12 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="26dp"
android:height="26dp"
android:viewportWidth="26"
android:viewportHeight="26">
<path
android:pathData="M8.407,21.5L8.407,13.567C6.65,13.567 4.689,13.567 2.5,13.567L13,3.5L23.5,13.567C23.5,13.567 23.5,13.567 17.594,13.567L17.594,21.5C17.594,21.5 17.594,21.5 8.407,21.5ZL8.407,21.5Z"
android:strokeLineJoin="round"
android:strokeWidth="2"
android:fillColor="#00000000"
android:strokeColor="#FFFFFF"/>
</vector>

View File

@ -0,0 +1,18 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="26dp"
android:height="26dp"
android:viewportWidth="26"
android:viewportHeight="26">
<path
android:pathData="M8.407,17.5L8.407,13.567C6.65,13.567 4.689,13.567 2.5,13.567L13,3.5L23.5,13.567C23.5,13.567 23.5,13.567 17.594,13.567L17.594,17.5C17.594,17.5 17.594,17.5 8.407,17.5ZL8.407,17.5Z"
android:strokeLineJoin="round"
android:strokeWidth="2"
android:fillColor="#00000000"
android:strokeColor="#FFFFFF"/>
<path
android:pathData="M8.5,21.5L17.5,21.5C17.5,21.5 17.5,21.5 8.5,21.5ZL8.5,21.5Z"
android:strokeLineJoin="round"
android:strokeWidth="2"
android:fillColor="#00000000"
android:strokeColor="#FFFFFF"/>
</vector>

View File

@ -402,7 +402,7 @@ public class Key implements Comparable<Key> {
: altCodeInAttr; : altCodeInAttr;
mOptionalAttributes = OptionalAttributes.newInstance(outputText, altCode, mOptionalAttributes = OptionalAttributes.newInstance(outputText, altCode,
disabledIconId, visualInsetsLeft, visualInsetsRight); disabledIconId, visualInsetsLeft, visualInsetsRight);
mKeyVisualAttributes = KeyVisualAttributes.newInstance(keyAttr); mKeyVisualAttributes = KeyVisualAttributes.newInstance(keyAttr, null);
mHashCode = computeHashCode(this); mHashCode = computeHashCode(this);
} }

View File

@ -175,7 +175,7 @@ public class KeyboardView extends View {
final TypedArray keyAttr = context.obtainStyledAttributes(attrs, final TypedArray keyAttr = context.obtainStyledAttributes(attrs,
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); mKeyVisualAttributes = KeyVisualAttributes.newInstance(keyAttr, mDrawableProvider);
keyAttr.recycle(); keyAttr.recycle();
mPaint.setAntiAlias(true); mPaint.setAntiAlias(true);

View File

@ -51,6 +51,7 @@ import org.futo.inputmethod.keyboard.internal.MoreKeySpec;
import org.futo.inputmethod.keyboard.internal.NonDistinctMultitouchHelper; import org.futo.inputmethod.keyboard.internal.NonDistinctMultitouchHelper;
import org.futo.inputmethod.keyboard.internal.SlidingKeyInputDrawingPreview; import org.futo.inputmethod.keyboard.internal.SlidingKeyInputDrawingPreview;
import org.futo.inputmethod.keyboard.internal.TimerHandler; import org.futo.inputmethod.keyboard.internal.TimerHandler;
import org.futo.inputmethod.latin.KeyboardDrawableProvider;
import org.futo.inputmethod.latin.R; import org.futo.inputmethod.latin.R;
import org.futo.inputmethod.latin.RichInputMethodSubtype; import org.futo.inputmethod.latin.RichInputMethodSubtype;
import org.futo.inputmethod.latin.SuggestedWords; import org.futo.inputmethod.latin.SuggestedWords;
@ -214,8 +215,10 @@ public final class MainKeyboardView extends KeyboardView implements DrawingProxy
mBackgroundDimAlphaPaint.setAlpha(backgroundDimAlpha); mBackgroundDimAlphaPaint.setAlpha(backgroundDimAlpha);
mLanguageOnSpacebarTextRatio = mainKeyboardViewAttr.getFraction( mLanguageOnSpacebarTextRatio = mainKeyboardViewAttr.getFraction(
R.styleable.MainKeyboardView_languageOnSpacebarTextRatio, 1, 1, 1.0f); R.styleable.MainKeyboardView_languageOnSpacebarTextRatio, 1, 1, 1.0f);
mLanguageOnSpacebarTextColor = mainKeyboardViewAttr.getColor( mLanguageOnSpacebarTextColor = KeyboardDrawableProvider.Companion.getColorOrDefault(
R.styleable.MainKeyboardView_languageOnSpacebarTextColor, 0); R.styleable.MainKeyboardView_languageOnSpacebarTextColor, 0,
mainKeyboardViewAttr, mDrawableProvider
);
mLanguageOnSpacebarTextShadowRadius = mainKeyboardViewAttr.getFloat( mLanguageOnSpacebarTextShadowRadius = mainKeyboardViewAttr.getFloat(
R.styleable.MainKeyboardView_languageOnSpacebarTextShadowRadius, R.styleable.MainKeyboardView_languageOnSpacebarTextShadowRadius,
LANGUAGE_ON_SPACEBAR_TEXT_SHADOW_RADIUS_DISABLED); LANGUAGE_ON_SPACEBAR_TEXT_SHADOW_RADIUS_DISABLED);

View File

@ -22,6 +22,7 @@ import android.content.Context;
import android.content.res.Resources; import android.content.res.Resources;
import android.content.res.TypedArray; import android.content.res.TypedArray;
import android.graphics.Color; import android.graphics.Color;
import android.graphics.drawable.Drawable;
import android.preference.PreferenceManager; import android.preference.PreferenceManager;
import androidx.viewpager.widget.ViewPager; import androidx.viewpager.widget.ViewPager;
import android.util.AttributeSet; import android.util.AttributeSet;
@ -374,14 +375,13 @@ public final class EmojiPalettesView extends LinearLayout implements OnTabChange
public void startEmojiPalettes(final String switchToAlphaLabel, public void startEmojiPalettes(final String switchToAlphaLabel,
final KeyVisualAttributes keyVisualAttr, final KeyVisualAttributes keyVisualAttr,
final KeyboardIconsSet iconSet) { final KeyboardIconsSet iconSet) {
final int deleteIconResId = iconSet.getIconResourceId(KeyboardIconsSet.NAME_DELETE_KEY); final Drawable deleteDrawable = iconSet.getIconDrawable(KeyboardIconsSet.getIconId(KeyboardIconsSet.NAME_DELETE_KEY));
if (deleteIconResId != 0) { if (deleteDrawable != null) {
mDeleteKey.setImageResource(deleteIconResId); mDeleteKey.setBackground(deleteDrawable); //?
} }
final int spacebarResId = iconSet.getIconResourceId(KeyboardIconsSet.NAME_SPACE_KEY); final Drawable spacebarDrawable = iconSet.getIconDrawable(KeyboardIconsSet.getIconId(KeyboardIconsSet.NAME_SPACE_KEY));
if (spacebarResId != 0) { if (spacebarDrawable != null) {
// TODO: Remove this workaround to place the spacebar icon. mSpacebarIcon.setBackground(spacebarDrawable);
mSpacebarIcon.setBackgroundResource(spacebarResId);
} }
final KeyDrawParams params = new KeyDrawParams(); final KeyDrawParams params = new KeyDrawParams();
params.updateParams(mEmojiLayoutParams.getActionBarHeight(), keyVisualAttr); params.updateParams(mEmojiLayoutParams.getActionBarHeight(), keyVisualAttr);

View File

@ -20,6 +20,7 @@ import android.content.res.TypedArray;
import android.graphics.Typeface; import android.graphics.Typeface;
import android.util.SparseIntArray; import android.util.SparseIntArray;
import org.futo.inputmethod.latin.KeyboardDrawableProvider;
import org.futo.inputmethod.latin.R; import org.futo.inputmethod.latin.R;
import org.futo.inputmethod.latin.utils.ResourceUtils; import org.futo.inputmethod.latin.utils.ResourceUtils;
@ -86,19 +87,19 @@ public final class KeyVisualAttributes {
} }
@Nullable @Nullable
public static KeyVisualAttributes newInstance(@Nonnull final TypedArray keyAttr) { public static KeyVisualAttributes newInstance(@Nonnull final TypedArray keyAttr, @Nullable final KeyboardDrawableProvider provider) {
final int indexCount = keyAttr.getIndexCount(); final int indexCount = keyAttr.getIndexCount();
for (int i = 0; i < indexCount; i++) { for (int i = 0; i < indexCount; i++) {
final int attrId = keyAttr.getIndex(i); final int attrId = keyAttr.getIndex(i);
if (sVisualAttributeIds.get(attrId, ATTR_NOT_FOUND) == ATTR_NOT_FOUND) { if (sVisualAttributeIds.get(attrId, ATTR_NOT_FOUND) == ATTR_NOT_FOUND) {
continue; continue;
} }
return new KeyVisualAttributes(keyAttr); return new KeyVisualAttributes(keyAttr, provider);
} }
return null; return null;
} }
private KeyVisualAttributes(@Nonnull final TypedArray keyAttr) { private KeyVisualAttributes(@Nonnull final TypedArray keyAttr, @Nullable final KeyboardDrawableProvider provider) {
if (keyAttr.hasValue(R.styleable.Keyboard_Key_keyTypeface)) { if (keyAttr.hasValue(R.styleable.Keyboard_Key_keyTypeface)) {
mTypeface = Typeface.defaultFromStyle( mTypeface = Typeface.defaultFromStyle(
keyAttr.getInt(R.styleable.Keyboard_Key_keyTypeface, Typeface.NORMAL)); keyAttr.getInt(R.styleable.Keyboard_Key_keyTypeface, Typeface.NORMAL));
@ -125,18 +126,24 @@ public final class KeyVisualAttributes {
mPreviewTextRatio = ResourceUtils.getFraction(keyAttr, mPreviewTextRatio = ResourceUtils.getFraction(keyAttr,
R.styleable.Keyboard_Key_keyPreviewTextRatio); R.styleable.Keyboard_Key_keyPreviewTextRatio);
mTextColor = keyAttr.getColor(R.styleable.Keyboard_Key_keyTextColor, 0); mTextColor = KeyboardDrawableProvider.Companion.getColorOrDefault(
mTextInactivatedColor = keyAttr.getColor( R.styleable.Keyboard_Key_keyTextColor, 0, keyAttr, provider);
R.styleable.Keyboard_Key_keyTextInactivatedColor, 0); mTextInactivatedColor = KeyboardDrawableProvider.Companion.getColorOrDefault(
mTextShadowColor = keyAttr.getColor(R.styleable.Keyboard_Key_keyTextShadowColor, 0); R.styleable.Keyboard_Key_keyTextInactivatedColor, 0, keyAttr, provider);
mFunctionalTextColor = keyAttr.getColor(R.styleable.Keyboard_Key_functionalTextColor, 0); mTextShadowColor = KeyboardDrawableProvider.Companion.getColorOrDefault(
mHintLetterColor = keyAttr.getColor(R.styleable.Keyboard_Key_keyHintLetterColor, 0); R.styleable.Keyboard_Key_keyTextShadowColor, 0, keyAttr, provider);
mHintLabelColor = keyAttr.getColor(R.styleable.Keyboard_Key_keyHintLabelColor, 0); mFunctionalTextColor = KeyboardDrawableProvider.Companion.getColorOrDefault(
mShiftedLetterHintInactivatedColor = keyAttr.getColor( R.styleable.Keyboard_Key_functionalTextColor, 0, keyAttr, provider);
R.styleable.Keyboard_Key_keyShiftedLetterHintInactivatedColor, 0); mHintLetterColor = KeyboardDrawableProvider.Companion.getColorOrDefault(
mShiftedLetterHintActivatedColor = keyAttr.getColor( R.styleable.Keyboard_Key_keyHintLetterColor, 0, keyAttr, provider);
R.styleable.Keyboard_Key_keyShiftedLetterHintActivatedColor, 0); mHintLabelColor = KeyboardDrawableProvider.Companion.getColorOrDefault(
mPreviewTextColor = keyAttr.getColor(R.styleable.Keyboard_Key_keyPreviewTextColor, 0); R.styleable.Keyboard_Key_keyHintLabelColor, 0, keyAttr, provider);
mShiftedLetterHintInactivatedColor = KeyboardDrawableProvider.Companion.getColorOrDefault(
R.styleable.Keyboard_Key_keyShiftedLetterHintInactivatedColor, 0, keyAttr, provider);
mShiftedLetterHintActivatedColor = KeyboardDrawableProvider.Companion.getColorOrDefault(
R.styleable.Keyboard_Key_keyShiftedLetterHintActivatedColor, 0, keyAttr, provider);
mPreviewTextColor = KeyboardDrawableProvider.Companion.getColorOrDefault(
R.styleable.Keyboard_Key_keyPreviewTextColor, 0, keyAttr, provider);
mHintLabelVerticalAdjustment = ResourceUtils.getFraction(keyAttr, mHintLabelVerticalAdjustment = ResourceUtils.getFraction(keyAttr,
R.styleable.Keyboard_Key_keyHintLabelVerticalAdjustment, 0.0f); R.styleable.Keyboard_Key_keyHintLabelVerticalAdjustment, 0.0f);

View File

@ -26,12 +26,15 @@ import android.util.AttributeSet;
import android.util.Log; import android.util.Log;
import android.util.TypedValue; import android.util.TypedValue;
import android.util.Xml; import android.util.Xml;
import android.view.ContextThemeWrapper;
import org.futo.inputmethod.annotations.UsedForTesting; import org.futo.inputmethod.annotations.UsedForTesting;
import org.futo.inputmethod.keyboard.Key; import org.futo.inputmethod.keyboard.Key;
import org.futo.inputmethod.keyboard.Keyboard; import org.futo.inputmethod.keyboard.Keyboard;
import org.futo.inputmethod.keyboard.KeyboardId; import org.futo.inputmethod.keyboard.KeyboardId;
import org.futo.inputmethod.keyboard.KeyboardTheme; import org.futo.inputmethod.keyboard.KeyboardTheme;
import org.futo.inputmethod.latin.KeyboardDrawableProvider;
import org.futo.inputmethod.latin.KeyboardDrawableProviderOwner;
import org.futo.inputmethod.latin.R; import org.futo.inputmethod.latin.R;
import org.futo.inputmethod.latin.common.Constants; import org.futo.inputmethod.latin.common.Constants;
import org.futo.inputmethod.latin.common.StringUtils; import org.futo.inputmethod.latin.common.StringUtils;
@ -150,8 +153,19 @@ public class KeyboardBuilder<KP extends KeyboardParams> {
private boolean mTopEdge; private boolean mTopEdge;
private Key mRightEdgeKey = null; private Key mRightEdgeKey = null;
private KeyboardDrawableProvider mProvider = null;
public KeyboardBuilder(final Context context, @Nonnull final KP params) { public KeyboardBuilder(final Context context, @Nonnull final KP params) {
mContext = context; mContext = context;
if(mContext instanceof KeyboardDrawableProviderOwner) {
mProvider = ((KeyboardDrawableProviderOwner) mContext).getDrawableProvider();
}else if(mContext instanceof ContextThemeWrapper) {
Context baseContext = ((ContextThemeWrapper) mContext).getBaseContext();
if(baseContext instanceof KeyboardDrawableProviderOwner) {
mProvider = ((KeyboardDrawableProviderOwner) baseContext).getDrawableProvider();
}
}
final Resources res = context.getResources(); final Resources res = context.getResources();
mResources = res; mResources = res;
@ -272,7 +286,7 @@ public class KeyboardBuilder<KP extends KeyboardParams> {
params.mDefaultRowHeight = (int)ResourceUtils.getDimensionOrFraction(keyboardAttr, params.mDefaultRowHeight = (int)ResourceUtils.getDimensionOrFraction(keyboardAttr,
R.styleable.Keyboard_rowHeight, baseHeight, baseHeight / DEFAULT_KEYBOARD_ROWS); R.styleable.Keyboard_rowHeight, baseHeight, baseHeight / DEFAULT_KEYBOARD_ROWS);
params.mKeyVisualAttributes = KeyVisualAttributes.newInstance(keyAttr); params.mKeyVisualAttributes = KeyVisualAttributes.newInstance(keyAttr, mProvider);
params.mMoreKeysTemplate = keyboardAttr.getResourceId( params.mMoreKeysTemplate = keyboardAttr.getResourceId(
R.styleable.Keyboard_moreKeysTemplate, 0); R.styleable.Keyboard_moreKeysTemplate, 0);
@ -280,7 +294,7 @@ public class KeyboardBuilder<KP extends KeyboardParams> {
R.styleable.Keyboard_Key_maxMoreKeysColumn, 5); R.styleable.Keyboard_Key_maxMoreKeysColumn, 5);
params.mThemeId = keyboardAttr.getInt(R.styleable.Keyboard_themeId, 0); params.mThemeId = keyboardAttr.getInt(R.styleable.Keyboard_themeId, 0);
params.mIconsSet.loadIcons(keyboardAttr); params.mIconsSet.loadIcons(keyboardAttr, mProvider);
params.mTextsSet.setLocale(params.mId.getLocale(), mContext); params.mTextsSet.setLocale(params.mId.getLocale(), mContext);
final int resourceId = keyboardAttr.getResourceId( final int resourceId = keyboardAttr.getResourceId(

View File

@ -22,6 +22,7 @@ import android.graphics.drawable.Drawable;
import android.util.Log; import android.util.Log;
import android.util.SparseIntArray; import android.util.SparseIntArray;
import org.futo.inputmethod.latin.KeyboardDrawableProvider;
import org.futo.inputmethod.latin.R; import org.futo.inputmethod.latin.R;
import java.util.HashMap; import java.util.HashMap;
@ -92,7 +93,6 @@ public final class KeyboardIconsSet {
private static int NUM_ICONS = NAMES_AND_ATTR_IDS.length / 2; private static int NUM_ICONS = NAMES_AND_ATTR_IDS.length / 2;
private static final String[] ICON_NAMES = new String[NUM_ICONS]; private static final String[] ICON_NAMES = new String[NUM_ICONS];
private final Drawable[] mIcons = new Drawable[NUM_ICONS]; private final Drawable[] mIcons = new Drawable[NUM_ICONS];
private final int[] mIconResourceIds = new int[NUM_ICONS];
static { static {
int iconId = ICON_UNDEFINED; int iconId = ICON_UNDEFINED;
@ -108,16 +108,15 @@ public final class KeyboardIconsSet {
} }
} }
public void loadIcons(final TypedArray keyboardAttrs) { public void loadIcons(final TypedArray keyboardAttrs, @Nullable KeyboardDrawableProvider provider) {
final int size = ATTR_ID_TO_ICON_ID.size(); final int size = ATTR_ID_TO_ICON_ID.size();
for (int index = 0; index < size; index++) { for (int index = 0; index < size; index++) {
final int attrId = ATTR_ID_TO_ICON_ID.keyAt(index); final int attrId = ATTR_ID_TO_ICON_ID.keyAt(index);
try { try {
final Drawable icon = keyboardAttrs.getDrawable(attrId); final Drawable icon = KeyboardDrawableProvider.Companion.getDrawableOrDefault(attrId, keyboardAttrs, provider);
setDefaultBounds(icon); setDefaultBounds(icon);
final Integer iconId = ATTR_ID_TO_ICON_ID.get(attrId); final Integer iconId = ATTR_ID_TO_ICON_ID.get(attrId);
mIcons[iconId] = icon; mIcons[iconId] = icon;
mIconResourceIds[iconId] = keyboardAttrs.getResourceId(attrId, 0);
} catch (Resources.NotFoundException e) { } catch (Resources.NotFoundException e) {
Log.w(TAG, "Drawable resource for icon #" Log.w(TAG, "Drawable resource for icon #"
+ keyboardAttrs.getResources().getResourceEntryName(attrId) + keyboardAttrs.getResources().getResourceEntryName(attrId)
@ -143,14 +142,6 @@ public final class KeyboardIconsSet {
throw new RuntimeException("unknown icon name: " + name); throw new RuntimeException("unknown icon name: " + name);
} }
public int getIconResourceId(final String name) {
final int iconId = getIconId(name);
if (isValidIconId(iconId)) {
return mIconResourceIds[iconId];
}
throw new RuntimeException("unknown icon name: " + name);
}
@Nullable @Nullable
public Drawable getIconDrawable(final int iconId) { public Drawable getIconDrawable(final int iconId) {
if (isValidIconId(iconId)) { if (isValidIconId(iconId)) {

View File

@ -2,6 +2,7 @@ package org.futo.inputmethod.latin
import android.content.Context import android.content.Context
import android.content.res.Configuration import android.content.res.Configuration
import android.content.res.TypedArray
import android.graphics.Color import android.graphics.Color
import android.graphics.drawable.Drawable import android.graphics.drawable.Drawable
import android.graphics.drawable.GradientDrawable import android.graphics.drawable.GradientDrawable
@ -9,10 +10,9 @@ import android.graphics.drawable.InsetDrawable
import android.graphics.drawable.LayerDrawable import android.graphics.drawable.LayerDrawable
import android.graphics.drawable.ShapeDrawable import android.graphics.drawable.ShapeDrawable
import android.graphics.drawable.StateListDrawable import android.graphics.drawable.StateListDrawable
import android.graphics.drawable.shapes.OvalShape
import android.graphics.drawable.shapes.RoundRectShape import android.graphics.drawable.shapes.RoundRectShape
import android.graphics.drawable.shapes.Shape
import android.inputmethodservice.InputMethodService import android.inputmethodservice.InputMethodService
import android.util.AttributeSet
import android.util.TypedValue import android.util.TypedValue
import android.view.KeyEvent import android.view.KeyEvent
import android.view.View import android.view.View
@ -21,13 +21,13 @@ import android.view.inputmethod.EditorInfo
import android.view.inputmethod.InputMethodManager import android.view.inputmethod.InputMethodManager
import android.view.inputmethod.InputMethodSubtype import android.view.inputmethod.InputMethodSubtype
import androidx.annotation.ColorInt import androidx.annotation.ColorInt
import androidx.appcompat.content.res.AppCompatResources
import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Spacer import androidx.compose.foundation.layout.Spacer
import androidx.compose.material3.MaterialTheme import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Surface import androidx.compose.material3.Surface
import androidx.compose.runtime.key import androidx.compose.runtime.key
import androidx.compose.ui.Modifier import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.RectangleShape
import androidx.compose.ui.graphics.toArgb import androidx.compose.ui.graphics.toArgb
import androidx.compose.ui.layout.onSizeChanged import androidx.compose.ui.layout.onSizeChanged
import androidx.compose.ui.platform.ComposeView import androidx.compose.ui.platform.ComposeView
@ -65,6 +65,22 @@ interface KeyboardDrawableProvider {
val moreKeysKeyboardBackground: Drawable val moreKeysKeyboardBackground: Drawable
val popupKey: Drawable val popupKey: Drawable
@ColorInt
fun getColor(i: Int): Int?
fun getDrawable(i: Int): Drawable?
companion object {
@ColorInt
fun getColorOrDefault(i: Int, @ColorInt default: Int, keyAttr: TypedArray, provider: KeyboardDrawableProvider?): Int {
return (provider?.getColor(i)) ?: keyAttr.getColor(i, default)
}
fun getDrawableOrDefault(i: Int, keyAttr: TypedArray, provider: KeyboardDrawableProvider?): Drawable? {
return (provider?.getDrawable(i)) ?: keyAttr.getDrawable(i)
}
}
} }
// TODO: Expand the number of drawables this provides so it covers the full theme, and // TODO: Expand the number of drawables this provides so it covers the full theme, and
@ -81,6 +97,17 @@ class BasicThemeProvider(val context: Context) : KeyboardDrawableProvider {
override val moreKeysKeyboardBackground: Drawable override val moreKeysKeyboardBackground: Drawable
override val popupKey: Drawable override val popupKey: Drawable
private val colors: HashMap<Int, Int> = HashMap()
override fun getColor(i: Int): Int? {
return colors[i]
}
private val drawables: HashMap<Int, Drawable> = HashMap()
override fun getDrawable(i: Int): Drawable? {
return drawables[i]
}
private fun dp(dp: Dp): Float { private fun dp(dp: Dp): Float {
return TypedValue.applyDimension( return TypedValue.applyDimension(
TypedValue.COMPLEX_UNIT_DIP, TypedValue.COMPLEX_UNIT_DIP,
@ -130,6 +157,23 @@ class BasicThemeProvider(val context: Context) : KeyboardDrawableProvider {
val transparent = Color.TRANSPARENT val transparent = Color.TRANSPARENT
colors[R.styleable.Keyboard_Key_keyTextColor] = DarkColorScheme.onBackground.toArgb()
colors[R.styleable.Keyboard_Key_keyTextInactivatedColor] = DarkColorScheme.onBackground.copy(alpha = 0.5f).toArgb()
colors[R.styleable.Keyboard_Key_keyTextShadowColor] = 0
colors[R.styleable.Keyboard_Key_functionalTextColor] = DarkColorScheme.onBackground.toArgb()
colors[R.styleable.Keyboard_Key_keyHintLetterColor] = DarkColorScheme.onBackground.copy(alpha = 0.5f).toArgb()
colors[R.styleable.Keyboard_Key_keyHintLabelColor] = DarkColorScheme.onBackground.copy(alpha = 0.5f).toArgb()
colors[R.styleable.Keyboard_Key_keyShiftedLetterHintInactivatedColor] = DarkColorScheme.onBackground.copy(alpha = 0.5f).toArgb()
colors[R.styleable.Keyboard_Key_keyShiftedLetterHintActivatedColor] = DarkColorScheme.onBackground.copy(alpha = 0.5f).toArgb()
colors[R.styleable.Keyboard_Key_keyPreviewTextColor] = DarkColorScheme.onBackground.toArgb()
colors[R.styleable.MainKeyboardView_languageOnSpacebarTextColor] = DarkColorScheme.onBackground.copy(alpha = 0.5f).toArgb()
drawables[R.styleable.Keyboard_iconDeleteKey] = AppCompatResources.getDrawable(context, R.drawable.delete)!!
drawables[R.styleable.Keyboard_iconLanguageSwitchKey] = AppCompatResources.getDrawable(context, R.drawable.globe)!!
drawables[R.styleable.Keyboard_iconShiftKey] = AppCompatResources.getDrawable(context, R.drawable.shift)!!
drawables[R.styleable.Keyboard_iconShiftKeyShifted] = AppCompatResources.getDrawable(context, R.drawable.shiftshifted)!!
primaryKeyboardColor = background primaryKeyboardColor = background
keyboardBackground = LayerDrawable(arrayOf( keyboardBackground = LayerDrawable(arrayOf(