fixed SoftKey repeat sometimes being too fast
This commit is contained in:
parent
16a8cc8b70
commit
0228c5fd81
8 changed files with 37 additions and 32 deletions
|
|
@ -9,7 +9,6 @@ public class SettingsStore extends SettingsUI {
|
|||
/************* internal settings *************/
|
||||
public static final int BACKSPACE_ACCELERATION_MAX_CHARS = 10;
|
||||
public static final int BACKSPACE_ACCELERATION_HARD_KEY_REPEAT_DEBOUNCE = 5;
|
||||
public static final int BACKSPACE_ACCELERATION_SOFT_KEY_REPEAT_DEBOUNCE = 7;
|
||||
public final static int CLIPBOARD_PREVIEW_LENGTH = 20;
|
||||
public final static int CUSTOM_WORDS_IMPORT_MAX_LINES = 250;
|
||||
public final static int CUSTOM_WORDS_MAX = 1000;
|
||||
|
|
@ -23,6 +22,7 @@ public class SettingsStore extends SettingsUI {
|
|||
public final static byte SLOW_QUERY_TIME = 50; // ms
|
||||
public final static int SOFT_KEY_DOUBLE_CLICK_DELAY = 500; // ms
|
||||
public final static int SOFT_KEY_REPEAT_DELAY = 40; // ms
|
||||
public final static int SOFT_KEY_BACKSPACE_ACCELERATION_REPEAT_DELAY = SOFT_KEY_REPEAT_DELAY * BACKSPACE_ACCELERATION_HARD_KEY_REPEAT_DEBOUNCE; // ms
|
||||
public final static int SOFT_KEY_TITLE_SIZE = 18; // sp
|
||||
public final static float SOFT_KEY_COMPLEX_LABEL_TITLE_RELATIVE_SIZE = 0.55f;
|
||||
public final static float SOFT_KEY_COMPLEX_LABEL_ARABIC_TITLE_RELATIVE_SIZE = 0.72f;
|
||||
|
|
|
|||
|
|
@ -11,7 +11,6 @@ import io.github.sspanak.tt9.ui.Vibration;
|
|||
|
||||
public class SoftBackspaceKey extends SoftKey {
|
||||
private boolean hold;
|
||||
private int repeatCount = 0;
|
||||
|
||||
public SoftBackspaceKey(Context context) {
|
||||
super(context);
|
||||
|
|
@ -29,23 +28,12 @@ public class SoftBackspaceKey extends SoftKey {
|
|||
final protected boolean handlePress() {
|
||||
super.handlePress();
|
||||
hold = false;
|
||||
repeatCount = 0;
|
||||
return validateTT9Handler() && deleteText();
|
||||
return deleteText();
|
||||
}
|
||||
|
||||
@Override
|
||||
final protected void handleHold() {
|
||||
hold = true;
|
||||
|
||||
if (
|
||||
validateTT9Handler()
|
||||
&& tt9.getSettings().getBackspaceAcceleration()
|
||||
&& ++repeatCount < SettingsStore.BACKSPACE_ACCELERATION_SOFT_KEY_REPEAT_DEBOUNCE
|
||||
) {
|
||||
return;
|
||||
}
|
||||
|
||||
repeatCount = 0;
|
||||
deleteText();
|
||||
}
|
||||
|
||||
|
|
@ -56,8 +44,13 @@ public class SoftBackspaceKey extends SoftKey {
|
|||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
final protected int getLongPressRepeatDelay() {
|
||||
return tt9 != null && tt9.getSettings().getBackspaceAcceleration() ? SettingsStore.SOFT_KEY_BACKSPACE_ACCELERATION_REPEAT_DELAY : super.getLongPressRepeatDelay();
|
||||
}
|
||||
|
||||
private boolean deleteText() {
|
||||
if (!tt9.onBackspace(hold && tt9.getSettings().getBackspaceAcceleration())) {
|
||||
if (validateTT9Handler() && !tt9.onBackspace(hold && tt9.getSettings().getBackspaceAcceleration())) {
|
||||
// Limited or special numeric field (e.g. formatted money or dates) cannot always return
|
||||
// the text length, therefore onBackspace() seems them as empty and does nothing. This results
|
||||
// in fallback to the default hardware key action. Here we simulate the hardware BACKSPACE.
|
||||
|
|
|
|||
|
|
@ -19,7 +19,9 @@ public class SoftCommandKey extends SoftNumberKey {
|
|||
public SoftCommandKey(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr);}
|
||||
|
||||
|
||||
@Override protected void handleHold() {}
|
||||
@Override protected void handleHold() {
|
||||
preventRepeat();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -34,6 +34,7 @@ public class SoftKey extends androidx.appcompat.widget.AppCompatButton implement
|
|||
|
||||
private boolean hold = false;
|
||||
private boolean repeat = false;
|
||||
private long lastLongClickTime = 0;
|
||||
private final Handler repeatHandler = new Handler(Looper.getMainLooper());
|
||||
private static int lastPressedKey = -1;
|
||||
|
||||
|
|
@ -98,11 +99,15 @@ public class SoftKey extends androidx.appcompat.widget.AppCompatButton implement
|
|||
|
||||
@Override
|
||||
public boolean onLongClick(View view) {
|
||||
hold = true;
|
||||
|
||||
// sometimes this gets called twice, so we debounce the call to the repeating function
|
||||
repeatHandler.removeCallbacks(this::repeatOnLongPress);
|
||||
repeatHandler.postDelayed(this::repeatOnLongPress, 5);
|
||||
final long now = System.currentTimeMillis();
|
||||
if (now - lastLongClickTime < SettingsStore.SOFT_KEY_DOUBLE_CLICK_DELAY) {
|
||||
return false;
|
||||
}
|
||||
|
||||
hold = true;
|
||||
lastLongClickTime = now;
|
||||
repeatOnLongPress();
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
@ -112,21 +117,25 @@ public class SoftKey extends androidx.appcompat.widget.AppCompatButton implement
|
|||
* Repeatedly calls "handleHold()" upon holding the respective SoftKey, to simulate physical keyboard behavior.
|
||||
*/
|
||||
private void repeatOnLongPress() {
|
||||
if (!validateTT9Handler()) {
|
||||
hold = false;
|
||||
return;
|
||||
}
|
||||
|
||||
if (hold) {
|
||||
repeat = true;
|
||||
handleHold();
|
||||
lastPressedKey = getId();
|
||||
repeatHandler.removeCallbacks(this::repeatOnLongPress);
|
||||
repeatHandler.postDelayed(this::repeatOnLongPress, SettingsStore.SOFT_KEY_REPEAT_DELAY);
|
||||
repeatHandler.postDelayed(this::repeatOnLongPress, getLongPressRepeatDelay());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns the delay between repeated calls to "handleHold()" when the SoftKey is being held.
|
||||
* Used in "repeatOnLongPress()".
|
||||
*/
|
||||
protected int getLongPressRepeatDelay() {
|
||||
return SettingsStore.SOFT_KEY_REPEAT_DELAY;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* preventRepeat
|
||||
* Prevents "handleHold()" from being called repeatedly when the SoftKey is being held.
|
||||
|
|
|
|||
|
|
@ -13,11 +13,12 @@ public class SoftKeyLF2 extends SoftKey {
|
|||
|
||||
@Override
|
||||
protected void handleHold() {
|
||||
preventRepeat();
|
||||
|
||||
if (!validateTT9Handler()) {
|
||||
return;
|
||||
}
|
||||
|
||||
preventRepeat();
|
||||
vibrate(Vibration.getHoldVibration());
|
||||
tt9.addWord();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -30,12 +30,12 @@ public class SoftKeyRF3 extends SoftKey {
|
|||
|
||||
@Override
|
||||
protected void handleHold() {
|
||||
preventRepeat();
|
||||
|
||||
if (!validateTT9Handler() || isTextEdtingActive()) {
|
||||
return;
|
||||
}
|
||||
|
||||
preventRepeat();
|
||||
|
||||
if (tt9.isVoiceInputActive()) {
|
||||
tt9.toggleVoiceInput();
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -30,13 +30,13 @@ public class SoftNumberKey extends SoftKey {
|
|||
|
||||
@Override
|
||||
protected void handleHold() {
|
||||
preventRepeat();
|
||||
|
||||
int keyCode = Key.numberToCode(getUpsideDownNumber(getId()));
|
||||
if (keyCode < 0 || !validateTT9Handler()) {
|
||||
return;
|
||||
}
|
||||
|
||||
preventRepeat();
|
||||
|
||||
vibrate(Vibration.getHoldVibration());
|
||||
tt9.onKeyLongPress(keyCode, new KeyEvent(KeyEvent.ACTION_DOWN, keyCode));
|
||||
tt9.onKeyUp(keyCode, new KeyEvent(KeyEvent.ACTION_UP, keyCode));
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue