From 4287f09693e2fed89779b24300f5d5afc6c86653 Mon Sep 17 00:00:00 2001 From: sspanak Date: Fri, 17 Mar 2023 08:45:31 +0200 Subject: [PATCH] attempt to fix OK again --- .../github/sspanak/tt9/ime/TraditionalT9.java | 27 ++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/src/io/github/sspanak/tt9/ime/TraditionalT9.java b/src/io/github/sspanak/tt9/ime/TraditionalT9.java index e93a4712b..7f3598a29 100644 --- a/src/io/github/sspanak/tt9/ime/TraditionalT9.java +++ b/src/io/github/sspanak/tt9/ime/TraditionalT9.java @@ -155,7 +155,9 @@ protected void onRestart(EditorInfo inputField) { protected void onFinishTyping() { isActive = false; - hideStatusIcon(); + if (isInputViewShown()) { + hideStatusIcon(); + } mEditing = NON_EDIT; } @@ -163,7 +165,9 @@ protected void onFinishTyping() { protected void onStop() { onFinishTyping(); clearSuggestions(); - hideWindow(); + if (isInputViewShown()) { + hideWindow(); + } softKeyHandler.hide(); } @@ -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);