restructured and simplified the handlers code a bit
This commit is contained in:
parent
7a45df1ffe
commit
b7565fd90a
4 changed files with 81 additions and 101 deletions
|
|
@ -6,7 +6,6 @@ import android.view.inputmethod.EditorInfo;
|
|||
import android.view.inputmethod.InputConnection;
|
||||
|
||||
import io.github.sspanak.tt9.ime.modes.InputMode;
|
||||
import io.github.sspanak.tt9.preferences.settings.SettingsStore;
|
||||
|
||||
abstract public class AbstractHandler extends InputMethodService {
|
||||
// hardware key handlers
|
||||
|
|
@ -17,8 +16,6 @@ abstract public class AbstractHandler extends InputMethodService {
|
|||
abstract public boolean onOK();
|
||||
abstract public boolean onText(String text, boolean validateOnly); // used for "#", "*" and whatnot
|
||||
|
||||
// helpers
|
||||
abstract public SettingsStore getSettings();
|
||||
abstract protected void onInit();
|
||||
abstract protected boolean onStart(InputConnection inputConnection, EditorInfo inputField);
|
||||
abstract protected void onFinishTyping();
|
||||
|
|
@ -26,7 +23,6 @@ abstract public class AbstractHandler extends InputMethodService {
|
|||
abstract protected void setInputField(InputConnection inputConnection, EditorInfo inputField);
|
||||
|
||||
// UI
|
||||
abstract protected View createMainView();
|
||||
abstract protected void createSuggestionBar(View mainView);
|
||||
abstract protected boolean forceShowWindow();
|
||||
abstract protected void renderMainView();
|
||||
|
|
|
|||
|
|
@ -1,13 +1,10 @@
|
|||
package io.github.sspanak.tt9.ime;
|
||||
|
||||
import android.view.KeyEvent;
|
||||
import android.view.View;
|
||||
import android.view.inputmethod.EditorInfo;
|
||||
|
||||
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.Logger;
|
||||
import io.github.sspanak.tt9.util.Timer;
|
||||
|
||||
|
||||
|
|
@ -40,71 +37,6 @@ abstract class KeyPadHandler extends AbstractHandler {
|
|||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean onEvaluateInputViewShown() {
|
||||
super.onEvaluateInputViewShown();
|
||||
setInputField(getCurrentInputConnection(), getCurrentInputEditorInfo());
|
||||
return shouldBeVisible();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean onEvaluateFullscreenMode() {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Called by the framework when your view for creating input needs to be
|
||||
* generated. This will be called the first time your input method is
|
||||
* displayed, and every time it needs to be re-created such as due to a
|
||||
* configuration change.
|
||||
*/
|
||||
@Override
|
||||
public View onCreateInputView() {
|
||||
return createMainView();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* This is the main point where we do our initialization of the input method
|
||||
* to begin operating on an application. At this point we have been bound to
|
||||
* the client, and are now receiving all of the detailed information about
|
||||
* the target of our edits.
|
||||
*/
|
||||
@Override
|
||||
public void onStartInput(EditorInfo inputField, boolean restarting) {
|
||||
Logger.i(
|
||||
"KeyPadHandler",
|
||||
"===> Start Up; packageName: " + inputField.packageName + " inputType: " + inputField.inputType + " actionId: " + inputField.actionId + " imeOptions: " + inputField.imeOptions + " privateImeOptions: " + inputField.privateImeOptions + " extras: " + inputField.extras
|
||||
);
|
||||
onStart(getCurrentInputConnection(), inputField);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onStartInputView(EditorInfo inputField, boolean restarting) {
|
||||
onStart(getCurrentInputConnection(), inputField);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onFinishInputView(boolean finishingInput) {
|
||||
super.onFinishInputView(finishingInput);
|
||||
onFinishTyping();
|
||||
}
|
||||
|
||||
/**
|
||||
* This is called when the user is done editing a field. We can use this to
|
||||
* reset our state.
|
||||
*/
|
||||
@Override
|
||||
public void onFinishInput() {
|
||||
super.onFinishInput();
|
||||
onStop();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Use this to monitor key events being delivered to the application. We get
|
||||
* first crack at them, and can either resume them or let them continue to
|
||||
|
|
|
|||
30
app/src/main/java/io/github/sspanak/tt9/ime/MainViewOps.java
Normal file
30
app/src/main/java/io/github/sspanak/tt9/ime/MainViewOps.java
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
package io.github.sspanak.tt9.ime;
|
||||
|
||||
import io.github.sspanak.tt9.preferences.settings.SettingsStore;
|
||||
|
||||
abstract public class MainViewOps extends HotkeyHandler {
|
||||
/**** Informational methods for the on-screen keyboard ****/
|
||||
public int getTextCase() {
|
||||
return mInputMode.getTextCase();
|
||||
}
|
||||
|
||||
public boolean isInputModeNumeric() {
|
||||
return mInputMode.is123();
|
||||
}
|
||||
|
||||
public boolean isNumericModeStrict() {
|
||||
return mInputMode.is123() && inputType.isNumeric() && !inputType.isPhoneNumber();
|
||||
}
|
||||
|
||||
public boolean isNumericModeSigned() {
|
||||
return mInputMode.is123() && inputType.isSignedNumber();
|
||||
}
|
||||
|
||||
public boolean isInputModePhone() {
|
||||
return mInputMode.is123() && inputType.isPhoneNumber();
|
||||
}
|
||||
|
||||
public SettingsStore getSettings() {
|
||||
return settings;
|
||||
}
|
||||
}
|
||||
|
|
@ -25,13 +25,62 @@ import io.github.sspanak.tt9.ui.tray.StatusBar;
|
|||
import io.github.sspanak.tt9.util.DeviceInfo;
|
||||
import io.github.sspanak.tt9.util.Logger;
|
||||
|
||||
public class TraditionalT9 extends HotkeyHandler {
|
||||
public class TraditionalT9 extends MainViewOps {
|
||||
@NonNull
|
||||
private final Handler normalizationHandler = new Handler(Looper.getMainLooper());
|
||||
private MainView mainView = null;
|
||||
private StatusBar statusBar = null;
|
||||
|
||||
|
||||
@Override
|
||||
public boolean onEvaluateInputViewShown() {
|
||||
super.onEvaluateInputViewShown();
|
||||
setInputField(getCurrentInputConnection(), getCurrentInputEditorInfo());
|
||||
return shouldBeVisible();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean onEvaluateFullscreenMode() {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public View onCreateInputView() {
|
||||
return createMainView();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onStartInput(EditorInfo inputField, boolean restarting) {
|
||||
Logger.i(
|
||||
"KeyPadHandler",
|
||||
"===> Start Up; packageName: " + inputField.packageName + " inputType: " + inputField.inputType + " actionId: " + inputField.actionId + " imeOptions: " + inputField.imeOptions + " privateImeOptions: " + inputField.privateImeOptions + " extras: " + inputField.extras
|
||||
);
|
||||
onStart(getCurrentInputConnection(), inputField);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onStartInputView(EditorInfo inputField, boolean restarting) {
|
||||
onStart(getCurrentInputConnection(), inputField);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onFinishInputView(boolean finishingInput) {
|
||||
super.onFinishInputView(finishingInput);
|
||||
onFinishTyping();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFinishInput() {
|
||||
super.onFinishInput();
|
||||
onStop();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int onStartCommand(Intent intent, int flags, int startId) {
|
||||
int result = super.onStartCommand(intent, flags, startId);
|
||||
|
|
@ -145,7 +194,7 @@ public class TraditionalT9 extends HotkeyHandler {
|
|||
* createMainView
|
||||
* Generates the actual UI of TT9.
|
||||
*/
|
||||
protected View createMainView() {
|
||||
private View createMainView() {
|
||||
mainView.forceCreateView();
|
||||
initTray();
|
||||
setDarkTheme();
|
||||
|
|
@ -224,31 +273,4 @@ public class TraditionalT9 extends HotkeyHandler {
|
|||
protected boolean shouldBeOff() {
|
||||
return currentInputConnection == null || mInputMode.isPassthrough();
|
||||
}
|
||||
|
||||
|
||||
/**** Informational methods for the on-screen keyboard ****/
|
||||
|
||||
public int getTextCase() {
|
||||
return mInputMode.getTextCase();
|
||||
}
|
||||
|
||||
public boolean isInputModeNumeric() {
|
||||
return mInputMode.is123();
|
||||
}
|
||||
|
||||
public boolean isNumericModeStrict() {
|
||||
return mInputMode.is123() && inputType.isNumeric() && !inputType.isPhoneNumber();
|
||||
}
|
||||
|
||||
public boolean isNumericModeSigned() {
|
||||
return mInputMode.is123() && inputType.isSignedNumber();
|
||||
}
|
||||
|
||||
public boolean isInputModePhone() {
|
||||
return mInputMode.is123() && inputType.isPhoneNumber();
|
||||
}
|
||||
|
||||
public SettingsStore getSettings() {
|
||||
return settings;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue