1
0
Fork 0

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:
Dimo Karaivanov 2023-06-05 15:45:10 +03:00 committed by GitHub
parent 4405c0e34b
commit de964e8b0f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 90 additions and 7 deletions

View file

@ -23,6 +23,7 @@
<string name="dictionary_load_title">Зареди речник</string>
<string name="dictionary_not_found">Неуспешно зареждане. Липсва речник за „%1$s“.</string>
<string name="dictionary_truncated">Речникът е изтрит успешно.</string>
<string name="pref_category_abc_mode">Режим АБВ</string>
<string name="pref_category_appearance">Облик</string>
<string name="pref_category_function_keys">Бутони за бърз достъп</string>
<string name="pref_show_soft_function_keys">Бутони на екрана</string>
@ -43,6 +44,8 @@
<string name="key_hold_key">(задръж)</string>
<string name="dictionary_loading_indeterminate">Зареждане на речник</string>
<string name="dictionary_load_cancelled">Зареждането е отменено.</string>
<string name="pref_abc_auto_accept">Автоматичен избор на буква</string>
<string name="pref_abc_auto_accept_summary">Автоматично избирай текущата буква след кратко изчакване.</string>
<string name="pref_auto_space">Автоматичен интервал</string>
<string name="pref_auto_space_summary">Добавяй автоматично интервал след препинателни знаци и думи.</string>
<string name="pref_auto_text_case">Автоматични главни букви</string>

View file

@ -28,8 +28,11 @@
<string name="pref_category_keypad">Клавиатура</string>
<string name="char_space">Пробел</string>
<string name="char_newline">Новая строка</string>
<string name="pref_category_abc_mode">Режим AБВ</string>
<string name="pref_category_appearance">Внешний вид</string>
<string name="pref_category_function_keys">Горячие клавиши</string>
<string name="pref_abc_auto_accept">Автоматический выбор буквы</string>
<string name="pref_abc_auto_accept_summary">Автоматически ввести выбранную букву после короткого ожидания.</string>
<string name="pref_auto_space">Авто пробел</string>
<string name="pref_auto_space_summary">Автоматически добавлять пробел после слов и знаков препинания.</string>
<string name="pref_auto_text_case">Авто заглавные буквы</string>

View file

@ -26,9 +26,12 @@
<string name="pref_category_keypad">Клавіатура</string>
<string name="char_space">Пробіл</string>
<string name="char_newline">Новий рядок</string>
<string name="pref_category_abc_mode">Режим AБВ</string>
<string name="pref_category_appearance">Вигляд</string>
<string name="pref_category_predictive_mode">Режим підсказки</string>
<string name="pref_category_function_keys">Гарячі клавіші</string>
<string name="pref_abc_auto_accept">Автоматичний вибір букви</string>
<string name="pref_abc_auto_accept_summary">Автоматично ввести вибрану букву після короткої затримки.</string>
<string name="pref_auto_space">Авто пробіл</string>
<string name="pref_auto_space_summary">Автоматично додавати пробіл після слів і розділових знаків.</string>
<string name="pref_auto_text_case">Авто заголовні букви</string>

View file

@ -15,12 +15,16 @@
<string name="add_word_field_placeholder">Type a word…</string>
<string name="pref_category_about">About</string>
<string name="pref_category_abc_mode">ABC Mode</string>
<string name="pref_category_appearance">Appearance</string>
<string name="pref_category_predictive_mode">Predictive Mode</string>
<string name="pref_category_function_keys">Select Hotkeys</string>
<string name="pref_category_keypad">Keypad</string>
<string name="pref_category_setup">Initial Setup</string>
<string name="pref_abc_auto_accept">Automatic Letter Select</string>
<string name="pref_abc_auto_accept_summary">Automatically type the selected letter after a short delay.</string>
<string name="pref_auto_space">Automatic Space</string>
<string name="pref_auto_space_summary">Automatically add a space after punctuation or words.</string>
<string name="pref_auto_text_case">Automatic Capitalization</string>

View file

@ -45,4 +45,18 @@
</PreferenceCategory>
<PreferenceCategory
android:title="@string/pref_category_abc_mode"
app:layout="@layout/pref_category"
app:singleLineTitle="true">
<SwitchPreferenceCompat
app:defaultValue="true"
app:key="abc_auto_accept"
app:layout="@layout/pref_switch"
app:summary="@string/pref_abc_auto_accept_summary"
app:title="@string/pref_abc_auto_accept" />
</PreferenceCategory>
</PreferenceScreen>

View file

@ -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;
}

View file

@ -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:

View file

@ -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;

View file

@ -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() {