Auto accept in abc mode (#269)
* added automatic delayed suggestion accept support in ABC mode * fixed: impossible to type a letter in ABC after coming back from preferences, if the same key was pressed before opening them
This commit is contained in:
parent
4405c0e34b
commit
de964e8b0f
9 changed files with 90 additions and 7 deletions
|
|
@ -2,6 +2,8 @@ package io.github.sspanak.tt9.ime;
|
|||
|
||||
import android.content.Context;
|
||||
import android.os.Build;
|
||||
import android.os.Handler;
|
||||
import android.os.Looper;
|
||||
import android.view.KeyEvent;
|
||||
import android.view.View;
|
||||
import android.view.inputmethod.EditorInfo;
|
||||
|
|
@ -31,6 +33,7 @@ public class TraditionalT9 extends KeyPadHandler {
|
|||
private boolean isActive = false;
|
||||
@NotNull private TextField textField = new TextField(null, null);
|
||||
@NotNull private InputType inputType = new InputType(null, null);
|
||||
@NotNull private final Handler autoAcceptHandler = new Handler(Looper.getMainLooper());
|
||||
|
||||
// input mode
|
||||
private ArrayList<Integer> allowedInputModes = new ArrayList<>();
|
||||
|
|
@ -136,6 +139,8 @@ public class TraditionalT9 extends KeyPadHandler {
|
|||
// in case we are back from Settings screen, update the language list
|
||||
mEnabledLanguages = settings.getEnabledLanguageIds();
|
||||
validateLanguages();
|
||||
|
||||
resetKeyRepeat();
|
||||
determineInputMode();
|
||||
determineTextCase();
|
||||
}
|
||||
|
|
@ -192,6 +197,7 @@ public class TraditionalT9 extends KeyPadHandler {
|
|||
|
||||
|
||||
protected void onFinishTyping() {
|
||||
cancelAutoAccept();
|
||||
isActive = false;
|
||||
}
|
||||
|
||||
|
|
@ -213,6 +219,7 @@ public class TraditionalT9 extends KeyPadHandler {
|
|||
return false;
|
||||
}
|
||||
|
||||
cancelAutoAccept();
|
||||
resetKeyRepeat();
|
||||
|
||||
if (mInputMode.onBackspace()) {
|
||||
|
|
@ -228,6 +235,8 @@ public class TraditionalT9 extends KeyPadHandler {
|
|||
|
||||
|
||||
public boolean onOK() {
|
||||
cancelAutoAccept();
|
||||
|
||||
if (!isInputViewShown() && !textField.isThereText()) {
|
||||
forceShowWindowIfHidden();
|
||||
return true;
|
||||
|
|
@ -248,6 +257,7 @@ public class TraditionalT9 extends KeyPadHandler {
|
|||
|
||||
protected boolean onUp() {
|
||||
if (previousSuggestion()) {
|
||||
cancelAutoAccept();
|
||||
mInputMode.setWordStem(suggestionBar.getCurrentSuggestion(), true);
|
||||
textField.setComposingTextWithHighlightedStem(suggestionBar.getCurrentSuggestion(), mInputMode);
|
||||
return true;
|
||||
|
|
@ -259,6 +269,7 @@ public class TraditionalT9 extends KeyPadHandler {
|
|||
|
||||
protected boolean onDown() {
|
||||
if (nextSuggestion()) {
|
||||
cancelAutoAccept();
|
||||
mInputMode.setWordStem(suggestionBar.getCurrentSuggestion(), true);
|
||||
textField.setComposingTextWithHighlightedStem(suggestionBar.getCurrentSuggestion(), mInputMode);
|
||||
return true;
|
||||
|
|
@ -269,6 +280,8 @@ public class TraditionalT9 extends KeyPadHandler {
|
|||
|
||||
|
||||
protected boolean onLeft() {
|
||||
cancelAutoAccept();
|
||||
|
||||
if (mInputMode.clearWordStem()) {
|
||||
mInputMode.loadSuggestions(this::getSuggestions, getComposingText());
|
||||
} else {
|
||||
|
|
@ -280,6 +293,8 @@ public class TraditionalT9 extends KeyPadHandler {
|
|||
|
||||
|
||||
protected boolean onRight(boolean repeat) {
|
||||
cancelAutoAccept();
|
||||
|
||||
String filter;
|
||||
if (repeat && !suggestionBar.getSuggestion(1).equals("")) {
|
||||
filter = suggestionBar.getSuggestion(1);
|
||||
|
|
@ -306,6 +321,7 @@ public class TraditionalT9 extends KeyPadHandler {
|
|||
* @return boolean
|
||||
*/
|
||||
protected boolean onNumber(int key, boolean hold, int repeat) {
|
||||
cancelAutoAccept();
|
||||
forceShowWindowIfHidden();
|
||||
|
||||
String currentWord = getComposingText();
|
||||
|
|
@ -329,6 +345,7 @@ public class TraditionalT9 extends KeyPadHandler {
|
|||
|
||||
if (mInputMode.shouldSelectNextSuggestion() && !isSuggestionViewHidden()) {
|
||||
nextSuggestion();
|
||||
scheduleAutoAccept(mInputMode.getAutoAcceptTimeout());
|
||||
} else {
|
||||
getSuggestions();
|
||||
}
|
||||
|
|
@ -338,6 +355,8 @@ public class TraditionalT9 extends KeyPadHandler {
|
|||
|
||||
|
||||
public boolean onOtherKey(int keyCode) {
|
||||
cancelAutoAccept();
|
||||
|
||||
String acceptedWord = acceptIncompleteSuggestion();
|
||||
if (mInputMode.onOtherKey(keyCode)) {
|
||||
autoCorrectSpace(acceptedWord, false);
|
||||
|
|
@ -355,6 +374,8 @@ public class TraditionalT9 extends KeyPadHandler {
|
|||
return false;
|
||||
}
|
||||
|
||||
cancelAutoAccept();
|
||||
|
||||
// accept the previously typed word (if any)
|
||||
autoCorrectSpace(acceptIncompleteSuggestion(), false);
|
||||
|
||||
|
|
@ -371,6 +392,7 @@ public class TraditionalT9 extends KeyPadHandler {
|
|||
return false;
|
||||
}
|
||||
|
||||
cancelAutoAccept();
|
||||
showAddWord();
|
||||
return true;
|
||||
}
|
||||
|
|
@ -378,6 +400,7 @@ public class TraditionalT9 extends KeyPadHandler {
|
|||
|
||||
public boolean onKeyNextLanguage() {
|
||||
if (nextLang()) {
|
||||
cancelAutoAccept();
|
||||
commitCurrentSuggestion(false);
|
||||
mInputMode.changeLanguage(mLanguage);
|
||||
mInputMode.reset();
|
||||
|
|
@ -390,12 +413,12 @@ public class TraditionalT9 extends KeyPadHandler {
|
|||
return true;
|
||||
}
|
||||
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
public boolean onKeyNextInputMode() {
|
||||
scheduleAutoAccept(mInputMode.getAutoAcceptTimeout()); // restart the timer
|
||||
nextInputMode();
|
||||
mainView.render();
|
||||
|
||||
|
|
@ -413,6 +436,7 @@ public class TraditionalT9 extends KeyPadHandler {
|
|||
return false;
|
||||
}
|
||||
|
||||
cancelAutoAccept();
|
||||
UI.showSettingsScreen(this);
|
||||
return true;
|
||||
}
|
||||
|
|
@ -456,6 +480,32 @@ public class TraditionalT9 extends KeyPadHandler {
|
|||
}
|
||||
|
||||
|
||||
private boolean scheduleAutoAccept(int delay) {
|
||||
cancelAutoAccept();
|
||||
|
||||
if (delay == 0) {
|
||||
this.onOK();
|
||||
return true;
|
||||
} else if (delay > 0) {
|
||||
autoAcceptHandler.postDelayed(this::autoAccept, delay);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
private void cancelAutoAccept() {
|
||||
autoAcceptHandler.removeCallbacksAndMessages(null);
|
||||
}
|
||||
|
||||
|
||||
private void autoAccept() {
|
||||
if (suggestionBar.hasElements()) {
|
||||
this.onOK();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private String acceptIncompleteSuggestion() {
|
||||
String currentWord = getComposingText();
|
||||
mInputMode.onAcceptSuggestion(currentWord);
|
||||
|
|
@ -504,12 +554,11 @@ public class TraditionalT9 extends KeyPadHandler {
|
|||
return;
|
||||
}
|
||||
|
||||
// display the list of suggestions
|
||||
// display the word suggestions
|
||||
setSuggestions(mInputMode.getSuggestions());
|
||||
|
||||
// flush the first suggestion immediately, if the InputMode has requested it
|
||||
if (mInputMode.getAutoAcceptTimeout() == 0) {
|
||||
onOK();
|
||||
// flush the first suggestion, if the InputMode has requested it
|
||||
if (scheduleAutoAccept(mInputMode.getAutoAcceptTimeout())) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -40,7 +40,7 @@ abstract public class InputMode {
|
|||
case MODE_PREDICTIVE:
|
||||
return new ModePredictive(settings, language);
|
||||
case MODE_ABC:
|
||||
return new ModeABC(language);
|
||||
return new ModeABC(settings, language);
|
||||
case MODE_DIALER:
|
||||
return new ModeDialer();
|
||||
default:
|
||||
|
|
|
|||
|
|
@ -3,13 +3,17 @@ package io.github.sspanak.tt9.ime.modes;
|
|||
import androidx.annotation.NonNull;
|
||||
|
||||
import io.github.sspanak.tt9.languages.Language;
|
||||
import io.github.sspanak.tt9.preferences.SettingsStore;
|
||||
|
||||
public class ModeABC extends InputMode {
|
||||
private final SettingsStore settings;
|
||||
|
||||
public int getId() { return MODE_ABC; }
|
||||
|
||||
private boolean shouldSelectNextLetter = false;
|
||||
|
||||
ModeABC(Language lang) {
|
||||
ModeABC(SettingsStore settings, Language lang) {
|
||||
this.settings = settings;
|
||||
changeLanguage(lang);
|
||||
}
|
||||
|
||||
|
|
@ -22,9 +26,11 @@ public class ModeABC extends InputMode {
|
|||
autoAcceptTimeout = 0;
|
||||
} else if (repeat > 0) {
|
||||
shouldSelectNextLetter = true;
|
||||
autoAcceptTimeout = settings.getAbcAutoAcceptTimeout();
|
||||
} else {
|
||||
reset();
|
||||
suggestions.addAll(language.getKeyCharacters(number));
|
||||
autoAcceptTimeout = settings.getAbcAutoAcceptTimeout();
|
||||
}
|
||||
|
||||
return true;
|
||||
|
|
|
|||
|
|
@ -208,6 +208,7 @@ public class SettingsStore {
|
|||
|
||||
/************* typing settings *************/
|
||||
|
||||
public int getAbcAutoAcceptTimeout() { return prefs.getBoolean("abc_auto_accept", true) ? 800 : -1; }
|
||||
public boolean getAutoSpace() { return prefs.getBoolean("auto_space", true); }
|
||||
public boolean getAutoTextCase() { return prefs.getBoolean("auto_text_case", true); }
|
||||
public String getDoubleZeroChar() {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue