fixed incorrect punctuation order in email fields and after toggling between currency and math chars
This commit is contained in:
parent
14e7224981
commit
b7923ac76b
4 changed files with 70 additions and 31 deletions
|
|
@ -179,6 +179,7 @@ abstract public class InputMode {
|
||||||
&& previousGroup != specialCharSelectedGroup; // verifies validation has passed
|
&& previousGroup != specialCharSelectedGroup; // verifies validation has passed
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
protected boolean loadSpecialCharacters() {
|
protected boolean loadSpecialCharacters() {
|
||||||
if (language == null || digitSequence.isEmpty()) {
|
if (language == null || digitSequence.isEmpty()) {
|
||||||
return false;
|
return false;
|
||||||
|
|
@ -201,6 +202,27 @@ abstract public class InputMode {
|
||||||
return true;
|
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 (language == null || specialCharSelectedGroup != 0 || key > 1) {
|
||||||
|
return new ArrayList<>(unordered);
|
||||||
|
}
|
||||||
|
|
||||||
|
ArrayList<String> ordered = new ArrayList<>();
|
||||||
|
for (String ch : settings.getOrderedKeyChars(language, key)) {
|
||||||
|
if (unordered.contains(ch)) {
|
||||||
|
ordered.add(ch);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return ordered;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// Stem filtering.
|
// Stem filtering.
|
||||||
// Where applicable, return "true" if the mode supports it and the operation was possible.
|
// Where applicable, return "true" if the mode supports it and the operation was possible.
|
||||||
public boolean clearWordStem() { return setWordStem("", true); }
|
public boolean clearWordStem() { return setWordStem("", true); }
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,6 @@ package io.github.sspanak.tt9.ime.modes;
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
|
||||||
|
|
||||||
import io.github.sspanak.tt9.hacks.InputType;
|
import io.github.sspanak.tt9.hacks.InputType;
|
||||||
import io.github.sspanak.tt9.languages.Language;
|
import io.github.sspanak.tt9.languages.Language;
|
||||||
|
|
@ -31,21 +30,20 @@ public class Mode123 extends ModePassthrough {
|
||||||
isEmailMode = inputType.isEmail();
|
isEmailMode = inputType.isEmail();
|
||||||
|
|
||||||
if (inputType.isPhoneNumber()) {
|
if (inputType.isPhoneNumber()) {
|
||||||
setSpecificSpecialCharacters(Characters.Phone);
|
setSpecificSpecialCharacters(Characters.Phone, false);
|
||||||
} else if (inputType.isNumeric()) {
|
} else if (inputType.isNumeric()) {
|
||||||
setSpecificSpecialCharacters(Characters.getNumberSpecialCharacters(inputType.isDecimal(), inputType.isSignedNumber()));
|
setSpecificSpecialCharacters(Characters.getNumberSpecialCharacters(inputType.isDecimal(), inputType.isSignedNumber()), false);
|
||||||
} else if (inputType.isEmail()) {
|
} else if (inputType.isEmail()) {
|
||||||
setSpecificSpecialCharacters(Characters.Email);
|
setSpecificSpecialCharacters(Characters.Email, true);
|
||||||
} else {
|
} else {
|
||||||
setDefaultSpecialCharacters();
|
setDefaultSpecialCharacters();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private void setSpecificSpecialCharacters(ArrayList<ArrayList<String>> chars) {
|
private void setSpecificSpecialCharacters(ArrayList<ArrayList<String>> chars, boolean sort) {
|
||||||
for (ArrayList<String> group : chars) {
|
for (int group = 0; group < chars.size(); group++) {
|
||||||
KEY_CHARACTERS.add(new ArrayList<>(group));
|
KEY_CHARACTERS.add(sort ? applyPunctuationOrder(chars.get(group), group) : new ArrayList<>(chars.get(group)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -56,26 +54,41 @@ public class Mode123 extends ModePassthrough {
|
||||||
* use the default list, but reorder it a bit for convenience.
|
* use the default list, but reorder it a bit for convenience.
|
||||||
*/
|
*/
|
||||||
private void setDefaultSpecialCharacters() {
|
private void setDefaultSpecialCharacters() {
|
||||||
// 0-key
|
KEY_CHARACTERS.add(applyNumericFieldCharacterOrder(settings.getOrderedKeyChars(language, 0), 0));
|
||||||
KEY_CHARACTERS.add(new ArrayList<>(Collections.singletonList("+")));
|
KEY_CHARACTERS.add(applyNumericFieldCharacterOrder(settings.getOrderedKeyChars(language, 1), 1));
|
||||||
for (String character : settings.getOrderedKeyChars(language, 0)) {
|
|
||||||
if (!character.equals("+") && !character.equals("\n")) {
|
|
||||||
KEY_CHARACTERS.get(0).add(character);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 1-key
|
|
||||||
KEY_CHARACTERS.add(new ArrayList<>(Collections.singletonList(".")));
|
|
||||||
for (String character : settings.getOrderedKeyChars(language, 1)) {
|
|
||||||
if (!character.equals(".")) {
|
|
||||||
KEY_CHARACTERS.get(1).add(character);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override protected boolean nextSpecialCharacters() {
|
@Override protected boolean nextSpecialCharacters() {
|
||||||
return !isEmailMode && digitSequence.equals(NaturalLanguage.SPECIAL_CHARS_KEY) && super.nextSpecialCharacters();
|
if (isEmailMode || !digitSequence.equals(NaturalLanguage.SPECIAL_CHARS_KEY) || !super.nextSpecialCharacters()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
ArrayList<String> ordered = applyNumericFieldCharacterOrder(suggestions, specialCharSelectedGroup);
|
||||||
|
suggestions.clear();
|
||||||
|
suggestions.addAll(ordered);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
protected ArrayList<String> applyNumericFieldCharacterOrder(ArrayList<String> unordered, int key) {
|
||||||
|
ArrayList<String> ordered = new ArrayList<>();
|
||||||
|
|
||||||
|
if (unordered.contains(".")) {
|
||||||
|
ordered.add(".");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (unordered.contains("+")) {
|
||||||
|
ordered.add("+");
|
||||||
|
}
|
||||||
|
|
||||||
|
for (String character : unordered) {
|
||||||
|
if (!character.equals("+") && !character.equals(".") && !character.equals("\n")) {
|
||||||
|
ordered.add(character);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return ordered;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -88,6 +101,7 @@ public class Mode123 extends ModePassthrough {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override public boolean onNumber(int number, boolean hold, int repeat) {
|
@Override public boolean onNumber(int number, boolean hold, int repeat) {
|
||||||
reset();
|
reset();
|
||||||
digitSequence = String.valueOf(number);
|
digitSequence = String.valueOf(number);
|
||||||
|
|
@ -102,6 +116,7 @@ public class Mode123 extends ModePassthrough {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* shouldIgnoreText
|
* shouldIgnoreText
|
||||||
* Since this is a numeric mode, we allow typing only numbers and:
|
* Since this is a numeric mode, we allow typing only numbers and:
|
||||||
|
|
@ -122,10 +137,12 @@ public class Mode123 extends ModePassthrough {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override public void onAcceptSuggestion(@NonNull String ignored, boolean ignored2) {
|
@Override public void onAcceptSuggestion(@NonNull String ignored, boolean ignored2) {
|
||||||
reset();
|
reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override public void reset() {
|
@Override public void reset() {
|
||||||
super.reset();
|
super.reset();
|
||||||
digitSequence = "";
|
digitSequence = "";
|
||||||
|
|
|
||||||
|
|
@ -23,8 +23,8 @@ public class ModeABC extends InputMode {
|
||||||
changeLanguage(lang);
|
changeLanguage(lang);
|
||||||
|
|
||||||
if (inputType.isEmail()) {
|
if (inputType.isEmail()) {
|
||||||
KEY_CHARACTERS.add(new ArrayList<>(Characters.Email.get(0)));
|
KEY_CHARACTERS.add(applyPunctuationOrder(Characters.Email.get(0), 0));
|
||||||
KEY_CHARACTERS.add(new ArrayList<>(Characters.Email.get(1)));
|
KEY_CHARACTERS.add(applyPunctuationOrder(Characters.Email.get(1), 1));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -51,13 +51,13 @@ public class ModePredictive extends InputMode {
|
||||||
digitSequence = "";
|
digitSequence = "";
|
||||||
predictions = new Predictions(settings, textField);
|
predictions = new Predictions(settings, textField);
|
||||||
|
|
||||||
if (inputType.isEmail()) {
|
|
||||||
KEY_CHARACTERS.add(new ArrayList<>(Characters.Email.get(0)));
|
|
||||||
KEY_CHARACTERS.add(new ArrayList<>(Characters.Email.get(1)));
|
|
||||||
}
|
|
||||||
|
|
||||||
changeLanguage(lang);
|
changeLanguage(lang);
|
||||||
defaultTextCase();
|
defaultTextCase();
|
||||||
|
|
||||||
|
if (inputType.isEmail()) {
|
||||||
|
KEY_CHARACTERS.add(applyPunctuationOrder(Characters.Email.get(0), 0));
|
||||||
|
KEY_CHARACTERS.add(applyPunctuationOrder(Characters.Email.get(1), 1));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue