Skip to content

Commit

Permalink
fixed 123 mode not working on some Kyocera and LG phones... hopefully…
Browse files Browse the repository at this point in the history
…... (#274)
  • Loading branch information
sspanak authored Jun 5, 2023
1 parent ada5b48 commit db53e74
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 65 deletions.
25 changes: 8 additions & 17 deletions src/io/github/sspanak/tt9/ime/KeyPadHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ public void onFinishInput() {
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (shouldBeOff()) {
return super.onKeyDown(keyCode, event);
return false;
}

// Logger.d("onKeyDown", "Key: " + event + " repeat?: " + event.getRepeatCount() + " long-time: " + event.isLongPress());
Expand All @@ -133,26 +133,20 @@ public boolean onKeyDown(int keyCode, KeyEvent event) {
event.startTracking();
}

if (
Key.isNumber(keyCode)
return Key.isNumber(keyCode)
|| Key.isOK(keyCode)
|| Key.isHotkey(settings, keyCode) || Key.isHotkey(settings, -keyCode)
|| keyCode == KeyEvent.KEYCODE_STAR
|| keyCode == KeyEvent.KEYCODE_POUND
|| ((keyCode == KeyEvent.KEYCODE_DPAD_UP || keyCode == KeyEvent.KEYCODE_DPAD_DOWN) && shouldTrackUpDown())
|| ((keyCode == KeyEvent.KEYCODE_DPAD_LEFT || keyCode == KeyEvent.KEYCODE_DPAD_RIGHT) && shouldTrackLeftRight())
) {
return true;
}

return super.onKeyDown(keyCode, event);
|| ((keyCode == KeyEvent.KEYCODE_DPAD_LEFT || keyCode == KeyEvent.KEYCODE_DPAD_RIGHT) && shouldTrackLeftRight());
}


@Override
public boolean onKeyLongPress(int keyCode, KeyEvent event) {
if (shouldBeOff()) {
return super.onKeyLongPress(keyCode, event);
return false;
}

// Logger.d("onLongPress", "LONG PRESS: " + keyCode);
Expand Down Expand Up @@ -183,7 +177,7 @@ public boolean onKeyLongPress(int keyCode, KeyEvent event) {
}

ignoreNextKeyUp = 0;
return super.onKeyLongPress(keyCode, event);
return false;
}


Expand All @@ -195,7 +189,7 @@ public boolean onKeyLongPress(int keyCode, KeyEvent event) {
@Override
public boolean onKeyUp(int keyCode, KeyEvent event) {
if (shouldBeOff()) {
return super.onKeyUp(keyCode, event);
return false;
}

// Logger.d("onKeyUp", "Key: " + keyCode + " repeat?: " + event.getRepeatCount());
Expand Down Expand Up @@ -238,13 +232,10 @@ public boolean onKeyUp(int keyCode, KeyEvent event) {
case KeyEvent.KEYCODE_DPAD_LEFT: return onLeft();
case KeyEvent.KEYCODE_DPAD_RIGHT: return onRight(keyRepeatCounter > 0);
case KeyEvent.KEYCODE_STAR:
case KeyEvent.KEYCODE_POUND:
if (onOtherKey(keyCode)) {
return true;
}
case KeyEvent.KEYCODE_POUND: return onOtherKey(keyCode);
}

return super.onKeyUp(keyCode, event);
return false;
}


Expand Down
10 changes: 5 additions & 5 deletions src/io/github/sspanak/tt9/ime/TraditionalT9.java
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ public boolean onBackspace() {
// 1. Dialer fields seem to handle backspace on their own and we must ignore it,
// otherwise, keyDown race condition occur for all keys.
// 2. Allow the assigned key to function normally, when there is no text (e.g. "Back" navigates back)
if (mInputMode.isDialer() || !textField.isThereText()) {
if (mInputMode.isPassthrough() || !textField.isThereText()) {
Logger.d("onBackspace", "backspace ignored");
mInputMode.reset();
return false;
Expand Down Expand Up @@ -598,7 +598,7 @@ private void refreshComposingText() {


private void nextInputMode() {
if (mInputMode.isDialer()) {
if (mInputMode.isPassthrough()) {
return;
} else if (allowedInputModes.size() == 1 && allowedInputModes.contains(InputMode.MODE_123)) {
mInputMode = !mInputMode.is123() ? InputMode.getInstance(settings, mLanguage, InputMode.MODE_123) : mInputMode;
Expand Down Expand Up @@ -770,7 +770,7 @@ protected View createSoftKeyView() {
*/
protected void forceShowWindowIfHidden() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P
&& !mInputMode.isDialer()
&& !mInputMode.isPassthrough()
&& !isInputViewShown()
) {
requestShowSelf(InputMethodManager.SHOW_IMPLICIT);
Expand All @@ -780,12 +780,12 @@ protected void forceShowWindowIfHidden() {

@Override
protected boolean shouldBeVisible() {
return !mInputMode.isDialer() && isActive;
return !mInputMode.isPassthrough() && isActive;
}


@Override
protected boolean shouldBeOff() {
return currentInputConnection == null || !isActive;
return currentInputConnection == null || !isActive || mInputMode.isPassthrough();
}
}
2 changes: 1 addition & 1 deletion src/io/github/sspanak/tt9/ime/helpers/TextField.java
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ public ArrayList<Integer> determineInputModes(InputType inputType) {
// Dialer field, not to be confused with Phone text field.
// It only accepts 0-9, "#" and "*".
if (inputType.isDialer()) {
allowedModes.add(InputMode.MODE_DIALER);
allowedModes.add(InputMode.MODE_PASSTHROUGH);
return allowedModes;
}

Expand Down
8 changes: 4 additions & 4 deletions src/io/github/sspanak/tt9/ime/modes/InputMode.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ abstract public class InputMode {
public static final int MODE_PREDICTIVE = 0;
public static final int MODE_ABC = 1;
public static final int MODE_123 = 2;
public static final int MODE_DIALER = 4;
public static final int MODE_PASSTHROUGH = 4;

// text case
public static final int CASE_UNDEFINED = -1;
Expand All @@ -41,8 +41,8 @@ public static InputMode getInstance(SettingsStore settings, Language language, i
return new ModePredictive(settings, language);
case MODE_ABC:
return new ModeABC(settings, language);
case MODE_DIALER:
return new ModeDialer();
case MODE_PASSTHROUGH:
return new ModePassthrough();
default:
Logger.w("tt9/InputMode", "Defaulting to mode: " + Mode123.class.getName() + " for unknown InputMode: " + mode);
case MODE_123:
Expand Down Expand Up @@ -80,7 +80,7 @@ public ArrayList<String> getSuggestions() {
// Mode identifiers
public boolean isABC() { return false; }
public boolean is123() { return false; }
public boolean isDialer() { return false; }
public boolean isPassthrough() { return false; }
public boolean isNumeric() { return false; }

// Utility
Expand Down
20 changes: 5 additions & 15 deletions src/io/github/sspanak/tt9/ime/modes/Mode123.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@

import io.github.sspanak.tt9.ime.helpers.Key;

public class Mode123 extends InputMode {
public int getId() { return MODE_123; }
public class Mode123 extends ModePassthrough {
@Override public int getId() { return MODE_123; }
@Override @NonNull public String toString() { return "123"; }

Mode123() {
allowedTextCases.add(CASE_LOWER);
}
@Override public final boolean is123() { return true; }
@Override public boolean isPassthrough() { return false; }

@Override
public boolean onNumber(int number, boolean hold, int repeat) {
Expand All @@ -30,14 +30,4 @@ public boolean onOtherKey(int key) {

return false;
}

@Override public boolean is123() { return true; }
@Override final public boolean isNumeric() { return true; }
@Override public int getSequenceLength() { return 0; }

@NonNull
@Override
public String toString() {
return "123";
}
}
23 changes: 0 additions & 23 deletions src/io/github/sspanak/tt9/ime/modes/ModeDialer.java

This file was deleted.

21 changes: 21 additions & 0 deletions src/io/github/sspanak/tt9/ime/modes/ModePassthrough.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package io.github.sspanak.tt9.ime.modes;

import androidx.annotation.NonNull;

// see: InputType.isDialer()
public class ModePassthrough extends InputMode {
ModePassthrough() {
reset();
allowedTextCases.add(CASE_LOWER);
}

@Override public int getId() { return MODE_PASSTHROUGH; }
@Override public int getSequenceLength() { return 0; }
@Override @NonNull public String toString() { return "Passthrough"; }

@Override public boolean isNumeric() { return true; }
@Override public boolean isPassthrough() { return true; }

public boolean onNumber(int number, boolean hold, int repeat) { return false; }
public boolean onOtherKey(int key) { return false; }
}

0 comments on commit db53e74

Please sign in to comment.