mirror of
https://github.com/Helium314/HeliBoard.git
synced 2025-04-23 07:39:11 +00:00
create flexible onEndSwipe method
This commit is contained in:
parent
c0c11d75b2
commit
0d79d1a79c
3 changed files with 34 additions and 30 deletions
|
@ -100,7 +100,7 @@ public interface KeyboardActionListener {
|
||||||
boolean toggleNumpad(boolean withSliding, boolean forceReturnToAlpha);
|
boolean toggleNumpad(boolean withSliding, boolean forceReturnToAlpha);
|
||||||
|
|
||||||
void onMoveDeletePointer(int steps);
|
void onMoveDeletePointer(int steps);
|
||||||
void onUpWithDeletePointerActive();
|
void onEndSwipe(int code, boolean vertical);
|
||||||
void resetMetaState();
|
void resetMetaState();
|
||||||
|
|
||||||
KeyboardActionListener EMPTY_LISTENER = new Adapter();
|
KeyboardActionListener EMPTY_LISTENER = new Adapter();
|
||||||
|
@ -150,7 +150,7 @@ public interface KeyboardActionListener {
|
||||||
@Override
|
@Override
|
||||||
public void onMoveDeletePointer(int steps) {}
|
public void onMoveDeletePointer(int steps) {}
|
||||||
@Override
|
@Override
|
||||||
public void onUpWithDeletePointerActive() {}
|
public void onEndSwipe(int code, boolean vertical) {}
|
||||||
@Override
|
@Override
|
||||||
public void resetMetaState() {}
|
public void resetMetaState() {}
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,7 +14,6 @@ import helium314.keyboard.latin.settings.Settings
|
||||||
import kotlin.math.abs
|
import kotlin.math.abs
|
||||||
|
|
||||||
class KeyboardActionListenerImpl(private val latinIME: LatinIME, private val inputLogic: InputLogic) : KeyboardActionListener {
|
class KeyboardActionListenerImpl(private val latinIME: LatinIME, private val inputLogic: InputLogic) : KeyboardActionListener {
|
||||||
|
|
||||||
private val keyboardSwitcher = KeyboardSwitcher.getInstance()
|
private val keyboardSwitcher = KeyboardSwitcher.getInstance()
|
||||||
private val settings = Settings.getInstance()
|
private val settings = Settings.getInstance()
|
||||||
private var metaState = 0 // is this enough, or are there threading issues with the different PointerTrackers?
|
private var metaState = 0 // is this enough, or are there threading issues with the different PointerTrackers?
|
||||||
|
@ -89,33 +88,40 @@ class KeyboardActionListenerImpl(private val latinIME: LatinIME, private val inp
|
||||||
|
|
||||||
override fun onMoveDeletePointer(steps: Int) {
|
override fun onMoveDeletePointer(steps: Int) {
|
||||||
inputLogic.finishInput()
|
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
|
var actualSteps = 0 // corrected steps to avoid splitting chars belonging to the same codepoint
|
||||||
if (steps > 0) {
|
if (steps > 0) {
|
||||||
val text = inputLogic.mConnection.getSelectedText(0)
|
val text = inputConnection.getSelectedText(0)
|
||||||
if (text == null) actualSteps = steps
|
if (text == null) actualSteps = steps
|
||||||
else loopOverCodePoints(text) {
|
else loopOverCodePoints(text) {
|
||||||
actualSteps += Character.charCount(it)
|
actualSteps += Character.charCount(it)
|
||||||
actualSteps >= steps
|
actualSteps >= steps
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
val text = inputLogic.mConnection.getTextBeforeCursor(-steps * 4, 0)
|
val text = inputConnection.getTextBeforeCursor(-steps * 4, 0)
|
||||||
if (text == null) actualSteps = steps
|
if (text == null) actualSteps = steps
|
||||||
else loopOverCodePointsBackwards(text) {
|
else loopOverCodePointsBackwards(text) {
|
||||||
actualSteps -= Character.charCount(it)
|
actualSteps -= Character.charCount(it)
|
||||||
actualSteps <= steps
|
actualSteps <= steps
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
val start = inputLogic.mConnection.expectedSelectionStart + actualSteps
|
val start = inputConnection.expectedSelectionStart + actualSteps
|
||||||
if (start > end) return
|
if (start > end) return
|
||||||
inputLogic.mConnection.setSelection(start, end)
|
inputConnection.setSelection(start, end)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onUpWithDeletePointerActive() {
|
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
|
if (!inputLogic.mConnection.hasSelection()) return
|
||||||
inputLogic.finishInput()
|
inputLogic.finishInput()
|
||||||
onCodeInput(KeyCode.DELETE, Constants.NOT_A_COORDINATE, Constants.NOT_A_COORDINATE, false)
|
onCodeInput(KeyCode.DELETE, Constants.NOT_A_COORDINATE, Constants.NOT_A_COORDINATE, false)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
override fun resetMetaState() {
|
override fun resetMetaState() {
|
||||||
metaState = 0
|
metaState = 0
|
||||||
|
@ -148,10 +154,11 @@ class KeyboardActionListenerImpl(private val latinIME: LatinIME, private val inp
|
||||||
if (rawSteps == 0) return false
|
if (rawSteps == 0) return false
|
||||||
// for RTL languages we want to invert pointer movement
|
// for RTL languages we want to invert pointer movement
|
||||||
val steps = if (RichInputMethodManager.getInstance().currentSubtype.isRtlSubtype) -rawSteps else rawSteps
|
val steps = if (RichInputMethodManager.getInstance().currentSubtype.isRtlSubtype) -rawSteps else rawSteps
|
||||||
|
val inputConnection = inputLogic.mConnection
|
||||||
val moveSteps: Int
|
val moveSteps: Int
|
||||||
if (steps < 0) {
|
if (steps < 0) {
|
||||||
var actualSteps = 0 // corrected steps to avoid splitting chars belonging to the same codepoint
|
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) {
|
loopOverCodePointsBackwards(text) {
|
||||||
if (StringUtils.mightBeEmoji(it)) {
|
if (StringUtils.mightBeEmoji(it)) {
|
||||||
actualSteps = 0
|
actualSteps = 0
|
||||||
|
@ -171,7 +178,7 @@ class KeyboardActionListenerImpl(private val latinIME: LatinIME, private val inp
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
var actualSteps = 0 // corrected steps to avoid splitting chars belonging to the same codepoint
|
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) {
|
loopOverCodePoints(text) {
|
||||||
if (StringUtils.mightBeEmoji(it)) {
|
if (StringUtils.mightBeEmoji(it)) {
|
||||||
actualSteps = 0
|
actualSteps = 0
|
||||||
|
@ -191,13 +198,13 @@ class KeyboardActionListenerImpl(private val latinIME: LatinIME, private val inp
|
||||||
if (inputLogic.moveCursorByAndReturnIfInsideComposingWord(moveSteps)) {
|
if (inputLogic.moveCursorByAndReturnIfInsideComposingWord(moveSteps)) {
|
||||||
// no need to finish input and restart suggestions if we're still in the word
|
// no need to finish input and restart suggestions if we're still in the word
|
||||||
// this is a noticeable performance improvement
|
// this is a noticeable performance improvement
|
||||||
val newPosition = inputLogic.mConnection.expectedSelectionStart + moveSteps
|
val newPosition = inputConnection.expectedSelectionStart + moveSteps
|
||||||
inputLogic.mConnection.setSelection(newPosition, newPosition)
|
inputConnection.setSelection(newPosition, newPosition)
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
inputLogic.finishInput()
|
inputLogic.finishInput()
|
||||||
val newPosition = inputLogic.mConnection.expectedSelectionStart + moveSteps
|
val newPosition = inputConnection.expectedSelectionStart + moveSteps
|
||||||
inputLogic.mConnection.setSelection(newPosition, newPosition)
|
inputConnection.setSelection(newPosition, newPosition)
|
||||||
inputLogic.restartSuggestionsOnWordTouchedByCursor(settings.current, keyboardSwitcher.currentKeyboardScript)
|
inputLogic.restartSuggestionsOnWordTouchedByCursor(settings.current, keyboardSwitcher.currentKeyboardScript)
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
|
@ -1021,8 +1021,15 @@ public final class PointerTracker implements PointerTrackerQueue.Element,
|
||||||
// Release the last pressed key.
|
// Release the last pressed key.
|
||||||
setReleasedKeyGraphics(currentKey, true);
|
setReleasedKeyGraphics(currentKey, true);
|
||||||
|
|
||||||
if (mInHorizontalSwipe && currentKey.getCode() == KeyCode.DELETE) {
|
if (mKeySwipeAllowed) {
|
||||||
sListener.onUpWithDeletePointerActive();
|
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()) {
|
if (isShowingPopupKeysPanel()) {
|
||||||
|
@ -1037,16 +1044,6 @@ public final class PointerTracker implements PointerTrackerQueue.Element,
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mKeySwipeAllowed) {
|
|
||||||
mKeySwipeAllowed = false;
|
|
||||||
sInKeySwipe = false;
|
|
||||||
if (mInHorizontalSwipe || mInVerticalSwipe) {
|
|
||||||
mInHorizontalSwipe = false;
|
|
||||||
mInVerticalSwipe = false;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (sInGesture) {
|
if (sInGesture) {
|
||||||
if (currentKey != null) {
|
if (currentKey != null) {
|
||||||
callListenerOnRelease(currentKey, currentKey.getCode(), true);
|
callListenerOnRelease(currentKey, currentKey.getCode(), true);
|
||||||
|
|
Loading…
Add table
Reference in a new issue