Skip to content

Commit

Permalink
timeout all keyswipes, but only during fast-typing. because of this, …
Browse files Browse the repository at this point in the history
…delete swipe starts more liberally.
  • Loading branch information
devycarol committed Jun 30, 2024
1 parent 52b9562 commit a30d00c
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 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 Down Expand Up @@ -876,14 +875,15 @@ private void dragFingerOutFromOldKey(final Key oldKey, final int x, final int y)
}
}

private boolean keySwipe(final Key key, final int x, final int y) {
final int code = key.getCode();
private boolean keySwipe(final Key key, final int x, final int y, final long eventTime) {
final SettingsValues sv = Settings.getInstance().getCurrent();
final int fastTypingTimeout = 3 * sv.mKeyLongpressTimeout / 4;
// 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 true;
final int code = key.getCode();
if (code == 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 true;
int dX = x - mStartX;
int dY = y - mStartY;

Expand Down Expand Up @@ -918,7 +918,7 @@ private boolean keySwipe(final Key key, final int x, final int y) {
if (code == KeyCode.DELETE) {
// Delete slider
int steps = (x - mStartX) / sPointerStep;
if (abs(steps) > 2 || (mInHorizontalSwipe && steps != 0)) {
if (steps != 0) {
if (!mInHorizontalSwipe) {
sTimerProxy.cancelKeyTimersOf(this);
mInHorizontalSwipe = true;
Expand All @@ -935,7 +935,7 @@ private void onMoveEventInternal(final int x, final int y, final long eventTime)
final Key oldKey = mCurrentKey;

// todo (later): extend key swipe stuff
if (mKeySwipeAllowed && keySwipe(oldKey, x, y))
if (mKeySwipeAllowed && keySwipe(oldKey, x, y, eventTime))
return;

final Key newKey = onMoveKey(x, y);
Expand Down Expand Up @@ -1206,7 +1206,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

0 comments on commit a30d00c

Please sign in to comment.