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
|
|
@ -102,7 +102,7 @@ abstract public class InputMode {
|
||||||
public boolean shouldDeletePrecedingSpace(InputType inputType) { return false; }
|
public boolean shouldDeletePrecedingSpace(InputType inputType) { return false; }
|
||||||
public boolean shouldIgnoreText(String text) { return text == null || text.isEmpty(); }
|
public boolean shouldIgnoreText(String text) { return text == null || text.isEmpty(); }
|
||||||
public boolean shouldSelectNextSuggestion() { return false; }
|
public boolean shouldSelectNextSuggestion() { return false; }
|
||||||
|
|
||||||
public void reset() {
|
public void reset() {
|
||||||
autoAcceptTimeout = -1;
|
autoAcceptTimeout = -1;
|
||||||
specialCharSelectedGroup = -1;
|
specialCharSelectedGroup = -1;
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,6 @@ public class SettingsStore extends SettingsUI {
|
||||||
/************* internal settings *************/
|
/************* internal settings *************/
|
||||||
public static final int BACKSPACE_ACCELERATION_MAX_CHARS = 10;
|
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_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 CLIPBOARD_PREVIEW_LENGTH = 20;
|
||||||
public final static int CUSTOM_WORDS_IMPORT_MAX_LINES = 250;
|
public final static int CUSTOM_WORDS_IMPORT_MAX_LINES = 250;
|
||||||
public final static int CUSTOM_WORDS_MAX = 1000;
|
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 byte SLOW_QUERY_TIME = 50; // ms
|
||||||
public final static int SOFT_KEY_DOUBLE_CLICK_DELAY = 500; // 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_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 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_TITLE_RELATIVE_SIZE = 0.55f;
|
||||||
public final static float SOFT_KEY_COMPLEX_LABEL_ARABIC_TITLE_RELATIVE_SIZE = 0.72f;
|
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 {
|
public class SoftBackspaceKey extends SoftKey {
|
||||||
private boolean hold;
|
private boolean hold;
|
||||||
private int repeatCount = 0;
|
|
||||||
|
|
||||||
public SoftBackspaceKey(Context context) {
|
public SoftBackspaceKey(Context context) {
|
||||||
super(context);
|
super(context);
|
||||||
|
|
@ -29,23 +28,12 @@ public class SoftBackspaceKey extends SoftKey {
|
||||||
final protected boolean handlePress() {
|
final protected boolean handlePress() {
|
||||||
super.handlePress();
|
super.handlePress();
|
||||||
hold = false;
|
hold = false;
|
||||||
repeatCount = 0;
|
return deleteText();
|
||||||
return validateTT9Handler() && deleteText();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
final protected void handleHold() {
|
final protected void handleHold() {
|
||||||
hold = true;
|
hold = true;
|
||||||
|
|
||||||
if (
|
|
||||||
validateTT9Handler()
|
|
||||||
&& tt9.getSettings().getBackspaceAcceleration()
|
|
||||||
&& ++repeatCount < SettingsStore.BACKSPACE_ACCELERATION_SOFT_KEY_REPEAT_DEBOUNCE
|
|
||||||
) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
repeatCount = 0;
|
|
||||||
deleteText();
|
deleteText();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -56,8 +44,13 @@ public class SoftBackspaceKey extends SoftKey {
|
||||||
return true;
|
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() {
|
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
|
// 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
|
// 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.
|
// 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);}
|
public SoftCommandKey(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr);}
|
||||||
|
|
||||||
|
|
||||||
@Override protected void handleHold() {}
|
@Override protected void handleHold() {
|
||||||
|
preventRepeat();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
||||||
|
|
@ -34,6 +34,7 @@ public class SoftKey extends androidx.appcompat.widget.AppCompatButton implement
|
||||||
|
|
||||||
private boolean hold = false;
|
private boolean hold = false;
|
||||||
private boolean repeat = false;
|
private boolean repeat = false;
|
||||||
|
private long lastLongClickTime = 0;
|
||||||
private final Handler repeatHandler = new Handler(Looper.getMainLooper());
|
private final Handler repeatHandler = new Handler(Looper.getMainLooper());
|
||||||
private static int lastPressedKey = -1;
|
private static int lastPressedKey = -1;
|
||||||
|
|
||||||
|
|
@ -98,11 +99,15 @@ public class SoftKey extends androidx.appcompat.widget.AppCompatButton implement
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onLongClick(View view) {
|
public boolean onLongClick(View view) {
|
||||||
hold = true;
|
|
||||||
|
|
||||||
// sometimes this gets called twice, so we debounce the call to the repeating function
|
// sometimes this gets called twice, so we debounce the call to the repeating function
|
||||||
repeatHandler.removeCallbacks(this::repeatOnLongPress);
|
final long now = System.currentTimeMillis();
|
||||||
repeatHandler.postDelayed(this::repeatOnLongPress, 5);
|
if (now - lastLongClickTime < SettingsStore.SOFT_KEY_DOUBLE_CLICK_DELAY) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
hold = true;
|
||||||
|
lastLongClickTime = now;
|
||||||
|
repeatOnLongPress();
|
||||||
return true;
|
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.
|
* Repeatedly calls "handleHold()" upon holding the respective SoftKey, to simulate physical keyboard behavior.
|
||||||
*/
|
*/
|
||||||
private void repeatOnLongPress() {
|
private void repeatOnLongPress() {
|
||||||
if (!validateTT9Handler()) {
|
|
||||||
hold = false;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (hold) {
|
if (hold) {
|
||||||
repeat = true;
|
repeat = true;
|
||||||
handleHold();
|
handleHold();
|
||||||
lastPressedKey = getId();
|
lastPressedKey = getId();
|
||||||
repeatHandler.removeCallbacks(this::repeatOnLongPress);
|
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
|
* preventRepeat
|
||||||
* Prevents "handleHold()" from being called repeatedly when the SoftKey is being held.
|
* Prevents "handleHold()" from being called repeatedly when the SoftKey is being held.
|
||||||
|
|
|
||||||
|
|
@ -13,11 +13,12 @@ public class SoftKeyLF2 extends SoftKey {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void handleHold() {
|
protected void handleHold() {
|
||||||
|
preventRepeat();
|
||||||
|
|
||||||
if (!validateTT9Handler()) {
|
if (!validateTT9Handler()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
preventRepeat();
|
|
||||||
vibrate(Vibration.getHoldVibration());
|
vibrate(Vibration.getHoldVibration());
|
||||||
tt9.addWord();
|
tt9.addWord();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -30,12 +30,12 @@ public class SoftKeyRF3 extends SoftKey {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void handleHold() {
|
protected void handleHold() {
|
||||||
|
preventRepeat();
|
||||||
|
|
||||||
if (!validateTT9Handler() || isTextEdtingActive()) {
|
if (!validateTT9Handler() || isTextEdtingActive()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
preventRepeat();
|
|
||||||
|
|
||||||
if (tt9.isVoiceInputActive()) {
|
if (tt9.isVoiceInputActive()) {
|
||||||
tt9.toggleVoiceInput();
|
tt9.toggleVoiceInput();
|
||||||
} else {
|
} else {
|
||||||
|
|
|
||||||
|
|
@ -30,13 +30,13 @@ public class SoftNumberKey extends SoftKey {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void handleHold() {
|
protected void handleHold() {
|
||||||
|
preventRepeat();
|
||||||
|
|
||||||
int keyCode = Key.numberToCode(getUpsideDownNumber(getId()));
|
int keyCode = Key.numberToCode(getUpsideDownNumber(getId()));
|
||||||
if (keyCode < 0 || !validateTT9Handler()) {
|
if (keyCode < 0 || !validateTT9Handler()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
preventRepeat();
|
|
||||||
|
|
||||||
vibrate(Vibration.getHoldVibration());
|
vibrate(Vibration.getHoldVibration());
|
||||||
tt9.onKeyLongPress(keyCode, new KeyEvent(KeyEvent.ACTION_DOWN, keyCode));
|
tt9.onKeyLongPress(keyCode, new KeyEvent(KeyEvent.ACTION_DOWN, keyCode));
|
||||||
tt9.onKeyUp(keyCode, new KeyEvent(KeyEvent.ACTION_UP, keyCode));
|
tt9.onKeyUp(keyCode, new KeyEvent(KeyEvent.ACTION_UP, keyCode));
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue