no more unnecessary throtling of the hardware backspace key
This commit is contained in:
parent
ff1c832a5a
commit
283bf7de6b
3 changed files with 28 additions and 35 deletions
|
|
@ -24,6 +24,8 @@ abstract class KeyPadHandler extends InputMethodService {
|
|||
protected int mEditing = NON_EDIT;
|
||||
|
||||
// temporal key handling
|
||||
private boolean backspaceHandled = false;
|
||||
|
||||
private int ignoreNextKeyUp = 0;
|
||||
|
||||
private int lastKeyCode = 0;
|
||||
|
|
@ -32,10 +34,6 @@ abstract class KeyPadHandler extends InputMethodService {
|
|||
private int lastNumKeyCode = 0;
|
||||
private int numKeyRepeatCounter = 0;
|
||||
|
||||
// throttling
|
||||
private static final int BACKSPACE_DEBOUNCE_TIME = 80;
|
||||
private long lastBackspaceCall = 0;
|
||||
|
||||
|
||||
/**
|
||||
* Main initialization of the input method component. Be sure to call to
|
||||
|
|
@ -135,18 +133,11 @@ abstract class KeyPadHandler extends InputMethodService {
|
|||
// Logger.d("onKeyDown", "Key: " + event + " repeat?: " + event.getRepeatCount() + " long-time: " + event.isLongPress());
|
||||
|
||||
// "backspace" key must repeat its function, when held down, so we handle it in a special way
|
||||
// Also dialer fields seem to handle backspace on their own and we must ignore it,
|
||||
// otherwise, keyDown race condition occur for all keys.
|
||||
if (mEditing != EDITING_DIALER && keyCode == settings.getKeyBackspace()) {
|
||||
boolean isThereTextBefore = InputFieldHelper.isThereText(currentInputConnection);
|
||||
boolean backspaceHandleStatus = handleBackspaceHold();
|
||||
|
||||
// Allow BACK key to function as back when there is no text
|
||||
if (keyCode == KeyEvent.KEYCODE_BACK) {
|
||||
return isThereTextBefore;
|
||||
} else {
|
||||
return backspaceHandleStatus;
|
||||
}
|
||||
if (keyCode == settings.getKeyBackspace()) {
|
||||
// When there is no more text, allow "Back" key to function normally, not to block navigation.
|
||||
// All other keys are blocked, unless it turns out it is annoying this way.
|
||||
backspaceHandled = onBackspace() || keyCode != KeyEvent.KEYCODE_BACK;
|
||||
return backspaceHandled;
|
||||
}
|
||||
|
||||
// In numeric fields, we do not want to handle anything, but "backspace"
|
||||
|
|
@ -249,11 +240,7 @@ abstract class KeyPadHandler extends InputMethodService {
|
|||
|
||||
// Logger.d("onKeyUp", "Key: " + keyCode + " repeat?: " + event.getRepeatCount());
|
||||
|
||||
if (
|
||||
mEditing != EDITING_DIALER // dialer fields seem to handle backspace on their own
|
||||
&& keyCode == settings.getKeyBackspace()
|
||||
&& InputFieldHelper.isThereText(currentInputConnection)
|
||||
) {
|
||||
if (backspaceHandled && keyCode == settings.getKeyBackspace()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
@ -300,18 +287,6 @@ abstract class KeyPadHandler extends InputMethodService {
|
|||
}
|
||||
|
||||
|
||||
protected boolean handleBackspaceHold() {
|
||||
if (System.currentTimeMillis() - lastBackspaceCall < BACKSPACE_DEBOUNCE_TIME) {
|
||||
return true;
|
||||
}
|
||||
|
||||
boolean handled = onBackspace();
|
||||
lastBackspaceCall = System.currentTimeMillis();
|
||||
|
||||
return handled;
|
||||
}
|
||||
|
||||
|
||||
private boolean handleSpecialFunctionKey(int keyCode, boolean hold) {
|
||||
if (keyCode == settings.getKeyAddWord() * (hold ? -1 : 1)) {
|
||||
return onKeyAddWord();
|
||||
|
|
|
|||
|
|
@ -17,6 +17,9 @@ class SoftKeyHandler implements View.OnTouchListener {
|
|||
private final TraditionalT9 tt9;
|
||||
private View view = null;
|
||||
|
||||
private static final int BACKSPACE_DEBOUNCE_TIME = 40;
|
||||
private long lastBackspaceCall = 0;
|
||||
|
||||
public SoftKeyHandler(TraditionalT9 tt9) {
|
||||
this.tt9 = tt9;
|
||||
|
||||
|
|
@ -101,6 +104,18 @@ class SoftKeyHandler implements View.OnTouchListener {
|
|||
}
|
||||
|
||||
|
||||
protected boolean handleBackspaceHold() {
|
||||
if (System.currentTimeMillis() - lastBackspaceCall < BACKSPACE_DEBOUNCE_TIME) {
|
||||
return true;
|
||||
}
|
||||
|
||||
boolean handled = tt9.onBackspace();
|
||||
lastBackspaceCall = System.currentTimeMillis();
|
||||
|
||||
return handled;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean onTouch(View view, MotionEvent event) {
|
||||
int action = event.getAction();
|
||||
|
|
@ -117,7 +132,7 @@ class SoftKeyHandler implements View.OnTouchListener {
|
|||
}
|
||||
|
||||
if (buttonId == R.id.main_right && action == MotionEvent.AXIS_PRESSURE) {
|
||||
return tt9.handleBackspaceHold();
|
||||
return handleBackspaceHold();
|
||||
}
|
||||
|
||||
return false;
|
||||
|
|
|
|||
|
|
@ -130,7 +130,10 @@ public class TraditionalT9 extends KeyPadHandler {
|
|||
|
||||
|
||||
public boolean onBackspace() {
|
||||
if (!InputFieldHelper.isThereText(currentInputConnection)) {
|
||||
// 1. Dialer fields seem to handle backspace on their own and we must ignore it,
|
||||
// otherwise, keyDown race condition occur for all keys.
|
||||
// 2. Allow the assigned key to function normally, when there is no text (e.g. "Back" navigates back)
|
||||
if (mEditing == EDITING_DIALER || !InputFieldHelper.isThereText(currentInputConnection)) {
|
||||
Logger.d("onBackspace", "backspace ignored");
|
||||
mInputMode.reset();
|
||||
return false;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue