mirror of
https://gitlab.futo.org/keyboard/latinime.git
synced 2024-09-28 14:54:30 +01:00
Convert Key.java to Key.kt, update key background handling to be less convoluted, update moreKeys width and background
This commit is contained in:
parent
4985afb348
commit
c644be00a2
@ -173,7 +173,7 @@ public class KeyboardAccessibilityDelegate<KV extends KeyboardView>
|
||||
String description = getKeyDescription(k);
|
||||
|
||||
if(description == null || description.isBlank()) {
|
||||
Log.e(TAG, "Invalid key has blank description: " + k.toLongString());
|
||||
Log.e(TAG, "Invalid key has blank description: " + k.toString());
|
||||
description = "Unknown";
|
||||
}
|
||||
|
||||
|
@ -250,10 +250,10 @@ public final class MainKeyboardAccessibilityDelegate
|
||||
// This long press has handled at {@link MainKeyboardView#onLongPress(PointerTracker)}.
|
||||
// We should ignore further hover events on this key.
|
||||
mBoundsToIgnoreHoverEvent.set(key.getHitBox());
|
||||
if (key.hasNoPanelAutoMoreKey()) {
|
||||
if (key.getHasNoPanelAutoMoreKey()) {
|
||||
// This long press has registered a code point without showing a more keys keyboard.
|
||||
// We should talk back the code point if possible.
|
||||
final int codePointOfNoPanelAutoMoreKey = key.getMoreKeys()[0].mCode;
|
||||
final int codePointOfNoPanelAutoMoreKey = key.getMoreKeys().get(0).mCode;
|
||||
final String text = KeyCodeDescriptionMapper.getInstance().getDescriptionForCodePoint(
|
||||
mKeyboardView.getContext(), codePointOfNoPanelAutoMoreKey);
|
||||
if (text != null) {
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -94,9 +94,6 @@ public class KeyboardView extends View {
|
||||
private final float mKeyTextShadowRadius;
|
||||
private final float mVerticalCorrection;
|
||||
private final Drawable mKeyboardBackground;
|
||||
private final Drawable mKeyBackground;
|
||||
private final Drawable mFunctionalKeyBackground;
|
||||
private final Drawable mSpacebarBackground;
|
||||
protected final DynamicThemeProvider mDrawableProvider;
|
||||
private final float mSpacebarIconWidthRatio;
|
||||
private final Rect mKeyBackgroundPadding = new Rect();
|
||||
@ -155,20 +152,10 @@ public class KeyboardView extends View {
|
||||
boolean isMoreKeys = keyAttr.getBoolean(R.styleable.Keyboard_Key_isMoreKey, false);
|
||||
boolean isMoreKeysAction = keyAttr.getBoolean(R.styleable.Keyboard_Key_isAction, false);
|
||||
|
||||
mKeyboardBackground = isMoreKeysAction ? null :
|
||||
isMoreKeys ? mDrawableProvider.getMoreKeysKeyboardBackground() :
|
||||
mKeyboardBackground = isMoreKeys ? mDrawableProvider.getMoreKeysKeyboardBackground() :
|
||||
mDrawableProvider.getKeyboardBackground();
|
||||
setBackground(mKeyboardBackground);
|
||||
|
||||
mKeyBackground = isMoreKeysAction ? mDrawableProvider.getActionPopupKey() :
|
||||
isMoreKeys ? mDrawableProvider.getPopupKey() :
|
||||
mDrawableProvider.getKeyBackground();
|
||||
mKeyBackground.getPadding(mKeyBackgroundPadding);
|
||||
|
||||
mFunctionalKeyBackground = mKeyBackground;
|
||||
|
||||
mSpacebarBackground = mDrawableProvider.getSpaceBarBackground();
|
||||
|
||||
mSpacebarIconWidthRatio = keyboardViewAttr.getFloat(
|
||||
R.styleable.KeyboardView_spacebarIconWidthRatio, 1.0f);
|
||||
mKeyHintLetterPadding = keyboardViewAttr.getDimension(
|
||||
@ -372,12 +359,9 @@ public class KeyboardView extends View {
|
||||
Math.min(key.getHeight(), key.getWidth()), attr);
|
||||
params.mAnimAlpha = Constants.Color.ALPHA_OPAQUE;
|
||||
|
||||
if (!key.isSpacer()) {
|
||||
final Drawable background = key.selectBackgroundDrawable(
|
||||
mKeyBackground, mFunctionalKeyBackground, mSpacebarBackground);
|
||||
if (background != null) {
|
||||
onDrawKeyBackground(key, canvas, background);
|
||||
}
|
||||
final Drawable background = key.selectBackground(mDrawableProvider);
|
||||
if (background != null) {
|
||||
onDrawKeyBackground(key, canvas, background);
|
||||
}
|
||||
onDrawKeyTopVisuals(key, canvas, paint, params);
|
||||
|
||||
@ -392,13 +376,15 @@ public class KeyboardView extends View {
|
||||
final int bgWidth, bgHeight, bgX, bgY;
|
||||
if (key.needsToKeepBackgroundAspectRatio(mDefaultKeyLabelFlags)
|
||||
// HACK: To disable expanding normal/functional key background.
|
||||
&& !key.hasCustomActionLabel()) {
|
||||
&& !key.getHasCustomActionLabel()) {
|
||||
bgWidth = Math.min(keyWidth, keyHeight);
|
||||
bgHeight = Math.min(keyWidth, keyHeight);
|
||||
bgX = (keyWidth - bgWidth) / 2;
|
||||
bgY = (keyHeight - bgHeight) / 2;
|
||||
} else {
|
||||
final Rect padding = mKeyBackgroundPadding;
|
||||
final Rect padding = new Rect();
|
||||
background.getPadding(padding);
|
||||
|
||||
bgWidth = keyWidth + padding.left + padding.right;
|
||||
bgHeight = keyHeight + padding.top + padding.bottom;
|
||||
bgX = -padding.left;
|
||||
@ -448,10 +434,10 @@ public class KeyboardView extends View {
|
||||
labelX = centerX;
|
||||
paint.setTextAlign(Align.CENTER);
|
||||
}
|
||||
if (key.needsAutoXScale()) {
|
||||
if (key.getNeedsAutoXScale()) {
|
||||
final float ratio = Math.min(1.0f, (keyWidth * MAX_LABEL_RATIO) /
|
||||
TypefaceUtils.getStringWidth(label, paint));
|
||||
if (key.needsAutoScale()) {
|
||||
if (key.getNeedsAutoScale()) {
|
||||
final float autoSize = paint.getTextSize() * ratio;
|
||||
paint.setTextSize(autoSize);
|
||||
} else {
|
||||
@ -460,7 +446,7 @@ public class KeyboardView extends View {
|
||||
}
|
||||
|
||||
if (key.isEnabled()) {
|
||||
paint.setColor(key.selectTextColor(params));
|
||||
paint.setColor(key.selectTextColor(mDrawableProvider, params));
|
||||
// Set a drop shadow for the text if the shadow radius is positive value.
|
||||
if (mKeyTextShadowRadius > 0.0f) {
|
||||
paint.setShadowLayer(mKeyTextShadowRadius, 0.0f, 0.0f, params.mTextShadowColor);
|
||||
@ -480,17 +466,17 @@ public class KeyboardView extends View {
|
||||
}
|
||||
|
||||
// Draw hint label.
|
||||
final String hintLabel = key.getHintLabel();
|
||||
final String hintLabel = key.getEffectiveHintLabel();
|
||||
if (hintLabel != null) {
|
||||
paint.setTextSize(key.selectHintTextSize(params));
|
||||
paint.setColor(key.selectHintTextColor(params));
|
||||
paint.setTextSize(key.selectHintTextSize(mDrawableProvider, params));
|
||||
paint.setColor(key.selectHintTextColor(mDrawableProvider, params));
|
||||
// TODO: Should add a way to specify type face for hint letters
|
||||
paint.setTypeface(Typeface.DEFAULT);
|
||||
blendAlpha(paint, params.mAnimAlpha);
|
||||
final float labelCharHeight = TypefaceUtils.getReferenceCharHeight(paint);
|
||||
final float labelCharWidth = TypefaceUtils.getReferenceCharWidth(paint);
|
||||
final float hintX, hintBaseline;
|
||||
if (key.hasHintLabel()) {
|
||||
if (key.getHasHintLabel()) {
|
||||
// The hint label is placed just right of the key label. Used mainly on
|
||||
// "phone number" layout.
|
||||
hintX = labelX + params.mHintLabelOffCenterRatio * labelCharWidth;
|
||||
@ -500,7 +486,7 @@ public class KeyboardView extends View {
|
||||
hintBaseline = centerY + labelCharHeight / 2.0f;
|
||||
}
|
||||
paint.setTextAlign(Align.CENTER);
|
||||
} else if (key.hasShiftedLetterHint()) {
|
||||
} else if (key.getHasShiftedLetterHint()) {
|
||||
// The hint label is placed at top-right corner of the key. Used mainly on tablet.
|
||||
hintX = keyWidth - mKeyShiftedLetterHintPadding - labelCharWidth / 2.0f;
|
||||
paint.getFontMetrics(mFontMetrics);
|
||||
@ -519,7 +505,7 @@ public class KeyboardView extends View {
|
||||
canvas.drawText(
|
||||
hintLabel, 0, hintLabel.length(), hintX, hintBaseline + adjustmentY, paint);
|
||||
} else if(hintIcon != null) {
|
||||
final float size = key.selectHintTextSize(params);
|
||||
final float size = key.selectHintTextSize(mDrawableProvider, params);
|
||||
|
||||
int iconWidth = (int)size;
|
||||
int iconHeight = (int)size;
|
||||
@ -527,7 +513,7 @@ public class KeyboardView extends View {
|
||||
int hintX = keyWidth - iconWidth - (int)mKeyHintLetterPadding;
|
||||
int hintY = (int)mKeyHintLetterPadding;
|
||||
|
||||
hintIcon.setTint(key.selectHintTextColor(params));
|
||||
hintIcon.setTint(key.selectHintTextColor(mDrawableProvider, params));
|
||||
drawIcon(canvas, hintIcon, hintX, hintY, iconWidth, iconHeight);
|
||||
}
|
||||
|
||||
@ -556,11 +542,11 @@ public class KeyboardView extends View {
|
||||
}
|
||||
final int iconX = (keyWidth - iconWidth) / 2; // Align horizontally center.
|
||||
|
||||
icon.setTint(key.selectTextColor(params));
|
||||
icon.setTint(key.selectTextColor(mDrawableProvider, params));
|
||||
drawIcon(canvas, icon, iconX, iconY, iconWidth, iconHeight);
|
||||
}
|
||||
|
||||
if (key.hasPopupHint() && key.getMoreKeys() != null) {
|
||||
if (key.getHasPopupHint() && !key.getMoreKeys().isEmpty()) {
|
||||
drawKeyPopupHint(key, canvas, paint, params);
|
||||
}
|
||||
}
|
||||
@ -599,7 +585,7 @@ public class KeyboardView extends View {
|
||||
paint.setTypeface(mKeyDrawParams.mTypeface);
|
||||
paint.setTextSize(mKeyDrawParams.mLabelSize);
|
||||
} else {
|
||||
paint.setColor(key.selectTextColor(mKeyDrawParams));
|
||||
paint.setColor(key.selectTextColor(mDrawableProvider, mKeyDrawParams));
|
||||
paint.setTypeface(key.selectTypeface(mKeyDrawParams));
|
||||
paint.setTextSize(key.selectTextSize(mKeyDrawParams));
|
||||
}
|
||||
|
@ -58,6 +58,7 @@ import org.futo.inputmethod.latin.common.CoordinateUtils;
|
||||
import org.futo.inputmethod.latin.utils.LanguageOnSpacebarUtils;
|
||||
import org.futo.inputmethod.latin.utils.TypefaceUtils;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.WeakHashMap;
|
||||
|
||||
@ -150,7 +151,6 @@ public final class MainKeyboardView extends KeyboardView implements DrawingProxy
|
||||
// More keys keyboard
|
||||
private final Paint mBackgroundDimAlphaPaint = new Paint();
|
||||
private final View mMoreKeysKeyboardContainer;
|
||||
private final View mMoreKeysKeyboardForActionContainer;
|
||||
private final WeakHashMap<Key, Keyboard> mMoreKeysKeyboardCache = new WeakHashMap<>();
|
||||
private final boolean mConfigShowMoreKeysKeyboardAtTouchedPoint;
|
||||
// More keys panel (used by both more keys keyboard and more suggestions view)
|
||||
@ -234,9 +234,6 @@ public final class MainKeyboardView extends KeyboardView implements DrawingProxy
|
||||
|
||||
final int moreKeysKeyboardLayoutId = mainKeyboardViewAttr.getResourceId(
|
||||
R.styleable.MainKeyboardView_moreKeysKeyboardLayout, 0);
|
||||
final int moreKeysKeyboardForActionLayoutId = mainKeyboardViewAttr.getResourceId(
|
||||
R.styleable.MainKeyboardView_moreKeysKeyboardForActionLayout,
|
||||
moreKeysKeyboardLayoutId);
|
||||
mConfigShowMoreKeysKeyboardAtTouchedPoint = mainKeyboardViewAttr.getBoolean(
|
||||
R.styleable.MainKeyboardView_showMoreKeysKeyboardAtTouchedPoint, false);
|
||||
|
||||
@ -258,8 +255,6 @@ public final class MainKeyboardView extends KeyboardView implements DrawingProxy
|
||||
|
||||
final LayoutInflater inflater = LayoutInflater.from(getContext());
|
||||
mMoreKeysKeyboardContainer = inflater.inflate(moreKeysKeyboardLayoutId, null);
|
||||
mMoreKeysKeyboardForActionContainer = inflater.inflate(
|
||||
moreKeysKeyboardForActionLayoutId, null);
|
||||
mLanguageOnSpacebarFadeoutAnimator = loadObjectAnimator(
|
||||
languageOnSpacebarFadeoutAnimatorResId, this);
|
||||
mAltCodeKeyWhileTypingFadeoutAnimator = loadObjectAnimator(
|
||||
@ -468,7 +463,7 @@ public final class MainKeyboardView extends KeyboardView implements DrawingProxy
|
||||
public void onKeyPressed(@Nonnull final Key key, final boolean withPreview) {
|
||||
key.onPressed();
|
||||
invalidateKey(key);
|
||||
if (withPreview && !key.noKeyPreview()) {
|
||||
if (withPreview && !key.getNoKeyPreview()) {
|
||||
showKeyPreview(key);
|
||||
}
|
||||
}
|
||||
@ -500,7 +495,7 @@ public final class MainKeyboardView extends KeyboardView implements DrawingProxy
|
||||
public void onKeyReleased(@Nonnull final Key key, final boolean withAnimation) {
|
||||
key.onReleased();
|
||||
invalidateKey(key);
|
||||
if (!key.noKeyPreview()) {
|
||||
if (!key.getNoKeyPreview()) {
|
||||
if (withAnimation) {
|
||||
dismissKeyPreview(key);
|
||||
} else {
|
||||
@ -597,8 +592,8 @@ public final class MainKeyboardView extends KeyboardView implements DrawingProxy
|
||||
@Nullable
|
||||
public MoreKeysPanel showMoreKeysKeyboard(@Nonnull final Key key,
|
||||
@Nonnull final PointerTracker tracker) {
|
||||
final MoreKeySpec[] moreKeys = key.getMoreKeys();
|
||||
if (moreKeys == null) {
|
||||
final List<MoreKeySpec> moreKeys = key.getMoreKeys();
|
||||
if (moreKeys.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
Keyboard moreKeysKeyboard = mMoreKeysKeyboardCache.get(key);
|
||||
@ -609,7 +604,7 @@ public final class MainKeyboardView extends KeyboardView implements DrawingProxy
|
||||
// will cause zero-division error at
|
||||
// {@link MoreKeysKeyboardParams#setParameters(int,int,int,int,int,int,boolean,int)}.
|
||||
final boolean isSingleMoreKeyWithPreview = mKeyPreviewDrawParams.isPopupEnabled()
|
||||
&& !key.noKeyPreview() && moreKeys.length == 1
|
||||
&& !key.getNoKeyPreview() && moreKeys.size() == 1
|
||||
&& mKeyPreviewDrawParams.getVisibleWidth() > 0;
|
||||
final MoreKeysKeyboard.Builder builder = new MoreKeysKeyboard.Builder(
|
||||
getContext(), key, getKeyboard(), isSingleMoreKeyWithPreview,
|
||||
@ -619,8 +614,7 @@ public final class MainKeyboardView extends KeyboardView implements DrawingProxy
|
||||
mMoreKeysKeyboardCache.put(key, moreKeysKeyboard);
|
||||
}
|
||||
|
||||
final View container = key.isActionKey() ? mMoreKeysKeyboardForActionContainer
|
||||
: mMoreKeysKeyboardContainer;
|
||||
final View container = mMoreKeysKeyboardContainer;
|
||||
final MoreKeysKeyboardView moreKeysKeyboardView =
|
||||
(MoreKeysKeyboardView)container.findViewById(R.id.more_keys_keyboard_view);
|
||||
moreKeysKeyboardView.setKeyboard(moreKeysKeyboard);
|
||||
@ -628,8 +622,7 @@ public final class MainKeyboardView extends KeyboardView implements DrawingProxy
|
||||
|
||||
final int[] lastCoords = CoordinateUtils.newInstance();
|
||||
tracker.getLastCoordinates(lastCoords);
|
||||
final boolean keyPreviewEnabled = mKeyPreviewDrawParams.isPopupEnabled()
|
||||
&& !key.noKeyPreview();
|
||||
final boolean keyPreviewEnabled = mKeyPreviewDrawParams.isPopupEnabled();
|
||||
// The more keys keyboard is usually horizontally aligned with the center of the parent key.
|
||||
// If showMoreKeysKeyboardAtTouchedPoint is true and the key preview is disabled, the more
|
||||
// keys keyboard is placed at the touch point of the parent key.
|
||||
@ -776,16 +769,7 @@ public final class MainKeyboardView extends KeyboardView implements DrawingProxy
|
||||
}
|
||||
|
||||
public void updateShortcutKey(final boolean available) {
|
||||
final Keyboard keyboard = getKeyboard();
|
||||
if (keyboard == null) {
|
||||
return;
|
||||
}
|
||||
final Key shortcutKey = keyboard.getKey(Constants.CODE_SHORTCUT);
|
||||
if (shortcutKey == null) {
|
||||
return;
|
||||
}
|
||||
shortcutKey.setEnabled(available);
|
||||
invalidateKey(shortcutKey);
|
||||
// TODO: Remove
|
||||
}
|
||||
|
||||
public void startDisplayLanguageOnSpacebar(final boolean subtypeChanged,
|
||||
@ -819,7 +803,7 @@ public final class MainKeyboardView extends KeyboardView implements DrawingProxy
|
||||
@Override
|
||||
protected void onDrawKeyTopVisuals(final Key key, final Canvas canvas, final Paint paint,
|
||||
final KeyDrawParams params) {
|
||||
if (key.altCodeWhileTyping() && key.isEnabled()) {
|
||||
if (key.getAltCodeWhileTyping() && key.isEnabled()) {
|
||||
params.mAnimAlpha = mAltCodeKeyWhileTypingAnimAlpha;
|
||||
}
|
||||
super.onDrawKeyTopVisuals(key, canvas, paint, params);
|
||||
|
@ -27,6 +27,8 @@ import org.futo.inputmethod.latin.R;
|
||||
import org.futo.inputmethod.latin.common.StringUtils;
|
||||
import org.futo.inputmethod.latin.utils.TypefaceUtils;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
public final class MoreKeysKeyboard extends Keyboard {
|
||||
@ -299,19 +301,16 @@ public final class MoreKeysKeyboard extends Keyboard {
|
||||
} else {
|
||||
final float padding = context.getResources().getDimension(
|
||||
R.dimen.config_more_keys_keyboard_key_horizontal_padding)
|
||||
+ (key.hasLabelsInMoreKeys()
|
||||
+ (key.getHasLabelsInMoreKeys()
|
||||
? mParams.mDefaultKeyWidth * LABEL_PADDING_RATIO : 0.0f);
|
||||
keyWidth = getMaxKeyWidth(key, mParams.mDefaultKeyWidth, padding, paintToMeasure);
|
||||
rowHeight = keyboard.mMostCommonKeyHeight;
|
||||
|
||||
int dimension = (int)(context.getResources().getDisplayMetrics().density * 44.5f);
|
||||
keyWidth = getMaxKeyWidth(key, Math.min(dimension, key.getTotalWidth()), padding, paintToMeasure);
|
||||
rowHeight = dimension;
|
||||
}
|
||||
final int dividerWidth;
|
||||
if (key.needsDividersInMoreKeys()) {
|
||||
dividerWidth = (int)(keyWidth * DIVIDER_RATIO);
|
||||
} else {
|
||||
dividerWidth = 0;
|
||||
}
|
||||
final MoreKeySpec[] moreKeys = key.getMoreKeys();
|
||||
mParams.setParameters(moreKeys.length, key.getMoreKeysColumnNumber(), keyWidth,
|
||||
final int dividerWidth = 0; // TODO: Remove divider
|
||||
final List<MoreKeySpec> moreKeys = key.getMoreKeys();
|
||||
mParams.setParameters(moreKeys.size(), key.getMoreKeysColumnNumber(), keyWidth,
|
||||
rowHeight, key.getX() + key.getWidth() / 2, keyboard.mId.mWidth,
|
||||
key.isMoreKeysFixedColumn(), key.isMoreKeysFixedOrder(), dividerWidth);
|
||||
}
|
||||
@ -335,36 +334,18 @@ public final class MoreKeysKeyboard extends Keyboard {
|
||||
public MoreKeysKeyboard build() {
|
||||
final MoreKeysKeyboardParams params = mParams;
|
||||
final int moreKeyFlags = mParentKey.getMoreKeyLabelFlags();
|
||||
final MoreKeySpec[] moreKeys = mParentKey.getMoreKeys();
|
||||
for (int n = 0; n < moreKeys.length; n++) {
|
||||
final MoreKeySpec moreKeySpec = moreKeys[n];
|
||||
final List<MoreKeySpec> moreKeys = mParentKey.getMoreKeys();
|
||||
for (int n = 0; n < moreKeys.size(); n++) {
|
||||
final MoreKeySpec moreKeySpec = moreKeys.get(n);
|
||||
final int row = n / params.mNumColumns;
|
||||
final int x = params.getX(n, row);
|
||||
final int y = params.getY(row);
|
||||
final Key key = moreKeySpec.buildKey(x, y, moreKeyFlags, params);
|
||||
params.markAsEdgeKey(key, row);
|
||||
params.onAddKey(key);
|
||||
|
||||
final int pos = params.getColumnPos(n);
|
||||
// The "pos" value represents the offset from the default position. Negative means
|
||||
// left of the default position.
|
||||
if (params.mDividerWidth > 0 && pos != 0) {
|
||||
final int dividerX = (pos > 0) ? x - params.mDividerWidth
|
||||
: x + params.mDefaultKeyWidth;
|
||||
final Key divider = new MoreKeyDivider(
|
||||
params, dividerX, y, params.mDividerWidth, params.mDefaultRowHeight);
|
||||
params.onAddKey(divider);
|
||||
}
|
||||
}
|
||||
return new MoreKeysKeyboard(params);
|
||||
}
|
||||
}
|
||||
|
||||
// Used as a divider maker. A divider is drawn by {@link MoreKeysKeyboardView}.
|
||||
public static class MoreKeyDivider extends Key.Spacer {
|
||||
public MoreKeyDivider(final KeyboardParams params, final int x, final int y,
|
||||
final int width, final int height) {
|
||||
super(params, x, y, width, height);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -88,8 +88,7 @@ public class MoreKeysKeyboardView extends KeyboardView implements MoreKeysPanel
|
||||
@Override
|
||||
protected void onDrawKeyTopVisuals(final Key key, final Canvas canvas, final Paint paint,
|
||||
final KeyDrawParams params) {
|
||||
if (!key.isSpacer() || !(key instanceof MoreKeysKeyboard.MoreKeyDivider)
|
||||
|| mDivider == null) {
|
||||
if (!key.isSpacer() || mDivider == null) {
|
||||
super.onDrawKeyTopVisuals(key, canvas, paint, params);
|
||||
return;
|
||||
}
|
||||
|
@ -291,7 +291,7 @@ public final class PointerTracker implements PointerTrackerQueue.Element,
|
||||
private void callListenerOnCodeInput(final Key key, final int primaryCode, final int x,
|
||||
final int y, final long eventTime, final boolean isKeyRepeat) {
|
||||
final boolean ignoreModifierKey = mIsInDraggingFinger && key.isModifier();
|
||||
final boolean altersCode = key.altCodeWhileTyping() && sTimerProxy.isTypingState();
|
||||
final boolean altersCode = key.getAltCodeWhileTyping() && sTimerProxy.isTypingState();
|
||||
final int code = altersCode ? key.getAltCode() : primaryCode;
|
||||
if (DEBUG_LISTENER) {
|
||||
final String output = code == Constants.CODE_OUTPUT_TEXT
|
||||
@ -412,7 +412,7 @@ public final class PointerTracker implements PointerTrackerQueue.Element,
|
||||
}
|
||||
}
|
||||
|
||||
if (key.altCodeWhileTyping()) {
|
||||
if (key.getAltCodeWhileTyping()) {
|
||||
final int altCode = key.getAltCode();
|
||||
final Key altKey = mKeyboard.getKey(altCode);
|
||||
if (altKey != null) {
|
||||
@ -437,7 +437,7 @@ public final class PointerTracker implements PointerTrackerQueue.Element,
|
||||
}
|
||||
|
||||
// Even if the key is disabled, it should respond if it is in the altCodeWhileTyping state.
|
||||
final boolean altersCode = key.altCodeWhileTyping() && sTimerProxy.isTypingState();
|
||||
final boolean altersCode = key.getAltCodeWhileTyping() && sTimerProxy.isTypingState();
|
||||
final boolean needsToUpdateGraphics = key.isEnabled() || altersCode;
|
||||
if (!needsToUpdateGraphics) {
|
||||
return;
|
||||
@ -1106,9 +1106,9 @@ public final class PointerTracker implements PointerTrackerQueue.Element,
|
||||
if (key == null) {
|
||||
return;
|
||||
}
|
||||
if (key.hasNoPanelAutoMoreKey()) {
|
||||
if (key.getHasNoPanelAutoMoreKey()) {
|
||||
cancelKeyTracking();
|
||||
final int moreKeyCode = key.getMoreKeys()[0].mCode;
|
||||
final int moreKeyCode = key.getMoreKeys().get(0).mCode;
|
||||
sListener.onPressKey(moreKeyCode, 0 /* repeatCont */, true /* isSinglePointer */);
|
||||
sListener.onCodeInput(moreKeyCode, Constants.NOT_A_COORDINATE,
|
||||
Constants.NOT_A_COORDINATE, false /* isKeyRepeat */);
|
||||
|
@ -46,7 +46,6 @@ import org.xmlpull.v1.XmlPullParser;
|
||||
import org.xmlpull.v1.XmlPullParserException;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
import java.util.Locale;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
@ -121,7 +120,7 @@ import javax.annotation.Nonnull;
|
||||
* </pre>
|
||||
*/
|
||||
|
||||
// TODO: Write unit tests for this class.
|
||||
// TODO: Remove this class, XML is no longer used for building keyboards
|
||||
public class KeyboardBuilder<KP extends KeyboardParams> {
|
||||
private static final String BUILDER_TAG = "Keyboard.Builder";
|
||||
private static final boolean DEBUG = false;
|
||||
@ -490,10 +489,10 @@ public class KeyboardBuilder<KP extends KeyboardParams> {
|
||||
final int y = row.getKeyY();
|
||||
final int width = (int)keyWidth;
|
||||
final int height = row.getRowHeight();
|
||||
final Key key = new Key(label, KeyboardIconsSet.ICON_UNDEFINED, code, outputText,
|
||||
null /* hintLabel */, labelFlags, backgroundType, x, y, width, height,
|
||||
mParams.mHorizontalGap, mParams.mVerticalGap, Key.ACTION_FLAGS_NO_KEY_PREVIEW);
|
||||
endKey(key);
|
||||
//final Key key = new Key(label, KeyboardIconsSet.ICON_UNDEFINED, code, outputText,
|
||||
// null /* hintLabel */, labelFlags, backgroundType, x, y, width, height,
|
||||
// mParams.mHorizontalGap, mParams.mVerticalGap, KeyConsts.ACTION_FLAGS_NO_KEY_PREVIEW);
|
||||
//endKey(key);
|
||||
row.advanceXPos(keyWidth);
|
||||
}
|
||||
endRow(row);
|
||||
@ -516,14 +515,14 @@ public class KeyboardBuilder<KP extends KeyboardParams> {
|
||||
if (TextUtils.isEmpty(keySpec)) {
|
||||
throw new ParseException("Empty keySpec", parser);
|
||||
}
|
||||
final Key key = new Key(keySpec, keyAttr, keyStyle, mParams, row);
|
||||
//final Key key = new Key(keySpec, keyAttr, keyStyle, mParams, row);
|
||||
keyAttr.recycle();
|
||||
if (DEBUG) {
|
||||
startEndTag("<%s%s %s moreKeys=%s />", TAG_KEY, (key.isEnabled() ? "" : " disabled"),
|
||||
key, Arrays.toString(key.getMoreKeys()));
|
||||
}
|
||||
//if (DEBUG) {
|
||||
// startEndTag("<%s%s %s moreKeys=%s />", TAG_KEY, (key.isEnabled() ? "" : " disabled"),
|
||||
// key, Arrays.toString(key.getMoreKeys()));
|
||||
//}
|
||||
XmlParseUtils.checkEndTag(TAG_KEY, parser);
|
||||
endKey(key);
|
||||
//endKey(key);
|
||||
}
|
||||
|
||||
private void parseSpacer(final XmlPullParser parser, final KeyboardRow row, final boolean skip)
|
||||
@ -536,11 +535,11 @@ public class KeyboardBuilder<KP extends KeyboardParams> {
|
||||
final TypedArray keyAttr = mResources.obtainAttributes(
|
||||
Xml.asAttributeSet(parser), R.styleable.Keyboard_Key);
|
||||
final KeyStyle keyStyle = mParams.mKeyStyles.getKeyStyle(keyAttr, parser);
|
||||
final Key spacer = new Key.Spacer(keyAttr, keyStyle, mParams, row);
|
||||
//final Key spacer = new Key.Spacer(keyAttr, keyStyle, mParams, row);
|
||||
keyAttr.recycle();
|
||||
if (DEBUG) startEndTag("<%s />", TAG_SPACER);
|
||||
XmlParseUtils.checkEndTag(TAG_SPACER, parser);
|
||||
endKey(spacer);
|
||||
//endKey(spacer);
|
||||
}
|
||||
|
||||
private void parseIncludeKeyboardContent(final XmlPullParser parser, final boolean skip)
|
||||
|
@ -133,7 +133,7 @@ public class KeyboardParams {
|
||||
if (key.getCode() == Constants.CODE_SHIFT) {
|
||||
mShiftKeys.add(key);
|
||||
}
|
||||
if (key.altCodeWhileTyping()) {
|
||||
if (key.getAltCodeWhileTyping()) {
|
||||
mAltCodeKeysWhileTyping.add(key);
|
||||
}
|
||||
}
|
||||
|
@ -20,7 +20,7 @@ import android.content.res.Resources;
|
||||
import android.content.res.TypedArray;
|
||||
import android.util.Xml;
|
||||
|
||||
import org.futo.inputmethod.keyboard.Key;
|
||||
import org.futo.inputmethod.keyboard.KeyConsts;
|
||||
import org.futo.inputmethod.keyboard.Keyboard;
|
||||
import org.futo.inputmethod.latin.R;
|
||||
import org.futo.inputmethod.latin.utils.ResourceUtils;
|
||||
@ -34,6 +34,7 @@ import java.util.ArrayDeque;
|
||||
* Some of the key size defaults can be overridden per row from what the {@link Keyboard}
|
||||
* defines.
|
||||
*/
|
||||
// TODO: Remove this class, it is no longer used
|
||||
public final class KeyboardRow {
|
||||
// keyWidth enum constants
|
||||
private static final int KEYWIDTH_NOT_ENUM = 0;
|
||||
@ -67,7 +68,7 @@ public final class KeyboardRow {
|
||||
keyboardWidth, keyboardWidth, defaultKeyWidth);
|
||||
mDefaultKeyLabelFlags = keyAttr.getInt(R.styleable.Keyboard_Key_keyLabelFlags, 0);
|
||||
mDefaultBackgroundType = keyAttr.getInt(R.styleable.Keyboard_Key_backgroundType,
|
||||
Key.BACKGROUND_TYPE_NORMAL);
|
||||
KeyConsts.BACKGROUND_TYPE_NORMAL);
|
||||
}
|
||||
|
||||
/**
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -84,9 +84,7 @@ public final class MoreKeySpec {
|
||||
@Nonnull
|
||||
public Key buildKey(final int x, final int y, final int labelFlags,
|
||||
@Nonnull final KeyboardParams params) {
|
||||
return new Key(mLabel, mIconId, mCode, mOutputText, null /* hintLabel */, labelFlags,
|
||||
Key.BACKGROUND_TYPE_NORMAL, x, y, params.mDefaultKeyWidth, params.mDefaultRowHeight,
|
||||
params.mHorizontalGap, params.mVerticalGap, Key.ACTION_FLAGS_NO_KEY_PREVIEW);
|
||||
return Key.buildKeyForMoreKeySpec(this, x, y, labelFlags, params);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -137,7 +137,7 @@ public final class TimerHandler extends LeakGuardHandlerWrapper<DrawingProxy>
|
||||
|
||||
@Override
|
||||
public void startTypingStateTimer(@Nonnull final Key typedKey) {
|
||||
if (typedKey.isModifier() || typedKey.altCodeWhileTyping()) {
|
||||
if (typedKey.isModifier() || typedKey.getAltCodeWhileTyping()) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -7,26 +7,23 @@ import android.graphics.drawable.LayerDrawable
|
||||
import android.graphics.drawable.ShapeDrawable
|
||||
import android.graphics.drawable.StateListDrawable
|
||||
import android.graphics.drawable.shapes.RoundRectShape
|
||||
import android.os.Build
|
||||
import android.util.Log
|
||||
import android.util.TypedValue
|
||||
import androidx.annotation.ColorInt
|
||||
import androidx.appcompat.content.res.AppCompatResources
|
||||
import androidx.compose.material3.ColorScheme
|
||||
import androidx.compose.material3.dynamicLightColorScheme
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.graphics.toArgb
|
||||
import androidx.compose.ui.unit.Dp
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.core.graphics.ColorUtils
|
||||
import androidx.datastore.preferences.core.Preferences
|
||||
import androidx.datastore.preferences.core.booleanPreferencesKey
|
||||
import androidx.datastore.preferences.core.floatPreferencesKey
|
||||
import com.google.android.material.color.DynamicColors
|
||||
import org.futo.inputmethod.keyboard.internal.KeyboardIconsSet
|
||||
import org.futo.inputmethod.latin.R
|
||||
import org.futo.inputmethod.latin.uix.actions.AllActions
|
||||
import org.futo.inputmethod.latin.uix.actions.AllActionsMap
|
||||
import org.futo.inputmethod.latin.uix.theme.DarkColorScheme
|
||||
import org.futo.inputmethod.v2keyboard.KeyVisualStyle
|
||||
import kotlin.math.roundToInt
|
||||
|
||||
val KeyBordersSetting = SettingsKey(booleanPreferencesKey("keyBorders"), true)
|
||||
@ -53,8 +50,6 @@ class BasicThemeProvider(val context: Context, val colorScheme: KeyboardColorSch
|
||||
|
||||
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? {
|
||||
@ -82,6 +77,11 @@ class BasicThemeProvider(val context: Context, val colorScheme: KeyboardColorSch
|
||||
return keyboardHeight
|
||||
}
|
||||
|
||||
val keyStyles: Map<KeyVisualStyle, VisualStyleDescriptor>
|
||||
override fun getKeyStyleDescriptor(visualStyle: KeyVisualStyle): VisualStyleDescriptor {
|
||||
return keyStyles[visualStyle]!!
|
||||
}
|
||||
|
||||
private fun dp(dp: Dp): Float {
|
||||
return TypedValue.applyDimension(
|
||||
TypedValue.COMPLEX_UNIT_DIP,
|
||||
@ -124,6 +124,17 @@ class BasicThemeProvider(val context: Context, val colorScheme: KeyboardColorSch
|
||||
addState(stateSet, drawable)
|
||||
}
|
||||
|
||||
private fun makeVisualStyle(background: Int, foreground: Int, highlight: Int, roundedness: Dp): VisualStyleDescriptor {
|
||||
val bg = coloredRoundedRectangle(background, dp(roundedness))
|
||||
val bgHighlight = coloredRoundedRectangle(highlight, dp(roundedness))
|
||||
return VisualStyleDescriptor(
|
||||
backgroundDrawable = bg,
|
||||
foregroundColor = foreground,
|
||||
|
||||
backgroundDrawablePressed = LayerDrawable(arrayOf(bg, bgHighlight))
|
||||
)
|
||||
}
|
||||
|
||||
val expertMode: Boolean
|
||||
val keyBorders: Boolean
|
||||
val showKeyHints: Boolean
|
||||
@ -272,44 +283,6 @@ class BasicThemeProvider(val context: Context, val colorScheme: KeyboardColorSch
|
||||
|
||||
keyboardBackground = coloredRectangle(primaryKeyboardColor)
|
||||
|
||||
keyBackground = StateListDrawable().apply {
|
||||
addStateWithHighlightLayerOnPressed(highlight, intArrayOf(android.R.attr.state_active),
|
||||
coloredRoundedRectangle(enterKeyBackground, dp(128.dp)),
|
||||
cornerRadius = 128.dp
|
||||
)
|
||||
|
||||
addStateWithHighlightLayerOnPressed(highlight, intArrayOf(android.R.attr.state_checkable, android.R.attr.state_checked),
|
||||
coloredRoundedRectangle(colorScheme.secondaryContainer.toArgb(), dp(8.dp))
|
||||
)
|
||||
|
||||
addStateWithHighlightLayerOnPressed(highlight, intArrayOf(android.R.attr.state_checkable),
|
||||
if(keyBorders) {
|
||||
coloredRoundedRectangle(keyColor, dp(8.dp))
|
||||
} else {
|
||||
coloredRectangle(transparent)
|
||||
}
|
||||
)
|
||||
|
||||
addStateWithHighlightLayerOnPressed(highlight, intArrayOf(android.R.attr.state_first),
|
||||
if(keyBorders) {
|
||||
coloredRoundedRectangle(functionalKeyColor, dp(8.dp))
|
||||
} else {
|
||||
coloredRectangle(transparent)
|
||||
}
|
||||
)
|
||||
|
||||
addStateWithHighlightLayerOnPressed(highlight, intArrayOf(android.R.attr.state_empty),
|
||||
coloredRectangle(transparent)
|
||||
)
|
||||
|
||||
addStateWithHighlightLayerOnPressed(highlight, intArrayOf(),
|
||||
if(keyBorders) {
|
||||
coloredRoundedRectangle(keyColor, dp(8.dp))
|
||||
} else {
|
||||
coloredRectangle(transparent)
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
val spaceCornerRadius = if(keyBorders) {
|
||||
8.dp
|
||||
@ -317,6 +290,99 @@ class BasicThemeProvider(val context: Context, val colorScheme: KeyboardColorSch
|
||||
48.dp
|
||||
}
|
||||
|
||||
keyStyles = mapOf(
|
||||
KeyVisualStyle.Action to VisualStyleDescriptor(
|
||||
backgroundDrawable = coloredRoundedRectangle(colorScheme.primary.toArgb(), dp(128.dp)),
|
||||
foregroundColor = colorScheme.onPrimary.toArgb(),
|
||||
|
||||
backgroundDrawablePressed = coloredRoundedRectangle(colorScheme.secondaryContainer.toArgb(), dp(128.dp)),
|
||||
foregroundColorPressed = colorScheme.onSecondaryContainer.toArgb()
|
||||
),
|
||||
|
||||
KeyVisualStyle.Normal to if(keyBorders) {
|
||||
makeVisualStyle(
|
||||
colorScheme.backgroundContainer.toArgb(),
|
||||
colorScheme.onBackgroundContainer.toArgb(),
|
||||
highlight,
|
||||
8.dp
|
||||
)
|
||||
} else {
|
||||
makeVisualStyle(
|
||||
transparent,
|
||||
onBackground,
|
||||
highlight,
|
||||
8.dp
|
||||
)
|
||||
},
|
||||
|
||||
KeyVisualStyle.MoreKey to VisualStyleDescriptor(
|
||||
backgroundDrawable = coloredRoundedRectangle(primaryContainer, dp(24.dp)),
|
||||
foregroundColor = onPrimaryContainer,
|
||||
|
||||
backgroundDrawablePressed = coloredRoundedRectangle(onPrimaryContainer, dp(24.dp)),
|
||||
foregroundColorPressed = primaryContainer
|
||||
),
|
||||
|
||||
KeyVisualStyle.Functional to if(keyBorders) {
|
||||
makeVisualStyle(
|
||||
colorScheme.backgroundContainerDim.toArgb(),
|
||||
colorScheme.onBackgroundContainer.toArgb(),
|
||||
highlight,
|
||||
8.dp
|
||||
)
|
||||
} else {
|
||||
makeVisualStyle(
|
||||
transparent,
|
||||
onBackground,
|
||||
highlight,
|
||||
8.dp
|
||||
)
|
||||
},
|
||||
|
||||
KeyVisualStyle.StickyOff to if(keyBorders) {
|
||||
makeVisualStyle(
|
||||
colorScheme.backgroundContainerDim.toArgb(),
|
||||
colorScheme.onBackgroundContainer.toArgb(),
|
||||
highlight,
|
||||
8.dp
|
||||
)
|
||||
} else {
|
||||
makeVisualStyle(
|
||||
transparent,
|
||||
onBackground,
|
||||
highlight,
|
||||
8.dp
|
||||
)
|
||||
},
|
||||
|
||||
KeyVisualStyle.NoBackground to makeVisualStyle(transparent, onBackground, highlight, 8.dp),
|
||||
|
||||
KeyVisualStyle.StickyOn to makeVisualStyle(
|
||||
colorScheme.secondaryContainer.toArgb(),
|
||||
colorScheme.onSecondaryContainer.toArgb(),
|
||||
highlight,
|
||||
8.dp
|
||||
),
|
||||
|
||||
KeyVisualStyle.Spacebar to when {
|
||||
keyBorders -> makeVisualStyle(keyColor, onKeyColor, highlight, spaceCornerRadius)
|
||||
expertMode -> makeVisualStyle(
|
||||
colorScheme.outline.copy(alpha = 0.1f).toArgb(),
|
||||
onKeyColor,
|
||||
highlight,
|
||||
spaceCornerRadius
|
||||
)
|
||||
else -> makeVisualStyle(
|
||||
highlight,
|
||||
onKeyColor,
|
||||
highlight,
|
||||
spaceCornerRadius
|
||||
)
|
||||
}
|
||||
)
|
||||
|
||||
keyBackground = keyStyles[KeyVisualStyle.Normal]!!.backgroundDrawable!!
|
||||
|
||||
val spaceDrawable = if(keyBorders) {
|
||||
coloredRoundedRectangle(keyColor, dp(spaceCornerRadius))
|
||||
} else if(expertMode) {
|
||||
@ -355,19 +421,11 @@ class BasicThemeProvider(val context: Context, val colorScheme: KeyboardColorSch
|
||||
}
|
||||
|
||||
moreKeysTextColor = onPrimaryContainer
|
||||
moreKeysKeyboardBackground = coloredRoundedRectangle(primaryContainer, dp(8.dp))
|
||||
popupKey = StateListDrawable().apply {
|
||||
addStateWithHighlightLayerOnPressed(primary, intArrayOf(),
|
||||
coloredRoundedRectangle(primaryContainer, dp(8.dp))
|
||||
)
|
||||
moreKeysKeyboardBackground = coloredRoundedRectangle(primaryContainer, dp(28.dp)).apply {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
|
||||
val padding = dp(4.dp).roundToInt()
|
||||
setPadding(padding, padding, padding, padding)
|
||||
}
|
||||
}
|
||||
actionPopupKey = StateListDrawable().apply {
|
||||
addStateWithHighlightLayerOnPressed(primary, intArrayOf(),
|
||||
coloredRoundedRectangle(primaryContainer, dp(128.dp)),
|
||||
128.dp
|
||||
)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -3,6 +3,24 @@ package org.futo.inputmethod.latin.uix
|
||||
import android.content.res.TypedArray
|
||||
import android.graphics.drawable.Drawable
|
||||
import androidx.annotation.ColorInt
|
||||
import org.futo.inputmethod.v2keyboard.KeyVisualStyle
|
||||
|
||||
/** Visual style descriptor for a key */
|
||||
data class VisualStyleDescriptor(
|
||||
/** Key background drawable when not pressed */
|
||||
val backgroundDrawable: Drawable?,
|
||||
|
||||
/** Key foreground label/icon color when not pressed */
|
||||
@ColorInt
|
||||
val foregroundColor: Int,
|
||||
|
||||
/** Key background drawable when pressed */
|
||||
val backgroundDrawablePressed: Drawable? = backgroundDrawable,
|
||||
|
||||
/** Key foreground label/icon color when pressed */
|
||||
@ColorInt
|
||||
val foregroundColorPressed: Int = foregroundColor
|
||||
)
|
||||
|
||||
interface DynamicThemeProvider {
|
||||
val primaryKeyboardColor: Int
|
||||
@ -16,8 +34,6 @@ interface DynamicThemeProvider {
|
||||
|
||||
val moreKeysTextColor: Int
|
||||
val moreKeysKeyboardBackground: Drawable
|
||||
val popupKey: Drawable
|
||||
val actionPopupKey: Drawable
|
||||
|
||||
@ColorInt
|
||||
fun getColor(i: Int): Int?
|
||||
@ -28,6 +44,8 @@ interface DynamicThemeProvider {
|
||||
|
||||
fun getKeyboardHeightMultiplier(): Float
|
||||
|
||||
fun getKeyStyleDescriptor(visualStyle: KeyVisualStyle): VisualStyleDescriptor
|
||||
|
||||
companion object {
|
||||
@ColorInt
|
||||
fun getColorOrDefault(i: Int, @ColorInt default: Int, keyAttr: TypedArray, provider: DynamicThemeProvider?): Int {
|
||||
|
@ -3,6 +3,7 @@ package org.futo.inputmethod.v2keyboard
|
||||
import kotlinx.serialization.SerialName
|
||||
import kotlinx.serialization.Serializable
|
||||
import kotlinx.serialization.builtins.serializer
|
||||
import org.futo.inputmethod.keyboard.KeyConsts
|
||||
import org.futo.inputmethod.keyboard.KeyboardId
|
||||
import org.futo.inputmethod.keyboard.internal.KeySpecParser
|
||||
import org.futo.inputmethod.keyboard.internal.KeyboardParams
|
||||
@ -10,8 +11,6 @@ import org.futo.inputmethod.keyboard.internal.MoreKeySpec
|
||||
import org.futo.inputmethod.latin.common.Constants
|
||||
import org.futo.inputmethod.latin.common.StringUtils
|
||||
|
||||
typealias KeyJ = org.futo.inputmethod.keyboard.Key
|
||||
|
||||
/**
|
||||
* Width tokens for keys. Rather than explicitly specifying a width in percentage as is common in
|
||||
* other layout systems, we instead use width tokens, which eliminates the need to explicitly
|
||||
@ -80,12 +79,12 @@ enum class KeyWidth {
|
||||
internal fun computeMoreKeysFlags(moreKeys: Array<String>, params: KeyboardParams): Int {
|
||||
// Get maximum column order number and set a relevant mode value.
|
||||
var moreKeysColumnAndFlags =
|
||||
(KeyJ.MORE_KEYS_MODE_MAX_COLUMN_WITH_AUTO_ORDER
|
||||
(KeyConsts.MORE_KEYS_MODE_MAX_COLUMN_WITH_AUTO_ORDER
|
||||
or params.mMaxMoreKeysKeyboardColumn)
|
||||
var value: Int
|
||||
if ((MoreKeySpec.getIntValue(
|
||||
moreKeys,
|
||||
KeyJ.MORE_KEYS_AUTO_COLUMN_ORDER,
|
||||
KeyConsts.MORE_KEYS_AUTO_COLUMN_ORDER,
|
||||
-1
|
||||
).also {
|
||||
value = it
|
||||
@ -93,12 +92,12 @@ internal fun computeMoreKeysFlags(moreKeys: Array<String>, params: KeyboardParam
|
||||
) {
|
||||
// Override with fixed column order number and set a relevant mode value.
|
||||
moreKeysColumnAndFlags =
|
||||
(KeyJ.MORE_KEYS_MODE_FIXED_COLUMN_WITH_AUTO_ORDER
|
||||
or (value and KeyJ.MORE_KEYS_COLUMN_NUMBER_MASK))
|
||||
(KeyConsts.MORE_KEYS_MODE_FIXED_COLUMN_WITH_AUTO_ORDER
|
||||
or (value and KeyConsts.MORE_KEYS_COLUMN_NUMBER_MASK))
|
||||
}
|
||||
if ((MoreKeySpec.getIntValue(
|
||||
moreKeys,
|
||||
KeyJ.MORE_KEYS_FIXED_COLUMN_ORDER,
|
||||
KeyConsts.MORE_KEYS_FIXED_COLUMN_ORDER,
|
||||
-1
|
||||
).also {
|
||||
value = it
|
||||
@ -106,43 +105,43 @@ internal fun computeMoreKeysFlags(moreKeys: Array<String>, params: KeyboardParam
|
||||
) {
|
||||
// Override with fixed column order number and set a relevant mode value.
|
||||
moreKeysColumnAndFlags =
|
||||
(KeyJ.MORE_KEYS_MODE_FIXED_COLUMN_WITH_FIXED_ORDER
|
||||
or (value and KeyJ.MORE_KEYS_COLUMN_NUMBER_MASK))
|
||||
(KeyConsts.MORE_KEYS_MODE_FIXED_COLUMN_WITH_FIXED_ORDER
|
||||
or (value and KeyConsts.MORE_KEYS_COLUMN_NUMBER_MASK))
|
||||
}
|
||||
if (MoreKeySpec.getBooleanValue(
|
||||
moreKeys,
|
||||
KeyJ.MORE_KEYS_HAS_LABELS
|
||||
KeyConsts.MORE_KEYS_HAS_LABELS
|
||||
)
|
||||
) {
|
||||
moreKeysColumnAndFlags =
|
||||
moreKeysColumnAndFlags or KeyJ.MORE_KEYS_FLAGS_HAS_LABELS
|
||||
moreKeysColumnAndFlags or KeyConsts.MORE_KEYS_FLAGS_HAS_LABELS
|
||||
}
|
||||
if (MoreKeySpec.getBooleanValue(
|
||||
moreKeys,
|
||||
KeyJ.MORE_KEYS_NEEDS_DIVIDERS
|
||||
KeyConsts.MORE_KEYS_NEEDS_DIVIDERS
|
||||
)
|
||||
) {
|
||||
moreKeysColumnAndFlags =
|
||||
moreKeysColumnAndFlags or KeyJ.MORE_KEYS_FLAGS_NEEDS_DIVIDERS
|
||||
moreKeysColumnAndFlags or KeyConsts.MORE_KEYS_FLAGS_NEEDS_DIVIDERS
|
||||
}
|
||||
if (MoreKeySpec.getBooleanValue(
|
||||
moreKeys,
|
||||
KeyJ.MORE_KEYS_NO_PANEL_AUTO_MORE_KEY
|
||||
KeyConsts.MORE_KEYS_NO_PANEL_AUTO_MORE_KEY
|
||||
)
|
||||
) {
|
||||
moreKeysColumnAndFlags =
|
||||
moreKeysColumnAndFlags or KeyJ.MORE_KEYS_FLAGS_NO_PANEL_AUTO_MORE_KEY
|
||||
moreKeysColumnAndFlags or KeyConsts.MORE_KEYS_FLAGS_NO_PANEL_AUTO_MORE_KEY
|
||||
}
|
||||
return moreKeysColumnAndFlags
|
||||
}
|
||||
|
||||
internal fun filterMoreKeysFlags(moreKeys: List<String>): List<String> =
|
||||
moreKeys.filter {
|
||||
!it.startsWith(KeyJ.MORE_KEYS_AUTO_COLUMN_ORDER) &&
|
||||
!it.startsWith(KeyJ.MORE_KEYS_FIXED_COLUMN_ORDER) &&
|
||||
!it.startsWith(KeyJ.MORE_KEYS_HAS_LABELS) &&
|
||||
!it.startsWith(KeyJ.MORE_KEYS_NEEDS_DIVIDERS) &&
|
||||
!it.startsWith(KeyJ.MORE_KEYS_NO_PANEL_AUTO_MORE_KEY)
|
||||
!it.startsWith(KeyConsts.MORE_KEYS_AUTO_COLUMN_ORDER) &&
|
||||
!it.startsWith(KeyConsts.MORE_KEYS_FIXED_COLUMN_ORDER) &&
|
||||
!it.startsWith(KeyConsts.MORE_KEYS_HAS_LABELS) &&
|
||||
!it.startsWith(KeyConsts.MORE_KEYS_NEEDS_DIVIDERS) &&
|
||||
!it.startsWith(KeyConsts.MORE_KEYS_NO_PANEL_AUTO_MORE_KEY)
|
||||
}
|
||||
|
||||
/**
|
||||
@ -165,10 +164,15 @@ enum class MoreKeyMode(
|
||||
*/
|
||||
OnlyFromKeyspec(true, false, false),
|
||||
|
||||
/**
|
||||
* Only automatically insert morekeys from coord, not keyspec shortcut.
|
||||
*/
|
||||
OnlyFromCoord(false, true, true),
|
||||
|
||||
/**
|
||||
* Do not automatically insert any morekeys.
|
||||
*/
|
||||
OnlyExplicit(false, false, false)
|
||||
OnlyExplicit(false, false, false),
|
||||
}
|
||||
|
||||
private fun Int.and(other: Boolean): Int {
|
||||
@ -190,14 +194,14 @@ data class LabelFlags(
|
||||
val autoXScale: Boolean = false,
|
||||
) {
|
||||
fun getValue(): Int =
|
||||
KeyJ.LABEL_FLAGS_ALIGN_LABEL_OFF_CENTER.and(alignLabelOffCenter) or
|
||||
KeyJ.LABEL_FLAGS_ALIGN_HINT_LABEL_TO_BOTTOM.and(alignHintLabelToBottom) or
|
||||
KeyJ.LABEL_FLAGS_ALIGN_ICON_TO_BOTTOM.and(alignIconToBottom) or
|
||||
KeyJ.LABEL_FLAGS_HAS_HINT_LABEL.and(hasHintLabel) or
|
||||
KeyJ.LABEL_FLAGS_FOLLOW_KEY_LABEL_RATIO.and(followKeyLabelRatio) or
|
||||
KeyJ.LABEL_FLAGS_FOLLOW_KEY_LETTER_RATIO.and(followKeyLetterRatio) or
|
||||
KeyJ.LABEL_FLAGS_FOLLOW_KEY_LARGE_LETTER_RATIO.and(followKeyLargeLetterRatio) or
|
||||
KeyJ.LABEL_FLAGS_AUTO_X_SCALE.and(autoXScale)
|
||||
KeyConsts.LABEL_FLAGS_ALIGN_LABEL_OFF_CENTER.and(alignLabelOffCenter) or
|
||||
KeyConsts.LABEL_FLAGS_ALIGN_HINT_LABEL_TO_BOTTOM.and(alignHintLabelToBottom) or
|
||||
KeyConsts.LABEL_FLAGS_ALIGN_ICON_TO_BOTTOM.and(alignIconToBottom) or
|
||||
KeyConsts.LABEL_FLAGS_HAS_HINT_LABEL.and(hasHintLabel) or
|
||||
KeyConsts.LABEL_FLAGS_FOLLOW_KEY_LABEL_RATIO.and(followKeyLabelRatio) or
|
||||
KeyConsts.LABEL_FLAGS_FOLLOW_KEY_LETTER_RATIO.and(followKeyLetterRatio) or
|
||||
KeyConsts.LABEL_FLAGS_FOLLOW_KEY_LARGE_LETTER_RATIO.and(followKeyLargeLetterRatio) or
|
||||
KeyConsts.LABEL_FLAGS_AUTO_X_SCALE.and(autoXScale)
|
||||
}
|
||||
|
||||
/**
|
||||
@ -583,20 +587,14 @@ enum class KeyVisualStyle {
|
||||
* the same as [Normal] (key borders enabled) or a
|
||||
* fully rounded rectangle (key borders disabled)
|
||||
*/
|
||||
Spacebar
|
||||
}
|
||||
Spacebar,
|
||||
|
||||
fun KeyVisualStyle.toBackgroundTypeInt(): Int = when(this) {
|
||||
KeyVisualStyle.Normal -> KeyJ.BACKGROUND_TYPE_NORMAL
|
||||
KeyVisualStyle.NoBackground -> KeyJ.BACKGROUND_TYPE_EMPTY
|
||||
KeyVisualStyle.Functional -> KeyJ.BACKGROUND_TYPE_FUNCTIONAL
|
||||
KeyVisualStyle.StickyOff -> KeyJ.BACKGROUND_TYPE_STICKY_OFF
|
||||
KeyVisualStyle.StickyOn -> KeyJ.BACKGROUND_TYPE_STICKY_ON
|
||||
KeyVisualStyle.Action -> KeyJ.BACKGROUND_TYPE_ACTION
|
||||
KeyVisualStyle.Spacebar -> KeyJ.BACKGROUND_TYPE_SPACEBAR
|
||||
/**
|
||||
* Visual style for moreKeys
|
||||
*/
|
||||
MoreKey,
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* An empty gap in place of a key
|
||||
*/
|
||||
|
@ -16,6 +16,7 @@ val KeySpecShortcuts = mapOf(
|
||||
"0" to listOf("keyspec_symbols_0", "additional_morekeys_symbols_0", "morekeys_symbols_0"),
|
||||
";" to listOf("keyspec_symbols_semicolon", "morekeys_symbols_semicolon"),
|
||||
"!" to listOf("!", "morekeys_exclamation"),
|
||||
"+" to listOf("+", "morekeys_plus"),
|
||||
"?" to listOf("keyspec_symbols_question", "morekeys_question"),
|
||||
"\"" to listOf("\"", "morekeys_double_quote"),
|
||||
"\'" to listOf("\'", "morekeys_single_quote"),
|
||||
|
@ -3,9 +3,7 @@ package org.futo.inputmethod.v2keyboard
|
||||
import android.content.Context
|
||||
import android.view.ContextThemeWrapper
|
||||
import androidx.compose.ui.unit.Dp
|
||||
import org.futo.inputmethod.keyboard.Key.ACTION_FLAGS_ENABLE_LONG_PRESS
|
||||
import org.futo.inputmethod.keyboard.Key.ACTION_FLAGS_IS_REPEATABLE
|
||||
import org.futo.inputmethod.keyboard.Key.ACTION_FLAGS_NO_KEY_PREVIEW
|
||||
import org.futo.inputmethod.keyboard.KeyConsts
|
||||
import org.futo.inputmethod.keyboard.internal.KeyboardLayoutElement
|
||||
import org.futo.inputmethod.keyboard.internal.KeyboardParams
|
||||
import org.futo.inputmethod.latin.R
|
||||
@ -458,9 +456,9 @@ data class LayoutEngine(
|
||||
return
|
||||
|
||||
|
||||
val actionsFlags = if(!data.showPopup) { ACTION_FLAGS_NO_KEY_PREVIEW } else { 0 } or
|
||||
if(data.longPressEnabled) { ACTION_FLAGS_ENABLE_LONG_PRESS } else { 0 } or
|
||||
if(data.repeatable) { ACTION_FLAGS_IS_REPEATABLE } else { 0 }
|
||||
val actionsFlags = if(!data.showPopup) { KeyConsts.ACTION_FLAGS_NO_KEY_PREVIEW } else { 0 } or
|
||||
if(data.longPressEnabled) { KeyConsts.ACTION_FLAGS_ENABLE_LONG_PRESS } else { 0 } or
|
||||
if(data.repeatable) { KeyConsts.ACTION_FLAGS_IS_REPEATABLE } else { 0 }
|
||||
|
||||
val verticalGapForKey = when {
|
||||
keyboard.rowHeightMode.clampHeight && height > layoutParams.standardRowHeight ->
|
||||
@ -471,25 +469,23 @@ data class LayoutEngine(
|
||||
} + verticalGapPx
|
||||
|
||||
val key = org.futo.inputmethod.keyboard.Key(
|
||||
data.label,
|
||||
data.icon,
|
||||
data.code,
|
||||
data.outputText,
|
||||
data.hint.ifEmpty { null },
|
||||
data.labelFlags,
|
||||
data.style.toBackgroundTypeInt(),
|
||||
x,
|
||||
y,
|
||||
width,
|
||||
height,
|
||||
horizontalGapPx.roundToInt(),
|
||||
verticalGapForKey.roundToInt(),
|
||||
actionsFlags
|
||||
code = data.code,
|
||||
label = data.label,
|
||||
width = width - horizontalGapPx.roundToInt(),
|
||||
height = height - verticalGapForKey.roundToInt(),
|
||||
iconId = data.icon,
|
||||
x = x,
|
||||
y = y,
|
||||
actionFlags = actionsFlags,
|
||||
horizontalGap = horizontalGapPx.roundToInt(),
|
||||
verticalGap = verticalGapForKey.roundToInt(),
|
||||
labelFlags = data.labelFlags,
|
||||
moreKeys = data.moreKeys,
|
||||
moreKeysColumnAndFlags = data.moreKeyFlags,
|
||||
visualStyle = data.style
|
||||
)
|
||||
|
||||
val key2 = org.futo.inputmethod.keyboard.Key(key, data.moreKeyFlags, data.moreKeys.toTypedArray())
|
||||
|
||||
params.onAddKey(key2)
|
||||
params.onAddKey(key)
|
||||
}
|
||||
|
||||
private fun addRow(row: List<LayoutEntry>, x: Float, y: Int, height: Int) {
|
||||
|
Loading…
Reference in New Issue
Block a user