From 8a2ccddddeadd71ee4a5c7dda1e5a791954a778a Mon Sep 17 00:00:00 2001 From: devycarol Date: Fri, 5 Jul 2024 18:14:05 -0600 Subject: [PATCH 01/14] make the numpad key toggle-based, allowing for use in its own layout. it also remembers the symbols-shift state. --- .../keyboard/keyboard/KeyboardSwitcher.java | 8 ++++ .../keyboard/internal/KeyboardState.java | 39 +++++++++++++++++-- 2 files changed, 43 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/helium314/keyboard/keyboard/KeyboardSwitcher.java b/app/src/main/java/helium314/keyboard/keyboard/KeyboardSwitcher.java index aa334334a..7434d2030 100644 --- a/app/src/main/java/helium314/keyboard/keyboard/KeyboardSwitcher.java +++ b/app/src/main/java/helium314/keyboard/keyboard/KeyboardSwitcher.java @@ -352,6 +352,14 @@ public void setNumpadKeyboard() { setKeyboard(KeyboardId.ELEMENT_NUMPAD, KeyboardSwitchState.OTHER); } + @Override + public void toggleNumpad(final int autoCapsFlags, final int recapitalizeMode) { + if (DEBUG_ACTION) { + Log.d(TAG, "toggleNumpad"); + } + mState.toggleNumpad(autoCapsFlags, recapitalizeMode); + } + public enum KeyboardSwitchState { HIDDEN(-1), SYMBOLS_SHIFTED(KeyboardId.ELEMENT_SYMBOLS_SHIFTED), diff --git a/app/src/main/java/helium314/keyboard/keyboard/internal/KeyboardState.java b/app/src/main/java/helium314/keyboard/keyboard/internal/KeyboardState.java index b74b809c0..fe409cbd9 100644 --- a/app/src/main/java/helium314/keyboard/keyboard/internal/KeyboardState.java +++ b/app/src/main/java/helium314/keyboard/keyboard/internal/KeyboardState.java @@ -47,6 +47,7 @@ public interface SwitchActions { void setEmojiKeyboard(); void setClipboardKeyboard(); void setNumpadKeyboard(); + void toggleNumpad(final int autoCapsFlags, final int recapitalizeMode); void setSymbolsKeyboard(); void setSymbolsShiftedKeyboard(); @@ -90,6 +91,7 @@ public interface SwitchActions { private static final int MODE_CLIPBOARD = 3; private static final int MODE_NUMPAD = 4; private int mMode = MODE_ALPHABET; + private int mModeBeforeNumpad = MODE_ALPHABET; private boolean mIsSymbolShifted; private boolean mPrevMainKeyboardWasShiftLocked; private boolean mPrevSymbolsKeyboardWasShifted; @@ -383,15 +385,44 @@ private void setNumpadKeyboard() { if (DEBUG_INTERNAL_ACTION) { Log.d(TAG, "setNumpadKeyboard"); } + if (mMode == MODE_ALPHABET) { + // Remember caps lock mode and reset alphabet shift state. + mPrevMainKeyboardWasShiftLocked = mAlphabetShiftState.isShiftLocked(); + mAlphabetShiftState.setShiftLocked(false); + } else if (mMode == MODE_SYMBOLS) { + // Remember symbols shifted state + mPrevSymbolsKeyboardWasShifted = mIsSymbolShifted; + } + mModeBeforeNumpad = mMode; mMode = MODE_NUMPAD; mRecapitalizeMode = RecapitalizeStatus.NOT_A_RECAPITALIZE_MODE; - // Remember caps lock mode and reset alphabet shift state. - mPrevMainKeyboardWasShiftLocked = mAlphabetShiftState.isShiftLocked(); - mAlphabetShiftState.setShiftLocked(false); mSwitchActions.setNumpadKeyboard(); mSwitchState = SWITCH_STATE_NUMPAD; } + public void toggleNumpad(final int autoCapsFlags, final int recapitalizeMode) { + if (DEBUG_INTERNAL_ACTION) { + Log.d(TAG, "toggleNumpad"); + } + if (mMode != MODE_NUMPAD) setNumpadKeyboard(); + else switch (mModeBeforeNumpad) { + case MODE_ALPHABET -> { + setAlphabetKeyboard(autoCapsFlags, recapitalizeMode); + if (mPrevMainKeyboardWasShiftLocked) { + setShiftLocked(true); + } + mPrevMainKeyboardWasShiftLocked = false; + } case MODE_SYMBOLS -> { + if (mPrevSymbolsKeyboardWasShifted) { + setSymbolsShiftedKeyboard(); + } else { + setSymbolsKeyboard(); + } + mPrevSymbolsKeyboardWasShifted = false; + } + } + } + private void setOneHandedModeEnabled(boolean enabled) { if (DEBUG_INTERNAL_ACTION) { Log.d(TAG, "setOneHandedModeEnabled"); @@ -763,7 +794,7 @@ public void onEvent(final Event event, final int autoCapsFlags, final int recapi setClipboardKeyboard(); } } else if (code == KeyCode.NUMPAD) { - setNumpadKeyboard(); + toggleNumpad(autoCapsFlags, recapitalizeMode); } else if (code == KeyCode.SYMBOL) { setSymbolsKeyboard(); } else if (code == KeyCode.START_ONE_HANDED_MODE) { From c5fffe7649c4f1e6c6ad32cdb64d51ded7d325d7 Mon Sep 17 00:00:00 2001 From: devycarol Date: Fri, 5 Jul 2024 18:28:16 -0600 Subject: [PATCH 02/14] add space swipe gesture to toggle the numpad --- .../keyboard/keyboard/KeyboardActionListener.java | 1 + .../keyboard/keyboard/KeyboardActionListenerImpl.kt | 7 +++++++ .../helium314/keyboard/keyboard/PointerTracker.java | 11 +++++++++-- .../helium314/keyboard/latin/settings/Settings.java | 2 ++ app/src/main/res/values/donottranslate.xml | 4 ++++ app/src/main/res/values/strings.xml | 2 ++ 6 files changed, 25 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/helium314/keyboard/keyboard/KeyboardActionListener.java b/app/src/main/java/helium314/keyboard/keyboard/KeyboardActionListener.java index 4320f7ba0..4685aa289 100644 --- a/app/src/main/java/helium314/keyboard/keyboard/KeyboardActionListener.java +++ b/app/src/main/java/helium314/keyboard/keyboard/KeyboardActionListener.java @@ -107,6 +107,7 @@ public interface KeyboardActionListener { int SWIPE_NO_ACTION = 0; int SWIPE_MOVE_CURSOR = 1; int SWIPE_SWITCH_LANGUAGE = 2; + int SWIPE_TOGGLE_NUMPAD = 3; class Adapter implements KeyboardActionListener { @Override diff --git a/app/src/main/java/helium314/keyboard/keyboard/KeyboardActionListenerImpl.kt b/app/src/main/java/helium314/keyboard/keyboard/KeyboardActionListenerImpl.kt index 9c6ff2294..3fca4221b 100644 --- a/app/src/main/java/helium314/keyboard/keyboard/KeyboardActionListenerImpl.kt +++ b/app/src/main/java/helium314/keyboard/keyboard/KeyboardActionListenerImpl.kt @@ -71,12 +71,14 @@ class KeyboardActionListenerImpl(private val latinIME: LatinIME, private val inp override fun onHorizontalSpaceSwipe(steps: Int): Boolean = when (Settings.getInstance().current.mSpaceSwipeHorizontal) { KeyboardActionListener.SWIPE_MOVE_CURSOR -> onMoveCursorHorizontally(steps) KeyboardActionListener.SWIPE_SWITCH_LANGUAGE -> onLanguageSlide(steps) + KeyboardActionListener.SWIPE_TOGGLE_NUMPAD -> onNumpadSlide() else -> false } override fun onVerticalSpaceSwipe(steps: Int): Boolean = when (Settings.getInstance().current.mSpaceSwipeVertical) { KeyboardActionListener.SWIPE_MOVE_CURSOR -> onMoveCursorVertically(steps) KeyboardActionListener.SWIPE_SWITCH_LANGUAGE -> onLanguageSlide(steps) + KeyboardActionListener.SWIPE_TOGGLE_NUMPAD -> onNumpadSlide() else -> false } @@ -130,6 +132,11 @@ class KeyboardActionListenerImpl(private val latinIME: LatinIME, private val inp return true } + private fun onNumpadSlide(): Boolean { + KeyboardSwitcher.getInstance().toggleNumpad(latinIME.currentAutoCapsState, latinIME.currentRecapitalizeState) + return true + } + private fun onMoveCursorVertically(steps: Int): Boolean { if (steps == 0) return false val code = if (steps < 0) KeyCode.ARROW_UP else KeyCode.ARROW_DOWN diff --git a/app/src/main/java/helium314/keyboard/keyboard/PointerTracker.java b/app/src/main/java/helium314/keyboard/keyboard/PointerTracker.java index 3566a2e5b..65af14ab9 100644 --- a/app/src/main/java/helium314/keyboard/keyboard/PointerTracker.java +++ b/app/src/main/java/helium314/keyboard/keyboard/PointerTracker.java @@ -879,6 +879,13 @@ private void dragFingerOutFromOldKey(final Key oldKey, final int x, final int y) } } + private boolean oneShotKeySwipe(final int swipeSetting) { + return switch (swipeSetting) { + case KeyboardActionListener.SWIPE_NO_ACTION, KeyboardActionListener.SWIPE_TOGGLE_NUMPAD -> true; + default -> false; + }; + } + private void onKeySwipe(final int code, final int x, final int y, final long eventTime) { final SettingsValues sv = Settings.getInstance().getCurrent(); final int fastTypingTimeout = 2 * sv.mKeyLongpressTimeout / 3; @@ -896,7 +903,7 @@ private void onKeySwipe(final int code, final int x, final int y, final long eve if (!mInVerticalSwipe) { sTimerProxy.cancelKeyTimersOf(this); mInVerticalSwipe = true; - } + } else if (oneShotKeySwipe(sv.mSpaceSwipeVertical)) return; if (sListener.onVerticalSpaceSwipe(stepsY)) { mStartY += stepsY * sPointerStep; } @@ -909,7 +916,7 @@ private void onKeySwipe(final int code, final int x, final int y, final long eve if (!mInHorizontalSwipe) { sTimerProxy.cancelKeyTimersOf(this); mInHorizontalSwipe = true; - } + } else if (oneShotKeySwipe(sv.mSpaceSwipeHorizontal)) return; if (sListener.onHorizontalSpaceSwipe(stepsX)) { mStartX += stepsX * sPointerStep; } diff --git a/app/src/main/java/helium314/keyboard/latin/settings/Settings.java b/app/src/main/java/helium314/keyboard/latin/settings/Settings.java index 8f9ce6e7f..d7341549e 100644 --- a/app/src/main/java/helium314/keyboard/latin/settings/Settings.java +++ b/app/src/main/java/helium314/keyboard/latin/settings/Settings.java @@ -380,6 +380,7 @@ public static int readHorizontalSpaceSwipe(final SharedPreferences prefs) { return switch (prefs.getString(PREF_SPACE_HORIZONTAL_SWIPE, "none")) { case "move_cursor" -> KeyboardActionListener.SWIPE_MOVE_CURSOR; case "switch_language" -> KeyboardActionListener.SWIPE_SWITCH_LANGUAGE; + case "toggle_numpad" -> KeyboardActionListener.SWIPE_TOGGLE_NUMPAD; default -> KeyboardActionListener.SWIPE_NO_ACTION; }; } @@ -388,6 +389,7 @@ public static int readVerticalSpaceSwipe(final SharedPreferences prefs) { return switch (prefs.getString(PREF_SPACE_VERTICAL_SWIPE, "none")) { case "move_cursor" -> KeyboardActionListener.SWIPE_MOVE_CURSOR; case "switch_language" -> KeyboardActionListener.SWIPE_SWITCH_LANGUAGE; + case "toggle_numpad" -> KeyboardActionListener.SWIPE_TOGGLE_NUMPAD; default -> KeyboardActionListener.SWIPE_NO_ACTION; }; } diff --git a/app/src/main/res/values/donottranslate.xml b/app/src/main/res/values/donottranslate.xml index 69d2ab0f2..a5df734f3 100644 --- a/app/src/main/res/values/donottranslate.xml +++ b/app/src/main/res/values/donottranslate.xml @@ -111,21 +111,25 @@ move_cursor switch_language + toggle_numpad none @string/space_swipe_move_cursor_entry @string/switch_language + @string/space_swipe_toggle_numpad_entry @string/action_none move_cursor switch_language + toggle_numpad none @string/space_swipe_move_cursor_entry @string/switch_language + @string/space_swipe_toggle_numpad_entry @string/action_none diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index ce1454399..205109c1b 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -853,6 +853,8 @@ New dictionary: None Move Cursor + + Toggle Numpad Variable toolbar direction From 9136474a685b1c6ded35f1a0b702ab4e2413b123 Mon Sep 17 00:00:00 2001 From: devycarol Date: Fri, 5 Jul 2024 19:26:52 -0600 Subject: [PATCH 03/14] allow sliding key input for the numpad key bugs: - lifting a pointer on the numpad key during a slide-from-numpad breaks toggling - you can't access the numpad during a slide into the symbols (etc.) layout like normal - sliding input with the symbols numpad long-press won't return to alpha --- .../java/helium314/keyboard/keyboard/Key.java | 7 ++- .../keyboard/KeyboardActionListener.java | 5 ++ .../keyboard/KeyboardActionListenerImpl.kt | 14 +++--- .../keyboard/keyboard/KeyboardSwitcher.java | 4 +- .../keyboard/keyboard/PointerTracker.java | 2 +- .../keyboard/internal/KeyboardState.java | 48 ++++++++++--------- 6 files changed, 45 insertions(+), 35 deletions(-) diff --git a/app/src/main/java/helium314/keyboard/keyboard/Key.java b/app/src/main/java/helium314/keyboard/keyboard/Key.java index 9cdeb36dc..419b50b0c 100644 --- a/app/src/main/java/helium314/keyboard/keyboard/Key.java +++ b/app/src/main/java/helium314/keyboard/keyboard/Key.java @@ -515,8 +515,11 @@ public final boolean isShift() { } public final boolean isModifier() { - return mCode == KeyCode.SHIFT || mCode == KeyCode.SYMBOL_ALPHA || mCode == KeyCode.ALPHA || mCode == KeyCode.SYMBOL - || mCode == KeyCode.CTRL || mCode == KeyCode.ALT || mCode == KeyCode.FN || mCode == KeyCode.META; + return switch (mCode) { + case KeyCode.SHIFT, KeyCode.SYMBOL_ALPHA, KeyCode.ALPHA, KeyCode.SYMBOL, KeyCode.NUMPAD, KeyCode.CTRL, + KeyCode.ALT, KeyCode.FN, KeyCode.META -> true; + default -> false; + }; } public final boolean isRepeatable() { diff --git a/app/src/main/java/helium314/keyboard/keyboard/KeyboardActionListener.java b/app/src/main/java/helium314/keyboard/keyboard/KeyboardActionListener.java index 4685aa289..8100015b6 100644 --- a/app/src/main/java/helium314/keyboard/keyboard/KeyboardActionListener.java +++ b/app/src/main/java/helium314/keyboard/keyboard/KeyboardActionListener.java @@ -97,6 +97,7 @@ public interface KeyboardActionListener { */ boolean onHorizontalSpaceSwipe(int steps); boolean onVerticalSpaceSwipe(int steps); + boolean toggleNumpad(); void onMoveDeletePointer(int steps); void onUpWithDeletePointerActive(); @@ -143,6 +144,10 @@ public boolean onVerticalSpaceSwipe(int steps) { return false; } @Override + public boolean toggleNumpad() { + return false; + } + @Override public void onMoveDeletePointer(int steps) {} @Override public void onUpWithDeletePointerActive() {} diff --git a/app/src/main/java/helium314/keyboard/keyboard/KeyboardActionListenerImpl.kt b/app/src/main/java/helium314/keyboard/keyboard/KeyboardActionListenerImpl.kt index 3fca4221b..7c8ecd853 100644 --- a/app/src/main/java/helium314/keyboard/keyboard/KeyboardActionListenerImpl.kt +++ b/app/src/main/java/helium314/keyboard/keyboard/KeyboardActionListenerImpl.kt @@ -71,14 +71,14 @@ class KeyboardActionListenerImpl(private val latinIME: LatinIME, private val inp override fun onHorizontalSpaceSwipe(steps: Int): Boolean = when (Settings.getInstance().current.mSpaceSwipeHorizontal) { KeyboardActionListener.SWIPE_MOVE_CURSOR -> onMoveCursorHorizontally(steps) KeyboardActionListener.SWIPE_SWITCH_LANGUAGE -> onLanguageSlide(steps) - KeyboardActionListener.SWIPE_TOGGLE_NUMPAD -> onNumpadSlide() + KeyboardActionListener.SWIPE_TOGGLE_NUMPAD -> toggleNumpad() else -> false } override fun onVerticalSpaceSwipe(steps: Int): Boolean = when (Settings.getInstance().current.mSpaceSwipeVertical) { KeyboardActionListener.SWIPE_MOVE_CURSOR -> onMoveCursorVertically(steps) KeyboardActionListener.SWIPE_SWITCH_LANGUAGE -> onLanguageSlide(steps) - KeyboardActionListener.SWIPE_TOGGLE_NUMPAD -> onNumpadSlide() + KeyboardActionListener.SWIPE_TOGGLE_NUMPAD -> toggleNumpad() else -> false } @@ -112,6 +112,11 @@ class KeyboardActionListenerImpl(private val latinIME: LatinIME, private val inp onCodeInput(KeyCode.DELETE, Constants.NOT_A_COORDINATE, Constants.NOT_A_COORDINATE, false) } + override fun toggleNumpad(): Boolean { + KeyboardSwitcher.getInstance().toggleNumpad(false, latinIME.currentAutoCapsState, latinIME.currentRecapitalizeState) + return true + } + override fun resetMetaState() { metaState = 0 } @@ -132,11 +137,6 @@ class KeyboardActionListenerImpl(private val latinIME: LatinIME, private val inp return true } - private fun onNumpadSlide(): Boolean { - KeyboardSwitcher.getInstance().toggleNumpad(latinIME.currentAutoCapsState, latinIME.currentRecapitalizeState) - return true - } - private fun onMoveCursorVertically(steps: Int): Boolean { if (steps == 0) return false val code = if (steps < 0) KeyCode.ARROW_UP else KeyCode.ARROW_DOWN diff --git a/app/src/main/java/helium314/keyboard/keyboard/KeyboardSwitcher.java b/app/src/main/java/helium314/keyboard/keyboard/KeyboardSwitcher.java index 7434d2030..279480f58 100644 --- a/app/src/main/java/helium314/keyboard/keyboard/KeyboardSwitcher.java +++ b/app/src/main/java/helium314/keyboard/keyboard/KeyboardSwitcher.java @@ -353,11 +353,11 @@ public void setNumpadKeyboard() { } @Override - public void toggleNumpad(final int autoCapsFlags, final int recapitalizeMode) { + public void toggleNumpad(final boolean withSliding, final int autoCapsFlags, final int recapitalizeMode) { if (DEBUG_ACTION) { Log.d(TAG, "toggleNumpad"); } - mState.toggleNumpad(autoCapsFlags, recapitalizeMode); + mState.toggleNumpad(withSliding, autoCapsFlags, recapitalizeMode); } public enum KeyboardSwitchState { diff --git a/app/src/main/java/helium314/keyboard/keyboard/PointerTracker.java b/app/src/main/java/helium314/keyboard/keyboard/PointerTracker.java index 65af14ab9..02de0b75f 100644 --- a/app/src/main/java/helium314/keyboard/keyboard/PointerTracker.java +++ b/app/src/main/java/helium314/keyboard/keyboard/PointerTracker.java @@ -1112,7 +1112,7 @@ public void onLongPressed() { } } if (code == KeyCode.SYMBOL_ALPHA && Settings.getInstance().getCurrent().mLongPressSymbolsForNumpad) { - sListener.onCodeInput(KeyCode.NUMPAD, Constants.NOT_A_COORDINATE, Constants.NOT_A_COORDINATE, false); + sListener.toggleNumpad(); return; } diff --git a/app/src/main/java/helium314/keyboard/keyboard/internal/KeyboardState.java b/app/src/main/java/helium314/keyboard/keyboard/internal/KeyboardState.java index fe409cbd9..8e4e935b3 100644 --- a/app/src/main/java/helium314/keyboard/keyboard/internal/KeyboardState.java +++ b/app/src/main/java/helium314/keyboard/keyboard/internal/KeyboardState.java @@ -47,7 +47,7 @@ public interface SwitchActions { void setEmojiKeyboard(); void setClipboardKeyboard(); void setNumpadKeyboard(); - void toggleNumpad(final int autoCapsFlags, final int recapitalizeMode); + void toggleNumpad(final boolean withSliding, final int autoCapsFlags, final int recapitalizeMode); void setSymbolsKeyboard(); void setSymbolsShiftedKeyboard(); @@ -82,7 +82,8 @@ public interface SwitchActions { private static final int SWITCH_STATE_MOMENTARY_ALPHA_AND_SYMBOL = 4; private static final int SWITCH_STATE_MOMENTARY_SYMBOL_AND_MORE = 5; private static final int SWITCH_STATE_MOMENTARY_ALPHA_SHIFT = 6; - private static final int SWITCH_STATE_MOMENTARY_FROM_NUMPAD = 7; + private static final int SWITCH_STATE_MOMENTARY_TO_NUMPAD = 7; + private static final int SWITCH_STATE_MOMENTARY_FROM_NUMPAD = 8; private int mSwitchState = SWITCH_STATE_ALPHA; private static final int MODE_ALPHABET = 0; @@ -205,7 +206,7 @@ private void onRestoreKeyboardState(final int autoCapsFlags, final int recapital return; } if (state.mMode == MODE_NUMPAD) { - setNumpadKeyboard(); + setNumpadKeyboard(false); return; } // Symbol mode @@ -381,7 +382,7 @@ private void setClipboardKeyboard() { mSwitchActions.setClipboardKeyboard(); } - private void setNumpadKeyboard() { + private void setNumpadKeyboard(final boolean withSliding) { if (DEBUG_INTERNAL_ACTION) { Log.d(TAG, "setNumpadKeyboard"); } @@ -397,22 +398,22 @@ private void setNumpadKeyboard() { mMode = MODE_NUMPAD; mRecapitalizeMode = RecapitalizeStatus.NOT_A_RECAPITALIZE_MODE; mSwitchActions.setNumpadKeyboard(); - mSwitchState = SWITCH_STATE_NUMPAD; + mSwitchState = withSliding ? SWITCH_STATE_MOMENTARY_TO_NUMPAD : SWITCH_STATE_NUMPAD; } - public void toggleNumpad(final int autoCapsFlags, final int recapitalizeMode) { + public void toggleNumpad(final boolean withSliding, final int autoCapsFlags, final int recapitalizeMode) { if (DEBUG_INTERNAL_ACTION) { Log.d(TAG, "toggleNumpad"); } - if (mMode != MODE_NUMPAD) setNumpadKeyboard(); - else switch (mModeBeforeNumpad) { - case MODE_ALPHABET -> { + if (mMode != MODE_NUMPAD) setNumpadKeyboard(withSliding); + else { + if (mModeBeforeNumpad == MODE_ALPHABET) { setAlphabetKeyboard(autoCapsFlags, recapitalizeMode); if (mPrevMainKeyboardWasShiftLocked) { setShiftLocked(true); } mPrevMainKeyboardWasShiftLocked = false; - } case MODE_SYMBOLS -> { + } else if (mModeBeforeNumpad == MODE_SYMBOLS) { if (mPrevSymbolsKeyboardWasShifted) { setSymbolsShiftedKeyboard(); } else { @@ -420,6 +421,7 @@ else switch (mModeBeforeNumpad) { } mPrevSymbolsKeyboardWasShifted = false; } + if (withSliding) mSwitchState = SWITCH_STATE_MOMENTARY_FROM_NUMPAD; } } @@ -461,6 +463,9 @@ public void onPressKey(final int code, final boolean isSinglePointer, final int } else if (code == KeyCode.ALPHA) { // don't start sliding, causes issues with fully customizable layouts // (also does not allow chording, but can be fixed later) + } else if (code == KeyCode.NUMPAD) { + // don't start sliding, causes issues with fully customizable layouts + // (also does not allow chording, but can be fixed later) } else { mShiftKeyState.onOtherKeyPressed(); mSymbolKeyState.onOtherKeyPressed(); @@ -490,16 +495,13 @@ public void onReleaseKey(final int code, final boolean withSliding, final int au + " sliding=" + withSliding + " " + stateToString(autoCapsFlags, recapitalizeMode)); } - if (code == KeyCode.SHIFT) { - onReleaseShift(withSliding, autoCapsFlags, recapitalizeMode); - } else if (code == KeyCode.CAPS_LOCK) { - setShiftLocked(!mAlphabetShiftState.isShiftLocked()); - } else if (code == KeyCode.SYMBOL_ALPHA) { - onReleaseAlphaSymbol(withSliding, autoCapsFlags, recapitalizeMode); - } else if (code == KeyCode.SYMBOL) { - onReleaseSymbol(withSliding, autoCapsFlags, recapitalizeMode); - } else if (code == KeyCode.ALPHA) { - onReleaseAlpha(withSliding, autoCapsFlags, recapitalizeMode); + switch (code) { + case KeyCode.SHIFT -> onReleaseShift(withSliding, autoCapsFlags, recapitalizeMode); + case KeyCode.CAPS_LOCK -> setShiftLocked(!mAlphabetShiftState.isShiftLocked()); + case KeyCode.SYMBOL_ALPHA -> onReleaseAlphaSymbol(withSliding, autoCapsFlags, recapitalizeMode); + case KeyCode.SYMBOL -> onReleaseSymbol(withSliding, autoCapsFlags, recapitalizeMode); + case KeyCode.ALPHA -> onReleaseAlpha(withSliding, autoCapsFlags, recapitalizeMode); + case KeyCode.NUMPAD -> toggleNumpad(withSliding, autoCapsFlags, recapitalizeMode); } } @@ -714,7 +716,8 @@ public void onFinishSlidingInput(final int autoCapsFlags, final int recapitalize case SWITCH_STATE_MOMENTARY_ALPHA_AND_SYMBOL -> toggleAlphabetAndSymbols(autoCapsFlags, recapitalizeMode); case SWITCH_STATE_MOMENTARY_SYMBOL_AND_MORE -> toggleShiftInSymbols(); case SWITCH_STATE_MOMENTARY_ALPHA_SHIFT -> setAlphabetKeyboard(autoCapsFlags, recapitalizeMode); - case SWITCH_STATE_MOMENTARY_FROM_NUMPAD -> setNumpadKeyboard(); + case SWITCH_STATE_MOMENTARY_FROM_NUMPAD -> setNumpadKeyboard(false); + case SWITCH_STATE_MOMENTARY_TO_NUMPAD -> toggleNumpad(false, autoCapsFlags, recapitalizeMode); } } @@ -793,8 +796,6 @@ public void onEvent(final Event event, final int autoCapsFlags, final int recapi if (Settings.getInstance().getCurrent().mClipboardHistoryEnabled) { setClipboardKeyboard(); } - } else if (code == KeyCode.NUMPAD) { - toggleNumpad(autoCapsFlags, recapitalizeMode); } else if (code == KeyCode.SYMBOL) { setSymbolsKeyboard(); } else if (code == KeyCode.START_ONE_HANDED_MODE) { @@ -824,6 +825,7 @@ private static String switchStateToString(final int switchState) { case SWITCH_STATE_MOMENTARY_SYMBOL_AND_MORE -> "MOMENTARY-SYMBOL-MORE"; case SWITCH_STATE_MOMENTARY_ALPHA_SHIFT -> "MOMENTARY-ALPHA_SHIFT"; case SWITCH_STATE_NUMPAD -> "NUMPAD"; + case SWITCH_STATE_MOMENTARY_TO_NUMPAD -> "MOMENTARY-TO-NUMPAD"; case SWITCH_STATE_MOMENTARY_FROM_NUMPAD -> "MOMENTARY-FROM-NUMPAD"; default -> null; }; From 16f0e04f839326a4cb0ac79cec87ba531ab8cf09 Mon Sep 17 00:00:00 2001 From: devycarol Date: Fri, 5 Jul 2024 21:12:38 -0600 Subject: [PATCH 04/14] fix those bugs --- .../keyboard/KeyboardActionListener.java | 4 +-- .../keyboard/KeyboardActionListenerImpl.kt | 14 +++++------ .../keyboard/keyboard/KeyboardSwitcher.java | 5 ++-- .../keyboard/keyboard/PointerTracker.java | 6 +++-- .../keyboard/internal/KeyboardState.java | 25 +++++++++++-------- 5 files changed, 30 insertions(+), 24 deletions(-) diff --git a/app/src/main/java/helium314/keyboard/keyboard/KeyboardActionListener.java b/app/src/main/java/helium314/keyboard/keyboard/KeyboardActionListener.java index 8100015b6..224337f34 100644 --- a/app/src/main/java/helium314/keyboard/keyboard/KeyboardActionListener.java +++ b/app/src/main/java/helium314/keyboard/keyboard/KeyboardActionListener.java @@ -97,7 +97,7 @@ public interface KeyboardActionListener { */ boolean onHorizontalSpaceSwipe(int steps); boolean onVerticalSpaceSwipe(int steps); - boolean toggleNumpad(); + boolean toggleNumpad(boolean withSliding, boolean forceReturnToAlpha); void onMoveDeletePointer(int steps); void onUpWithDeletePointerActive(); @@ -144,7 +144,7 @@ public boolean onVerticalSpaceSwipe(int steps) { return false; } @Override - public boolean toggleNumpad() { + public boolean toggleNumpad(boolean withSliding, boolean forceReturnToAlpha) { return false; } @Override diff --git a/app/src/main/java/helium314/keyboard/keyboard/KeyboardActionListenerImpl.kt b/app/src/main/java/helium314/keyboard/keyboard/KeyboardActionListenerImpl.kt index 7c8ecd853..fad78ee8f 100644 --- a/app/src/main/java/helium314/keyboard/keyboard/KeyboardActionListenerImpl.kt +++ b/app/src/main/java/helium314/keyboard/keyboard/KeyboardActionListenerImpl.kt @@ -71,17 +71,22 @@ class KeyboardActionListenerImpl(private val latinIME: LatinIME, private val inp override fun onHorizontalSpaceSwipe(steps: Int): Boolean = when (Settings.getInstance().current.mSpaceSwipeHorizontal) { KeyboardActionListener.SWIPE_MOVE_CURSOR -> onMoveCursorHorizontally(steps) KeyboardActionListener.SWIPE_SWITCH_LANGUAGE -> onLanguageSlide(steps) - KeyboardActionListener.SWIPE_TOGGLE_NUMPAD -> toggleNumpad() + KeyboardActionListener.SWIPE_TOGGLE_NUMPAD -> toggleNumpad(false, false) else -> false } override fun onVerticalSpaceSwipe(steps: Int): Boolean = when (Settings.getInstance().current.mSpaceSwipeVertical) { KeyboardActionListener.SWIPE_MOVE_CURSOR -> onMoveCursorVertically(steps) KeyboardActionListener.SWIPE_SWITCH_LANGUAGE -> onLanguageSlide(steps) - KeyboardActionListener.SWIPE_TOGGLE_NUMPAD -> toggleNumpad() + KeyboardActionListener.SWIPE_TOGGLE_NUMPAD -> toggleNumpad(false, false) else -> false } + override fun toggleNumpad(withSliding: Boolean, forceReturnToAlpha: Boolean): Boolean { + KeyboardSwitcher.getInstance().toggleNumpad(withSliding, latinIME.currentAutoCapsState, latinIME.currentRecapitalizeState, forceReturnToAlpha) + return true + } + override fun onMoveDeletePointer(steps: Int) { inputLogic.finishInput() val end = inputLogic.mConnection.expectedSelectionEnd @@ -112,11 +117,6 @@ class KeyboardActionListenerImpl(private val latinIME: LatinIME, private val inp onCodeInput(KeyCode.DELETE, Constants.NOT_A_COORDINATE, Constants.NOT_A_COORDINATE, false) } - override fun toggleNumpad(): Boolean { - KeyboardSwitcher.getInstance().toggleNumpad(false, latinIME.currentAutoCapsState, latinIME.currentRecapitalizeState) - return true - } - override fun resetMetaState() { metaState = 0 } diff --git a/app/src/main/java/helium314/keyboard/keyboard/KeyboardSwitcher.java b/app/src/main/java/helium314/keyboard/keyboard/KeyboardSwitcher.java index 279480f58..33f6cfd55 100644 --- a/app/src/main/java/helium314/keyboard/keyboard/KeyboardSwitcher.java +++ b/app/src/main/java/helium314/keyboard/keyboard/KeyboardSwitcher.java @@ -353,11 +353,12 @@ public void setNumpadKeyboard() { } @Override - public void toggleNumpad(final boolean withSliding, final int autoCapsFlags, final int recapitalizeMode) { + public void toggleNumpad(final boolean withSliding, final int autoCapsFlags, final int recapitalizeMode, + final boolean forceReturnToAlpha) { if (DEBUG_ACTION) { Log.d(TAG, "toggleNumpad"); } - mState.toggleNumpad(withSliding, autoCapsFlags, recapitalizeMode); + mState.toggleNumpad(withSliding, autoCapsFlags, recapitalizeMode, forceReturnToAlpha); } public enum KeyboardSwitchState { diff --git a/app/src/main/java/helium314/keyboard/keyboard/PointerTracker.java b/app/src/main/java/helium314/keyboard/keyboard/PointerTracker.java index 02de0b75f..f13ff2d13 100644 --- a/app/src/main/java/helium314/keyboard/keyboard/PointerTracker.java +++ b/app/src/main/java/helium314/keyboard/keyboard/PointerTracker.java @@ -268,7 +268,8 @@ private boolean callListenerOnPressAndCheckKeyboardLayoutChange(final Key key, // primaryCode is different from {@link Key#mKeyCode}. private void callListenerOnCodeInput(final Key key, final int primaryCode, final int x, final int y, final long eventTime, final boolean isKeyRepeat) { - final boolean ignoreModifierKey = mIsInDraggingFinger && key.isModifier(); + final boolean ignoreModifierKey = mIsInDraggingFinger && key.isModifier() + && key.getCode() != KeyCode.NUMPAD; // we allow for the numpad to be toggled from sliding input final boolean altersCode = key.altCodeWhileTyping() && sTimerProxy.isTypingState() && !isClearlyInsideKey(key, x, y); final int code = altersCode ? key.getAltCode() : primaryCode; if (DEBUG_LISTENER) { @@ -1112,7 +1113,8 @@ public void onLongPressed() { } } if (code == KeyCode.SYMBOL_ALPHA && Settings.getInstance().getCurrent().mLongPressSymbolsForNumpad) { - sListener.toggleNumpad(); + // toggle numpad with sliding input enabled, forcing return to the alpha layout when done + sListener.toggleNumpad(true, true); return; } diff --git a/app/src/main/java/helium314/keyboard/keyboard/internal/KeyboardState.java b/app/src/main/java/helium314/keyboard/keyboard/internal/KeyboardState.java index 8e4e935b3..615fa51a0 100644 --- a/app/src/main/java/helium314/keyboard/keyboard/internal/KeyboardState.java +++ b/app/src/main/java/helium314/keyboard/keyboard/internal/KeyboardState.java @@ -47,7 +47,8 @@ public interface SwitchActions { void setEmojiKeyboard(); void setClipboardKeyboard(); void setNumpadKeyboard(); - void toggleNumpad(final boolean withSliding, final int autoCapsFlags, final int recapitalizeMode); + void toggleNumpad(final boolean withSliding, final int autoCapsFlags, final int recapitalizeMode, + final boolean forceReturnToAlpha); void setSymbolsKeyboard(); void setSymbolsShiftedKeyboard(); @@ -206,7 +207,7 @@ private void onRestoreKeyboardState(final int autoCapsFlags, final int recapital return; } if (state.mMode == MODE_NUMPAD) { - setNumpadKeyboard(false); + setNumpadKeyboard(false, false); return; } // Symbol mode @@ -382,7 +383,7 @@ private void setClipboardKeyboard() { mSwitchActions.setClipboardKeyboard(); } - private void setNumpadKeyboard(final boolean withSliding) { + private void setNumpadKeyboard(final boolean withSliding, final boolean forceReturnToAlpha) { if (DEBUG_INTERNAL_ACTION) { Log.d(TAG, "setNumpadKeyboard"); } @@ -394,18 +395,19 @@ private void setNumpadKeyboard(final boolean withSliding) { // Remember symbols shifted state mPrevSymbolsKeyboardWasShifted = mIsSymbolShifted; } - mModeBeforeNumpad = mMode; + mModeBeforeNumpad = forceReturnToAlpha ? MODE_ALPHABET : mMode; mMode = MODE_NUMPAD; mRecapitalizeMode = RecapitalizeStatus.NOT_A_RECAPITALIZE_MODE; mSwitchActions.setNumpadKeyboard(); mSwitchState = withSliding ? SWITCH_STATE_MOMENTARY_TO_NUMPAD : SWITCH_STATE_NUMPAD; } - public void toggleNumpad(final boolean withSliding, final int autoCapsFlags, final int recapitalizeMode) { + public void toggleNumpad(final boolean withSliding, final int autoCapsFlags, final int recapitalizeMode, + final boolean forceReturnToAlpha) { if (DEBUG_INTERNAL_ACTION) { Log.d(TAG, "toggleNumpad"); } - if (mMode != MODE_NUMPAD) setNumpadKeyboard(withSliding); + if (mMode != MODE_NUMPAD) setNumpadKeyboard(withSliding, forceReturnToAlpha); else { if (mModeBeforeNumpad == MODE_ALPHABET) { setAlphabetKeyboard(autoCapsFlags, recapitalizeMode); @@ -501,7 +503,7 @@ public void onReleaseKey(final int code, final boolean withSliding, final int au case KeyCode.SYMBOL_ALPHA -> onReleaseAlphaSymbol(withSliding, autoCapsFlags, recapitalizeMode); case KeyCode.SYMBOL -> onReleaseSymbol(withSliding, autoCapsFlags, recapitalizeMode); case KeyCode.ALPHA -> onReleaseAlpha(withSliding, autoCapsFlags, recapitalizeMode); - case KeyCode.NUMPAD -> toggleNumpad(withSliding, autoCapsFlags, recapitalizeMode); + case KeyCode.NUMPAD -> toggleNumpad(withSliding, autoCapsFlags, recapitalizeMode, false); } } @@ -711,13 +713,14 @@ public void onFinishSlidingInput(final int autoCapsFlags, final int recapitalize if (DEBUG_EVENT) { Log.d(TAG, "onFinishSlidingInput: " + stateToString(autoCapsFlags, recapitalizeMode)); } - // Switch back to the previous keyboard mode if the user cancels sliding input. - switch (mSwitchState) { + // Switch back to the previous keyboard mode if the user didn't enter the numpad. + if (mMode != MODE_NUMPAD) switch (mSwitchState) { case SWITCH_STATE_MOMENTARY_ALPHA_AND_SYMBOL -> toggleAlphabetAndSymbols(autoCapsFlags, recapitalizeMode); case SWITCH_STATE_MOMENTARY_SYMBOL_AND_MORE -> toggleShiftInSymbols(); case SWITCH_STATE_MOMENTARY_ALPHA_SHIFT -> setAlphabetKeyboard(autoCapsFlags, recapitalizeMode); - case SWITCH_STATE_MOMENTARY_FROM_NUMPAD -> setNumpadKeyboard(false); - case SWITCH_STATE_MOMENTARY_TO_NUMPAD -> toggleNumpad(false, autoCapsFlags, recapitalizeMode); + case SWITCH_STATE_MOMENTARY_FROM_NUMPAD -> setNumpadKeyboard(false, false); + } else if (mSwitchState == SWITCH_STATE_MOMENTARY_TO_NUMPAD) { + toggleNumpad(false, autoCapsFlags, recapitalizeMode, false); } } From 7ec6df29f9af92504d4738873061b2538f30748b Mon Sep 17 00:00:00 2001 From: devycarol Date: Fri, 5 Jul 2024 21:13:26 -0600 Subject: [PATCH 05/14] update the bottom row of the numpad --- app/src/main/assets/layouts/numpad.json | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/app/src/main/assets/layouts/numpad.json b/app/src/main/assets/layouts/numpad.json index 4edfca2f0..0624afe1e 100644 --- a/app/src/main/assets/layouts/numpad.json +++ b/app/src/main/assets/layouts/numpad.json @@ -39,12 +39,12 @@ { "label": "delete" } ], [ - { "label": "alpha" }, + { "label": "alpha", "width": 0.15 }, { "label": "comma", "width": 0.1 }, - { "label": "symbol", "type": "character", "width": 0.12 }, + { "label": "numpad", "width": 0.14 }, { "label": "0", "type": "numeric" }, - { "label": "=", "width": 0.12, "popup": { "relevant": [ { "label": "≠"}, { "label": "≈"} ] } }, + { "label": "=", "type": "function", "width": 0.14, "popup": { "relevant": [ { "label": "≠"}, { "label": "≈"} ] } }, { "label": "period", "width": 0.1 }, - { "label": "action" } + { "label": "action", "width": 0.15 } ] ] From 4b54fde833b85274e943934226f97e0a7278eb20 Mon Sep 17 00:00:00 2001 From: devycarol Date: Fri, 5 Jul 2024 21:51:00 -0600 Subject: [PATCH 06/14] add space swipe gesture to toggle the numpad --- .../java/helium314/keyboard/keyboard/PointerTracker.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/helium314/keyboard/keyboard/PointerTracker.java b/app/src/main/java/helium314/keyboard/keyboard/PointerTracker.java index f13ff2d13..b04286c61 100644 --- a/app/src/main/java/helium314/keyboard/keyboard/PointerTracker.java +++ b/app/src/main/java/helium314/keyboard/keyboard/PointerTracker.java @@ -880,7 +880,7 @@ private void dragFingerOutFromOldKey(final Key oldKey, final int x, final int y) } } - private boolean oneShotKeySwipe(final int swipeSetting) { + private boolean oneShotSwipe(final int swipeSetting) { return switch (swipeSetting) { case KeyboardActionListener.SWIPE_NO_ACTION, KeyboardActionListener.SWIPE_TOGGLE_NUMPAD -> true; default -> false; @@ -904,7 +904,7 @@ private void onKeySwipe(final int code, final int x, final int y, final long eve if (!mInVerticalSwipe) { sTimerProxy.cancelKeyTimersOf(this); mInVerticalSwipe = true; - } else if (oneShotKeySwipe(sv.mSpaceSwipeVertical)) return; + } else if (oneShotSwipe(sv.mSpaceSwipeVertical)) return; if (sListener.onVerticalSpaceSwipe(stepsY)) { mStartY += stepsY * sPointerStep; } @@ -917,7 +917,7 @@ private void onKeySwipe(final int code, final int x, final int y, final long eve if (!mInHorizontalSwipe) { sTimerProxy.cancelKeyTimersOf(this); mInHorizontalSwipe = true; - } else if (oneShotKeySwipe(sv.mSpaceSwipeHorizontal)) return; + } else if (oneShotSwipe(sv.mSpaceSwipeHorizontal)) return; if (sListener.onHorizontalSpaceSwipe(stepsX)) { mStartX += stepsX * sPointerStep; } From 37f31487f39510a201a002bffc29fd92bd8df66c Mon Sep 17 00:00:00 2001 From: devycarol Date: Sun, 7 Jul 2024 13:36:04 -0600 Subject: [PATCH 07/14] update layouts.md --- layouts.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/layouts.md b/layouts.md index e6576eb49..40e8faa39 100644 --- a/layouts.md +++ b/layouts.md @@ -83,7 +83,7 @@ Usually the label is what is displayed on the key. However, there are some speci * _alpha_: switch to alphabet keyboard (or main phone keyboard in case of phone layout) * _symbol_: switch to symbol keyboard (or phone symbols keyboard in case of phone layout) * _symbol_alpha_: toggle alpha / symbol keyboard - * _numpad_: switch to numpad layout + * _numpad_: toggle numpad layout * _emoji_: switch to emoji view * _com_: display common TLDs (.com and similar, currently not localized) * _language_switch_: language switch key From 6ea5727c21051230b9f464bb3e00262d9f8c97ff Mon Sep 17 00:00:00 2001 From: devycarol Date: Sun, 7 Jul 2024 15:42:01 -0600 Subject: [PATCH 08/14] add numpad toolbar key --- .../keyboard/keyboard/internal/KeyboardCodesSet.java | 2 -- .../keyboard/keyboard/internal/KeyboardIconsSet.kt | 2 -- .../keyboard/keyboard/internal/KeyboardState.java | 8 ++++++-- .../internal/keyboard_parser/floris/TextKeyData.kt | 1 - .../java/helium314/keyboard/latin/utils/ToolbarUtils.kt | 6 ++++-- app/src/main/res/values/strings.xml | 3 ++- 6 files changed, 12 insertions(+), 10 deletions(-) diff --git a/app/src/main/java/helium314/keyboard/keyboard/internal/KeyboardCodesSet.java b/app/src/main/java/helium314/keyboard/keyboard/internal/KeyboardCodesSet.java index 4dc91203a..7c21f1542 100644 --- a/app/src/main/java/helium314/keyboard/keyboard/internal/KeyboardCodesSet.java +++ b/app/src/main/java/helium314/keyboard/keyboard/internal/KeyboardCodesSet.java @@ -52,7 +52,6 @@ public static int getCode(final String name) { "key_emoji", "key_unspecified", "key_clipboard", - "key_numpad", "key_start_onehanded", "key_stop_onehanded", "key_switch_onehanded" @@ -78,7 +77,6 @@ public static int getCode(final String name) { KeyCode.EMOJI, KeyCode.NOT_SPECIFIED, KeyCode.CLIPBOARD, - KeyCode.NUMPAD, KeyCode.START_ONE_HANDED_MODE, KeyCode.STOP_ONE_HANDED_MODE, KeyCode.SWITCH_ONE_HANDED_MODE diff --git a/app/src/main/java/helium314/keyboard/keyboard/internal/KeyboardIconsSet.kt b/app/src/main/java/helium314/keyboard/keyboard/internal/KeyboardIconsSet.kt index 0221085c9..8acb10e90 100644 --- a/app/src/main/java/helium314/keyboard/keyboard/internal/KeyboardIconsSet.kt +++ b/app/src/main/java/helium314/keyboard/keyboard/internal/KeyboardIconsSet.kt @@ -57,7 +57,6 @@ class KeyboardIconsSet { const val NAME_CLIPBOARD_NORMAL_KEY = "clipboard_normal_key" const val NAME_CLEAR_CLIPBOARD_KEY = "clear_clipboard_key" const val NAME_CUT_KEY = "cut_key" - const val NAME_NUMPAD_KEY = "numpad_key" const val NAME_START_ONEHANDED_KEY = "start_onehanded_mode_key" const val NAME_STOP_ONEHANDED_KEY = "stop_onehanded_mode_key" const val NAME_SWITCH_ONEHANDED_KEY = "switch_onehanded_key" @@ -90,7 +89,6 @@ class KeyboardIconsSet { NAME_CLIPBOARD_NORMAL_KEY to R.styleable.Keyboard_iconClipboardNormalKey, NAME_CLEAR_CLIPBOARD_KEY to R.styleable.Keyboard_iconClearClipboardKey, NAME_CUT_KEY to R.styleable.Keyboard_iconCutKey, - NAME_NUMPAD_KEY to R.styleable.Keyboard_iconNumpadKey, NAME_START_ONEHANDED_KEY to R.styleable.Keyboard_iconStartOneHandedMode, NAME_STOP_ONEHANDED_KEY to R.styleable.Keyboard_iconStopOneHandedMode, NAME_SWITCH_ONEHANDED_KEY to R.styleable.Keyboard_iconSwitchOneHandedMode, diff --git a/app/src/main/java/helium314/keyboard/keyboard/internal/KeyboardState.java b/app/src/main/java/helium314/keyboard/keyboard/internal/KeyboardState.java index 615fa51a0..549782446 100644 --- a/app/src/main/java/helium314/keyboard/keyboard/internal/KeyboardState.java +++ b/app/src/main/java/helium314/keyboard/keyboard/internal/KeyboardState.java @@ -503,8 +503,10 @@ public void onReleaseKey(final int code, final boolean withSliding, final int au case KeyCode.SYMBOL_ALPHA -> onReleaseAlphaSymbol(withSliding, autoCapsFlags, recapitalizeMode); case KeyCode.SYMBOL -> onReleaseSymbol(withSliding, autoCapsFlags, recapitalizeMode); case KeyCode.ALPHA -> onReleaseAlpha(withSliding, autoCapsFlags, recapitalizeMode); - case KeyCode.NUMPAD -> toggleNumpad(withSliding, autoCapsFlags, recapitalizeMode, false); - } + case KeyCode.NUMPAD -> { + // if no sliding, toggling is instead handled by {@link #onEvent} to accomodate toolbar key + if (withSliding) toggleNumpad(true, autoCapsFlags, recapitalizeMode, false); + }} } private void onPressAlphaSymbol(final int autoCapsFlags, final int recapitalizeMode) { @@ -799,6 +801,8 @@ public void onEvent(final Event event, final int autoCapsFlags, final int recapi if (Settings.getInstance().getCurrent().mClipboardHistoryEnabled) { setClipboardKeyboard(); } + } else if (code == KeyCode.NUMPAD) { + toggleNumpad(false, autoCapsFlags, recapitalizeMode, false); } else if (code == KeyCode.SYMBOL) { setSymbolsKeyboard(); } else if (code == KeyCode.START_ONE_HANDED_MODE) { 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 c5ec0ad69..2b7999437 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 @@ -480,7 +480,6 @@ sealed interface KeyData : AbstractKeyData { // todo (later): label and popupKeys for .com should be in localeKeyTexts, handled similar to currency key KeyLabel.COM -> ".com" KeyLabel.LANGUAGE_SWITCH -> "!icon/language_switch_key|!code/key_language_switch" - KeyLabel.NUMPAD -> "!icon/numpad_key|!code/key_numpad" KeyLabel.ZWNJ -> "!icon/zwnj_key|\u200C" KeyLabel.CURRENCY -> params.mLocaleKeyboardInfos.currencyKey.first KeyLabel.CURRENCY1 -> params.mLocaleKeyboardInfos.currencyKey.second[0] diff --git a/app/src/main/java/helium314/keyboard/latin/utils/ToolbarUtils.kt b/app/src/main/java/helium314/keyboard/latin/utils/ToolbarUtils.kt index 774455cd3..5b48b8135 100644 --- a/app/src/main/java/helium314/keyboard/latin/utils/ToolbarUtils.kt +++ b/app/src/main/java/helium314/keyboard/latin/utils/ToolbarUtils.kt @@ -37,6 +37,7 @@ fun createToolbarKey(context: Context, keyboardAttr: TypedArray, key: ToolbarKey fun getCodeForToolbarKey(key: ToolbarKey) = when (key) { VOICE -> KeyCode.VOICE_INPUT CLIPBOARD -> KeyCode.CLIPBOARD + NUMPAD -> KeyCode.NUMPAD UNDO -> KeyCode.UNDO REDO -> KeyCode.REDO SETTINGS -> KeyCode.SETTINGS @@ -86,6 +87,7 @@ fun getCodeForToolbarKeyLongClick(key: ToolbarKey) = when (key) { fun getStyleableIconId(key: ToolbarKey) = when (key) { VOICE -> R.styleable.Keyboard_iconShortcutKey CLIPBOARD -> R.styleable.Keyboard_iconClipboardNormalKey + NUMPAD -> R.styleable.Keyboard_iconNumpadKey UNDO -> R.styleable.Keyboard_iconUndo REDO -> R.styleable.Keyboard_iconRedo SETTINGS -> R.styleable.Keyboard_iconSettingsKey @@ -125,8 +127,8 @@ fun getToolbarIconByName(name: String, context: Context): Drawable? { // names need to be aligned with resources strings (using lowercase of key.name) enum class ToolbarKey { - VOICE, CLIPBOARD, UNDO, REDO, SETTINGS, SELECT_ALL, SELECT_WORD, COPY, CUT, PASTE, ONE_HANDED, INCOGNITO, - AUTOCORRECT, CLEAR_CLIPBOARD, CLOSE_HISTORY, EMOJI, LEFT, RIGHT, UP, DOWN, WORD_LEFT, WORD_RIGHT, + VOICE, CLIPBOARD, NUMPAD, UNDO, REDO, SETTINGS, SELECT_ALL, SELECT_WORD, COPY, CUT, PASTE, ONE_HANDED, + INCOGNITO, AUTOCORRECT, CLEAR_CLIPBOARD, CLOSE_HISTORY, EMOJI, LEFT, RIGHT, UP, DOWN, WORD_LEFT, WORD_RIGHT, PAGE_UP, PAGE_DOWN, FULL_LEFT, FULL_RIGHT, PAGE_START, PAGE_END } diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 5971d41ad..f940aa422 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -248,6 +248,7 @@ Clipboard Clear clipboard Voice input + @string/layout_numpad Settings @android:string/selectAll Select word @@ -858,7 +859,7 @@ New dictionary: None Move Cursor - + Toggle Numpad Variable toolbar direction From 2b0ab0e181c9319f081d094a4f8fcee53f4b95fe Mon Sep 17 00:00:00 2001 From: devycarol Date: Sun, 7 Jul 2024 18:14:42 -0600 Subject: [PATCH 09/14] don't forget toggle state on orientation change and account for toggling via clipboard toolbar --- .../keyboard/keyboard/KeyboardSwitcher.java | 2 +- .../keyboard/internal/KeyboardState.java | 59 +++++++++++-------- 2 files changed, 36 insertions(+), 25 deletions(-) diff --git a/app/src/main/java/helium314/keyboard/keyboard/KeyboardSwitcher.java b/app/src/main/java/helium314/keyboard/keyboard/KeyboardSwitcher.java index 33f6cfd55..1583e0aa1 100644 --- a/app/src/main/java/helium314/keyboard/keyboard/KeyboardSwitcher.java +++ b/app/src/main/java/helium314/keyboard/keyboard/KeyboardSwitcher.java @@ -358,7 +358,7 @@ public void toggleNumpad(final boolean withSliding, final int autoCapsFlags, fin if (DEBUG_ACTION) { Log.d(TAG, "toggleNumpad"); } - mState.toggleNumpad(withSliding, autoCapsFlags, recapitalizeMode, forceReturnToAlpha); + mState.toggleNumpad(withSliding, autoCapsFlags, recapitalizeMode, forceReturnToAlpha, true); } public enum KeyboardSwitchState { diff --git a/app/src/main/java/helium314/keyboard/keyboard/internal/KeyboardState.java b/app/src/main/java/helium314/keyboard/keyboard/internal/KeyboardState.java index 549782446..79691e6a3 100644 --- a/app/src/main/java/helium314/keyboard/keyboard/internal/KeyboardState.java +++ b/app/src/main/java/helium314/keyboard/keyboard/internal/KeyboardState.java @@ -207,7 +207,8 @@ private void onRestoreKeyboardState(final int autoCapsFlags, final int recapital return; } if (state.mMode == MODE_NUMPAD) { - setNumpadKeyboard(false, false); + // don't overwrite toggle info in this case + setNumpadKeyboard(false, false, false); return; } // Symbol mode @@ -383,19 +384,22 @@ private void setClipboardKeyboard() { mSwitchActions.setClipboardKeyboard(); } - private void setNumpadKeyboard(final boolean withSliding, final boolean forceReturnToAlpha) { + private void setNumpadKeyboard(final boolean withSliding, final boolean forceReturnToAlpha, + final boolean rememberState) { if (DEBUG_INTERNAL_ACTION) { Log.d(TAG, "setNumpadKeyboard"); } - if (mMode == MODE_ALPHABET) { - // Remember caps lock mode and reset alphabet shift state. - mPrevMainKeyboardWasShiftLocked = mAlphabetShiftState.isShiftLocked(); - mAlphabetShiftState.setShiftLocked(false); - } else if (mMode == MODE_SYMBOLS) { - // Remember symbols shifted state - mPrevSymbolsKeyboardWasShifted = mIsSymbolShifted; + if (rememberState) { + if (mMode == MODE_ALPHABET) { + // Remember caps lock mode and reset alphabet shift state. + mPrevMainKeyboardWasShiftLocked = mAlphabetShiftState.isShiftLocked(); + mAlphabetShiftState.setShiftLocked(false); + } else if (mMode == MODE_SYMBOLS) { + // Remember symbols shifted state + mPrevSymbolsKeyboardWasShifted = mIsSymbolShifted; + } // When d-pad is added, "selection mode" may need to be remembered if not a global state + mModeBeforeNumpad = forceReturnToAlpha ? MODE_ALPHABET : mMode; } - mModeBeforeNumpad = forceReturnToAlpha ? MODE_ALPHABET : mMode; mMode = MODE_NUMPAD; mRecapitalizeMode = RecapitalizeStatus.NOT_A_RECAPITALIZE_MODE; mSwitchActions.setNumpadKeyboard(); @@ -403,25 +407,31 @@ private void setNumpadKeyboard(final boolean withSliding, final boolean forceRet } public void toggleNumpad(final boolean withSliding, final int autoCapsFlags, final int recapitalizeMode, - final boolean forceReturnToAlpha) { + final boolean forceReturnToAlpha, final boolean rememberState) { if (DEBUG_INTERNAL_ACTION) { Log.d(TAG, "toggleNumpad"); } - if (mMode != MODE_NUMPAD) setNumpadKeyboard(withSliding, forceReturnToAlpha); + if (mMode != MODE_NUMPAD) setNumpadKeyboard(withSliding, forceReturnToAlpha, rememberState); else { - if (mModeBeforeNumpad == MODE_ALPHABET) { + if (mModeBeforeNumpad == MODE_ALPHABET || forceReturnToAlpha) { setAlphabetKeyboard(autoCapsFlags, recapitalizeMode); if (mPrevMainKeyboardWasShiftLocked) { setShiftLocked(true); } mPrevMainKeyboardWasShiftLocked = false; - } else if (mModeBeforeNumpad == MODE_SYMBOLS) { - if (mPrevSymbolsKeyboardWasShifted) { - setSymbolsShiftedKeyboard(); - } else { - setSymbolsKeyboard(); + } else switch (mModeBeforeNumpad) { + case MODE_SYMBOLS -> { + if (mPrevSymbolsKeyboardWasShifted) { + setSymbolsShiftedKeyboard(); + } else { + setSymbolsKeyboard(); + } + mPrevSymbolsKeyboardWasShifted = false; } - mPrevSymbolsKeyboardWasShifted = false; + // toggling numpad and emoji layout isn't actually possible yet due to lack of toolbar + // keys or key-swipes in that layout, but included for safety. + case MODE_EMOJI -> setEmojiKeyboard(); + case MODE_CLIPBOARD -> setClipboardKeyboard(); } if (withSliding) mSwitchState = SWITCH_STATE_MOMENTARY_FROM_NUMPAD; } @@ -504,8 +514,9 @@ public void onReleaseKey(final int code, final boolean withSliding, final int au case KeyCode.SYMBOL -> onReleaseSymbol(withSliding, autoCapsFlags, recapitalizeMode); case KeyCode.ALPHA -> onReleaseAlpha(withSliding, autoCapsFlags, recapitalizeMode); case KeyCode.NUMPAD -> { - // if no sliding, toggling is instead handled by {@link #onEvent} to accomodate toolbar key - if (withSliding) toggleNumpad(true, autoCapsFlags, recapitalizeMode, false); + // if no sliding, toggling is instead handled by {@link #onEvent} to accomodate toolbar key. + // also prevent sliding into to the clipboard layout, which isn't supported yet. + if (withSliding) toggleNumpad(true, autoCapsFlags, recapitalizeMode, mModeBeforeNumpad == MODE_CLIPBOARD, true); }} } @@ -720,9 +731,9 @@ public void onFinishSlidingInput(final int autoCapsFlags, final int recapitalize case SWITCH_STATE_MOMENTARY_ALPHA_AND_SYMBOL -> toggleAlphabetAndSymbols(autoCapsFlags, recapitalizeMode); case SWITCH_STATE_MOMENTARY_SYMBOL_AND_MORE -> toggleShiftInSymbols(); case SWITCH_STATE_MOMENTARY_ALPHA_SHIFT -> setAlphabetKeyboard(autoCapsFlags, recapitalizeMode); - case SWITCH_STATE_MOMENTARY_FROM_NUMPAD -> setNumpadKeyboard(false, false); + case SWITCH_STATE_MOMENTARY_FROM_NUMPAD -> setNumpadKeyboard(false, false, true); } else if (mSwitchState == SWITCH_STATE_MOMENTARY_TO_NUMPAD) { - toggleNumpad(false, autoCapsFlags, recapitalizeMode, false); + toggleNumpad(false, autoCapsFlags, recapitalizeMode, false, true); } } @@ -802,7 +813,7 @@ public void onEvent(final Event event, final int autoCapsFlags, final int recapi setClipboardKeyboard(); } } else if (code == KeyCode.NUMPAD) { - toggleNumpad(false, autoCapsFlags, recapitalizeMode, false); + toggleNumpad(false, autoCapsFlags, recapitalizeMode, false, true); } else if (code == KeyCode.SYMBOL) { setSymbolsKeyboard(); } else if (code == KeyCode.START_ONE_HANDED_MODE) { From b9527990bbc5ccdfa1d86d18b33dc1de0d4cec2b Mon Sep 17 00:00:00 2001 From: devycarol Date: Mon, 8 Jul 2024 09:56:39 -0600 Subject: [PATCH 10/14] don't change the numpad layout. thus, the numpad key is not intended for use therein; remove toggle logic from the slide. --- app/src/main/assets/layouts/numpad.json | 8 ++++---- .../keyboard/keyboard/internal/KeyboardState.java | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/app/src/main/assets/layouts/numpad.json b/app/src/main/assets/layouts/numpad.json index 0624afe1e..4edfca2f0 100644 --- a/app/src/main/assets/layouts/numpad.json +++ b/app/src/main/assets/layouts/numpad.json @@ -39,12 +39,12 @@ { "label": "delete" } ], [ - { "label": "alpha", "width": 0.15 }, + { "label": "alpha" }, { "label": "comma", "width": 0.1 }, - { "label": "numpad", "width": 0.14 }, + { "label": "symbol", "type": "character", "width": 0.12 }, { "label": "0", "type": "numeric" }, - { "label": "=", "type": "function", "width": 0.14, "popup": { "relevant": [ { "label": "≠"}, { "label": "≈"} ] } }, + { "label": "=", "width": 0.12, "popup": { "relevant": [ { "label": "≠"}, { "label": "≈"} ] } }, { "label": "period", "width": 0.1 }, - { "label": "action", "width": 0.15 } + { "label": "action" } ] ] diff --git a/app/src/main/java/helium314/keyboard/keyboard/internal/KeyboardState.java b/app/src/main/java/helium314/keyboard/keyboard/internal/KeyboardState.java index 79691e6a3..9a8e3ba7c 100644 --- a/app/src/main/java/helium314/keyboard/keyboard/internal/KeyboardState.java +++ b/app/src/main/java/helium314/keyboard/keyboard/internal/KeyboardState.java @@ -514,9 +514,9 @@ public void onReleaseKey(final int code, final boolean withSliding, final int au case KeyCode.SYMBOL -> onReleaseSymbol(withSliding, autoCapsFlags, recapitalizeMode); case KeyCode.ALPHA -> onReleaseAlpha(withSliding, autoCapsFlags, recapitalizeMode); case KeyCode.NUMPAD -> { - // if no sliding, toggling is instead handled by {@link #onEvent} to accomodate toolbar key. + // if no sliding, toggling is instead handled by {@link #onEvent} to accommodate toolbar key. // also prevent sliding into to the clipboard layout, which isn't supported yet. - if (withSliding) toggleNumpad(true, autoCapsFlags, recapitalizeMode, mModeBeforeNumpad == MODE_CLIPBOARD, true); + if (withSliding) setNumpadKeyboard(true, mModeBeforeNumpad == MODE_CLIPBOARD, true); }} } From 60e4ce67848346fa5f1873f1c018c9f4479bdf4b Mon Sep 17 00:00:00 2001 From: devycarol Date: Mon, 8 Jul 2024 10:03:40 -0600 Subject: [PATCH 11/14] don't overwrite toggle state on finish sliding input --- .../helium314/keyboard/keyboard/internal/KeyboardState.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/helium314/keyboard/keyboard/internal/KeyboardState.java b/app/src/main/java/helium314/keyboard/keyboard/internal/KeyboardState.java index 9a8e3ba7c..df11bc61a 100644 --- a/app/src/main/java/helium314/keyboard/keyboard/internal/KeyboardState.java +++ b/app/src/main/java/helium314/keyboard/keyboard/internal/KeyboardState.java @@ -731,9 +731,9 @@ public void onFinishSlidingInput(final int autoCapsFlags, final int recapitalize case SWITCH_STATE_MOMENTARY_ALPHA_AND_SYMBOL -> toggleAlphabetAndSymbols(autoCapsFlags, recapitalizeMode); case SWITCH_STATE_MOMENTARY_SYMBOL_AND_MORE -> toggleShiftInSymbols(); case SWITCH_STATE_MOMENTARY_ALPHA_SHIFT -> setAlphabetKeyboard(autoCapsFlags, recapitalizeMode); - case SWITCH_STATE_MOMENTARY_FROM_NUMPAD -> setNumpadKeyboard(false, false, true); + case SWITCH_STATE_MOMENTARY_FROM_NUMPAD -> setNumpadKeyboard(false, false, false); } else if (mSwitchState == SWITCH_STATE_MOMENTARY_TO_NUMPAD) { - toggleNumpad(false, autoCapsFlags, recapitalizeMode, false, true); + toggleNumpad(false, autoCapsFlags, recapitalizeMode, false, false); } } From d293493c8798a2caf9aa2a0dc2b45b0832ae1681 Mon Sep 17 00:00:00 2001 From: devycarol Date: Mon, 8 Jul 2024 10:31:13 -0600 Subject: [PATCH 12/14] revise comments --- .../helium314/keyboard/keyboard/internal/KeyboardState.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/helium314/keyboard/keyboard/internal/KeyboardState.java b/app/src/main/java/helium314/keyboard/keyboard/internal/KeyboardState.java index df11bc61a..dd13606bc 100644 --- a/app/src/main/java/helium314/keyboard/keyboard/internal/KeyboardState.java +++ b/app/src/main/java/helium314/keyboard/keyboard/internal/KeyboardState.java @@ -207,7 +207,7 @@ private void onRestoreKeyboardState(final int autoCapsFlags, final int recapital return; } if (state.mMode == MODE_NUMPAD) { - // don't overwrite toggle info in this case + // don't overwrite toggle state if reloading from orientation change, etc. setNumpadKeyboard(false, false, false); return; } @@ -515,7 +515,7 @@ public void onReleaseKey(final int code, final boolean withSliding, final int au case KeyCode.ALPHA -> onReleaseAlpha(withSliding, autoCapsFlags, recapitalizeMode); case KeyCode.NUMPAD -> { // if no sliding, toggling is instead handled by {@link #onEvent} to accommodate toolbar key. - // also prevent sliding into to the clipboard layout, which isn't supported yet. + // also prevent sliding to clipboard layout, which isn't supported yet. if (withSliding) setNumpadKeyboard(true, mModeBeforeNumpad == MODE_CLIPBOARD, true); }} } From cd4cd997ad0867e7501964efd322fe60f9b42f5f Mon Sep 17 00:00:00 2001 From: devycarol Date: Mon, 8 Jul 2024 12:41:22 -0600 Subject: [PATCH 13/14] update key backgrounds --- app/src/main/assets/layouts/numpad.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/src/main/assets/layouts/numpad.json b/app/src/main/assets/layouts/numpad.json index 4edfca2f0..d55793233 100644 --- a/app/src/main/assets/layouts/numpad.json +++ b/app/src/main/assets/layouts/numpad.json @@ -41,9 +41,9 @@ [ { "label": "alpha" }, { "label": "comma", "width": 0.1 }, - { "label": "symbol", "type": "character", "width": 0.12 }, + { "label": "symbol", "width": 0.12 }, { "label": "0", "type": "numeric" }, - { "label": "=", "width": 0.12, "popup": { "relevant": [ { "label": "≠"}, { "label": "≈"} ] } }, + { "label": "=", "type": "function", "width": 0.12, "popup": { "relevant": [ { "label": "≠"}, { "label": "≈"} ] } }, { "label": "period", "width": 0.1 }, { "label": "action" } ] From 99dd11f9438933449736f53d2d0727af56406252 Mon Sep 17 00:00:00 2001 From: devycarol Date: Tue, 9 Jul 2024 11:47:49 -0600 Subject: [PATCH 14/14] not translatable --- app/src/main/res/values/strings.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index f940aa422..9cff4bdf7 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -248,7 +248,7 @@ Clipboard Clear clipboard Voice input - @string/layout_numpad + @string/layout_numpad Settings @android:string/selectAll Select word