changing the language while typing a word now automatically updates the suggestion list with new words, instead of clearing it
This commit is contained in:
parent
9553452af1
commit
17232e4e1d
4 changed files with 67 additions and 5 deletions
|
|
@ -30,6 +30,7 @@ import io.github.sspanak.tt9.ime.modes.ModePassthrough;
|
||||||
import io.github.sspanak.tt9.ime.modes.ModePredictive;
|
import io.github.sspanak.tt9.ime.modes.ModePredictive;
|
||||||
import io.github.sspanak.tt9.languages.Language;
|
import io.github.sspanak.tt9.languages.Language;
|
||||||
import io.github.sspanak.tt9.languages.LanguageCollection;
|
import io.github.sspanak.tt9.languages.LanguageCollection;
|
||||||
|
import io.github.sspanak.tt9.languages.Text;
|
||||||
import io.github.sspanak.tt9.preferences.SettingsStore;
|
import io.github.sspanak.tt9.preferences.SettingsStore;
|
||||||
import io.github.sspanak.tt9.preferences.helpers.Hotkeys;
|
import io.github.sspanak.tt9.preferences.helpers.Hotkeys;
|
||||||
import io.github.sspanak.tt9.ui.PopupDialogActivity;
|
import io.github.sspanak.tt9.ui.PopupDialogActivity;
|
||||||
|
|
@ -486,15 +487,17 @@ public class TraditionalT9 extends KeyPadHandler {
|
||||||
}
|
}
|
||||||
|
|
||||||
cancelAutoAccept();
|
cancelAutoAccept();
|
||||||
commitCurrentSuggestion(false);
|
|
||||||
resetKeyRepeat();
|
|
||||||
nextLang();
|
nextLang();
|
||||||
mInputMode.changeLanguage(mLanguage);
|
mInputMode.changeLanguage(mLanguage);
|
||||||
mInputMode.reset();
|
mInputMode.clearWordStem();
|
||||||
|
getSuggestions();
|
||||||
|
|
||||||
statusBar.setText(mInputMode.toString());
|
statusBar.setText(mInputMode.toString());
|
||||||
mainView.render();
|
mainView.render();
|
||||||
forceShowWindowIfHidden();
|
forceShowWindowIfHidden();
|
||||||
|
if (!suggestionBar.isEmpty()) {
|
||||||
|
UI.toastLanguage(this, mLanguage);
|
||||||
|
}
|
||||||
|
|
||||||
if (mInputMode instanceof ModePredictive) {
|
if (mInputMode instanceof ModePredictive) {
|
||||||
DictionaryLoader.autoLoad(this, mLanguage);
|
DictionaryLoader.autoLoad(this, mLanguage);
|
||||||
|
|
@ -658,6 +661,15 @@ public class TraditionalT9 extends KeyPadHandler {
|
||||||
// display the word suggestions
|
// display the word suggestions
|
||||||
setSuggestions(mInputMode.getSuggestions());
|
setSuggestions(mInputMode.getSuggestions());
|
||||||
|
|
||||||
|
// In case we are here, because the language was changed, and there were words for the old language,
|
||||||
|
// but there are no words for the new language, we'll get only generated suggestions, consisting
|
||||||
|
// of the last word of the previous language + endings from the new language. These words are invalid,
|
||||||
|
// so we discard them.
|
||||||
|
if (mInputMode instanceof ModePredictive && !mLanguage.isValidWord(suggestionBar.getCurrentSuggestion()) && !Text.isGraphic(suggestionBar.getCurrentSuggestion())) {
|
||||||
|
mInputMode.reset();
|
||||||
|
setSuggestions(null);
|
||||||
|
}
|
||||||
|
|
||||||
// flush the first suggestion, if the InputMode has requested it
|
// flush the first suggestion, if the InputMode has requested it
|
||||||
if (scheduleAutoAccept(mInputMode.getAutoAcceptTimeout())) {
|
if (scheduleAutoAccept(mInputMode.getAutoAcceptTimeout())) {
|
||||||
return;
|
return;
|
||||||
|
|
|
||||||
|
|
@ -29,8 +29,8 @@ public class ModeABC extends InputMode {
|
||||||
reset();
|
reset();
|
||||||
autoAcceptTimeout = 0;
|
autoAcceptTimeout = 0;
|
||||||
digitSequence = String.valueOf(number);
|
digitSequence = String.valueOf(number);
|
||||||
suggestions.add(language.getKeyNumber(number));
|
|
||||||
shouldSelectNextLetter = false;
|
shouldSelectNextLetter = false;
|
||||||
|
suggestions.add(language.getKeyNumber(number));
|
||||||
} else if (repeat > 0) {
|
} else if (repeat > 0) {
|
||||||
autoAcceptTimeout = settings.getAbcAutoAcceptTimeout();
|
autoAcceptTimeout = settings.getAbcAutoAcceptTimeout();
|
||||||
shouldSelectNextLetter = true;
|
shouldSelectNextLetter = true;
|
||||||
|
|
@ -38,9 +38,9 @@ public class ModeABC extends InputMode {
|
||||||
reset();
|
reset();
|
||||||
autoAcceptTimeout = settings.getAbcAutoAcceptTimeout();
|
autoAcceptTimeout = settings.getAbcAutoAcceptTimeout();
|
||||||
digitSequence = String.valueOf(number);
|
digitSequence = String.valueOf(number);
|
||||||
|
shouldSelectNextLetter = false;
|
||||||
suggestions.addAll(language.getKeyCharacters(number));
|
suggestions.addAll(language.getKeyCharacters(number));
|
||||||
suggestions.add(language.getKeyNumber(number));
|
suggestions.add(language.getKeyNumber(number));
|
||||||
shouldSelectNextLetter = false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|
@ -51,6 +51,14 @@ public class ModeABC extends InputMode {
|
||||||
return newTextCase == CASE_UPPER ? word.toUpperCase(language.getLocale()) : word.toLowerCase(language.getLocale());
|
return newTextCase == CASE_UPPER ? word.toUpperCase(language.getLocale()) : word.toLowerCase(language.getLocale());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void refreshSuggestions() {
|
||||||
|
if (digitSequence.isEmpty()) {
|
||||||
|
suggestions.clear();
|
||||||
|
} else {
|
||||||
|
onNumber(digitSequence.charAt(0) - '0', false, 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected boolean nextSpecialCharacters() {
|
protected boolean nextSpecialCharacters() {
|
||||||
if (digitSequence.equals(Language.SPECIAL_CHARS_KEY) && super.nextSpecialCharacters()) {
|
if (digitSequence.equals(Language.SPECIAL_CHARS_KEY) && super.nextSpecialCharacters()) {
|
||||||
|
|
@ -70,6 +78,9 @@ public class ModeABC extends InputMode {
|
||||||
if (language.hasUpperCase()) {
|
if (language.hasUpperCase()) {
|
||||||
allowedTextCases.add(CASE_UPPER);
|
allowedTextCases.add(CASE_UPPER);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
refreshSuggestions();
|
||||||
|
shouldSelectNextLetter = true; // do not accept any previous suggestions after loading the new ones
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override public int getSequenceLength() { return 1; }
|
@Override public int getSequenceLength() { return 1; }
|
||||||
|
|
|
||||||
|
|
@ -266,6 +266,29 @@ public class Language implements Comparable<Language> {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks whether the given word contains characters outside of the language alphabet.
|
||||||
|
*/
|
||||||
|
public boolean isValidWord(String word) {
|
||||||
|
if (word == null || word.isEmpty() || (word.length() == 1 && Character.isDigit(word.charAt(0)))) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
String lowerCaseWord = word.toLowerCase(locale);
|
||||||
|
if (characterKeyMap.isEmpty()) {
|
||||||
|
generateCharacterKeyMap();
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int i = 0; i < lowerCaseWord.length(); i++) {
|
||||||
|
if (!characterKeyMap.containsKey(lowerCaseWord.charAt(i))) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
|
|
|
||||||
|
|
@ -7,10 +7,15 @@ import android.os.Looper;
|
||||||
import android.view.inputmethod.InputMethodManager;
|
import android.view.inputmethod.InputMethodManager;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
|
||||||
|
import androidx.annotation.NonNull;
|
||||||
|
|
||||||
import io.github.sspanak.tt9.ime.TraditionalT9;
|
import io.github.sspanak.tt9.ime.TraditionalT9;
|
||||||
|
import io.github.sspanak.tt9.languages.Language;
|
||||||
import io.github.sspanak.tt9.preferences.PreferencesActivity;
|
import io.github.sspanak.tt9.preferences.PreferencesActivity;
|
||||||
|
|
||||||
public class UI {
|
public class UI {
|
||||||
|
private static Toast toastLang = null;
|
||||||
|
|
||||||
public static void showAddWordDialog(TraditionalT9 tt9, int language, String currentWord) {
|
public static void showAddWordDialog(TraditionalT9 tt9, int language, String currentWord) {
|
||||||
Intent intent = new Intent(tt9, PopupDialogActivity.class);
|
Intent intent = new Intent(tt9, PopupDialogActivity.class);
|
||||||
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||||
|
|
@ -93,4 +98,15 @@ public class UI {
|
||||||
public static void toastLong(Context context, CharSequence msg) {
|
public static void toastLong(Context context, CharSequence msg) {
|
||||||
Toast.makeText(context, msg, Toast.LENGTH_LONG).show();
|
Toast.makeText(context, msg, Toast.LENGTH_LONG).show();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void toastLanguage(@NonNull Context context, @NonNull Language language) {
|
||||||
|
if (toastLang != null) {
|
||||||
|
toastLang.cancel();
|
||||||
|
}
|
||||||
|
|
||||||
|
// we recreate the toast, because if set new text, when it is fading out,
|
||||||
|
// the new text is discarded
|
||||||
|
toastLang = Toast.makeText(context, language.getName(), Toast.LENGTH_SHORT);
|
||||||
|
toastLang.show();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue