smooth language change is now possible to/from East Asian languages too
This commit is contained in:
parent
86a3274436
commit
d996b74b5e
6 changed files with 14 additions and 18 deletions
|
|
@ -308,7 +308,9 @@ public abstract class HotkeyHandler extends CommandHandler {
|
||||||
if (mInputMode.changeLanguage(mLanguage)) {
|
if (mInputMode.changeLanguage(mLanguage)) {
|
||||||
mInputMode.clearWordStem();
|
mInputMode.clearWordStem();
|
||||||
} else {
|
} else {
|
||||||
|
final String digits = mInputMode.getSequence();
|
||||||
mInputMode = InputMode.getInstance(settings, mLanguage, inputType, textField, determineInputModeId());
|
mInputMode = InputMode.getInstance(settings, mLanguage, inputType, textField, determineInputModeId());
|
||||||
|
mInputMode.setSequence(digits);
|
||||||
}
|
}
|
||||||
|
|
||||||
getSuggestions(null);
|
getSuggestions(null);
|
||||||
|
|
|
||||||
|
|
@ -24,7 +24,6 @@ import io.github.sspanak.tt9.languages.LanguageCollection;
|
||||||
import io.github.sspanak.tt9.languages.LanguageKind;
|
import io.github.sspanak.tt9.languages.LanguageKind;
|
||||||
import io.github.sspanak.tt9.preferences.settings.SettingsStore;
|
import io.github.sspanak.tt9.preferences.settings.SettingsStore;
|
||||||
import io.github.sspanak.tt9.ui.UI;
|
import io.github.sspanak.tt9.ui.UI;
|
||||||
import io.github.sspanak.tt9.util.Text;
|
|
||||||
|
|
||||||
public abstract class TypingHandler extends KeyPadHandler {
|
public abstract class TypingHandler extends KeyPadHandler {
|
||||||
// internal settings/data
|
// internal settings/data
|
||||||
|
|
@ -407,15 +406,6 @@ public abstract class TypingHandler extends KeyPadHandler {
|
||||||
// display the word suggestions
|
// display the word suggestions
|
||||||
suggestionOps.set(mInputMode.getSuggestions(), mInputMode.containsGeneratedSuggestions());
|
suggestionOps.set(mInputMode.getSuggestions(), mInputMode.containsGeneratedSuggestions());
|
||||||
|
|
||||||
// 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 (InputModeKind.isPredictive(mInputMode) && !mLanguage.isValidWord(suggestionOps.getCurrent()) && !Text.isGraphic(suggestionOps.getCurrent())) {
|
|
||||||
mInputMode.reset();
|
|
||||||
suggestionOps.set(null);
|
|
||||||
}
|
|
||||||
|
|
||||||
// flush the first suggestion, if the InputMode has requested it
|
// flush the first suggestion, if the InputMode has requested it
|
||||||
if (suggestionOps.scheduleDelayedAccept(mInputMode.getAutoAcceptTimeout())) {
|
if (suggestionOps.scheduleDelayedAccept(mInputMode.getAutoAcceptTimeout())) {
|
||||||
return;
|
return;
|
||||||
|
|
|
||||||
|
|
@ -114,7 +114,8 @@ abstract public class InputMode {
|
||||||
// Utility
|
// Utility
|
||||||
abstract public int getId();
|
abstract public int getId();
|
||||||
public boolean containsGeneratedSuggestions() { return false; }
|
public boolean containsGeneratedSuggestions() { return false; }
|
||||||
public String getSequence() { return digitSequence; }
|
@NonNull public String getSequence() { return digitSequence; }
|
||||||
|
public void setSequence(@NonNull String sequence) { digitSequence = sequence; }
|
||||||
public int getSequenceLength() { return digitSequence.length(); } // The number of key presses for the current word.
|
public int getSequenceLength() { return digitSequence.length(); } // The number of key presses for the current word.
|
||||||
public int getAutoAcceptTimeout() {
|
public int getAutoAcceptTimeout() {
|
||||||
return autoAcceptTimeout;
|
return autoAcceptTimeout;
|
||||||
|
|
|
||||||
|
|
@ -100,9 +100,9 @@ public class ModeIdeograms extends ModeWords {
|
||||||
@Override
|
@Override
|
||||||
public void onAcceptSuggestion(@NonNull String currentWord, boolean preserveWords) {
|
public void onAcceptSuggestion(@NonNull String currentWord, boolean preserveWords) {
|
||||||
final Text text = new Text(currentWord);
|
final Text text = new Text(currentWord);
|
||||||
if (text.isEmpty() || text.startsWithWhitespace() || text.isNumeric()) {
|
if (text.isEmpty() || text.startsWithWhitespace() || text.isNumeric() || !language.isValidWord(currentWord)) {
|
||||||
reset();
|
reset();
|
||||||
Logger.i(LOG_TAG, "Current word is empty or numeric. Nothing to accept.");
|
Logger.i(LOG_TAG, "Current word is empty, numeric or invalid. Nothing to accept.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -114,7 +114,7 @@ public class ModeIdeograms extends ModeWords {
|
||||||
}
|
}
|
||||||
|
|
||||||
final int initialLength = digitSequence.length();
|
final int initialLength = digitSequence.length();
|
||||||
final boolean lastDigitBelongsToNewWord = preserveWords && initialLength >= 2;
|
boolean lastDigitBelongsToNewWord = preserveWords && initialLength >= 2;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (!digitSequence.equals(SPECIAL_CHAR_SEQUENCE) && !digitSequence.equals(PUNCTUATION_SEQUENCE)) {
|
if (!digitSequence.equals(SPECIAL_CHAR_SEQUENCE) && !digitSequence.equals(PUNCTUATION_SEQUENCE)) {
|
||||||
|
|
@ -125,8 +125,8 @@ public class ModeIdeograms extends ModeWords {
|
||||||
((IdeogramPredictions) predictions).onAcceptIdeogram(currentWord);
|
((IdeogramPredictions) predictions).onAcceptIdeogram(currentWord);
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
lastAcceptedSequence = lastAcceptedWord = "";
|
|
||||||
Logger.e(LOG_TAG, "Failed incrementing priority of word: '" + currentWord + "'. " + e.getMessage());
|
Logger.e(LOG_TAG, "Failed incrementing priority of word: '" + currentWord + "'. " + e.getMessage());
|
||||||
|
lastAcceptedSequence = lastAcceptedWord = "";
|
||||||
}
|
}
|
||||||
|
|
||||||
if (lastDigitBelongsToNewWord) {
|
if (lastDigitBelongsToNewWord) {
|
||||||
|
|
|
||||||
|
|
@ -323,8 +323,8 @@ class ModeWords extends ModeCheonjiin {
|
||||||
}
|
}
|
||||||
stem = "";
|
stem = "";
|
||||||
|
|
||||||
if (currentWord.isEmpty()) {
|
if (currentWord.isEmpty() || !language.isValidWord(currentWord)) {
|
||||||
Logger.i(LOG_TAG, "Current word is empty. Nothing to accept.");
|
Logger.i(LOG_TAG, "Current word is empty or invalid. Nothing to accept.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -264,12 +264,15 @@ public class NaturalLanguage extends TranscribedLanguage {
|
||||||
if (
|
if (
|
||||||
word == null
|
word == null
|
||||||
|| word.isEmpty()
|
|| word.isEmpty()
|
||||||
|| (super.isValidWord(word))
|
|
||||||
|| (word.length() == 1 && Character.isDigit(word.charAt(0)))
|
|| (word.length() == 1 && Character.isDigit(word.charAt(0)))
|
||||||
) {
|
) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (isTranscribed) {
|
||||||
|
return super.isValidWord(word);
|
||||||
|
}
|
||||||
|
|
||||||
String lowerCaseWord = word.toLowerCase(locale);
|
String lowerCaseWord = word.toLowerCase(locale);
|
||||||
|
|
||||||
for (int i = 0; i < lowerCaseWord.length(); i++) {
|
for (int i = 0; i < lowerCaseWord.length(); i++) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue