Status bar (#230)
* input mode is now displayed in a StatusBar * status icons are no more >:) * updated docs * removed the EDITING_NOSHOW mode, because it became obsolete and it was preventing the StatusBar from appearing in some ABC-only fields
This commit is contained in:
parent
37abc2bbc4
commit
baca3c1d8f
128 changed files with 265 additions and 561 deletions
|
|
@ -18,7 +18,6 @@ abstract class KeyPadHandler extends InputMethodService {
|
|||
// editing mode
|
||||
protected static final int NON_EDIT = 0;
|
||||
protected static final int EDITING = 1;
|
||||
protected static final int EDITING_NOSHOW = 2;
|
||||
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;
|
||||
|
|
@ -51,7 +50,7 @@ abstract class KeyPadHandler extends InputMethodService {
|
|||
@Override
|
||||
public boolean onEvaluateInputViewShown() {
|
||||
super.onEvaluateInputViewShown();
|
||||
return mEditing != EDITING_NOSHOW;
|
||||
return mEditing != EDITING_DIALER && mEditing != NON_EDIT;
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -96,7 +95,7 @@ abstract class KeyPadHandler extends InputMethodService {
|
|||
@Override
|
||||
public void onFinishInputView(boolean finishingInput) {
|
||||
super.onFinishInputView(finishingInput);
|
||||
if (mEditing == EDITING || mEditing == EDITING_NOSHOW) {
|
||||
if (mEditing == EDITING || mEditing == EDITING_STRICT_NUMERIC) {
|
||||
onFinishTyping();
|
||||
}
|
||||
}
|
||||
|
|
@ -109,7 +108,7 @@ abstract class KeyPadHandler extends InputMethodService {
|
|||
public void onFinishInput() {
|
||||
super.onFinishInput();
|
||||
// Logger.d("onFinishInput", "When is this called?");
|
||||
if (mEditing == EDITING || mEditing == EDITING_NOSHOW) {
|
||||
if (mEditing == EDITING || mEditing == EDITING_STRICT_NUMERIC) {
|
||||
onStop();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -21,7 +21,8 @@ import io.github.sspanak.tt9.ime.helpers.TextField;
|
|||
import io.github.sspanak.tt9.ime.modes.InputMode;
|
||||
import io.github.sspanak.tt9.languages.Language;
|
||||
import io.github.sspanak.tt9.languages.LanguageCollection;
|
||||
import io.github.sspanak.tt9.ui.SuggestionsView;
|
||||
import io.github.sspanak.tt9.ui.bottom.StatusBar;
|
||||
import io.github.sspanak.tt9.ui.bottom.SuggestionsBar;
|
||||
import io.github.sspanak.tt9.ui.UI;
|
||||
|
||||
public class TraditionalT9 extends KeyPadHandler {
|
||||
|
|
@ -40,7 +41,8 @@ public class TraditionalT9 extends KeyPadHandler {
|
|||
|
||||
// soft key view
|
||||
private SoftKeyHandler softKeyHandler = null;
|
||||
private SuggestionsView mSuggestionView = null;
|
||||
private StatusBar statusBar = null;
|
||||
private SuggestionsBar suggestionBar = null;
|
||||
|
||||
|
||||
private static TraditionalT9 self;
|
||||
|
|
@ -82,8 +84,12 @@ public class TraditionalT9 extends KeyPadHandler {
|
|||
softKeyHandler = new SoftKeyHandler(this);
|
||||
}
|
||||
|
||||
if (mSuggestionView == null) {
|
||||
mSuggestionView = new SuggestionsView(settings, softKeyHandler.getView());
|
||||
if (statusBar == null) {
|
||||
statusBar = new StatusBar(softKeyHandler.getView());
|
||||
}
|
||||
|
||||
if (suggestionBar == null) {
|
||||
suggestionBar = new SuggestionsBar(settings, softKeyHandler.getView());
|
||||
}
|
||||
|
||||
loadSettings();
|
||||
|
|
@ -110,10 +116,12 @@ public class TraditionalT9 extends KeyPadHandler {
|
|||
|
||||
|
||||
private void initUi() {
|
||||
UI.updateStatusIcon(this, mLanguage, mInputMode);
|
||||
statusBar
|
||||
.setText(mInputMode != null ? mInputMode.toString() : "")
|
||||
.setDarkTheme(settings.getDarkTheme());
|
||||
|
||||
clearSuggestions();
|
||||
mSuggestionView.setDarkTheme(settings.getDarkTheme());
|
||||
suggestionBar.setDarkTheme(settings.getDarkTheme());
|
||||
|
||||
softKeyHandler.setDarkTheme(settings.getDarkTheme());
|
||||
softKeyHandler.setSoftKeysVisibility(settings.getShowSoftKeys());
|
||||
|
|
@ -148,8 +156,6 @@ public class TraditionalT9 extends KeyPadHandler {
|
|||
|
||||
protected void onFinishTyping() {
|
||||
isActive = false;
|
||||
|
||||
hideStatusIcon();
|
||||
mEditing = NON_EDIT;
|
||||
}
|
||||
|
||||
|
|
@ -191,7 +197,7 @@ public class TraditionalT9 extends KeyPadHandler {
|
|||
return performOKAction();
|
||||
}
|
||||
|
||||
String word = mSuggestionView.getCurrentSuggestion();
|
||||
String word = suggestionBar.getCurrentSuggestion();
|
||||
|
||||
mInputMode.onAcceptSuggestion(word);
|
||||
commitCurrentSuggestion();
|
||||
|
|
@ -204,8 +210,8 @@ public class TraditionalT9 extends KeyPadHandler {
|
|||
|
||||
protected boolean onUp() {
|
||||
if (previousSuggestion()) {
|
||||
mInputMode.setWordStem(mSuggestionView.getCurrentSuggestion(), true);
|
||||
textField.setComposingTextWithHighlightedStem(mSuggestionView.getCurrentSuggestion(), mInputMode);
|
||||
mInputMode.setWordStem(suggestionBar.getCurrentSuggestion(), true);
|
||||
textField.setComposingTextWithHighlightedStem(suggestionBar.getCurrentSuggestion(), mInputMode);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
@ -215,8 +221,8 @@ public class TraditionalT9 extends KeyPadHandler {
|
|||
|
||||
protected boolean onDown() {
|
||||
if (nextSuggestion()) {
|
||||
mInputMode.setWordStem(mSuggestionView.getCurrentSuggestion(), true);
|
||||
textField.setComposingTextWithHighlightedStem(mSuggestionView.getCurrentSuggestion(), mInputMode);
|
||||
mInputMode.setWordStem(suggestionBar.getCurrentSuggestion(), true);
|
||||
textField.setComposingTextWithHighlightedStem(suggestionBar.getCurrentSuggestion(), mInputMode);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
@ -237,8 +243,8 @@ public class TraditionalT9 extends KeyPadHandler {
|
|||
|
||||
protected boolean onRight(boolean repeat) {
|
||||
String filter;
|
||||
if (repeat && !mSuggestionView.getSuggestion(1).equals("")) {
|
||||
filter = mSuggestionView.getSuggestion(1);
|
||||
if (repeat && !suggestionBar.getSuggestion(1).equals("")) {
|
||||
filter = suggestionBar.getSuggestion(1);
|
||||
} else {
|
||||
filter = getComposingText();
|
||||
}
|
||||
|
|
@ -319,7 +325,7 @@ public class TraditionalT9 extends KeyPadHandler {
|
|||
|
||||
|
||||
protected boolean onKeyAddWord() {
|
||||
if (mEditing == EDITING_NOSHOW || mEditing == EDITING_DIALER) {
|
||||
if (mEditing == EDITING_STRICT_NUMERIC || mEditing == EDITING_DIALER) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
@ -335,6 +341,7 @@ public class TraditionalT9 extends KeyPadHandler {
|
|||
mInputMode.reset();
|
||||
resetKeyRepeat();
|
||||
clearSuggestions();
|
||||
statusBar.setText(mInputMode.toString());
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
@ -350,7 +357,7 @@ public class TraditionalT9 extends KeyPadHandler {
|
|||
|
||||
|
||||
protected boolean onKeyShowSettings() {
|
||||
if (mEditing == EDITING_NOSHOW || mEditing == EDITING_DIALER) {
|
||||
if (mEditing == EDITING_DIALER) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
@ -365,16 +372,16 @@ public class TraditionalT9 extends KeyPadHandler {
|
|||
|
||||
|
||||
protected boolean shouldTrackUpDown() {
|
||||
return mEditing != EDITING_NOSHOW && !isSuggestionViewHidden() && mInputMode.shouldTrackUpDown();
|
||||
return mEditing != EDITING_STRICT_NUMERIC && !isSuggestionViewHidden() && mInputMode.shouldTrackUpDown();
|
||||
}
|
||||
|
||||
protected boolean shouldTrackLeftRight() {
|
||||
return mEditing != EDITING_NOSHOW && !isSuggestionViewHidden() && mInputMode.shouldTrackLeftRight();
|
||||
return mEditing != EDITING_STRICT_NUMERIC && !isSuggestionViewHidden() && mInputMode.shouldTrackLeftRight();
|
||||
}
|
||||
|
||||
|
||||
private boolean isSuggestionViewHidden() {
|
||||
return mSuggestionView == null || !mSuggestionView.hasElements();
|
||||
return suggestionBar == null || !suggestionBar.hasElements();
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -383,8 +390,8 @@ public class TraditionalT9 extends KeyPadHandler {
|
|||
return false;
|
||||
}
|
||||
|
||||
mSuggestionView.scrollToSuggestion(-1);
|
||||
textField.setComposingTextWithHighlightedStem(mSuggestionView.getCurrentSuggestion(), mInputMode);
|
||||
suggestionBar.scrollToSuggestion(-1);
|
||||
textField.setComposingTextWithHighlightedStem(suggestionBar.getCurrentSuggestion(), mInputMode);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
@ -395,8 +402,8 @@ public class TraditionalT9 extends KeyPadHandler {
|
|||
return false;
|
||||
}
|
||||
|
||||
mSuggestionView.scrollToSuggestion(1);
|
||||
textField.setComposingTextWithHighlightedStem(mSuggestionView.getCurrentSuggestion(), mInputMode);
|
||||
suggestionBar.scrollToSuggestion(1);
|
||||
textField.setComposingTextWithHighlightedStem(suggestionBar.getCurrentSuggestion(), mInputMode);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
@ -409,7 +416,7 @@ public class TraditionalT9 extends KeyPadHandler {
|
|||
private void commitCurrentSuggestion(boolean entireSuggestion) {
|
||||
if (!isSuggestionViewHidden() && currentInputConnection != null) {
|
||||
if (entireSuggestion) {
|
||||
textField.setComposingText(mSuggestionView.getCurrentSuggestion());
|
||||
textField.setComposingText(suggestionBar.getCurrentSuggestion());
|
||||
}
|
||||
currentInputConnection.finishComposingText();
|
||||
}
|
||||
|
|
@ -429,7 +436,7 @@ public class TraditionalT9 extends KeyPadHandler {
|
|||
|
||||
|
||||
private void getSuggestions() {
|
||||
if (!mInputMode.loadSuggestions(handleSuggestionsAsync, mSuggestionView.getCurrentSuggestion())) {
|
||||
if (!mInputMode.loadSuggestions(handleSuggestionsAsync, suggestionBar.getCurrentSuggestion())) {
|
||||
handleSuggestions();
|
||||
}
|
||||
}
|
||||
|
|
@ -441,7 +448,7 @@ public class TraditionalT9 extends KeyPadHandler {
|
|||
// Put the first suggestion in the text field,
|
||||
// but cut it off to the length of the sequence (how many keys were pressed),
|
||||
// for a more intuitive experience.
|
||||
String word = mSuggestionView.getCurrentSuggestion();
|
||||
String word = suggestionBar.getCurrentSuggestion();
|
||||
word = word.substring(0, Math.min(mInputMode.getSequenceLength(), word.length()));
|
||||
textField.setComposingTextWithHighlightedStem(word, mInputMode);
|
||||
}
|
||||
|
|
@ -460,19 +467,19 @@ public class TraditionalT9 extends KeyPadHandler {
|
|||
}
|
||||
|
||||
private void setSuggestions(List<String> suggestions, int selectedIndex) {
|
||||
if (mSuggestionView == null) {
|
||||
if (suggestionBar == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
boolean show = suggestions != null && suggestions.size() > 0;
|
||||
|
||||
mSuggestionView.setSuggestions(suggestions, selectedIndex);
|
||||
suggestionBar.setSuggestions(suggestions, selectedIndex);
|
||||
setCandidatesViewShown(show);
|
||||
}
|
||||
|
||||
|
||||
private String getComposingText() {
|
||||
String text = mSuggestionView.getCurrentSuggestion();
|
||||
String text = suggestionBar.getCurrentSuggestion();
|
||||
if (text.length() > 0 && text.length() > mInputMode.getSequenceLength()) {
|
||||
text = text.substring(0, mInputMode.getSequenceLength());
|
||||
}
|
||||
|
|
@ -499,7 +506,7 @@ public class TraditionalT9 extends KeyPadHandler {
|
|||
// This is why we retry, until there is a visual change.
|
||||
for (int retries = 0; retries < 2 && mLanguage.hasUpperCase(); retries++) {
|
||||
mInputMode.nextTextCase();
|
||||
setSuggestions(mInputMode.getSuggestions(), mSuggestionView.getCurrentIndex());
|
||||
setSuggestions(mInputMode.getSuggestions(), suggestionBar.getCurrentIndex());
|
||||
refreshComposingText();
|
||||
|
||||
if (!currentSuggestionBefore.equals(getComposingText())) {
|
||||
|
|
@ -521,7 +528,7 @@ public class TraditionalT9 extends KeyPadHandler {
|
|||
settings.saveInputMode(mInputMode.getId());
|
||||
settings.saveTextCase(mInputMode.getTextCase());
|
||||
|
||||
UI.updateStatusIcon(this, mLanguage, mInputMode);
|
||||
statusBar.setText(mInputMode.toString());
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -545,9 +552,6 @@ public class TraditionalT9 extends KeyPadHandler {
|
|||
// save it for the next time
|
||||
settings.saveInputLanguage(mLanguage.getId());
|
||||
|
||||
UI.updateStatusIcon(this, mLanguage, mInputMode);
|
||||
UI.toastInputMode(this, settings, mLanguage, mInputMode);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
@ -580,7 +584,7 @@ public class TraditionalT9 extends KeyPadHandler {
|
|||
} else if (mInputMode.is123() && allowedInputModes.size() == 1) {
|
||||
mEditing = EDITING_STRICT_NUMERIC;
|
||||
} else {
|
||||
mEditing = inputType.isFilter() ? EDITING_NOSHOW : EDITING;
|
||||
mEditing = EDITING;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -64,10 +64,6 @@ public class InputType {
|
|||
}
|
||||
|
||||
|
||||
/**
|
||||
* isFilter
|
||||
* handle filter list cases... do not hijack DPAD center and make sure back's go through proper
|
||||
*/
|
||||
public boolean isFilter() {
|
||||
if (field == null) {
|
||||
return false;
|
||||
|
|
|
|||
|
|
@ -1,5 +1,7 @@
|
|||
package io.github.sspanak.tt9.ime.modes;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class Mode123 extends InputMode {
|
||||
|
|
@ -24,4 +26,10 @@ public class Mode123 extends InputMode {
|
|||
final public boolean is123() { return true; }
|
||||
public int getSequenceLength() { return 0; }
|
||||
public boolean shouldTrackNumPress() { return false; }
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public String toString() {
|
||||
return "123";
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,7 @@
|
|||
package io.github.sspanak.tt9.ime.modes;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import io.github.sspanak.tt9.languages.Language;
|
||||
|
|
@ -56,4 +58,19 @@ public class ModeABC extends InputMode {
|
|||
@Override public boolean shouldSelectNextSuggestion() {
|
||||
return shouldSelectNextLetter;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public String toString() {
|
||||
if (language == null) {
|
||||
return textCase == CASE_LOWER ? "abc" : "ABC";
|
||||
}
|
||||
|
||||
String langCode = language.getLocale().getCountry();
|
||||
langCode = langCode.length() == 0 ? language.getLocale().getLanguage() : langCode;
|
||||
|
||||
String modeString = language.getAbcString() + " / " + langCode.toUpperCase();
|
||||
|
||||
return (textCase == CASE_LOWER) ? modeString.toLowerCase(language.getLocale()) : modeString.toUpperCase(language.getLocale());
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,6 +4,8 @@ import android.os.Handler;
|
|||
import android.os.Looper;
|
||||
import android.os.Message;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import io.github.sspanak.tt9.Logger;
|
||||
import io.github.sspanak.tt9.db.DictionaryDb;
|
||||
import io.github.sspanak.tt9.ime.helpers.InputType;
|
||||
|
|
@ -331,4 +333,21 @@ public class ModePredictive extends InputMode {
|
|||
|
||||
@Override final public boolean isPredictive() { return true; }
|
||||
@Override public int getSequenceLength() { return digitSequence.length(); }
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public String toString() {
|
||||
if (language == null) {
|
||||
return "Predictive";
|
||||
}
|
||||
|
||||
String modeString = language.getName();
|
||||
if (textCase == CASE_UPPER) {
|
||||
return modeString.toUpperCase(language.getLocale());
|
||||
} else if (textCase == CASE_LOWER && !settings.getAutoTextCase()) {
|
||||
return modeString.toLowerCase(language.getLocale());
|
||||
} else {
|
||||
return modeString;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -11,14 +11,13 @@ public class Language {
|
|||
private int id;
|
||||
protected String name;
|
||||
protected Locale locale;
|
||||
protected int icon;
|
||||
protected String dictionaryFile;
|
||||
protected int abcLowerCaseIcon;
|
||||
protected int abcUpperCaseIcon;
|
||||
protected String abcString;
|
||||
protected ArrayList<ArrayList<String>> characterMap = new ArrayList<>();
|
||||
private final HashMap<Character, String> reverseCharacterMap = new HashMap<>();
|
||||
|
||||
// settings
|
||||
protected boolean hasUpperCase = true;
|
||||
protected boolean isPunctuationPartOfWords; // see the getter for more info
|
||||
|
||||
final public int getId() {
|
||||
|
|
@ -34,19 +33,31 @@ public class Language {
|
|||
}
|
||||
|
||||
final public String getName() {
|
||||
return name;
|
||||
}
|
||||
if (name == null) {
|
||||
name = locale != null ? capitalize(locale.getDisplayLanguage(locale)) : "";
|
||||
}
|
||||
|
||||
final public int getIcon() {
|
||||
return icon;
|
||||
return name;
|
||||
}
|
||||
|
||||
final public String getDictionaryFile() {
|
||||
return dictionaryFile;
|
||||
}
|
||||
|
||||
final public int getAbcIcon(boolean lowerCase) {
|
||||
return lowerCase ? abcLowerCaseIcon : abcUpperCaseIcon;
|
||||
final public String getAbcString() {
|
||||
if (abcString == null) {
|
||||
ArrayList<String> lettersList = getKeyCharacters(2, false);
|
||||
|
||||
abcString = "";
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (int i = 0; i < lettersList.size() && i < 3; i++) {
|
||||
sb.append(lettersList.get(i));
|
||||
}
|
||||
|
||||
abcString = sb.toString();
|
||||
}
|
||||
|
||||
return abcString;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -68,8 +79,8 @@ public class Language {
|
|||
final public boolean isPunctuationPartOfWords() { return isPunctuationPartOfWords; }
|
||||
|
||||
|
||||
final public boolean hasUpperCase() {
|
||||
return abcUpperCaseIcon != 0;
|
||||
public boolean hasUpperCase() {
|
||||
return hasUpperCase;
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -164,6 +175,6 @@ public class Language {
|
|||
@NonNull
|
||||
@Override
|
||||
public String toString() {
|
||||
return name != null ? name : "";
|
||||
return getName();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,8 +3,6 @@ package io.github.sspanak.tt9.languages.definitions;
|
|||
import java.util.Arrays;
|
||||
import java.util.Locale;
|
||||
|
||||
import io.github.sspanak.tt9.R;
|
||||
|
||||
public class BrazilianPortuguese extends English {
|
||||
public BrazilianPortuguese() {
|
||||
super();
|
||||
|
|
@ -12,7 +10,6 @@ public class BrazilianPortuguese extends English {
|
|||
name = "Português brasileiro";
|
||||
locale = new Locale("pt","BR");
|
||||
dictionaryFile = "pt-BR-utf8.csv";
|
||||
icon = R.drawable.ime_lang_br;
|
||||
|
||||
isPunctuationPartOfWords = true;
|
||||
|
||||
|
|
|
|||
|
|
@ -4,18 +4,13 @@ import java.util.ArrayList;
|
|||
import java.util.Arrays;
|
||||
import java.util.Locale;
|
||||
|
||||
import io.github.sspanak.tt9.R;
|
||||
import io.github.sspanak.tt9.languages.Language;
|
||||
import io.github.sspanak.tt9.languages.Characters;
|
||||
|
||||
public class Bulgarian extends Language {
|
||||
public Bulgarian() {
|
||||
name = "Български";
|
||||
locale = new Locale("bg","BG");
|
||||
dictionaryFile = "bg-utf8.csv";
|
||||
icon = R.drawable.ime_lang_bg;
|
||||
abcLowerCaseIcon = R.drawable.ime_lang_cyrillic_lower;
|
||||
abcUpperCaseIcon = R.drawable.ime_lang_cyrillic_upper;
|
||||
|
||||
isPunctuationPartOfWords = false;
|
||||
|
||||
|
|
|
|||
|
|
@ -3,16 +3,12 @@ package io.github.sspanak.tt9.languages.definitions;
|
|||
import java.util.Arrays;
|
||||
import java.util.Locale;
|
||||
|
||||
import io.github.sspanak.tt9.R;
|
||||
|
||||
public class Dutch extends English {
|
||||
public Dutch() {
|
||||
super();
|
||||
|
||||
name = "Nederlands";
|
||||
locale = new Locale("nl","NL");
|
||||
dictionaryFile = "nl-utf8.csv";
|
||||
icon = R.drawable.ime_lang_nl;
|
||||
|
||||
isPunctuationPartOfWords = true;
|
||||
|
||||
|
|
|
|||
|
|
@ -4,18 +4,13 @@ import java.util.ArrayList;
|
|||
import java.util.Arrays;
|
||||
import java.util.Locale;
|
||||
|
||||
import io.github.sspanak.tt9.R;
|
||||
import io.github.sspanak.tt9.languages.Language;
|
||||
import io.github.sspanak.tt9.languages.Characters;
|
||||
import io.github.sspanak.tt9.languages.Language;
|
||||
|
||||
public class English extends Language {
|
||||
public English() {
|
||||
name = "English";
|
||||
locale = Locale.ENGLISH;
|
||||
dictionaryFile = "en-utf8.csv";
|
||||
icon = R.drawable.ime_lang_en;
|
||||
abcLowerCaseIcon = R.drawable.ime_lang_latin_lower;
|
||||
abcUpperCaseIcon = R.drawable.ime_lang_latin_upper;
|
||||
|
||||
isPunctuationPartOfWords = true;
|
||||
|
||||
|
|
|
|||
|
|
@ -3,20 +3,16 @@ package io.github.sspanak.tt9.languages.definitions;
|
|||
import java.util.Arrays;
|
||||
import java.util.Locale;
|
||||
|
||||
import io.github.sspanak.tt9.R;
|
||||
|
||||
public class Finnish extends English {
|
||||
public Finnish() {
|
||||
super();
|
||||
|
||||
name = "Suomi";
|
||||
locale = new Locale("fi","FI");
|
||||
dictionaryFile = "fi-utf8.csv";
|
||||
icon = R.drawable.ime_lang_fi;
|
||||
|
||||
isPunctuationPartOfWords = true;
|
||||
|
||||
characterMap.get(2).addAll(Arrays.asList("ä", "å"));
|
||||
characterMap.get(6).addAll(Arrays.asList("ö"));
|
||||
characterMap.get(6).add("ö");
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,16 +3,12 @@ package io.github.sspanak.tt9.languages.definitions;
|
|||
import java.util.Arrays;
|
||||
import java.util.Locale;
|
||||
|
||||
import io.github.sspanak.tt9.R;
|
||||
|
||||
public class French extends English {
|
||||
public French() {
|
||||
super();
|
||||
|
||||
name = "Français";
|
||||
locale = Locale.FRENCH;
|
||||
dictionaryFile = "fr-utf8.csv";
|
||||
icon = R.drawable.ime_lang_fr;
|
||||
|
||||
isPunctuationPartOfWords = false;
|
||||
|
||||
|
|
|
|||
|
|
@ -2,16 +2,12 @@ package io.github.sspanak.tt9.languages.definitions;
|
|||
|
||||
import java.util.Locale;
|
||||
|
||||
import io.github.sspanak.tt9.R;
|
||||
|
||||
public class German extends English {
|
||||
public German() {
|
||||
super();
|
||||
|
||||
name = "Deutsch";
|
||||
locale = Locale.GERMAN;
|
||||
dictionaryFile = "de-utf8.csv";
|
||||
icon = R.drawable.ime_lang_de;
|
||||
|
||||
isPunctuationPartOfWords = false;
|
||||
|
||||
|
|
|
|||
|
|
@ -4,18 +4,16 @@ import java.util.ArrayList;
|
|||
import java.util.Arrays;
|
||||
import java.util.Locale;
|
||||
|
||||
import io.github.sspanak.tt9.R;
|
||||
import io.github.sspanak.tt9.languages.Language;
|
||||
import io.github.sspanak.tt9.languages.Characters;
|
||||
import io.github.sspanak.tt9.languages.Language;
|
||||
|
||||
public class Hebrew extends Language {
|
||||
public Hebrew() {
|
||||
name = "עברית";
|
||||
locale = new Locale("iw","IL");
|
||||
dictionaryFile = "he-utf8.csv";
|
||||
icon = R.drawable.ime_lang_hebrew;
|
||||
abcLowerCaseIcon = R.drawable.ime_lang_hebrew_abc;
|
||||
abcString = "אבג";
|
||||
|
||||
hasUpperCase = false;
|
||||
isPunctuationPartOfWords = true;
|
||||
|
||||
characterMap = new ArrayList<>(Arrays.asList(
|
||||
|
|
|
|||
|
|
@ -3,16 +3,12 @@ package io.github.sspanak.tt9.languages.definitions;
|
|||
import java.util.Arrays;
|
||||
import java.util.Locale;
|
||||
|
||||
import io.github.sspanak.tt9.R;
|
||||
|
||||
public class Italian extends English {
|
||||
public Italian() {
|
||||
super();
|
||||
|
||||
name = "Italiano";
|
||||
locale = Locale.ITALIAN;
|
||||
dictionaryFile = "it-utf8.csv";
|
||||
icon = R.drawable.ime_lang_it;
|
||||
|
||||
isPunctuationPartOfWords = false;
|
||||
|
||||
|
|
|
|||
|
|
@ -3,16 +3,12 @@ package io.github.sspanak.tt9.languages.definitions;
|
|||
import java.util.Arrays;
|
||||
import java.util.Locale;
|
||||
|
||||
import io.github.sspanak.tt9.R;
|
||||
|
||||
public class Norwegian extends English {
|
||||
public Norwegian() {
|
||||
super();
|
||||
|
||||
name = "Norsk bokmål";
|
||||
locale = new Locale("nb","NO");
|
||||
dictionaryFile = "nb-utf8.csv";
|
||||
icon = R.drawable.ime_lang_nb;
|
||||
|
||||
isPunctuationPartOfWords = false;
|
||||
|
||||
|
|
|
|||
|
|
@ -4,18 +4,13 @@ import java.util.ArrayList;
|
|||
import java.util.Arrays;
|
||||
import java.util.Locale;
|
||||
|
||||
import io.github.sspanak.tt9.R;
|
||||
import io.github.sspanak.tt9.languages.Language;
|
||||
import io.github.sspanak.tt9.languages.Characters;
|
||||
import io.github.sspanak.tt9.languages.Language;
|
||||
|
||||
public class Russian extends Language {
|
||||
public Russian() {
|
||||
name = "Русский";
|
||||
locale = new Locale("ru","RU");
|
||||
dictionaryFile = "ru-utf8.csv";
|
||||
icon = R.drawable.ime_lang_ru;
|
||||
abcLowerCaseIcon = R.drawable.ime_lang_cyrillic_lower;
|
||||
abcUpperCaseIcon = R.drawable.ime_lang_cyrillic_upper;
|
||||
|
||||
isPunctuationPartOfWords = false;
|
||||
|
||||
|
|
|
|||
|
|
@ -5,17 +5,14 @@ import java.util.Arrays;
|
|||
import java.util.Collections;
|
||||
import java.util.Locale;
|
||||
|
||||
import io.github.sspanak.tt9.R;
|
||||
import io.github.sspanak.tt9.languages.Characters;
|
||||
|
||||
public class Spanish extends English {
|
||||
public Spanish() {
|
||||
super();
|
||||
|
||||
name = "Español";
|
||||
locale = new Locale("es", "ES");
|
||||
dictionaryFile = "es-utf8.csv";
|
||||
icon = R.drawable.ime_lang_es;
|
||||
|
||||
isPunctuationPartOfWords = false;
|
||||
|
||||
|
|
|
|||
|
|
@ -3,21 +3,17 @@ package io.github.sspanak.tt9.languages.definitions;
|
|||
import java.util.Arrays;
|
||||
import java.util.Locale;
|
||||
|
||||
import io.github.sspanak.tt9.R;
|
||||
|
||||
public class Swedish extends English {
|
||||
public Swedish() {
|
||||
super();
|
||||
|
||||
name = "Svenska";
|
||||
locale = new Locale("sv","SE");
|
||||
dictionaryFile = "sv-utf8.csv";
|
||||
icon = R.drawable.ime_lang_sv;
|
||||
|
||||
isPunctuationPartOfWords = false;
|
||||
|
||||
characterMap.get(2).addAll(Arrays.asList("å", "ä"));
|
||||
characterMap.get(3).addAll(Arrays.asList("é"));
|
||||
characterMap.get(6).addAll(Arrays.asList("ö"));
|
||||
characterMap.get(3).add("é");
|
||||
characterMap.get(6).add("ö");
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,18 +4,13 @@ import java.util.ArrayList;
|
|||
import java.util.Arrays;
|
||||
import java.util.Locale;
|
||||
|
||||
import io.github.sspanak.tt9.R;
|
||||
import io.github.sspanak.tt9.languages.Language;
|
||||
import io.github.sspanak.tt9.languages.Characters;
|
||||
import io.github.sspanak.tt9.languages.Language;
|
||||
|
||||
public class Ukrainian extends Language {
|
||||
public Ukrainian() {
|
||||
name = "Українська";
|
||||
locale = new Locale("uk","UA");
|
||||
dictionaryFile = "uk-utf8.csv";
|
||||
icon = R.drawable.ime_lang_uk;
|
||||
abcLowerCaseIcon = R.drawable.ime_lang_cyrillic_lower;
|
||||
abcUpperCaseIcon = R.drawable.ime_lang_cyrillic_upper;
|
||||
|
||||
isPunctuationPartOfWords = true;
|
||||
|
||||
|
|
|
|||
|
|
@ -31,33 +31,6 @@ public class UI {
|
|||
tt9.startActivity(prefIntent);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* updateStatusIcon
|
||||
* Set the status icon that is appropriate in current mode (based on
|
||||
* openwmm-legacy)
|
||||
*/
|
||||
public static void updateStatusIcon(TraditionalT9 tt9, Language inputLanguage, InputMode inputMode) {
|
||||
if (inputMode.isABC()) {
|
||||
tt9.showStatusIcon(inputLanguage.getAbcIcon(inputMode.getTextCase() == InputMode.CASE_LOWER));
|
||||
} else if (inputMode.isPredictive()) {
|
||||
tt9.showStatusIcon(inputLanguage.getIcon());
|
||||
} else if (inputMode.is123()) {
|
||||
tt9.showStatusIcon(R.drawable.ime_number);
|
||||
} else {
|
||||
Logger.w("tt9.UI", "Unknown inputMode mode: " + inputMode + ". Hiding status icon.");
|
||||
tt9.hideStatusIcon();
|
||||
}
|
||||
}
|
||||
|
||||
public static void toastInputMode(Context context, SettingsStore settings, Language newLanguage, InputMode mode) {
|
||||
if (mode.isABC() && settings.getNotifyNextLanguageInModeAbc()) {
|
||||
String toastMessage = newLanguage.getName();
|
||||
toastMessage += mode.getTextCase() == InputMode.CASE_LOWER ? " (abc)" : " (ABC)";
|
||||
toast(context, toastMessage);
|
||||
}
|
||||
}
|
||||
|
||||
public static void toast(Context context, CharSequence msg) {
|
||||
Toast.makeText(context, msg, Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
|
|
|
|||
60
src/io/github/sspanak/tt9/ui/bottom/StatusBar.java
Normal file
60
src/io/github/sspanak/tt9/ui/bottom/StatusBar.java
Normal file
|
|
@ -0,0 +1,60 @@
|
|||
package io.github.sspanak.tt9.ui.bottom;
|
||||
|
||||
import android.content.Context;
|
||||
import android.view.View;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.core.content.ContextCompat;
|
||||
|
||||
import io.github.sspanak.tt9.Logger;
|
||||
import io.github.sspanak.tt9.R;
|
||||
|
||||
public class StatusBar {
|
||||
private final TextView statusView;
|
||||
private String statusText;
|
||||
|
||||
|
||||
public StatusBar(View mainView) {
|
||||
statusView = mainView.findViewById(R.id.status_bar);
|
||||
}
|
||||
|
||||
|
||||
public StatusBar setText(String text) {
|
||||
statusText = "[ " + text + " ]";
|
||||
this.render();
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public StatusBar setDarkTheme(boolean darkTheme) {
|
||||
if (statusView == null) {
|
||||
Logger.w("StatusBar.setDarkTheme", "Not changing the theme of a NULL View.");
|
||||
return this;
|
||||
}
|
||||
|
||||
Context context = statusView.getContext();
|
||||
|
||||
int backgroundColor = ContextCompat.getColor(
|
||||
context,
|
||||
darkTheme ? R.color.dark_candidate_background : R.color.candidate_background
|
||||
);
|
||||
int color = ContextCompat.getColor(
|
||||
context,
|
||||
darkTheme ? R.color.dark_candidate_color : R.color.candidate_color
|
||||
);
|
||||
|
||||
statusView.setBackgroundColor(backgroundColor);
|
||||
statusView.setTextColor(color);
|
||||
this.render();
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
private void render() {
|
||||
if (statusText == null) {
|
||||
Logger.w("StatusBar.render", "Not displaying status of NULL mode");
|
||||
}
|
||||
|
||||
statusView.setText(statusText);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package io.github.sspanak.tt9.ui;
|
||||
package io.github.sspanak.tt9.ui.bottom;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.Color;
|
||||
|
|
@ -1,7 +1,8 @@
|
|||
package io.github.sspanak.tt9.ui;
|
||||
package io.github.sspanak.tt9.ui.bottom;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.content.Context;
|
||||
import android.graphics.Color;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.view.View;
|
||||
|
||||
|
|
@ -17,21 +18,22 @@ import java.util.List;
|
|||
import io.github.sspanak.tt9.R;
|
||||
import io.github.sspanak.tt9.preferences.SettingsStore;
|
||||
|
||||
public class SuggestionsView {
|
||||
public class SuggestionsBar {
|
||||
private final List<String> suggestions = new ArrayList<>();
|
||||
protected int selectedIndex = 0;
|
||||
private boolean isDarkThemeEnabled = false;
|
||||
|
||||
private final RecyclerView mView;
|
||||
private final SettingsStore settings;
|
||||
private SuggestionsAdapter mSuggestionsAdapter;
|
||||
|
||||
|
||||
public SuggestionsView(SettingsStore settings, View mainView) {
|
||||
public SuggestionsBar(SettingsStore settings, View mainView) {
|
||||
super();
|
||||
|
||||
this.settings = settings;
|
||||
|
||||
mView = mainView.findViewById(R.id.main_suggestions_list);
|
||||
mView = mainView.findViewById(R.id.suggestions_bar);
|
||||
mView.setLayoutManager(new LinearLayoutManager(mainView.getContext(), RecyclerView.HORIZONTAL,false));
|
||||
|
||||
initDataAdapter(mainView.getContext());
|
||||
|
|
@ -108,6 +110,8 @@ public class SuggestionsView {
|
|||
|
||||
@SuppressLint("NotifyDataSetChanged")
|
||||
public void setSuggestions(List<String> newSuggestions, int initialSel) {
|
||||
ecoSetBackground(newSuggestions);
|
||||
|
||||
suggestions.clear();
|
||||
selectedIndex = 0;
|
||||
|
||||
|
|
@ -159,14 +163,54 @@ public class SuggestionsView {
|
|||
* https://stackoverflow.com/questions/72382886/system-applies-night-mode-to-views-added-in-service-type-application-overlay
|
||||
*/
|
||||
public void setDarkTheme(boolean darkEnabled) {
|
||||
isDarkThemeEnabled = darkEnabled;
|
||||
Context context = mView.getContext();
|
||||
|
||||
int backgroundColor = darkEnabled ? R.color.dark_candidate_background : R.color.candidate_background;
|
||||
int defaultColor = darkEnabled ? R.color.dark_candidate_color : R.color.candidate_color;
|
||||
int highlightColor = darkEnabled ? R.color.dark_candidate_selected : R.color.candidate_selected;
|
||||
|
||||
mView.setBackgroundColor(ContextCompat.getColor(context, backgroundColor));
|
||||
mSuggestionsAdapter.setColorDefault(ContextCompat.getColor(context, defaultColor));
|
||||
mSuggestionsAdapter.setColorHighlight(ContextCompat.getColor(context, highlightColor));
|
||||
|
||||
setBackground(suggestions);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* setBackground
|
||||
* Makes the background transparent, when there are no suggestions and theme-colored,
|
||||
* when there are suggestions.
|
||||
*/
|
||||
private void setBackground(List<String> newSuggestions) {
|
||||
int newSuggestionsSize = newSuggestions != null ? newSuggestions.size() : 0;
|
||||
if (newSuggestionsSize == 0) {
|
||||
mView.setBackgroundColor(Color.TRANSPARENT);
|
||||
return;
|
||||
}
|
||||
|
||||
int color = ContextCompat.getColor(
|
||||
mView.getContext(),
|
||||
isDarkThemeEnabled ? R.color.dark_candidate_background : R.color.candidate_background
|
||||
);
|
||||
|
||||
mView.setBackgroundColor(color);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* ecoSetBackground
|
||||
* A performance-optimized version of "setBackground().
|
||||
* Determines if the suggestions have changed and only then it changes the background.
|
||||
*/
|
||||
private void ecoSetBackground(List<String> newSuggestions) {
|
||||
int newSuggestionsSize = newSuggestions != null ? newSuggestions.size() : 0;
|
||||
if (
|
||||
(newSuggestionsSize == 0 && suggestions.size() == 0)
|
||||
|| (newSuggestionsSize > 0 && suggestions.size() > 0)
|
||||
) {
|
||||
return;
|
||||
}
|
||||
|
||||
setBackground(newSuggestions);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue