removed the InputConnectionCompat as it does not seem to have any effect
This commit is contained in:
parent
0058928709
commit
4d714cf5e7
16 changed files with 2 additions and 167 deletions
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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<Boolean> 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;
|
||||
}
|
||||
}
|
||||
|
|
@ -5,7 +5,6 @@
|
|||
<string name="completed">Завършено</string>
|
||||
<string name="loading">Зареждане…</string>
|
||||
<string name="error_unexpected">Възникна неочаквана грешка.</string>
|
||||
<string name="error_unstable_input_connection">Нестабилна връзка с приложението!</string>
|
||||
<string name="add_word_add">Добави</string>
|
||||
<string name="add_word_no_selection">Преместете показалеца върху дума, за да я добавите към речника.</string>
|
||||
<string name="add_word_blank">Не може да се въведе празна дума.</string>
|
||||
|
|
|
|||
|
|
@ -4,7 +4,6 @@
|
|||
<string name="loading">Laden…</string>
|
||||
<string name="error_unexpected">Unerwarteter Fehler aufgetreten.</string>
|
||||
|
||||
<string name="error_unstable_input_connection">Instabile Anwendungsverbindung!</string>
|
||||
<string name="add_word_add">Hinzufügen</string>
|
||||
<string name="add_word_confirm">Wort \"%1$s\" zu %2$s hinzufügen?</string>
|
||||
<string name="add_word_no_selection">Bewegen Sie den Cursor innerhalb eines Wortes, um es hinzuzufügen.</string>
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
<string name="app_settings">Configuración de Traditional T9</string>
|
||||
<string name="error_unstable_input_connection">¡Conexión inestable con la aplicación!</string>
|
||||
<string name="add_word_add">Agregar</string>
|
||||
<string name="add_word_confirm">¿Agregar la palabra \"%1$s\" a %2$s?</string>
|
||||
<string name="add_word_no_selection">Mueve el cursor dentro de una palabra para añadirla.</string>
|
||||
|
|
|
|||
|
|
@ -5,7 +5,6 @@
|
|||
<string name="completed">Fini</string>
|
||||
<string name="loading">Chargement…</string>
|
||||
<string name="error_unexpected">Une erreur inattendue s\'est produite.</string>
|
||||
<string name="error_unstable_input_connection">Connexion instable à l\'application !</string>
|
||||
<string name="add_word_add">Ajouter</string>
|
||||
<string name="add_word_no_selection">Déplacez le curseur dans un mot pour l\'ajouter.</string>
|
||||
<string name="add_word_blank">Mot vide non ajouté.</string>
|
||||
|
|
|
|||
|
|
@ -6,7 +6,6 @@
|
|||
<string name="loading">Caricamento…</string>
|
||||
<string name="error_unexpected">Si è verificato un errore imprevisto.</string>
|
||||
|
||||
<string name="error_unstable_input_connection">Connessione instabile all\'applicazione!</string>
|
||||
<string name="add_word_add">Aggiungere</string>
|
||||
<string name="add_word_confirm">Aggiungi la parola \"%1$s\" a %2$s?</string>
|
||||
<string name="add_word_no_selection">Sposta il cursore dentro un parola per aggiungerla.</string>
|
||||
|
|
|
|||
|
|
@ -6,7 +6,6 @@
|
|||
<string name="loading">טוען…</string>
|
||||
<string name="error_unexpected">אירעה שגיאה לא צפויה.</string>
|
||||
|
||||
<string name="error_unstable_input_connection">חיבור לא יציב לאפליקציה!</string>
|
||||
<string name="add_word_add">הוסף</string>
|
||||
<string name="add_word_confirm">האם להוסיף את המילה \"%1$s\" ל-%2$s?</string>
|
||||
<string name="add_word_no_selection">הזיזו את הסמן בתוך מילה כדי להוסיף אותה.</string>
|
||||
|
|
|
|||
|
|
@ -7,7 +7,6 @@
|
|||
|
||||
<string name="error_unexpected">Įvyko netikėta klaida.</string>
|
||||
|
||||
<string name="error_unstable_input_connection">Nestabilus programėlės ryšys!</string>
|
||||
<string name="add_word_add">Pridėti</string>
|
||||
<string name="add_word_confirm">Pridėti žodį \"%1$s\" į \"%2$s\" žodyną?</string>
|
||||
<string name="add_word_no_selection">Perkelkite žymeklį prie žodžio kurį norite pridėti.</string>
|
||||
|
|
|
|||
|
|
@ -4,7 +4,6 @@
|
|||
<string name="loading">Laden…</string>
|
||||
<string name="error_unexpected">Er is een onverwachte fout opgetreden.</string>
|
||||
|
||||
<string name="error_unstable_input_connection">Onstabiele applicatieverbinding!</string>
|
||||
<string name="add_word_add">Toevoegen</string>
|
||||
<string name="add_word_confirm">Voeg woord \"%1$s\" toe aan %2$s?</string>
|
||||
<string name="add_word_no_selection">Verplaats de cursor binnen een woord om het toe te voegen.</string>
|
||||
|
|
|
|||
|
|
@ -6,7 +6,6 @@
|
|||
<string name="loading">Carregando…</string>
|
||||
<string name="error_unexpected">Um erro inesperado aconteceu.</string>
|
||||
|
||||
<string name="error_unstable_input_connection">Conexão instável com o aplicativo!</string>
|
||||
<string name="add_word_add">Adicionar</string>
|
||||
<string name="add_word_confirm">Adicionar a palavra \"%1$s\" a %2$s?</string>
|
||||
<string name="add_word_no_selection">Mova o cursor dentro de uma palavra para adicioná-la.</string>
|
||||
|
|
|
|||
|
|
@ -5,7 +5,6 @@
|
|||
<string name="completed">Выполнено</string>
|
||||
<string name="loading">Загрузка…</string>
|
||||
<string name="error_unexpected">Произошла непредвиденная ошибка.</string>
|
||||
<string name="error_unstable_input_connection">Нестабильное соединение с приложением!</string>
|
||||
<string name="add_word_add">Добавить</string>
|
||||
<string name="add_word_no_selection">Переместите курсор внутрь слова, чтобы добавить его.</string>
|
||||
<string name="add_word_blank">Невозможно добавить слово.</string>
|
||||
|
|
|
|||
|
|
@ -4,7 +4,6 @@
|
|||
<string name="loading">Yükleniyor…</string>
|
||||
<string name="error_unexpected">Beklenmeyen bir hata ile karşılaşıldı.</string>
|
||||
|
||||
<string name="error_unstable_input_connection">Uygulama bağlantısı kararsız!</string>
|
||||
<string name="add_word_add">Ekle</string>
|
||||
<string name="add_word_confirm">\"%1$s\" kelimesi %2$s sözlüğe eklensin mi?</string>
|
||||
<string name="add_word_no_selection">Ekleme yapmak için imleci eklemek istediğiniz kelimeye götürün.</string>
|
||||
|
|
|
|||
|
|
@ -7,7 +7,6 @@
|
|||
|
||||
<string name="error_unexpected">Сталася неочікувана помилка.</string>
|
||||
|
||||
<string name="error_unstable_input_connection">Нестабільне з\'єднання з додатком!</string>
|
||||
<string name="add_word_add">Додати</string>
|
||||
<string name="add_word_confirm">Додати слово \"%1$s\" в %2$s?</string>
|
||||
<string name="add_word_no_selection">Перемістіть курсор у слово, щоб додати його.</string>
|
||||
|
|
|
|||
|
|
@ -11,7 +11,6 @@
|
|||
<string name="search_results_void">No results.</string>
|
||||
|
||||
<string name="error_unexpected">Unexpected error occurred.</string>
|
||||
<string name="error_unstable_input_connection">Unstable application connection!</string>
|
||||
|
||||
<string name="add_word_add">Add</string>
|
||||
<string name="add_word_confirm">Add word \"%1$s\" to %2$s?</string>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue