removed all remaining code related to alternative character groups per key
This commit is contained in:
parent
ce3446c3dd
commit
aecc350b91
11 changed files with 66 additions and 107 deletions
|
|
@ -42,7 +42,6 @@ abstract public class InputMode {
|
|||
protected final SettingsStore settings;
|
||||
@NonNull protected final ArrayList<String> suggestions = new ArrayList<>();
|
||||
@NonNull protected Runnable onSuggestionsUpdated = () -> {};
|
||||
protected int specialCharSelectedGroup = 0;
|
||||
@NonNull protected Sequences seq = new Sequences();
|
||||
|
||||
|
||||
|
|
@ -165,7 +164,6 @@ abstract public class InputMode {
|
|||
|
||||
public void reset() {
|
||||
autoAcceptTimeout = -1;
|
||||
specialCharSelectedGroup = 0;
|
||||
suggestions.clear();
|
||||
}
|
||||
|
||||
|
|
@ -211,62 +209,13 @@ abstract public class InputMode {
|
|||
|
||||
|
||||
protected boolean loadSpecialCharacters() {
|
||||
int key = digitSequence.charAt(0) - '0';
|
||||
ArrayList<String> chars = settings.getOrderedKeyChars(language, key, specialCharSelectedGroup);
|
||||
|
||||
if (chars.isEmpty() && specialCharSelectedGroup == 1) {
|
||||
specialCharSelectedGroup = 0;
|
||||
return false;
|
||||
} else if (chars.isEmpty()) {
|
||||
specialCharSelectedGroup = 0;
|
||||
chars = settings.getOrderedKeyChars(language, key, specialCharSelectedGroup);
|
||||
}
|
||||
|
||||
suggestions.clear();
|
||||
suggestions.addAll(chars);
|
||||
suggestions.addAll(settings.getOrderedKeyChars(language, digitSequence.charAt(0) - '0'));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Applies the punctuation order when we don't want to display the entire
|
||||
* list of characters, for example in email, numeric or other specialized fields.
|
||||
*/
|
||||
protected ArrayList<String> applyPunctuationOrder(ArrayList<String> unordered, int key) {
|
||||
if (specialCharSelectedGroup != 0 || key > 1) {
|
||||
return new ArrayList<>(unordered);
|
||||
}
|
||||
|
||||
return orderSpecialChars(unordered, settings.getOrderedKeyChars(language, key));
|
||||
}
|
||||
|
||||
|
||||
public ArrayList<String> orderSpecialChars(@NonNull ArrayList<String> unordered, @Nullable ArrayList<String> order) {
|
||||
ArrayList<String> ordered = new ArrayList<>();
|
||||
if (unordered.isEmpty() || order == null || order.isEmpty()) {
|
||||
return ordered;
|
||||
}
|
||||
|
||||
if (isEmailMode) {
|
||||
if (unordered.contains("@")) ordered.add("@");
|
||||
if (unordered.contains("_")) ordered.add("_");
|
||||
}
|
||||
|
||||
for (String ch : order) {
|
||||
if (isEmailMode && (ch.charAt(0) == '@' || ch.charAt(0) == '_')) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (unordered.contains(ch)) {
|
||||
ordered.add(ch);
|
||||
}
|
||||
}
|
||||
|
||||
return ordered;
|
||||
}
|
||||
|
||||
|
||||
// Stem filtering.
|
||||
// Where applicable, return "true" if the mode supports it and the operation was possible.
|
||||
public boolean clearWordStem() { return setWordStem("", true); }
|
||||
|
|
|
|||
|
|
@ -40,7 +40,9 @@ class Mode123 extends ModePassthrough {
|
|||
|
||||
private void setSpecificSpecialCharacters(ArrayList<ArrayList<String>> chars, boolean sort) {
|
||||
for (int group = 0; group < chars.size(); group++) {
|
||||
KEY_CHARACTERS.add(sort ? applyPunctuationOrder(chars.get(group), group) : new ArrayList<>(chars.get(group)));
|
||||
KEY_CHARACTERS.add(
|
||||
sort ? Characters.orderByList(chars.get(group), settings.getOrderedKeyChars(language, group), isEmailMode) : new ArrayList<>(chars.get(group))
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -55,13 +57,12 @@ class Mode123 extends ModePassthrough {
|
|||
Language english = LanguageCollection.getByLocale("en");
|
||||
KEY_CHARACTERS.add(getAbbreviatedSpecialChars());
|
||||
KEY_CHARACTERS.add(
|
||||
TextTools.removeLettersFromList(orderSpecialChars(settings.getOrderedKeyChars(english, 1), null))
|
||||
TextTools.removeLettersFromList(orderCharsForNumericField(settings.getOrderedKeyChars(english, 1), null))
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public ArrayList<String> orderSpecialChars(@NonNull ArrayList<String> unordered, @Nullable ArrayList<String> o) {
|
||||
private ArrayList<String> orderCharsForNumericField(@NonNull ArrayList<String> unordered, @Nullable ArrayList<String> o) {
|
||||
ArrayList<String> ordered = new ArrayList<>();
|
||||
|
||||
if (unordered.contains(".")) {
|
||||
|
|
|
|||
|
|
@ -21,14 +21,6 @@ class ModeABC extends InputMode {
|
|||
protected ModeABC(SettingsStore settings, Language lang, InputType inputType) {
|
||||
super(settings, inputType);
|
||||
changeLanguage(lang);
|
||||
|
||||
if (isEmailMode) {
|
||||
KEY_CHARACTERS.add(applyPunctuationOrder(Characters.Email.get(0), 0));
|
||||
KEY_CHARACTERS.add(applyPunctuationOrder(Characters.Email.get(1), 1));
|
||||
} else {
|
||||
KEY_CHARACTERS.add(getAbbreviatedSpecialChars());
|
||||
KEY_CHARACTERS.add(settings.getOrderedKeyChars(language, 1));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -57,7 +49,7 @@ class ModeABC extends InputMode {
|
|||
autoAcceptTimeout = settings.getAbcAutoAcceptTimeout();
|
||||
digitSequence = String.valueOf(number);
|
||||
shouldSelectNextLetter = false;
|
||||
suggestions.addAll(KEY_CHARACTERS.size() > number ? KEY_CHARACTERS.get(number) : new ArrayList<>());
|
||||
suggestions.addAll(KEY_CHARACTERS.size() > number ? KEY_CHARACTERS.get(number) : settings.getOrderedKeyChars(language, number));
|
||||
suggestions.add(language.getKeyNumeral(number));
|
||||
}
|
||||
|
||||
|
|
@ -91,6 +83,14 @@ class ModeABC extends InputMode {
|
|||
allowedTextCases.add(CASE_UPPER);
|
||||
}
|
||||
|
||||
KEY_CHARACTERS.clear();
|
||||
if (isEmailMode) {
|
||||
KEY_CHARACTERS.add(Characters.orderByList(Characters.Email.get(0), settings.getOrderedKeyChars(language, 0), true));
|
||||
KEY_CHARACTERS.add(Characters.orderByList(Characters.Email.get(1), settings.getOrderedKeyChars(language, 1), true));
|
||||
} else {
|
||||
KEY_CHARACTERS.add(getAbbreviatedSpecialChars());
|
||||
}
|
||||
|
||||
refreshSuggestions();
|
||||
shouldSelectNextLetter = true; // do not accept any previous suggestions after loading the new ones
|
||||
|
||||
|
|
|
|||
|
|
@ -51,7 +51,7 @@ public class ModeBopomofo extends ModePinyin {
|
|||
|
||||
// punctuation
|
||||
KEY_CHARACTERS.add(
|
||||
TextTools.removeLettersFromList(applyPunctuationOrder(Characters.PunctuationChineseBopomofo, 1))
|
||||
TextTools.removeLettersFromList(Characters.orderByList(Characters.PunctuationChineseBopomofo, settings.getOrderedKeyChars(language, 1), false))
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -67,7 +67,7 @@ class ModeCheonjiin extends InputMode {
|
|||
|
||||
// punctuation
|
||||
KEY_CHARACTERS.add(
|
||||
TextTools.removeLettersFromList(applyPunctuationOrder(Characters.PunctuationKorean, 1))
|
||||
TextTools.removeLettersFromList(Characters.orderByList(Characters.PunctuationKorean, settings.getOrderedKeyChars(language, 1), false))
|
||||
);
|
||||
}
|
||||
|
||||
|
|
@ -80,8 +80,8 @@ class ModeCheonjiin extends InputMode {
|
|||
|
||||
KEY_CHARACTERS.clear();
|
||||
if (isEmailMode) {
|
||||
KEY_CHARACTERS.add(applyPunctuationOrder(Characters.Email.get(0), 0));
|
||||
KEY_CHARACTERS.add(applyPunctuationOrder(Characters.Email.get(1), 1));
|
||||
KEY_CHARACTERS.add(Characters.orderByList(Characters.Email.get(0), settings.getOrderedKeyChars(language, 0), true));
|
||||
KEY_CHARACTERS.add(Characters.orderByList(Characters.Email.get(1), settings.getOrderedKeyChars(language, 1), true));
|
||||
} else {
|
||||
setCustomSpecialCharacters();
|
||||
}
|
||||
|
|
@ -246,18 +246,6 @@ class ModeCheonjiin extends InputMode {
|
|||
return false;
|
||||
}
|
||||
|
||||
// KEY_CHARACTERS contains chars for group 0 only. If it turns out we are at group > 0
|
||||
// we must allow super to do its job.
|
||||
boolean callSuper = true;
|
||||
if (specialCharSelectedGroup > 0) {
|
||||
super.loadSpecialCharacters(); // this increments specialCharSelectedGroup or resets it to 0, if no more groups are available
|
||||
callSuper = false;
|
||||
if (specialCharSelectedGroup > 0) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
// ... otherwise display our custom first groups, if available
|
||||
int number = digitSequence.isEmpty() ? Integer.MAX_VALUE : digitSequence.charAt(digitSequence.length() - 1) - '0';
|
||||
if (KEY_CHARACTERS.size() > number) {
|
||||
suggestions.clear();
|
||||
|
|
@ -265,8 +253,7 @@ class ModeCheonjiin extends InputMode {
|
|||
return true;
|
||||
}
|
||||
|
||||
// if we never asked super to advance the group and load the respective chars, do it now
|
||||
return callSuper && super.loadSpecialCharacters();
|
||||
return super.loadSpecialCharacters();
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -33,11 +33,16 @@ public class EmojiLanguage extends Language {
|
|||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public ArrayList<String> getKeyCharacters(int key, int characterGroup) {
|
||||
return key == 1 && characterGroup >= 0 ? Characters.getEmoji(characterGroup) : new ArrayList<>();
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public ArrayList<String> getKeyCharacters(int key) {
|
||||
return getKeyCharacters(key, 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isValidWord(String word) {
|
||||
return TextTools.isGraphic(word);
|
||||
|
|
|
|||
|
|
@ -53,13 +53,8 @@ abstract public class Language {
|
|||
/**
|
||||
* Returns the characters that the key would type in ABC or Predictive mode. For example,
|
||||
* the key 2 in English would return A-B-C.
|
||||
* Keys that have special characters assigned, may have more than one group assigned. The specific
|
||||
* group is selected by the characterGroup parameter. By default, group 0 is returned.
|
||||
*/
|
||||
@NonNull abstract public ArrayList<String> getKeyCharacters(int key, int characterGroup);
|
||||
@NonNull public ArrayList<String> getKeyCharacters(int key) {
|
||||
return getKeyCharacters(key, 0);
|
||||
}
|
||||
@NonNull abstract public ArrayList<String> getKeyCharacters(int key);
|
||||
|
||||
@NonNull public String getKeyNumeral(int key) {
|
||||
return String.valueOf(key);
|
||||
|
|
|
|||
|
|
@ -212,7 +212,8 @@ public class NaturalLanguage extends TranscribedLanguage {
|
|||
|
||||
|
||||
@NonNull
|
||||
public ArrayList<String> getKeyCharacters(int key, int characterGroup) {
|
||||
@Override
|
||||
public ArrayList<String> getKeyCharacters(int key) {
|
||||
if (key < 0 || key >= layout.size()) {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,17 +16,17 @@ public class NullLanguage extends Language {
|
|||
name = "Nulla Lingua";
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public ArrayList<String> getKeyCharacters(int key, int characterGroup) {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isValidWord(String word) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public ArrayList<String> getKeyCharacters(int key) {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public String getDigitSequenceForWord(String word) {
|
||||
|
|
|
|||
|
|
@ -95,16 +95,6 @@ class SettingsPunctuation extends SettingsInput {
|
|||
}
|
||||
|
||||
|
||||
@NonNull
|
||||
public ArrayList<String> getOrderedKeyChars(Language language, int number, int group) {
|
||||
if (group > 0 && language != null) {
|
||||
return language.getKeyCharacters(number, group);
|
||||
}
|
||||
|
||||
return getOrderedKeyChars(language, number);
|
||||
}
|
||||
|
||||
|
||||
private ArrayList<String> getCharsAsList(String chars, ArrayList<String> defaultValue) {
|
||||
if (chars == null) {
|
||||
return defaultValue;
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
package io.github.sspanak.tt9.util.chars;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
|
@ -107,4 +108,34 @@ public class Characters extends Emoji {
|
|||
ch == 0x0950 // Devanagari
|
||||
|| ch == 0x0AD0; // Gujarati
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Orders a list of characters according according to the order of another list. Any characters
|
||||
* from "unordered" list that are not present in the "order" list will be ignored. In email mode,
|
||||
* email-specific characters will be moved to the beginning of the list.
|
||||
*/
|
||||
public static ArrayList<String> orderByList(@NonNull ArrayList<String> unordered, @Nullable ArrayList<String> order, boolean isEmailMode) {
|
||||
ArrayList<String> ordered = new ArrayList<>();
|
||||
if (unordered.isEmpty() || order == null || order.isEmpty()) {
|
||||
return ordered;
|
||||
}
|
||||
|
||||
if (isEmailMode) {
|
||||
if (unordered.contains("@")) ordered.add("@");
|
||||
if (unordered.contains("_")) ordered.add("_");
|
||||
}
|
||||
|
||||
for (String ch : order) {
|
||||
if (isEmailMode && (ch.charAt(0) == '@' || ch.charAt(0) == '_')) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (unordered.contains(ch)) {
|
||||
ordered.add(ch);
|
||||
}
|
||||
}
|
||||
|
||||
return ordered;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue