1
0
Fork 0

OK sends messages (#194)

* OK now performs the default application action correctly, when an action is allowed (e.g. send a message, go to a URL or the next form field)

* updated manual
This commit is contained in:
Dimo Karaivanov 2023-02-27 16:35:11 +02:00 committed by GitHub
parent c523f0f0f1
commit 9b0a3c64ef
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 45 additions and 1 deletions

View file

@ -192,7 +192,7 @@ public class TraditionalT9 extends KeyPadHandler {
public boolean onOK() {
if (isSuggestionViewHidden() && currentInputConnection != null) {
return sendDefaultEditorAction(false);
return performOKAction();
}
String word = mSuggestionView.getCurrentSuggestion();
@ -601,6 +601,20 @@ public class TraditionalT9 extends KeyPadHandler {
}
private boolean performOKAction() {
int action = textField.getAction();
switch (action) {
case EditorInfo.IME_ACTION_NONE:
return false;
case TextField.IME_ACTION_ENTER:
sendDownUpKeyEvents(KeyEvent.KEYCODE_ENTER);
return true;
default:
return currentInputConnection.performEditorAction(action);
}
}
private void showAddWord() {
if (currentInputConnection == null) {
return;

View file

@ -18,6 +18,8 @@ import io.github.sspanak.tt9.Logger;
import io.github.sspanak.tt9.ime.modes.InputMode;
public class TextField {
public static final int IME_ACTION_ENTER = EditorInfo.IME_MASK_ACTION + 1;
private static final Pattern beforeCursorWordRegex = Pattern.compile("(\\w+)(?!\n)$");
private static final Pattern afterCursorWordRegex = Pattern.compile("^(?<!\n)(\\w+)");
@ -297,4 +299,23 @@ public class TextField {
return styledWord;
}
public int getAction() {
if (field.actionId > 0) {
return field.actionId; // custom action, defined by the connected app
}
int standardAction = field.imeOptions & (EditorInfo.IME_MASK_ACTION | EditorInfo.IME_FLAG_NO_ENTER_ACTION);
switch (standardAction) {
case EditorInfo.IME_ACTION_GO:
case EditorInfo.IME_ACTION_NEXT:
case EditorInfo.IME_ACTION_PREVIOUS:
case EditorInfo.IME_ACTION_SEARCH:
case EditorInfo.IME_ACTION_SEND:
return standardAction;
default:
return IME_ACTION_ENTER;
}
}
}