diff --git a/app/src/main/java/io/github/sspanak/tt9/ime/HotkeyHandler.java b/app/src/main/java/io/github/sspanak/tt9/ime/HotkeyHandler.java index b8d8427d..22e4a050 100644 --- a/app/src/main/java/io/github/sspanak/tt9/ime/HotkeyHandler.java +++ b/app/src/main/java/io/github/sspanak/tt9/ime/HotkeyHandler.java @@ -31,7 +31,11 @@ public abstract class HotkeyHandler extends TypingHandler { suggestionOps.cancelDelayedAccept(); if (!suggestionOps.isEmpty()) { - onAcceptSuggestionManually(suggestionOps.acceptCurrent(), KeyEvent.KEYCODE_ENTER); + if (shouldBeVisible() && !isInputViewShown()) { + forceShowWindowIfHidden(); + } else { + onAcceptSuggestionManually(suggestionOps.acceptCurrent(), KeyEvent.KEYCODE_ENTER); + } return true; } diff --git a/app/src/main/java/io/github/sspanak/tt9/ime/TraditionalT9.java b/app/src/main/java/io/github/sspanak/tt9/ime/TraditionalT9.java index 850bb87e..b312a546 100644 --- a/app/src/main/java/io/github/sspanak/tt9/ime/TraditionalT9.java +++ b/app/src/main/java/io/github/sspanak/tt9/ime/TraditionalT9.java @@ -172,7 +172,7 @@ public class TraditionalT9 extends HotkeyHandler { * on how much time the restart takes, this may erase the current user input. */ protected void forceShowWindowIfHidden() { - if (getInputModeId() == InputMode.MODE_PASSTHROUGH || isInputViewShown() || settings.isMainLayoutStealth()) { + if (isInputViewShown() || !shouldBeVisible()) { return; } @@ -202,7 +202,7 @@ public class TraditionalT9 extends HotkeyHandler { @Override protected boolean shouldBeVisible() { - return getInputModeId() != InputMode.MODE_PASSTHROUGH; + return getInputModeId() != InputMode.MODE_PASSTHROUGH && !settings.isMainLayoutStealth(); } diff --git a/app/src/main/java/io/github/sspanak/tt9/ime/helpers/AppHacks.java b/app/src/main/java/io/github/sspanak/tt9/ime/helpers/AppHacks.java index 55f157fc..d88c40f7 100644 --- a/app/src/main/java/io/github/sspanak/tt9/ime/helpers/AppHacks.java +++ b/app/src/main/java/io/github/sspanak/tt9/ime/helpers/AppHacks.java @@ -190,7 +190,7 @@ public class AppHacks { * no matter how the hardware key is implemented. */ private boolean onEnterFbMessenger() { - if (inputConnection == null || textField == null || !textField.isThereText()) { + if (inputConnection == null || textField == null || textField.isEmpty()) { return false; } @@ -205,7 +205,7 @@ public class AppHacks { * the send button it, then going back to the text field, so that one can continue typing. */ private boolean onEnterGoogleChat() { - if (inputConnection == null || textField == null || !textField.isThereText()) { + if (inputConnection == null || textField == null || textField.isEmpty()) { return false; } diff --git a/app/src/main/java/io/github/sspanak/tt9/ime/helpers/TextField.java b/app/src/main/java/io/github/sspanak/tt9/ime/helpers/TextField.java index cf6e2f76..5cbc1049 100644 --- a/app/src/main/java/io/github/sspanak/tt9/ime/helpers/TextField.java +++ b/app/src/main/java/io/github/sspanak/tt9/ime/helpers/TextField.java @@ -6,8 +6,6 @@ import android.text.SpannableString; import android.text.style.StyleSpan; import android.text.style.UnderlineSpan; import android.view.inputmethod.EditorInfo; -import android.view.inputmethod.ExtractedText; -import android.view.inputmethod.ExtractedTextRequest; import android.view.inputmethod.InputConnection; import androidx.annotation.NonNull; @@ -44,13 +42,8 @@ public class TextField { } - public boolean isThereText() { - if (connection == null) { - return false; - } - - ExtractedText extractedText = connection.getExtractedText(new ExtractedTextRequest(), 0); - return extractedText != null && extractedText.text.length() > 0; + public boolean isEmpty() { + return getStringBeforeCursor(1).isEmpty() && getStringAfterCursor(1).isEmpty(); } diff --git a/docs/user-manual.md b/docs/user-manual.md index 4fe077f7..65f33772 100644 --- a/docs/user-manual.md +++ b/docs/user-manual.md @@ -195,7 +195,7 @@ This happens if you are using one of the small-sized layouts. Currently, there i - You can now go back to the settings and disable the on-screen numpad. The emoji and sticker panels will remain accessible until you restart the app or the phone. #### Traditional T9 does not appear immediately in some applications -If you have opened an application where you can type, but TT9 does not wake up, just start typing and it will. Alternatively, you could also use the hotkeys to change [the input mode](#next-input-mode-key-default-press-) or the [language](#next-language-key-default-hold-). You may also use the OK key, but this is not recommended, because you may accidentally send a message, submit a form, or perform another action, depending on the application. +If you have opened an application where you can type, but TT9 does not wake up, just start typing and it will. Alternatively, you could also use the hotkeys to change [the input mode](#next-input-mode-key-default-press-) or the [language](#next-language-key-default-hold-). If it still invisible, while you are typing a new word, press the OK key and it should appear. **Long explanation.** The reason for this problem is Android was originally designed for touchscreen devices. Hence, it expects you to touch the text/number field to show the keyboard. It is possible to make TT9 appear without this confirmation, but then, in some cases, Android will forget to hide it when it must. For example, it may remain visible after you have dialed a phone number or after you have submitted text in a search field.