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:
parent
c5f0e47eb5
commit
a2651cea62
2 changed files with 59 additions and 16 deletions
|
|
@ -24,18 +24,54 @@ public class SoftKeyBackspace extends SwipeableKey {
|
||||||
super(context, attrs, defStyleAttr);
|
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
|
@Override
|
||||||
final protected boolean handlePress() {
|
final protected boolean handlePress() {
|
||||||
super.handlePress();
|
super.handlePress();
|
||||||
return deleteText();
|
return deleteText();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
final protected void handleHold() {
|
final protected void handleHold() {
|
||||||
repeat++;
|
repeat++;
|
||||||
deleteText();
|
deleteText();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
final protected boolean handleRelease() {
|
final protected boolean handleRelease() {
|
||||||
vibrate(repeat > 0 ? Vibration.getReleaseVibration() : Vibration.getNoVibration());
|
vibrate(repeat > 0 ? Vibration.getReleaseVibration() : Vibration.getNoVibration());
|
||||||
|
|
@ -43,6 +79,7 @@ public class SoftKeyBackspace extends SwipeableKey {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void handleEndSwipeX(float position, float delta) {
|
protected void handleEndSwipeX(float position, float delta) {
|
||||||
if (validateTT9Handler()) {
|
if (validateTT9Handler()) {
|
||||||
|
|
@ -50,6 +87,7 @@ public class SoftKeyBackspace extends SwipeableKey {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private boolean deleteText() {
|
private boolean deleteText() {
|
||||||
if (validateTT9Handler() && !tt9.onBackspace(repeat)) {
|
if (validateTT9Handler() && !tt9.onBackspace(repeat)) {
|
||||||
// Limited or special numeric field (e.g. formatted money or dates) cannot always return
|
// 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;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected int getNoEmojiTitle() {
|
protected int getNoEmojiTitle() {
|
||||||
return R.string.virtual_key_del;
|
return R.string.virtual_key_del;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected String getTitle() {
|
protected String getTitle() {
|
||||||
return LanguageKind.isRTL(tt9 != null ? tt9.getLanguage() : null) ? "⌦" : "⌫";
|
return LanguageKind.isRTL(tt9 != null ? tt9.getLanguage() : null) ? "⌦" : "⌫";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void render() {
|
public void render() {
|
||||||
super.render();
|
super.render();
|
||||||
|
|
|
||||||
|
|
@ -25,36 +25,30 @@ abstract public class SwipeableKey extends SoftKey {
|
||||||
|
|
||||||
public SwipeableKey(Context context) {
|
public SwipeableKey(Context context) {
|
||||||
super(context);
|
super(context);
|
||||||
init(context);
|
resetTimeThresholds(context);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public SwipeableKey(Context context, AttributeSet attrs) {
|
public SwipeableKey(Context context, AttributeSet attrs) {
|
||||||
super(context, attrs);
|
super(context, attrs);
|
||||||
init(context);
|
resetTimeThresholds(context);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public SwipeableKey(Context context, AttributeSet attrs, int defStyleAttr) {
|
public SwipeableKey(Context context, AttributeSet attrs, int defStyleAttr) {
|
||||||
super(context, attrs, defStyleAttr);
|
super(context, attrs, defStyleAttr);
|
||||||
init(context);
|
resetTimeThresholds(context);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private void init(Context context) {
|
protected final void resetTimeThresholds(Context context) {
|
||||||
if (HOLD_DURATION_THRESHOLD == 0) {
|
|
||||||
HOLD_DURATION_THRESHOLD = getHoldDurationThreshold();
|
HOLD_DURATION_THRESHOLD = getHoldDurationThreshold();
|
||||||
}
|
|
||||||
if (SWIPE_X_THRESHOLD == 0) {
|
|
||||||
SWIPE_X_THRESHOLD = getSwipeXThreshold(context);
|
SWIPE_X_THRESHOLD = getSwipeXThreshold(context);
|
||||||
}
|
|
||||||
if (SWIPE_Y_THRESHOLD == 0) {
|
|
||||||
SWIPE_Y_THRESHOLD = getSwipeYThreshold(context);
|
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 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; }
|
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
|
@Override
|
||||||
public boolean onLongClick(View view) {
|
public boolean onLongClick(View view) {
|
||||||
if (System.currentTimeMillis() - startTime < HOLD_DURATION_THRESHOLD) {
|
if (System.currentTimeMillis() - startTime < HOLD_DURATION_THRESHOLD) {
|
||||||
return true;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
isHolding = !isSwipingY && !isSwipingX;
|
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 handleEndSwipeX(float position, float delta) {}
|
||||||
protected void handleEndSwipeY(float position, float delta) {}
|
protected void handleEndSwipeY(float position, float delta) {}
|
||||||
protected boolean notSwiped() { return notSwiped; }
|
protected boolean notSwiped() { return notSwiped; }
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void render() {
|
||||||
|
// readjust the action detection delays for keys that set them dynamically
|
||||||
|
resetTimeThresholds(getContext());
|
||||||
|
super.render();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue