1
0
Fork 0

fixed some more scenarios where the OK key was not working

This commit is contained in:
sspanak 2024-04-07 16:00:50 +03:00 committed by Dimo Karaivanov
parent 32638aca46
commit 3c86d0b0cd
3 changed files with 23 additions and 11 deletions

View file

@ -130,7 +130,7 @@ public class AppHacks {
* onEnter * onEnter
* Tries to guess and send the correct confirmation key code or sequence of key codes, * Tries to guess and send the correct confirmation key code or sequence of key codes,
* depending on the connected application and input field. On invalid connection or field, * depending on the connected application and input field. On invalid connection or field,
* it does nothing. * it does nothing and return "false", signaling the system we have ignored the key press.
*/ */
public boolean onEnter() { public boolean onEnter() {
if (settings.getFbMessengerHack() && isMessenger()) { if (settings.getFbMessengerHack() && isMessenger()) {
@ -138,18 +138,18 @@ public class AppHacks {
} else if (settings.getGoogleChatHack() && isGoogleChat()) { } else if (settings.getGoogleChatHack() && isGoogleChat()) {
return onEnterGoogleChat(); return onEnterGoogleChat();
} else if (isTermux() || isMultilineTextInNonSystemApp()) { } else if (isTermux() || isMultilineTextInNonSystemApp()) {
// 1. Termux supports only ENTER, so we convert DPAD_CENTER for it. // Termux supports only ENTER, so we convert DPAD_CENTER for it.
// 2. Any extra installed apps are likely not designed for hardware keypads, so again, // Any extra installed apps are likely not designed for hardware keypads, so again,
// we don't want to send DPAD_CENTER to them. // we don't want to send DPAD_CENTER to them.
return sendDownUpKeyEvents(KeyEvent.KEYCODE_ENTER); return sendDownUpKeyEvents(KeyEvent.KEYCODE_ENTER);
} }
// The rest of the cases are probably system apps or numeric fields, which should // The rest of the cases are probably system apps or numeric fields, which should
// now how to handle the incoming OK key code, be it ENTER or DPAD_CENTER. // now how to handle the incoming OK key code, be it ENTER or DPAD_CENTER.
// As per the docs, we must return "false", to indicate that we have not "seen" the key press.
return false; return false;
} }
/** /**
* onEnterFbMessenger * onEnterFbMessenger
* Messenger responds only to ENTER, but not DPAD_CENTER, so we make sure to send the correct code, * Messenger responds only to ENTER, but not DPAD_CENTER, so we make sure to send the correct code,

View file

@ -181,7 +181,7 @@ public class TextField {
/** /**
* setComposingTextWithHighlightedStem * setComposingTextWithHighlightedStem
* * <p>
* Sets the composing text, but makes the "stem" substring bold. If "highlightMore" is true, * Sets the composing text, but makes the "stem" substring bold. If "highlightMore" is true,
* the "stem" part will be in bold and italic. * the "stem" part will be in bold and italic.
*/ */
@ -263,12 +263,18 @@ public class TextField {
return EditorInfo.IME_ACTION_NONE; return EditorInfo.IME_ACTION_NONE;
} }
if (field.actionId == EditorInfo.IME_ACTION_DONE) { // custom actions handling as in LatinIME. See the example in OpenBoard repo:
// https://github.com/openboard-team/openboard/blob/master/app/src/main/java/org/dslul/openboard/inputmethod/latin/utils/InputTypeUtils.java#L107
if (field.actionId == EditorInfo.IME_ACTION_DONE || field.actionLabel != null) {
return IME_ACTION_ENTER; return IME_ACTION_ENTER;
} else if (field.actionId > 0) { } else if (field.actionId > 0) {
return field.actionId; return field.actionId;
} }
// As in LatinIME, we want to perform an editor action, including in the case of "IME_ACTION_UNSPECIFIED".
// Otherwise, we pass through the ENTER or DPAD_CENTER key press and let the app or the system decide what to do.
// See the example below:
// https://github.com/openboard-team/openboard/blob/c3772cd56e770975ea5570db903f93b199de8b32/app/src/main/java/org/dslul/openboard/inputmethod/latin/inputlogic/InputLogic.java#L756
int standardAction = field.imeOptions & (EditorInfo.IME_MASK_ACTION | EditorInfo.IME_FLAG_NO_ENTER_ACTION); int standardAction = field.imeOptions & (EditorInfo.IME_MASK_ACTION | EditorInfo.IME_FLAG_NO_ENTER_ACTION);
switch (standardAction) { switch (standardAction) {
case EditorInfo.IME_ACTION_DONE: case EditorInfo.IME_ACTION_DONE:
@ -277,10 +283,12 @@ public class TextField {
case EditorInfo.IME_ACTION_PREVIOUS: case EditorInfo.IME_ACTION_PREVIOUS:
case EditorInfo.IME_ACTION_SEARCH: case EditorInfo.IME_ACTION_SEARCH:
case EditorInfo.IME_ACTION_SEND: case EditorInfo.IME_ACTION_SEND:
case EditorInfo.IME_ACTION_UNSPECIFIED:
return standardAction; return standardAction;
default: default:
return IME_ACTION_ENTER; return IME_ACTION_ENTER;
} }
} }
/** /**

View file

@ -20,9 +20,13 @@ public class SoftOkKey extends SoftKey {
@Override @Override
protected boolean handleRelease() { protected boolean handleRelease() {
return if (validateTT9Handler() && !tt9.onOK()) {
validateTT9Handler() // If no standard editor action was performed, it probably means we can only type a new line,
&& tt9.onKeyDown(KeyEvent.KEYCODE_ENTER, new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_ENTER)) // so we simulate the hardware ENTER key.
&& tt9.onKeyUp(KeyEvent.KEYCODE_ENTER, new KeyEvent(KeyEvent.ACTION_UP, KeyEvent.KEYCODE_ENTER)); tt9.sendDownUpKeyEvents(KeyEvent.KEYCODE_ENTER);
return true;
}
return false;
} }
} }