Skip to content

Commit

Permalink
(not so) big code cleanup (#243)
Browse files Browse the repository at this point in the history
* removed some unused resources and code

* removed a nonsense package.json section from .editorconfig

* minimized the usage of mEditing

* removed obsolete toggling of the system candidate view
  • Loading branch information
sspanak authored Apr 28, 2023
1 parent 1fa1e7c commit 4d67c02
Show file tree
Hide file tree
Showing 22 changed files with 40 additions and 61 deletions.
2 changes: 0 additions & 2 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,3 @@ trim_trailing_whitespace = true
[*.md]
indent_style = space
trim_trailing_whitespace = true

[package.json]
2 changes: 0 additions & 2 deletions res/layout/addwordview.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
android:gravity="end">

<Button
android:id="@+id/add_word_cancel"
style="@style/Widget.AppCompat.Button.Borderless.Colored"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
Expand All @@ -39,7 +38,6 @@
android:text="@android:string/cancel" />

<Button
android:id="@+id/add_word_add"
style="@style/Widget.AppCompat.Button.Borderless.Colored"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
Expand Down
2 changes: 0 additions & 2 deletions res/layout/main_numpad.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/main_numpad"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
Expand Down Expand Up @@ -85,7 +84,6 @@
style="@style/numSeparator" />

<io.github.sspanak.tt9.ui.main.keys.SoftBackspaceKey
android:id="@+id/soft_key_backspace"
style="@android:style/Widget.Holo.Button.Borderless"
android:layout_width="0dp"
android:layout_height="match_parent"
Expand Down
2 changes: 0 additions & 2 deletions res/layout/main_small.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/main_small"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
Expand Down Expand Up @@ -68,7 +67,6 @@
style="@style/hSeparator" />

<io.github.sspanak.tt9.ui.main.keys.SoftBackspaceKey
android:id="@+id/soft_key_backspace"
style="@android:style/Widget.Holo.Button.Borderless"
android:layout_width="0dp"
android:layout_height="match_parent"
Expand Down
1 change: 0 additions & 1 deletion res/layout/suggestion_list.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/suggestion_list_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:orientation="horizontal">
Expand Down
1 change: 0 additions & 1 deletion res/layout/suggestion_list_numpad.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/suggestion_list_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:orientation="horizontal">
Expand Down
1 change: 0 additions & 1 deletion res/values-bg/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
<string name="function_reset_keys_done">Възстановени са стандартните „бързи“ бутони.</string>
<string name="setup_keyboard_status">Състояние</string>
<string name="setup_default_keyboard">Избор на клавиатура по подразбиране</string>
<string name="setup_goto_main_screen">Назад към Настройки</string>
<string name="setup_tt9_on">Traditional T9 е активен</string>
<string name="setup_tt9_off">Traditional T9 е изключен</string>
<string name="setup_click_here_to_enable">Натиснете тук, за да включите TT9 от настройките на Андроид.</string>
Expand Down
1 change: 0 additions & 1 deletion res/values-es/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
<string name="char_space">Espacio</string>
<string name="setup_keyboard_status">Estado</string>
<string name="setup_default_keyboard">Selecciona teclado predeterminado</string>
<string name="setup_goto_main_screen">Volver a la pantalla de configuración</string>
<string name="char_newline">Nueva línea</string>
<string name="dictionary_load_title">Cargar diccionario</string>
<string name="dictionary_loading_indeterminate">Cargando diccionario</string>
Expand Down
1 change: 0 additions & 1 deletion res/values-fr/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
<string name="char_space">Espace</string>
<string name="setup_keyboard_status">État</string>
<string name="setup_default_keyboard">Sélectionnez le clavier par défaut</string>
<string name="setup_goto_main_screen">Retour à l\'écran des paramètres</string>
<string name="setup_tt9_on">Traditional T9 est activé</string>
<string name="setup_tt9_off">Traditional T9 est désactivé</string>
<string name="setup_click_here_to_enable">Cliquez ici pour activer TT9 dans les paramètres Android.</string>
Expand Down
1 change: 0 additions & 1 deletion res/values-it/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
<string name="char_space">Spazio</string>
<string name="setup_keyboard_status">Stato</string>
<string name="setup_default_keyboard">Scegli Tastiera predefinita</string>
<string name="setup_goto_main_screen">Torna a Impostazioni</string>
<string name="char_newline">Nuova riga</string>
<string name="pref_upside_down_keys">Invertire l\'ordine delle chiavi</string>
<string name="pref_upside_down_keys_summary">Abilita l\'impostazione se ci sono 7–8–9 sulla prima riga, invece di 1–2–3.</string>
Expand Down
1 change: 0 additions & 1 deletion res/values-ru/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@
<string name="function_reset_keys_done">Настройки кнопок по умолчанию восстановлены.</string>
<string name="setup_keyboard_status">Состояние</string>
<string name="setup_default_keyboard">Выберите клавиатуру по умолчанию</string>
<string name="setup_goto_main_screen">Вернуться к настройкам</string>
<string name="setup_tt9_on">Traditional T9 активен</string>
<string name="setup_tt9_off">Traditional T9 отключен</string>
<string name="setup_click_here_to_enable">Нажмите здесь, чтобы включить TT9 в настройках Android.</string>
Expand Down
1 change: 0 additions & 1 deletion res/values-uk/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
<string name="key_call">Виклик</string>
<string name="setup_keyboard_status">Стан</string>
<string name="setup_default_keyboard">Вибрати стандартну клавіатуру</string>
<string name="setup_goto_main_screen">Назад до налаштувань</string>
<string name="setup_tt9_on">Traditional T9 активний</string>
<string name="setup_tt9_off">Traditional T9 вимкнено</string>
<string name="setup_click_here_to_enable">Натисніть тут, щоб увімкнути TT9 в налаштуваннях Android.</string>
Expand Down
1 change: 0 additions & 1 deletion res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@

<string name="setup_keyboard_status">Status</string>
<string name="setup_default_keyboard">Select Default Keyboard</string>
<string name="setup_goto_main_screen">Return to Settings</string>
<string name="setup_tt9_on">Traditional T9 is enabled</string>
<string name="setup_tt9_off">Traditional T9 is disabled</string>
<string name="setup_click_here_to_enable">Click here to enable TT9 from Android Settings.</string>
Expand Down
2 changes: 1 addition & 1 deletion src/io/github/sspanak/tt9/db/DictionaryLoader.java
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ private void importWords(Language language, String dictionaryFile) throws Except
try {
dbWords.add(stringToWord(language, word, frequency));
} catch (InvalidLanguageCharactersException e) {
throw new DictionaryImportException(dictionaryFile, word, lineCount);
throw new DictionaryImportException(word, lineCount);
}

if (lineCount % settings.getDictionaryImportWordChunkSize() == 0 || lineCount == totalWords - 1) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
package io.github.sspanak.tt9.db.exceptions;

public class DictionaryImportException extends Exception {
public final String file;
public final String word;
public final long line;

public DictionaryImportException(String file, String word, long line) {
public DictionaryImportException(String word, long line) {
super("Dictionary import failed");
this.file = file;
this.word = word;
this.line = line;
}
Expand Down
32 changes: 10 additions & 22 deletions src/io/github/sspanak/tt9/ime/KeyPadHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,6 @@ abstract class KeyPadHandler extends InputMethodService {

protected SettingsStore settings;

// editing mode
protected static final int NON_EDIT = 0;
protected static final int EDITING = 1;
protected static final int EDITING_STRICT_NUMERIC = 3;
protected static final int EDITING_DIALER = 4; // see: https://github.com/sspanak/tt9/issues/46
protected int mEditing = NON_EDIT;

// temporal key handling
private boolean isBackspaceHandled = false;

Expand Down Expand Up @@ -51,7 +44,7 @@ public void onCreate() {
public boolean onEvaluateInputViewShown() {
super.onEvaluateInputViewShown();
onRestart(getCurrentInputEditorInfo());
return mEditing != EDITING_DIALER && mEditing != NON_EDIT;
return shouldBeVisible();
}


Expand Down Expand Up @@ -96,9 +89,7 @@ public void onStartInputView(EditorInfo inputField, boolean restarting) {
@Override
public void onFinishInputView(boolean finishingInput) {
super.onFinishInputView(finishingInput);
if (mEditing == EDITING || mEditing == EDITING_STRICT_NUMERIC) {
onFinishTyping();
}
onFinishTyping();
}

/**
Expand All @@ -109,9 +100,7 @@ public void onFinishInputView(boolean finishingInput) {
public void onFinishInput() {
super.onFinishInput();
// Logger.d("onFinishInput", "When is this called?");
if (mEditing == EDITING || mEditing == EDITING_STRICT_NUMERIC) {
onStop();
}
onStop();
}


Expand All @@ -122,7 +111,7 @@ public void onFinishInput() {
*/
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (isOff()) {
if (shouldBeOff()) {
return super.onKeyDown(keyCode, event);
}

Expand Down Expand Up @@ -161,7 +150,7 @@ public boolean onKeyDown(int keyCode, KeyEvent event) {

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

Expand Down Expand Up @@ -200,7 +189,7 @@ public boolean onKeyLongPress(int keyCode, KeyEvent event) {
*/
@Override
public boolean onKeyUp(int keyCode, KeyEvent event) {
if (isOff()) {
if (shouldBeOff()) {
return super.onKeyUp(keyCode, event);
}

Expand Down Expand Up @@ -273,11 +262,6 @@ private boolean handleHotkey(int keyCode, boolean hold) {
}


private boolean isOff() {
return currentInputConnection == null || mEditing == NON_EDIT;
}


protected void resetKeyRepeat() {
numKeyRepeatCounter = 0;
keyRepeatCounter = 0;
Expand Down Expand Up @@ -312,5 +296,9 @@ protected void resetKeyRepeat() {
abstract protected void onRestart(EditorInfo inputField);
abstract protected void onFinishTyping();
abstract protected void onStop();

// UI
abstract protected View createSoftKeyView();
abstract protected boolean shouldBeVisible();
abstract protected boolean shouldBeOff();
}
36 changes: 23 additions & 13 deletions src/io/github/sspanak/tt9/ime/TraditionalT9.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,13 @@ public class TraditionalT9 extends KeyPadHandler {
private TextField textField;
private InputType inputType;

// editing mode
protected static final int NON_EDIT = 0;
protected static final int EDITING = 1;
protected static final int EDITING_STRICT_NUMERIC = 3;
protected static final int EDITING_DIALER = 4; // see: https://github.com/sspanak/tt9/issues/46
protected int mEditing = NON_EDIT;

// input mode
private ArrayList<Integer> allowedInputModes = new ArrayList<>();
private InputMode mInputMode;
Expand Down Expand Up @@ -365,6 +372,7 @@ public boolean onKeyNextLanguage() {
return true;
}


return false;
}

Expand Down Expand Up @@ -505,14 +513,9 @@ private void setSuggestions(List<String> suggestions) {
}

private void setSuggestions(List<String> suggestions, int selectedIndex) {
if (suggestionBar == null) {
return;
if (suggestionBar != null) {
suggestionBar.setSuggestions(suggestions, selectedIndex);
}

boolean show = suggestions != null && suggestions.size() > 0;

suggestionBar.setSuggestions(suggestions, selectedIndex);
setCandidatesViewShown(show);
}


Expand Down Expand Up @@ -572,15 +575,10 @@ else if (mInputMode.isABC() && mInputMode.getTextCase() == InputMode.CASE_LOWER


private boolean nextLang() {
if (mEditing == EDITING_STRICT_NUMERIC || mEditing == EDITING_DIALER) {
if (mInputMode.is123() || mEnabledLanguages.size() < 2) {
return false;
}

// when only one language is enabled, just acknowledge the key was pressed
if (mEnabledLanguages.size() < 2) {
return true;
}

// select the next language
int previous = mEnabledLanguages.indexOf(mLanguage.getId());
int next = (previous + 1) % mEnabledLanguages.size();
Expand Down Expand Up @@ -743,4 +741,16 @@ protected void forceShowWindowIfHidden() {
requestShowSelf(InputMethodManager.SHOW_IMPLICIT);
}
}


@Override
protected boolean shouldBeVisible() {
return mEditing != EDITING_DIALER && mEditing != NON_EDIT;
}


@Override
protected boolean shouldBeOff() {
return currentInputConnection == null || mEditing == NON_EDIT;
}
}
4 changes: 4 additions & 0 deletions src/io/github/sspanak/tt9/ime/helpers/TextField.java
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,10 @@ private CharSequence highlightText(CharSequence word, int start, int end, boolea


public int getAction() {
if (field == null) {
return EditorInfo.IME_ACTION_NONE;
}

if (field.actionId > 0) {
return field.actionId; // custom action, defined by the connected app
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
package io.github.sspanak.tt9.languages;

public class InvalidLanguageCharactersException extends Exception {
private final Language language;

public InvalidLanguageCharactersException(Language language, String extraMessage) {
super("Some characters are not supported in language: " + language.getName() + ". " + extraMessage);
this.language = language;
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Locale;

import io.github.sspanak.tt9.languages.Characters;
Expand Down
1 change: 0 additions & 1 deletion src/io/github/sspanak/tt9/preferences/SettingsStore.java
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,6 @@ public String getDoubleZeroChar() {
public int getSuggestionSelectAnimationDuration() { return 66; }
public int getSuggestionTranslateAnimationDuration() { return 0; }

public int getSoftKeyInitialDelay() { return 250; /* ms */ }
public int getSoftKeyRepeatDelay() { return 40; /* ms */ }

public int getWordFrequencyMax() { return 25500; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public void enableValidation() {
}

item.setOnPreferenceChangeListener((preference, newValue) -> {
HashSet<String> newLanguages = (HashSet<String>) newValue;
@SuppressWarnings("unchecked") HashSet<String> newLanguages = (HashSet<String>) newValue;
if (newLanguages.size() == 0) {
newLanguages.add("1");
}
Expand Down

0 comments on commit 4d67c02

Please sign in to comment.