6th attempt to fix the 'privileged options' problem
This commit is contained in:
parent
22d0d73e29
commit
057702e7b5
8 changed files with 52 additions and 17 deletions
|
|
@ -5,6 +5,7 @@ import android.view.KeyEvent;
|
|||
import io.github.sspanak.tt9.ime.helpers.Key;
|
||||
import io.github.sspanak.tt9.preferences.screens.debug.ItemInputHandlingMode;
|
||||
import io.github.sspanak.tt9.preferences.settings.SettingsStore;
|
||||
import io.github.sspanak.tt9.util.SystemSettings;
|
||||
import io.github.sspanak.tt9.util.Timer;
|
||||
|
||||
|
||||
|
|
@ -28,6 +29,10 @@ abstract class KeyPadHandler extends UiHandler {
|
|||
*/
|
||||
@Override
|
||||
public void onCreate() {
|
||||
if (!SystemSettings.isTT9Selected(this)) {
|
||||
return;
|
||||
}
|
||||
|
||||
super.onCreate();
|
||||
settings = new SettingsStore(getApplicationContext());
|
||||
|
||||
|
|
|
|||
|
|
@ -25,6 +25,12 @@ abstract public class MainViewHandler extends HotkeyHandler {
|
|||
}
|
||||
}
|
||||
|
||||
protected void cleanUp() {
|
||||
mainView.removeListeners();
|
||||
orientationListener.stop();
|
||||
orientationListener = null;
|
||||
}
|
||||
|
||||
public int getTextCase() {
|
||||
return mInputMode.getTextCase();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -30,7 +30,7 @@ public class TraditionalT9 extends MainViewHandler {
|
|||
@Override
|
||||
public boolean onEvaluateInputViewShown() {
|
||||
super.onEvaluateInputViewShown();
|
||||
if (!SystemSettings.isTT9Active(this)) {
|
||||
if (!SystemSettings.isTT9Selected(this)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
@ -47,7 +47,7 @@ public class TraditionalT9 extends MainViewHandler {
|
|||
|
||||
@Override
|
||||
public View onCreateInputView() {
|
||||
mainView.forceCreateInputView();
|
||||
mainView.forceCreate();
|
||||
initTray();
|
||||
setDarkTheme();
|
||||
statusBar.setText(mInputMode);
|
||||
|
|
@ -113,6 +113,7 @@ public class TraditionalT9 extends MainViewHandler {
|
|||
return result;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void onInit() {
|
||||
isDead = false;
|
||||
|
|
@ -125,12 +126,12 @@ public class TraditionalT9 extends MainViewHandler {
|
|||
|
||||
@Override
|
||||
protected boolean onStart(InputConnection connection, EditorInfo field) {
|
||||
if (!SystemSettings.isTT9Active(this)) {
|
||||
onDestroy(); // it will call onFinishInput() -> onStop() -> onZombie().
|
||||
if (!SystemSettings.isTT9Selected(this) && !isDead) {
|
||||
zombieDetector.postDelayed(this::startZombieCheck, SettingsStore.ZOMBIE_CHECK_INTERVAL);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!super.onStart(connection, field)) {
|
||||
if (isDead || !super.onStart(connection, field)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
@ -169,7 +170,7 @@ public class TraditionalT9 extends MainViewHandler {
|
|||
updateInputViewShown();
|
||||
}
|
||||
|
||||
if (SystemSettings.isTT9Active(this)) {
|
||||
if (SystemSettings.isTT9Selected(this)) {
|
||||
backgroundTasks.removeCallbacksAndMessages(null);
|
||||
backgroundTasks.postDelayed(this::runBackgroundTasks, SettingsStore.WORD_BACKGROUND_TASKS_DELAY);
|
||||
}
|
||||
|
|
@ -185,7 +186,7 @@ public class TraditionalT9 extends MainViewHandler {
|
|||
* Here we attempt to detect if we are disabled, then hide and kill ourselves.
|
||||
*/
|
||||
protected void startZombieCheck() {
|
||||
if (!SystemSettings.isTT9Active(this)) {
|
||||
if (!SystemSettings.isTT9Selected(this)) {
|
||||
zombieChecks = 0;
|
||||
onZombie();
|
||||
return;
|
||||
|
|
@ -200,7 +201,7 @@ public class TraditionalT9 extends MainViewHandler {
|
|||
}
|
||||
|
||||
|
||||
private void onZombie() {
|
||||
protected void onZombie() {
|
||||
if (isDead) {
|
||||
Logger.w("onZombie", "===> Already dead. Nothing to do.");
|
||||
return;
|
||||
|
|
@ -208,11 +209,25 @@ public class TraditionalT9 extends MainViewHandler {
|
|||
|
||||
Logger.w("onZombie", "===> Killing self");
|
||||
requestHideSelf(0);
|
||||
cleanUp();
|
||||
stopSelf();
|
||||
isDead = true;
|
||||
}
|
||||
|
||||
|
||||
protected void cleanUp() {
|
||||
super.cleanUp();
|
||||
setInputField(null, null);
|
||||
backgroundTasks.removeCallbacksAndMessages(null);
|
||||
zombieDetector.removeCallbacksAndMessages(null);
|
||||
stopSelf();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onDestroy() {
|
||||
cleanUp();
|
||||
isDead = true;
|
||||
super.onDestroy();
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -33,7 +33,7 @@ abstract class UiHandler extends AbstractHandler {
|
|||
|
||||
|
||||
public void initUi(InputMode inputMode) {
|
||||
if (mainView.createInputView()) {
|
||||
if (mainView.create()) {
|
||||
initTray();
|
||||
}
|
||||
setDarkTheme();
|
||||
|
|
|
|||
|
|
@ -39,4 +39,8 @@ public class OrientationListener extends android.view.OrientationEventListener {
|
|||
enable();
|
||||
}
|
||||
}
|
||||
|
||||
public void stop() {
|
||||
disable();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,10 +14,10 @@ public class MainView {
|
|||
protected MainView(TraditionalT9 tt9) {
|
||||
this.tt9 = tt9;
|
||||
|
||||
forceCreateInputView();
|
||||
forceCreate();
|
||||
}
|
||||
|
||||
public boolean createInputView() {
|
||||
public boolean create() {
|
||||
SettingsStore settings = tt9.getSettings();
|
||||
|
||||
if (settings.isMainLayoutNumpad() && !(main instanceof MainLayoutNumpad)) {
|
||||
|
|
@ -37,9 +37,9 @@ public class MainView {
|
|||
return true;
|
||||
}
|
||||
|
||||
public void forceCreateInputView() {
|
||||
public void forceCreate() {
|
||||
main = null;
|
||||
if (!createInputView()) {
|
||||
if (!create()) {
|
||||
Logger.w(getClass().getSimpleName(), "Invalid MainView setting. Creating default.");
|
||||
main = new MainLayoutSmall(tt9);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -36,8 +36,8 @@ public class ResizableMainView extends MainView implements View.OnAttachStateCha
|
|||
|
||||
|
||||
@Override
|
||||
public boolean createInputView() {
|
||||
if (!super.createInputView()) {
|
||||
public boolean create() {
|
||||
if (!super.create()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
@ -49,6 +49,11 @@ public class ResizableMainView extends MainView implements View.OnAttachStateCha
|
|||
return true;
|
||||
}
|
||||
|
||||
public void removeListeners() {
|
||||
if (main != null && main.getView() != null) {
|
||||
main.getView().removeOnAttachStateChangeListener(this);
|
||||
}
|
||||
}
|
||||
|
||||
private void onCreateAdjustHeight() {
|
||||
if (tt9.getSettings().isMainLayoutNumpad() && height > heightSmall && height <= heightNumpad) {
|
||||
|
|
|
|||
|
|
@ -28,7 +28,7 @@ public class SystemSettings {
|
|||
return false;
|
||||
}
|
||||
|
||||
public static boolean isTT9Active(Context context) {
|
||||
public static boolean isTT9Selected(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;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue