Skip to content

Commit

Permalink
Summer bugs (#401)
Browse files Browse the repository at this point in the history
* removed isActive and fixed a startup crash in onEvaluateInputViewShown() (#364, #385, #389)

* fixed the MainView is visible in dropdowns or other non-text inputs (#367)

* fixed logging settings not being applied at startup sometimes

* code cleanup: remove using isThereText (#347)

* removed the Messenger Lite hacks, since the app has been discontinued and no longer works

---------

Co-authored-by: alexknop <knopalex@msu.edu>
Co-authored-by: Alex Knop <alexknoptech@protonmail.com>
  • Loading branch information
3 people authored Dec 21, 2023
1 parent c02b414 commit 7cde9ec
Show file tree
Hide file tree
Showing 11 changed files with 58 additions and 80 deletions.
2 changes: 1 addition & 1 deletion res/values-bg/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
<string name="pref_category_appearance">Облик</string>
<string name="pref_category_function_keys">Бутони за бърз достъп</string>
<string name="pref_hack_fb_messenger">Изпращай съобщения с ОК в Messenger</string>
<string name="pref_hack_fb_messenger_summary">Позволява изпращането на съобщения с бутона ОК във Facebook Messenger и Messenger Lite.</string>
<string name="pref_hack_fb_messenger_summary">Позволява изпращането на съобщения с бутона ОК във Facebook Messenger.</string>
<string name="pref_show_soft_function_keys">Бутони на екрана</string>
<string name="key_back">Назад</string>
<string name="key_call">Зелена слушалка</string>
Expand Down
2 changes: 1 addition & 1 deletion res/values-fr/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
<string name="dictionary_load_bad_char">Echec du chargement. Mot inadmissible «%1$s» à la ligne %2$d de langue «%3$s».</string>
<string name="dictionary_truncated">Le dictionaire est supprimé avec succès.</string>
<string name="pref_hack_fb_messenger">Envoyer des messages avec OK dans Messenger</string>
<string name="pref_hack_fb_messenger_summary">La touche OK servira pour envoyer des messages dans Facebook Messenger et Messenger Lite.</string>
<string name="pref_hack_fb_messenger_summary">La touche OK servira pour envoyer des messages dans Facebook Messenger.</string>
<string name="pref_show_soft_function_keys">Boutons à l\'écran</string>
<string name="dictionary_loading_indeterminate">Chargement du dictionnaire</string>
<string name="dictionary_load_cancelled">Chargement est annulé.</string>
Expand Down
2 changes: 1 addition & 1 deletion res/values-ru/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
<string name="pref_auto_text_case_summary">Автоматически начинать предложение с заглавной буквы.</string>
<string name="pref_double_zero_char">Символ при двойном нажатии клавиши 0</string>
<string name="pref_hack_fb_messenger">Отправка сообщения с «ОК» в Messenger</string>
<string name="pref_hack_fb_messenger_summary">Позволяет отправлять сообщения с помощью кнопки «ОК» в Facebook Messenger и Messenger Lite.</string>
<string name="pref_hack_fb_messenger_summary">Позволяет отправлять сообщения с помощью кнопки «ОК» в Facebook Messenger.</string>
<string name="pref_show_soft_function_keys">Кнопки на экране</string>
<string name="dictionary_load_bad_char">Не удалось загрузить словарь. Проблема в слове «%1$s» в строке %2$d для языка «%3$s».</string>
<string name="dictionary_missing_go_load_it">Отсутствует словарь для языка «%1$s». Вы можете загрузить его в Настройках.</string>
Expand Down
2 changes: 1 addition & 1 deletion res/values-uk/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
<string name="pref_auto_text_case_summary">Автоматично починати речення з заголовної букви.</string>
<string name="pref_double_zero_char">Символ при подвійному натисканні клавіші 0</string>
<string name="pref_hack_fb_messenger">Надсилати повідомлення з «ОК» до Messenger</string>
<string name="pref_hack_fb_messenger_summary">Дозволяє надсилати повідомлення за допомогою клавіші «ОК» у Facebook Messenger і Messenger Lite.</string>
<string name="pref_hack_fb_messenger_summary">Дозволяє надсилати повідомлення за допомогою клавіші «ОК» у Facebook Messenger.</string>
<string name="pref_show_soft_function_keys">Кнопки на екрані</string>
<string name="key_back">Назад</string>
<string name="key_call">Виклик</string>
Expand Down
2 changes: 1 addition & 1 deletion res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
<string name="pref_system_logs" translatable="false">System Logs</string>
<string name="pref_double_zero_char">Character for Double 0-key Press</string>
<string name="pref_hack_fb_messenger">Send messages with OK in Messenger</string>
<string name="pref_hack_fb_messenger_summary">Allows sending messages with the OK key in Facebook Messenger and Messenger Lite.</string>
<string name="pref_hack_fb_messenger_summary">Allows sending messages with the OK key in Facebook Messenger.</string>
<string name="pref_show_soft_function_keys">Show On-Screen Keys</string>
<string name="pref_show_soft_numpad">Show On-Screen Numpad</string>
<string name="pref_show_soft_numpad_summary" translatable="false">(BETA)</string>
Expand Down
14 changes: 5 additions & 9 deletions src/io/github/sspanak/tt9/ime/KeyPadHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@


abstract class KeyPadHandler extends InputMethodService {
protected InputConnection currentInputConnection = null;

protected SettingsStore settings;

// temporal key handling
Expand Down Expand Up @@ -44,7 +42,7 @@ public void onCreate() {
@Override
public boolean onEvaluateInputViewShown() {
super.onEvaluateInputViewShown();
onRestart(getCurrentInputEditorInfo());
setInputField(getCurrentInputConnection(), getCurrentInputEditorInfo());
return shouldBeVisible();
}

Expand Down Expand Up @@ -79,15 +77,13 @@ public void onStartInput(EditorInfo inputField, boolean restarting) {
"KeyPadHandler",
"===> Start Up; packageName: " + inputField.packageName + " inputType: " + inputField.inputType + " fieldId: " + inputField.fieldId + " fieldName: " + inputField.fieldName + " privateImeOptions: " + inputField.privateImeOptions + " imeOptions: " + inputField.imeOptions + " extras: " + inputField.extras
);
currentInputConnection = getCurrentInputConnection();
onStart(inputField);
onStart(getCurrentInputConnection(), inputField);
}


@Override
public void onStartInputView(EditorInfo inputField, boolean restarting) {
currentInputConnection = getCurrentInputConnection();
onRestart(inputField);
onStart(getCurrentInputConnection(), inputField);
}


Expand Down Expand Up @@ -294,10 +290,10 @@ protected void resetKeyRepeat() {

// helpers
abstract protected void onInit();
abstract protected void onStart(EditorInfo inputField);
abstract protected void onRestart(EditorInfo inputField);
abstract protected void onStart(InputConnection inputConnection, EditorInfo inputField);
abstract protected void onFinishTyping();
abstract protected void onStop();
abstract protected void setInputField(InputConnection inputConnection, EditorInfo inputField);

// UI
abstract protected View createSoftKeyView();
Expand Down
80 changes: 42 additions & 38 deletions src/io/github/sspanak/tt9/ime/TraditionalT9.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import android.view.KeyEvent;
import android.view.View;
import android.view.inputmethod.EditorInfo;
import android.view.inputmethod.InputConnection;
import android.view.inputmethod.InputMethodManager;

import androidx.annotation.NonNull;
Expand All @@ -34,18 +35,16 @@
import io.github.sspanak.tt9.ui.tray.SuggestionsBar;

public class TraditionalT9 extends KeyPadHandler {
private InputConnection currentInputConnection = null;
// internal settings/data
@NonNull private AppHacks appHacks = new AppHacks(null,null, null, null);
@NonNull private TextField textField = new TextField(null, null);
@NonNull private InputType inputType = new InputType(null, null);
@NonNull private final Handler autoAcceptHandler = new Handler(Looper.getMainLooper());

@Deprecated // migrate to "ModePassthrough" when "isActive" == "false"
private boolean isActive = false;

// input mode
private ArrayList<Integer> allowedInputModes = new ArrayList<>();
private InputMode mInputMode;
@NonNull private InputMode mInputMode = InputMode.getInstance(null, null, null, InputMode.MODE_PASSTHROUGH);

// language
protected ArrayList<Integer> mEnabledLanguages;
Expand All @@ -66,23 +65,23 @@ public SettingsStore getSettings() {
}

public boolean isInputModeNumeric() {
return mInputMode != null && mInputMode.is123();
return mInputMode.is123();
}

public boolean isNumericModeStrict() {
return mInputMode != null && mInputMode.is123() && inputType.isNumeric() && !inputType.isPhoneNumber();
return mInputMode.is123() && inputType.isNumeric() && !inputType.isPhoneNumber();
}

public boolean isNumericModeSigned() {
return mInputMode != null && mInputMode.is123() && inputType.isSignedNumber();
return mInputMode.is123() && inputType.isSignedNumber();
}

public boolean isInputModePhone() {
return mInputMode != null && mInputMode.is123() && inputType.isPhoneNumber();
return mInputMode.is123() && inputType.isPhoneNumber();
}

public int getTextCase() {
return mInputMode != null ? mInputMode.getTextCase() : InputMode.CASE_UNDEFINED;
return mInputMode.getTextCase();
}


Expand All @@ -103,14 +102,18 @@ private void validateFunctionKeys() {


/**
* determineInputMode
* Restore the last input mode or choose a more appropriate one.
* getInputMode
* Load the last input mode or choose a more appropriate one.
* Some input fields support only numbers or are not suited for predictions (e.g. password fields)
*/
private void determineInputMode() {
private InputMode getInputMode() {
if (!inputType.isValid() || (inputType.isLimited() && !appHacks.isTermux())) {
return InputMode.getInstance(settings, mLanguage, inputType, InputMode.MODE_PASSTHROUGH);
}

allowedInputModes = textField.determineInputModes(inputType);
int validModeId = InputModeValidator.validateMode(settings.getInputMode(), allowedInputModes);
mInputMode = InputMode.getInstance(settings, mLanguage, inputType, validModeId);
return InputMode.getInstance(settings, mLanguage, inputType, validModeId);
}


Expand All @@ -123,7 +126,7 @@ private void determineInputMode() {
private void determineTextCase() {
mInputMode.defaultTextCase();
mInputMode.setTextFieldCase(textField.determineTextCase(inputType));
mInputMode.determineNextWordTextCase(textField.isThereText(), textField.getTextBeforeCursor());
mInputMode.determineNextWordTextCase(textField.getTextBeforeCursor());
InputModeValidator.validateTextCase(mInputMode, settings.getTextCase());
}

Expand All @@ -144,6 +147,7 @@ public int onStartCommand(Intent intent, int flags, int startId) {

protected void onInit() {
self = this;
Logger.enableDebugLevel(settings.getDebugLogsEnabled());

DictionaryDb.init(this);
DictionaryDb.normalizeWordFrequencies(settings);
Expand All @@ -157,6 +161,14 @@ protected void onInit() {
}


protected void setInputField(InputConnection connection, EditorInfo field) {
currentInputConnection = connection;
inputType = new InputType(currentInputConnection, field);
textField = new TextField(currentInputConnection, field);
appHacks = new AppHacks(settings, connection, field, textField);
}


private void initTyping() {
// in case we are back from Settings screen, update the language list
mEnabledLanguages = settings.getEnabledLanguageIds();
Expand All @@ -165,7 +177,7 @@ private void initTyping() {

resetKeyRepeat();
setSuggestions(null);
determineInputMode();
mInputMode = getInputMode();
determineTextCase();
}

Expand All @@ -188,41 +200,33 @@ private void initUi() {
if (mainView.createView()) {
initTray();
}
statusBar.setText(mInputMode != null ? mInputMode.toString() : "");
statusBar.setText(mInputMode.toString());
setDarkTheme();
mainView.render();
}


protected void onStart(EditorInfo input) {
inputType = new InputType(currentInputConnection, input);
textField = new TextField(currentInputConnection, input);
appHacks = new AppHacks(settings, currentInputConnection, input, textField);
protected void onStart(InputConnection connection, EditorInfo field) {
Logger.enableDebugLevel(settings.getDebugLogsEnabled());

if (!inputType.isValid() || (inputType.isLimited() && !appHacks.isTermux())) {
setInputField(connection, field);
initTyping();

if (mInputMode.isPassthrough()) {
// When the input is invalid or simple, let Android handle it.
onStop();
updateInputViewShown();
return;
}

initTyping();
initUi();
Logger.enableDebugLevel(settings.getDebugLogsEnabled());

isActive = true;
}


protected void onRestart(EditorInfo inputField) {
if (!isActive) {
onStart(inputField);
}
updateInputViewShown();
}


protected void onFinishTyping() {
cancelAutoAccept();
isActive = false;
mInputMode = InputMode.getInstance(null, null, null, InputMode.MODE_PASSTHROUGH);
}


Expand Down Expand Up @@ -286,7 +290,7 @@ protected boolean onNumber(int key, boolean hold, int repeat) {

// Auto-adjust the text case before each word, if the InputMode supports it.
if (getComposingText().isEmpty()) {
mInputMode.determineNextWordTextCase(textField.isThereText(), textField.getTextBeforeCursor());
mInputMode.determineNextWordTextCase(textField.getTextBeforeCursor());
}

if (!mInputMode.onNumber(key, hold, repeat)) {
Expand Down Expand Up @@ -613,7 +617,7 @@ private void handleSuggestions() {
commitCurrentSuggestion(false);
mInputMode.onAcceptSuggestion(lastComposingText, true);
autoCorrectSpace(lastComposingText, false, -1);
mInputMode.determineNextWordTextCase(textField.isThereText(), textField.getTextBeforeCursor());
mInputMode.determineNextWordTextCase(textField.getTextBeforeCursor());
}

// display the word suggestions
Expand Down Expand Up @@ -709,7 +713,7 @@ else if (mInputMode.isABC() && mInputMode.getTextCase() == InputMode.CASE_LOWER
int nextModeIndex = (allowedInputModes.indexOf(mInputMode.getId()) + 1) % allowedInputModes.size();
mInputMode = InputMode.getInstance(settings, mLanguage, inputType, allowedInputModes.get(nextModeIndex));
mInputMode.setTextFieldCase(textField.determineTextCase(inputType));
mInputMode.determineNextWordTextCase(textField.isThereText(), textField.getTextBeforeCursor());
mInputMode.determineNextWordTextCase(textField.getTextBeforeCursor());

resetKeyRepeat();
}
Expand Down Expand Up @@ -779,12 +783,12 @@ protected void forceShowWindowIfHidden() {

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


@Override
protected boolean shouldBeOff() {
return currentInputConnection == null || !isActive || mInputMode.isPassthrough();
return currentInputConnection == null || mInputMode.isPassthrough();
}
}
24 changes: 1 addition & 23 deletions src/io/github/sspanak/tt9/ime/helpers/AppHacks.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,19 +59,6 @@ private boolean isMessenger() {
}


/**
* isMessengerLite
* Facebook Messenger Lite does not support sending messages with OK/ENTER. To enable that, we
* detect the chat field and apply the proper series of commands to it. See "onFbMessengerEnter()" for info how the hack works.
*/
private boolean isMessengerLite() {
return isAppField(
"com.facebook.mlite",
EditorInfo.TYPE_CLASS_TEXT | EditorInfo.TYPE_TEXT_FLAG_MULTI_LINE | EditorInfo.TYPE_TEXT_FLAG_CAP_SENTENCES | EditorInfo.TYPE_TEXT_FLAG_AUTO_CORRECT
);
}


/**
* isAppField
* Detects a particular input field of a particular application.
Expand Down Expand Up @@ -125,7 +112,7 @@ public boolean onEnter() {
if (isTermux()) {
sendDownUpKeyEvents(KeyEvent.KEYCODE_ENTER);
return true;
} else if (isMessenger() || isMessengerLite()) {
} else if (isMessenger()) {
return onEnterFbMessenger();
}

Expand Down Expand Up @@ -196,17 +183,8 @@ private boolean onEnterFbMessenger() {
// Messenger responds only to ENTER, but not DPAD_CENTER, so we make sure to send the correct code,
// no matter how the hardware key is implemented.
sendDownUpKeyEvents(KeyEvent.KEYCODE_ENTER);
} else {
// Messenger Lite responds to no key codes, so we trick it by going right to the Send button, pressing it,
// then going back to the chat field.
sendDownUpKeyEvents(KeyEvent.KEYCODE_DPAD_RIGHT);
sendDownUpKeyEvents(KeyEvent.KEYCODE_DPAD_RIGHT);
sendDownUpKeyEvents(KeyEvent.KEYCODE_DPAD_CENTER);
sendDownUpKeyEvents(KeyEvent.KEYCODE_DPAD_LEFT);
sendDownUpKeyEvents(KeyEvent.KEYCODE_DPAD_LEFT);
}


return true;
}

Expand Down
2 changes: 1 addition & 1 deletion src/io/github/sspanak/tt9/ime/modes/InputMode.java
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ public void nextTextCase() {
textCase = allowedTextCases.get(nextIndex);
}

public void determineNextWordTextCase(boolean isThereText, String textBeforeCursor) {}
public void determineNextWordTextCase(String textBeforeCursor) {}

// Based on the internal logic of the mode (punctuation or grammar rules), re-adjust the text case for when getSuggestions() is called.
protected String adjustSuggestionTextCase(String word, int newTextCase) { return word; }
Expand Down
4 changes: 2 additions & 2 deletions src/io/github/sspanak/tt9/ime/modes/ModePredictive.java
Original file line number Diff line number Diff line change
Expand Up @@ -295,8 +295,8 @@ protected String adjustSuggestionTextCase(String word, int newTextCase) {
}

@Override
public void determineNextWordTextCase(boolean isThereText, String textBeforeCursor) {
textCase = autoTextCase.determineNextWordTextCase(isThereText, textCase, textFieldTextCase, textBeforeCursor);
public void determineNextWordTextCase(String textBeforeCursor) {
textCase = autoTextCase.determineNextWordTextCase(textCase, textFieldTextCase, textBeforeCursor);
}

@Override
Expand Down
4 changes: 2 additions & 2 deletions src/io/github/sspanak/tt9/ime/modes/helpers/AutoTextCase.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public String adjustSuggestionTextCase(Language language, String word, int newTe
* For example, this function will return CASE_LOWER by default, but CASE_UPPER at the beginning
* of a sentence.
*/
public int determineNextWordTextCase(boolean isThereText, int currentTextCase, int textFieldTextCase, String textBeforeCursor) {
public int determineNextWordTextCase(int currentTextCase, int textFieldTextCase, String textBeforeCursor) {
if (
// When the setting is off, don't do any changes.
!settings.getAutoTextCase()
Expand All @@ -60,7 +60,7 @@ public int determineNextWordTextCase(boolean isThereText, int currentTextCase, i
}

// start of text
if (!isThereText) {
if (textBeforeCursor.isEmpty()) {
return InputMode.CASE_CAPITALIZE;
}

Expand Down

0 comments on commit 7cde9ec

Please sign in to comment.