1
0
Fork 0

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:
sspanak 2023-03-17 08:45:31 +02:00 committed by Dimo Karaivanov
parent d6884ef894
commit 2df5932896
2 changed files with 27 additions and 7 deletions

View file

@ -144,6 +144,10 @@ abstract class KeyPadHandler extends InputMethodService {
isBackspaceHandled = false; isBackspaceHandled = false;
} }
if (Key.isOK(keyCode)) {
return true;
}
// In numeric fields, we do not want to handle anything, but "backspace" // In numeric fields, we do not want to handle anything, but "backspace"
if (mEditing == EDITING_STRICT_NUMERIC) { if (mEditing == EDITING_STRICT_NUMERIC) {
return false; return false;
@ -171,8 +175,7 @@ abstract class KeyPadHandler extends InputMethodService {
|| keyCode == KeyEvent.KEYCODE_POUND || keyCode == KeyEvent.KEYCODE_POUND
|| (Key.isNumber(keyCode) && shouldTrackNumPress()) || (Key.isNumber(keyCode) && shouldTrackNumPress())
|| ((keyCode == KeyEvent.KEYCODE_DPAD_UP || keyCode == KeyEvent.KEYCODE_DPAD_DOWN) && shouldTrackUpDown()) || ((keyCode == KeyEvent.KEYCODE_DPAD_UP || keyCode == KeyEvent.KEYCODE_DPAD_DOWN) && shouldTrackUpDown())
|| ((keyCode == KeyEvent.KEYCODE_DPAD_LEFT || keyCode == KeyEvent.KEYCODE_DPAD_RIGHT) && shouldTrackLeftRight()) || ((keyCode == KeyEvent.KEYCODE_DPAD_LEFT || keyCode == KeyEvent.KEYCODE_DPAD_RIGHT) && shouldTrackLeftRight());
|| (mEditing != EDITING_NOSHOW && Key.isOK(keyCode));
} }
@ -235,6 +238,10 @@ abstract class KeyPadHandler extends InputMethodService {
return true; return true;
} }
if (Key.isOK(keyCode)) {
return onOK();
}
// in numeric fields, we just handle backspace and let the rest go as-is. // in numeric fields, we just handle backspace and let the rest go as-is.
if (mEditing == EDITING_STRICT_NUMERIC) { if (mEditing == EDITING_STRICT_NUMERIC) {
return false; return false;
@ -254,10 +261,6 @@ abstract class KeyPadHandler extends InputMethodService {
return true; return true;
} }
if (Key.isOK(keyCode)) {
return onOK();
}
if (Key.isNumber(keyCode)) { if (Key.isNumber(keyCode)) {
return onNumber(Key.codeToNumber(settings, keyCode), false, numKeyRepeatCounter); return onNumber(Key.codeToNumber(settings, keyCode), false, numKeyRepeatCounter);
} }

View file

@ -616,7 +616,24 @@ public class TraditionalT9 extends KeyPadHandler {
case EditorInfo.IME_ACTION_NONE: case EditorInfo.IME_ACTION_NONE:
return false; return false;
case TextField.IME_ACTION_ENTER: case TextField.IME_ACTION_ENTER:
sendDownUpKeyEvents(KeyEvent.KEYCODE_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; return true;
default: default:
return currentInputConnection.performEditorAction(action); return currentInputConnection.performEditorAction(action);