another attempt to fix the 'priviliged options' problem
This commit is contained in:
parent
71fd37e1ac
commit
df4ec5478f
4 changed files with 49 additions and 2 deletions
|
|
@ -21,6 +21,7 @@ abstract public class AbstractHandler extends InputMethodService {
|
||||||
abstract protected boolean onStart(InputConnection inputConnection, EditorInfo inputField);
|
abstract protected boolean onStart(InputConnection inputConnection, EditorInfo inputField);
|
||||||
abstract protected void onFinishTyping();
|
abstract protected void onFinishTyping();
|
||||||
abstract protected void onStop();
|
abstract protected void onStop();
|
||||||
|
abstract protected void onDeath();
|
||||||
abstract protected void setInputField(InputConnection inputConnection, EditorInfo inputField);
|
abstract protected void setInputField(InputConnection inputConnection, EditorInfo inputField);
|
||||||
|
|
||||||
// UI
|
// UI
|
||||||
|
|
|
||||||
|
|
@ -103,6 +103,7 @@ abstract public class CommandHandler extends TextEditingHandler {
|
||||||
suggestionOps.cancelDelayedAccept();
|
suggestionOps.cancelDelayedAccept();
|
||||||
stopVoiceInput();
|
stopVoiceInput();
|
||||||
UI.showChangeKeyboardDialog(this);
|
UI.showChangeKeyboardDialog(this);
|
||||||
|
onDeath();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -17,10 +17,12 @@ import io.github.sspanak.tt9.preferences.settings.SettingsStore;
|
||||||
import io.github.sspanak.tt9.ui.UI;
|
import io.github.sspanak.tt9.ui.UI;
|
||||||
import io.github.sspanak.tt9.ui.dialogs.PopupDialog;
|
import io.github.sspanak.tt9.ui.dialogs.PopupDialog;
|
||||||
import io.github.sspanak.tt9.util.Logger;
|
import io.github.sspanak.tt9.util.Logger;
|
||||||
|
import io.github.sspanak.tt9.util.SystemSettings;
|
||||||
|
|
||||||
public class TraditionalT9 extends MainViewHandler {
|
public class TraditionalT9 extends MainViewHandler {
|
||||||
@NonNull
|
@NonNull
|
||||||
private final Handler normalizationHandler = new Handler(Looper.getMainLooper());
|
private final Handler normalizationHandler = new Handler(Looper.getMainLooper());
|
||||||
|
private final Handler deathDetector = new Handler(Looper.getMainLooper());
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
@ -116,6 +118,8 @@ public class TraditionalT9 extends MainViewHandler {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected boolean onStart(InputConnection connection, EditorInfo field) {
|
protected boolean onStart(InputConnection connection, EditorInfo field) {
|
||||||
|
deathDetector.removeCallbacksAndMessages(null);
|
||||||
|
|
||||||
if (!super.onStart(connection, field)) {
|
if (!super.onStart(connection, field)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
@ -157,6 +161,33 @@ public class TraditionalT9 extends MainViewHandler {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* On Android 11 the IME is sometimes not killed when the user switches to a different one.
|
||||||
|
* Here we attempt to detect if we are disabled, then hide and kill ourselves.
|
||||||
|
*/
|
||||||
|
protected void onDeath() {
|
||||||
|
if (SystemSettings.isTT9Active(this)) {
|
||||||
|
Logger.w("onDeath", "===> Still active, rescheduling");
|
||||||
|
deathDetector.postDelayed(this::onDeath, 2000);
|
||||||
|
return;
|
||||||
|
} else {
|
||||||
|
deathDetector.removeCallbacksAndMessages(null);
|
||||||
|
}
|
||||||
|
|
||||||
|
Logger.w("onDeath", "===> Killing self");
|
||||||
|
requestHideSelf(0);
|
||||||
|
onStop();
|
||||||
|
stopSelf();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onDestroy() {
|
||||||
|
super.onDestroy();
|
||||||
|
onDeath();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected boolean onNumber(int key, boolean hold, int repeat) {
|
protected boolean onNumber(int key, boolean hold, int repeat) {
|
||||||
if (mInputMode instanceof ModePredictive && DictionaryLoader.autoLoad(this, mLanguage)) {
|
if (mInputMode instanceof ModePredictive && DictionaryLoader.autoLoad(this, mLanguage)) {
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,9 @@
|
||||||
package io.github.sspanak.tt9.util;
|
package io.github.sspanak.tt9.util;
|
||||||
|
|
||||||
import android.app.Activity;
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
import android.os.LocaleList;
|
import android.os.LocaleList;
|
||||||
|
import android.provider.Settings;
|
||||||
import android.view.inputmethod.InputMethodInfo;
|
import android.view.inputmethod.InputMethodInfo;
|
||||||
import android.view.inputmethod.InputMethodManager;
|
import android.view.inputmethod.InputMethodManager;
|
||||||
|
|
||||||
|
|
@ -14,7 +14,7 @@ public class SystemSettings {
|
||||||
private static InputMethodManager inputManager;
|
private static InputMethodManager inputManager;
|
||||||
private static String packageName;
|
private static String packageName;
|
||||||
|
|
||||||
public static boolean isTT9Enabled(Activity context) {
|
public static boolean isTT9Enabled(Context context) {
|
||||||
inputManager = inputManager == null ? (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE) : inputManager;
|
inputManager = inputManager == null ? (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE) : inputManager;
|
||||||
packageName = packageName == null ? context.getPackageName() : packageName;
|
packageName = packageName == null ? context.getPackageName() : packageName;
|
||||||
|
|
||||||
|
|
@ -26,6 +26,20 @@ public class SystemSettings {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static boolean isTT9Active(Context context) {
|
||||||
|
String defaultIME = Settings.Secure.getString(context.getContentResolver(), Settings.Secure.DEFAULT_INPUT_METHOD);
|
||||||
|
inputManager = inputManager == null ? (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE) : inputManager;
|
||||||
|
packageName = packageName == null ? context.getPackageName() : packageName;
|
||||||
|
|
||||||
|
|
||||||
|
for (final InputMethodInfo imeInfo : inputManager.getEnabledInputMethodList()) {
|
||||||
|
if (packageName.equals(imeInfo.getPackageName()) && imeInfo.getId().equals(defaultIME)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
public static String getLocale() {
|
public static String getLocale() {
|
||||||
Locale locale = Build.VERSION.SDK_INT >= Build.VERSION_CODES.N ? LocaleList.getDefault().get(0) : Locale.getDefault();
|
Locale locale = Build.VERSION.SDK_INT >= Build.VERSION_CODES.N ? LocaleList.getDefault().get(0) : Locale.getDefault();
|
||||||
String country = locale.getCountry();
|
String country = locale.getCountry();
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue