1
0
Fork 0

zombie check now rely on internal 'isDead' flag instead of 'currentInputConnection', which is no more

This commit is contained in:
sspanak 2024-10-05 14:48:35 +03:00
parent 9e951a6283
commit 309d245a53
2 changed files with 17 additions and 24 deletions

View file

@ -21,9 +21,9 @@ import io.github.sspanak.tt9.util.Logger;
import io.github.sspanak.tt9.util.SystemSettings; import io.github.sspanak.tt9.util.SystemSettings;
public class TraditionalT9 extends MainViewHandler { public class TraditionalT9 extends MainViewHandler {
@NonNull @NonNull private final Handler backgroundTasks = new Handler(Looper.getMainLooper());
private final Handler backgroundTasks = new Handler(Looper.getMainLooper()); @NonNull private final Handler zombieDetector = new Handler(Looper.getMainLooper());
private final Handler zombieDetector = new Handler(Looper.getMainLooper()); private boolean isDead = false;
private int zombieChecks = 0; private int zombieChecks = 0;
@ -115,6 +115,7 @@ public class TraditionalT9 extends MainViewHandler {
@Override @Override
protected void onInit() { protected void onInit() {
isDead = false;
settings.setDemoMode(false); settings.setDemoMode(false);
Logger.setLevel(settings.getLogLevel()); Logger.setLevel(settings.getLogLevel());
DataStore.init(this); DataStore.init(this);
@ -125,8 +126,7 @@ public class TraditionalT9 extends MainViewHandler {
@Override @Override
protected boolean onStart(InputConnection connection, EditorInfo field) { protected boolean onStart(InputConnection connection, EditorInfo field) {
if (!SystemSettings.isTT9Active(this)) { if (!SystemSettings.isTT9Active(this)) {
onStop(); onDestroy(); // it will call onFinishInput() -> onStop() -> onZombie().
onDeath();
return false; 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. * 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. * Here we attempt to detect if we are disabled, then hide and kill ourselves.
*/ */
private void startZombieCheck() { protected void startZombieCheck() {
if (!SystemSettings.isTT9Active(this)) { if (!SystemSettings.isTT9Active(this)) {
onDeath(); zombieChecks = 0;
onZombie();
return; return;
} }
@ -199,25 +200,19 @@ public class TraditionalT9 extends MainViewHandler {
} }
private void onDeath() { private void onZombie() {
if (currentInputConnection == null) { if (isDead) {
Logger.w("onDeath", "===> Already dead. Nothing to do."); Logger.w("onZombie", "===> Already dead. Nothing to do.");
return; return;
} }
Logger.w("onDeath", "===> Killing self"); Logger.w("onZombie", "===> Killing self");
requestHideSelf(0); requestHideSelf(0);
setInputField(null, null); setInputField(null, null);
backgroundTasks.removeCallbacksAndMessages(null); backgroundTasks.removeCallbacksAndMessages(null);
zombieDetector.removeCallbacksAndMessages(null); zombieDetector.removeCallbacksAndMessages(null);
stopSelf(); stopSelf();
} isDead = true;
@Override
public void onDestroy() {
onDeath();
super.onDestroy();
} }

View file

@ -27,7 +27,6 @@ import io.github.sspanak.tt9.util.Text;
public abstract class TypingHandler extends KeyPadHandler { public abstract class TypingHandler extends KeyPadHandler {
// internal settings/data // internal settings/data
@NonNull protected AppHacks appHacks = new AppHacks(null,null, null, null, null); @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 InputType inputType = new InputType(null, null);
@NonNull protected TextField textField = new TextField(null, null); @NonNull protected TextField textField = new TextField(null, null);
@NonNull protected TextSelection textSelection = new TextSelection(this,null); @NonNull protected TextSelection textSelection = new TextSelection(this,null);
@ -49,7 +48,7 @@ public abstract class TypingHandler extends KeyPadHandler {
protected boolean shouldBeOff() { protected boolean shouldBeOff() {
return currentInputConnection == null || mInputMode.isPassthrough(); return getCurrentInputConnection() == null || mInputMode.isPassthrough();
} }
@Override @Override
@ -83,10 +82,9 @@ public abstract class TypingHandler extends KeyPadHandler {
return; return;
} }
currentInputConnection = connection; inputType = new InputType(connection, field);
inputType = new InputType(currentInputConnection, field); textField = new TextField(connection, field);
textField = new TextField(currentInputConnection, field); textSelection = new TextSelection(this, connection);
textSelection = new TextSelection(this, currentInputConnection);
// changing the TextField and notifying all interested classes is an atomic operation // changing the TextField and notifying all interested classes is an atomic operation
appHacks = new AppHacks(settings, connection, inputType, textField, textSelection); appHacks = new AppHacks(settings, connection, inputType, textField, textSelection);