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