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 3a84e637..b912134f 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 @@ -9,7 +9,6 @@ import android.view.inputmethod.InputConnection; import androidx.annotation.NonNull; -import io.github.sspanak.tt9.R; import io.github.sspanak.tt9.db.DataStore; import io.github.sspanak.tt9.db.words.DictionaryLoader; import io.github.sspanak.tt9.hacks.InputType; @@ -252,22 +251,10 @@ public class TraditionalT9 extends MainViewHandler { if (InputModeKind.isPredictive(mInputMode) && DictionaryLoader.autoLoad(this, mLanguage)) { return true; } - if (textField.shouldReportConnectionErrors()) { - UI.toastLongSingle(getApplicationContext(), R.string.error_unstable_input_connection); - } return super.onNumber(key, hold, repeat); } - @Override - public boolean onBackspace(int repeat) { - if (textField.shouldReportConnectionErrors()) { - UI.toastLongSingle(getApplicationContext(), R.string.error_unstable_input_connection); - } - return super.onBackspace(repeat); - } - - @Override protected TraditionalT9 getFinalContext() { return this; 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 9cf4744d..d3f57063 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 @@ -18,13 +18,10 @@ import io.github.sspanak.tt9.ime.modes.InputMode; import io.github.sspanak.tt9.languages.Language; import io.github.sspanak.tt9.languages.LanguageKind; import io.github.sspanak.tt9.preferences.settings.SettingsStore; -import io.github.sspanak.tt9.util.InputConnectionCompat; import io.github.sspanak.tt9.util.Logger; import io.github.sspanak.tt9.util.Text; public class TextField extends InputField { - @NonNull private final InputConnectionCompat connectionCompat; - private CharSequence composingText = ""; private final boolean isComposingSupported; private final boolean isNonText; @@ -33,8 +30,6 @@ public class TextField extends InputField { public TextField(InputConnection inputConnection, EditorInfo inputField) { super(inputConnection, inputField); - connectionCompat = new InputConnectionCompat(inputConnection); - InputType inputType = new InputType(inputConnection, inputField); isComposingSupported = !inputType.isNumeric() && !inputType.isLimited() && !inputType.isRustDesk() && !inputType.isDeezerSearchBar(); isNonText = !inputType.isText(); @@ -42,13 +37,13 @@ public class TextField extends InputField { public String getStringAfterCursor(int numberOfChars) { - CharSequence chars = connectionCompat.getTextAfterCursor(numberOfChars, 0); + CharSequence chars = connection != null ? connection.getTextAfterCursor(numberOfChars, 0) : null; return chars != null ? chars.toString() : ""; } public String getStringBeforeCursor(int numberOfChars) { - CharSequence chars = connectionCompat.getTextBeforeCursor(numberOfChars, 0); + CharSequence chars = connection != null ? connection.getTextBeforeCursor(numberOfChars, 0) : null; return chars != null ? chars.toString() : ""; } @@ -396,9 +391,4 @@ public class TextField extends InputField { return false; } - - - public boolean shouldReportConnectionErrors() { - return connectionCompat.shouldReportTimeout(); - } } diff --git a/app/src/main/java/io/github/sspanak/tt9/util/InputConnectionCompat.java b/app/src/main/java/io/github/sspanak/tt9/util/InputConnectionCompat.java deleted file mode 100644 index e00f0722..00000000 --- a/app/src/main/java/io/github/sspanak/tt9/util/InputConnectionCompat.java +++ /dev/null @@ -1,129 +0,0 @@ -package io.github.sspanak.tt9.util; - -import android.os.Build; -import android.view.inputmethod.InputConnection; - -import androidx.annotation.NonNull; -import androidx.annotation.Nullable; -import androidx.annotation.RequiresApi; - -import java.util.concurrent.CompletableFuture; -import java.util.concurrent.ExecutionException; -import java.util.concurrent.ExecutorService; -import java.util.concurrent.Executors; -import java.util.concurrent.TimeUnit; -import java.util.concurrent.TimeoutException; - -import io.github.sspanak.tt9.preferences.settings.SettingsStore; - -public class InputConnectionCompat { - private static final String LOG_TAG = InputConnectionCompat.class.getSimpleName(); - - @Nullable private final InputConnection connection; - - @Nullable private CompletableFuture future; - @NonNull private final ExecutorService executor = Executors.newSingleThreadExecutor(); - private int connectionErrors = 0; - private boolean isErrorReported = false; - - private CharSequence result; - - - public InputConnectionCompat(@Nullable InputConnection connection) { - this.connection = connection; - } - - - public CharSequence getTextAfterCursor(int i, int ii) { - return getTextNextToCursor(i, ii, true); - } - - - public CharSequence getTextBeforeCursor(int i, int ii) { - return getTextNextToCursor(i, ii, false); - } - - - @Nullable - private CharSequence getTextNextToCursor(int i, int ii, boolean after) { - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { - getTextNextToCursorModern(i, ii, after); - } else { - getTextNextToCursorClassic(i, ii, after); - } - - return result; - } - - - private void getTextNextToCursorClassic(int i, int ii, boolean after) { - result = null; - if (connection != null) { - result = after ? connection.getTextAfterCursor(i, ii) : connection.getTextBeforeCursor(i, ii); - } - } - - - /** - * getTextNextToCursorModern - * On some devices with Android >= 11, getTextBeforeCursor() sometimes takes too long to execute, - * blocking the UI thread and ultimately causing ANR. This method is a wrapper around - * getTextBeforeCursor() that terminates the operations after a certain timeout. Just in case we - * handle getTextAfterCursor() the same way. - */ - @RequiresApi(api = Build.VERSION_CODES.N) - private void getTextNextToCursorModern(int i, int ii, boolean after) { - // CompletableFuture is supported only in API 24 and above, so we initialize it here. - future = new CompletableFuture<>(); - - // Start only the watchdog in a separate thread. If we start the main operation there too, - // it will causes a deadlock, because main would be waiting for the thread, which will be waiting - // for main to provide text. - executor.submit(this::awaitTextResult); - - try { - getTextNextToCursorClassic(i, ii, after); - future.complete(true); - } catch (Exception e) { - connectionErrors++; - logError("getStringBeforeCursor() failed " + connectionErrors + " times so far. Current error: " + e); - } - } - - - @RequiresApi(api = Build.VERSION_CODES.N) - private void awaitTextResult() { - if (future == null) { - logError("No future. Cannot call getStringBeforeCursor()."); - return; - } - - try { - if (!future.get(SettingsStore.INPUT_CONNECTION_OPERATIONS_TIMEOUT, TimeUnit.MILLISECONDS)) { - logError("Future is not true. InputConnection.getTextBeforeCursor() probably failed."); - } - } catch (TimeoutException e) { - connectionErrors++; - logError( - "getStringBeforeCursor() timed out after " + SettingsStore.INPUT_CONNECTION_OPERATIONS_TIMEOUT + "ms. " + connectionErrors + " errors so far." - ); - } catch (InterruptedException | ExecutionException e) { - connectionErrors++; - logError("getStringBeforeCursor() failed " + connectionErrors + " times so far. Current error: " + e); - } - } - - - private void logError(@NonNull String error) { - Logger.e(LOG_TAG, error); - } - - - public boolean shouldReportTimeout() { - if (!isErrorReported && connectionErrors > SettingsStore.INPUT_CONNECTION_ERRORS_MAX) { - isErrorReported = true; - return true; - } - return false; - } -} diff --git a/app/src/main/res/values-bg/strings.xml b/app/src/main/res/values-bg/strings.xml index 81baf396..a0d9e8fb 100644 --- a/app/src/main/res/values-bg/strings.xml +++ b/app/src/main/res/values-bg/strings.xml @@ -5,7 +5,6 @@ Завършено Зареждане… Възникна неочаквана грешка. - Нестабилна връзка с приложението! Добави Преместете показалеца върху дума, за да я добавите към речника. Не може да се въведе празна дума. diff --git a/app/src/main/res/values-de/strings.xml b/app/src/main/res/values-de/strings.xml index 457ee719..6d00747d 100644 --- a/app/src/main/res/values-de/strings.xml +++ b/app/src/main/res/values-de/strings.xml @@ -4,7 +4,6 @@ Laden… Unerwarteter Fehler aufgetreten. - Instabile Anwendungsverbindung! Hinzufügen Wort \"%1$s\" zu %2$s hinzufügen? Bewegen Sie den Cursor innerhalb eines Wortes, um es hinzuzufügen. diff --git a/app/src/main/res/values-es/strings.xml b/app/src/main/res/values-es/strings.xml index 86863bef..94f953b1 100644 --- a/app/src/main/res/values-es/strings.xml +++ b/app/src/main/res/values-es/strings.xml @@ -1,7 +1,6 @@ Configuración de Traditional T9 - ¡Conexión inestable con la aplicación! Agregar ¿Agregar la palabra \"%1$s\" a %2$s? Mueve el cursor dentro de una palabra para añadirla. diff --git a/app/src/main/res/values-fr/strings.xml b/app/src/main/res/values-fr/strings.xml index f7534fc8..76373303 100644 --- a/app/src/main/res/values-fr/strings.xml +++ b/app/src/main/res/values-fr/strings.xml @@ -5,7 +5,6 @@ Fini Chargement… Une erreur inattendue s\'est produite. - Connexion instable à l\'application ! Ajouter Déplacez le curseur dans un mot pour l\'ajouter. Mot vide non ajouté. diff --git a/app/src/main/res/values-it/strings.xml b/app/src/main/res/values-it/strings.xml index d39fa3a0..908a7dc1 100644 --- a/app/src/main/res/values-it/strings.xml +++ b/app/src/main/res/values-it/strings.xml @@ -6,7 +6,6 @@ Caricamento… Si è verificato un errore imprevisto. - Connessione instabile all\'applicazione! Aggiungere Aggiungi la parola \"%1$s\" a %2$s? Sposta il cursore dentro un parola per aggiungerla. diff --git a/app/src/main/res/values-iw/strings.xml b/app/src/main/res/values-iw/strings.xml index 046f26e0..e1b5aa3f 100644 --- a/app/src/main/res/values-iw/strings.xml +++ b/app/src/main/res/values-iw/strings.xml @@ -6,7 +6,6 @@ טוען… אירעה שגיאה לא צפויה. - חיבור לא יציב לאפליקציה! הוסף האם להוסיף את המילה \"%1$s\" ל-%2$s? הזיזו את הסמן בתוך מילה כדי להוסיף אותה. diff --git a/app/src/main/res/values-lt/strings.xml b/app/src/main/res/values-lt/strings.xml index de5b3d8b..0d57b823 100644 --- a/app/src/main/res/values-lt/strings.xml +++ b/app/src/main/res/values-lt/strings.xml @@ -7,7 +7,6 @@ Įvyko netikėta klaida. - Nestabilus programėlės ryšys! Pridėti Pridėti žodį \"%1$s\" į \"%2$s\" žodyną? Perkelkite žymeklį prie žodžio kurį norite pridėti. diff --git a/app/src/main/res/values-nl/strings.xml b/app/src/main/res/values-nl/strings.xml index 30e46a6b..319c2f1f 100644 --- a/app/src/main/res/values-nl/strings.xml +++ b/app/src/main/res/values-nl/strings.xml @@ -4,7 +4,6 @@ Laden… Er is een onverwachte fout opgetreden. - Onstabiele applicatieverbinding! Toevoegen Voeg woord \"%1$s\" toe aan %2$s? Verplaats de cursor binnen een woord om het toe te voegen. diff --git a/app/src/main/res/values-pt-rBR/strings.xml b/app/src/main/res/values-pt-rBR/strings.xml index a146a552..aea3f3cc 100644 --- a/app/src/main/res/values-pt-rBR/strings.xml +++ b/app/src/main/res/values-pt-rBR/strings.xml @@ -6,7 +6,6 @@ Carregando… Um erro inesperado aconteceu. - Conexão instável com o aplicativo! Adicionar Adicionar a palavra \"%1$s\" a %2$s? Mova o cursor dentro de uma palavra para adicioná-la. diff --git a/app/src/main/res/values-ru/strings.xml b/app/src/main/res/values-ru/strings.xml index 56829187..2cc14e37 100644 --- a/app/src/main/res/values-ru/strings.xml +++ b/app/src/main/res/values-ru/strings.xml @@ -5,7 +5,6 @@ Выполнено Загрузка… Произошла непредвиденная ошибка. - Нестабильное соединение с приложением! Добавить Переместите курсор внутрь слова, чтобы добавить его. Невозможно добавить слово. diff --git a/app/src/main/res/values-tr/strings.xml b/app/src/main/res/values-tr/strings.xml index e7875627..6d4ee962 100644 --- a/app/src/main/res/values-tr/strings.xml +++ b/app/src/main/res/values-tr/strings.xml @@ -4,7 +4,6 @@ Yükleniyor… Beklenmeyen bir hata ile karşılaşıldı. - Uygulama bağlantısı kararsız! Ekle \"%1$s\" kelimesi %2$s sözlüğe eklensin mi? Ekleme yapmak için imleci eklemek istediğiniz kelimeye götürün. diff --git a/app/src/main/res/values-uk/strings.xml b/app/src/main/res/values-uk/strings.xml index 944e8324..2df04ed4 100644 --- a/app/src/main/res/values-uk/strings.xml +++ b/app/src/main/res/values-uk/strings.xml @@ -7,7 +7,6 @@ Сталася неочікувана помилка. - Нестабільне з\'єднання з додатком! Додати Додати слово \"%1$s\" в %2$s? Перемістіть курсор у слово, щоб додати його. diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 7357e0ba..b875e6c1 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -11,7 +11,6 @@ No results. Unexpected error occurred. - Unstable application connection! Add Add word \"%1$s\" to %2$s?