Improved OK handling
* OK key now attempts to send DPAD_CENTER or ENTER (if needed), in attempt to make it work consistently accross all devices * OK is no longer ignored in numeric mode
This commit is contained in:
parent
d6884ef894
commit
2df5932896
2 changed files with 27 additions and 7 deletions
|
|
@ -144,6 +144,10 @@ abstract class KeyPadHandler extends InputMethodService {
|
|||
isBackspaceHandled = false;
|
||||
}
|
||||
|
||||
if (Key.isOK(keyCode)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// In numeric fields, we do not want to handle anything, but "backspace"
|
||||
if (mEditing == EDITING_STRICT_NUMERIC) {
|
||||
return false;
|
||||
|
|
@ -171,8 +175,7 @@ abstract class KeyPadHandler extends InputMethodService {
|
|||
|| keyCode == KeyEvent.KEYCODE_POUND
|
||||
|| (Key.isNumber(keyCode) && shouldTrackNumPress())
|
||||
|| ((keyCode == KeyEvent.KEYCODE_DPAD_UP || keyCode == KeyEvent.KEYCODE_DPAD_DOWN) && shouldTrackUpDown())
|
||||
|| ((keyCode == KeyEvent.KEYCODE_DPAD_LEFT || keyCode == KeyEvent.KEYCODE_DPAD_RIGHT) && shouldTrackLeftRight())
|
||||
|| (mEditing != EDITING_NOSHOW && Key.isOK(keyCode));
|
||||
|| ((keyCode == KeyEvent.KEYCODE_DPAD_LEFT || keyCode == KeyEvent.KEYCODE_DPAD_RIGHT) && shouldTrackLeftRight());
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -235,6 +238,10 @@ abstract class KeyPadHandler extends InputMethodService {
|
|||
return true;
|
||||
}
|
||||
|
||||
if (Key.isOK(keyCode)) {
|
||||
return onOK();
|
||||
}
|
||||
|
||||
// in numeric fields, we just handle backspace and let the rest go as-is.
|
||||
if (mEditing == EDITING_STRICT_NUMERIC) {
|
||||
return false;
|
||||
|
|
@ -254,10 +261,6 @@ abstract class KeyPadHandler extends InputMethodService {
|
|||
return true;
|
||||
}
|
||||
|
||||
if (Key.isOK(keyCode)) {
|
||||
return onOK();
|
||||
}
|
||||
|
||||
if (Key.isNumber(keyCode)) {
|
||||
return onNumber(Key.codeToNumber(settings, keyCode), false, numKeyRepeatCounter);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -616,7 +616,24 @@ public class TraditionalT9 extends KeyPadHandler {
|
|||
case EditorInfo.IME_ACTION_NONE:
|
||||
return false;
|
||||
case TextField.IME_ACTION_ENTER:
|
||||
String oldText = textField.getTextBeforeCursor() + textField.getTextAfterCursor();
|
||||
|
||||
sendDownUpKeyEvents(KeyEvent.KEYCODE_DPAD_CENTER);
|
||||
|
||||
try {
|
||||
// In Android there is no strictly defined confirmation key, hence DPAD_CENTER may have done nothing.
|
||||
// If so, send an alternative key code as a final resort.
|
||||
Thread.sleep(80);
|
||||
String newText = textField.getTextBeforeCursor() + textField.getTextAfterCursor();
|
||||
if (newText.equals(oldText)) {
|
||||
sendDownUpKeyEvents(KeyEvent.KEYCODE_ENTER);
|
||||
}
|
||||
} catch (InterruptedException e) {
|
||||
// This thread got interrupted. Assume it's because the connected application has taken an action
|
||||
// after receiving DPAD_CENTER, so we don't need to do anything else.
|
||||
return true;
|
||||
}
|
||||
|
||||
return true;
|
||||
default:
|
||||
return currentInputConnection.performEditorAction(action);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue