From 309d245a53319fc69c6c2f3935fbb81eeba8e9ac Mon Sep 17 00:00:00 2001 From: sspanak Date: Sat, 5 Oct 2024 14:48:35 +0300 Subject: [PATCH] zombie check now rely on internal 'isDead' flag instead of 'currentInputConnection', which is no more --- .../github/sspanak/tt9/ime/TraditionalT9.java | 31 ++++++++----------- .../github/sspanak/tt9/ime/TypingHandler.java | 10 +++--- 2 files changed, 17 insertions(+), 24 deletions(-) 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 5cd1e53b..803f09dc 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 @@ -21,9 +21,9 @@ import io.github.sspanak.tt9.util.Logger; import io.github.sspanak.tt9.util.SystemSettings; public class TraditionalT9 extends MainViewHandler { - @NonNull - private final Handler backgroundTasks = new Handler(Looper.getMainLooper()); - private final Handler zombieDetector = new Handler(Looper.getMainLooper()); + @NonNull private final Handler backgroundTasks = new Handler(Looper.getMainLooper()); + @NonNull private final Handler zombieDetector = new Handler(Looper.getMainLooper()); + private boolean isDead = false; private int zombieChecks = 0; @@ -115,6 +115,7 @@ public class TraditionalT9 extends MainViewHandler { @Override protected void onInit() { + isDead = false; settings.setDemoMode(false); Logger.setLevel(settings.getLogLevel()); DataStore.init(this); @@ -125,8 +126,7 @@ public class TraditionalT9 extends MainViewHandler { @Override protected boolean onStart(InputConnection connection, EditorInfo field) { if (!SystemSettings.isTT9Active(this)) { - onStop(); - onDeath(); + onDestroy(); // it will call onFinishInput() -> onStop() -> onZombie(). return false; } @@ -184,9 +184,10 @@ 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. */ - private void startZombieCheck() { + protected void startZombieCheck() { if (!SystemSettings.isTT9Active(this)) { - onDeath(); + zombieChecks = 0; + onZombie(); return; } @@ -199,25 +200,19 @@ public class TraditionalT9 extends MainViewHandler { } - private void onDeath() { - if (currentInputConnection == null) { - Logger.w("onDeath", "===> Already dead. Nothing to do."); + private void onZombie() { + if (isDead) { + Logger.w("onZombie", "===> Already dead. Nothing to do."); return; } - Logger.w("onDeath", "===> Killing self"); + Logger.w("onZombie", "===> Killing self"); requestHideSelf(0); setInputField(null, null); backgroundTasks.removeCallbacksAndMessages(null); zombieDetector.removeCallbacksAndMessages(null); stopSelf(); - } - - - @Override - public void onDestroy() { - onDeath(); - super.onDestroy(); + isDead = true; } diff --git a/app/src/main/java/io/github/sspanak/tt9/ime/TypingHandler.java b/app/src/main/java/io/github/sspanak/tt9/ime/TypingHandler.java index 98f31bc3..c2033f90 100644 --- a/app/src/main/java/io/github/sspanak/tt9/ime/TypingHandler.java +++ b/app/src/main/java/io/github/sspanak/tt9/ime/TypingHandler.java @@ -27,7 +27,6 @@ import io.github.sspanak.tt9.util.Text; public abstract class TypingHandler extends KeyPadHandler { // internal settings/data @NonNull protected AppHacks appHacks = new AppHacks(null,null, null, null, null); - protected InputConnection currentInputConnection = null; @NonNull protected InputType inputType = new InputType(null, null); @NonNull protected TextField textField = new TextField(null, null); @NonNull protected TextSelection textSelection = new TextSelection(this,null); @@ -49,7 +48,7 @@ public abstract class TypingHandler extends KeyPadHandler { protected boolean shouldBeOff() { - return currentInputConnection == null || mInputMode.isPassthrough(); + return getCurrentInputConnection() == null || mInputMode.isPassthrough(); } @Override @@ -83,10 +82,9 @@ public abstract class TypingHandler extends KeyPadHandler { return; } - currentInputConnection = connection; - inputType = new InputType(currentInputConnection, field); - textField = new TextField(currentInputConnection, field); - textSelection = new TextSelection(this, currentInputConnection); + inputType = new InputType(connection, field); + textField = new TextField(connection, field); + textSelection = new TextSelection(this, connection); // changing the TextField and notifying all interested classes is an atomic operation appHacks = new AppHacks(settings, connection, inputType, textField, textSelection);