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