Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix erroneous keyswipes #919

Merged
merged 24 commits into from
Jul 5, 2024
Merged
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
9abdd6a
fix the pop-up keys into keyswipe bug and make keyswipe handling a se…
devycarol Jun 27, 2024
987eae7
continue move event as normal if the user doesn't have a space bar ge…
devycarol Jun 27, 2024
eea9d6a
name can be shortened
devycarol Jun 27, 2024
de75123
also require that there not be a repeating key
devycarol Jun 27, 2024
825eef7
determination can be more concise
devycarol Jun 27, 2024
ce57612
only allow keyswipe if it was the initial key that was pressed
devycarol Jun 30, 2024
2e3e83d
cancel the longpress timers directly
devycarol Jun 30, 2024
e90e004
timeout all keyswipes, but only during fast-typing. because of this, …
devycarol Jun 30, 2024
2325206
just use code for now
devycarol Jun 30, 2024
f842504
clarity
devycarol Jun 30, 2024
b02854b
devycarol Jun 30, 2024
c050053
clarify todo
devycarol Jun 30, 2024
fab8750
initialize as false
devycarol Jun 30, 2024
81cf7dc
warranted…spam
devycarol Jun 30, 2024
5994846
if no horizontal gesture is set, subsequent vertical movement should …
devycarol Jun 30, 2024
feb1745
fix keyswipes freezing above the keyboard
devycarol Jun 30, 2024
6f589a2
doesn't need to be a boolean after all
devycarol Jul 2, 2024
6c09b97
disallow keyswipes when another pointer is doing a word gesture
devycarol Jul 3, 2024
e989d74
disallow word gestures when a keyswipe is occurring
devycarol Jul 3, 2024
af1149f
Revert: unable to disallow word gestures when a keyswipe is occurring
devycarol Jul 3, 2024
0e6ad88
Redo: disallow word gestures when a keyswipe is occurring
devycarol Jul 3, 2024
9431870
account for simultaneous down-events
devycarol Jul 3, 2024
bd662e4
Merge branch 'Helium314:main' into fix-popup-panel-keyswipes
devycarol Jul 3, 2024
6ee2c47
reinstate the directional swipe-start restriction for a space bar wit…
devycarol Jul 4, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
99 changes: 68 additions & 31 deletions app/src/main/java/helium314/keyboard/keyboard/PointerTracker.java
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,6 @@ public PointerTrackerParams(final TypedArray mainKeyboardViewAttr) {
// the popup keys panel currently being shown. equals null if no panel is active.
private PopupKeysPanel mPopupKeysPanel;

private static final int MULTIPLIER_FOR_LONG_PRESS_TIMEOUT_IN_SLIDING_INPUT = 3;
// true if this pointer is in the dragging finger mode.
boolean mIsInDraggingFinger;
// true if this pointer is sliding from a modifier key and in the sliding key input mode,
Expand All @@ -142,6 +141,9 @@ public PointerTrackerParams(final TypedArray mainKeyboardViewAttr) {

// true if dragging finger is allowed.
private boolean mIsAllowedDraggingFinger;
// true if a keyswipe gesture is enabled and warranted.
private boolean mKeySwipeAllowed = false;
private static boolean sInKeySwipe = false;

private final BatchInputArbiter mBatchInputArbiter;
private final GestureStrokeDrawingPoints mGestureStrokeDrawingPoints;
Expand Down Expand Up @@ -637,7 +639,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()
&& key != null && !key.isModifier();
&& key != null && !key.isModifier() && !mKeySwipeAllowed && !sInKeySwipe;
if (mIsDetectingGesture) {
mBatchInputArbiter.addDownEventPoint(x, y, eventTime,
sTypingTimeRecorder.getLastLetterTypingTime(), getActivePointerTrackerCount());
Expand Down Expand Up @@ -666,6 +668,10 @@ private void onDownEventInternal(final int x, final int y, final long eventTime)
mIsAllowedDraggingFinger = sParams.mKeySelectionByDraggingFinger
|| (key != null && key.isModifier())
|| mKeyDetector.alwaysAllowsKeySelectionByDraggingFinger();
if (key != null && isSwiper(key.getCode()) && !sInGesture) {
mKeySwipeAllowed = true;
sInKeySwipe = true;
}
mKeyboardLayoutHasBeenChanged = false;
mIsTrackingForActionDisabled = false;
resetKeySelectionByDraggingFinger();
Expand Down Expand Up @@ -704,9 +710,19 @@ private void resetKeySelectionByDraggingFinger() {
sDrawingProxy.showSlidingKeyInputPreview(null);
}

private boolean isSwiper(final int code) {
final SettingsValues sv = Settings.getInstance().getCurrent();
return switch (code) {
case Constants.CODE_SPACE -> sv.mSpaceSwipeHorizontal != KeyboardActionListener.SWIPE_NO_ACTION
|| sv.mSpaceSwipeVertical != KeyboardActionListener.SWIPE_NO_ACTION;
case KeyCode.DELETE -> sv.mDeleteSwipeEnabled;
default -> false;
};
}

private void onGestureMoveEvent(final int x, final int y, final long eventTime,
final boolean isMajorEvent, final Key key) {
if (!mIsDetectingGesture) {
if (!mIsDetectingGesture || sInKeySwipe) {
return;
}
final boolean onValidArea = mBatchInputArbiter.addMoveEventPoint(
Expand Down Expand Up @@ -863,23 +879,24 @@ private void dragFingerOutFromOldKey(final Key oldKey, final int x, final int y)
}
}

private void onMoveEventInternal(final int x, final int y, final long eventTime) {
final Key oldKey = mCurrentKey;
private void onKeySwipe(final int code, final int x, final int y, final long eventTime) {
final SettingsValues sv = Settings.getInstance().getCurrent();

// todo (later): move key swipe stuff to a separate function (and finally extend it)
if (!mIsInSlidingKeyInput && oldKey != null && oldKey.getCode() == Constants.CODE_SPACE) {
// reason for timeout: https://github.com/openboard-team/openboard/issues/411
final int longpressTimeout = 2 * sv.mKeyLongpressTimeout / MULTIPLIER_FOR_LONG_PRESS_TIMEOUT_IN_SLIDING_INPUT;
if (mStartTime + longpressTimeout > System.currentTimeMillis())
return;
final int fastTypingTimeout = 2 * sv.mKeyLongpressTimeout / 3;
// we don't want keyswipes to start immediately if the user is fast-typing,
// see https://github.com/openboard-team/openboard/issues/411
if (System.currentTimeMillis() < mStartTime + fastTypingTimeout && sTypingTimeRecorder.isInFastTyping(eventTime))
return;
if (code == Constants.CODE_SPACE) {
int dX = x - mStartX;
int dY = y - mStartY;

// vertical movement
// Vertical movement
int stepsY = dY / sPointerStep;
if (stepsY != 0 && abs(dX) < abs(dY) && !mInHorizontalSwipe) {
mInVerticalSwipe = true;
if (!mInVerticalSwipe) {
sTimerProxy.cancelKeyTimersOf(this);
mInVerticalSwipe = true;
}
if (sListener.onVerticalSpaceSwipe(stepsY)) {
mStartY += stepsY * sPointerStep;
}
Expand All @@ -889,23 +906,34 @@ private void onMoveEventInternal(final int x, final int y, final long eventTime)
// Horizontal movement
int stepsX = dX / sPointerStep;
if (stepsX != 0 && !mInVerticalSwipe) {
mInHorizontalSwipe = true;
if (!mInHorizontalSwipe) {
sTimerProxy.cancelKeyTimersOf(this);
mInHorizontalSwipe = true;
}
if (sListener.onHorizontalSpaceSwipe(stepsX)) {
mStartX += stepsX * sPointerStep;
}
}
return;
}

if (!mIsInSlidingKeyInput && oldKey != null && oldKey.getCode() == KeyCode.DELETE && sv.mDeleteSwipeEnabled) {
} else if (code == KeyCode.DELETE) {
// Delete slider
int steps = (x - mStartX) / sPointerStep;
if (abs(steps) > 2 || (mInHorizontalSwipe && steps != 0)) {
sTimerProxy.cancelKeyTimersOf(this);
mInHorizontalSwipe = true;
if (steps != 0) {
if (!mInHorizontalSwipe) {
sTimerProxy.cancelKeyTimersOf(this);
mInHorizontalSwipe = true;
}
mStartX += steps * sPointerStep;
sListener.onMoveDeletePointer(steps);
}
}
}

private void onMoveEventInternal(final int x, final int y, final long eventTime) {
final Key oldKey = mCurrentKey;

// todo (later): move key swipe stuff to KeyboardActionListener (and finally extend it)
if (mKeySwipeAllowed) {
onKeySwipe(oldKey.getCode(), x, y, eventTime);
return;
}

Expand Down Expand Up @@ -985,7 +1013,7 @@ 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) {
if (mInHorizontalSwipe && currentKey.getCode() == KeyCode.DELETE) {
sListener.onUpWithDeletePointerActive();
}

Expand All @@ -1001,10 +1029,14 @@ private void onUpEventInternal(final int x, final int y, final long eventTime) {
return;
}

if (mInHorizontalSwipe || mInVerticalSwipe) {
mInHorizontalSwipe = false;
mInVerticalSwipe = false;
return;
if (mKeySwipeAllowed) {
mKeySwipeAllowed = false;
sInKeySwipe = false;
if (mInHorizontalSwipe || mInVerticalSwipe) {
mInHorizontalSwipe = false;
mInVerticalSwipe = false;
return;
}
}

if (sInGesture) {
Expand Down Expand Up @@ -1049,9 +1081,6 @@ public void onLongPressed() {
if (isShowingPopupKeysPanel()) {
return;
}
if(mInHorizontalSwipe || mInVerticalSwipe) {
return;
}
final Key key = getKey();
if (key == null) {
return;
Expand Down Expand Up @@ -1093,6 +1122,10 @@ public void onLongPressed() {
final int translatedY = popupKeysPanel.translateY(mLastY);
popupKeysPanel.onDownEvent(translatedX, translatedY, mPointerId, SystemClock.uptimeMillis());
mPopupKeysPanel = popupKeysPanel;
if (mKeySwipeAllowed) {
mKeySwipeAllowed = false;
sInKeySwipe = false;
}
}

private void cancelKeyTracking() {
Expand Down Expand Up @@ -1179,7 +1212,7 @@ private int getLongPressTimeout(final int code) {
return longpressTimeout * 3 / 2;
} else if (mIsInSlidingKeyInput) {
// We use longer timeout for sliding finger input started from a modifier key.
return longpressTimeout * MULTIPLIER_FOR_LONG_PRESS_TIMEOUT_IN_SLIDING_INPUT;
return longpressTimeout * 3;
}
return longpressTimeout;
}
Expand Down Expand Up @@ -1218,6 +1251,10 @@ public void onKeyRepeat(final int code, final int repeatCount) {
return;
}
mCurrentRepeatingKeyCode = code;
if (mKeySwipeAllowed) {
mKeySwipeAllowed = false;
sInKeySwipe = false;
}
mIsDetectingGesture = false;
final int nextRepeatCount = repeatCount + 1;
startKeyRepeatTimer(nextRepeatCount);
Expand Down