big code cleanup and code style fixes of the entire project
This commit is contained in:
parent
4e5416f6b4
commit
eb67ab18ea
23 changed files with 31 additions and 77 deletions
|
|
@ -3,7 +3,7 @@ package io.github.sspanak.tt9;
|
|||
import android.util.Log;
|
||||
|
||||
public class Logger {
|
||||
public static int LEVEL = BuildConfig.DEBUG ? Log.DEBUG : Log.ERROR;
|
||||
public static final int LEVEL = BuildConfig.DEBUG ? Log.DEBUG : Log.ERROR;
|
||||
|
||||
static public void v(String tag, String msg) {
|
||||
if (LEVEL <= Log.VERBOSE) {
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ package io.github.sspanak.tt9.db.migrations;
|
|||
|
||||
import android.content.Context;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.room.migration.Migration;
|
||||
import androidx.sqlite.db.SupportSQLiteDatabase;
|
||||
|
||||
|
|
@ -74,7 +75,7 @@ public class DB7 {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void migrate(SupportSQLiteDatabase database) {
|
||||
public void migrate(@NonNull SupportSQLiteDatabase database) {
|
||||
migrateSQL(database);
|
||||
migrateSettings();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -114,12 +114,6 @@ abstract class KeyPadHandler extends InputMethodService {
|
|||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onDestroy() {
|
||||
super.onDestroy();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 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
|
||||
|
|
@ -283,7 +277,6 @@ abstract class KeyPadHandler extends InputMethodService {
|
|||
// toggle handlers
|
||||
abstract protected boolean shouldTrackUpDown();
|
||||
abstract protected boolean shouldTrackLeftRight();
|
||||
abstract protected boolean shouldTrackNumPress();
|
||||
|
||||
// default hardware key handlers
|
||||
abstract public boolean onBackspace();
|
||||
|
|
|
|||
|
|
@ -383,11 +383,6 @@ public class TraditionalT9 extends KeyPadHandler {
|
|||
}
|
||||
|
||||
|
||||
protected boolean shouldTrackNumPress() {
|
||||
return mInputMode.shouldTrackNumPress();
|
||||
}
|
||||
|
||||
|
||||
protected boolean shouldTrackUpDown() {
|
||||
return mEditing != EDITING_STRICT_NUMERIC && !isSuggestionViewHidden() && mInputMode.shouldTrackUpDown();
|
||||
}
|
||||
|
|
@ -641,7 +636,6 @@ public class TraditionalT9 extends KeyPadHandler {
|
|||
|
||||
private void determineNextTextCase() {
|
||||
mInputMode.determineNextWordTextCase(
|
||||
settings,
|
||||
textField.isThereText(),
|
||||
textField.getTextBeforeCursor()
|
||||
);
|
||||
|
|
|
|||
|
|
@ -25,7 +25,7 @@ public class InputType {
|
|||
* Special or limited input type means the input connection is not rich,
|
||||
* or it can not process or show things like candidate text, nor retrieve the current text.
|
||||
*
|
||||
* https://developer.android.com/reference/android/text/InputType#TYPE_NULL
|
||||
* <a href="https://developer.android.com/reference/android/text/InputType#TYPE_NULL">...</a>
|
||||
*/
|
||||
public boolean isLimited() {
|
||||
return field != null && field.inputType == android.text.InputType.TYPE_NULL;
|
||||
|
|
|
|||
|
|
@ -22,14 +22,14 @@ abstract public class InputMode {
|
|||
public static final int CASE_CAPITALIZE = 1;
|
||||
public static final int CASE_LOWER = 2;
|
||||
public static final int CASE_DICTIONARY = 3; // do not force it, but use the dictionary word as-is
|
||||
protected ArrayList<Integer> allowedTextCases = new ArrayList<>();
|
||||
protected final ArrayList<Integer> allowedTextCases = new ArrayList<>();
|
||||
protected int textCase = CASE_LOWER;
|
||||
protected int textFieldTextCase = CASE_UNDEFINED;
|
||||
|
||||
// data
|
||||
protected int autoAcceptTimeout = -1;
|
||||
protected Language language;
|
||||
protected ArrayList<String> suggestions = new ArrayList<>();
|
||||
protected final ArrayList<String> suggestions = new ArrayList<>();
|
||||
protected int keyCode = 0;
|
||||
|
||||
|
||||
|
|
@ -87,7 +87,7 @@ abstract public class InputMode {
|
|||
public boolean shouldAddAutoSpace(InputType inputType, TextField textField, boolean isWordAcceptedManually, int incomingKey, boolean hold, boolean repeat) { return false; }
|
||||
public boolean shouldDeletePrecedingSpace(InputType inputType) { return false; }
|
||||
public boolean shouldSelectNextSuggestion() { return false; }
|
||||
public boolean shouldTrackNumPress() { return true; }
|
||||
|
||||
public boolean shouldTrackUpDown() { return false; }
|
||||
public boolean shouldTrackLeftRight() { return false; }
|
||||
|
||||
|
|
@ -122,7 +122,7 @@ abstract public class InputMode {
|
|||
textCase = allowedTextCases.get(nextIndex);
|
||||
}
|
||||
|
||||
public void determineNextWordTextCase(SettingsStore settings, boolean isThereText, String textBeforeCursor) {}
|
||||
public void determineNextWordTextCase(boolean isThereText, 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; }
|
||||
|
|
|
|||
|
|
@ -28,7 +28,6 @@ public class Mode123 extends InputMode {
|
|||
|
||||
@Override final public boolean is123() { return true; }
|
||||
@Override public int getSequenceLength() { return 0; }
|
||||
@Override public boolean shouldTrackNumPress() { return false; }
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -257,7 +257,7 @@ public class ModePredictive extends InputMode {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void determineNextWordTextCase(SettingsStore settings, boolean isThereText, String textBeforeCursor) {
|
||||
public void determineNextWordTextCase(boolean isThereText, String textBeforeCursor) {
|
||||
textCase = autoTextCase.determineNextWordTextCase(isThereText, textCase, textFieldTextCase, textBeforeCursor);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -73,9 +73,8 @@ public class Predictions {
|
|||
return this;
|
||||
}
|
||||
|
||||
public Predictions setWordsChangedHandler(Handler handler) {
|
||||
public void setWordsChangedHandler(Handler handler) {
|
||||
wordsChangedHandler = handler;
|
||||
return this;
|
||||
}
|
||||
|
||||
public ArrayList<String> getList() {
|
||||
|
|
|
|||
|
|
@ -8,8 +8,5 @@ public class InvalidLanguageCharactersException extends Exception {
|
|||
this.language = language;
|
||||
}
|
||||
|
||||
public Language getLanguage() {
|
||||
return language;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -19,9 +19,9 @@ public class Spanish extends English {
|
|||
characterMap.set(1, new ArrayList<>(Characters.Sentence));
|
||||
characterMap.get(1).addAll(Arrays.asList("¡", "¿"));
|
||||
|
||||
characterMap.get(2).addAll(Collections.singletonList("á"));
|
||||
characterMap.get(3).addAll(Collections.singletonList("é"));
|
||||
characterMap.get(4).addAll(Collections.singletonList("í"));
|
||||
characterMap.get(2).add("á");
|
||||
characterMap.get(3).add("é");
|
||||
characterMap.get(4).add("í");
|
||||
characterMap.set(6, new ArrayList<>(Arrays.asList("m", "n", "ñ", "o", "ó")));
|
||||
characterMap.get(8).addAll(Arrays.asList("ú", "ü"));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -198,11 +198,8 @@ public class SettingsStore {
|
|||
return getFunctionKey(SectionKeymap.ITEM_SHOW_SETTINGS);
|
||||
}
|
||||
|
||||
|
||||
/************* UI settings *************/
|
||||
|
||||
public boolean getNotifyNextLanguageInModeAbc() { return prefs.getBoolean("notify_next_language_in_mode_abc", true); }
|
||||
|
||||
public boolean getDarkTheme() { return prefs.getBoolean("pref_dark_theme", true); }
|
||||
|
||||
public boolean getShowSoftKeys() { return prefs.getBoolean("pref_show_soft_keys", true); }
|
||||
|
|
|
|||
|
|
@ -28,7 +28,7 @@ abstract class ItemClickable {
|
|||
*
|
||||
* My smashed Qin F21 Pro+ occasionally does this, if I press the keys hard.
|
||||
* There were reports the same happens on Kyocera KYF31, causing absolutely undesirable side effects.
|
||||
* @see: https://github.com/sspanak/tt9/issues/117
|
||||
* @see: <a href="https://github.com/sspanak/tt9/issues/117">...</a>
|
||||
*/
|
||||
protected boolean debounceClick(Preference p) {
|
||||
long now = System.currentTimeMillis();
|
||||
|
|
|
|||
|
|
@ -46,9 +46,9 @@ public class ItemSelectLanguage {
|
|||
}
|
||||
|
||||
|
||||
public ItemSelectLanguage enableValidation() {
|
||||
public void enableValidation() {
|
||||
if (item == null) {
|
||||
return this;
|
||||
return;
|
||||
}
|
||||
|
||||
item.setOnPreferenceChangeListener((preference, newValue) -> {
|
||||
|
|
@ -65,7 +65,6 @@ public class ItemSelectLanguage {
|
|||
return false;
|
||||
});
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -41,10 +41,10 @@ public class ItemSelectZeroKeyCharacter {
|
|||
}
|
||||
|
||||
|
||||
public ItemSelectZeroKeyCharacter activate() {
|
||||
public void activate() {
|
||||
if (item == null) {
|
||||
Logger.w("tt9/ItemSelectZeroKeyChar.activate", "Cannot set a click listener a NULL item. Ignoring.");
|
||||
return this;
|
||||
return;
|
||||
}
|
||||
|
||||
item.setOnPreferenceChangeListener((preference, newChar) -> {
|
||||
|
|
@ -53,7 +53,6 @@ public class ItemSelectZeroKeyCharacter {
|
|||
return true;
|
||||
});
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -46,12 +46,11 @@ public class SectionKeymap {
|
|||
}
|
||||
|
||||
|
||||
public SectionKeymap activate() {
|
||||
public void activate() {
|
||||
for (DropDownPreference item : items) {
|
||||
onItemClick(item);
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -40,14 +40,13 @@ public class AddWordAct extends AppCompatActivity {
|
|||
word = i.getStringExtra("io.github.sspanak.tt9.word");
|
||||
lang = i.getIntExtra("io.github.sspanak.tt9.lang", -1);
|
||||
|
||||
View v = View.inflate(this, R.layout.addwordview, null);
|
||||
main = View.inflate(this, R.layout.addwordview, null);
|
||||
|
||||
EditText et = v.findViewById(R.id.add_word_text);
|
||||
EditText et = main.findViewById(R.id.add_word_text);
|
||||
et.setOnClickListener(this::addWord);
|
||||
et.setText(word);
|
||||
et.setSelection(word.length());
|
||||
setContentView(v);
|
||||
main = v;
|
||||
setContentView(main);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -170,14 +170,11 @@ public class DictionaryLoadingBar {
|
|||
if (lang == null || errorType.equals(InvalidLanguageException.class.getSimpleName())) {
|
||||
message = resources.getString(R.string.add_word_invalid_language);
|
||||
} else if (errorType.equals(DictionaryImportException.class.getSimpleName()) || errorType.equals(InvalidLanguageCharactersException.class.getSimpleName())) {
|
||||
String languageName = lang.getName();
|
||||
message = resources.getString(R.string.dictionary_load_bad_char, word, line, languageName);
|
||||
message = resources.getString(R.string.dictionary_load_bad_char, word, line, lang.getName());
|
||||
} else if (errorType.equals(IOException.class.getSimpleName()) || errorType.equals(FileNotFoundException.class.getSimpleName())) {
|
||||
String languageName = lang.getName();
|
||||
message = resources.getString(R.string.dictionary_not_found, languageName);
|
||||
message = resources.getString(R.string.dictionary_not_found, lang.getName());
|
||||
} else {
|
||||
String languageName = lang.getName();
|
||||
message = resources.getString(R.string.dictionary_load_error, languageName, errorType);
|
||||
message = resources.getString(R.string.dictionary_load_error, lang.getName(), errorType);
|
||||
}
|
||||
|
||||
title = generateTitle(-1);
|
||||
|
|
|
|||
|
|
@ -4,13 +4,8 @@ import android.content.Context;
|
|||
import android.content.Intent;
|
||||
import android.widget.Toast;
|
||||
|
||||
import io.github.sspanak.tt9.Logger;
|
||||
import io.github.sspanak.tt9.R;
|
||||
import io.github.sspanak.tt9.ime.TraditionalT9;
|
||||
import io.github.sspanak.tt9.ime.modes.InputMode;
|
||||
import io.github.sspanak.tt9.languages.Language;
|
||||
import io.github.sspanak.tt9.preferences.PreferencesActivity;
|
||||
import io.github.sspanak.tt9.preferences.SettingsStore;
|
||||
|
||||
public class UI {
|
||||
public static void showAddWordDialog(TraditionalT9 tt9, int language, String currentWord) {
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ import io.github.sspanak.tt9.ime.TraditionalT9;
|
|||
import io.github.sspanak.tt9.ui.main.keys.SoftKey;
|
||||
|
||||
abstract class BaseMainLayout {
|
||||
protected TraditionalT9 tt9;
|
||||
protected final TraditionalT9 tt9;
|
||||
private final int xml;
|
||||
|
||||
protected View view = null;
|
||||
|
|
@ -56,18 +56,6 @@ abstract class BaseMainLayout {
|
|||
return view;
|
||||
}
|
||||
|
||||
public void show() {
|
||||
if (view != null) {
|
||||
view.setVisibility(View.VISIBLE);
|
||||
}
|
||||
}
|
||||
|
||||
public void hide() {
|
||||
if (view != null) {
|
||||
view.setVisibility(View.GONE);
|
||||
}
|
||||
}
|
||||
|
||||
public void enableClickHandlers() {
|
||||
for (SoftKey key : getKeys()) {
|
||||
key.setTT9(tt9);
|
||||
|
|
|
|||
|
|
@ -19,17 +19,16 @@ public class StatusBar {
|
|||
}
|
||||
|
||||
|
||||
public StatusBar setText(String text) {
|
||||
public void setText(String text) {
|
||||
statusText = "[ " + text + " ]";
|
||||
this.render();
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public StatusBar setDarkTheme(boolean darkTheme) {
|
||||
public void setDarkTheme(boolean darkTheme) {
|
||||
if (statusView == null) {
|
||||
Logger.w("StatusBar.setDarkTheme", "Not changing the theme of a NULL View.");
|
||||
return this;
|
||||
return;
|
||||
}
|
||||
|
||||
Context context = statusView.getContext();
|
||||
|
|
@ -47,7 +46,6 @@ public class StatusBar {
|
|||
statusView.setTextColor(color);
|
||||
this.render();
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
private void render() {
|
||||
|
|
|
|||
|
|
@ -71,7 +71,7 @@ public class SuggestionsAdapter extends RecyclerView.Adapter<SuggestionsAdapter.
|
|||
|
||||
|
||||
public class ViewHolder extends RecyclerView.ViewHolder {
|
||||
TextView suggestionItem;
|
||||
final TextView suggestionItem;
|
||||
|
||||
ViewHolder(View itemView) {
|
||||
super(itemView);
|
||||
|
|
|
|||
|
|
@ -161,7 +161,7 @@ public class SuggestionsBar {
|
|||
* system context and theme.
|
||||
*
|
||||
* More info:
|
||||
* https://stackoverflow.com/questions/72382886/system-applies-night-mode-to-views-added-in-service-type-application-overlay
|
||||
* <a href="https://stackoverflow.com/questions/72382886/system-applies-night-mode-to-views-added-in-service-type-application-overlay">...</a>
|
||||
*/
|
||||
public void setDarkTheme(boolean darkEnabled) {
|
||||
isDarkThemeEnabled = darkEnabled;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue