From 377cb16600e0a3a194dc7f8274b7a43a47b92433 Mon Sep 17 00:00:00 2001 From: devycarol <[email protected]> Date: Mon, 12 Jan 2026 13:56:59 -0700 Subject: [PATCH 1/7] pointless finals --- .../keyboard/keyboard/KeyboardId.java | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/app/src/main/java/helium314/keyboard/keyboard/KeyboardId.java b/app/src/main/java/helium314/keyboard/keyboard/KeyboardId.java index 3c5de6925e..91a6076fc2 100644 --- a/app/src/main/java/helium314/keyboard/keyboard/KeyboardId.java +++ b/app/src/main/java/helium314/keyboard/keyboard/KeyboardId.java @@ -87,7 +87,7 @@ public final class KeyboardId { private final int mHashCode; - public KeyboardId(final int elementId, final KeyboardLayoutSet.Params params) { + public KeyboardId(int elementId, KeyboardLayoutSet.Params params) { mSubtype = params.mSubtype; mWidth = params.mKeyboardWidth; mHeight = params.mKeyboardHeight; @@ -109,7 +109,7 @@ public KeyboardId(final int elementId, final KeyboardLayoutSet.Params params) { mHashCode = computeHashCode(this); } - private static int computeHashCode(final KeyboardId id) { + private static int computeHashCode(KeyboardId id) { return Arrays.hashCode(new Object[] { id.mElementId, id.mMode, @@ -132,7 +132,7 @@ private static int computeHashCode(final KeyboardId id) { }); } - private boolean equals(final KeyboardId other) { + private boolean equals(KeyboardId other) { if (other == this) return true; return other.mElementId == mElementId @@ -155,7 +155,7 @@ private boolean equals(final KeyboardId other) { && Objects.equals(other.mInternalAction, mInternalAction); } - private static boolean isAlphabetKeyboard(final int elementId) { + private static boolean isAlphabetKeyboard(int elementId) { return elementId < ELEMENT_SYMBOLS; } @@ -178,7 +178,7 @@ public boolean navigatePrevious() { } public boolean passwordInput() { - final int inputType = mEditorInfo.inputType; + int inputType = mEditorInfo.inputType; return InputTypeUtils.isAnyPasswordInputType(inputType); } @@ -218,7 +218,7 @@ public Locale getLocale() { } @Override - public boolean equals(final Object other) { + public boolean equals(Object other) { return other instanceof KeyboardId && equals((KeyboardId) other); } @@ -249,7 +249,7 @@ public String toString() { ); } - public static boolean equivalentEditorInfoForKeyboard(final EditorInfo a, final EditorInfo b) { + public static boolean equivalentEditorInfoForKeyboard(EditorInfo a, EditorInfo b) { if (a == null && b == null) return true; if (a == null || b == null) return false; return a.inputType == b.inputType @@ -257,7 +257,7 @@ public static boolean equivalentEditorInfoForKeyboard(final EditorInfo a, final && TextUtils.equals(a.privateImeOptions, b.privateImeOptions); } - public static String elementIdToName(final int elementId) { + public static String elementIdToName(int elementId) { return switch (elementId) { case ELEMENT_ALPHABET -> "alphabet"; case ELEMENT_ALPHABET_MANUAL_SHIFTED -> "alphabetManualShifted"; @@ -292,7 +292,7 @@ public static String elementIdToName(final int elementId) { }; } - public static String modeName(final int mode) { + public static String modeName(int mode) { return switch (mode) { case MODE_TEXT -> "text"; case MODE_URL -> "url"; @@ -308,7 +308,7 @@ public static String modeName(final int mode) { }; } - public static String actionName(final int actionId) { + public static String actionName(int actionId) { return (actionId == InputTypeUtils.IME_ACTION_CUSTOM_LABEL) ? "actionCustomLabel" : EditorInfoCompatUtils.imeActionName(actionId); } From 317d68af9d9e766fa2f5717ce35c8202cd1167a7 Mon Sep 17 00:00:00 2001 From: devycarol <[email protected]> Date: Mon, 12 Jan 2026 14:11:41 -0700 Subject: [PATCH 2/7] 'm' prefix is confising for public fields --- .../accessibility/KeyCodeDescriptionMapper.kt | 4 +- .../KeyboardAccessibilityNodeProvider.kt | 2 +- .../MainKeyboardAccessibilityDelegate.kt | 18 +- .../java/helium314/keyboard/keyboard/Key.java | 4 +- .../helium314/keyboard/keyboard/Keyboard.java | 4 +- .../keyboard/KeyboardActionListenerImpl.kt | 2 +- .../keyboard/keyboard/KeyboardId.java | 174 +++++++++--------- .../keyboard/keyboard/KeyboardLayoutSet.java | 4 +- .../keyboard/keyboard/KeyboardSwitcher.java | 6 +- .../keyboard/keyboard/KeyboardView.java | 8 +- .../keyboard/keyboard/MainKeyboardView.java | 4 +- .../keyboard/keyboard/PopupKeysKeyboard.java | 4 +- .../keyboard/internal/KeyboardBuilder.kt | 12 +- .../keyboard/internal/KeyboardParams.java | 6 +- .../internal/keyboard_parser/EmojiParser.kt | 6 +- .../keyboard_parser/KeyboardParser.kt | 16 +- .../internal/keyboard_parser/LayoutParser.kt | 4 +- .../keyboard_parser/floris/KeyData.kt | 30 +-- .../keyboard_parser/floris/KeyLabel.kt | 14 +- .../keyboard_parser/floris/TextKeyData.kt | 36 ++-- .../helium314/keyboard/latin/LatinIME.java | 2 +- .../keyboard/latin/inputlogic/InputLogic.java | 2 +- .../keyboard/latin/utils/PopupKeysUtils.kt | 2 +- 23 files changed, 182 insertions(+), 182 deletions(-) diff --git a/app/src/main/java/helium314/keyboard/accessibility/KeyCodeDescriptionMapper.kt b/app/src/main/java/helium314/keyboard/accessibility/KeyCodeDescriptionMapper.kt index cd1841ce67..36c7af5337 100644 --- a/app/src/main/java/helium314/keyboard/accessibility/KeyCodeDescriptionMapper.kt +++ b/app/src/main/java/helium314/keyboard/accessibility/KeyCodeDescriptionMapper.kt @@ -129,7 +129,7 @@ internal class KeyCodeDescriptionMapper private constructor() { * @return a character sequence describing the action performed by pressing the key */ private fun getDescriptionForSwitchAlphaSymbol(context: Context, keyboard: Keyboard?): String? { - val resId = when (val elementId = keyboard?.mId?.mElementId) { + val resId = when (val elementId = keyboard?.mId?.elementId) { KeyboardId.ELEMENT_ALPHABET, KeyboardId.ELEMENT_ALPHABET_AUTOMATIC_SHIFTED, KeyboardId.ELEMENT_ALPHABET_MANUAL_SHIFTED, KeyboardId.ELEMENT_ALPHABET_SHIFT_LOCK_SHIFTED, KeyboardId.ELEMENT_ALPHABET_SHIFT_LOCKED -> R.string.spoken_description_to_symbol KeyboardId.ELEMENT_SYMBOLS, KeyboardId.ELEMENT_SYMBOLS_SHIFTED -> R.string.spoken_description_to_alpha KeyboardId.ELEMENT_PHONE -> R.string.spoken_description_to_symbol @@ -150,7 +150,7 @@ internal class KeyCodeDescriptionMapper private constructor() { * @return A context-sensitive description of the "Shift" key. */ private fun getDescriptionForShiftKey(context: Context, keyboard: Keyboard?): String { - val resId: Int = when (keyboard?.mId?.mElementId) { + val resId: Int = when (keyboard?.mId?.elementId) { KeyboardId.ELEMENT_ALPHABET_SHIFT_LOCK_SHIFTED, KeyboardId.ELEMENT_ALPHABET_SHIFT_LOCKED -> R.string.spoken_description_caps_lock KeyboardId.ELEMENT_ALPHABET_AUTOMATIC_SHIFTED, KeyboardId.ELEMENT_ALPHABET_MANUAL_SHIFTED -> R.string.spoken_description_shift_shifted KeyboardId.ELEMENT_SYMBOLS -> R.string.spoken_description_symbols_shift diff --git a/app/src/main/java/helium314/keyboard/accessibility/KeyboardAccessibilityNodeProvider.kt b/app/src/main/java/helium314/keyboard/accessibility/KeyboardAccessibilityNodeProvider.kt index 15dcbb97b0..32d599fbe5 100644 --- a/app/src/main/java/helium314/keyboard/accessibility/KeyboardAccessibilityNodeProvider.kt +++ b/app/src/main/java/helium314/keyboard/accessibility/KeyboardAccessibilityNodeProvider.kt @@ -269,7 +269,7 @@ class KeyboardAccessibilityNodeProvider( * @return The context-specific description of the key. */ private fun getKeyDescription(key: Key): String? { - val editorInfo = mKeyboard?.mId?.mEditorInfo + val editorInfo = mKeyboard?.mId?.editorInfo val shouldObscure = mAccessibilityUtils.shouldObscureInput(editorInfo) val currentSettings = Settings.getValues() val keyCodeDescription = mKeyCodeDescriptionMapper.getDescriptionForKey( diff --git a/app/src/main/java/helium314/keyboard/accessibility/MainKeyboardAccessibilityDelegate.kt b/app/src/main/java/helium314/keyboard/accessibility/MainKeyboardAccessibilityDelegate.kt index 6a4283494e..e421df9bb3 100644 --- a/app/src/main/java/helium314/keyboard/accessibility/MainKeyboardAccessibilityDelegate.kt +++ b/app/src/main/java/helium314/keyboard/accessibility/MainKeyboardAccessibilityDelegate.kt @@ -47,24 +47,24 @@ class MainKeyboardAccessibilityDelegate( val lastKeyboard = super.keyboard super.keyboard = keyboard val lastKeyboardMode = mLastKeyboardMode - mLastKeyboardMode = keyboard.mId.mMode + mLastKeyboardMode = keyboard.mId.mode // Since this method is called even when accessibility is off, make sure // to check the state before announcing anything. if (!AccessibilityUtils.instance.isAccessibilityEnabled) { return } // Announce the language name only when the language is changed. - if (lastKeyboard == null || keyboard.mId.mSubtype != lastKeyboard.mId.mSubtype) { + if (lastKeyboard == null || keyboard.mId.subtype != lastKeyboard.mId.subtype) { announceKeyboardLanguage(keyboard) return } // Announce the mode only when the mode is changed. - if (keyboard.mId.mMode != lastKeyboardMode) { + if (keyboard.mId.mode != lastKeyboardMode) { announceKeyboardMode(keyboard) return } // Announce the keyboard type only when the type is changed. - if (keyboard.mId.mElementId != lastKeyboard.mId.mElementId) { + if (keyboard.mId.elementId != lastKeyboard.mId.elementId) { announceKeyboardType(keyboard, lastKeyboard) return } @@ -86,7 +86,7 @@ class MainKeyboardAccessibilityDelegate( * @param keyboard The new keyboard. */ private fun announceKeyboardLanguage(keyboard: Keyboard) { - sendWindowStateChanged(keyboard.mId.mSubtype.rawSubtype.displayName()) + sendWindowStateChanged(keyboard.mId.subtype.rawSubtype.displayName()) } /** @@ -97,7 +97,7 @@ class MainKeyboardAccessibilityDelegate( */ private fun announceKeyboardMode(keyboard: Keyboard) { val context = mKeyboardView.context - val modeTextResId = KEYBOARD_MODE_RES_IDS[keyboard.mId.mMode] + val modeTextResId = KEYBOARD_MODE_RES_IDS[keyboard.mId.mode] if (modeTextResId == 0) { return } @@ -113,8 +113,8 @@ class MainKeyboardAccessibilityDelegate( * @param lastKeyboard The last keyboard. */ private fun announceKeyboardType(keyboard: Keyboard, lastKeyboard: Keyboard) { - val lastElementId = lastKeyboard.mId.mElementId - val resId = when (keyboard.mId.mElementId) { + val lastElementId = lastKeyboard.mId.elementId + val resId = when (keyboard.mId.elementId) { KeyboardId.ELEMENT_ALPHABET_AUTOMATIC_SHIFTED, KeyboardId.ELEMENT_ALPHABET -> { if (lastElementId == KeyboardId.ELEMENT_ALPHABET || lastElementId == KeyboardId.ELEMENT_ALPHABET_AUTOMATIC_SHIFTED) { @@ -257,4 +257,4 @@ class MainKeyboardAccessibilityDelegate( } private const val KEYBOARD_IS_HIDDEN = -1 } -} \ No newline at end of file +} diff --git a/app/src/main/java/helium314/keyboard/keyboard/Key.java b/app/src/main/java/helium314/keyboard/keyboard/Key.java index c5de708515..f1f2cbcaf7 100644 --- a/app/src/main/java/helium314/keyboard/keyboard/Key.java +++ b/app/src/main/java/helium314/keyboard/keyboard/Key.java @@ -1071,7 +1071,7 @@ public KeyParams( mHeight = params.mDefaultRowHeight; mIconName = KeySpecParser.getIconName(keySpec); - final boolean needsToUpcase = needsToUpcase(mLabelFlags, params.mId.mElementId); + final boolean needsToUpcase = needsToUpcase(mLabelFlags, params.mId.elementId); final Locale localeForUpcasing = params.mId.getLocale(); int actionFlags = 0; if (params.mId.isNumberLayout()) @@ -1080,7 +1080,7 @@ public KeyParams( // label String label = null; if ((mLabelFlags & LABEL_FLAGS_FROM_CUSTOM_ACTION_LABEL) != 0) { - mLabel = params.mId.mCustomActionLabel; + mLabel = params.mId.customActionLabel; } else if (code >= Character.MIN_SUPPLEMENTARY_CODE_POINT) { // This is a workaround to have a key that has a supplementary code point in its label. // Because we can put a string in resource neither as a XML entity of a supplementary diff --git a/app/src/main/java/helium314/keyboard/keyboard/Keyboard.java b/app/src/main/java/helium314/keyboard/keyboard/Keyboard.java index c894235387..3a04dfdbfe 100644 --- a/app/src/main/java/helium314/keyboard/keyboard/Keyboard.java +++ b/app/src/main/java/helium314/keyboard/keyboard/Keyboard.java @@ -148,8 +148,8 @@ public boolean hasProximityCharsCorrection(final int code) { // Note: The native code has the main keyboard layout only at this moment. // TODO: Figure out how to handle proximity characters information of all layouts. final boolean canAssumeNativeHasProximityCharsInfoOfAllKeys = ( - mId.mElementId == KeyboardId.ELEMENT_ALPHABET - || mId.mElementId == KeyboardId.ELEMENT_ALPHABET_AUTOMATIC_SHIFTED); + mId.elementId == KeyboardId.ELEMENT_ALPHABET + || mId.elementId == KeyboardId.ELEMENT_ALPHABET_AUTOMATIC_SHIFTED); return canAssumeNativeHasProximityCharsInfoOfAllKeys || Character.isLetter(code); } diff --git a/app/src/main/java/helium314/keyboard/keyboard/KeyboardActionListenerImpl.kt b/app/src/main/java/helium314/keyboard/keyboard/KeyboardActionListenerImpl.kt index 451ac57961..87341aed98 100644 --- a/app/src/main/java/helium314/keyboard/keyboard/KeyboardActionListenerImpl.kt +++ b/app/src/main/java/helium314/keyboard/keyboard/KeyboardActionListenerImpl.kt @@ -79,7 +79,7 @@ class KeyboardActionListenerImpl(private val latinIME: LatinIME, private val inp val event: Event if (settings.current.mLocale.language == "ko") { // todo: this does not appear to be the right place - val subtype = keyboardSwitcher.keyboard?.mId?.mSubtype ?: RichInputMethodManager.getInstance().currentSubtype + val subtype = keyboardSwitcher.keyboard?.mId?.subtype ?: RichInputMethodManager.getInstance().currentSubtype event = HangulEventDecoder.decodeHardwareKeyEvent(subtype, keyEvent) { getHardwareKeyEventDecoder(keyEvent.deviceId).decodeHardwareKey(keyEvent) } diff --git a/app/src/main/java/helium314/keyboard/keyboard/KeyboardId.java b/app/src/main/java/helium314/keyboard/keyboard/KeyboardId.java index 91a6076fc2..3b542db655 100644 --- a/app/src/main/java/helium314/keyboard/keyboard/KeyboardId.java +++ b/app/src/main/java/helium314/keyboard/keyboard/KeyboardId.java @@ -68,91 +68,91 @@ public final class KeyboardId { public static final int ELEMENT_EMOJI_BOTTOM_ROW = 29; public static final int ELEMENT_CLIPBOARD_BOTTOM_ROW = 30; - public final RichInputMethodSubtype mSubtype; - public final int mWidth; - public final int mHeight; - public final int mMode; - public final int mElementId; - public final EditorInfo mEditorInfo; - public final boolean mDeviceLocked; - public final boolean mNumberRowEnabled; - public final boolean mNumberRowInSymbols; - public final boolean mLanguageSwitchKeyEnabled; - public final boolean mEmojiKeyEnabled; - public final String mCustomActionLabel; - public final boolean mHasShortcutKey; - public final boolean mIsSplitLayout; - public final boolean mOneHandedModeEnabled; - public final KeyboardLayoutSet.InternalAction mInternalAction; + public final RichInputMethodSubtype subtype; + public final int width; + public final int height; + public final int mode; + public final int elementId; + public final EditorInfo editorInfo; + public final boolean deviceLocked; + public final boolean numberRowEnabled; + public final boolean numberRowInSymbols; + public final boolean languageSwitchKeyEnabled; + public final boolean emojiKeyEnabled; + public final String customActionLabel; + public final boolean hasShortcutKey; + public final boolean isSplitLayout; + public final boolean oneHandedModeEnabled; + public final KeyboardLayoutSet.InternalAction internalAction; private final int mHashCode; public KeyboardId(int elementId, KeyboardLayoutSet.Params params) { - mSubtype = params.mSubtype; - mWidth = params.mKeyboardWidth; - mHeight = params.mKeyboardHeight; - mMode = params.mMode; - mElementId = elementId; - mEditorInfo = params.mEditorInfo; - mDeviceLocked = params.mDeviceLocked; - mNumberRowEnabled = params.mNumberRowEnabled; - mNumberRowInSymbols = params.mNumberRowInSymbols; - mLanguageSwitchKeyEnabled = params.mLanguageSwitchKeyEnabled; - mEmojiKeyEnabled = params.mEmojiKeyEnabled; - mCustomActionLabel = (mEditorInfo.actionLabel != null) - ? mEditorInfo.actionLabel.toString() : null; - mHasShortcutKey = params.mVoiceInputKeyEnabled; - mIsSplitLayout = params.mIsSplitLayoutEnabled; - mOneHandedModeEnabled = params.mOneHandedModeEnabled; - mInternalAction = params.mInternalAction; + subtype = params.mSubtype; + width = params.mKeyboardWidth; + height = params.mKeyboardHeight; + mode = params.mMode; + this.elementId = elementId; + editorInfo = params.mEditorInfo; + deviceLocked = params.mDeviceLocked; + numberRowEnabled = params.mNumberRowEnabled; + numberRowInSymbols = params.mNumberRowInSymbols; + languageSwitchKeyEnabled = params.mLanguageSwitchKeyEnabled; + emojiKeyEnabled = params.mEmojiKeyEnabled; + customActionLabel = (editorInfo.actionLabel != null) + ? editorInfo.actionLabel.toString() : null; + hasShortcutKey = params.mVoiceInputKeyEnabled; + isSplitLayout = params.mIsSplitLayoutEnabled; + oneHandedModeEnabled = params.mOneHandedModeEnabled; + internalAction = params.mInternalAction; mHashCode = computeHashCode(this); } private static int computeHashCode(KeyboardId id) { return Arrays.hashCode(new Object[] { - id.mElementId, - id.mMode, - id.mWidth, - id.mHeight, + id.elementId, + id.mode, + id.width, + id.height, id.passwordInput(), - id.mDeviceLocked, - id.mHasShortcutKey, - id.mNumberRowEnabled, - id.mLanguageSwitchKeyEnabled, - id.mEmojiKeyEnabled, + id.deviceLocked, + id.hasShortcutKey, + id.numberRowEnabled, + id.languageSwitchKeyEnabled, + id.emojiKeyEnabled, id.isMultiLine(), id.imeAction(), - id.mCustomActionLabel, + id.customActionLabel, id.navigateNext(), id.navigatePrevious(), - id.mSubtype, - id.mIsSplitLayout, - id.mInternalAction + id.subtype, + id.isSplitLayout, + id.internalAction }); } private boolean equals(KeyboardId other) { if (other == this) return true; - return other.mElementId == mElementId - && other.mMode == mMode - && other.mWidth == mWidth - && other.mHeight == mHeight + return other.elementId == elementId + && other.mode == mode + && other.width == width + && other.height == height && other.passwordInput() == passwordInput() - && other.mDeviceLocked == mDeviceLocked - && other.mHasShortcutKey == mHasShortcutKey - && other.mNumberRowEnabled == mNumberRowEnabled - && other.mLanguageSwitchKeyEnabled == mLanguageSwitchKeyEnabled - && other.mEmojiKeyEnabled == mEmojiKeyEnabled + && other.deviceLocked == deviceLocked + && other.hasShortcutKey == hasShortcutKey + && other.numberRowEnabled == numberRowEnabled + && other.languageSwitchKeyEnabled == languageSwitchKeyEnabled + && other.emojiKeyEnabled == emojiKeyEnabled && other.isMultiLine() == isMultiLine() && other.imeAction() == imeAction() - && TextUtils.equals(other.mCustomActionLabel, mCustomActionLabel) + && TextUtils.equals(other.customActionLabel, customActionLabel) && other.navigateNext() == navigateNext() && other.navigatePrevious() == navigatePrevious() - && other.mSubtype.equals(mSubtype) - && other.mIsSplitLayout == mIsSplitLayout - && Objects.equals(other.mInternalAction, mInternalAction); + && other.subtype.equals(subtype) + && other.isSplitLayout == isSplitLayout + && Objects.equals(other.internalAction, internalAction); } private static boolean isAlphabetKeyboard(int elementId) { @@ -160,61 +160,61 @@ private static boolean isAlphabetKeyboard(int elementId) { } public boolean isAlphaOrSymbolKeyboard() { - return mElementId <= ELEMENT_SYMBOLS_SHIFTED; + return elementId <= ELEMENT_SYMBOLS_SHIFTED; } public boolean isAlphabetKeyboard() { - return isAlphabetKeyboard(mElementId); + return isAlphabetKeyboard(elementId); } public boolean navigateNext() { - return (mEditorInfo.imeOptions & EditorInfo.IME_FLAG_NAVIGATE_NEXT) != 0 + return (editorInfo.imeOptions & EditorInfo.IME_FLAG_NAVIGATE_NEXT) != 0 || imeAction() == EditorInfo.IME_ACTION_NEXT; } public boolean navigatePrevious() { - return (mEditorInfo.imeOptions & EditorInfo.IME_FLAG_NAVIGATE_PREVIOUS) != 0 + return (editorInfo.imeOptions & EditorInfo.IME_FLAG_NAVIGATE_PREVIOUS) != 0 || imeAction() == EditorInfo.IME_ACTION_PREVIOUS; } public boolean passwordInput() { - int inputType = mEditorInfo.inputType; + int inputType = editorInfo.inputType; return InputTypeUtils.isAnyPasswordInputType(inputType); } public boolean isMultiLine() { - return (mEditorInfo.inputType & InputType.TYPE_TEXT_FLAG_MULTI_LINE) != 0; + return (editorInfo.inputType & InputType.TYPE_TEXT_FLAG_MULTI_LINE) != 0; } public boolean isAlphabetShifted() { - return mElementId == ELEMENT_ALPHABET_SHIFT_LOCKED || mElementId == ELEMENT_ALPHABET_SHIFT_LOCK_SHIFTED - || mElementId == ELEMENT_ALPHABET_AUTOMATIC_SHIFTED || mElementId == ELEMENT_ALPHABET_MANUAL_SHIFTED; + return elementId == ELEMENT_ALPHABET_SHIFT_LOCKED || elementId == ELEMENT_ALPHABET_SHIFT_LOCK_SHIFTED + || elementId == ELEMENT_ALPHABET_AUTOMATIC_SHIFTED || elementId == ELEMENT_ALPHABET_MANUAL_SHIFTED; } public boolean isAlphabetShiftedManually() { - return mElementId == ELEMENT_ALPHABET_SHIFT_LOCKED || mElementId == ELEMENT_ALPHABET_SHIFT_LOCK_SHIFTED - || mElementId == ELEMENT_ALPHABET_MANUAL_SHIFTED; + return elementId == ELEMENT_ALPHABET_SHIFT_LOCKED || elementId == ELEMENT_ALPHABET_SHIFT_LOCK_SHIFTED + || elementId == ELEMENT_ALPHABET_MANUAL_SHIFTED; } public boolean isNumberLayout() { - return mElementId == ELEMENT_NUMBER || mElementId == ELEMENT_NUMPAD - || mElementId == ELEMENT_PHONE || mElementId == ELEMENT_PHONE_SYMBOLS; + return elementId == ELEMENT_NUMBER || elementId == ELEMENT_NUMPAD + || elementId == ELEMENT_PHONE || elementId == ELEMENT_PHONE_SYMBOLS; } public boolean isEmojiKeyboard() { - return mElementId >= ELEMENT_EMOJI_RECENTS && mElementId <= ELEMENT_EMOJI_CATEGORY16; + return elementId >= ELEMENT_EMOJI_RECENTS && elementId <= ELEMENT_EMOJI_CATEGORY16; } public boolean isEmojiClipBottomRow() { - return mElementId == ELEMENT_CLIPBOARD_BOTTOM_ROW || mElementId == ELEMENT_EMOJI_BOTTOM_ROW; + return elementId == ELEMENT_CLIPBOARD_BOTTOM_ROW || elementId == ELEMENT_EMOJI_BOTTOM_ROW; } public int imeAction() { - return InputTypeUtils.getImeOptionsActionIdFromEditorInfo(mEditorInfo); + return InputTypeUtils.getImeOptionsActionIdFromEditorInfo(editorInfo); } public Locale getLocale() { - return mSubtype.getLocale(); + return subtype.getLocale(); } @Override @@ -230,22 +230,22 @@ public int hashCode() { @Override public String toString() { return String.format(Locale.ROOT, "[%s %s:%s %dx%d %s %s%s%s%s%s%s%s%s%s%s%s]", - elementIdToName(mElementId), - mSubtype.getLocale(), - mSubtype.getExtraValueOf(KEYBOARD_LAYOUT_SET), - mWidth, mHeight, - modeName(mMode), + elementIdToName(elementId), + subtype.getLocale(), + subtype.getExtraValueOf(KEYBOARD_LAYOUT_SET), + width, height, + modeName(mode), actionName(imeAction()), (navigateNext() ? " navigateNext" : ""), (navigatePrevious() ? " navigatePrevious" : ""), - (mDeviceLocked ? " deviceLocked" : ""), + (deviceLocked ? " deviceLocked" : ""), (passwordInput() ? " passwordInput" : ""), - (mHasShortcutKey ? " hasShortcutKey" : ""), - (mNumberRowEnabled ? " numberRowEnabled" : ""), - (mLanguageSwitchKeyEnabled ? " languageSwitchKeyEnabled" : ""), - (mEmojiKeyEnabled ? " emojiKeyEnabled" : ""), + (hasShortcutKey ? " hasShortcutKey" : ""), + (numberRowEnabled ? " numberRowEnabled" : ""), + (languageSwitchKeyEnabled ? " languageSwitchKeyEnabled" : ""), + (emojiKeyEnabled ? " emojiKeyEnabled" : ""), (isMultiLine() ? " isMultiLine" : ""), - (mIsSplitLayout ? " isSplitLayout" : "") + (isSplitLayout ? " isSplitLayout" : "") ); } @@ -314,7 +314,7 @@ public static String actionName(int actionId) { } public int getKeyboardCapsMode() { - return switch (mElementId) { + return switch (elementId) { case KeyboardId.ELEMENT_ALPHABET_SHIFT_LOCKED, KeyboardId.ELEMENT_ALPHABET_SHIFT_LOCK_SHIFTED -> WordComposer.CAPS_MODE_MANUAL_SHIFT_LOCKED; case KeyboardId.ELEMENT_ALPHABET_MANUAL_SHIFTED -> WordComposer.CAPS_MODE_MANUAL_SHIFTED; diff --git a/app/src/main/java/helium314/keyboard/keyboard/KeyboardLayoutSet.java b/app/src/main/java/helium314/keyboard/keyboard/KeyboardLayoutSet.java index 5c293b4e6e..8de5e6fe59 100644 --- a/app/src/main/java/helium314/keyboard/keyboard/KeyboardLayoutSet.java +++ b/app/src/main/java/helium314/keyboard/keyboard/KeyboardLayoutSet.java @@ -175,8 +175,8 @@ private Keyboard getKeyboard(final KeyboardId id) { } final Keyboard keyboard = builder.build(); sKeyboardCache.put(id, new SoftReference<>(keyboard)); - if ((id.mElementId == KeyboardId.ELEMENT_ALPHABET - || id.mElementId == KeyboardId.ELEMENT_ALPHABET_AUTOMATIC_SHIFTED) + if ((id.elementId == KeyboardId.ELEMENT_ALPHABET + || id.elementId == KeyboardId.ELEMENT_ALPHABET_AUTOMATIC_SHIFTED) && !mParams.mIsSpellChecker) { // We only forcibly cache the primary, "ALPHABET", layouts. for (int i = sForcibleKeyboardCache.length - 1; i >= 1; --i) { diff --git a/app/src/main/java/helium314/keyboard/keyboard/KeyboardSwitcher.java b/app/src/main/java/helium314/keyboard/keyboard/KeyboardSwitcher.java index eb29a0c6c6..429c3053bd 100644 --- a/app/src/main/java/helium314/keyboard/keyboard/KeyboardSwitcher.java +++ b/app/src/main/java/helium314/keyboard/keyboard/KeyboardSwitcher.java @@ -209,8 +209,8 @@ private void setKeyboard(final int keyboardId, @NonNull final KeyboardSwitchStat mCurrentInputView.setKeyboardTopPadding(newKeyboard.mTopPadding); keyboardView.setKeyPreviewPopupEnabled(currentSettingsValues.mKeyPreviewPopupOn); keyboardView.updateShortcutKey(mRichImm.isShortcutImeReady()); - final boolean subtypeChanged = (oldKeyboard == null) || !newKeyboard.mId.mSubtype.equals(oldKeyboard.mId.mSubtype); - final int languageOnSpacebarFormatType = LanguageOnSpacebarUtils.getLanguageOnSpacebarFormatType(newKeyboard.mId.mSubtype); + final boolean subtypeChanged = (oldKeyboard == null) || !newKeyboard.mId.subtype.equals(oldKeyboard.mId.subtype); + final int languageOnSpacebarFormatType = LanguageOnSpacebarUtils.getLanguageOnSpacebarFormatType(newKeyboard.mId.subtype); final boolean hasMultipleEnabledIMEsOrSubtypes = mRichImm.hasMultipleEnabledIMEsOrSubtypes(true); keyboardView.startDisplayLanguageOnSpacebar(subtypeChanged, languageOnSpacebarFormatType, hasMultipleEnabledIMEsOrSubtypes); } @@ -611,7 +611,7 @@ public boolean isShowingKeyboardId(@NonNull int... keyboardIds) { final Keyboard keyboard = mKeyboardView.getKeyboard(); if (keyboard == null) // may happen when using hardware keyboard return false; - int activeKeyboardId = keyboard.mId.mElementId; + int activeKeyboardId = keyboard.mId.elementId; for (int keyboardId : keyboardIds) { if (activeKeyboardId == keyboardId) { return true; diff --git a/app/src/main/java/helium314/keyboard/keyboard/KeyboardView.java b/app/src/main/java/helium314/keyboard/keyboard/KeyboardView.java index 8b5174dca4..12248a5293 100644 --- a/app/src/main/java/helium314/keyboard/keyboard/KeyboardView.java +++ b/app/src/main/java/helium314/keyboard/keyboard/KeyboardView.java @@ -624,10 +624,10 @@ private void setKeyIconColor(Key key, Drawable icon, Keyboard keyboard) { if (key.hasActionKeyBackground()) { mColors.setColor(icon, ColorType.ACTION_KEY_ICON); } else if (key.isShift() && keyboard != null) { - if (keyboard.mId.mElementId == KeyboardId.ELEMENT_ALPHABET_MANUAL_SHIFTED - || keyboard.mId.mElementId == KeyboardId.ELEMENT_ALPHABET_SHIFT_LOCKED - || keyboard.mId.mElementId == KeyboardId.ELEMENT_ALPHABET_AUTOMATIC_SHIFTED - || keyboard.mId.mElementId == KeyboardId.ELEMENT_ALPHABET_SHIFT_LOCK_SHIFTED + if (keyboard.mId.elementId == KeyboardId.ELEMENT_ALPHABET_MANUAL_SHIFTED + || keyboard.mId.elementId == KeyboardId.ELEMENT_ALPHABET_SHIFT_LOCKED + || keyboard.mId.elementId == KeyboardId.ELEMENT_ALPHABET_AUTOMATIC_SHIFTED + || keyboard.mId.elementId == KeyboardId.ELEMENT_ALPHABET_SHIFT_LOCK_SHIFTED ) mColors.setColor(icon, ColorType.SHIFT_KEY_ICON); else diff --git a/app/src/main/java/helium314/keyboard/keyboard/MainKeyboardView.java b/app/src/main/java/helium314/keyboard/keyboard/MainKeyboardView.java index 7c1e7e4480..96ca9e813d 100644 --- a/app/src/main/java/helium314/keyboard/keyboard/MainKeyboardView.java +++ b/app/src/main/java/helium314/keyboard/keyboard/MainKeyboardView.java @@ -817,10 +817,10 @@ private void drawLanguageOnSpacebar(final Key key, final Canvas canvas, final Pa spaceText = customText; } else if (DebugFlags.DEBUG_ENABLED) { final String l = KeyboardSwitcher.getInstance().getLocaleAndConfidenceInfo(); - spaceText = l != null ? l : layoutLanguageOnSpacebar(paint, keyboard.mId.mSubtype, width); + spaceText = l != null ? l : layoutLanguageOnSpacebar(paint, keyboard.mId.subtype, width); } else - spaceText = layoutLanguageOnSpacebar(paint, keyboard.mId.mSubtype, width); + spaceText = layoutLanguageOnSpacebar(paint, keyboard.mId.subtype, width); // Draw language text with shadow final float descent = paint.descent(); final float textHeight = -paint.ascent() + descent; diff --git a/app/src/main/java/helium314/keyboard/keyboard/PopupKeysKeyboard.java b/app/src/main/java/helium314/keyboard/keyboard/PopupKeysKeyboard.java index 645e420bbc..bf058fbbd3 100644 --- a/app/src/main/java/helium314/keyboard/keyboard/PopupKeysKeyboard.java +++ b/app/src/main/java/helium314/keyboard/keyboard/PopupKeysKeyboard.java @@ -299,12 +299,12 @@ public Builder(final Context context, final Key key, final Keyboard keyboard, } final PopupKeySpec[] popupKeys = key.getPopupKeys(); final int defaultColumns = key.getPopupKeysColumnNumber(); - final int spaceForKeys = keyboard.mId.mWidth / keyWidth; + final int spaceForKeys = keyboard.mId.width / keyWidth; final int finalNumColumns = spaceForKeys >= Math.min(popupKeys.length, defaultColumns) ? defaultColumns : (spaceForKeys > 0 ? spaceForKeys : defaultColumns); // in last case setParameters will throw an exception mParams.setParameters(popupKeys.length, finalNumColumns, keyWidth, - rowHeight, key.getX() + key.getWidth() / 2, keyboard.mId.mWidth, + rowHeight, key.getX() + key.getWidth() / 2, keyboard.mId.width, key.isPopupKeysFixedColumn(), key.isPopupKeysFixedOrder(), dividerWidth); } diff --git a/app/src/main/java/helium314/keyboard/keyboard/internal/KeyboardBuilder.kt b/app/src/main/java/helium314/keyboard/keyboard/internal/KeyboardBuilder.kt index ed6e9b559c..02f84ed710 100644 --- a/app/src/main/java/helium314/keyboard/keyboard/internal/KeyboardBuilder.kt +++ b/app/src/main/java/helium314/keyboard/keyboard/internal/KeyboardBuilder.kt @@ -57,7 +57,7 @@ open class KeyboardBuilder(protected val mContext: Context, mParams.mTouchPositionCorrection.load(mContext.resources.getStringArray(R.array.touch_position_correction_data_default)) determineAbsoluteValues() } catch (e: Exception) { - Log.e(TAG, "error parsing layout $id ${id.mElementId}", e) + Log.e(TAG, "error parsing layout $id ${id.elementId}", e) throw e } } @@ -67,8 +67,8 @@ open class KeyboardBuilder(protected val mContext: Context, private fun setupParams() { val sv = Settings.getValues() mParams.mAllowRedundantPopupKeys = !sv.mRemoveRedundantPopups - mParams.mProximityCharsCorrectionEnabled = mParams.mId.mElementId == KeyboardId.ELEMENT_ALPHABET - || (mParams.mId.isAlphabetKeyboard && !mParams.mId.mSubtype.hasExtraValue(Constants.Subtype.ExtraValue.NO_SHIFT_PROXIMITY_CORRECTION)) + mParams.mProximityCharsCorrectionEnabled = mParams.mId.elementId == KeyboardId.ELEMENT_ALPHABET + || (mParams.mId.isAlphabetKeyboard && !mParams.mId.subtype.hasExtraValue(Constants.Subtype.ExtraValue.NO_SHIFT_PROXIMITY_CORRECTION)) addLocaleKeyTextsToParams(mContext, mParams, sv.mShowMorePopupKeys) mParams.mPopupKeyTypes.addAll(sv.mPopupKeyTypes) @@ -101,8 +101,8 @@ open class KeyboardBuilder(protected val mContext: Context, } open fun build(): Keyboard { - if (mParams.mId.mIsSplitLayout - && mParams.mId.mElementId in KeyboardId.ELEMENT_ALPHABET..KeyboardId.ELEMENT_SYMBOLS_SHIFTED) { + if (mParams.mId.isSplitLayout + && mParams.mId.elementId in KeyboardId.ELEMENT_ALPHABET..KeyboardId.ELEMENT_SYMBOLS_SHIFTED) { addSplit() } addKeysToParams() @@ -129,7 +129,7 @@ open class KeyboardBuilder(protected val mContext: Context, val spacerRelativeWidth = Settings.getValues().mSplitKeyboardSpacerRelativeWidth // adjust gaps for the whole keyboard, so it's the same for all rows mParams.mRelativeHorizontalGap *= 1f / (1f + spacerRelativeWidth) - mParams.mHorizontalGap = (mParams.mRelativeHorizontalGap * mParams.mId.mWidth).toInt() + mParams.mHorizontalGap = (mParams.mRelativeHorizontalGap * mParams.mId.width).toInt() var maxWidthBeforeSpacer = 0f var maxWidthAfterSpacer = 0f for (row in keysInRows) { diff --git a/app/src/main/java/helium314/keyboard/keyboard/internal/KeyboardParams.java b/app/src/main/java/helium314/keyboard/keyboard/internal/KeyboardParams.java index 56e3ebe655..1a4214fc0f 100644 --- a/app/src/main/java/helium314/keyboard/keyboard/internal/KeyboardParams.java +++ b/app/src/main/java/helium314/keyboard/keyboard/internal/KeyboardParams.java @@ -216,8 +216,8 @@ public void readAttributes(final Context context, @Nullable final AttributeSet a else keyAttr = context.getResources().obtainAttributes(attr, R.styleable.Keyboard_Key); try { - final int height = mId.mHeight; - final int width = mId.mWidth; + final int height = mId.height; + final int width = mId.width; mOccupiedHeight = height; mOccupiedWidth = width; mTopPadding = (int) keyboardAttr.getFraction( @@ -286,6 +286,6 @@ public void readAttributes(final Context context, @Nullable final AttributeSet a keyAttr.recycle(); keyboardAttr.recycle(); } - setTabletExtraKeys = Settings.getInstance().isTablet() && !mId.mSubtype.isCustom(); + setTabletExtraKeys = Settings.getInstance().isTablet() && !mId.subtype.isCustom(); } } diff --git a/app/src/main/java/helium314/keyboard/keyboard/internal/keyboard_parser/EmojiParser.kt b/app/src/main/java/helium314/keyboard/keyboard/internal/keyboard_parser/EmojiParser.kt index f4662fb1a2..460ce52ae6 100644 --- a/app/src/main/java/helium314/keyboard/keyboard/internal/keyboard_parser/EmojiParser.kt +++ b/app/src/main/java/helium314/keyboard/keyboard/internal/keyboard_parser/EmojiParser.kt @@ -22,7 +22,7 @@ import kotlin.math.sqrt class EmojiParser(private val params: KeyboardParams, private val context: Context) { fun parse(): ArrayList> { - val emojiFileName = when (params.mId.mElementId) { + val emojiFileName = when (params.mId.elementId) { KeyboardId.ELEMENT_EMOJI_CATEGORY1 -> "SMILEYS_AND_EMOTION.txt" KeyboardId.ELEMENT_EMOJI_CATEGORY2 -> "PEOPLE_AND_BODY.txt" KeyboardId.ELEMENT_EMOJI_CATEGORY3 -> "ANIMALS_AND_NATURE.txt" @@ -44,7 +44,7 @@ class EmojiParser(private val params: KeyboardParams, private val context: Conte context.assets.open("emoji/$emojiFileName").reader().use { it.readLines() } } val defaultSkinTone = context.prefs().getString(Settings.PREF_EMOJI_SKIN_TONE, Defaults.PREF_EMOJI_SKIN_TONE)!! - if (params.mId.mElementId == KeyboardId.ELEMENT_EMOJI_CATEGORY2 && defaultSkinTone != "") { + if (params.mId.elementId == KeyboardId.ELEMENT_EMOJI_CATEGORY2 && defaultSkinTone != "") { // adjust PEOPLE_AND_BODY if we have a non-yellow default skin tone val modifiedLines = emojiLines.map { line -> val split = line.splitOnWhitespace().toMutableList() @@ -94,7 +94,7 @@ class EmojiParser(private val params: KeyboardParams, private val context: Conte } private fun parseEmojiKeyNew(line: String): KeyParams? { - if (!line.contains(" ") || params.mId.mElementId == KeyboardId.ELEMENT_EMOJI_CATEGORY10) { + if (!line.contains(" ") || params.mId.elementId == KeyboardId.ELEMENT_EMOJI_CATEGORY10) { // single emoji without popups, or emoticons (there is one that contains space...) return if (SupportedEmojis.isUnsupported(line)) null else KeyParams(line, line.getCode(), null, null, Key.LABEL_FLAGS_FONT_NORMAL, params) diff --git a/app/src/main/java/helium314/keyboard/keyboard/internal/keyboard_parser/KeyboardParser.kt b/app/src/main/java/helium314/keyboard/keyboard/internal/keyboard_parser/KeyboardParser.kt index 29dcc182ac..06f29c0c04 100644 --- a/app/src/main/java/helium314/keyboard/keyboard/internal/keyboard_parser/KeyboardParser.kt +++ b/app/src/main/java/helium314/keyboard/keyboard/internal/keyboard_parser/KeyboardParser.kt @@ -47,7 +47,7 @@ class KeyboardParser(private val params: KeyboardParams, private val context: Co params.readAttributes(context, null) // todo: maybe determine layoutType earlier, and to less stuff based on elementId - val layoutType = when (params.mId.mElementId) { + val layoutType = when (params.mId.elementId) { KeyboardId.ELEMENT_SYMBOLS -> LayoutType.SYMBOLS KeyboardId.ELEMENT_SYMBOLS_SHIFTED -> LayoutType.MORE_SYMBOLS KeyboardId.ELEMENT_PHONE -> LayoutType.PHONE @@ -87,7 +87,7 @@ class KeyboardParser(private val params: KeyboardParams, private val context: Co private fun createRows(baseKeys: MutableList>): ArrayList> { // add padding for number layouts in landscape mode (maybe do it some other way later) - if (params.mId.isNumberLayout && params.mId.mElementId != KeyboardId.ELEMENT_NUMPAD + if (params.mId.isNumberLayout && params.mId.elementId != KeyboardId.ELEMENT_NUMPAD && context.resources.configuration.orientation == Configuration.ORIENTATION_LANDSCAPE) { params.mLeftPadding = (params.mOccupiedWidth * 0.1f).toInt() params.mRightPadding = (params.mOccupiedWidth * 0.1f).toInt() @@ -98,7 +98,7 @@ class KeyboardParser(private val params: KeyboardParams, private val context: Co addNumberRowOrPopupKeys(baseKeys, numberRow) if (params.mId.isAlphabetKeyboard) addSymbolPopupKeys(baseKeys) - if (params.mId.isAlphaOrSymbolKeyboard && params.mId.mNumberRowEnabled) { + if (params.mId.isAlphaOrSymbolKeyboard && params.mId.numberRowEnabled) { val newLabelFlags = defaultLabelFlags or if (Settings.getValues().mShowNumberRowHints) 0 else Key.LABEL_FLAGS_DISABLE_HINT_LABEL baseKeys.add(0, numberRow.mapTo(mutableListOf()) { it.copy(newLabelFlags = newLabelFlags) }) @@ -122,7 +122,7 @@ class KeyboardParser(private val params: KeyboardParams, private val context: Co val baseKeyParams = baseKeys.mapIndexed { i, it -> val row: List = if (params.mId.isAlphaOrSymbolKeyboard && i == baseKeys.lastIndex - 1 && params.setTabletExtraKeys) { // add bottom row extra keys - val tabletExtraKeys = params.mLocaleKeyboardInfos.getTabletExtraKeys(params.mId.mElementId) + val tabletExtraKeys = params.mLocaleKeyboardInfos.getTabletExtraKeys(params.mId.elementId) tabletExtraKeys.first + it + tabletExtraKeys.second } else { it @@ -264,12 +264,12 @@ class KeyboardParser(private val params: KeyboardParams, private val context: Co } private fun addNumberRowOrPopupKeys(baseKeys: MutableList>, numberRow: MutableList) { - if (!params.mId.mNumberRowEnabled && params.mId.mNumberRowInSymbols && params.mId.mElementId == KeyboardId.ELEMENT_SYMBOLS) { + if (!params.mId.numberRowEnabled && params.mId.numberRowInSymbols && params.mId.elementId == KeyboardId.ELEMENT_SYMBOLS) { // replace first symbols row with number row, but use the labels as popupKeys val numberRowCopy = numberRow.toMutableList() numberRowCopy.forEachIndexed { index, keyData -> keyData.popup.symbol = baseKeys[0].getOrNull(index)?.label } baseKeys[0] = numberRowCopy - } else if (!params.mId.mNumberRowEnabled && params.mId.isAlphabetKeyboard && !hasBuiltInNumbers()) { + } else if (!params.mId.numberRowEnabled && params.mId.isAlphabetKeyboard && !hasBuiltInNumbers()) { if (baseKeys[0].any { it.popup.main != null || !it.popup.relevant.isNullOrEmpty() } // first row of baseKeys has any layout popup key && params.mPopupKeyLabelSources.let { val layout = it.indexOf(POPUP_KEYS_LAYOUT) @@ -324,9 +324,9 @@ class KeyboardParser(private val params: KeyboardParams, private val context: Co } // some layouts have numbers hardcoded in the main layout (pcqwerty as keys, and others as popups) - private fun hasBuiltInNumbers() = params.mId.mSubtype.mainLayoutName == "pcqwerty" + private fun hasBuiltInNumbers() = params.mId.subtype.mainLayoutName == "pcqwerty" || (Settings.getValues().mPopupKeyTypes.contains(POPUP_KEYS_LAYOUT) - && params.mId.mSubtype.mainLayoutName in listOf("lao", "thai", "korean_sebeolsik_390", "korean_sebeolsik_final") + && params.mId.subtype.mainLayoutName in listOf("lao", "thai", "korean_sebeolsik_390", "korean_sebeolsik_final") ) companion object { diff --git a/app/src/main/java/helium314/keyboard/keyboard/internal/keyboard_parser/LayoutParser.kt b/app/src/main/java/helium314/keyboard/keyboard/internal/keyboard_parser/LayoutParser.kt index ecee477cb3..351cc5bd33 100644 --- a/app/src/main/java/helium314/keyboard/keyboard/internal/keyboard_parser/LayoutParser.kt +++ b/app/src/main/java/helium314/keyboard/keyboard/internal/keyboard_parser/LayoutParser.kt @@ -37,8 +37,8 @@ object LayoutParser { fun parseLayout(layoutType: LayoutType, params: KeyboardParams, context: Context): MutableList> { if (layoutType == LayoutType.FUNCTIONAL && !params.mId.isAlphaOrSymbolKeyboard) return mutableListOf(mutableListOf()) // no functional keys - val layoutName = if (layoutType == LayoutType.MAIN) params.mId.mSubtype.mainLayoutName - else params.mId.mSubtype.layouts[layoutType] ?: Settings.readDefaultLayoutName(layoutType, context.prefs()) + val layoutName = if (layoutType == LayoutType.MAIN) params.mId.subtype.mainLayoutName + else params.mId.subtype.layouts[layoutType] ?: Settings.readDefaultLayoutName(layoutType, context.prefs()) return layoutCache.getOrPut(layoutType.name + layoutName) { createCacheLambda(layoutType, layoutName, context) }(params) diff --git a/app/src/main/java/helium314/keyboard/keyboard/internal/keyboard_parser/floris/KeyData.kt b/app/src/main/java/helium314/keyboard/keyboard/internal/keyboard_parser/floris/KeyData.kt index 7c8b0736d4..590df01b19 100644 --- a/app/src/main/java/helium314/keyboard/keyboard/internal/keyboard_parser/floris/KeyData.kt +++ b/app/src/main/java/helium314/keyboard/keyboard/internal/keyboard_parser/floris/KeyData.kt @@ -115,7 +115,7 @@ class ShiftStateSelector( val manualOrLocked: AbstractKeyData? = null, ) : AbstractKeyData { override fun compute(params: KeyboardParams): KeyData? { - return when (params.mId.mElementId) { + return when (params.mId.elementId) { KeyboardId.ELEMENT_ALPHABET, KeyboardId.ELEMENT_SYMBOLS -> unshifted ?: default KeyboardId.ELEMENT_ALPHABET_MANUAL_SHIFTED -> shiftedManual ?: manualOrLocked ?: shifted ?: default KeyboardId.ELEMENT_ALPHABET_AUTOMATIC_SHIFTED -> shiftedAutomatic ?: shifted ?: default @@ -174,11 +174,11 @@ data class VariationSelector( override fun compute(params: KeyboardParams): KeyData? { return when { params.mId.passwordInput() -> password ?: default - params.mId.mMode == KeyboardId.MODE_EMAIL -> email ?: default - params.mId.mMode == KeyboardId.MODE_URL -> uri ?: default - params.mId.mMode == KeyboardId.MODE_DATE -> date ?: default - params.mId.mMode == KeyboardId.MODE_TIME -> time ?: default - params.mId.mMode == KeyboardId.MODE_DATETIME -> datetime ?: default + params.mId.mode == KeyboardId.MODE_EMAIL -> email ?: default + params.mId.mode == KeyboardId.MODE_URL -> uri ?: default + params.mId.mode == KeyboardId.MODE_DATE -> date ?: default + params.mId.mode == KeyboardId.MODE_TIME -> time ?: default + params.mId.mode == KeyboardId.MODE_DATETIME -> datetime ?: default else -> normal ?: default }?.compute(params) } @@ -193,10 +193,10 @@ data class VariationSelector( * The JSON class identifier for this selector is `keyboard_state_selector`. * Note that the conditions are checked in order as given below, and the first non-null AbstractKeyData is selected. * - * @property emojiKeyEnabled The key data to use if [KeyboardId.mEmojiKeyEnabled] is true. - * @property languageKeyEnabled The key data to use if [KeyboardId.mLanguageSwitchKeyEnabled] is true. - * @property symbols The key data to use if [KeyboardId.mElementId] is [KeyboardId.ELEMENT_SYMBOLS]. - * @property moreSymbols The key data to use if [KeyboardId.mElementId] is [KeyboardId.ELEMENT_SYMBOLS_SHIFTED]. + * @property emojiKeyEnabled The key data to use if [KeyboardId.emojiKeyEnabled] is true. + * @property languageKeyEnabled The key data to use if [KeyboardId.languageSwitchKeyEnabled] is true. + * @property symbols The key data to use if [KeyboardId.elementId] is [KeyboardId.ELEMENT_SYMBOLS]. + * @property moreSymbols The key data to use if [KeyboardId.elementId] is [KeyboardId.ELEMENT_SYMBOLS_SHIFTED]. * @property alphabet The key data to use if [KeyboardId.isAlphabetKeyboard] is true. * @property default The default key data which should be used in case none of the other conditions have a matching non-null * AbstractKeyData. Can be null, in this case no key is displayed. @@ -212,13 +212,13 @@ class KeyboardStateSelector( val default: AbstractKeyData? = null, ) : AbstractKeyData { override fun compute(params: KeyboardParams): KeyData? { - if (params.mId.mEmojiKeyEnabled) + if (params.mId.emojiKeyEnabled) emojiKeyEnabled?.compute(params)?.let { return it } - if (params.mId.mLanguageSwitchKeyEnabled) + if (params.mId.languageSwitchKeyEnabled) languageKeyEnabled?.compute(params)?.let { return it } - if (params.mId.mElementId == KeyboardId.ELEMENT_SYMBOLS) + if (params.mId.elementId == KeyboardId.ELEMENT_SYMBOLS) symbols?.compute(params)?.let { return it } - if (params.mId.mElementId == KeyboardId.ELEMENT_SYMBOLS_SHIFTED) + if (params.mId.elementId == KeyboardId.ELEMENT_SYMBOLS_SHIFTED) moreSymbols?.compute(params)?.let { return it } if (params.mId.isAlphabetKeyboard) alphabet?.compute(params)?.let { return it } @@ -255,7 +255,7 @@ class LayoutDirectionSelector( val rtl: AbstractKeyData, ) : AbstractKeyData { override fun compute(params: KeyboardParams): KeyData? { - return (if (params.mId.mSubtype.isRtlSubtype) { rtl } else { ltr }).compute(params) + return (if (params.mId.subtype.isRtlSubtype) { rtl } else { ltr }).compute(params) } override fun asString(isForDisplay: Boolean): String { diff --git a/app/src/main/java/helium314/keyboard/keyboard/internal/keyboard_parser/floris/KeyLabel.kt b/app/src/main/java/helium314/keyboard/keyboard/internal/keyboard_parser/floris/KeyLabel.kt index a473255c86..600b83e612 100644 --- a/app/src/main/java/helium314/keyboard/keyboard/internal/keyboard_parser/floris/KeyLabel.kt +++ b/app/src/main/java/helium314/keyboard/keyboard/internal/keyboard_parser/floris/KeyLabel.kt @@ -65,7 +65,7 @@ object KeyLabel { } fun String.rtlLabel(params: KeyboardParams): String { - if (!params.mId.mSubtype.isRtlSubtype || params.mId.isNumberLayout) return this + if (!params.mId.subtype.isRtlSubtype || params.mId.isNumberLayout) return this return when (this) { "{" -> "{|}" "}" -> "}|{" @@ -130,7 +130,7 @@ object KeyLabel { else "$newLabel|!code/$code" } - private fun getShiftLabel(params: KeyboardParams) = when (params.mId.mElementId) { + private fun getShiftLabel(params: KeyboardParams) = when (params.mId.elementId) { KeyboardId.ELEMENT_SYMBOLS_SHIFTED -> params.mLocaleKeyboardInfos.labelSymbol KeyboardId.ELEMENT_SYMBOLS -> params.mLocaleKeyboardInfos.getShiftSymbolLabel( Settings.getInstance().isTablet) @@ -157,15 +157,15 @@ object KeyLabel { // todo (later): should this be handled with metaState? but metaState shift would require LOTS of changes... private fun getActionKeyCode(params: KeyboardParams): String { - params.mId.mInternalAction?.let { return "${KeyboardCodesSet.PREFIX_CODE}${it.code()}" } - return if (params.mId.isMultiLine && (params.mId.mElementId == KeyboardId.ELEMENT_ALPHABET_MANUAL_SHIFTED || params.mId.mElementId == KeyboardId.ELEMENT_ALPHABET_SHIFT_LOCK_SHIFTED)) + params.mId.internalAction?.let { return "${KeyboardCodesSet.PREFIX_CODE}${it.code()}" } + return if (params.mId.isMultiLine && (params.mId.elementId == KeyboardId.ELEMENT_ALPHABET_MANUAL_SHIFTED || params.mId.elementId == KeyboardId.ELEMENT_ALPHABET_SHIFT_LOCK_SHIFTED)) "!code/key_shift_enter" else "!code/key_enter" } private fun getActionKeyLabel(params: KeyboardParams): String { - params.mId.mInternalAction?.let { return it.label() } - if (params.mId.isMultiLine && (params.mId.mElementId == KeyboardId.ELEMENT_ALPHABET_MANUAL_SHIFTED || params.mId.mElementId == KeyboardId.ELEMENT_ALPHABET_SHIFT_LOCK_SHIFTED)) + params.mId.internalAction?.let { return it.label() } + if (params.mId.isMultiLine && (params.mId.elementId == KeyboardId.ELEMENT_ALPHABET_MANUAL_SHIFTED || params.mId.elementId == KeyboardId.ELEMENT_ALPHABET_SHIFT_LOCK_SHIFTED)) return "!icon/enter_key" val iconName = when (params.mId.imeAction()) { EditorInfo.IME_ACTION_GO -> KeyboardIconsSet.NAME_GO_KEY @@ -174,7 +174,7 @@ object KeyLabel { EditorInfo.IME_ACTION_NEXT -> KeyboardIconsSet.NAME_NEXT_KEY EditorInfo.IME_ACTION_DONE -> KeyboardIconsSet.NAME_DONE_KEY EditorInfo.IME_ACTION_PREVIOUS -> KeyboardIconsSet.NAME_PREVIOUS_KEY - InputTypeUtils.IME_ACTION_CUSTOM_LABEL -> return params.mId.mCustomActionLabel + InputTypeUtils.IME_ACTION_CUSTOM_LABEL -> return params.mId.customActionLabel else -> return "!icon/enter_key" } val replacement = iconName.replaceIconWithLabelIfNoDrawable(params) diff --git a/app/src/main/java/helium314/keyboard/keyboard/internal/keyboard_parser/floris/TextKeyData.kt b/app/src/main/java/helium314/keyboard/keyboard/internal/keyboard_parser/floris/TextKeyData.kt index 07f3a37382..6a0989adb3 100644 --- a/app/src/main/java/helium314/keyboard/keyboard/internal/keyboard_parser/floris/TextKeyData.kt +++ b/app/src/main/java/helium314/keyboard/keyboard/internal/keyboard_parser/floris/TextKeyData.kt @@ -95,15 +95,15 @@ sealed interface KeyData : AbstractKeyData { // keys could be replaced with toolbar keys, but parsing needs to be adjusted (should happen anyway...) private fun getCommaPopupKeys(params: KeyboardParams): List { val keys = mutableListOf() - if (!params.mId.mDeviceLocked) + if (!params.mId.deviceLocked) keys.add("!icon/clipboard_normal_key|!code/key_clipboard") - if (!params.mId.mEmojiKeyEnabled && !params.mId.isNumberLayout) + if (!params.mId.emojiKeyEnabled && !params.mId.isNumberLayout) keys.add("!icon/emoji_normal_key|!code/key_emoji") - if (!params.mId.mLanguageSwitchKeyEnabled && !params.mId.isNumberLayout && RichInputMethodManager.canSwitchLanguage()) + if (!params.mId.languageSwitchKeyEnabled && !params.mId.isNumberLayout && RichInputMethodManager.canSwitchLanguage()) keys.add("!icon/language_switch_key|!code/key_language_switch") - if (!params.mId.mOneHandedModeEnabled) + if (!params.mId.oneHandedModeEnabled) keys.add("!icon/start_onehanded_mode_key|!code/key_toggle_onehanded") - if (!params.mId.mDeviceLocked) + if (!params.mId.deviceLocked) keys.add("!icon/settings_key|!code/key_settings") if (shouldShowTldPopups(params)) { keys.add(",") @@ -112,12 +112,12 @@ sealed interface KeyData : AbstractKeyData { } private fun getPunctuationPopupKeys(params: KeyboardParams): List { - if (params.mId.mElementId == KeyboardId.ELEMENT_SYMBOLS || params.mId.mElementId == KeyboardId.ELEMENT_SYMBOLS_SHIFTED) + if (params.mId.elementId == KeyboardId.ELEMENT_SYMBOLS || params.mId.elementId == KeyboardId.ELEMENT_SYMBOLS_SHIFTED) return listOf("…") if (params.mId.isNumberLayout) return listOf(":", "…", ";", "∞", "π", "√", "°", "^") val popupKeys = params.mLocaleKeyboardInfos.getPopupKeys("punctuation")!!.toMutableList() - if (params.mId.mSubtype.isRtlSubtype) { + if (params.mId.subtype.isRtlSubtype) { for (i in popupKeys.indices) popupKeys[i] = popupKeys[i].rtlLabel(params) // for parentheses } @@ -166,7 +166,7 @@ sealed interface KeyData : AbstractKeyData { else -> null } // could change definition of numbers to query a range, or have a pre-defined list, but not that crucial - keyboardId.isNumberLayout || keyboardId.mMode in listOf(KeyboardId.MODE_EMAIL, KeyboardId.MODE_DATE, KeyboardId.MODE_TIME, KeyboardId.MODE_DATETIME) -> when { + keyboardId.isNumberLayout || keyboardId.mode in listOf(KeyboardId.MODE_EMAIL, KeyboardId.MODE_DATE, KeyboardId.MODE_TIME, KeyboardId.MODE_DATETIME) -> when { action == EditorInfo.IME_ACTION_NEXT && navigatePrev -> POPUP_KEYS_NAVIGATE_PREVIOUS action == EditorInfo.IME_ACTION_NEXT -> null action == EditorInfo.IME_ACTION_PREVIOUS && navigateNext -> POPUP_KEYS_NAVIGATE_NEXT @@ -206,7 +206,7 @@ sealed interface KeyData : AbstractKeyData { } // remove emoji shortcut on enter in tablet mode (like original, because bottom row always has an emoji key) // (probably not necessary, but whatever) and in emoji mode - if ((Settings.getInstance().isTablet || params.mId.mElementId == KeyboardId.ELEMENT_EMOJI_BOTTOM_ROW) + if ((Settings.getInstance().isTablet || params.mId.elementId == KeyboardId.ELEMENT_EMOJI_BOTTOM_ROW) && popupKeys.remove("!icon/emoji_action_key|!code/key_emoji")) { val i = popupKeys.indexOfFirst { it.startsWith(Key.POPUP_KEYS_FIXED_COLUMN_ORDER) } if (i > -1) { @@ -215,16 +215,16 @@ sealed interface KeyData : AbstractKeyData { popupKeys[i] = popupKeys[i].replace(n.toString(), (n - 1).toString()) } } - if (params.mId.mElementId == KeyboardId.ELEMENT_CLIPBOARD_BOTTOM_ROW) + if (params.mId.elementId == KeyboardId.ELEMENT_CLIPBOARD_BOTTOM_ROW) popupKeys.remove("!icon/clipboard_action_key|!code/key_clipboard") return SimplePopups(popupKeys) } fun String.replaceIconWithLabelIfNoDrawable(params: KeyboardParams): String { if (params.mIconsSet.getIconDrawable(this) != null) return this - if (params.mId.mWidth == AndroidSpellCheckerService.SPELLCHECKER_DUMMY_KEYBOARD_WIDTH - && params.mId.mHeight == AndroidSpellCheckerService.SPELLCHECKER_DUMMY_KEYBOARD_HEIGHT - && !params.mId.mSubtype.hasExtraValue(Constants.Subtype.ExtraValue.EMOJI_CAPABLE) + if (params.mId.width == AndroidSpellCheckerService.SPELLCHECKER_DUMMY_KEYBOARD_WIDTH + && params.mId.height == AndroidSpellCheckerService.SPELLCHECKER_DUMMY_KEYBOARD_HEIGHT + && !params.mId.subtype.hasExtraValue(Constants.Subtype.ExtraValue.EMOJI_CAPABLE) ) // fake keyboard that is used by spell checker (for key coordinates), but not shown to the user // often this doesn't have any icons loaded, and there is no need to bother with this @@ -239,8 +239,8 @@ sealed interface KeyData : AbstractKeyData { private fun shouldShowTldPopups(params: KeyboardParams): Boolean = (Settings.getInstance().current.mShowTldPopupKeys - && params.mId.mSubtype.layouts[LayoutType.FUNCTIONAL] != "functional_keys_tablet" - && params.mId.mMode in setOf(KeyboardId.MODE_URL, KeyboardId.MODE_EMAIL)) + && params.mId.subtype.layouts[LayoutType.FUNCTIONAL] != "functional_keys_tablet" + && params.mId.mode in setOf(KeyboardId.MODE_URL, KeyboardId.MODE_EMAIL)) // could make arrays right away, but they need to be copied anyway as popupKeys arrays are modified when creating KeyParams private const val POPUP_KEYS_NAVIGATE_PREVIOUS = "!icon/previous_key|!code/key_action_previous,!icon/clipboard_action_key|!code/key_clipboard" @@ -304,14 +304,14 @@ sealed interface KeyData : AbstractKeyData { require(width >= 0f || width == -1f) { "illegal width $width" } val newLabel = label.convertFlorisLabel().resolveStringLabel(params) if (newLabel == KeyLabel.SHIFT && params.mId.isAlphabetKeyboard - && params.mId.mSubtype.hasExtraValue(Constants.Subtype.ExtraValue.NO_SHIFT_KEY)) { + && params.mId.subtype.hasExtraValue(Constants.Subtype.ExtraValue.NO_SHIFT_KEY)) { return null } val newCode = code.checkAndConvertCode() val newLabelFlags = if (labelFlags == 0 && params.mId.isNumberLayout) { if (type == KeyType.NUMERIC) { - when (params.mId.mElementId) { + when (params.mId.elementId) { KeyboardId.ELEMENT_PHONE -> Key.LABEL_FLAGS_ALIGN_LABEL_OFF_CENTER or Key.LABEL_FLAGS_HAS_HINT_LABEL or Key.LABEL_FLAGS_FOLLOW_KEY_LARGE_LETTER_RATIO KeyboardId.ELEMENT_PHONE_SYMBOLS -> 0 else -> Key.LABEL_FLAGS_FOLLOW_KEY_LARGE_LETTER_RATIO @@ -411,7 +411,7 @@ sealed interface KeyData : AbstractKeyData { KeyLabel.SHIFT -> return Key.BACKGROUND_TYPE_FUNCTIONAL } if (type == KeyType.PLACEHOLDER) return Key.BACKGROUND_TYPE_EMPTY - if ((params.mId.mElementId == KeyboardId.ELEMENT_SYMBOLS || params.mId.mElementId == KeyboardId.ELEMENT_SYMBOLS_SHIFTED) + if ((params.mId.elementId == KeyboardId.ELEMENT_SYMBOLS || params.mId.elementId == KeyboardId.ELEMENT_SYMBOLS_SHIFTED) && (groupId == GROUP_COMMA || groupId == GROUP_PERIOD)) return Key.BACKGROUND_TYPE_FUNCTIONAL return Key.BACKGROUND_TYPE_NORMAL diff --git a/app/src/main/java/helium314/keyboard/latin/LatinIME.java b/app/src/main/java/helium314/keyboard/latin/LatinIME.java index fe5458ab61..abe84c2371 100644 --- a/app/src/main/java/helium314/keyboard/latin/LatinIME.java +++ b/app/src/main/java/helium314/keyboard/latin/LatinIME.java @@ -1712,7 +1712,7 @@ protected void dump(final FileDescriptor fd, final PrintWriter fout, final Strin p.println(" VersionCode = " + BuildConfig.VERSION_CODE); p.println(" VersionName = " + BuildConfig.VERSION_NAME); final Keyboard keyboard = mKeyboardSwitcher.getKeyboard(); - final int keyboardMode = keyboard != null ? keyboard.mId.mMode : -1; + final int keyboardMode = keyboard != null ? keyboard.mId.mode : -1; p.println(" Keyboard mode = " + keyboardMode); final SettingsValues settingsValues = mSettings.getCurrent(); p.println(settingsValues.dump()); diff --git a/app/src/main/java/helium314/keyboard/latin/inputlogic/InputLogic.java b/app/src/main/java/helium314/keyboard/latin/inputlogic/InputLogic.java index afa7162e66..2f72a39b8f 100644 --- a/app/src/main/java/helium314/keyboard/latin/inputlogic/InputLogic.java +++ b/app/src/main/java/helium314/keyboard/latin/inputlogic/InputLogic.java @@ -2648,7 +2648,7 @@ private void setInlineEmojiSearchAction(boolean on) { private static boolean isInlineEmojiSearchAction() { var keyboard = KeyboardSwitcher.getInstance().getKeyboard(); - var internalAction = keyboard != null? keyboard.mId.mInternalAction : null; + var internalAction = keyboard != null? keyboard.mId.internalAction : null; return internalAction != null && internalAction.code() == KeyCode.INLINE_EMOJI_SEARCH_DONE; } diff --git a/app/src/main/java/helium314/keyboard/latin/utils/PopupKeysUtils.kt b/app/src/main/java/helium314/keyboard/latin/utils/PopupKeysUtils.kt index 7cb6c7846d..ad0f56a61c 100644 --- a/app/src/main/java/helium314/keyboard/latin/utils/PopupKeysUtils.kt +++ b/app/src/main/java/helium314/keyboard/latin/utils/PopupKeysUtils.kt @@ -92,7 +92,7 @@ private fun transformLabel(label: String, params: KeyboardParams): String = params.mLocaleKeyboardInfos.currencyKey.second[index - 1] else label } - } else if (params.mId.mSubtype.isRtlSubtype) { + } else if (params.mId.subtype.isRtlSubtype) { label.rtlLabel(params) } else label From a1ddcb53b7951dd1894ee2dc1707f2ae66cf1cab Mon Sep 17 00:00:00 2001 From: devycarol <[email protected]> Date: Mon, 12 Jan 2026 14:18:24 -0700 Subject: [PATCH 3/7] don't do this btw --- .../java/helium314/keyboard/keyboard/Key.java | 7 ++--- .../keyboard/keyboard/KeyboardId.java | 27 ++++++++++--------- .../keyboard/latin/NgramContext.java | 3 ++- .../latin/makedict/ProbabilityInfo.java | 5 ++-- .../latin/makedict/WeightedString.java | 3 ++- .../keyboard/latin/makedict/WordProperty.java | 5 ++-- 6 files changed, 28 insertions(+), 22 deletions(-) diff --git a/app/src/main/java/helium314/keyboard/keyboard/Key.java b/app/src/main/java/helium314/keyboard/keyboard/Key.java index f1f2cbcaf7..5f3ea4ce9d 100644 --- a/app/src/main/java/helium314/keyboard/keyboard/Key.java +++ b/app/src/main/java/helium314/keyboard/keyboard/Key.java @@ -28,6 +28,7 @@ import java.util.Arrays; import java.util.Locale; +import java.util.Objects; import androidx.annotation.NonNull; import androidx.annotation.Nullable; @@ -373,7 +374,7 @@ private static boolean needsToUpcase(final int labelFlags, final int keyboardEle } private static int computeHashCode(final Key key) { - return Arrays.hashCode(new Object[] { + return Objects.hash( key.mX, key.mY, key.mWidth, @@ -386,7 +387,7 @@ private static int computeHashCode(final Key key) { Arrays.hashCode(key.mPopupKeys), key.getOutputText(), key.mActionFlags, - key.mLabelFlags, + key.mLabelFlags // Key can be distinguishable without the following members. // key.mOptionalAttributes.mAltCode, // key.mOptionalAttributes.mDisabledIconId, @@ -396,7 +397,7 @@ private static int computeHashCode(final Key key) { // key.mOptionalAttributes.mVisualInsetLeft, // key.mOptionalAttributes.mVisualInsetRight, // key.mMaxPopupKeysColumn, - }); + ); } private boolean equalsInternal(final Key o) { diff --git a/app/src/main/java/helium314/keyboard/keyboard/KeyboardId.java b/app/src/main/java/helium314/keyboard/keyboard/KeyboardId.java index 3b542db655..caa9aaf557 100644 --- a/app/src/main/java/helium314/keyboard/keyboard/KeyboardId.java +++ b/app/src/main/java/helium314/keyboard/keyboard/KeyboardId.java @@ -110,7 +110,7 @@ public KeyboardId(int elementId, KeyboardLayoutSet.Params params) { } private static int computeHashCode(KeyboardId id) { - return Arrays.hashCode(new Object[] { + return Objects.hash( id.elementId, id.mode, id.width, @@ -129,7 +129,7 @@ private static int computeHashCode(KeyboardId id) { id.subtype, id.isSplitLayout, id.internalAction - }); + ); } private boolean equals(KeyboardId other) { @@ -233,19 +233,20 @@ public String toString() { elementIdToName(elementId), subtype.getLocale(), subtype.getExtraValueOf(KEYBOARD_LAYOUT_SET), - width, height, + width, + height, modeName(mode), actionName(imeAction()), - (navigateNext() ? " navigateNext" : ""), - (navigatePrevious() ? " navigatePrevious" : ""), - (deviceLocked ? " deviceLocked" : ""), - (passwordInput() ? " passwordInput" : ""), - (hasShortcutKey ? " hasShortcutKey" : ""), - (numberRowEnabled ? " numberRowEnabled" : ""), - (languageSwitchKeyEnabled ? " languageSwitchKeyEnabled" : ""), - (emojiKeyEnabled ? " emojiKeyEnabled" : ""), - (isMultiLine() ? " isMultiLine" : ""), - (isSplitLayout ? " isSplitLayout" : "") + navigateNext() ? " navigateNext" : "", + navigatePrevious() ? " navigatePrevious" : "", + deviceLocked ? " deviceLocked" : "", + passwordInput() ? " passwordInput" : "", + hasShortcutKey ? " hasShortcutKey" : "", + numberRowEnabled ? " numberRowEnabled" : "", + languageSwitchKeyEnabled ? " languageSwitchKeyEnabled" : "", + emojiKeyEnabled ? " emojiKeyEnabled" : "", + isMultiLine() ? " isMultiLine" : "", + isSplitLayout ? " isSplitLayout" : "" ); } diff --git a/app/src/main/java/helium314/keyboard/latin/NgramContext.java b/app/src/main/java/helium314/keyboard/latin/NgramContext.java index 45871507d3..9dd328ffba 100644 --- a/app/src/main/java/helium314/keyboard/latin/NgramContext.java +++ b/app/src/main/java/helium314/keyboard/latin/NgramContext.java @@ -15,6 +15,7 @@ import java.util.ArrayList; import java.util.Arrays; +import java.util.Objects; /** * Class to represent information of previous words. This class is used to add n-gram entries @@ -69,7 +70,7 @@ public boolean isValid() { @Override public int hashCode() { - return Arrays.hashCode(new Object[] { mWord, mIsBeginningOfSentence } ); + return Objects.hash(mWord, mIsBeginningOfSentence); } @Override diff --git a/app/src/main/java/helium314/keyboard/latin/makedict/ProbabilityInfo.java b/app/src/main/java/helium314/keyboard/latin/makedict/ProbabilityInfo.java index 512c130166..4489bf16c8 100644 --- a/app/src/main/java/helium314/keyboard/latin/makedict/ProbabilityInfo.java +++ b/app/src/main/java/helium314/keyboard/latin/makedict/ProbabilityInfo.java @@ -10,6 +10,7 @@ import helium314.keyboard.latin.utils.CombinedFormatUtils; import java.util.Arrays; +import java.util.Objects; public final class ProbabilityInfo { public final int mProbability; @@ -51,9 +52,9 @@ public boolean hasHistoricalInfo() { @Override public int hashCode() { if (hasHistoricalInfo()) { - return Arrays.hashCode(new Object[] { mProbability, mTimestamp, mLevel, mCount }); + return Objects.hash(mProbability, mTimestamp, mLevel, mCount); } - return Arrays.hashCode(new Object[] { mProbability }); + return Objects.hash(mProbability); } @Override diff --git a/app/src/main/java/helium314/keyboard/latin/makedict/WeightedString.java b/app/src/main/java/helium314/keyboard/latin/makedict/WeightedString.java index ce4d8d219a..2322c7fade 100644 --- a/app/src/main/java/helium314/keyboard/latin/makedict/WeightedString.java +++ b/app/src/main/java/helium314/keyboard/latin/makedict/WeightedString.java @@ -7,6 +7,7 @@ package helium314.keyboard.latin.makedict; import java.util.Arrays; +import java.util.Objects; /** * A string with a probability. @@ -36,7 +37,7 @@ public void setProbability(final int probability) { @Override public int hashCode() { - return Arrays.hashCode(new Object[] { mWord, mProbabilityInfo}); + return Objects.hash(mWord, mProbabilityInfo); } @Override diff --git a/app/src/main/java/helium314/keyboard/latin/makedict/WordProperty.java b/app/src/main/java/helium314/keyboard/latin/makedict/WordProperty.java index 7aaa76d9f5..29d5f54b96 100644 --- a/app/src/main/java/helium314/keyboard/latin/makedict/WordProperty.java +++ b/app/src/main/java/helium314/keyboard/latin/makedict/WordProperty.java @@ -18,6 +18,7 @@ import java.util.ArrayList; import java.util.Arrays; +import java.util.Objects; /** * Utility class for a word with a probability. @@ -139,14 +140,14 @@ public int getProbability() { } private static int computeHashCode(WordProperty word) { - return Arrays.hashCode(new Object[] { + return Objects.hash( word.mWord, word.mProbabilityInfo, word.mShortcutTargets, word.mNgrams, word.mIsNotAWord, word.mIsPossiblyOffensive - }); + ); } /** From bf15d9626625bd64edbbd0793b904e44a887b221 Mon Sep 17 00:00:00 2001 From: devycarol <[email protected]> Date: Mon, 12 Jan 2026 16:02:45 -0700 Subject: [PATCH 4/7] unnecessary final --- .../keyboard/keyboard/KeyboardLayoutSet.java | 139 ++++++++---------- 1 file changed, 65 insertions(+), 74 deletions(-) diff --git a/app/src/main/java/helium314/keyboard/keyboard/KeyboardLayoutSet.java b/app/src/main/java/helium314/keyboard/keyboard/KeyboardLayoutSet.java index 8de5e6fe59..e6e361c449 100644 --- a/app/src/main/java/helium314/keyboard/keyboard/KeyboardLayoutSet.java +++ b/app/src/main/java/helium314/keyboard/keyboard/KeyboardLayoutSet.java @@ -64,7 +64,7 @@ public final class KeyboardLayoutSet { public static final class KeyboardLayoutSetException extends RuntimeException { public final KeyboardId mKeyboardId; - public KeyboardLayoutSetException(final Throwable cause, final KeyboardId keyboardId) { + public KeyboardLayoutSetException(Throwable cause, KeyboardId keyboardId) { super(cause); mKeyboardId = keyboardId; } @@ -118,47 +118,44 @@ private static void clearKeyboardCache() { KeyboardIconsSet.Companion.setNeedsReload(true); } - KeyboardLayoutSet(final Context context, @NonNull final Params params) { + KeyboardLayoutSet(Context context, @NonNull Params params) { mContext = context; mParams = params; mLocaleKeyboardInfos = LocaleKeyboardInfosKt.getOrCreate(context, params.mSubtype.getLocale()); } @NonNull - public Keyboard getKeyboard(final int baseKeyboardLayoutSetElementId) { - final int keyboardLayoutSetElementId; - switch (mParams.mMode) { - case KeyboardId.MODE_PHONE -> { - if (baseKeyboardLayoutSetElementId == KeyboardId.ELEMENT_SYMBOLS) { - keyboardLayoutSetElementId = KeyboardId.ELEMENT_PHONE_SYMBOLS; - } else { - keyboardLayoutSetElementId = KeyboardId.ELEMENT_PHONE; - } - } - case KeyboardId.MODE_NUMPAD -> keyboardLayoutSetElementId = KeyboardId.ELEMENT_NUMPAD; - case KeyboardId.MODE_NUMBER, KeyboardId.MODE_DATE, KeyboardId.MODE_TIME, KeyboardId.MODE_DATETIME -> - keyboardLayoutSetElementId = KeyboardId.ELEMENT_NUMBER; - default -> keyboardLayoutSetElementId = baseKeyboardLayoutSetElementId; - } + public Keyboard getKeyboard(int baseKeyboardLayoutSetElementId) { + int keyboardLayoutSetElementId = switch (mParams.mMode) { + case KeyboardId.MODE_PHONE -> baseKeyboardLayoutSetElementId == KeyboardId.ELEMENT_SYMBOLS + ? KeyboardId.ELEMENT_PHONE_SYMBOLS + : KeyboardId.ELEMENT_PHONE; + case KeyboardId.MODE_NUMPAD -> KeyboardId.ELEMENT_NUMPAD; + case KeyboardId.MODE_NUMBER, + KeyboardId.MODE_DATE, + KeyboardId.MODE_TIME, + KeyboardId.MODE_DATETIME -> KeyboardId.ELEMENT_NUMBER; + default -> baseKeyboardLayoutSetElementId; + }; // Note: The keyboard for each shift state, and mode are represented as an elementName // attribute in a keyboard_layout_set XML file. Also each keyboard layout XML resource is // specified as an elementKeyboard attribute in the file. // The KeyboardId is an internal key for a Keyboard object. - final KeyboardId id = new KeyboardId(keyboardLayoutSetElementId, mParams); + var id = new KeyboardId(keyboardLayoutSetElementId, mParams); try { return getKeyboard(id); - } catch (final RuntimeException e) { + } catch (RuntimeException e) { Log.e(TAG, "Can't create keyboard: " + id, e); throw new KeyboardLayoutSetException(e, id); } } @NonNull - private Keyboard getKeyboard(final KeyboardId id) { - final SoftReference ref = sKeyboardCache.get(id); - final Keyboard cachedKeyboard = (ref == null) ? null : ref.get(); + private Keyboard getKeyboard(KeyboardId id) { + SoftReference ref = sKeyboardCache.get(id); + Keyboard cachedKeyboard = (ref == null) ? null : ref.get(); if (cachedKeyboard != null) { if (DEBUG_CACHE) { Log.d(TAG, "keyboard cache size=" + sKeyboardCache.size() + ": HIT id=" + id); @@ -166,14 +163,13 @@ private Keyboard getKeyboard(final KeyboardId id) { return cachedKeyboard; } - final KeyboardBuilder builder = - new KeyboardBuilder<>(mContext, new KeyboardParams(sUniqueKeysCache)); + var builder = new KeyboardBuilder(mContext, new KeyboardParams(sUniqueKeysCache)); sUniqueKeysCache.setEnabled(id.isAlphabetKeyboard()); builder.load(id); if (mParams.mDisableTouchPositionCorrectionDataForTest) { builder.disableTouchPositionCorrectionDataForTest(); } - final Keyboard keyboard = builder.build(); + Keyboard keyboard = builder.build(); sKeyboardCache.put(id, new SoftReference<>(keyboard)); if ((id.elementId == KeyboardId.ELEMENT_ALPHABET || id.elementId == KeyboardId.ELEMENT_ALPHABET_AUTOMATIC_SHIFTED) @@ -205,11 +201,11 @@ public static final class Builder { private static final EditorInfo EMPTY_EDITOR_INFO = new EditorInfo(); - public Builder(final Context context, @Nullable final EditorInfo ei) { + public Builder(Context context, @Nullable EditorInfo ei) { mContext = context; - final Params params = mParams; + Params params = mParams; - final EditorInfo editorInfo = (ei != null) ? ei : EMPTY_EDITOR_INFO; + EditorInfo editorInfo = (ei != null) ? ei : EMPTY_EDITOR_INFO; params.mMode = getKeyboardMode(editorInfo); // TODO: Consolidate those with {@link InputAttributes}. params.mEditorInfo = editorInfo; @@ -218,58 +214,58 @@ public Builder(final Context context, @Nullable final EditorInfo ei) { params.mDeviceLocked = IsLockedCompatKt.isDeviceLocked(context); } - public static KeyboardLayoutSet buildEmojiClipBottomRow(final Context context, @Nullable final EditorInfo ei) { - final Builder builder = new Builder(context, ei); + public static KeyboardLayoutSet buildEmojiClipBottomRow(Context context, @Nullable EditorInfo ei) { + var builder = new Builder(context, ei); builder.mParams.mMode = KeyboardId.MODE_TEXT; - final int width = ResourceUtils.getKeyboardWidth(context, Settings.getValues()); + int width = ResourceUtils.getKeyboardWidth(context, Settings.getValues()); // actually the keyboard does not have full height, but at this point we use it to get correct key heights - final int height = ResourceUtils.getKeyboardHeight(context.getResources(), Settings.getValues()); + int height = ResourceUtils.getKeyboardHeight(context.getResources(), Settings.getValues()); builder.setKeyboardGeometry(width, height); builder.setSubtype(RichInputMethodManager.getInstance().getCurrentSubtype()); return builder.build(); } - public Builder setKeyboardGeometry(final int keyboardWidth, final int keyboardHeight) { + public Builder setKeyboardGeometry(int keyboardWidth, int keyboardHeight) { mParams.mKeyboardWidth = keyboardWidth; mParams.mKeyboardHeight = keyboardHeight; return this; } - public Builder setSubtype(@NonNull final RichInputMethodSubtype subtype) { - final boolean asciiCapable = subtype.getRawSubtype().isAsciiCapable(); - final boolean forceAscii = (mParams.mEditorInfo.imeOptions & EditorInfo.IME_FLAG_FORCE_ASCII) != 0; + public Builder setSubtype(@NonNull RichInputMethodSubtype subtype) { + boolean asciiCapable = subtype.getRawSubtype().isAsciiCapable(); + boolean forceAscii = (mParams.mEditorInfo.imeOptions & EditorInfo.IME_FLAG_FORCE_ASCII) != 0; mParams.mSubtype = (forceAscii && !asciiCapable) ? RichInputMethodSubtype.Companion.getNoLanguageSubtype() : subtype; return this; } - public Builder setIsSpellChecker(final boolean isSpellChecker) { + public Builder setIsSpellChecker(boolean isSpellChecker) { mParams.mIsSpellChecker = isSpellChecker; return this; } - public Builder setVoiceInputKeyEnabled(final boolean enabled) { + public Builder setVoiceInputKeyEnabled(boolean enabled) { mParams.mVoiceInputKeyEnabled = enabled; return this; } - public Builder setNumberRowEnabled(final boolean enabled) { + public Builder setNumberRowEnabled(boolean enabled) { mParams.mNumberRowEnabled = enabled; return this; } - public Builder setNumberRowInSymbolsEnabled(final boolean enabled) { + public Builder setNumberRowInSymbolsEnabled(boolean enabled) { mParams.mNumberRowInSymbols = enabled; return this; } - public Builder setLanguageSwitchKeyEnabled(final boolean enabled) { + public Builder setLanguageSwitchKeyEnabled(boolean enabled) { mParams.mLanguageSwitchKeyEnabled = enabled; return this; } - public Builder setEmojiKeyEnabled(final boolean enabled) { + public Builder setEmojiKeyEnabled(boolean enabled) { mParams.mEmojiKeyEnabled = enabled; return this; } @@ -279,7 +275,7 @@ public Builder disableTouchPositionCorrectionData() { return this; } - public Builder setSplitLayoutEnabled(final boolean enabled) { + public Builder setSplitLayoutEnabled(boolean enabled) { mParams.mIsSplitLayoutEnabled = enabled; return this; } @@ -301,43 +297,38 @@ public KeyboardLayoutSet build() { return new KeyboardLayoutSet(mContext, mParams); } - private static int getKeyboardMode(final EditorInfo editorInfo) { - final int inputType = editorInfo.inputType; - final int variation = inputType & InputType.TYPE_MASK_VARIATION; - - switch (inputType & InputType.TYPE_MASK_CLASS) { - case InputType.TYPE_CLASS_NUMBER: - return KeyboardId.MODE_NUMBER; - case InputType.TYPE_CLASS_DATETIME: - return switch (variation) { - case InputType.TYPE_DATETIME_VARIATION_DATE -> KeyboardId.MODE_DATE; - case InputType.TYPE_DATETIME_VARIATION_TIME -> KeyboardId.MODE_TIME; - default -> KeyboardId.MODE_DATETIME; // must be InputType.TYPE_DATETIME_VARIATION_NORMAL - }; - case InputType.TYPE_CLASS_PHONE: - return KeyboardId.MODE_PHONE; - case InputType.TYPE_CLASS_TEXT: + private static int getKeyboardMode(EditorInfo editorInfo) { + int inputType = editorInfo.inputType; + int variation = inputType & InputType.TYPE_MASK_VARIATION; + + return switch (inputType & InputType.TYPE_MASK_CLASS) { + case InputType.TYPE_CLASS_NUMBER -> KeyboardId.MODE_NUMBER; + case InputType.TYPE_CLASS_DATETIME -> switch (variation) { + case InputType.TYPE_DATETIME_VARIATION_DATE -> KeyboardId.MODE_DATE; + case InputType.TYPE_DATETIME_VARIATION_TIME -> KeyboardId.MODE_TIME; + default -> KeyboardId.MODE_DATETIME; // must be InputType.TYPE_DATETIME_VARIATION_NORMAL + }; + case InputType.TYPE_CLASS_PHONE -> KeyboardId.MODE_PHONE; + case InputType.TYPE_CLASS_TEXT -> { if (InputTypeUtils.isEmailVariation(variation)) { - return KeyboardId.MODE_EMAIL; - } else if (variation == InputType.TYPE_TEXT_VARIATION_URI) { - return KeyboardId.MODE_URL; - } else if (variation == InputType.TYPE_TEXT_VARIATION_SHORT_MESSAGE) { - //return KeyboardId.MODE_IM; - return KeyboardId.MODE_TEXT; - } else if (variation == InputType.TYPE_TEXT_VARIATION_FILTER) { - return KeyboardId.MODE_TEXT; - } else { - return KeyboardId.MODE_TEXT; + yield KeyboardId.MODE_EMAIL; } - default: - return KeyboardId.MODE_TEXT; - } + yield switch (variation) { + case InputType.TYPE_TEXT_VARIATION_URI -> KeyboardId.MODE_URL; + case InputType.TYPE_TEXT_VARIATION_SHORT_MESSAGE -> + //KeyboardId.MODE_IM; + KeyboardId.MODE_TEXT; + default -> KeyboardId.MODE_TEXT; + }; + } + default -> KeyboardId.MODE_TEXT; + }; } } // used for testing keyboard layout files without actually creating a keyboard - public static KeyboardId getFakeKeyboardId(final int elementId) { - final Params params = new Params(); + public static KeyboardId getFakeKeyboardId(int elementId) { + var params = new Params(); params.mEditorInfo = new EditorInfo(); params.mSubtype = RichInputMethodSubtype.Companion.getEmojiSubtype(); params.mSubtype.getMainLayoutName(); From 78217b6430d8354c4bea6888c5f9867d2c289975 Mon Sep 17 00:00:00 2001 From: devycarol <[email protected]> Date: Mon, 12 Jan 2026 18:05:13 -0700 Subject: [PATCH 5/7] KeyboardElement and KeyboardMode enums --- .../accessibility/KeyCodeDescriptionMapper.kt | 24 +-- .../MainKeyboardAccessibilityDelegate.kt | 70 +++--- .../java/helium314/keyboard/keyboard/Key.java | 16 +- .../helium314/keyboard/keyboard/Keyboard.java | 6 +- .../keyboard/KeyboardActionListenerImpl.kt | 2 +- .../keyboard/keyboard/KeyboardElement.java | 83 ++++++++ .../keyboard/keyboard/KeyboardId.java | 200 +++--------------- .../keyboard/keyboard/KeyboardLayoutSet.java | 60 +++--- .../keyboard/keyboard/KeyboardMode.java | 32 +++ .../keyboard/keyboard/KeyboardSwitcher.java | 53 ++--- .../keyboard/keyboard/KeyboardView.java | 8 +- .../keyboard/keyboard/PointerTracker.java | 2 +- .../clipboard/ClipboardHistoryView.kt | 4 +- .../keyboard/emoji/EmojiCategory.java | 93 ++++---- .../keyboard/emoji/EmojiPalettesView.java | 4 +- .../keyboard/internal/KeyboardBuilder.kt | 17 +- .../keyboard/internal/KeyboardParams.java | 4 +- .../internal/keyboard_parser/EmojiParser.kt | 29 +-- .../keyboard_parser/KeyboardParser.kt | 53 ++--- .../internal/keyboard_parser/LayoutParser.kt | 4 +- .../keyboard_parser/LocaleKeyboardInfos.kt | 10 +- .../keyboard_parser/floris/KeyData.kt | 61 +++--- .../keyboard_parser/floris/KeyLabel.kt | 45 ++-- .../keyboard_parser/floris/TextKeyData.kt | 66 +++--- .../keyboard/latin/InputAttributes.java | 2 +- .../helium314/keyboard/latin/LatinIME.java | 16 +- .../java/helium314/keyboard/latin/Suggest.kt | 6 +- .../dictionary/DictionaryCollection.java | 2 +- .../keyboard/latin/inputlogic/InputLogic.java | 13 +- .../AndroidSpellCheckerService.java | 4 +- .../keyboard/latin/utils/LayoutUtilsCustom.kt | 4 +- .../keyboard/latin/utils/PopupKeysUtils.kt | 2 +- app/src/main/res/values/attrs.xml | 42 ---- .../values/strings-talkback-descriptions.xml | 8 + .../helium314/keyboard/KeyboardParserTest.kt | 19 +- .../java/helium314/keyboard/SubtypeTest.kt | 4 +- 36 files changed, 498 insertions(+), 570 deletions(-) create mode 100644 app/src/main/java/helium314/keyboard/keyboard/KeyboardElement.java create mode 100644 app/src/main/java/helium314/keyboard/keyboard/KeyboardMode.java diff --git a/app/src/main/java/helium314/keyboard/accessibility/KeyCodeDescriptionMapper.kt b/app/src/main/java/helium314/keyboard/accessibility/KeyCodeDescriptionMapper.kt index 36c7af5337..9f7f9ac7a9 100644 --- a/app/src/main/java/helium314/keyboard/accessibility/KeyCodeDescriptionMapper.kt +++ b/app/src/main/java/helium314/keyboard/accessibility/KeyCodeDescriptionMapper.kt @@ -13,7 +13,7 @@ import android.util.SparseIntArray import android.view.inputmethod.EditorInfo import helium314.keyboard.keyboard.Key import helium314.keyboard.keyboard.Keyboard -import helium314.keyboard.keyboard.KeyboardId +import helium314.keyboard.keyboard.KeyboardElement import helium314.keyboard.keyboard.internal.keyboard_parser.floris.KeyCode import helium314.keyboard.latin.R import helium314.keyboard.latin.common.Constants @@ -129,13 +129,13 @@ internal class KeyCodeDescriptionMapper private constructor() { * @return a character sequence describing the action performed by pressing the key */ private fun getDescriptionForSwitchAlphaSymbol(context: Context, keyboard: Keyboard?): String? { - val resId = when (val elementId = keyboard?.mId?.elementId) { - KeyboardId.ELEMENT_ALPHABET, KeyboardId.ELEMENT_ALPHABET_AUTOMATIC_SHIFTED, KeyboardId.ELEMENT_ALPHABET_MANUAL_SHIFTED, KeyboardId.ELEMENT_ALPHABET_SHIFT_LOCK_SHIFTED, KeyboardId.ELEMENT_ALPHABET_SHIFT_LOCKED -> R.string.spoken_description_to_symbol - KeyboardId.ELEMENT_SYMBOLS, KeyboardId.ELEMENT_SYMBOLS_SHIFTED -> R.string.spoken_description_to_alpha - KeyboardId.ELEMENT_PHONE -> R.string.spoken_description_to_symbol - KeyboardId.ELEMENT_PHONE_SYMBOLS -> R.string.spoken_description_to_numeric + val resId = when (val element = keyboard?.mId?.element) { + KeyboardElement.ALPHABET, KeyboardElement.ALPHABET_AUTOMATIC_SHIFTED, KeyboardElement.ALPHABET_MANUAL_SHIFTED, KeyboardElement.ALPHABET_SHIFT_LOCK_SHIFTED, KeyboardElement.ALPHABET_SHIFT_LOCKED -> R.string.spoken_description_to_symbol + KeyboardElement.SYMBOLS, KeyboardElement.SYMBOLS_SHIFTED -> R.string.spoken_description_to_alpha + KeyboardElement.PHONE -> R.string.spoken_description_to_symbol + KeyboardElement.PHONE_SYMBOLS -> R.string.spoken_description_to_numeric else -> { - Log.e(TAG, "Missing description for keyboard element ID:$elementId") + Log.e(TAG, "Missing description for keyboard element ID:$element") return null } } @@ -150,11 +150,11 @@ internal class KeyCodeDescriptionMapper private constructor() { * @return A context-sensitive description of the "Shift" key. */ private fun getDescriptionForShiftKey(context: Context, keyboard: Keyboard?): String { - val resId: Int = when (keyboard?.mId?.elementId) { - KeyboardId.ELEMENT_ALPHABET_SHIFT_LOCK_SHIFTED, KeyboardId.ELEMENT_ALPHABET_SHIFT_LOCKED -> R.string.spoken_description_caps_lock - KeyboardId.ELEMENT_ALPHABET_AUTOMATIC_SHIFTED, KeyboardId.ELEMENT_ALPHABET_MANUAL_SHIFTED -> R.string.spoken_description_shift_shifted - KeyboardId.ELEMENT_SYMBOLS -> R.string.spoken_description_symbols_shift - KeyboardId.ELEMENT_SYMBOLS_SHIFTED -> R.string.spoken_description_symbols_shift_shifted + val resId: Int = when (keyboard?.mId?.element) { + KeyboardElement.ALPHABET_SHIFT_LOCK_SHIFTED, KeyboardElement.ALPHABET_SHIFT_LOCKED -> R.string.spoken_description_caps_lock + KeyboardElement.ALPHABET_AUTOMATIC_SHIFTED, KeyboardElement.ALPHABET_MANUAL_SHIFTED -> R.string.spoken_description_shift_shifted + KeyboardElement.SYMBOLS -> R.string.spoken_description_symbols_shift + KeyboardElement.SYMBOLS_SHIFTED -> R.string.spoken_description_symbols_shift_shifted else -> R.string.spoken_description_shift } return context.getString(resId) diff --git a/app/src/main/java/helium314/keyboard/accessibility/MainKeyboardAccessibilityDelegate.kt b/app/src/main/java/helium314/keyboard/accessibility/MainKeyboardAccessibilityDelegate.kt index e421df9bb3..bc14f3e1a1 100644 --- a/app/src/main/java/helium314/keyboard/accessibility/MainKeyboardAccessibilityDelegate.kt +++ b/app/src/main/java/helium314/keyboard/accessibility/MainKeyboardAccessibilityDelegate.kt @@ -9,7 +9,6 @@ package helium314.keyboard.accessibility import android.graphics.Rect import android.os.SystemClock import helium314.keyboard.latin.utils.Log -import android.util.SparseIntArray import android.view.MotionEvent import helium314.keyboard.accessibility.AccessibilityLongPressTimer.LongPressTimerCallback import helium314.keyboard.keyboard.* @@ -25,7 +24,7 @@ class MainKeyboardAccessibilityDelegate( keyDetector: KeyDetector ) : KeyboardAccessibilityDelegate(mainKeyboardView, keyDetector), LongPressTimerCallback { /** The most recently set keyboard mode. */ - private var mLastKeyboardMode = KEYBOARD_IS_HIDDEN + private var mLastKeyboardMode: KeyboardMode? = null // The rectangle region to ignore hover events. private val mBoundsToIgnoreHoverEvent = Rect() private val mAccessibilityLongPressTimer = AccessibilityLongPressTimer(this /* callback */, mainKeyboardView.context) @@ -64,7 +63,7 @@ class MainKeyboardAccessibilityDelegate( return } // Announce the keyboard type only when the type is changed. - if (keyboard.mId.elementId != lastKeyboard.mId.elementId) { + if (keyboard.mId.element != lastKeyboard.mId.element) { announceKeyboardType(keyboard, lastKeyboard) return } @@ -74,10 +73,10 @@ class MainKeyboardAccessibilityDelegate( * Called when the keyboard is hidden and accessibility is enabled. */ fun onHideWindow() { - if (mLastKeyboardMode != KEYBOARD_IS_HIDDEN) { + if (mLastKeyboardMode != null) { announceKeyboardHidden() } - mLastKeyboardMode = KEYBOARD_IS_HIDDEN + mLastKeyboardMode = null } /** @@ -96,13 +95,10 @@ class MainKeyboardAccessibilityDelegate( * @param keyboard The new keyboard. */ private fun announceKeyboardMode(keyboard: Keyboard) { - val context = mKeyboardView.context - val modeTextResId = KEYBOARD_MODE_RES_IDS[keyboard.mId.mode] - if (modeTextResId == 0) { - return - } - val modeText = context.getString(modeTextResId) - val text = context.getString(R.string.announce_keyboard_mode, modeText) + val res = mKeyboardView.resources + val modeText = res.getString(keyboard.mId.mode.contentDescription) + val text = res.getString(R.string.announce_keyboard_mode, modeText) + // TODO: this is saying "Showing showing (text) keyboard" sendWindowStateChanged(text) } @@ -113,41 +109,40 @@ class MainKeyboardAccessibilityDelegate( * @param lastKeyboard The last keyboard. */ private fun announceKeyboardType(keyboard: Keyboard, lastKeyboard: Keyboard) { - val lastElementId = lastKeyboard.mId.elementId - val resId = when (keyboard.mId.elementId) { - KeyboardId.ELEMENT_ALPHABET_AUTOMATIC_SHIFTED, KeyboardId.ELEMENT_ALPHABET -> { - if (lastElementId == KeyboardId.ELEMENT_ALPHABET - || lastElementId == KeyboardId.ELEMENT_ALPHABET_AUTOMATIC_SHIFTED) { + val lastElement = lastKeyboard.mId.element + val element = keyboard.mId.element + when (element) { + KeyboardElement.ALPHABET, KeyboardElement.ALPHABET_AUTOMATIC_SHIFTED -> { + if (lastElement == KeyboardElement.ALPHABET || lastElement == KeyboardElement.ALPHABET_AUTOMATIC_SHIFTED) { // Transition between alphabet mode and automatic shifted mode should be silently // ignored because it can be determined by each key's talk back announce. return } - R.string.spoken_description_mode_alpha } - KeyboardId.ELEMENT_ALPHABET_MANUAL_SHIFTED -> { - if (lastElementId == KeyboardId.ELEMENT_ALPHABET_AUTOMATIC_SHIFTED) { + KeyboardElement.ALPHABET_MANUAL_SHIFTED -> { + if (lastElement == KeyboardElement.ALPHABET_AUTOMATIC_SHIFTED) { // Resetting automatic shifted mode by pressing the shift key causes the transition // from automatic shifted to manual shifted that should be silently ignored. return } - R.string.spoken_description_shiftmode_on } - KeyboardId.ELEMENT_ALPHABET_SHIFT_LOCK_SHIFTED -> { - if (lastElementId == KeyboardId.ELEMENT_ALPHABET_SHIFT_LOCKED) { + KeyboardElement.ALPHABET_SHIFT_LOCK_SHIFTED -> { + if (lastElement == KeyboardElement.ALPHABET_SHIFT_LOCKED) { // Resetting caps locked mode by pressing the shift key causes the transition // from shift locked to shift lock shifted that should be silently ignored. return } - R.string.spoken_description_shiftmode_locked } - KeyboardId.ELEMENT_ALPHABET_SHIFT_LOCKED -> R.string.spoken_description_shiftmode_locked - KeyboardId.ELEMENT_SYMBOLS -> R.string.spoken_description_mode_symbol - KeyboardId.ELEMENT_SYMBOLS_SHIFTED -> R.string.spoken_description_mode_symbol_shift - KeyboardId.ELEMENT_PHONE -> R.string.spoken_description_mode_phone - KeyboardId.ELEMENT_PHONE_SYMBOLS -> R.string.spoken_description_mode_phone_shift - else -> return + else -> {} + } + if (element.isEmojiLayout) { + // the emoji pages are handled in EmojiCategory + return + } + val contentDescription = element.contentDescription + if (contentDescription != 0) { + sendWindowStateChanged(contentDescription) } - sendWindowStateChanged(resId) } /** @@ -243,18 +238,5 @@ class MainKeyboardAccessibilityDelegate( companion object { private val TAG = MainKeyboardAccessibilityDelegate::class.java.simpleName - /** Map of keyboard modes to resource IDs. */ - private val KEYBOARD_MODE_RES_IDS = SparseIntArray().apply { - put(KeyboardId.MODE_DATE, R.string.keyboard_mode_date) - put(KeyboardId.MODE_DATETIME, R.string.keyboard_mode_date_time) - put(KeyboardId.MODE_EMAIL, R.string.keyboard_mode_email) - put(KeyboardId.MODE_IM, R.string.keyboard_mode_im) - put(KeyboardId.MODE_NUMBER, R.string.keyboard_mode_number) - put(KeyboardId.MODE_PHONE, R.string.keyboard_mode_phone) - put(KeyboardId.MODE_TEXT, R.string.keyboard_mode_text) - put(KeyboardId.MODE_TIME, R.string.keyboard_mode_time) - put(KeyboardId.MODE_URL, R.string.keyboard_mode_url) - } - private const val KEYBOARD_IS_HIDDEN = -1 } } diff --git a/app/src/main/java/helium314/keyboard/keyboard/Key.java b/app/src/main/java/helium314/keyboard/keyboard/Key.java index 5f3ea4ce9d..4b258174f6 100644 --- a/app/src/main/java/helium314/keyboard/keyboard/Key.java +++ b/app/src/main/java/helium314/keyboard/keyboard/Key.java @@ -364,13 +364,8 @@ public static Key removeRedundantPopupKeys(@NonNull final Key key, return (filteredPopupKeys == popupKeys) ? key : new Key(key, filteredPopupKeys); } - private static boolean needsToUpcase(final int labelFlags, final int keyboardElementId) { - if ((labelFlags & LABEL_FLAGS_PRESERVE_CASE) != 0) return false; - return switch (keyboardElementId) { - case KeyboardId.ELEMENT_ALPHABET_MANUAL_SHIFTED, KeyboardId.ELEMENT_ALPHABET_AUTOMATIC_SHIFTED, - KeyboardId.ELEMENT_ALPHABET_SHIFT_LOCKED, KeyboardId.ELEMENT_ALPHABET_SHIFT_LOCK_SHIFTED -> true; - default -> false; - }; + private static boolean needsToUpcase(final int labelFlags, final KeyboardElement element) { + return (labelFlags & LABEL_FLAGS_PRESERVE_CASE) == 0 && element.isAlphabetShifted(); } private static int computeHashCode(final Key key) { @@ -1072,10 +1067,11 @@ public KeyParams( mHeight = params.mDefaultRowHeight; mIconName = KeySpecParser.getIconName(keySpec); - final boolean needsToUpcase = needsToUpcase(mLabelFlags, params.mId.elementId); + KeyboardElement element = params.mId.element; + final boolean needsToUpcase = needsToUpcase(mLabelFlags, element); final Locale localeForUpcasing = params.mId.getLocale(); int actionFlags = 0; - if (params.mId.isNumberLayout()) + if (element.isNumberLayout()) actionFlags = ACTION_FLAGS_NO_KEY_PREVIEW; // label @@ -1154,7 +1150,7 @@ public KeyParams( // action flags don't need to be specified, they can be deduced from the key if (mCode == Constants.CODE_SPACE || mCode == KeyCode.LANGUAGE_SWITCH - || (mCode == KeyCode.SYMBOL_ALPHA && !params.mId.isAlphabetKeyboard()) + || (mCode == KeyCode.SYMBOL_ALPHA && !element.isAlphabetLayout()) ) actionFlags |= ACTION_FLAGS_ENABLE_LONG_PRESS; if (mCode <= Constants.CODE_SPACE && mCode != KeyCode.MULTIPLE_CODE_POINTS && mIconName == null) diff --git a/app/src/main/java/helium314/keyboard/keyboard/Keyboard.java b/app/src/main/java/helium314/keyboard/keyboard/Keyboard.java index 3a04dfdbfe..303ea36049 100644 --- a/app/src/main/java/helium314/keyboard/keyboard/Keyboard.java +++ b/app/src/main/java/helium314/keyboard/keyboard/Keyboard.java @@ -147,9 +147,9 @@ public boolean hasProximityCharsCorrection(final int code) { } // Note: The native code has the main keyboard layout only at this moment. // TODO: Figure out how to handle proximity characters information of all layouts. - final boolean canAssumeNativeHasProximityCharsInfoOfAllKeys = ( - mId.elementId == KeyboardId.ELEMENT_ALPHABET - || mId.elementId == KeyboardId.ELEMENT_ALPHABET_AUTOMATIC_SHIFTED); + final boolean canAssumeNativeHasProximityCharsInfoOfAllKeys = + mId.element == KeyboardElement.ALPHABET + || mId.element == KeyboardElement.ALPHABET_AUTOMATIC_SHIFTED; return canAssumeNativeHasProximityCharsInfoOfAllKeys || Character.isLetter(code); } diff --git a/app/src/main/java/helium314/keyboard/keyboard/KeyboardActionListenerImpl.kt b/app/src/main/java/helium314/keyboard/keyboard/KeyboardActionListenerImpl.kt index 87341aed98..debe9ad9f2 100644 --- a/app/src/main/java/helium314/keyboard/keyboard/KeyboardActionListenerImpl.kt +++ b/app/src/main/java/helium314/keyboard/keyboard/KeyboardActionListenerImpl.kt @@ -113,7 +113,7 @@ class KeyboardActionListenerImpl(private val latinIME: LatinIME, private val inp // todo: // setting meta shift should only be done for arrow and similar cursor movement keys // should only be enabled once it works more reliably (currently depends on app for some reason) -// if (mkv.keyboard?.mId?.isAlphabetShiftedManually == true) +// if (mkv.keyboard?.mId?.element.isAlphabetShiftedManually == true) // Event.createSoftwareKeypressEvent(primaryCode, metaState or KeyEvent.META_SHIFT_ON, mkv.getKeyX(x), mkv.getKeyY(y), isKeyRepeat) // else Event.createSoftwareKeypressEvent(primaryCode, metaState, mkv.getKeyX(x), mkv.getKeyY(y), isKeyRepeat) Event.createSoftwareKeypressEvent(primaryCode, metaState, mkv.getKeyX(x), mkv.getKeyY(y), isKeyRepeat) diff --git a/app/src/main/java/helium314/keyboard/keyboard/KeyboardElement.java b/app/src/main/java/helium314/keyboard/keyboard/KeyboardElement.java new file mode 100644 index 0000000000..1327a18fb8 --- /dev/null +++ b/app/src/main/java/helium314/keyboard/keyboard/KeyboardElement.java @@ -0,0 +1,83 @@ +package helium314.keyboard.keyboard; + +import androidx.annotation.StringRes; + +import helium314.keyboard.latin.R; +import helium314.keyboard.latin.WordComposer; + +public enum KeyboardElement { + ALPHABET(R.string.spoken_description_mode_alpha), + ALPHABET_AUTOMATIC_SHIFTED(R.string.spoken_description_mode_alpha), + ALPHABET_MANUAL_SHIFTED(R.string.spoken_description_shiftmode_on), + ALPHABET_SHIFT_LOCKED(R.string.spoken_description_shiftmode_locked), + ALPHABET_SHIFT_LOCK_SHIFTED(R.string.spoken_description_shiftmode_locked), // todo: what? + SYMBOLS(R.string.spoken_description_mode_symbol), + SYMBOLS_SHIFTED(R.string.spoken_description_mode_symbol_shift), + DPAD(R.string.spoken_description_mode_dpad), + NUMPAD(R.string.spoken_description_mode_numpad), + NUMBER(R.string.spoken_description_mode_number), + PHONE(R.string.spoken_description_mode_phone), + PHONE_SYMBOLS(R.string.spoken_description_mode_phone_shift), + EMOJI_RECENTS(R.string.spoken_description_emoji_category_recents), + EMOJI_CATEGORY1(R.string.spoken_description_emoji_category_eight_smiley), + EMOJI_CATEGORY2(R.string.spoken_description_emoji_category_eight_smiley_people), + EMOJI_CATEGORY3(R.string.spoken_description_emoji_category_eight_animals_nature), + EMOJI_CATEGORY4(R.string.spoken_description_emoji_category_eight_food_drink), + EMOJI_CATEGORY5(R.string.spoken_description_emoji_category_eight_travel_places), + EMOJI_CATEGORY6(R.string.spoken_description_emoji_category_eight_activity), + EMOJI_CATEGORY7(R.string.spoken_description_emoji_category_objects), + EMOJI_CATEGORY8(R.string.spoken_description_emoji_category_symbols), + EMOJI_CATEGORY9(R.string.spoken_description_emoji_category_flags), + EMOJI_CATEGORY10(R.string.spoken_description_emoji_category_emoticons), + EMOJI_BOTTOM_ROW(0), + CLIPBOARD(R.string.spoken_description_mode_clipboard), + CLIPBOARD_BOTTOM_ROW(0); + + private static final int EMOJI_LAYOUT_COUNT = 11; + + @StringRes + public final int contentDescription; + + KeyboardElement(@StringRes int contentDescription) { + this.contentDescription = contentDescription; + } + + public final boolean isAlphabetLayout() { + return compareTo(SYMBOLS) < 0; + } + + public final boolean isAlphabetShifted() { + return isAlphabetLayout() && this != ALPHABET; + } + + public final boolean isAlphabetShiftedManually() { + return isAlphabetLayout() && compareTo(ALPHABET_AUTOMATIC_SHIFTED) > 0; + } + + public final boolean isAlphaOrSymbolLayout() { + return compareTo(SYMBOLS_SHIFTED) <= 0; + } + + public final boolean isNumberLayout() { + return compareTo(NUMPAD) >= 0 && compareTo(PHONE_SYMBOLS) <= 0; + } + + public final boolean isEmojiLayout() { + return compareTo(EMOJI_RECENTS) >= 0 && compareTo(EMOJI_CATEGORY10) <= 0; + } + + public final boolean isBottomRow() { + return this == EMOJI_BOTTOM_ROW || this == CLIPBOARD_BOTTOM_ROW; + } + + public final int capsMode() { + return switch (this) { + case ALPHABET_AUTOMATIC_SHIFTED -> WordComposer.CAPS_MODE_AUTO_SHIFTED; + case ALPHABET_MANUAL_SHIFTED -> WordComposer.CAPS_MODE_MANUAL_SHIFTED; + case ALPHABET_SHIFT_LOCKED, + ALPHABET_SHIFT_LOCK_SHIFTED -> WordComposer.CAPS_MODE_MANUAL_SHIFT_LOCKED; + default -> WordComposer.CAPS_MODE_OFF; + }; + } + +} diff --git a/app/src/main/java/helium314/keyboard/keyboard/KeyboardId.java b/app/src/main/java/helium314/keyboard/keyboard/KeyboardId.java index caa9aaf557..2b8b4c0103 100644 --- a/app/src/main/java/helium314/keyboard/keyboard/KeyboardId.java +++ b/app/src/main/java/helium314/keyboard/keyboard/KeyboardId.java @@ -12,10 +12,8 @@ import helium314.keyboard.compat.EditorInfoCompatUtils; import helium314.keyboard.latin.RichInputMethodSubtype; -import helium314.keyboard.latin.WordComposer; import helium314.keyboard.latin.utils.InputTypeUtils; -import java.util.Arrays; import java.util.Locale; import java.util.Objects; @@ -25,54 +23,11 @@ * Unique identifier for each keyboard type. */ public final class KeyboardId { - public static final int MODE_TEXT = 0; - public static final int MODE_URL = 1; - public static final int MODE_EMAIL = 2; - public static final int MODE_IM = 3; - public static final int MODE_PHONE = 4; - public static final int MODE_NUMBER = 5; - public static final int MODE_DATE = 6; - public static final int MODE_TIME = 7; - public static final int MODE_DATETIME = 8; - public static final int MODE_NUMPAD = 9; - - public static final int ELEMENT_ALPHABET = 0; - public static final int ELEMENT_ALPHABET_MANUAL_SHIFTED = 1; - public static final int ELEMENT_ALPHABET_AUTOMATIC_SHIFTED = 2; - public static final int ELEMENT_ALPHABET_SHIFT_LOCKED = 3; - public static final int ELEMENT_ALPHABET_SHIFT_LOCK_SHIFTED = 4; - public static final int ELEMENT_SYMBOLS = 5; - public static final int ELEMENT_SYMBOLS_SHIFTED = 6; - public static final int ELEMENT_PHONE = 7; - public static final int ELEMENT_PHONE_SYMBOLS = 8; - public static final int ELEMENT_NUMBER = 9; - public static final int ELEMENT_EMOJI_RECENTS = 10; - public static final int ELEMENT_EMOJI_CATEGORY1 = 11; - public static final int ELEMENT_EMOJI_CATEGORY2 = 12; - public static final int ELEMENT_EMOJI_CATEGORY3 = 13; - public static final int ELEMENT_EMOJI_CATEGORY4 = 14; - public static final int ELEMENT_EMOJI_CATEGORY5 = 15; - public static final int ELEMENT_EMOJI_CATEGORY6 = 16; - public static final int ELEMENT_EMOJI_CATEGORY7 = 17; - public static final int ELEMENT_EMOJI_CATEGORY8 = 18; - public static final int ELEMENT_EMOJI_CATEGORY9 = 19; - public static final int ELEMENT_EMOJI_CATEGORY10 = 20; - public static final int ELEMENT_EMOJI_CATEGORY11 = 21; - public static final int ELEMENT_EMOJI_CATEGORY12 = 22; - public static final int ELEMENT_EMOJI_CATEGORY13 = 23; - public static final int ELEMENT_EMOJI_CATEGORY14 = 24; - public static final int ELEMENT_EMOJI_CATEGORY15 = 25; - public static final int ELEMENT_EMOJI_CATEGORY16 = 26; - public static final int ELEMENT_CLIPBOARD = 27; - public static final int ELEMENT_NUMPAD = 28; - public static final int ELEMENT_EMOJI_BOTTOM_ROW = 29; - public static final int ELEMENT_CLIPBOARD_BOTTOM_ROW = 30; - public final RichInputMethodSubtype subtype; public final int width; public final int height; - public final int mode; - public final int elementId; + public final KeyboardMode mode; + public final KeyboardElement element; public final EditorInfo editorInfo; public final boolean deviceLocked; public final boolean numberRowEnabled; @@ -87,19 +42,19 @@ public final class KeyboardId { private final int mHashCode; - public KeyboardId(int elementId, KeyboardLayoutSet.Params params) { + public KeyboardId(KeyboardElement element, KeyboardLayoutSet.Params params) { subtype = params.mSubtype; width = params.mKeyboardWidth; height = params.mKeyboardHeight; mode = params.mMode; - this.elementId = elementId; + this.element = element; editorInfo = params.mEditorInfo; deviceLocked = params.mDeviceLocked; numberRowEnabled = params.mNumberRowEnabled; numberRowInSymbols = params.mNumberRowInSymbols; languageSwitchKeyEnabled = params.mLanguageSwitchKeyEnabled; emojiKeyEnabled = params.mEmojiKeyEnabled; - customActionLabel = (editorInfo.actionLabel != null) + customActionLabel = editorInfo.actionLabel != null ? editorInfo.actionLabel.toString() : null; hasShortcutKey = params.mVoiceInputKeyEnabled; isSplitLayout = params.mIsSplitLayoutEnabled; @@ -111,7 +66,7 @@ public KeyboardId(int elementId, KeyboardLayoutSet.Params params) { private static int computeHashCode(KeyboardId id) { return Objects.hash( - id.elementId, + id.element, id.mode, id.width, id.height, @@ -132,41 +87,6 @@ private static int computeHashCode(KeyboardId id) { ); } - private boolean equals(KeyboardId other) { - if (other == this) - return true; - return other.elementId == elementId - && other.mode == mode - && other.width == width - && other.height == height - && other.passwordInput() == passwordInput() - && other.deviceLocked == deviceLocked - && other.hasShortcutKey == hasShortcutKey - && other.numberRowEnabled == numberRowEnabled - && other.languageSwitchKeyEnabled == languageSwitchKeyEnabled - && other.emojiKeyEnabled == emojiKeyEnabled - && other.isMultiLine() == isMultiLine() - && other.imeAction() == imeAction() - && TextUtils.equals(other.customActionLabel, customActionLabel) - && other.navigateNext() == navigateNext() - && other.navigatePrevious() == navigatePrevious() - && other.subtype.equals(subtype) - && other.isSplitLayout == isSplitLayout - && Objects.equals(other.internalAction, internalAction); - } - - private static boolean isAlphabetKeyboard(int elementId) { - return elementId < ELEMENT_SYMBOLS; - } - - public boolean isAlphaOrSymbolKeyboard() { - return elementId <= ELEMENT_SYMBOLS_SHIFTED; - } - - public boolean isAlphabetKeyboard() { - return isAlphabetKeyboard(elementId); - } - public boolean navigateNext() { return (editorInfo.imeOptions & EditorInfo.IME_FLAG_NAVIGATE_NEXT) != 0 || imeAction() == EditorInfo.IME_ACTION_NEXT; @@ -186,29 +106,6 @@ public boolean isMultiLine() { return (editorInfo.inputType & InputType.TYPE_TEXT_FLAG_MULTI_LINE) != 0; } - public boolean isAlphabetShifted() { - return elementId == ELEMENT_ALPHABET_SHIFT_LOCKED || elementId == ELEMENT_ALPHABET_SHIFT_LOCK_SHIFTED - || elementId == ELEMENT_ALPHABET_AUTOMATIC_SHIFTED || elementId == ELEMENT_ALPHABET_MANUAL_SHIFTED; - } - - public boolean isAlphabetShiftedManually() { - return elementId == ELEMENT_ALPHABET_SHIFT_LOCKED || elementId == ELEMENT_ALPHABET_SHIFT_LOCK_SHIFTED - || elementId == ELEMENT_ALPHABET_MANUAL_SHIFTED; - } - - public boolean isNumberLayout() { - return elementId == ELEMENT_NUMBER || elementId == ELEMENT_NUMPAD - || elementId == ELEMENT_PHONE || elementId == ELEMENT_PHONE_SYMBOLS; - } - - public boolean isEmojiKeyboard() { - return elementId >= ELEMENT_EMOJI_RECENTS && elementId <= ELEMENT_EMOJI_CATEGORY16; - } - - public boolean isEmojiClipBottomRow() { - return elementId == ELEMENT_CLIPBOARD_BOTTOM_ROW || elementId == ELEMENT_EMOJI_BOTTOM_ROW; - } - public int imeAction() { return InputTypeUtils.getImeOptionsActionIdFromEditorInfo(editorInfo); } @@ -219,7 +116,25 @@ public Locale getLocale() { @Override public boolean equals(Object other) { - return other instanceof KeyboardId && equals((KeyboardId) other); + return other instanceof KeyboardId id + && id.element == element + && id.mode == mode + && id.width == width + && id.height == height + && id.passwordInput() == passwordInput() + && id.deviceLocked == deviceLocked + && id.hasShortcutKey == hasShortcutKey + && id.numberRowEnabled == numberRowEnabled + && id.languageSwitchKeyEnabled == languageSwitchKeyEnabled + && id.emojiKeyEnabled == emojiKeyEnabled + && id.isMultiLine() == isMultiLine() + && id.imeAction() == imeAction() + && TextUtils.equals(id.customActionLabel, customActionLabel) + && id.navigateNext() == navigateNext() + && id.navigatePrevious() == navigatePrevious() + && id.subtype.equals(subtype) + && id.isSplitLayout == isSplitLayout + && Objects.equals(id.internalAction, internalAction); } @Override @@ -230,12 +145,12 @@ public int hashCode() { @Override public String toString() { return String.format(Locale.ROOT, "[%s %s:%s %dx%d %s %s%s%s%s%s%s%s%s%s%s%s]", - elementIdToName(elementId), + element, subtype.getLocale(), subtype.getExtraValueOf(KEYBOARD_LAYOUT_SET), width, height, - modeName(mode), + mode, actionName(imeAction()), navigateNext() ? " navigateNext" : "", navigatePrevious() ? " navigatePrevious" : "", @@ -258,69 +173,8 @@ public static boolean equivalentEditorInfoForKeyboard(EditorInfo a, EditorInfo b && TextUtils.equals(a.privateImeOptions, b.privateImeOptions); } - public static String elementIdToName(int elementId) { - return switch (elementId) { - case ELEMENT_ALPHABET -> "alphabet"; - case ELEMENT_ALPHABET_MANUAL_SHIFTED -> "alphabetManualShifted"; - case ELEMENT_ALPHABET_AUTOMATIC_SHIFTED -> "alphabetAutomaticShifted"; - case ELEMENT_ALPHABET_SHIFT_LOCKED -> "alphabetShiftLocked"; - case ELEMENT_ALPHABET_SHIFT_LOCK_SHIFTED -> "alphabetShiftLockShifted"; - case ELEMENT_SYMBOLS -> "symbols"; - case ELEMENT_SYMBOLS_SHIFTED -> "symbolsShifted"; - case ELEMENT_PHONE -> "phone"; - case ELEMENT_PHONE_SYMBOLS -> "phoneSymbols"; - case ELEMENT_NUMBER -> "number"; - case ELEMENT_EMOJI_RECENTS -> "emojiRecents"; - case ELEMENT_EMOJI_CATEGORY1 -> "emojiCategory1"; - case ELEMENT_EMOJI_CATEGORY2 -> "emojiCategory2"; - case ELEMENT_EMOJI_CATEGORY3 -> "emojiCategory3"; - case ELEMENT_EMOJI_CATEGORY4 -> "emojiCategory4"; - case ELEMENT_EMOJI_CATEGORY5 -> "emojiCategory5"; - case ELEMENT_EMOJI_CATEGORY6 -> "emojiCategory6"; - case ELEMENT_EMOJI_CATEGORY7 -> "emojiCategory7"; - case ELEMENT_EMOJI_CATEGORY8 -> "emojiCategory8"; - case ELEMENT_EMOJI_CATEGORY9 -> "emojiCategory9"; - case ELEMENT_EMOJI_CATEGORY10 -> "emojiCategory10"; - case ELEMENT_EMOJI_CATEGORY11 -> "emojiCategory11"; - case ELEMENT_EMOJI_CATEGORY12 -> "emojiCategory12"; - case ELEMENT_EMOJI_CATEGORY13 -> "emojiCategory13"; - case ELEMENT_EMOJI_CATEGORY14 -> "emojiCategory14"; - case ELEMENT_EMOJI_CATEGORY15 -> "emojiCategory15"; - case ELEMENT_EMOJI_CATEGORY16 -> "emojiCategory16"; - case ELEMENT_CLIPBOARD -> "clipboard"; - case ELEMENT_NUMPAD -> "numpad"; - default -> null; - }; - } - - public static String modeName(int mode) { - return switch (mode) { - case MODE_TEXT -> "text"; - case MODE_URL -> "url"; - case MODE_EMAIL -> "email"; - case MODE_IM -> "im"; - case MODE_PHONE -> "phone"; - case MODE_NUMBER -> "number"; - case MODE_DATE -> "date"; - case MODE_TIME -> "time"; - case MODE_DATETIME -> "datetime"; - case MODE_NUMPAD -> "numpad"; - default -> null; - }; - } - public static String actionName(int actionId) { return (actionId == InputTypeUtils.IME_ACTION_CUSTOM_LABEL) ? "actionCustomLabel" : EditorInfoCompatUtils.imeActionName(actionId); } - - public int getKeyboardCapsMode() { - return switch (elementId) { - case KeyboardId.ELEMENT_ALPHABET_SHIFT_LOCKED, KeyboardId.ELEMENT_ALPHABET_SHIFT_LOCK_SHIFTED -> - WordComposer.CAPS_MODE_MANUAL_SHIFT_LOCKED; - case KeyboardId.ELEMENT_ALPHABET_MANUAL_SHIFTED -> WordComposer.CAPS_MODE_MANUAL_SHIFTED; - case KeyboardId.ELEMENT_ALPHABET_AUTOMATIC_SHIFTED -> WordComposer.CAPS_MODE_AUTO_SHIFTED; - default -> WordComposer.CAPS_MODE_OFF; - }; - } } diff --git a/app/src/main/java/helium314/keyboard/keyboard/KeyboardLayoutSet.java b/app/src/main/java/helium314/keyboard/keyboard/KeyboardLayoutSet.java index e6e361c449..af1464f471 100644 --- a/app/src/main/java/helium314/keyboard/keyboard/KeyboardLayoutSet.java +++ b/app/src/main/java/helium314/keyboard/keyboard/KeyboardLayoutSet.java @@ -79,7 +79,7 @@ public KeyboardLayoutSetException(Throwable cause, KeyboardId keyboardId) { public record InternalAction(int code, String label) {} public static final class Params { - int mMode; + KeyboardMode mMode; boolean mDisableTouchPositionCorrectionDataForTest; // remove // TODO: Use {@link InputAttributes} instead of these variables. EditorInfo mEditorInfo; @@ -125,17 +125,16 @@ private static void clearKeyboardCache() { } @NonNull - public Keyboard getKeyboard(int baseKeyboardLayoutSetElementId) { - int keyboardLayoutSetElementId = switch (mParams.mMode) { - case KeyboardId.MODE_PHONE -> baseKeyboardLayoutSetElementId == KeyboardId.ELEMENT_SYMBOLS - ? KeyboardId.ELEMENT_PHONE_SYMBOLS - : KeyboardId.ELEMENT_PHONE; - case KeyboardId.MODE_NUMPAD -> KeyboardId.ELEMENT_NUMPAD; - case KeyboardId.MODE_NUMBER, - KeyboardId.MODE_DATE, - KeyboardId.MODE_TIME, - KeyboardId.MODE_DATETIME -> KeyboardId.ELEMENT_NUMBER; - default -> baseKeyboardLayoutSetElementId; + public Keyboard getKeyboard(@Nullable KeyboardElement baseElement) { + KeyboardElement element = switch (mParams.mMode) { + case PHONE -> baseElement == KeyboardElement.SYMBOLS + ? KeyboardElement.PHONE_SYMBOLS + : KeyboardElement.PHONE; + case NUMBER, + DATE, + TIME, + DATETIME -> KeyboardElement.NUMBER; + default -> baseElement; }; // Note: The keyboard for each shift state, and mode are represented as an elementName @@ -143,7 +142,7 @@ public Keyboard getKeyboard(int baseKeyboardLayoutSetElementId) { // specified as an elementKeyboard attribute in the file. // The KeyboardId is an internal key for a Keyboard object. - var id = new KeyboardId(keyboardLayoutSetElementId, mParams); + var id = new KeyboardId(element, mParams); try { return getKeyboard(id); } catch (RuntimeException e) { @@ -164,15 +163,16 @@ private Keyboard getKeyboard(KeyboardId id) { } var builder = new KeyboardBuilder(mContext, new KeyboardParams(sUniqueKeysCache)); - sUniqueKeysCache.setEnabled(id.isAlphabetKeyboard()); + KeyboardElement element = id.element; + sUniqueKeysCache.setEnabled(element.isAlphabetLayout()); builder.load(id); if (mParams.mDisableTouchPositionCorrectionDataForTest) { builder.disableTouchPositionCorrectionDataForTest(); } Keyboard keyboard = builder.build(); sKeyboardCache.put(id, new SoftReference<>(keyboard)); - if ((id.elementId == KeyboardId.ELEMENT_ALPHABET - || id.elementId == KeyboardId.ELEMENT_ALPHABET_AUTOMATIC_SHIFTED) + if ((element == KeyboardElement.ALPHABET + || element == KeyboardElement.ALPHABET_AUTOMATIC_SHIFTED) && !mParams.mIsSpellChecker) { // We only forcibly cache the primary, "ALPHABET", layouts. for (int i = sForcibleKeyboardCache.length - 1; i >= 1; --i) { @@ -216,7 +216,7 @@ public Builder(Context context, @Nullable EditorInfo ei) { public static KeyboardLayoutSet buildEmojiClipBottomRow(Context context, @Nullable EditorInfo ei) { var builder = new Builder(context, ei); - builder.mParams.mMode = KeyboardId.MODE_TEXT; + builder.mParams.mMode = KeyboardMode.TEXT; int width = ResourceUtils.getKeyboardWidth(context, Settings.getValues()); // actually the keyboard does not have full height, but at this point we use it to get correct key heights int height = ResourceUtils.getKeyboardHeight(context.getResources(), Settings.getValues()); @@ -297,41 +297,41 @@ public KeyboardLayoutSet build() { return new KeyboardLayoutSet(mContext, mParams); } - private static int getKeyboardMode(EditorInfo editorInfo) { + private static KeyboardMode getKeyboardMode(EditorInfo editorInfo) { int inputType = editorInfo.inputType; int variation = inputType & InputType.TYPE_MASK_VARIATION; return switch (inputType & InputType.TYPE_MASK_CLASS) { - case InputType.TYPE_CLASS_NUMBER -> KeyboardId.MODE_NUMBER; + case InputType.TYPE_CLASS_NUMBER -> KeyboardMode.NUMBER; case InputType.TYPE_CLASS_DATETIME -> switch (variation) { - case InputType.TYPE_DATETIME_VARIATION_DATE -> KeyboardId.MODE_DATE; - case InputType.TYPE_DATETIME_VARIATION_TIME -> KeyboardId.MODE_TIME; - default -> KeyboardId.MODE_DATETIME; // must be InputType.TYPE_DATETIME_VARIATION_NORMAL + case InputType.TYPE_DATETIME_VARIATION_DATE -> KeyboardMode.DATE; + case InputType.TYPE_DATETIME_VARIATION_TIME -> KeyboardMode.TIME; + default -> KeyboardMode.DATETIME; // must be InputType.TYPE_DATETIME_VARIATION_NORMAL }; - case InputType.TYPE_CLASS_PHONE -> KeyboardId.MODE_PHONE; + case InputType.TYPE_CLASS_PHONE -> KeyboardMode.PHONE; case InputType.TYPE_CLASS_TEXT -> { if (InputTypeUtils.isEmailVariation(variation)) { - yield KeyboardId.MODE_EMAIL; + yield KeyboardMode.EMAIL; } yield switch (variation) { - case InputType.TYPE_TEXT_VARIATION_URI -> KeyboardId.MODE_URL; + case InputType.TYPE_TEXT_VARIATION_URI -> KeyboardMode.URL; case InputType.TYPE_TEXT_VARIATION_SHORT_MESSAGE -> //KeyboardId.MODE_IM; - KeyboardId.MODE_TEXT; - default -> KeyboardId.MODE_TEXT; + KeyboardMode.TEXT; + default -> KeyboardMode.TEXT; }; } - default -> KeyboardId.MODE_TEXT; + default -> KeyboardMode.TEXT; }; } } // used for testing keyboard layout files without actually creating a keyboard - public static KeyboardId getFakeKeyboardId(int elementId) { + public static KeyboardId getFakeKeyboardId(KeyboardElement element) { var params = new Params(); params.mEditorInfo = new EditorInfo(); params.mSubtype = RichInputMethodSubtype.Companion.getEmojiSubtype(); params.mSubtype.getMainLayoutName(); - return new KeyboardId(elementId, params); + return new KeyboardId(element, params); } } diff --git a/app/src/main/java/helium314/keyboard/keyboard/KeyboardMode.java b/app/src/main/java/helium314/keyboard/keyboard/KeyboardMode.java new file mode 100644 index 0000000000..c3056947ab --- /dev/null +++ b/app/src/main/java/helium314/keyboard/keyboard/KeyboardMode.java @@ -0,0 +1,32 @@ +package helium314.keyboard.keyboard; + +import androidx.annotation.StringRes; + +import helium314.keyboard.latin.R; + +public enum KeyboardMode { + TEXT(R.string.keyboard_mode_text), + URL(R.string.keyboard_mode_url), + EMAIL(R.string.keyboard_mode_email), + IM(R.string.keyboard_mode_im), + PHONE(R.string.keyboard_mode_phone), + NUMBER(R.string.keyboard_mode_number), + DATE(R.string.keyboard_mode_date), + TIME(R.string.keyboard_mode_time), + DATETIME(R.string.keyboard_mode_date_time); + + @StringRes + public final int contentDescription; + + KeyboardMode(@StringRes int contentDescription) { + this.contentDescription = contentDescription; + } + + public final boolean shouldSuppressEmojis() { + return compareTo(PHONE) >= 0 || this == EMAIL; + } + + public final boolean isWebMode() { + return this == URL || this == EMAIL; + } +} diff --git a/app/src/main/java/helium314/keyboard/keyboard/KeyboardSwitcher.java b/app/src/main/java/helium314/keyboard/keyboard/KeyboardSwitcher.java index 429c3053bd..c927b5de02 100644 --- a/app/src/main/java/helium314/keyboard/keyboard/KeyboardSwitcher.java +++ b/app/src/main/java/helium314/keyboard/keyboard/KeyboardSwitcher.java @@ -194,9 +194,9 @@ public void onHideWindow() { } } - private void setKeyboard(final int keyboardId, @NonNull final KeyboardSwitchState toggleState) { + private void setKeyboard(@Nullable final KeyboardElement element, @NonNull final KeyboardSwitchState toggleState) { // with a hardware keyboard we might get here without ever calling onCreateInputView, so don't crash - if (mKeyboardView == null) return; + if (mKeyboardView == null || element == null) return; // Make {@link MainKeyboardView} visible and hide {@link EmojiPalettesView}. final SettingsValues currentSettingsValues = Settings.getValues(); @@ -204,7 +204,7 @@ private void setKeyboard(final int keyboardId, @NonNull final KeyboardSwitchStat // TODO: pass this object to setKeyboard instead of getting the current values. final MainKeyboardView keyboardView = mKeyboardView; final Keyboard oldKeyboard = keyboardView.getKeyboard(); - final Keyboard newKeyboard = mKeyboardLayoutSet.getKeyboard(keyboardId); + final Keyboard newKeyboard = mKeyboardLayoutSet.getKeyboard(element); keyboardView.setKeyboard(newKeyboard); mCurrentInputView.setKeyboardTopPadding(newKeyboard.mTopPadding); keyboardView.setKeyPreviewPopupEnabled(currentSettingsValues.mKeyPreviewPopupOn); @@ -250,7 +250,7 @@ public void setAlphabetKeyboard() { if (DEBUG_ACTION) { Log.d(TAG, "setAlphabetKeyboard"); } - setKeyboard(KeyboardId.ELEMENT_ALPHABET, KeyboardSwitchState.OTHER); + setKeyboard(KeyboardElement.ALPHABET, KeyboardSwitchState.OTHER); } // Implements {@link KeyboardState.SwitchActions}. @@ -259,7 +259,7 @@ public void setAlphabetManualShiftedKeyboard() { if (DEBUG_ACTION) { Log.d(TAG, "setAlphabetManualShiftedKeyboard"); } - setKeyboard(KeyboardId.ELEMENT_ALPHABET_MANUAL_SHIFTED, KeyboardSwitchState.OTHER); + setKeyboard(KeyboardElement.ALPHABET_MANUAL_SHIFTED, KeyboardSwitchState.OTHER); } // Implements {@link KeyboardState.SwitchActions}. @@ -268,7 +268,7 @@ public void setAlphabetAutomaticShiftedKeyboard() { if (DEBUG_ACTION) { Log.d(TAG, "setAlphabetAutomaticShiftedKeyboard"); } - setKeyboard(KeyboardId.ELEMENT_ALPHABET_AUTOMATIC_SHIFTED, KeyboardSwitchState.OTHER); + setKeyboard(KeyboardElement.ALPHABET_AUTOMATIC_SHIFTED, KeyboardSwitchState.OTHER); } // Implements {@link KeyboardState.SwitchActions}. @@ -277,7 +277,7 @@ public void setAlphabetShiftLockedKeyboard() { if (DEBUG_ACTION) { Log.d(TAG, "setAlphabetShiftLockedKeyboard"); } - setKeyboard(KeyboardId.ELEMENT_ALPHABET_SHIFT_LOCKED, KeyboardSwitchState.OTHER); + setKeyboard(KeyboardElement.ALPHABET_SHIFT_LOCKED, KeyboardSwitchState.OTHER); } // Implements {@link KeyboardState.SwitchActions}. @@ -286,7 +286,7 @@ public void setAlphabetShiftLockShiftedKeyboard() { if (DEBUG_ACTION) { Log.d(TAG, "setAlphabetShiftLockShiftedKeyboard"); } - setKeyboard(KeyboardId.ELEMENT_ALPHABET_SHIFT_LOCK_SHIFTED, KeyboardSwitchState.OTHER); + setKeyboard(KeyboardElement.ALPHABET_SHIFT_LOCK_SHIFTED, KeyboardSwitchState.OTHER); } // Implements {@link KeyboardState.SwitchActions}. @@ -295,7 +295,7 @@ public void setSymbolsKeyboard() { if (DEBUG_ACTION) { Log.d(TAG, "setSymbolsKeyboard"); } - setKeyboard(KeyboardId.ELEMENT_SYMBOLS, KeyboardSwitchState.OTHER); + setKeyboard(KeyboardElement.SYMBOLS, KeyboardSwitchState.OTHER); } // Implements {@link KeyboardState.SwitchActions}. @@ -304,7 +304,7 @@ public void setSymbolsShiftedKeyboard() { if (DEBUG_ACTION) { Log.d(TAG, "setSymbolsShiftedKeyboard"); } - setKeyboard(KeyboardId.ELEMENT_SYMBOLS_SHIFTED, KeyboardSwitchState.SYMBOLS_SHIFTED); + setKeyboard(KeyboardElement.SYMBOLS_SHIFTED, KeyboardSwitchState.SYMBOLS_SHIFTED); } public boolean isImeSuppressedByHardwareKeyboard( @@ -382,7 +382,7 @@ public void setNumpadKeyboard() { if (DEBUG_ACTION) { Log.d(TAG, "setNumpadKeyboard"); } - setKeyboard(KeyboardId.ELEMENT_NUMPAD, KeyboardSwitchState.OTHER); + setKeyboard(KeyboardElement.NUMPAD, KeyboardSwitchState.OTHER); } @Override @@ -395,16 +395,17 @@ public void toggleNumpad(final boolean withSliding, final int autoCapsFlags, } public enum KeyboardSwitchState { - HIDDEN(-1), - SYMBOLS_SHIFTED(KeyboardId.ELEMENT_SYMBOLS_SHIFTED), - EMOJI(KeyboardId.ELEMENT_EMOJI_RECENTS), - CLIPBOARD(KeyboardId.ELEMENT_CLIPBOARD), - OTHER(-1); + HIDDEN(null), + SYMBOLS_SHIFTED(KeyboardElement.SYMBOLS_SHIFTED), + EMOJI(KeyboardElement.EMOJI_RECENTS), + CLIPBOARD(KeyboardElement.CLIPBOARD), + OTHER(null); - final int mKeyboardId; + @Nullable + final KeyboardElement mElement; - KeyboardSwitchState(int keyboardId) { - mKeyboardId = keyboardId; + KeyboardSwitchState(@Nullable KeyboardElement element) { + mElement = element; } } @@ -419,7 +420,7 @@ public KeyboardSwitchState getKeyboardSwitchState() { return KeyboardSwitchState.EMOJI; } else if (isShowingClipboardHistory()) { return KeyboardSwitchState.CLIPBOARD; - } else if (isShowingKeyboardId(KeyboardId.ELEMENT_SYMBOLS_SHIFTED)) { + } else if (isShowingKeyboardId(KeyboardElement.SYMBOLS_SHIFTED)) { return KeyboardSwitchState.SYMBOLS_SHIFTED; } return KeyboardSwitchState.OTHER; @@ -447,7 +448,7 @@ public void onToggleKeyboard(@NonNull final KeyboardSwitchState toggleState) { mMainKeyboardFrame.setVisibility(View.VISIBLE); mKeyboardView.setVisibility(View.VISIBLE); - setKeyboard(toggleState.mKeyboardId, toggleState); + setKeyboard(toggleState.mElement, toggleState); } } } @@ -604,16 +605,16 @@ public void onEvent(final Event event, final int currentAutoCapsState, mState.onEvent(event, currentAutoCapsState, currentRecapitalizeState); } - public boolean isShowingKeyboardId(@NonNull int... keyboardIds) { + public boolean isShowingKeyboardId(@NonNull KeyboardElement... elements) { if (mKeyboardView == null || !mKeyboardView.isShown()) { return false; } final Keyboard keyboard = mKeyboardView.getKeyboard(); if (keyboard == null) // may happen when using hardware keyboard return false; - int activeKeyboardId = keyboard.mId.elementId; - for (int keyboardId : keyboardIds) { - if (activeKeyboardId == keyboardId) { + KeyboardElement activeElement = keyboard.mId.element; + for (KeyboardElement element : elements) { + if (activeElement == element) { return true; } } @@ -732,7 +733,7 @@ public int getKeyboardShiftMode() { if (keyboard == null) { return WordComposer.CAPS_MODE_OFF; } - return keyboard.mId.getKeyboardCapsMode(); + return keyboard.mId.element.capsMode(); } public String getCurrentKeyboardScript() { diff --git a/app/src/main/java/helium314/keyboard/keyboard/KeyboardView.java b/app/src/main/java/helium314/keyboard/keyboard/KeyboardView.java index 12248a5293..052d08684a 100644 --- a/app/src/main/java/helium314/keyboard/keyboard/KeyboardView.java +++ b/app/src/main/java/helium314/keyboard/keyboard/KeyboardView.java @@ -194,7 +194,7 @@ public void setKeyboard(@NonNull final Keyboard keyboard) { mKeyDrawParams.updateParams(scaledKeyHeight, keyboard.mKeyVisualAttributes); invalidateAllKeys(); requestLayout(); - mFontSizeMultiplier = mKeyboard.mId.isEmojiKeyboard() + mFontSizeMultiplier = mKeyboard.mId.element.isEmojiLayout() // In the case of EmojiKeyFit, the size of emojis is taken care of by the size of the keys ? (Settings.getValues().mEmojiKeyFit? 1 : Settings.getValues().mFontSizeMultiplierEmoji) : Settings.getValues().mFontSizeMultiplier; @@ -624,11 +624,7 @@ private void setKeyIconColor(Key key, Drawable icon, Keyboard keyboard) { if (key.hasActionKeyBackground()) { mColors.setColor(icon, ColorType.ACTION_KEY_ICON); } else if (key.isShift() && keyboard != null) { - if (keyboard.mId.elementId == KeyboardId.ELEMENT_ALPHABET_MANUAL_SHIFTED - || keyboard.mId.elementId == KeyboardId.ELEMENT_ALPHABET_SHIFT_LOCKED - || keyboard.mId.elementId == KeyboardId.ELEMENT_ALPHABET_AUTOMATIC_SHIFTED - || keyboard.mId.elementId == KeyboardId.ELEMENT_ALPHABET_SHIFT_LOCK_SHIFTED - ) + if (keyboard.mId.element.isAlphabetShifted()) mColors.setColor(icon, ColorType.SHIFT_KEY_ICON); else mColors.setColor(icon, ColorType.KEY_ICON); // normal key if not shifted diff --git a/app/src/main/java/helium314/keyboard/keyboard/PointerTracker.java b/app/src/main/java/helium314/keyboard/keyboard/PointerTracker.java index f317942eeb..b4927a275b 100644 --- a/app/src/main/java/helium314/keyboard/keyboard/PointerTracker.java +++ b/app/src/main/java/helium314/keyboard/keyboard/PointerTracker.java @@ -674,7 +674,7 @@ private void onDownEvent(final int x, final int y, final long eventTime, } // A gesture should start only from a non-modifier key. Note that the gesture detection is // disabled when the key is repeating. - mIsDetectingGesture = (mKeyboard != null) && mKeyboard.mId.isAlphabetKeyboard() + mIsDetectingGesture = (mKeyboard != null) && mKeyboard.mId.element.isAlphabetLayout() && key != null && !key.isModifier() && !mKeySwipeAllowed && !sInKeySwipe; if (mIsDetectingGesture) { mBatchInputArbiter.addDownEventPoint(x, y, eventTime, diff --git a/app/src/main/java/helium314/keyboard/keyboard/clipboard/ClipboardHistoryView.kt b/app/src/main/java/helium314/keyboard/keyboard/clipboard/ClipboardHistoryView.kt index 36f976e8b4..18581d87ea 100644 --- a/app/src/main/java/helium314/keyboard/keyboard/clipboard/ClipboardHistoryView.kt +++ b/app/src/main/java/helium314/keyboard/keyboard/clipboard/ClipboardHistoryView.kt @@ -15,7 +15,7 @@ import android.widget.TextView import androidx.recyclerview.widget.StaggeredGridLayoutManager import helium314.keyboard.event.HapticEvent import helium314.keyboard.keyboard.KeyboardActionListener -import helium314.keyboard.keyboard.KeyboardId +import helium314.keyboard.keyboard.KeyboardElement import helium314.keyboard.keyboard.KeyboardLayoutSet import helium314.keyboard.keyboard.KeyboardSwitcher import helium314.keyboard.keyboard.MainKeyboardView @@ -132,7 +132,7 @@ class ClipboardHistoryView @JvmOverloads constructor( keyboardView.setKeyboardActionListener(listener) PointerTracker.switchTo(keyboardView) val kls = KeyboardLayoutSet.Builder.buildEmojiClipBottomRow(context, editorInfo) - val keyboard = kls.getKeyboard(KeyboardId.ELEMENT_CLIPBOARD_BOTTOM_ROW) + val keyboard = kls.getKeyboard(KeyboardElement.CLIPBOARD_BOTTOM_ROW) keyboardView.setKeyboard(keyboard) } diff --git a/app/src/main/java/helium314/keyboard/keyboard/emoji/EmojiCategory.java b/app/src/main/java/helium314/keyboard/keyboard/emoji/EmojiCategory.java index 413a6b8f62..fb074af593 100644 --- a/app/src/main/java/helium314/keyboard/keyboard/emoji/EmojiCategory.java +++ b/app/src/main/java/helium314/keyboard/keyboard/emoji/EmojiCategory.java @@ -20,7 +20,7 @@ import androidx.core.graphics.PaintCompat; import helium314.keyboard.keyboard.Key; import helium314.keyboard.keyboard.Keyboard; -import helium314.keyboard.keyboard.KeyboardId; +import helium314.keyboard.keyboard.KeyboardElement; import helium314.keyboard.keyboard.KeyboardLayoutSet; import helium314.keyboard.latin.R; import helium314.keyboard.latin.settings.Settings; @@ -34,7 +34,7 @@ import java.util.concurrent.ConcurrentHashMap; final class EmojiCategory { - private final String TAG = EmojiCategory.class.getSimpleName(); + private static final String TAG = EmojiCategory.class.getSimpleName(); private static final int ID_UNSPECIFIED = -1; public static final int ID_RECENTS = 0; @@ -51,7 +51,7 @@ final class EmojiCategory { private static final int MAX_LINE_COUNT_PER_PAGE = 3; - public final class CategoryProperties { + final class CategoryProperties { public final int mCategoryId; private int mPageCount = -1; public CategoryProperties(final int categoryId) { @@ -90,31 +90,18 @@ public int getPageCount() { R.styleable.EmojiPalettesView_iconEmojiCategory9Tab, R.styleable.EmojiPalettesView_iconEmojiCategory10Tab }; - private static final int[] sAccessibilityDescriptionResourceIdsForCategories = { - R.string.spoken_description_emoji_category_recents, - R.string.spoken_description_emoji_category_eight_smiley, - R.string.spoken_description_emoji_category_eight_smiley_people, - R.string.spoken_description_emoji_category_eight_animals_nature, - R.string.spoken_description_emoji_category_eight_food_drink, - R.string.spoken_description_emoji_category_eight_travel_places, - R.string.spoken_description_emoji_category_eight_activity, - R.string.spoken_description_emoji_category_objects, - R.string.spoken_description_emoji_category_symbols, - R.string.spoken_description_emoji_category_flags, - R.string.spoken_description_emoji_category_emoticons}; - - private static final int[] sCategoryElementId = { - KeyboardId.ELEMENT_EMOJI_RECENTS, - KeyboardId.ELEMENT_EMOJI_CATEGORY1, - KeyboardId.ELEMENT_EMOJI_CATEGORY2, - KeyboardId.ELEMENT_EMOJI_CATEGORY3, - KeyboardId.ELEMENT_EMOJI_CATEGORY4, - KeyboardId.ELEMENT_EMOJI_CATEGORY5, - KeyboardId.ELEMENT_EMOJI_CATEGORY6, - KeyboardId.ELEMENT_EMOJI_CATEGORY7, - KeyboardId.ELEMENT_EMOJI_CATEGORY8, - KeyboardId.ELEMENT_EMOJI_CATEGORY9, - KeyboardId.ELEMENT_EMOJI_CATEGORY10 }; + private static final KeyboardElement[] sCategoryElement = { + KeyboardElement.EMOJI_RECENTS, + KeyboardElement.EMOJI_CATEGORY1, + KeyboardElement.EMOJI_CATEGORY2, + KeyboardElement.EMOJI_CATEGORY3, + KeyboardElement.EMOJI_CATEGORY4, + KeyboardElement.EMOJI_CATEGORY5, + KeyboardElement.EMOJI_CATEGORY6, + KeyboardElement.EMOJI_CATEGORY7, + KeyboardElement.EMOJI_CATEGORY8, + KeyboardElement.EMOJI_CATEGORY9, + KeyboardElement.EMOJI_CATEGORY10 }; private final SharedPreferences mPrefs; private final Resources mRes; @@ -126,10 +113,10 @@ public int getPageCount() { private final ArrayList mShownCategories = new ArrayList<>(); private final ConcurrentHashMap mCategoryKeyboardMap = new ConcurrentHashMap<>(); - private int mCurrentCategoryId = EmojiCategory.ID_UNSPECIFIED; + private int mCurrentCategoryId = ID_UNSPECIFIED; private int mCurrentCategoryPageId = 0; - public EmojiCategory(final Context ctx, final KeyboardLayoutSet layoutSet, final TypedArray emojiPaletteViewAttr) { + EmojiCategory(final Context ctx, final KeyboardLayoutSet layoutSet, final TypedArray emojiPaletteViewAttr) { mPrefs = KtxKt.prefs(ctx); mRes = ctx.getResources(); mContext = ctx; @@ -142,27 +129,27 @@ public EmojiCategory(final Context ctx, final KeyboardLayoutSet layoutSet, final } public void initialize() { - int defaultCategoryId = EmojiCategory.ID_SMILEYS_EMOTION; - addShownCategoryId(EmojiCategory.ID_RECENTS); - addShownCategoryId(EmojiCategory.ID_SMILEYS_EMOTION); - addShownCategoryId(EmojiCategory.ID_PEOPLE_BODY); - addShownCategoryId(EmojiCategory.ID_ANIMALS_NATURE); - addShownCategoryId(EmojiCategory.ID_FOOD_DRINK); - addShownCategoryId(EmojiCategory.ID_TRAVEL_PLACES); - addShownCategoryId(EmojiCategory.ID_ACTIVITIES); - addShownCategoryId(EmojiCategory.ID_OBJECTS); - addShownCategoryId(EmojiCategory.ID_SYMBOLS); + int defaultCategoryId = ID_SMILEYS_EMOTION; + addShownCategoryId(ID_RECENTS); + addShownCategoryId(ID_SMILEYS_EMOTION); + addShownCategoryId(ID_PEOPLE_BODY); + addShownCategoryId(ID_ANIMALS_NATURE); + addShownCategoryId(ID_FOOD_DRINK); + addShownCategoryId(ID_TRAVEL_PLACES); + addShownCategoryId(ID_ACTIVITIES); + addShownCategoryId(ID_OBJECTS); + addShownCategoryId(ID_SYMBOLS); if (canShowFlagEmoji()) { - addShownCategoryId(EmojiCategory.ID_FLAGS); + addShownCategoryId(ID_FLAGS); } - addShownCategoryId(EmojiCategory.ID_EMOTICONS); + addShownCategoryId(ID_EMOTICONS); - DynamicGridKeyboard recentsKbd = getKeyboard(EmojiCategory.ID_RECENTS, 0); + DynamicGridKeyboard recentsKbd = getKeyboard(ID_RECENTS, 0); mCurrentCategoryId = mPrefs.getInt(Settings.PREF_LAST_SHOWN_EMOJI_CATEGORY_ID, defaultCategoryId); mCurrentCategoryPageId = mPrefs.getInt(Settings.PREF_LAST_SHOWN_EMOJI_CATEGORY_PAGE_ID, Defaults.PREF_LAST_SHOWN_EMOJI_CATEGORY_PAGE_ID); if (!isShownCategoryId(mCurrentCategoryId)) { mCurrentCategoryId = defaultCategoryId; - } else if (mCurrentCategoryId == EmojiCategory.ID_RECENTS && + } else if (mCurrentCategoryId == ID_RECENTS && recentsKbd.getSortedKeys().isEmpty()) { mCurrentCategoryId = defaultCategoryId; } @@ -207,7 +194,7 @@ public int getCategoryTabIcon(final int categoryId) { } public String getAccessibilityDescription(final int categoryId) { - return mRes.getString(sAccessibilityDescriptionResourceIdsForCategories[categoryId]); + return mRes.getString(sCategoryElement[categoryId].contentDescription); } public ArrayList getShownCategories() { @@ -248,7 +235,7 @@ public int getCurrentCategoryPageId() { } public boolean isInRecentTab() { - return mCurrentCategoryId == EmojiCategory.ID_RECENTS; + return mCurrentCategoryId == ID_RECENTS; } public int getTabIdFromCategoryId(final int categoryId) { @@ -262,11 +249,11 @@ public int getTabIdFromCategoryId(final int categoryId) { } public int getRecentTabId() { - return getTabIdFromCategoryId(EmojiCategory.ID_RECENTS); + return getTabIdFromCategoryId(ID_RECENTS); } private int computeCategoryPageCount(final int categoryId) { - final Keyboard keyboard = mLayoutSet.getKeyboard(sCategoryElementId[categoryId]); + final Keyboard keyboard = mLayoutSet.getKeyboard(sCategoryElement[categoryId]); return (keyboard.getSortedKeys().size() - 1) / computeMaxKeyCountPerPage() + 1; } @@ -291,22 +278,22 @@ public DynamicGridKeyboard getKeyboard(final int categoryId, final int id) { } final int currentWidth = ResourceUtils.getKeyboardWidth(mContext, Settings.getValues()); - if (categoryId == EmojiCategory.ID_RECENTS) { + if (categoryId == ID_RECENTS) { final DynamicGridKeyboard kbd = new DynamicGridKeyboard(mPrefs, - mLayoutSet.getKeyboard(KeyboardId.ELEMENT_EMOJI_RECENTS), + mLayoutSet.getKeyboard(KeyboardElement.EMOJI_RECENTS), mMaxRecentsKeyCount, categoryId, currentWidth); mCategoryKeyboardMap.put(categoryKeyboardMapKey, kbd); kbd.loadRecentKeys(mCategoryKeyboardMap.values()); return kbd; } - final Keyboard keyboard = mLayoutSet.getKeyboard(sCategoryElementId[categoryId]); + final Keyboard keyboard = mLayoutSet.getKeyboard(sCategoryElement[categoryId]); final int keyCountPerPage = computeMaxKeyCountPerPage(); final Key[][] sortedKeysPages = sortKeysGrouped( keyboard.getSortedKeys(), keyCountPerPage); for (int pageId = 0; pageId < sortedKeysPages.length; ++pageId) { final DynamicGridKeyboard tempKeyboard = new DynamicGridKeyboard(mPrefs, - mLayoutSet.getKeyboard(KeyboardId.ELEMENT_EMOJI_RECENTS), + mLayoutSet.getKeyboard(KeyboardElement.EMOJI_RECENTS), keyCountPerPage, categoryId, currentWidth); for (final Key emojiKey : sortedKeysPages[pageId]) { if (emojiKey == null) { @@ -322,7 +309,7 @@ public DynamicGridKeyboard getKeyboard(final int categoryId, final int id) { private int computeMaxKeyCountPerPage() { final DynamicGridKeyboard tempKeyboard = new DynamicGridKeyboard(mPrefs, - mLayoutSet.getKeyboard(KeyboardId.ELEMENT_EMOJI_RECENTS), + mLayoutSet.getKeyboard(KeyboardElement.EMOJI_RECENTS), 0, 0, ResourceUtils.getKeyboardWidth(mContext, Settings.getValues())); return MAX_LINE_COUNT_PER_PAGE * tempKeyboard.getOccupiedColumnCount(); } diff --git a/app/src/main/java/helium314/keyboard/keyboard/emoji/EmojiPalettesView.java b/app/src/main/java/helium314/keyboard/keyboard/emoji/EmojiPalettesView.java index 534483c984..fe3d7ca7e5 100644 --- a/app/src/main/java/helium314/keyboard/keyboard/emoji/EmojiPalettesView.java +++ b/app/src/main/java/helium314/keyboard/keyboard/emoji/EmojiPalettesView.java @@ -30,7 +30,7 @@ import helium314.keyboard.keyboard.Key; import helium314.keyboard.keyboard.Keyboard; import helium314.keyboard.keyboard.KeyboardActionListener; -import helium314.keyboard.keyboard.KeyboardId; +import helium314.keyboard.keyboard.KeyboardElement; import helium314.keyboard.keyboard.KeyboardLayoutSet; import helium314.keyboard.keyboard.KeyboardSwitcher; import helium314.keyboard.keyboard.KeyboardView; @@ -361,7 +361,7 @@ private void setupBottomRowKeyboard(final EditorInfo editorInfo, final KeyboardA keyboardView.setKeyboardActionListener(keyboardActionListener); PointerTracker.switchTo(keyboardView); final KeyboardLayoutSet kls = KeyboardLayoutSet.Builder.buildEmojiClipBottomRow(getContext(), editorInfo); - final Keyboard keyboard = kls.getKeyboard(KeyboardId.ELEMENT_EMOJI_BOTTOM_ROW); + final Keyboard keyboard = kls.getKeyboard(KeyboardElement.EMOJI_BOTTOM_ROW); keyboardView.setKeyboard(keyboard); } diff --git a/app/src/main/java/helium314/keyboard/keyboard/internal/KeyboardBuilder.kt b/app/src/main/java/helium314/keyboard/keyboard/internal/KeyboardBuilder.kt index 02f84ed710..8f3335acb8 100644 --- a/app/src/main/java/helium314/keyboard/keyboard/internal/KeyboardBuilder.kt +++ b/app/src/main/java/helium314/keyboard/keyboard/internal/KeyboardBuilder.kt @@ -12,6 +12,7 @@ import androidx.annotation.XmlRes import helium314.keyboard.keyboard.Key import helium314.keyboard.keyboard.Key.KeyParams import helium314.keyboard.keyboard.Keyboard +import helium314.keyboard.keyboard.KeyboardElement import helium314.keyboard.keyboard.KeyboardId import helium314.keyboard.keyboard.internal.keyboard_parser.EmojiParser import helium314.keyboard.keyboard.internal.keyboard_parser.KeyboardParser @@ -45,7 +46,8 @@ open class KeyboardBuilder(protected val mContext: Context, fun load(id: KeyboardId): KeyboardBuilder { mParams.mId = id - if (id.isEmojiKeyboard) { + val element = id.element + if (element.isEmojiLayout) { mParams.mAllowRedundantPopupKeys = true readAttributes(R.xml.kbd_emoji) keysInRows = EmojiParser(mParams, mContext).parse() @@ -57,7 +59,7 @@ open class KeyboardBuilder(protected val mContext: Context, mParams.mTouchPositionCorrection.load(mContext.resources.getStringArray(R.array.touch_position_correction_data_default)) determineAbsoluteValues() } catch (e: Exception) { - Log.e(TAG, "error parsing layout $id ${id.elementId}", e) + Log.e(TAG, "error parsing layout $id $element", e) throw e } } @@ -67,8 +69,9 @@ open class KeyboardBuilder(protected val mContext: Context, private fun setupParams() { val sv = Settings.getValues() mParams.mAllowRedundantPopupKeys = !sv.mRemoveRedundantPopups - mParams.mProximityCharsCorrectionEnabled = mParams.mId.elementId == KeyboardId.ELEMENT_ALPHABET - || (mParams.mId.isAlphabetKeyboard && !mParams.mId.subtype.hasExtraValue(Constants.Subtype.ExtraValue.NO_SHIFT_PROXIMITY_CORRECTION)) + val element = mParams.mId.element + mParams.mProximityCharsCorrectionEnabled = element == KeyboardElement.ALPHABET + || (element.isAlphabetLayout && !mParams.mId.subtype.hasExtraValue(Constants.Subtype.ExtraValue.NO_SHIFT_PROXIMITY_CORRECTION)) addLocaleKeyTextsToParams(mContext, mParams, sv.mShowMorePopupKeys) mParams.mPopupKeyTypes.addAll(sv.mPopupKeyTypes) @@ -101,8 +104,8 @@ open class KeyboardBuilder(protected val mContext: Context, } open fun build(): Keyboard { - if (mParams.mId.isSplitLayout - && mParams.mId.elementId in KeyboardId.ELEMENT_ALPHABET..KeyboardId.ELEMENT_SYMBOLS_SHIFTED) { + val id = mParams.mId + if (id.isSplitLayout && id.element.isAlphaOrSymbolLayout) { addSplit() } addKeysToParams() @@ -248,7 +251,7 @@ open class KeyboardBuilder(protected val mContext: Context, // -> why is this happening? // but anyway, since the height is resized correctly already, we don't need to adjust the // occupied height, except for the scrollable emoji keyoards - if (!mParams.mId.isEmojiKeyboard) return + if (!mParams.mId.element.isEmojiLayout) return val actualHeight = mCurrentY - mParams.mVerticalGap + mParams.mBottomPadding mParams.mOccupiedHeight = mParams.mOccupiedHeight.coerceAtLeast(actualHeight) } diff --git a/app/src/main/java/helium314/keyboard/keyboard/internal/KeyboardParams.java b/app/src/main/java/helium314/keyboard/keyboard/internal/KeyboardParams.java index 1a4214fc0f..692df42c32 100644 --- a/app/src/main/java/helium314/keyboard/keyboard/internal/KeyboardParams.java +++ b/app/src/main/java/helium314/keyboard/keyboard/internal/KeyboardParams.java @@ -236,7 +236,7 @@ public void readAttributes(final Context context, @Nullable final AttributeSet a final float defaultKeyWidthFactor = context.getResources().getInteger(R.integer.config_screen_metrics) > 2 ? 0.9f : 1f; final float alphaSymbolKeyWidth = keyAttr.getFraction(R.styleable.Keyboard_Key_keyWidth, 1, 1, defaultKeyWidthFactor / DEFAULT_KEYBOARD_COLUMNS); - mDefaultKeyWidth = mId.isNumberLayout() ? 0.17f : alphaSymbolKeyWidth; + mDefaultKeyWidth = mId.element.isNumberLayout() ? 0.17f : alphaSymbolKeyWidth; mDefaultAbsoluteKeyWidth = (int) (mDefaultKeyWidth * mBaseWidth); mAbsolutePopupKeyWidth = (int) (alphaSymbolKeyWidth * mBaseWidth); @@ -278,7 +278,7 @@ public void readAttributes(final Context context, @Nullable final AttributeSet a // touchPositionResId currently is 0 for popups, and touch_position_correction_data_holo for others final int touchPositionResId = keyboardAttr.getResourceId(R.styleable.Keyboard_touchPositionCorrectionData, 0); if (touchPositionResId != 0) { - final int actualId = mId.isAlphabetKeyboard() ? touchPositionResId : R.array.touch_position_correction_data_default; + final int actualId = mId.element.isAlphabetLayout() ? touchPositionResId : R.array.touch_position_correction_data_default; final String[] data = context.getResources().getStringArray(actualId); mTouchPositionCorrection.load(data); } diff --git a/app/src/main/java/helium314/keyboard/keyboard/internal/keyboard_parser/EmojiParser.kt b/app/src/main/java/helium314/keyboard/keyboard/internal/keyboard_parser/EmojiParser.kt index 460ce52ae6..2b2799664e 100644 --- a/app/src/main/java/helium314/keyboard/keyboard/internal/keyboard_parser/EmojiParser.kt +++ b/app/src/main/java/helium314/keyboard/keyboard/internal/keyboard_parser/EmojiParser.kt @@ -4,7 +4,7 @@ package helium314.keyboard.keyboard.internal.keyboard_parser import android.content.Context import helium314.keyboard.keyboard.Key import helium314.keyboard.keyboard.Key.KeyParams -import helium314.keyboard.keyboard.KeyboardId +import helium314.keyboard.keyboard.KeyboardElement import helium314.keyboard.keyboard.emoji.SupportedEmojis import helium314.keyboard.keyboard.internal.KeyboardParams import helium314.keyboard.keyboard.internal.keyboard_parser.floris.KeyCode @@ -22,17 +22,18 @@ import kotlin.math.sqrt class EmojiParser(private val params: KeyboardParams, private val context: Context) { fun parse(): ArrayList> { - val emojiFileName = when (params.mId.elementId) { - KeyboardId.ELEMENT_EMOJI_CATEGORY1 -> "SMILEYS_AND_EMOTION.txt" - KeyboardId.ELEMENT_EMOJI_CATEGORY2 -> "PEOPLE_AND_BODY.txt" - KeyboardId.ELEMENT_EMOJI_CATEGORY3 -> "ANIMALS_AND_NATURE.txt" - KeyboardId.ELEMENT_EMOJI_CATEGORY4 -> "FOOD_AND_DRINK.txt" - KeyboardId.ELEMENT_EMOJI_CATEGORY5 -> "TRAVEL_AND_PLACES.txt" - KeyboardId.ELEMENT_EMOJI_CATEGORY6 -> "ACTIVITIES.txt" - KeyboardId.ELEMENT_EMOJI_CATEGORY7 -> "OBJECTS.txt" - KeyboardId.ELEMENT_EMOJI_CATEGORY8 -> "SYMBOLS.txt" - KeyboardId.ELEMENT_EMOJI_CATEGORY9 -> "FLAGS.txt" - KeyboardId.ELEMENT_EMOJI_CATEGORY10 -> "EMOTICONS.txt" + val element = params.mId.element + val emojiFileName = when (element) { + KeyboardElement.EMOJI_CATEGORY1 -> "SMILEYS_AND_EMOTION.txt" + KeyboardElement.EMOJI_CATEGORY2 -> "PEOPLE_AND_BODY.txt" + KeyboardElement.EMOJI_CATEGORY3 -> "ANIMALS_AND_NATURE.txt" + KeyboardElement.EMOJI_CATEGORY4 -> "FOOD_AND_DRINK.txt" + KeyboardElement.EMOJI_CATEGORY5 -> "TRAVEL_AND_PLACES.txt" + KeyboardElement.EMOJI_CATEGORY6 -> "ACTIVITIES.txt" + KeyboardElement.EMOJI_CATEGORY7 -> "OBJECTS.txt" + KeyboardElement.EMOJI_CATEGORY8 -> "SYMBOLS.txt" + KeyboardElement.EMOJI_CATEGORY9 -> "FLAGS.txt" + KeyboardElement.EMOJI_CATEGORY10 -> "EMOTICONS.txt" else -> null } val emojiLines = if (emojiFileName == null) { @@ -44,7 +45,7 @@ class EmojiParser(private val params: KeyboardParams, private val context: Conte context.assets.open("emoji/$emojiFileName").reader().use { it.readLines() } } val defaultSkinTone = context.prefs().getString(Settings.PREF_EMOJI_SKIN_TONE, Defaults.PREF_EMOJI_SKIN_TONE)!! - if (params.mId.elementId == KeyboardId.ELEMENT_EMOJI_CATEGORY2 && defaultSkinTone != "") { + if (element == KeyboardElement.EMOJI_CATEGORY2 && defaultSkinTone != "") { // adjust PEOPLE_AND_BODY if we have a non-yellow default skin tone val modifiedLines = emojiLines.map { line -> val split = line.splitOnWhitespace().toMutableList() @@ -94,7 +95,7 @@ class EmojiParser(private val params: KeyboardParams, private val context: Conte } private fun parseEmojiKeyNew(line: String): KeyParams? { - if (!line.contains(" ") || params.mId.elementId == KeyboardId.ELEMENT_EMOJI_CATEGORY10) { + if (!line.contains(" ") || params.mId.element == KeyboardElement.EMOJI_CATEGORY10) { // single emoji without popups, or emoticons (there is one that contains space...) return if (SupportedEmojis.isUnsupported(line)) null else KeyParams(line, line.getCode(), null, null, Key.LABEL_FLAGS_FONT_NORMAL, params) diff --git a/app/src/main/java/helium314/keyboard/keyboard/internal/keyboard_parser/KeyboardParser.kt b/app/src/main/java/helium314/keyboard/keyboard/internal/keyboard_parser/KeyboardParser.kt index 06f29c0c04..b3f649c551 100644 --- a/app/src/main/java/helium314/keyboard/keyboard/internal/keyboard_parser/KeyboardParser.kt +++ b/app/src/main/java/helium314/keyboard/keyboard/internal/keyboard_parser/KeyboardParser.kt @@ -6,7 +6,7 @@ import android.content.res.Configuration import helium314.keyboard.latin.utils.Log import helium314.keyboard.keyboard.Key import helium314.keyboard.keyboard.Key.KeyParams -import helium314.keyboard.keyboard.KeyboardId +import helium314.keyboard.keyboard.KeyboardElement import helium314.keyboard.keyboard.internal.KeyboardParams import helium314.keyboard.keyboard.internal.keyboard_parser.floris.KeyCode import helium314.keyboard.keyboard.internal.keyboard_parser.floris.KeyData @@ -36,33 +36,34 @@ import kotlin.math.roundToInt */ class KeyboardParser(private val params: KeyboardParams, private val context: Context) { private val defaultLabelFlags = when { - params.mId.isAlphabetKeyboard -> params.mLocaleKeyboardInfos.labelFlags + params.mId.element.isAlphabetLayout -> params.mLocaleKeyboardInfos.labelFlags // reproduce the no-hints in symbol layouts // todo: add setting? or put it in TextKeyData to happen only if no label flags specified explicitly? - params.mId.isAlphaOrSymbolKeyboard -> Key.LABEL_FLAGS_DISABLE_HINT_LABEL + params.mId.element.isAlphaOrSymbolLayout -> Key.LABEL_FLAGS_DISABLE_HINT_LABEL else -> 0 } fun parseLayout(): ArrayList> { params.readAttributes(context, null) - // todo: maybe determine layoutType earlier, and to less stuff based on elementId - val layoutType = when (params.mId.elementId) { - KeyboardId.ELEMENT_SYMBOLS -> LayoutType.SYMBOLS - KeyboardId.ELEMENT_SYMBOLS_SHIFTED -> LayoutType.MORE_SYMBOLS - KeyboardId.ELEMENT_PHONE -> LayoutType.PHONE - KeyboardId.ELEMENT_PHONE_SYMBOLS -> LayoutType.PHONE_SYMBOLS - KeyboardId.ELEMENT_NUMBER -> LayoutType.NUMBER - KeyboardId.ELEMENT_NUMPAD -> if (Settings.getValues().mDisplayOrientation == Configuration.ORIENTATION_LANDSCAPE) + // todo: maybe determine layoutType earlier + val element = params.mId.element + val layoutType = when (element) { + KeyboardElement.SYMBOLS -> LayoutType.SYMBOLS + KeyboardElement.SYMBOLS_SHIFTED -> LayoutType.MORE_SYMBOLS + KeyboardElement.PHONE -> LayoutType.PHONE + KeyboardElement.PHONE_SYMBOLS -> LayoutType.PHONE_SYMBOLS + KeyboardElement.NUMBER -> LayoutType.NUMBER + KeyboardElement.NUMPAD -> if (Settings.getValues().mDisplayOrientation == Configuration.ORIENTATION_LANDSCAPE) LayoutType.NUMPAD_LANDSCAPE else LayoutType.NUMPAD - KeyboardId.ELEMENT_EMOJI_BOTTOM_ROW -> LayoutType.EMOJI_BOTTOM - KeyboardId.ELEMENT_CLIPBOARD_BOTTOM_ROW -> LayoutType.CLIPBOARD_BOTTOM + KeyboardElement.EMOJI_BOTTOM_ROW -> LayoutType.EMOJI_BOTTOM + KeyboardElement.CLIPBOARD_BOTTOM_ROW -> LayoutType.CLIPBOARD_BOTTOM else -> LayoutType.MAIN } val baseKeys = LayoutParser.parseLayout(layoutType, params, context) val keysInRows = createRows(baseKeys) val heightRescale: Float - if (params.mId.isEmojiClipBottomRow) { + if (element.isBottomRow) { heightRescale = 4f // params rescale is not perfect, especially mTopPadding may cause 1 pixel offsets because it's already been converted to int once if (Settings.getValues().mShowsNumberRow) { @@ -87,7 +88,8 @@ class KeyboardParser(private val params: KeyboardParams, private val context: Co private fun createRows(baseKeys: MutableList>): ArrayList> { // add padding for number layouts in landscape mode (maybe do it some other way later) - if (params.mId.isNumberLayout && params.mId.elementId != KeyboardId.ELEMENT_NUMPAD + val element = params.mId.element + if (element.isNumberLayout && element != KeyboardElement.NUMPAD && context.resources.configuration.orientation == Configuration.ORIENTATION_LANDSCAPE) { params.mLeftPadding = (params.mOccupiedWidth * 0.1f).toInt() params.mRightPadding = (params.mOccupiedWidth * 0.1f).toInt() @@ -96,9 +98,9 @@ class KeyboardParser(private val params: KeyboardParams, private val context: Co val numberRow = getNumberRow() addNumberRowOrPopupKeys(baseKeys, numberRow) - if (params.mId.isAlphabetKeyboard) + if (element.isAlphabetLayout) addSymbolPopupKeys(baseKeys) - if (params.mId.isAlphaOrSymbolKeyboard && params.mId.numberRowEnabled) { + if (element.isAlphaOrSymbolLayout && params.mId.numberRowEnabled) { val newLabelFlags = defaultLabelFlags or if (Settings.getValues().mShowNumberRowHints) 0 else Key.LABEL_FLAGS_DISABLE_HINT_LABEL baseKeys.add(0, numberRow.mapTo(mutableListOf()) { it.copy(newLabelFlags = newLabelFlags) }) @@ -120,9 +122,9 @@ class KeyboardParser(private val params: KeyboardParams, private val context: Co val functionalKeys = mutableListOf, List>>() val baseKeyParams = baseKeys.mapIndexed { i, it -> - val row: List = if (params.mId.isAlphaOrSymbolKeyboard && i == baseKeys.lastIndex - 1 && params.setTabletExtraKeys) { + val row: List = if (element.isAlphaOrSymbolLayout && i == baseKeys.lastIndex - 1 && params.setTabletExtraKeys) { // add bottom row extra keys - val tabletExtraKeys = params.mLocaleKeyboardInfos.getTabletExtraKeys(params.mId.elementId) + val tabletExtraKeys = params.mLocaleKeyboardInfos.getTabletExtraKeys(element) tabletExtraKeys.first + it + tabletExtraKeys.second } else { it @@ -192,7 +194,7 @@ class KeyboardParser(private val params: KeyboardParams, private val context: Co // adjust last normal row key widths to be aligned with row above, assuming a reasonably close-to-default alpha / symbol layout // like in original layouts, e.g. for nordic and swiss layouts - if (!params.mId.isAlphaOrSymbolKeyboard || bassKeyParams.size < 3 || bassKeyParams.last().isNotEmpty()) + if (!params.mId.element.isAlphaOrSymbolLayout || bassKeyParams.size < 3 || bassKeyParams.last().isNotEmpty()) return keysInRows val lastNormalRow = bassKeyParams[bassKeyParams.lastIndex - 1] val rowAboveLast = bassKeyParams[bassKeyParams.lastIndex - 2] @@ -225,7 +227,8 @@ class KeyboardParser(private val params: KeyboardParams, private val context: Co */ private fun adjustBottomFunctionalRowAndBaseKeys(allFunctionalKeys: MutableList>, baseKeys: MutableList>) { val functionalKeysBottom = allFunctionalKeys.lastOrNull() ?: return - if (!params.mId.isAlphaOrSymbolKeyboard || functionalKeysBottom.isEmpty() || functionalKeysBottom.any { it.isKeyPlaceholder() }) + val element = params.mId.element + if (!element.isAlphaOrSymbolLayout || functionalKeysBottom.isEmpty() || functionalKeysBottom.any { it.isKeyPlaceholder() }) return // replace comma / period if 2 keys in normal bottom row if (baseKeys.last().size == 2) { @@ -244,7 +247,7 @@ class KeyboardParser(private val params: KeyboardParams, private val context: Co // add zwnj key next to space if necessary val spaceIndex = functionalKeysBottom.indexOfFirst { it.label == KeyLabel.SPACE && it.width <= 0 } // width could be 0 or -1 if (spaceIndex >= 0) { - if (params.mLocaleKeyboardInfos.hasZwnjKey && params.mId.isAlphabetKeyboard) { + if (params.mLocaleKeyboardInfos.hasZwnjKey && element.isAlphabetLayout) { functionalKeysBottom.add(spaceIndex + 1, TextKeyData(label = KeyLabel.ZWNJ)) } } @@ -264,12 +267,14 @@ class KeyboardParser(private val params: KeyboardParams, private val context: Co } private fun addNumberRowOrPopupKeys(baseKeys: MutableList>, numberRow: MutableList) { - if (!params.mId.numberRowEnabled && params.mId.numberRowInSymbols && params.mId.elementId == KeyboardId.ELEMENT_SYMBOLS) { + val id = params.mId + val element = id.element + if (!id.numberRowEnabled && id.numberRowInSymbols && element == KeyboardElement.SYMBOLS) { // replace first symbols row with number row, but use the labels as popupKeys val numberRowCopy = numberRow.toMutableList() numberRowCopy.forEachIndexed { index, keyData -> keyData.popup.symbol = baseKeys[0].getOrNull(index)?.label } baseKeys[0] = numberRowCopy - } else if (!params.mId.numberRowEnabled && params.mId.isAlphabetKeyboard && !hasBuiltInNumbers()) { + } else if (!id.numberRowEnabled && element.isAlphabetLayout && !hasBuiltInNumbers()) { if (baseKeys[0].any { it.popup.main != null || !it.popup.relevant.isNullOrEmpty() } // first row of baseKeys has any layout popup key && params.mPopupKeyLabelSources.let { val layout = it.indexOf(POPUP_KEYS_LAYOUT) diff --git a/app/src/main/java/helium314/keyboard/keyboard/internal/keyboard_parser/LayoutParser.kt b/app/src/main/java/helium314/keyboard/keyboard/internal/keyboard_parser/LayoutParser.kt index 351cc5bd33..1eca241b26 100644 --- a/app/src/main/java/helium314/keyboard/keyboard/internal/keyboard_parser/LayoutParser.kt +++ b/app/src/main/java/helium314/keyboard/keyboard/internal/keyboard_parser/LayoutParser.kt @@ -35,7 +35,7 @@ object LayoutParser { fun clearCache() = layoutCache.clear() fun parseLayout(layoutType: LayoutType, params: KeyboardParams, context: Context): MutableList> { - if (layoutType == LayoutType.FUNCTIONAL && !params.mId.isAlphaOrSymbolKeyboard) + if (layoutType == LayoutType.FUNCTIONAL && !params.mId.element.isAlphaOrSymbolLayout) return mutableListOf(mutableListOf()) // no functional keys val layoutName = if (layoutType == LayoutType.MAIN) params.mId.subtype.mainLayoutName else params.mId.subtype.layouts[layoutType] ?: Settings.readDefaultLayoutName(layoutType, context.prefs()) @@ -91,7 +91,7 @@ object LayoutParser { return { params -> simpleKeyData.mapIndexedTo(mutableListOf()) { i, row -> val newRow = row.toMutableList() - if (params.mId.isAlphabetKeyboard && layoutName.endsWith("+")) + if (params.mId.element.isAlphabetLayout && layoutName.endsWith("+")) params.mLocaleKeyboardInfos.getExtraKeys(i+1)?.let { newRow.addAll(it) } newRow } diff --git a/app/src/main/java/helium314/keyboard/keyboard/internal/keyboard_parser/LocaleKeyboardInfos.kt b/app/src/main/java/helium314/keyboard/keyboard/internal/keyboard_parser/LocaleKeyboardInfos.kt index 676685a15a..ededa52804 100644 --- a/app/src/main/java/helium314/keyboard/keyboard/internal/keyboard_parser/LocaleKeyboardInfos.kt +++ b/app/src/main/java/helium314/keyboard/keyboard/internal/keyboard_parser/LocaleKeyboardInfos.kt @@ -3,7 +3,7 @@ package helium314.keyboard.keyboard.internal.keyboard_parser import android.content.Context import helium314.keyboard.keyboard.Key -import helium314.keyboard.keyboard.KeyboardId +import helium314.keyboard.keyboard.KeyboardElement import helium314.keyboard.keyboard.internal.KeyboardParams import helium314.keyboard.keyboard.internal.keyboard_parser.floris.KeyData import helium314.keyboard.keyboard.internal.keyboard_parser.floris.toTextKey @@ -91,11 +91,11 @@ class LocaleKeyboardInfos(dataStream: InputStream?, locale: Locale) { } /** Pair(extraKeysLeft, extraKeysRight) */ - fun getTabletExtraKeys(elementId: Int): Pair, List> { + fun getTabletExtraKeys(element: KeyboardElement): Pair, List> { val flags = Key.LABEL_FLAGS_FONT_DEFAULT - return when (elementId) { - KeyboardId.ELEMENT_SYMBOLS -> listOf("\\".toTextKey(labelFlags = flags), "=".toTextKey(labelFlags = flags)) to emptyList() - KeyboardId.ELEMENT_SYMBOLS_SHIFTED -> emptyList() to listOf("¡".toTextKey(labelFlags = flags), "¿".toTextKey(labelFlags = flags)) + return when (element) { + KeyboardElement.SYMBOLS -> listOf("\\".toTextKey(labelFlags = flags), "=".toTextKey(labelFlags = flags)) to emptyList() + KeyboardElement.SYMBOLS_SHIFTED -> emptyList() to listOf("¡".toTextKey(labelFlags = flags), "¿".toTextKey(labelFlags = flags)) else -> emptyList() to listOf("!".toTextKey(labelFlags = flags), labelQuestion.toTextKey(labelFlags = flags)) // assume alphabet } } diff --git a/app/src/main/java/helium314/keyboard/keyboard/internal/keyboard_parser/floris/KeyData.kt b/app/src/main/java/helium314/keyboard/keyboard/internal/keyboard_parser/floris/KeyData.kt index 590df01b19..28092a05d7 100644 --- a/app/src/main/java/helium314/keyboard/keyboard/internal/keyboard_parser/floris/KeyData.kt +++ b/app/src/main/java/helium314/keyboard/keyboard/internal/keyboard_parser/floris/KeyData.kt @@ -5,9 +5,11 @@ */ package helium314.keyboard.keyboard.internal.keyboard_parser.floris +import helium314.keyboard.keyboard.KeyboardElement import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable import helium314.keyboard.keyboard.KeyboardId +import helium314.keyboard.keyboard.KeyboardMode import helium314.keyboard.keyboard.internal.KeyboardParams // taken from FlorisBoard, small modifications @@ -69,7 +71,7 @@ class CaseSelector( val upper: AbstractKeyData, ) : AbstractKeyData { override fun compute(params: KeyboardParams): KeyData? { - return (if (params.mId.isAlphabetShifted) { upper } else { lower }).compute(params) + return (if (params.mId.element.isAlphabetShifted) { upper } else { lower }).compute(params) } override fun asString(isForDisplay: Boolean): String { @@ -115,11 +117,11 @@ class ShiftStateSelector( val manualOrLocked: AbstractKeyData? = null, ) : AbstractKeyData { override fun compute(params: KeyboardParams): KeyData? { - return when (params.mId.elementId) { - KeyboardId.ELEMENT_ALPHABET, KeyboardId.ELEMENT_SYMBOLS -> unshifted ?: default - KeyboardId.ELEMENT_ALPHABET_MANUAL_SHIFTED -> shiftedManual ?: manualOrLocked ?: shifted ?: default - KeyboardId.ELEMENT_ALPHABET_AUTOMATIC_SHIFTED -> shiftedAutomatic ?: shifted ?: default - KeyboardId.ELEMENT_ALPHABET_SHIFT_LOCKED, KeyboardId.ELEMENT_ALPHABET_SHIFT_LOCK_SHIFTED -> capsLock ?: manualOrLocked ?: shifted ?: default + return when (params.mId.element) { + KeyboardElement.ALPHABET, KeyboardElement.SYMBOLS -> unshifted ?: default + KeyboardElement.ALPHABET_MANUAL_SHIFTED -> shiftedManual ?: manualOrLocked ?: shifted ?: default + KeyboardElement.ALPHABET_AUTOMATIC_SHIFTED -> shiftedAutomatic ?: shifted ?: default + KeyboardElement.ALPHABET_SHIFT_LOCKED, KeyboardElement.ALPHABET_SHIFT_LOCK_SHIFTED -> capsLock ?: manualOrLocked ?: shifted ?: default else -> default // or rather unshifted? }?.compute(params) } @@ -144,19 +146,19 @@ class ShiftStateSelector( * @property default The default key data which should be used in case no key variation is known or for the current * key variation no override key is defined. Can be null, in this case this may mean the variation selector hides * the key if no direct match is present. - * @property email The key data to use if [KeyboardId.MODE_EMAIL] is active. If this value is + * @property email The key data to use if [KeyboardMode.EMAIL] is active. If this value is * null, [default] will be used instead. - * @property uri The key data to use if [KeyboardId.MODE_URL] is active. If this value is null, + * @property uri The key data to use if [KeyboardMode.URL] is active. If this value is null, * [default] will be used instead. * @property normal The key data to use when? Currently ignored... If this value is null, * [default] will be used instead. * @property password The key data to use if [KeyboardId.passwordInput] return true. If this value is * null, [default] will be used instead. - * @property date The key data to use if [KeyboardId.MODE_DATE] is active. If this value is null, + * @property date The key data to use if [KeyboardMode.DATE] is active. If this value is null, * null, [default] will be used instead. - * @property time The key data to use if [KeyboardId.MODE_TIME] is active. If this value is null, + * @property time The key data to use if [KeyboardMode.TIME] is active. If this value is null, * null, [default] will be used instead. - * @property datetime The key data to use if [KeyboardId.MODE_DATETIME] is active. If this value is null, + * @property datetime The key data to use if [KeyboardMode.DATETIME] is active. If this value is null, * null, [default] will be used instead. */ @Serializable @@ -172,15 +174,18 @@ data class VariationSelector( val datetime: AbstractKeyData? = null, ) : AbstractKeyData { override fun compute(params: KeyboardParams): KeyData? { - return when { - params.mId.passwordInput() -> password ?: default - params.mId.mode == KeyboardId.MODE_EMAIL -> email ?: default - params.mId.mode == KeyboardId.MODE_URL -> uri ?: default - params.mId.mode == KeyboardId.MODE_DATE -> date ?: default - params.mId.mode == KeyboardId.MODE_TIME -> time ?: default - params.mId.mode == KeyboardId.MODE_DATETIME -> datetime ?: default - else -> normal ?: default - }?.compute(params) + val id = params.mId + return ( + if (id.passwordInput()) password ?: default + else when (id.mode) { + KeyboardMode.EMAIL -> email ?: default + KeyboardMode.URL -> uri ?: default + KeyboardMode.DATE -> date ?: default + KeyboardMode.TIME -> time ?: default + KeyboardMode.DATETIME -> datetime ?: default + else -> normal ?: default + } + )?.compute(params) } override fun asString(isForDisplay: Boolean): String { @@ -195,8 +200,8 @@ data class VariationSelector( * * @property emojiKeyEnabled The key data to use if [KeyboardId.emojiKeyEnabled] is true. * @property languageKeyEnabled The key data to use if [KeyboardId.languageSwitchKeyEnabled] is true. - * @property symbols The key data to use if [KeyboardId.elementId] is [KeyboardId.ELEMENT_SYMBOLS]. - * @property moreSymbols The key data to use if [KeyboardId.elementId] is [KeyboardId.ELEMENT_SYMBOLS_SHIFTED]. + * @property symbols The key data to use if [KeyboardId.element] is [KeyboardElement.SYMBOLS]. + * @property moreSymbols The key data to use if [KeyboardId.element] is [KeyboardElement.SYMBOLS_SHIFTED]. * @property alphabet The key data to use if [KeyboardId.isAlphabetKeyboard] is true. * @property default The default key data which should be used in case none of the other conditions have a matching non-null * AbstractKeyData. Can be null, in this case no key is displayed. @@ -212,15 +217,17 @@ class KeyboardStateSelector( val default: AbstractKeyData? = null, ) : AbstractKeyData { override fun compute(params: KeyboardParams): KeyData? { - if (params.mId.emojiKeyEnabled) + val id = params.mId + if (id.emojiKeyEnabled) emojiKeyEnabled?.compute(params)?.let { return it } - if (params.mId.languageSwitchKeyEnabled) + if (id.languageSwitchKeyEnabled) languageKeyEnabled?.compute(params)?.let { return it } - if (params.mId.elementId == KeyboardId.ELEMENT_SYMBOLS) + val element = id.element + if (element == KeyboardElement.SYMBOLS) symbols?.compute(params)?.let { return it } - if (params.mId.elementId == KeyboardId.ELEMENT_SYMBOLS_SHIFTED) + if (element == KeyboardElement.SYMBOLS_SHIFTED) moreSymbols?.compute(params)?.let { return it } - if (params.mId.isAlphabetKeyboard) + if (element.isAlphabetLayout) alphabet?.compute(params)?.let { return it } return default?.compute(params) diff --git a/app/src/main/java/helium314/keyboard/keyboard/internal/keyboard_parser/floris/KeyLabel.kt b/app/src/main/java/helium314/keyboard/keyboard/internal/keyboard_parser/floris/KeyLabel.kt index 600b83e612..6059cbb8a5 100644 --- a/app/src/main/java/helium314/keyboard/keyboard/internal/keyboard_parser/floris/KeyLabel.kt +++ b/app/src/main/java/helium314/keyboard/keyboard/internal/keyboard_parser/floris/KeyLabel.kt @@ -1,7 +1,7 @@ package helium314.keyboard.keyboard.internal.keyboard_parser.floris import android.view.inputmethod.EditorInfo -import helium314.keyboard.keyboard.KeyboardId +import helium314.keyboard.keyboard.KeyboardElement import helium314.keyboard.keyboard.internal.KeyboardCodesSet import helium314.keyboard.keyboard.internal.KeyboardIconsSet import helium314.keyboard.keyboard.internal.KeyboardParams @@ -65,7 +65,8 @@ object KeyLabel { } fun String.rtlLabel(params: KeyboardParams): String { - if (!params.mId.subtype.isRtlSubtype || params.mId.isNumberLayout) return this + val id = params.mId + if (!id.subtype.isRtlSubtype || id.element.isNumberLayout) return this return when (this) { "{" -> "{|}" "}" -> "}|{" @@ -89,7 +90,7 @@ object KeyLabel { fun keyLabelToActualLabel(label: String, params: KeyboardParams): String { val newLabel = when (label) { - SYMBOL_ALPHA -> if (params.mId.isAlphabetKeyboard) params.mLocaleKeyboardInfos.labelSymbol else params.mLocaleKeyboardInfos.labelAlphabet + SYMBOL_ALPHA -> if (params.mId.element.isAlphabetLayout) params.mLocaleKeyboardInfos.labelSymbol else params.mLocaleKeyboardInfos.labelAlphabet SYMBOL -> params.mLocaleKeyboardInfos.labelSymbol ALPHA -> params.mLocaleKeyboardInfos.labelAlphabet COMMA -> params.mLocaleKeyboardInfos.labelComma @@ -130,12 +131,12 @@ object KeyLabel { else "$newLabel|!code/$code" } - private fun getShiftLabel(params: KeyboardParams) = when (params.mId.elementId) { - KeyboardId.ELEMENT_SYMBOLS_SHIFTED -> params.mLocaleKeyboardInfos.labelSymbol - KeyboardId.ELEMENT_SYMBOLS -> params.mLocaleKeyboardInfos.getShiftSymbolLabel( + private fun getShiftLabel(params: KeyboardParams) = when (params.mId.element) { + KeyboardElement.SYMBOLS_SHIFTED -> params.mLocaleKeyboardInfos.labelSymbol + KeyboardElement.SYMBOLS -> params.mLocaleKeyboardInfos.getShiftSymbolLabel( Settings.getInstance().isTablet) - KeyboardId.ELEMENT_ALPHABET_MANUAL_SHIFTED, KeyboardId.ELEMENT_ALPHABET_AUTOMATIC_SHIFTED -> "!icon/${KeyboardIconsSet.NAME_SHIFT_KEY_SHIFTED}" - KeyboardId.ELEMENT_ALPHABET_SHIFT_LOCKED, KeyboardId.ELEMENT_ALPHABET_SHIFT_LOCK_SHIFTED -> "!icon/${KeyboardIconsSet.NAME_SHIFT_KEY_LOCKED}" + KeyboardElement.ALPHABET_MANUAL_SHIFTED, KeyboardElement.ALPHABET_AUTOMATIC_SHIFTED -> "!icon/${KeyboardIconsSet.NAME_SHIFT_KEY_SHIFTED}" + KeyboardElement.ALPHABET_SHIFT_LOCKED, KeyboardElement.ALPHABET_SHIFT_LOCK_SHIFTED -> "!icon/${KeyboardIconsSet.NAME_SHIFT_KEY_LOCKED}" else -> "!icon/${KeyboardIconsSet.NAME_SHIFT_KEY}" } @@ -144,37 +145,45 @@ object KeyLabel { // maybe just remove it and if users want it they can use custom functional layouts? // but it has been like this "forever" and actually seems to make sense private fun getPeriodLabel(params: KeyboardParams): String { - if (params.mId.isNumberLayout) return "." - if (params.mId.isAlphabetKeyboard || params.mId.locale.language in listOf("ar", "fa")) + val id = params.mId + val element = id.element + if (element.isNumberLayout) return "." + if (element.isAlphabetLayout || id.locale.language in listOf("ar", "fa")) return params.mLocaleKeyboardInfos.labelPeriod return "." } - private fun getSpaceLabel(params: KeyboardParams): String = - if (params.mId.isAlphaOrSymbolKeyboard || params.mId.isEmojiClipBottomRow) + private fun getSpaceLabel(params: KeyboardParams): String { + val element = params.mId.element + return if (element.isAlphaOrSymbolLayout || element.isBottomRow) "!icon/space_key|!code/key_space" else "!icon/space_key_for_number_layout|!code/key_space" + } // todo (later): should this be handled with metaState? but metaState shift would require LOTS of changes... private fun getActionKeyCode(params: KeyboardParams): String { - params.mId.internalAction?.let { return "${KeyboardCodesSet.PREFIX_CODE}${it.code()}" } - return if (params.mId.isMultiLine && (params.mId.elementId == KeyboardId.ELEMENT_ALPHABET_MANUAL_SHIFTED || params.mId.elementId == KeyboardId.ELEMENT_ALPHABET_SHIFT_LOCK_SHIFTED)) + val id = params.mId + id.internalAction?.let { return "${KeyboardCodesSet.PREFIX_CODE}${it.code()}" } + val element = id.element + return if (id.isMultiLine && (element == KeyboardElement.ALPHABET_MANUAL_SHIFTED || element == KeyboardElement.ALPHABET_SHIFT_LOCK_SHIFTED)) "!code/key_shift_enter" else "!code/key_enter" } private fun getActionKeyLabel(params: KeyboardParams): String { - params.mId.internalAction?.let { return it.label() } - if (params.mId.isMultiLine && (params.mId.elementId == KeyboardId.ELEMENT_ALPHABET_MANUAL_SHIFTED || params.mId.elementId == KeyboardId.ELEMENT_ALPHABET_SHIFT_LOCK_SHIFTED)) + val id = params.mId + id.internalAction?.let { return it.label() } + val element = id.element + if (id.isMultiLine && (element == KeyboardElement.ALPHABET_MANUAL_SHIFTED || element == KeyboardElement.ALPHABET_SHIFT_LOCK_SHIFTED)) return "!icon/enter_key" - val iconName = when (params.mId.imeAction()) { + val iconName = when (id.imeAction()) { EditorInfo.IME_ACTION_GO -> KeyboardIconsSet.NAME_GO_KEY EditorInfo.IME_ACTION_SEARCH -> KeyboardIconsSet.NAME_SEARCH_KEY EditorInfo.IME_ACTION_SEND -> KeyboardIconsSet.NAME_SEND_KEY EditorInfo.IME_ACTION_NEXT -> KeyboardIconsSet.NAME_NEXT_KEY EditorInfo.IME_ACTION_DONE -> KeyboardIconsSet.NAME_DONE_KEY EditorInfo.IME_ACTION_PREVIOUS -> KeyboardIconsSet.NAME_PREVIOUS_KEY - InputTypeUtils.IME_ACTION_CUSTOM_LABEL -> return params.mId.customActionLabel + InputTypeUtils.IME_ACTION_CUSTOM_LABEL -> return id.customActionLabel else -> return "!icon/enter_key" } val replacement = iconName.replaceIconWithLabelIfNoDrawable(params) diff --git a/app/src/main/java/helium314/keyboard/keyboard/internal/keyboard_parser/floris/TextKeyData.kt b/app/src/main/java/helium314/keyboard/keyboard/internal/keyboard_parser/floris/TextKeyData.kt index 6a0989adb3..eea33cc1ea 100644 --- a/app/src/main/java/helium314/keyboard/keyboard/internal/keyboard_parser/floris/TextKeyData.kt +++ b/app/src/main/java/helium314/keyboard/keyboard/internal/keyboard_parser/floris/TextKeyData.kt @@ -10,7 +10,9 @@ import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable import kotlinx.serialization.Transient import helium314.keyboard.keyboard.Key +import helium314.keyboard.keyboard.KeyboardElement import helium314.keyboard.keyboard.KeyboardId +import helium314.keyboard.keyboard.KeyboardMode import helium314.keyboard.keyboard.KeyboardTheme import helium314.keyboard.keyboard.internal.KeyboardCodesSet import helium314.keyboard.keyboard.internal.KeyboardIconsSet @@ -95,15 +97,17 @@ sealed interface KeyData : AbstractKeyData { // keys could be replaced with toolbar keys, but parsing needs to be adjusted (should happen anyway...) private fun getCommaPopupKeys(params: KeyboardParams): List { val keys = mutableListOf() - if (!params.mId.deviceLocked) + val id = params.mId + if (!id.deviceLocked) keys.add("!icon/clipboard_normal_key|!code/key_clipboard") - if (!params.mId.emojiKeyEnabled && !params.mId.isNumberLayout) + val element = id.element + if (!id.emojiKeyEnabled && !element.isNumberLayout) keys.add("!icon/emoji_normal_key|!code/key_emoji") - if (!params.mId.languageSwitchKeyEnabled && !params.mId.isNumberLayout && RichInputMethodManager.canSwitchLanguage()) + if (!id.languageSwitchKeyEnabled && !element.isNumberLayout && RichInputMethodManager.canSwitchLanguage()) keys.add("!icon/language_switch_key|!code/key_language_switch") - if (!params.mId.oneHandedModeEnabled) + if (!id.oneHandedModeEnabled) keys.add("!icon/start_onehanded_mode_key|!code/key_toggle_onehanded") - if (!params.mId.deviceLocked) + if (!id.deviceLocked) keys.add("!icon/settings_key|!code/key_settings") if (shouldShowTldPopups(params)) { keys.add(",") @@ -112,9 +116,10 @@ sealed interface KeyData : AbstractKeyData { } private fun getPunctuationPopupKeys(params: KeyboardParams): List { - if (params.mId.elementId == KeyboardId.ELEMENT_SYMBOLS || params.mId.elementId == KeyboardId.ELEMENT_SYMBOLS_SHIFTED) + val element = params.mId.element + if (element == KeyboardElement.SYMBOLS || element == KeyboardElement.SYMBOLS_SHIFTED) return listOf("…") - if (params.mId.isNumberLayout) + if (element.isNumberLayout) return listOf(":", "…", ";", "∞", "π", "√", "°", "^") val popupKeys = params.mLocaleKeyboardInfos.getPopupKeys("punctuation")!!.toMutableList() if (params.mId.subtype.isRtlSubtype) { @@ -155,18 +160,7 @@ sealed interface KeyData : AbstractKeyData { val navigatePrev = keyboardId.navigatePrevious() val navigateNext = keyboardId.navigateNext() return when { - keyboardId.passwordInput() -> when { - navigatePrev && action == EditorInfo.IME_ACTION_NEXT -> POPUP_KEYS_NAVIGATE_PREVIOUS - action == EditorInfo.IME_ACTION_NEXT -> null - navigateNext && action == EditorInfo.IME_ACTION_PREVIOUS -> POPUP_KEYS_NAVIGATE_NEXT - action == EditorInfo.IME_ACTION_PREVIOUS -> null - navigateNext && navigatePrev -> POPUP_KEYS_NAVIGATE_PREVIOUS_NEXT - navigateNext -> POPUP_KEYS_NAVIGATE_NEXT - navigatePrev -> POPUP_KEYS_NAVIGATE_PREVIOUS - else -> null - } - // could change definition of numbers to query a range, or have a pre-defined list, but not that crucial - keyboardId.isNumberLayout || keyboardId.mode in listOf(KeyboardId.MODE_EMAIL, KeyboardId.MODE_DATE, KeyboardId.MODE_TIME, KeyboardId.MODE_DATETIME) -> when { + keyboardId.passwordInput() || keyboardId.element.isNumberLayout || keyboardId.mode.shouldSuppressEmojis() -> when { action == EditorInfo.IME_ACTION_NEXT && navigatePrev -> POPUP_KEYS_NAVIGATE_PREVIOUS action == EditorInfo.IME_ACTION_NEXT -> null action == EditorInfo.IME_ACTION_PREVIOUS && navigateNext -> POPUP_KEYS_NAVIGATE_NEXT @@ -206,7 +200,8 @@ sealed interface KeyData : AbstractKeyData { } // remove emoji shortcut on enter in tablet mode (like original, because bottom row always has an emoji key) // (probably not necessary, but whatever) and in emoji mode - if ((Settings.getInstance().isTablet || params.mId.elementId == KeyboardId.ELEMENT_EMOJI_BOTTOM_ROW) + val element = params.mId.element + if ((Settings.getInstance().isTablet || element == KeyboardElement.EMOJI_BOTTOM_ROW) && popupKeys.remove("!icon/emoji_action_key|!code/key_emoji")) { val i = popupKeys.indexOfFirst { it.startsWith(Key.POPUP_KEYS_FIXED_COLUMN_ORDER) } if (i > -1) { @@ -215,7 +210,7 @@ sealed interface KeyData : AbstractKeyData { popupKeys[i] = popupKeys[i].replace(n.toString(), (n - 1).toString()) } } - if (params.mId.elementId == KeyboardId.ELEMENT_CLIPBOARD_BOTTOM_ROW) + if (element == KeyboardElement.CLIPBOARD_BOTTOM_ROW) popupKeys.remove("!icon/clipboard_action_key|!code/key_clipboard") return SimplePopups(popupKeys) } @@ -240,7 +235,7 @@ sealed interface KeyData : AbstractKeyData { private fun shouldShowTldPopups(params: KeyboardParams): Boolean = (Settings.getInstance().current.mShowTldPopupKeys && params.mId.subtype.layouts[LayoutType.FUNCTIONAL] != "functional_keys_tablet" - && params.mId.mode in setOf(KeyboardId.MODE_URL, KeyboardId.MODE_EMAIL)) + && params.mId.mode.isWebMode) // could make arrays right away, but they need to be copied anyway as popupKeys arrays are modified when creating KeyParams private const val POPUP_KEYS_NAVIGATE_PREVIOUS = "!icon/previous_key|!code/key_action_previous,!icon/clipboard_action_key|!code/key_clipboard" @@ -303,17 +298,18 @@ sealed interface KeyData : AbstractKeyData { require(label.isNotEmpty() || type == KeyType.PLACEHOLDER || code != KeyCode.UNSPECIFIED) { "non-placeholder key has no code and no label" } require(width >= 0f || width == -1f) { "illegal width $width" } val newLabel = label.convertFlorisLabel().resolveStringLabel(params) - if (newLabel == KeyLabel.SHIFT && params.mId.isAlphabetKeyboard + val element = params.mId.element + if (newLabel == KeyLabel.SHIFT && element.isAlphabetLayout && params.mId.subtype.hasExtraValue(Constants.Subtype.ExtraValue.NO_SHIFT_KEY)) { return null } val newCode = code.checkAndConvertCode() - val newLabelFlags = if (labelFlags == 0 && params.mId.isNumberLayout) { + val newLabelFlags = if (labelFlags == 0 && element.isNumberLayout) { if (type == KeyType.NUMERIC) { - when (params.mId.elementId) { - KeyboardId.ELEMENT_PHONE -> Key.LABEL_FLAGS_ALIGN_LABEL_OFF_CENTER or Key.LABEL_FLAGS_HAS_HINT_LABEL or Key.LABEL_FLAGS_FOLLOW_KEY_LARGE_LETTER_RATIO - KeyboardId.ELEMENT_PHONE_SYMBOLS -> 0 + when (element) { + KeyboardElement.PHONE -> Key.LABEL_FLAGS_ALIGN_LABEL_OFF_CENTER or Key.LABEL_FLAGS_HAS_HINT_LABEL or Key.LABEL_FLAGS_FOLLOW_KEY_LARGE_LETTER_RATIO + KeyboardElement.PHONE_SYMBOLS -> 0 else -> Key.LABEL_FLAGS_FOLLOW_KEY_LARGE_LETTER_RATIO } } else 0 @@ -411,15 +407,17 @@ sealed interface KeyData : AbstractKeyData { KeyLabel.SHIFT -> return Key.BACKGROUND_TYPE_FUNCTIONAL } if (type == KeyType.PLACEHOLDER) return Key.BACKGROUND_TYPE_EMPTY - if ((params.mId.elementId == KeyboardId.ELEMENT_SYMBOLS || params.mId.elementId == KeyboardId.ELEMENT_SYMBOLS_SHIFTED) + val element = params.mId.element + if ((element == KeyboardElement.SYMBOLS || element == KeyboardElement.SYMBOLS_SHIFTED) && (groupId == GROUP_COMMA || groupId == GROUP_PERIOD)) return Key.BACKGROUND_TYPE_FUNCTIONAL return Key.BACKGROUND_TYPE_NORMAL } private fun getDefaultWidth(params: KeyboardParams): Float { - return if (label == KeyLabel.SPACE && params.mId.isAlphaOrSymbolKeyboard) -1f - else if (type == KeyType.NUMERIC && params.mId.isNumberLayout) -1f + val element = params.mId.element + return if (label == KeyLabel.SPACE && element.isAlphaOrSymbolLayout) -1f + else if (type == KeyType.NUMERIC && element.isNumberLayout) -1f else params.mDefaultKeyWidth } @@ -430,15 +428,15 @@ sealed interface KeyData : AbstractKeyData { KeyLabel.COMMA -> Key.LABEL_FLAGS_HAS_POPUP_HINT // essentially the first term only changes the appearance of the armenian period key in holo theme KeyLabel.PERIOD -> (Key.LABEL_FLAGS_HAS_POPUP_HINT and - if (params.mId.isAlphabetKeyboard) params.mLocaleKeyboardInfos.labelFlags else 0) or + if (params.mId.element.isAlphabetLayout) params.mLocaleKeyboardInfos.labelFlags else 0) or Key.LABEL_FLAGS_PRESERVE_CASE or // in functional_keys.json the label flag is already defined, let's not override it in case it's removed by the user - if (!params.mId.isAlphaOrSymbolKeyboard && shouldShowTldPopups(params)) Key.LABEL_FLAGS_DISABLE_HINT_LABEL else 0 + if (!params.mId.element.isAlphaOrSymbolLayout && shouldShowTldPopups(params)) Key.LABEL_FLAGS_DISABLE_HINT_LABEL else 0 KeyLabel.ACTION -> { Key.LABEL_FLAGS_PRESERVE_CASE or Key.LABEL_FLAGS_AUTO_X_SCALE or Key.LABEL_FLAGS_FOLLOW_KEY_LABEL_RATIO or Key.LABEL_FLAGS_HAS_POPUP_HINT or KeyboardTheme.getThemeActionAndEmojiKeyLabelFlags(params.mThemeId) } - KeyLabel.SPACE -> if (params.mId.isNumberLayout) Key.LABEL_FLAGS_ALIGN_ICON_TO_BOTTOM else 0 + KeyLabel.SPACE -> if (params.mId.element.isNumberLayout) Key.LABEL_FLAGS_ALIGN_ICON_TO_BOTTOM else 0 KeyLabel.SHIFT -> Key.LABEL_FLAGS_PRESERVE_CASE toolbarKeyStrings[ToolbarKey.EMOJI] -> KeyboardTheme.getThemeActionAndEmojiKeyLabelFlags(params.mThemeId) KeyLabel.COM -> Key.LABEL_FLAGS_AUTO_X_SCALE or Key.LABEL_FLAGS_FONT_NORMAL or Key.LABEL_FLAGS_HAS_POPUP_HINT or Key.LABEL_FLAGS_PRESERVE_CASE @@ -459,7 +457,7 @@ sealed interface KeyData : AbstractKeyData { KeyLabel.PERIOD -> getPeriodPopups(params) KeyLabel.ACTION -> getActionKeyPopupKeys(params) KeyLabel.SHIFT -> { - if (params.mId.isAlphabetKeyboard) SimplePopups( + if (params.mId.element.isAlphabetLayout) SimplePopups( listOf( "!noPanelAutoPopupKey!", " |!code/key_capslock" diff --git a/app/src/main/java/helium314/keyboard/latin/InputAttributes.java b/app/src/main/java/helium314/keyboard/latin/InputAttributes.java index b991fa10a3..408adc0503 100644 --- a/app/src/main/java/helium314/keyboard/latin/InputAttributes.java +++ b/app/src/main/java/helium314/keyboard/latin/InputAttributes.java @@ -27,7 +27,7 @@ * Class to hold attributes of the input field. */ public final class InputAttributes { - private final String TAG = InputAttributes.class.getSimpleName(); + private static final String TAG = InputAttributes.class.getSimpleName(); final public String mTargetApplicationPackageName; final public boolean mInputTypeShouldAutoCorrect; diff --git a/app/src/main/java/helium314/keyboard/latin/LatinIME.java b/app/src/main/java/helium314/keyboard/latin/LatinIME.java index abe84c2371..47cf11b642 100644 --- a/app/src/main/java/helium314/keyboard/latin/LatinIME.java +++ b/app/src/main/java/helium314/keyboard/latin/LatinIME.java @@ -41,6 +41,7 @@ import helium314.keyboard.event.HapticEvent; import helium314.keyboard.keyboard.KeyboardActionListener; import helium314.keyboard.keyboard.KeyboardActionListenerImpl; +import helium314.keyboard.keyboard.KeyboardMode; import helium314.keyboard.keyboard.emoji.EmojiPalettesView; import helium314.keyboard.keyboard.internal.KeyboardIconsSet; import helium314.keyboard.keyboard.internal.keyboard_parser.floris.KeyCode; @@ -1046,8 +1047,9 @@ public void onUpdateSelection(final int oldSelStart, final int oldSelEnd, // we don't want to update a manually set shift state if selection changed towards one side // because this may end the manual shift, which is unwanted in case of shift + arrow keys for changing selection // todo: this is not fully implemented yet, and maybe should be behind a setting - if (mKeyboardSwitcher.getKeyboard() != null && mKeyboardSwitcher.getKeyboard().mId.isAlphabetShiftedManually() - && ((oldSelEnd == newSelEnd && oldSelStart != newSelStart) || (oldSelEnd != newSelEnd && oldSelStart == newSelStart))) + Keyboard keyboard = mKeyboardSwitcher.getKeyboard(); + if (keyboard != null && keyboard.mId.element.isAlphabetShiftedManually() + && (oldSelStart == newSelStart) != (oldSelEnd == newSelEnd)) return; mKeyboardSwitcher.requestUpdatingShiftState(getCurrentAutoCapsState(), getCurrentRecapitalizeState()); } @@ -1704,17 +1706,17 @@ public void debugDumpStateAndCrashWithException(final String context) { } @Override - protected void dump(final FileDescriptor fd, final PrintWriter fout, final String[] args) { + protected void dump(FileDescriptor fd, PrintWriter fout, String[] args) { super.dump(fd, fout, args); - final Printer p = new PrintWriterPrinter(fout); + var p = new PrintWriterPrinter(fout); p.println("LatinIME state :"); p.println(" VersionCode = " + BuildConfig.VERSION_CODE); p.println(" VersionName = " + BuildConfig.VERSION_NAME); - final Keyboard keyboard = mKeyboardSwitcher.getKeyboard(); - final int keyboardMode = keyboard != null ? keyboard.mId.mode : -1; + Keyboard keyboard = mKeyboardSwitcher.getKeyboard(); + KeyboardMode keyboardMode = keyboard != null ? keyboard.mId.mode : null; p.println(" Keyboard mode = " + keyboardMode); - final SettingsValues settingsValues = mSettings.getCurrent(); + SettingsValues settingsValues = mSettings.getCurrent(); p.println(settingsValues.dump()); p.println(mDictionaryFacilitator.dump(this)); } diff --git a/app/src/main/java/helium314/keyboard/latin/Suggest.kt b/app/src/main/java/helium314/keyboard/latin/Suggest.kt index 98cb617466..cc30c79c1a 100644 --- a/app/src/main/java/helium314/keyboard/latin/Suggest.kt +++ b/app/src/main/java/helium314/keyboard/latin/Suggest.kt @@ -77,7 +77,7 @@ class Suggest(private val mDictionaryFacilitator: DictionaryFacilitator) { val trailingSingleQuotesCount = StringUtils.getTrailingSingleQuotesCount(typedWordString) val suggestionsContainer = getTransformedSuggestedWordInfoList(wordComposer, suggestionResults, trailingSingleQuotesCount, mDictionaryFacilitator.mainLocale, keyboard) - val keyboardShiftMode = keyboard.mId.keyboardCapsMode + val keyboardShiftMode = keyboard.mId.element.capsMode() val capitalizedTypedWord = capitalize(typedWordString, keyboardShiftMode == WordComposer.CAPS_MODE_MANUAL_SHIFT_LOCKED, keyboardShiftMode == WordComposer.CAPS_MODE_MANUAL_SHIFTED, mDictionaryFacilitator.mainLocale) @@ -275,7 +275,7 @@ class Suggest(private val mDictionaryFacilitator: DictionaryFacilitator) { val locale = mDictionaryFacilitator.mainLocale val suggestionsContainer = ArrayList(suggestionResults) val suggestionsCount = suggestionsContainer.size - val keyboardShiftMode = keyboard.mId.keyboardCapsMode + val keyboardShiftMode = keyboard.mId.element.capsMode() val shouldMakeSuggestionsOnlyFirstCharCapitalized = wordComposer.wasShiftedNoLock() || keyboardShiftMode == WordComposer.CAPS_MODE_MANUAL_SHIFTED val shouldMakeSuggestionsAllUpperCase = wordComposer.isAllUpperCase @@ -369,7 +369,7 @@ class Suggest(private val mDictionaryFacilitator: DictionaryFacilitator) { wordComposer: WordComposer, results: SuggestionResults, trailingSingleQuotesCount: Int, defaultLocale: Locale, keyboard: Keyboard ): ArrayList { - val keyboardShiftMode = keyboard.mId.keyboardCapsMode + val keyboardShiftMode = keyboard.mId.element.capsMode() val shouldMakeSuggestionsAllUpperCase = wordComposer.isAllUpperCase && !wordComposer.isResumed || keyboardShiftMode == WordComposer.CAPS_MODE_MANUAL_SHIFT_LOCKED val shouldMakeSuggestionsOnlyFirstCharCapitalized = wordComposer.isOrWillBeOnlyFirstCharCapitalized diff --git a/app/src/main/java/helium314/keyboard/latin/dictionary/DictionaryCollection.java b/app/src/main/java/helium314/keyboard/latin/dictionary/DictionaryCollection.java index e746446da1..6c1a393be8 100644 --- a/app/src/main/java/helium314/keyboard/latin/dictionary/DictionaryCollection.java +++ b/app/src/main/java/helium314/keyboard/latin/dictionary/DictionaryCollection.java @@ -22,7 +22,7 @@ * Class for a collection of dictionaries that behave like one dictionary. */ public final class DictionaryCollection extends Dictionary { - private final String TAG = DictionaryCollection.class.getSimpleName(); + private static final String TAG = DictionaryCollection.class.getSimpleName(); private final ArrayList mDictionaries; private final float[] mWeights; diff --git a/app/src/main/java/helium314/keyboard/latin/inputlogic/InputLogic.java b/app/src/main/java/helium314/keyboard/latin/inputlogic/InputLogic.java index 2f72a39b8f..18bc409a15 100644 --- a/app/src/main/java/helium314/keyboard/latin/inputlogic/InputLogic.java +++ b/app/src/main/java/helium314/keyboard/latin/inputlogic/InputLogic.java @@ -679,8 +679,11 @@ private void handleFunctionalEvent(final Event event, final InputTransaction inp inputTransaction.setDidAffectContents(); break; case KeyCode.SHIFT: - if (KeyboardSwitcher.getInstance().getKeyboard() != null && !KeyboardSwitcher.getInstance().getKeyboard().mId.isAlphabetKeyboard()) - break; // recapitalization and follow-up code should only trigger for alphabet shift, see #1256 + { + Keyboard keyboard = KeyboardSwitcher.getInstance().getKeyboard(); + if (keyboard != null && !keyboard.mId.element.isAlphabetLayout()) + break; // recapitalization and follow-up code should only trigger for alphabet shift, see #1256 + } performRecapitalization(inputTransaction.getSettingsValues()); inputTransaction.requireShiftUpdate(InputTransaction.SHIFT_UPDATE_NOW); inputTransaction.setRequiresUpdateSuggestions(); @@ -801,6 +804,8 @@ private void handleFunctionalEvent(final Event event, final InputTransaction inp break; case KeyCode.SEND_INTENT_ONE, KeyCode.SEND_INTENT_TWO, KeyCode.SEND_INTENT_THREE: IntentUtils.handleSendIntentKey(mLatinIME, event.getKeyCode()); + mLatinIME.requestHideSelf(0); + break; case KeyCode.IME_HIDE_UI: mLatinIME.requestHideSelf(0); break; @@ -816,8 +821,8 @@ private void handleFunctionalEvent(final Event event, final InputTransaction inp case KeyCode.EMOJI, KeyCode.TOGGLE_ONE_HANDED_MODE, KeyCode.SWITCH_ONE_HANDED_MODE: break; case KeyCode.CAPS_LOCK: - if (KeyboardSwitcher.getInstance().getKeyboard() == null - || KeyboardSwitcher.getInstance().getKeyboard().mId.isAlphabetKeyboard()) { + Keyboard keyboard = KeyboardSwitcher.getInstance().getKeyboard(); + if (keyboard == null || keyboard.mId.element.isAlphabetLayout()) { inputTransaction.setRequiresUpdateSuggestions(); } break; diff --git a/app/src/main/java/helium314/keyboard/latin/spellcheck/AndroidSpellCheckerService.java b/app/src/main/java/helium314/keyboard/latin/spellcheck/AndroidSpellCheckerService.java index 73d66ad309..1c6dbbb276 100644 --- a/app/src/main/java/helium314/keyboard/latin/spellcheck/AndroidSpellCheckerService.java +++ b/app/src/main/java/helium314/keyboard/latin/spellcheck/AndroidSpellCheckerService.java @@ -17,7 +17,7 @@ import androidx.annotation.NonNull; import helium314.keyboard.keyboard.Keyboard; -import helium314.keyboard.keyboard.KeyboardId; +import helium314.keyboard.keyboard.KeyboardElement; import helium314.keyboard.keyboard.KeyboardLayoutSet; import helium314.keyboard.latin.DictionaryFacilitator; import helium314.keyboard.latin.DictionaryFacilitatorLruCache; @@ -207,7 +207,7 @@ private Keyboard createKeyboardForLocale(final Locale locale) { final String mainLayoutName = SubtypeSettings.INSTANCE.getMatchingMainLayoutNameForLocale(locale); final InputMethodSubtype subtype = SubtypeUtilsAdditional.INSTANCE.createDummyAdditionalSubtype(locale, mainLayoutName); final KeyboardLayoutSet keyboardLayoutSet = createKeyboardSetForSpellChecker(subtype); - return keyboardLayoutSet.getKeyboard(KeyboardId.ELEMENT_ALPHABET); + return keyboardLayoutSet.getKeyboard(KeyboardElement.ALPHABET); } private KeyboardLayoutSet createKeyboardSetForSpellChecker(final InputMethodSubtype subtype) { diff --git a/app/src/main/java/helium314/keyboard/latin/utils/LayoutUtilsCustom.kt b/app/src/main/java/helium314/keyboard/latin/utils/LayoutUtilsCustom.kt index 4f8686442f..27cfe92d33 100644 --- a/app/src/main/java/helium314/keyboard/latin/utils/LayoutUtilsCustom.kt +++ b/app/src/main/java/helium314/keyboard/latin/utils/LayoutUtilsCustom.kt @@ -4,7 +4,7 @@ package helium314.keyboard.latin.utils import android.content.Context import android.widget.Toast import helium314.keyboard.keyboard.Key -import helium314.keyboard.keyboard.KeyboardId +import helium314.keyboard.keyboard.KeyboardElement import helium314.keyboard.keyboard.KeyboardLayoutSet import helium314.keyboard.keyboard.KeyboardSwitcher import helium314.keyboard.keyboard.internal.KeyboardParams @@ -32,7 +32,7 @@ object LayoutUtilsCustom { if (Settings.getValues() == null) Settings.getInstance().loadSettings(context) val params = KeyboardParams() - params.mId = KeyboardLayoutSet.getFakeKeyboardId(KeyboardId.ELEMENT_ALPHABET) + params.mId = KeyboardLayoutSet.getFakeKeyboardId(KeyboardElement.ALPHABET) params.mPopupKeyTypes.add(POPUP_KEYS_LAYOUT) addLocaleKeyTextsToParams(context, params, POPUP_KEYS_NORMAL) try { diff --git a/app/src/main/java/helium314/keyboard/latin/utils/PopupKeysUtils.kt b/app/src/main/java/helium314/keyboard/latin/utils/PopupKeysUtils.kt index ad0f56a61c..b0b3ddb90f 100644 --- a/app/src/main/java/helium314/keyboard/latin/utils/PopupKeysUtils.kt +++ b/app/src/main/java/helium314/keyboard/latin/utils/PopupKeysUtils.kt @@ -26,7 +26,7 @@ fun createPopupKeysArray(popupSet: PopupSet<*>?, params: KeyboardParams, label: // often PopupKeys are empty, so we want to avoid unnecessarily creating sets val popupKeysDelegate = lazy { mutableSetOf() } val popupKeys by popupKeysDelegate - val types = if (params.mId.isAlphabetKeyboard) params.mPopupKeyTypes else allPopupKeyTypes + val types = if (params.mId.element.isAlphabetLayout) params.mPopupKeyTypes else allPopupKeyTypes types.forEach { type -> when (type) { POPUP_KEYS_NUMBER -> popupSet?.numberLabel?.let { popupKeys.add(it) } diff --git a/app/src/main/res/values/attrs.xml b/app/src/main/res/values/attrs.xml index ce545a89ae..e4001688c9 100644 --- a/app/src/main/res/values/attrs.xml +++ b/app/src/main/res/values/attrs.xml @@ -350,38 +350,6 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -391,16 +359,6 @@ - - - - - - - - - diff --git a/app/src/main/res/values/strings-talkback-descriptions.xml b/app/src/main/res/values/strings-talkback-descriptions.xml index 60a4d4fcb4..f6c089fd5c 100644 --- a/app/src/main/res/values/strings-talkback-descriptions.xml +++ b/app/src/main/res/values/strings-talkback-descriptions.xml @@ -76,10 +76,18 @@ More symbols mode Letters mode + + D-pad mode + + Numpad mode + + Numbers mode Phone mode Phone symbols mode + + Clipboard mode Keyboard hidden diff --git a/app/src/test/java/helium314/keyboard/KeyboardParserTest.kt b/app/src/test/java/helium314/keyboard/KeyboardParserTest.kt index 6d6a1fb700..e67da241a7 100644 --- a/app/src/test/java/helium314/keyboard/KeyboardParserTest.kt +++ b/app/src/test/java/helium314/keyboard/KeyboardParserTest.kt @@ -6,6 +6,7 @@ import android.view.inputmethod.InputMethodSubtype import com.android.inputmethod.keyboard.ProximityInfo import helium314.keyboard.keyboard.Key.KeyParams import helium314.keyboard.keyboard.Keyboard +import helium314.keyboard.keyboard.KeyboardElement import helium314.keyboard.keyboard.KeyboardId import helium314.keyboard.keyboard.KeyboardLayoutSet import helium314.keyboard.keyboard.internal.KeySpecParser.KeySpecParserError @@ -51,7 +52,7 @@ class ParserTest { ShadowLog.setupLogging() ShadowLog.stream = System.out params = KeyboardParams() - params.mId = KeyboardLayoutSet.getFakeKeyboardId(KeyboardId.ELEMENT_ALPHABET) + params.mId = KeyboardLayoutSet.getFakeKeyboardId(KeyboardElement.ALPHABET) params.mPopupKeyTypes.add(POPUP_KEYS_LAYOUT) addLocaleKeyTextsToParams(latinIME, params, POPUP_KEYS_NORMAL) } @@ -430,25 +431,25 @@ f""", // no newline at the end @Test fun canLoadKeyboard() { val editorInfo = EditorInfo() val subtype = SubtypeUtilsAdditional.createEmojiCapableAdditionalSubtype(Locale.ENGLISH, "qwerty", true) - val (kb, keys) = buildKeyboard(editorInfo, subtype, KeyboardId.ELEMENT_ALPHABET) + val (kb, keys) = buildKeyboard(editorInfo, subtype, KeyboardElement.ALPHABET) assertEquals(kb.sortedKeys.size, keys.sumOf { it.size }) } @Test fun `dvorak has 4 rows`() { val editorInfo = EditorInfo() val subtype = SubtypeUtilsAdditional.createEmojiCapableAdditionalSubtype(Locale.ENGLISH, "dvorak", true) - val (_, keys) = buildKeyboard(editorInfo, subtype, KeyboardId.ELEMENT_ALPHABET) + val (_, keys) = buildKeyboard(editorInfo, subtype, KeyboardElement.ALPHABET) assertEquals(keys.size, 4) } @Test fun `de_DE has extra keys`() { val editorInfo = EditorInfo() val subtype = SubtypeUtilsAdditional.createEmojiCapableAdditionalSubtype(Locale.GERMANY, "qwertz+", true) - val (_, keys) = buildKeyboard(editorInfo, subtype, KeyboardId.ELEMENT_ALPHABET) + val (_, keys) = buildKeyboard(editorInfo, subtype, KeyboardElement.ALPHABET) assertEquals(11, keys[0].size) assertEquals(11, keys[1].size) assertEquals(10, keys[2].size) - val (_, keys2) = buildKeyboard(editorInfo, subtype, KeyboardId.ELEMENT_ALPHABET_AUTOMATIC_SHIFTED) + val (_, keys2) = buildKeyboard(editorInfo, subtype, KeyboardElement.ALPHABET_AUTOMATIC_SHIFTED) assertEquals(11, keys2[0].size) assertEquals(11, keys2[1].size) assertEquals(10, keys2[2].size) @@ -457,8 +458,8 @@ f""", // no newline at the end @Test fun `popup key count does not depend on shift for (for simple layout)`() { val editorInfo = EditorInfo() val subtype = SubtypeUtilsAdditional.createEmojiCapableAdditionalSubtype(Locale.ENGLISH, "qwerty", true) - val (kb, keys) = buildKeyboard(editorInfo, subtype, KeyboardId.ELEMENT_ALPHABET) - val (kb2, keys2) = buildKeyboard(editorInfo, subtype, KeyboardId.ELEMENT_ALPHABET_AUTOMATIC_SHIFTED) + val (kb, keys) = buildKeyboard(editorInfo, subtype, KeyboardElement.ALPHABET) + val (kb2, keys2) = buildKeyboard(editorInfo, subtype, KeyboardElement.ALPHABET_AUTOMATIC_SHIFTED) assertEquals(kb.sortedKeys.size, kb2.sortedKeys.size) keys.forEachIndexed { i, kpList -> kpList.forEachIndexed { j, kp -> assertEquals(kp.mPopupKeys?.size, keys2[i][j].mPopupKeys?.size) @@ -532,7 +533,7 @@ f""", // no newline at the end } } - private fun buildKeyboard(editorInfo: EditorInfo, subtype: InputMethodSubtype, elementId: Int): Pair>> { + private fun buildKeyboard(editorInfo: EditorInfo, subtype: InputMethodSubtype, element: KeyboardElement): Pair>> { val layoutParams = KeyboardLayoutSet.Params() val editorInfoField = KeyboardLayoutSet.Params::class.java.getDeclaredField("mEditorInfo").apply { isAccessible = true } editorInfoField.set(layoutParams, editorInfo) @@ -545,7 +546,7 @@ f""", // no newline at the end val keysInRowsField = KeyboardBuilder::class.java.getDeclaredField("keysInRows").apply { isAccessible = true } - val id = KeyboardId(elementId, layoutParams) + val id = KeyboardId(element, layoutParams) val builder = KeyboardBuilder(latinIME, KeyboardParams(UniqueKeysCache.NO_CACHE)) builder.load(id) @Suppress("UNCHECKED_CAST") diff --git a/app/src/test/java/helium314/keyboard/SubtypeTest.kt b/app/src/test/java/helium314/keyboard/SubtypeTest.kt index a101c07d98..f9aca48ad2 100644 --- a/app/src/test/java/helium314/keyboard/SubtypeTest.kt +++ b/app/src/test/java/helium314/keyboard/SubtypeTest.kt @@ -1,6 +1,6 @@ package helium314.keyboard -import helium314.keyboard.keyboard.KeyboardId +import helium314.keyboard.keyboard.KeyboardElement import helium314.keyboard.keyboard.KeyboardLayoutSet import helium314.keyboard.keyboard.internal.KeyboardParams import helium314.keyboard.keyboard.internal.keyboard_parser.POPUP_KEYS_NORMAL @@ -37,7 +37,7 @@ class SubtypeTest { ShadowLog.setupLogging() ShadowLog.stream = System.out params = KeyboardParams() - params.mId = KeyboardLayoutSet.getFakeKeyboardId(KeyboardId.ELEMENT_ALPHABET) + params.mId = KeyboardLayoutSet.getFakeKeyboardId(KeyboardElement.ALPHABET) params.mPopupKeyTypes.add(POPUP_KEYS_LAYOUT) addLocaleKeyTextsToParams(latinIME, params, POPUP_KEYS_NORMAL) } From 61cc7672b1e2d3f464925dc4227154b3df49a1dd Mon Sep 17 00:00:00 2001 From: devycarol <[email protected]> Date: Mon, 12 Jan 2026 18:21:37 -0700 Subject: [PATCH 6/7] pointless final --- .../keyboard/emoji/EmojiCategory.java | 76 ++++++++++--------- 1 file changed, 39 insertions(+), 37 deletions(-) diff --git a/app/src/main/java/helium314/keyboard/keyboard/emoji/EmojiCategory.java b/app/src/main/java/helium314/keyboard/keyboard/emoji/EmojiCategory.java index fb074af593..fc6dddf16d 100644 --- a/app/src/main/java/helium314/keyboard/keyboard/emoji/EmojiCategory.java +++ b/app/src/main/java/helium314/keyboard/keyboard/emoji/EmojiCategory.java @@ -54,9 +54,11 @@ final class EmojiCategory { final class CategoryProperties { public final int mCategoryId; private int mPageCount = -1; - public CategoryProperties(final int categoryId) { + + CategoryProperties(int categoryId) { mCategoryId = categoryId; } + public int getPageCount() { if (mPageCount < 0) mPageCount = computeCategoryPageCount(mCategoryId); @@ -116,7 +118,7 @@ public int getPageCount() { private int mCurrentCategoryId = ID_UNSPECIFIED; private int mCurrentCategoryPageId = 0; - EmojiCategory(final Context ctx, final KeyboardLayoutSet layoutSet, final TypedArray emojiPaletteViewAttr) { + EmojiCategory(Context ctx, KeyboardLayoutSet layoutSet, TypedArray emojiPaletteViewAttr) { mPrefs = KtxKt.prefs(ctx); mRes = ctx.getResources(); mContext = ctx; @@ -165,14 +167,14 @@ public void clearKeyboardCache() { props.mPageCount = -1; // reset page count in case size (number of keys per row) changed } - private void addShownCategoryId(final int categoryId) { + private void addShownCategoryId(int categoryId) { // Load a keyboard of categoryId - final CategoryProperties properties = new CategoryProperties(categoryId); + var properties = new CategoryProperties(categoryId); mShownCategories.add(properties); } - private boolean isShownCategoryId(final int categoryId) { - for (final CategoryProperties prop : mShownCategories) { + private boolean isShownCategoryId(int categoryId) { + for (CategoryProperties prop : mShownCategories) { if (prop.mCategoryId == categoryId) { return true; } @@ -180,20 +182,20 @@ private boolean isShownCategoryId(final int categoryId) { return false; } - public static String getCategoryName(final int categoryId, final int categoryPageId) { + public static String getCategoryName(int categoryId, int categoryPageId) { return sCategoryName[categoryId] + "-" + categoryPageId; } - public int getCategoryId(final String name) { - final String[] strings = name.split("-"); + public int getCategoryId(String name) { + String[] strings = name.split("-"); return mCategoryNameToIdMap.get(strings[0]); } - public int getCategoryTabIcon(final int categoryId) { + public int getCategoryTabIcon(int categoryId) { return mCategoryTabIconId[categoryId]; } - public String getAccessibilityDescription(final int categoryId) { + public String getAccessibilityDescription(int categoryId) { return mRes.getString(sCategoryElement[categoryId].contentDescription); } @@ -209,8 +211,8 @@ public int getCurrentCategoryPageCount() { return getCategoryPageCount(mCurrentCategoryId); } - public int getCategoryPageCount(final int categoryId) { - for (final CategoryProperties prop : mShownCategories) { + public int getCategoryPageCount(int categoryId) { + for (CategoryProperties prop : mShownCategories) { if (prop.mCategoryId == categoryId) { return prop.getPageCount(); } @@ -220,12 +222,12 @@ public int getCategoryPageCount(final int categoryId) { return 0; } - public void setCurrentCategoryId(final int categoryId) { + public void setCurrentCategoryId(int categoryId) { mCurrentCategoryId = categoryId; mPrefs.edit().putInt(Settings.PREF_LAST_SHOWN_EMOJI_CATEGORY_ID, categoryId).apply(); } - public void setCurrentCategoryPageId(final int id) { + public void setCurrentCategoryPageId(int id) { mCurrentCategoryPageId = id; mPrefs.edit().putInt(Settings.PREF_LAST_SHOWN_EMOJI_CATEGORY_PAGE_ID, id).apply(); } @@ -238,7 +240,7 @@ public boolean isInRecentTab() { return mCurrentCategoryId == ID_RECENTS; } - public int getTabIdFromCategoryId(final int categoryId) { + public int getTabIdFromCategoryId(int categoryId) { for (int i = 0; i < mShownCategories.size(); ++i) { if (mShownCategories.get(i).mCategoryId == categoryId) { return i; @@ -252,13 +254,13 @@ public int getRecentTabId() { return getTabIdFromCategoryId(ID_RECENTS); } - private int computeCategoryPageCount(final int categoryId) { - final Keyboard keyboard = mLayoutSet.getKeyboard(sCategoryElement[categoryId]); + private int computeCategoryPageCount(int categoryId) { + Keyboard keyboard = mLayoutSet.getKeyboard(sCategoryElement[categoryId]); return (keyboard.getSortedKeys().size() - 1) / computeMaxKeyCountPerPage() + 1; } // Returns a keyboard from the recycler view's adapter position. - public DynamicGridKeyboard getKeyboardFromAdapterPosition(int categoryId, final int position) { + public DynamicGridKeyboard getKeyboardFromAdapterPosition(int categoryId, int position) { if (position >= 0 && position < getCategoryPageCount(categoryId)) { return getKeyboard(categoryId, position); } @@ -266,20 +268,20 @@ public DynamicGridKeyboard getKeyboardFromAdapterPosition(int categoryId, final return null; } - private static Long getCategoryKeyboardMapKey(final int categoryId, final int id) { + private static Long getCategoryKeyboardMapKey(int categoryId, int id) { return (((long) categoryId) << Integer.SIZE) | id; } - public DynamicGridKeyboard getKeyboard(final int categoryId, final int id) { + public DynamicGridKeyboard getKeyboard(int categoryId, int id) { synchronized (mCategoryKeyboardMap) { - final Long categoryKeyboardMapKey = getCategoryKeyboardMapKey(categoryId, id); + Long categoryKeyboardMapKey = getCategoryKeyboardMapKey(categoryId, id); if (mCategoryKeyboardMap.containsKey(categoryKeyboardMapKey)) { return mCategoryKeyboardMap.get(categoryKeyboardMapKey); } - final int currentWidth = ResourceUtils.getKeyboardWidth(mContext, Settings.getValues()); + int currentWidth = ResourceUtils.getKeyboardWidth(mContext, Settings.getValues()); if (categoryId == ID_RECENTS) { - final DynamicGridKeyboard kbd = new DynamicGridKeyboard(mPrefs, + var kbd = new DynamicGridKeyboard(mPrefs, mLayoutSet.getKeyboard(KeyboardElement.EMOJI_RECENTS), mMaxRecentsKeyCount, categoryId, currentWidth); mCategoryKeyboardMap.put(categoryKeyboardMapKey, kbd); @@ -287,15 +289,15 @@ public DynamicGridKeyboard getKeyboard(final int categoryId, final int id) { return kbd; } - final Keyboard keyboard = mLayoutSet.getKeyboard(sCategoryElement[categoryId]); - final int keyCountPerPage = computeMaxKeyCountPerPage(); - final Key[][] sortedKeysPages = sortKeysGrouped( + Keyboard keyboard = mLayoutSet.getKeyboard(sCategoryElement[categoryId]); + int keyCountPerPage = computeMaxKeyCountPerPage(); + Key[][] sortedKeysPages = sortKeysGrouped( keyboard.getSortedKeys(), keyCountPerPage); for (int pageId = 0; pageId < sortedKeysPages.length; ++pageId) { - final DynamicGridKeyboard tempKeyboard = new DynamicGridKeyboard(mPrefs, + var tempKeyboard = new DynamicGridKeyboard(mPrefs, mLayoutSet.getKeyboard(KeyboardElement.EMOJI_RECENTS), keyCountPerPage, categoryId, currentWidth); - for (final Key emojiKey : sortedKeysPages[pageId]) { + for (Key emojiKey : sortedKeysPages[pageId]) { if (emojiKey == null) { break; } @@ -308,15 +310,15 @@ public DynamicGridKeyboard getKeyboard(final int categoryId, final int id) { } private int computeMaxKeyCountPerPage() { - final DynamicGridKeyboard tempKeyboard = new DynamicGridKeyboard(mPrefs, + var tempKeyboard = new DynamicGridKeyboard(mPrefs, mLayoutSet.getKeyboard(KeyboardElement.EMOJI_RECENTS), 0, 0, ResourceUtils.getKeyboardWidth(mContext, Settings.getValues())); return MAX_LINE_COUNT_PER_PAGE * tempKeyboard.getOccupiedColumnCount(); } private static final Comparator EMOJI_KEY_COMPARATOR = (lhs, rhs) -> { - final Rect lHitBox = lhs.getHitBox(); - final Rect rHitBox = rhs.getHitBox(); + Rect lHitBox = lhs.getHitBox(); + Rect rHitBox = rhs.getHitBox(); if (lHitBox.top < rHitBox.top) { return -1; } else if (lHitBox.top > rHitBox.top) { @@ -333,11 +335,11 @@ private int computeMaxKeyCountPerPage() { return lhs.getCode() < rhs.getCode() ? -1 : 1; }; - private static Key[][] sortKeysGrouped(final List inKeys, final int maxPageCount) { - final ArrayList keys = new ArrayList<>(inKeys); + private static Key[][] sortKeysGrouped(List inKeys, int maxPageCount) { + var keys = new ArrayList(inKeys); Collections.sort(keys, EMOJI_KEY_COMPARATOR); - final int pageCount = (keys.size() - 1) / maxPageCount + 1; - final Key[][] retval = new Key[pageCount][maxPageCount]; + int pageCount = (keys.size() - 1) / maxPageCount + 1; + var retval = new Key[pageCount][maxPageCount]; for (int i = 0; i < keys.size(); ++i) { retval[i / maxPageCount][i % maxPageCount] = keys.get(i); } @@ -345,7 +347,7 @@ private static Key[][] sortKeysGrouped(final List inKeys, final int maxPage } private static boolean canShowFlagEmoji() { - Paint paint = new Paint(); + var paint = new Paint(); String switzerland = "\uD83C\uDDE8\uD83C\uDDED"; // U+1F1E8 U+1F1ED Flag for Switzerland return PaintCompat.hasGlyph(paint, switzerland); } From ef9e4c1ea692f6b755dc5d26e026d711eac134ac Mon Sep 17 00:00:00 2001 From: devycarol <[email protected]> Date: Tue, 13 Jan 2026 14:50:23 -0700 Subject: [PATCH 7/7] extract KeyboardState enums --- .../keyboard/internal/KeyboardState.kt | 99 ++++++++----------- .../keyboard/internal/LayoutMode.java | 10 ++ .../keyboard/keyboard/internal/ShiftMode.java | 8 ++ 3 files changed, 60 insertions(+), 57 deletions(-) create mode 100644 app/src/main/java/helium314/keyboard/keyboard/internal/LayoutMode.java create mode 100644 app/src/main/java/helium314/keyboard/keyboard/internal/ShiftMode.java diff --git a/app/src/main/java/helium314/keyboard/keyboard/internal/KeyboardState.kt b/app/src/main/java/helium314/keyboard/keyboard/internal/KeyboardState.kt index 357ad1d50b..290da468a4 100644 --- a/app/src/main/java/helium314/keyboard/keyboard/internal/KeyboardState.kt +++ b/app/src/main/java/helium314/keyboard/keyboard/internal/KeyboardState.kt @@ -62,8 +62,8 @@ class KeyboardState(private val switchActions: SwitchActions) { private var switchState = SwitchState.ALPHA - private var mode = Mode.ALPHABET - private var modeBeforeNumpad = Mode.ALPHABET + private var mode = LayoutMode.ALPHABET + private var modeBeforeNumpad = LayoutMode.ALPHABET private var isSymbolShifted = false private var prevMainKeyboardWasShiftLocked = false private var prevSymbolsKeyboardWasShifted = false @@ -78,14 +78,14 @@ class KeyboardState(private val switchActions: SwitchActions) { private class SavedKeyboardState { var isValid = false var isAlphabetShiftLocked = false - var mode = Mode.ALPHABET + var mode = LayoutMode.ALPHABET var shiftMode = ShiftMode.UNSHIFT override fun toString(): String { if (!isValid) return "INVALID" return when (mode) { - Mode.ALPHABET -> "${mode}_${if (isAlphabetShiftLocked) ShiftMode.SHIFT_LOCKED else shiftMode}" - Mode.SYMBOLS -> "${mode}_$shiftMode" + LayoutMode.ALPHABET -> "${mode}_${if (isAlphabetShiftLocked) ShiftMode.SHIFT_LOCKED else shiftMode}" + LayoutMode.SYMBOLS -> "${mode}_$shiftMode" else -> mode.toString() } } @@ -113,7 +113,7 @@ class KeyboardState(private val switchActions: SwitchActions) { fun onSaveKeyboardState() { savedKeyboardState.mode = mode - if (mode == Mode.ALPHABET) { + if (mode == LayoutMode.ALPHABET) { savedKeyboardState.isAlphabetShiftLocked = alphabetShiftState.isShiftLocked savedKeyboardState.shiftMode = when { alphabetShiftState.isAutomaticShifted -> ShiftMode.AUTOMATIC @@ -136,23 +136,23 @@ class KeyboardState(private val switchActions: SwitchActions) { } prevMainKeyboardWasShiftLocked = savedKeyboardState.isAlphabetShiftLocked when (savedKeyboardState.mode) { - Mode.ALPHABET -> { + LayoutMode.ALPHABET -> { setAlphabetKeyboard(autoCapsFlags, recapitalizeMode) setShiftLocked(savedKeyboardState.isAlphabetShiftLocked) if (!savedKeyboardState.isAlphabetShiftLocked) { setShifted(savedKeyboardState.shiftMode) } } - Mode.SYMBOLS -> if (savedKeyboardState.shiftMode == ShiftMode.MANUAL) setSymbolsShiftedKeyboard() else setSymbolsKeyboard() - Mode.EMOJI -> setEmojiKeyboard() - Mode.CLIPBOARD -> setClipboardKeyboard() + LayoutMode.SYMBOLS -> if (savedKeyboardState.shiftMode == ShiftMode.MANUAL) setSymbolsShiftedKeyboard() else setSymbolsKeyboard() + LayoutMode.EMOJI -> setEmojiKeyboard() + LayoutMode.CLIPBOARD -> setClipboardKeyboard() // don't overwrite toggle state if reloading from orientation change, etc. - Mode.NUMPAD -> setNumpadKeyboard(false, false, false) + LayoutMode.NUMPAD -> setNumpadKeyboard(false, false, false) } } private fun setShifted(shiftMode: ShiftMode) { - if (mode != Mode.ALPHABET) return + if (mode != LayoutMode.ALPHABET) return val prevShiftMode = when { alphabetShiftState.isAutomaticShifted -> ShiftMode.AUTOMATIC alphabetShiftState.isManualShifted -> ShiftMode.MANUAL @@ -188,7 +188,7 @@ class KeyboardState(private val switchActions: SwitchActions) { if (DebugFlags.DEBUG_ENABLED) { Log.d(TAG, "setShiftLocked: shiftLocked=$shiftLocked $this") } - if (mode != Mode.ALPHABET) return + if (mode != LayoutMode.ALPHABET) return if (shiftLocked && (!alphabetShiftState.isShiftLocked || alphabetShiftState.isShiftLockShifted)) { switchActions.setAlphabetShiftLockedKeyboard() } @@ -202,7 +202,7 @@ class KeyboardState(private val switchActions: SwitchActions) { if (DebugFlags.DEBUG_ENABLED) { Log.d(TAG, "toggleAlphabetAndSymbols: ${stateToString(autoCapsFlags, recapitalizeMode)}") } - if (mode == Mode.ALPHABET) { + if (mode == LayoutMode.ALPHABET) { prevMainKeyboardWasShiftLocked = alphabetShiftState.isShiftLocked if (prevSymbolsKeyboardWasShifted) setSymbolsShiftedKeyboard() else setSymbolsKeyboard() prevSymbolsKeyboardWasShifted = false @@ -220,7 +220,7 @@ class KeyboardState(private val switchActions: SwitchActions) { if (DebugFlags.DEBUG_ENABLED) { Log.d(TAG, "resetKeyboardStateToAlphabet: ${stateToString(autoCapsFlags, recapitalizeMode)}") } - if (mode == Mode.ALPHABET) return + if (mode == LayoutMode.ALPHABET) return prevSymbolsKeyboardWasShifted = isSymbolShifted setAlphabetKeyboard(autoCapsFlags, recapitalizeMode) @@ -244,7 +244,7 @@ class KeyboardState(private val switchActions: SwitchActions) { } switchActions.setAlphabetKeyboard() - mode = Mode.ALPHABET + mode = LayoutMode.ALPHABET isSymbolShifted = false this.recapitalizeMode = null switchState = SwitchState.ALPHA @@ -256,7 +256,7 @@ class KeyboardState(private val switchActions: SwitchActions) { Log.d(TAG, "setSymbolsKeyboard") } switchActions.setSymbolsKeyboard() - mode = Mode.SYMBOLS + mode = LayoutMode.SYMBOLS isSymbolShifted = false recapitalizeMode = null // Reset alphabet shift state. @@ -269,7 +269,7 @@ class KeyboardState(private val switchActions: SwitchActions) { Log.d(TAG, "setSymbolsShiftedKeyboard") } switchActions.setSymbolsShiftedKeyboard() - mode = Mode.SYMBOLS + mode = LayoutMode.SYMBOLS isSymbolShifted = true recapitalizeMode = null // Reset alphabet shift state. @@ -281,7 +281,7 @@ class KeyboardState(private val switchActions: SwitchActions) { if (DebugFlags.DEBUG_ENABLED) { Log.d(TAG, "setEmojiKeyboard") } - mode = Mode.EMOJI + mode = LayoutMode.EMOJI recapitalizeMode = null // Remember caps lock mode and reset alphabet shift state. prevMainKeyboardWasShiftLocked = alphabetShiftState.isShiftLocked @@ -293,7 +293,7 @@ class KeyboardState(private val switchActions: SwitchActions) { if (DebugFlags.DEBUG_ENABLED) { Log.d(TAG, "setClipboardKeyboard") } - mode = Mode.CLIPBOARD + mode = LayoutMode.CLIPBOARD recapitalizeMode = null // Remember caps lock mode and reset alphabet shift state. prevMainKeyboardWasShiftLocked = alphabetShiftState.isShiftLocked @@ -306,18 +306,18 @@ class KeyboardState(private val switchActions: SwitchActions) { Log.d(TAG, "setNumpadKeyboard") } if (rememberState) { - if (mode == Mode.ALPHABET) { + if (mode == LayoutMode.ALPHABET) { // Remember caps lock mode and reset alphabet shift state. prevMainKeyboardWasShiftLocked = alphabetShiftState.isShiftLocked alphabetShiftState.setShiftLocked(false) - } else if (mode == Mode.SYMBOLS) { + } else if (mode == LayoutMode.SYMBOLS) { // Remember symbols shifted state prevSymbolsKeyboardWasShifted = isSymbolShifted } // When d-pad is added, "selection mode" may need to be remembered if not a global state - modeBeforeNumpad = if (forceReturnToAlpha) Mode.ALPHABET else mode + modeBeforeNumpad = if (forceReturnToAlpha) LayoutMode.ALPHABET else mode } - mode = Mode.NUMPAD + mode = LayoutMode.NUMPAD recapitalizeMode = null switchActions.setNumpadKeyboard() switchState = if (withSliding) SwitchState.MOMENTARY_TO_NUMPAD else SwitchState.NUMPAD_BEGIN @@ -333,25 +333,25 @@ class KeyboardState(private val switchActions: SwitchActions) { if (DebugFlags.DEBUG_ENABLED) { Log.d(TAG, "toggleNumpad") } - if (mode != Mode.NUMPAD) { + if (mode != LayoutMode.NUMPAD) { setNumpadKeyboard(withSliding, forceReturnToAlpha, rememberState) return } - if (modeBeforeNumpad == Mode.ALPHABET || forceReturnToAlpha) { + if (modeBeforeNumpad == LayoutMode.ALPHABET || forceReturnToAlpha) { setAlphabetKeyboard(autoCapsFlags, recapitalizeMode) if (prevMainKeyboardWasShiftLocked) { setShiftLocked(true) } prevMainKeyboardWasShiftLocked = false } else when (modeBeforeNumpad) { - Mode.ALPHABET -> {} - Mode.SYMBOLS -> { + LayoutMode.ALPHABET -> {} + LayoutMode.SYMBOLS -> { if (prevSymbolsKeyboardWasShifted) setSymbolsShiftedKeyboard() else setSymbolsKeyboard() prevSymbolsKeyboardWasShifted = false } - Mode.EMOJI -> setEmojiKeyboard() - Mode.CLIPBOARD -> setClipboardKeyboard() - Mode.NUMPAD -> {} + LayoutMode.EMOJI -> setEmojiKeyboard() + LayoutMode.CLIPBOARD -> setClipboardKeyboard() + LayoutMode.NUMPAD -> {} } if (withSliding) switchState = SwitchState.MOMENTARY_FROM_NUMPAD } @@ -396,7 +396,7 @@ class KeyboardState(private val switchActions: SwitchActions) { // off because, for example, we may be in the #1 state within the manual temporary // shifted mode. if (!isSinglePointer - && mode == Mode.ALPHABET + && mode == LayoutMode.ALPHABET && autoCapsFlags != TextUtils.CAP_MODE_CHARACTERS && (alphabetShiftState.isAutomaticShifted || (alphabetShiftState.isManualShifted && shiftKeyState.isReleasing)) ) { @@ -419,7 +419,7 @@ class KeyboardState(private val switchActions: SwitchActions) { KeyCode.NUMPAD -> { // if no sliding, toggling is instead handled by onEvent to accommodate toolbar key. // also prevent sliding to clipboard layout, which isn't supported yet. - if (withSliding) setNumpadKeyboard(true, modeBeforeNumpad == Mode.CLIPBOARD, true) + if (withSliding) setNumpadKeyboard(true, modeBeforeNumpad == LayoutMode.CLIPBOARD, true) } } } @@ -447,13 +447,13 @@ class KeyboardState(private val switchActions: SwitchActions) { private fun onReleaseSymbol(withSliding: Boolean, autoCapsFlags: Int, recapitalizeMode: RecapitalizeMode?) { val oldMode = mode setSymbolsKeyboard() - if (withSliding && oldMode == Mode.NUMPAD) switchState = SwitchState.MOMENTARY_FROM_NUMPAD + if (withSliding && oldMode == LayoutMode.NUMPAD) switchState = SwitchState.MOMENTARY_FROM_NUMPAD } private fun onReleaseAlpha(withSliding: Boolean, autoCapsFlags: Int, recapitalizeMode: RecapitalizeMode?) { val oldMode = mode setAlphabetKeyboard(autoCapsFlags, recapitalizeMode) - if (withSliding && oldMode == Mode.NUMPAD) switchState = SwitchState.MOMENTARY_FROM_NUMPAD + if (withSliding && oldMode == LayoutMode.NUMPAD) switchState = SwitchState.MOMENTARY_FROM_NUMPAD } fun onUpdateShiftState(autoCapsFlags: Int, recapitalizeMode: RecapitalizeMode?) { @@ -485,7 +485,7 @@ class KeyboardState(private val switchActions: SwitchActions) { } private fun updateAlphabetShiftState(autoCapsFlags: Int, recapitalizeMode: RecapitalizeMode?) { - if (mode != Mode.ALPHABET) return + if (mode != LayoutMode.ALPHABET) return if (recapitalizeMode != null) { // We are recapitalizing. Match the keyboard to the current recapitalize state. updateShiftStateForRecapitalize(recapitalizeMode) @@ -507,7 +507,7 @@ class KeyboardState(private val switchActions: SwitchActions) { if (recapitalizeMode != null) { return } - if (mode != Mode.ALPHABET) { + if (mode != LayoutMode.ALPHABET) { // In symbol mode, just toggle symbol and symbol popup keyboard. toggleShiftInSymbols() switchState = SwitchState.MOMENTARY_SYMBOL_AND_MORE @@ -549,7 +549,7 @@ class KeyboardState(private val switchActions: SwitchActions) { if (this.recapitalizeMode != null) { // We are recapitalizing. We should match the keyboard state to the recapitalize state in priority. updateShiftStateForRecapitalize(this.recapitalizeMode) - } else if (mode != Mode.ALPHABET) { + } else if (mode != LayoutMode.ALPHABET) { // In symbol mode, switch back to the previous keyboard mode if the user chords the // shift key and another key, then releases the shift key. if (shiftKeyState.isChording) { @@ -595,7 +595,7 @@ class KeyboardState(private val switchActions: SwitchActions) { Log.d(TAG, "onFinishSlidingInput: " + stateToString(autoCapsFlags, recapitalizeMode)) } // Switch back to the previous keyboard mode if the user didn't enter the numpad. - if (mode != Mode.NUMPAD) when (switchState) { + if (mode != LayoutMode.NUMPAD) when (switchState) { SwitchState.MOMENTARY_ALPHA_AND_SYMBOL -> toggleAlphabetAndSymbols(autoCapsFlags, recapitalizeMode) SwitchState.MOMENTARY_SYMBOL_AND_MORE -> toggleShiftInSymbols() SwitchState.MOMENTARY_ALPHA_SHIFT -> setAlphabetKeyboard(autoCapsFlags, recapitalizeMode) @@ -621,7 +621,7 @@ class KeyboardState(private val switchActions: SwitchActions) { prevSymbolsKeyboardWasShifted = false } SwitchState.SYMBOL_BEGIN -> - if (mode == Mode.EMOJI || mode == Mode.CLIPBOARD) { + if (mode == LayoutMode.EMOJI || mode == LayoutMode.CLIPBOARD) { // When in the Emoji keyboard or clipboard one, we don't want to switch back to the main layout even // after the user hits an emoji letter followed by an enter or a space. } else if (!isSpaceOrEnter(code) && (Constants.isLetterCode(code) || code == KeyCode.MULTIPLE_CODE_POINTS)) { @@ -640,7 +640,7 @@ class KeyboardState(private val switchActions: SwitchActions) { SwitchState.MOMENTARY_ALPHA_AND_SYMBOL -> if (code == KeyCode.SYMBOL_ALPHA) { // Detected only the mode change key has been pressed, and then released. - switchState = if (mode == Mode.ALPHABET) SwitchState.ALPHA else SwitchState.SYMBOL_BEGIN + switchState = if (mode == LayoutMode.ALPHABET) SwitchState.ALPHA else SwitchState.SYMBOL_BEGIN } SwitchState.MOMENTARY_SYMBOL_AND_MORE -> if (code == KeyCode.SHIFT) { @@ -671,7 +671,7 @@ class KeyboardState(private val switchActions: SwitchActions) { override fun toString(): String { val keyboard = when { - mode == Mode.ALPHABET -> alphabetShiftState.toString() + mode == LayoutMode.ALPHABET -> alphabetShiftState.toString() isSymbolShifted -> "SYMBOLS_SHIFTED" else -> "SYMBOLS" } @@ -694,21 +694,6 @@ class KeyboardState(private val switchActions: SwitchActions) { MOMENTARY_FROM_NUMPAD, } - private enum class Mode { - ALPHABET, - SYMBOLS, - EMOJI, - CLIPBOARD, - NUMPAD, - } - - private enum class ShiftMode { - UNSHIFT, - MANUAL, - AUTOMATIC, - SHIFT_LOCKED, - } - companion object { private val TAG = KeyboardState::class.java.simpleName private const val DEBUG_EVENT = false diff --git a/app/src/main/java/helium314/keyboard/keyboard/internal/LayoutMode.java b/app/src/main/java/helium314/keyboard/keyboard/internal/LayoutMode.java new file mode 100644 index 0000000000..25094b251a --- /dev/null +++ b/app/src/main/java/helium314/keyboard/keyboard/internal/LayoutMode.java @@ -0,0 +1,10 @@ +package helium314.keyboard.keyboard.internal; + +enum LayoutMode { + ALPHABET, + SYMBOLS, +// MORE_SYMBOLS, + EMOJI, + CLIPBOARD, + NUMPAD, +} diff --git a/app/src/main/java/helium314/keyboard/keyboard/internal/ShiftMode.java b/app/src/main/java/helium314/keyboard/keyboard/internal/ShiftMode.java new file mode 100644 index 0000000000..359394ced8 --- /dev/null +++ b/app/src/main/java/helium314/keyboard/keyboard/internal/ShiftMode.java @@ -0,0 +1,8 @@ +package helium314.keyboard.keyboard.internal; + +enum ShiftMode { + UNSHIFT, + MANUAL, + AUTOMATIC, + SHIFT_LOCKED, +}