1
0
Fork 0

Increased the hold duration for virtual keys that also support swiping. It was extremely short and uncontrollable on fast devices

This commit is contained in:
sspanak 2024-09-19 15:16:15 +03:00 committed by Dimo Karaivanov
parent c5f0e47eb5
commit a2651cea62
2 changed files with 59 additions and 16 deletions

View file

@ -24,18 +24,54 @@ public class SoftKeyBackspace extends SwipeableKey {
super(context, attrs, defStyleAttr);
}
private boolean isFastDeleteOn() {
return tt9 != null && tt9.getSettings().getBackspaceAcceleration();
}
/**
* When fast-delete is on, decrease the hold duration threshold for smoother operation.
*/
@Override
protected float getHoldDurationThreshold() {
return isFastDeleteOn() ? SettingsStore.SOFT_KEY_REPEAT_DELAY * 3 : super.getHoldDurationThreshold();
}
/**
* When fast-delete is on, prevent swapping that does nothing. It may feel frustrating if the user
* moves their finger slightly and the key does not delete anything.
*/
@Override
protected float getSwipeXThreshold(Context context) {
return isFastDeleteOn() ? super.getSwipeXThreshold(context) : Integer.MAX_VALUE;
}
/**
* Disable vertical swiping for backspace key.
*/
@Override
protected float getSwipeYThreshold(Context context) {
return Integer.MAX_VALUE;
}
@Override
final protected boolean handlePress() {
super.handlePress();
return deleteText();
}
@Override
final protected void handleHold() {
repeat++;
deleteText();
}
@Override
final protected boolean handleRelease() {
vibrate(repeat > 0 ? Vibration.getReleaseVibration() : Vibration.getNoVibration());
@ -43,6 +79,7 @@ public class SoftKeyBackspace extends SwipeableKey {
return true;
}
@Override
protected void handleEndSwipeX(float position, float delta) {
if (validateTT9Handler()) {
@ -50,6 +87,7 @@ public class SoftKeyBackspace extends SwipeableKey {
}
}
private boolean deleteText() {
if (validateTT9Handler() && !tt9.onBackspace(repeat)) {
// Limited or special numeric field (e.g. formatted money or dates) cannot always return
@ -62,16 +100,19 @@ public class SoftKeyBackspace extends SwipeableKey {
return false;
}
@Override
protected int getNoEmojiTitle() {
return R.string.virtual_key_del;
}
@Override
protected String getTitle() {
return LanguageKind.isRTL(tt9 != null ? tt9.getLanguage() : null) ? "" : "";
}
@Override
public void render() {
super.render();

View file

@ -25,36 +25,30 @@ abstract public class SwipeableKey extends SoftKey {
public SwipeableKey(Context context) {
super(context);
init(context);
resetTimeThresholds(context);
}
public SwipeableKey(Context context, AttributeSet attrs) {
super(context, attrs);
init(context);
resetTimeThresholds(context);
}
public SwipeableKey(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
init(context);
resetTimeThresholds(context);
}
private void init(Context context) {
if (HOLD_DURATION_THRESHOLD == 0) {
protected final void resetTimeThresholds(Context context) {
HOLD_DURATION_THRESHOLD = getHoldDurationThreshold();
}
if (SWIPE_X_THRESHOLD == 0) {
SWIPE_X_THRESHOLD = getSwipeXThreshold(context);
}
if (SWIPE_Y_THRESHOLD == 0) {
SWIPE_Y_THRESHOLD = getSwipeYThreshold(context);
}
}
protected float getHoldDurationThreshold() { return SettingsStore.SOFT_KEY_REPEAT_DELAY * 3; }
protected float getHoldDurationThreshold() { return SettingsStore.SOFT_KEY_REPEAT_DELAY * 9; }
protected float getSwipeXThreshold(Context context) { return context.getResources().getDimensionPixelSize(R.dimen.numpad_key_height) / 10.0f; }
protected float getSwipeYThreshold(Context context) { return context.getResources().getDimensionPixelSize(R.dimen.numpad_key_height) / 10.0f; }
@ -80,11 +74,11 @@ abstract public class SwipeableKey extends SoftKey {
@Override
public boolean onLongClick(View view) {
if (System.currentTimeMillis() - startTime < HOLD_DURATION_THRESHOLD) {
return true;
return false;
}
isHolding = !isSwipingY && !isSwipingX;
return isSwipingY || isSwipingX || super.onLongClick(view);
return !isHolding || super.onLongClick(view);
}
@ -143,4 +137,12 @@ abstract public class SwipeableKey extends SoftKey {
protected void handleEndSwipeX(float position, float delta) {}
protected void handleEndSwipeY(float position, float delta) {}
protected boolean notSwiped() { return notSwiped; }
@Override
public void render() {
// readjust the action detection delays for keys that set them dynamically
resetTimeThresholds(getContext());
super.render();
}
}