diff --git a/app/src/main/java/helium314/keyboard/keyboard/KeyboardActionListener.java b/app/src/main/java/helium314/keyboard/keyboard/KeyboardActionListener.java index 224337f34..e404830c3 100644 --- a/app/src/main/java/helium314/keyboard/keyboard/KeyboardActionListener.java +++ b/app/src/main/java/helium314/keyboard/keyboard/KeyboardActionListener.java @@ -100,7 +100,7 @@ public interface KeyboardActionListener { boolean toggleNumpad(boolean withSliding, boolean forceReturnToAlpha); void onMoveDeletePointer(int steps); - void onUpWithDeletePointerActive(); + void onEndSwipe(int code, boolean vertical); void resetMetaState(); KeyboardActionListener EMPTY_LISTENER = new Adapter(); @@ -150,7 +150,7 @@ public boolean toggleNumpad(boolean withSliding, boolean forceReturnToAlpha) { @Override public void onMoveDeletePointer(int steps) {} @Override - public void onUpWithDeletePointerActive() {} + public void onEndSwipe(int code, boolean vertical) {} @Override public void resetMetaState() {} } diff --git a/app/src/main/java/helium314/keyboard/keyboard/KeyboardActionListenerImpl.kt b/app/src/main/java/helium314/keyboard/keyboard/KeyboardActionListenerImpl.kt index fad78ee8f..41dac9a53 100644 --- a/app/src/main/java/helium314/keyboard/keyboard/KeyboardActionListenerImpl.kt +++ b/app/src/main/java/helium314/keyboard/keyboard/KeyboardActionListenerImpl.kt @@ -14,7 +14,6 @@ import helium314.keyboard.latin.settings.Settings import kotlin.math.abs class KeyboardActionListenerImpl(private val latinIME: LatinIME, private val inputLogic: InputLogic) : KeyboardActionListener { - private val keyboardSwitcher = KeyboardSwitcher.getInstance() private val settings = Settings.getInstance() private var metaState = 0 // is this enough, or are there threading issues with the different PointerTrackers? @@ -89,32 +88,39 @@ class KeyboardActionListenerImpl(private val latinIME: LatinIME, private val inp override fun onMoveDeletePointer(steps: Int) { inputLogic.finishInput() - val end = inputLogic.mConnection.expectedSelectionEnd + val inputConnection = inputLogic.mConnection + val end = inputConnection.expectedSelectionEnd var actualSteps = 0 // corrected steps to avoid splitting chars belonging to the same codepoint if (steps > 0) { - val text = inputLogic.mConnection.getSelectedText(0) + val text = inputConnection.getSelectedText(0) if (text == null) actualSteps = steps else loopOverCodePoints(text) { actualSteps += Character.charCount(it) actualSteps >= steps } } else { - val text = inputLogic.mConnection.getTextBeforeCursor(-steps * 4, 0) + val text = inputConnection.getTextBeforeCursor(-steps * 4, 0) if (text == null) actualSteps = steps else loopOverCodePointsBackwards(text) { actualSteps -= Character.charCount(it) actualSteps <= steps } } - val start = inputLogic.mConnection.expectedSelectionStart + actualSteps + val start = inputConnection.expectedSelectionStart + actualSteps if (start > end) return - inputLogic.mConnection.setSelection(start, end) + inputConnection.setSelection(start, end) } - override fun onUpWithDeletePointerActive() { - if (!inputLogic.mConnection.hasSelection()) return - inputLogic.finishInput() - onCodeInput(KeyCode.DELETE, Constants.NOT_A_COORDINATE, Constants.NOT_A_COORDINATE, false) + override fun onEndSwipe(code: Int, vertical: Boolean) { + when (code) { + // todo: for space, toggle layouts here and not at the beginning of the swipe + // should prevent layout changes when doing android's "swipe down for notifications" + KeyCode.DELETE -> { + if (!inputLogic.mConnection.hasSelection()) return + inputLogic.finishInput() + onCodeInput(KeyCode.DELETE, Constants.NOT_A_COORDINATE, Constants.NOT_A_COORDINATE, false) + } + } } override fun resetMetaState() { @@ -148,10 +154,11 @@ class KeyboardActionListenerImpl(private val latinIME: LatinIME, private val inp if (rawSteps == 0) return false // for RTL languages we want to invert pointer movement val steps = if (RichInputMethodManager.getInstance().currentSubtype.isRtlSubtype) -rawSteps else rawSteps + val inputConnection = inputLogic.mConnection val moveSteps: Int if (steps < 0) { var actualSteps = 0 // corrected steps to avoid splitting chars belonging to the same codepoint - val text = inputLogic.mConnection.getTextBeforeCursor(-steps * 4, 0) ?: return false + val text = inputConnection.getTextBeforeCursor(-steps * 4, 0) ?: return false loopOverCodePointsBackwards(text) { if (StringUtils.mightBeEmoji(it)) { actualSteps = 0 @@ -171,7 +178,7 @@ class KeyboardActionListenerImpl(private val latinIME: LatinIME, private val inp } } else { var actualSteps = 0 // corrected steps to avoid splitting chars belonging to the same codepoint - val text = inputLogic.mConnection.getTextAfterCursor(steps * 4, 0) ?: return false + val text = inputConnection.getTextAfterCursor(steps * 4, 0) ?: return false loopOverCodePoints(text) { if (StringUtils.mightBeEmoji(it)) { actualSteps = 0 @@ -191,13 +198,13 @@ class KeyboardActionListenerImpl(private val latinIME: LatinIME, private val inp if (inputLogic.moveCursorByAndReturnIfInsideComposingWord(moveSteps)) { // no need to finish input and restart suggestions if we're still in the word // this is a noticeable performance improvement - val newPosition = inputLogic.mConnection.expectedSelectionStart + moveSteps - inputLogic.mConnection.setSelection(newPosition, newPosition) + val newPosition = inputConnection.expectedSelectionStart + moveSteps + inputConnection.setSelection(newPosition, newPosition) return true } inputLogic.finishInput() - val newPosition = inputLogic.mConnection.expectedSelectionStart + moveSteps - inputLogic.mConnection.setSelection(newPosition, newPosition) + val newPosition = inputConnection.expectedSelectionStart + moveSteps + inputConnection.setSelection(newPosition, newPosition) inputLogic.restartSuggestionsOnWordTouchedByCursor(settings.current, keyboardSwitcher.currentKeyboardScript) return true } diff --git a/app/src/main/java/helium314/keyboard/keyboard/PointerTracker.java b/app/src/main/java/helium314/keyboard/keyboard/PointerTracker.java index b04286c61..d5a4c994f 100644 --- a/app/src/main/java/helium314/keyboard/keyboard/PointerTracker.java +++ b/app/src/main/java/helium314/keyboard/keyboard/PointerTracker.java @@ -1021,8 +1021,15 @@ private void onUpEventInternal(final int x, final int y, final long eventTime) { // Release the last pressed key. setReleasedKeyGraphics(currentKey, true); - if (mInHorizontalSwipe && currentKey.getCode() == KeyCode.DELETE) { - sListener.onUpWithDeletePointerActive(); + if (mKeySwipeAllowed) { + mKeySwipeAllowed = false; + sInKeySwipe = false; // todo: only make false when no other pointers are in swipes + if (mInHorizontalSwipe || mInVerticalSwipe) { + sListener.onEndSwipe(currentKey.getCode(), mInVerticalSwipe); + mInHorizontalSwipe = false; + mInVerticalSwipe = false; + return; + } } if (isShowingPopupKeysPanel()) { @@ -1037,16 +1044,6 @@ private void onUpEventInternal(final int x, final int y, final long eventTime) { return; } - if (mKeySwipeAllowed) { - mKeySwipeAllowed = false; - sInKeySwipe = false; - if (mInHorizontalSwipe || mInVerticalSwipe) { - mInHorizontalSwipe = false; - mInVerticalSwipe = false; - return; - } - } - if (sInGesture) { if (currentKey != null) { callListenerOnRelease(currentKey, currentKey.getCode(), true);