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;
|
protected int mEditing = NON_EDIT;
|
||||||
|
|
||||||
// temporal key handling
|
// temporal key handling
|
||||||
|
private boolean backspaceHandled = false;
|
||||||
|
|
||||||
private int ignoreNextKeyUp = 0;
|
private int ignoreNextKeyUp = 0;
|
||||||
|
|
||||||
private int lastKeyCode = 0;
|
private int lastKeyCode = 0;
|
||||||
|
|
@ -32,10 +34,6 @@ abstract class KeyPadHandler extends InputMethodService {
|
||||||
private int lastNumKeyCode = 0;
|
private int lastNumKeyCode = 0;
|
||||||
private int numKeyRepeatCounter = 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
|
* 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());
|
// 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
|
// "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,
|
if (keyCode == settings.getKeyBackspace()) {
|
||||||
// otherwise, keyDown race condition occur for all keys.
|
// When there is no more text, allow "Back" key to function normally, not to block navigation.
|
||||||
if (mEditing != EDITING_DIALER && keyCode == settings.getKeyBackspace()) {
|
// All other keys are blocked, unless it turns out it is annoying this way.
|
||||||
boolean isThereTextBefore = InputFieldHelper.isThereText(currentInputConnection);
|
backspaceHandled = onBackspace() || keyCode != KeyEvent.KEYCODE_BACK;
|
||||||
boolean backspaceHandleStatus = handleBackspaceHold();
|
return backspaceHandled;
|
||||||
|
|
||||||
// Allow BACK key to function as back when there is no text
|
|
||||||
if (keyCode == KeyEvent.KEYCODE_BACK) {
|
|
||||||
return isThereTextBefore;
|
|
||||||
} else {
|
|
||||||
return backspaceHandleStatus;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// In numeric fields, we do not want to handle anything, but "backspace"
|
// 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());
|
// Logger.d("onKeyUp", "Key: " + keyCode + " repeat?: " + event.getRepeatCount());
|
||||||
|
|
||||||
if (
|
if (backspaceHandled && keyCode == settings.getKeyBackspace()) {
|
||||||
mEditing != EDITING_DIALER // dialer fields seem to handle backspace on their own
|
|
||||||
&& keyCode == settings.getKeyBackspace()
|
|
||||||
&& InputFieldHelper.isThereText(currentInputConnection)
|
|
||||||
) {
|
|
||||||
return true;
|
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) {
|
private boolean handleSpecialFunctionKey(int keyCode, boolean hold) {
|
||||||
if (keyCode == settings.getKeyAddWord() * (hold ? -1 : 1)) {
|
if (keyCode == settings.getKeyAddWord() * (hold ? -1 : 1)) {
|
||||||
return onKeyAddWord();
|
return onKeyAddWord();
|
||||||
|
|
|
||||||
|
|
@ -17,6 +17,9 @@ class SoftKeyHandler implements View.OnTouchListener {
|
||||||
private final TraditionalT9 tt9;
|
private final TraditionalT9 tt9;
|
||||||
private View view = null;
|
private View view = null;
|
||||||
|
|
||||||
|
private static final int BACKSPACE_DEBOUNCE_TIME = 40;
|
||||||
|
private long lastBackspaceCall = 0;
|
||||||
|
|
||||||
public SoftKeyHandler(TraditionalT9 tt9) {
|
public SoftKeyHandler(TraditionalT9 tt9) {
|
||||||
this.tt9 = 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
|
@Override
|
||||||
public boolean onTouch(View view, MotionEvent event) {
|
public boolean onTouch(View view, MotionEvent event) {
|
||||||
int action = event.getAction();
|
int action = event.getAction();
|
||||||
|
|
@ -117,7 +132,7 @@ class SoftKeyHandler implements View.OnTouchListener {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (buttonId == R.id.main_right && action == MotionEvent.AXIS_PRESSURE) {
|
if (buttonId == R.id.main_right && action == MotionEvent.AXIS_PRESSURE) {
|
||||||
return tt9.handleBackspaceHold();
|
return handleBackspaceHold();
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
|
|
|
||||||
|
|
@ -130,7 +130,10 @@ public class TraditionalT9 extends KeyPadHandler {
|
||||||
|
|
||||||
|
|
||||||
public boolean onBackspace() {
|
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");
|
Logger.d("onBackspace", "backspace ignored");
|
||||||
mInputMode.reset();
|
mInputMode.reset();
|
||||||
return false;
|
return false;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue