Skip to content

Commit

Permalink
attempt to fix OK again
Browse files Browse the repository at this point in the history
  • Loading branch information
sspanak committed Mar 22, 2023
1 parent d6884ef commit 4287f09
Showing 1 changed file with 24 additions and 3 deletions.
27 changes: 24 additions & 3 deletions src/io/github/sspanak/tt9/ime/TraditionalT9.java
Original file line number Diff line number Diff line change
Expand Up @@ -155,15 +155,19 @@ protected void onRestart(EditorInfo inputField) {
protected void onFinishTyping() {
isActive = false;

hideStatusIcon();
if (isInputViewShown()) {
hideStatusIcon();
}
mEditing = NON_EDIT;
}


protected void onStop() {
onFinishTyping();
clearSuggestions();
hideWindow();
if (isInputViewShown()) {
hideWindow();
}

softKeyHandler.hide();
}
Expand Down Expand Up @@ -616,7 +620,24 @@ private boolean performOKAction() {
case EditorInfo.IME_ACTION_NONE:
return false;
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;
default:
return currentInputConnection.performEditorAction(action);
Expand Down

0 comments on commit 4287f09

Please sign in to comment.