(not so) big code cleanup (#243)
* 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
This commit is contained in:
parent
1fa1e7c6e6
commit
4d67c02340
22 changed files with 40 additions and 61 deletions
|
|
@ -216,7 +216,7 @@ public class DictionaryLoader {
|
|||
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) {
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
||||
|
|
@ -51,7 +44,7 @@ abstract class KeyPadHandler extends InputMethodService {
|
|||
public boolean onEvaluateInputViewShown() {
|
||||
super.onEvaluateInputViewShown();
|
||||
onRestart(getCurrentInputEditorInfo());
|
||||
return mEditing != EDITING_DIALER && mEditing != NON_EDIT;
|
||||
return shouldBeVisible();
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -96,9 +89,7 @@ abstract class KeyPadHandler extends InputMethodService {
|
|||
@Override
|
||||
public void onFinishInputView(boolean finishingInput) {
|
||||
super.onFinishInputView(finishingInput);
|
||||
if (mEditing == EDITING || mEditing == EDITING_STRICT_NUMERIC) {
|
||||
onFinishTyping();
|
||||
}
|
||||
onFinishTyping();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -109,9 +100,7 @@ abstract class KeyPadHandler extends InputMethodService {
|
|||
public void onFinishInput() {
|
||||
super.onFinishInput();
|
||||
// Logger.d("onFinishInput", "When is this called?");
|
||||
if (mEditing == EDITING || mEditing == EDITING_STRICT_NUMERIC) {
|
||||
onStop();
|
||||
}
|
||||
onStop();
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -122,7 +111,7 @@ abstract class KeyPadHandler extends InputMethodService {
|
|||
*/
|
||||
@Override
|
||||
public boolean onKeyDown(int keyCode, KeyEvent event) {
|
||||
if (isOff()) {
|
||||
if (shouldBeOff()) {
|
||||
return super.onKeyDown(keyCode, event);
|
||||
}
|
||||
|
||||
|
|
@ -161,7 +150,7 @@ abstract class KeyPadHandler extends InputMethodService {
|
|||
|
||||
@Override
|
||||
public boolean onKeyLongPress(int keyCode, KeyEvent event) {
|
||||
if (isOff()) {
|
||||
if (shouldBeOff()) {
|
||||
return super.onKeyLongPress(keyCode, event);
|
||||
}
|
||||
|
||||
|
|
@ -200,7 +189,7 @@ abstract class KeyPadHandler extends InputMethodService {
|
|||
*/
|
||||
@Override
|
||||
public boolean onKeyUp(int keyCode, KeyEvent event) {
|
||||
if (isOff()) {
|
||||
if (shouldBeOff()) {
|
||||
return super.onKeyUp(keyCode, event);
|
||||
}
|
||||
|
||||
|
|
@ -273,11 +262,6 @@ abstract class KeyPadHandler extends InputMethodService {
|
|||
}
|
||||
|
||||
|
||||
private boolean isOff() {
|
||||
return currentInputConnection == null || mEditing == NON_EDIT;
|
||||
}
|
||||
|
||||
|
||||
protected void resetKeyRepeat() {
|
||||
numKeyRepeatCounter = 0;
|
||||
keyRepeatCounter = 0;
|
||||
|
|
@ -312,5 +296,9 @@ abstract class KeyPadHandler extends InputMethodService {
|
|||
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();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
@ -365,6 +372,7 @@ public class TraditionalT9 extends KeyPadHandler {
|
|||
return true;
|
||||
}
|
||||
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
@ -505,14 +513,9 @@ public class TraditionalT9 extends KeyPadHandler {
|
|||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -572,15 +575,10 @@ public class TraditionalT9 extends KeyPadHandler {
|
|||
|
||||
|
||||
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();
|
||||
|
|
@ -743,4 +741,16 @@ public class TraditionalT9 extends KeyPadHandler {
|
|||
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;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -317,6 +317,10 @@ public class TextField {
|
|||
|
||||
|
||||
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
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,7 +2,6 @@ package io.github.sspanak.tt9.languages.definitions;
|
|||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.Locale;
|
||||
|
||||
import io.github.sspanak.tt9.languages.Characters;
|
||||
|
|
|
|||
|
|
@ -232,7 +232,6 @@ public class SettingsStore {
|
|||
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; }
|
||||
|
|
|
|||
|
|
@ -52,7 +52,7 @@ public class ItemSelectLanguage {
|
|||
}
|
||||
|
||||
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");
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue