1
0
Fork 0

ABC auto-accept time out is now adjustable

This commit is contained in:
sspanak 2024-04-05 15:40:46 +03:00 committed by Dimo Karaivanov
parent b0f15168f6
commit a09e6f65e7
23 changed files with 173 additions and 91 deletions

View file

@ -10,24 +10,31 @@ import io.github.sspanak.tt9.util.Logger;
public class ItemDropDown {
private final DropDownPreference item;
private LinkedHashMap<Integer, String> values;
private LinkedHashMap<String, String> values;
public ItemDropDown(DropDownPreference item) {
this.item = item;
}
protected void populate(LinkedHashMap<Integer, String> values) {
protected void populateIntegers(LinkedHashMap<Integer, String> values) {
LinkedHashMap<String, String> stringifiedValues = new LinkedHashMap<>();
if (values != null) {
for (Integer key : values.keySet()) {
stringifiedValues.put(String.valueOf(key), values.get(key));
}
}
populate(stringifiedValues);
}
protected void populate(LinkedHashMap<String, String> values) {
if (item == null) {
Logger.w("ItemDropDown.populate", "Cannot populate a NULL item. Ignoring.");
return;
}
this.values = values != null ? values : new LinkedHashMap<>();
ArrayList<String> keys = new ArrayList<>();
for (int key : this.values.keySet()) {
keys.add(String.valueOf(key));
}
ArrayList<String> keys = new ArrayList<>(this.values.keySet());
item.setEntryValues(keys.toArray(new CharSequence[0]));
item.setEntries(this.values.values().toArray(new CharSequence[0]));
@ -56,14 +63,11 @@ public class ItemDropDown {
}
protected boolean onClick(Preference preference, Object newKey) {
try {
String previewValue = values.get(Integer.parseInt(newKey.toString()));
String previewValue = values.get(newKey.toString());
((DropDownPreference) preference).setValue(newKey.toString());
setPreview(previewValue);
return true;
} catch (NumberFormatException e) {
return false;
}
}
private void setPreview(String value) {
@ -74,7 +78,7 @@ public class ItemDropDown {
public ItemDropDown preview() {
try {
setPreview(values.get(Integer.parseInt(item.getValue())));
setPreview(values.get(item.getValue()));
} catch (Exception e) {
setPreview("");
}

View file

@ -28,7 +28,7 @@ public class ItemSelectLayoutType extends ItemDropDown {
items.put(SettingsUI.LAYOUT_SMALL, context.getString(R.string.pref_layout_small));
items.put(SettingsUI.LAYOUT_NUMPAD, context.getString(R.string.pref_layout_numpad));
super.populate(items);
super.populateIntegers(items);
return this;
}

View file

@ -27,7 +27,7 @@ class ItemSelectTheme extends ItemDropDown {
themes.put(AppCompatDelegate.MODE_NIGHT_NO, context.getString(R.string.pref_dark_theme_no));
themes.put(AppCompatDelegate.MODE_NIGHT_YES, context.getString(R.string.pref_dark_theme_yes));
super.populate(themes);
super.populateIntegers(themes);
return this;
}

View file

@ -27,7 +27,7 @@ public class ItemInputHandlingMode extends ItemDropDown {
values.put(RETURN_FALSE, "Return False");
values.put(CALL_SUPER, "Call Super");
super.populate(values);
super.populateIntegers(values);
super.setValue(String.valueOf(settings.getInputHandlingMode()));
return this;

View file

@ -7,8 +7,8 @@ import androidx.preference.Preference;
import java.util.LinkedHashMap;
import io.github.sspanak.tt9.util.Logger;
import io.github.sspanak.tt9.preferences.items.ItemDropDown;
import io.github.sspanak.tt9.util.Logger;
class ItemLogLevel extends ItemDropDown {
public static final String NAME = "pref_log_level";
@ -18,12 +18,12 @@ class ItemLogLevel extends ItemDropDown {
}
public ItemLogLevel populate() {
LinkedHashMap<Integer, String> values = new LinkedHashMap<>();
values.put(Log.VERBOSE, "Verbose");
values.put(Log.DEBUG, "Debug");
values.put(Log.INFO, "Info");
values.put(Log.WARN, "Warning");
values.put(Log.ERROR, "Error (default)");
LinkedHashMap<String, String> values = new LinkedHashMap<>();
values.put(String.valueOf(Log.VERBOSE), "Verbose");
values.put(String.valueOf(Log.DEBUG), "Debug");
values.put(String.valueOf(Log.INFO), "Info");
values.put(String.valueOf(Log.WARN), "Warning");
values.put(String.valueOf(Log.ERROR), "Error (default)");
super.populate(values);
super.setValue(String.valueOf(Logger.LEVEL));

View file

@ -0,0 +1,34 @@
package io.github.sspanak.tt9.preferences.screens.keypad;
import android.content.Context;
import androidx.preference.DropDownPreference;
import java.util.LinkedHashMap;
import io.github.sspanak.tt9.R;
import io.github.sspanak.tt9.preferences.items.ItemDropDown;
public class ItemSelectABCAutoAccceptTime extends ItemDropDown {
public static final String NAME = "pref_abc_auto_accept_time";
private final Context context;
public ItemSelectABCAutoAccceptTime(DropDownPreference item, Context context) {
super(item);
this.context = context;
}
public ItemSelectABCAutoAccceptTime populate() {
LinkedHashMap<String, String> dropDownOptions = new LinkedHashMap<>();
dropDownOptions.put("-1", context.getString(R.string.pref_abc_auto_accept_off));
dropDownOptions.put("350", context.getString(R.string.pref_abc_auto_accept_fastest));
dropDownOptions.put("500", context.getString(R.string.pref_abc_auto_accept_fast));
dropDownOptions.put("800", context.getString(R.string.pref_abc_auto_accept_normal));
dropDownOptions.put("1200", context.getString(R.string.pref_abc_auto_accept_slow));
super.populate(dropDownOptions);
return this;
}
}

View file

@ -1,67 +1,32 @@
package io.github.sspanak.tt9.preferences.screens.keypad;
import android.content.Context;
import android.content.res.Resources;
import androidx.preference.DropDownPreference;
import java.util.LinkedHashMap;
import io.github.sspanak.tt9.util.Logger;
import io.github.sspanak.tt9.R;
import io.github.sspanak.tt9.preferences.items.ItemDropDown;
class ItemSelectZeroKeyCharacter {
class ItemSelectZeroKeyCharacter extends ItemDropDown {
public static final String NAME = "pref_double_zero_char";
private final DropDownPreference item;
private final LinkedHashMap<String, String> KEYS = new LinkedHashMap<>();
private final Context context;
ItemSelectZeroKeyCharacter(DropDownPreference dropDown, Context context) {
this.item = dropDown;
Resources resources = context.getResources();
KEYS.put(".", resources.getString(R.string.char_dot));
KEYS.put(",", resources.getString(R.string.char_comma));
KEYS.put("\\n", resources.getString(R.string.char_newline)); // SharedPreferences return a corrupted string when using the real "\n"... :(
KEYS.put(" ", resources.getString(R.string.char_space));
super(dropDown);
this.context = context;
}
public ItemSelectZeroKeyCharacter populate() {
if (item == null) {
Logger.w("ItemSelectZeroKeyChar.populate", "Cannot populate a NULL item. Ignoring.");
LinkedHashMap<String, String> items = new LinkedHashMap<>();
items.put(".", context.getString(R.string.char_dot));
items.put(",", context.getString(R.string.char_comma));
items.put("\\n", context.getString(R.string.char_newline)); // SharedPreferences return a corrupted string when using the real "\n"... :(
items.put(" ", context.getString(R.string.char_space));
super.populate(items);
return this;
}
item.setEntries(KEYS.values().toArray(new CharSequence[0]));
item.setEntryValues(KEYS.keySet().toArray(new CharSequence[0]));
previewSelection(item.getValue());
return this;
}
public void activate() {
if (item == null) {
Logger.w("ItemSelectZeroKeyChar.activate", "Cannot set a click listener a NULL item. Ignoring.");
return;
}
item.setOnPreferenceChangeListener((preference, newChar) -> {
((DropDownPreference) preference).setValue(newChar.toString());
previewSelection(newChar.toString());
return true;
});
}
private void previewSelection(String newChar) {
if (item == null) {
return;
}
item.setSummary(KEYS.get(newChar));
}
}

View file

@ -15,6 +15,14 @@ public class KeyPadScreen extends BaseScreenFragment {
@Override
protected void onCreate() {
(new ItemSelectZeroKeyCharacter(findPreference(ItemSelectZeroKeyCharacter.NAME), activity)).populate().activate();
(new ItemSelectZeroKeyCharacter(findPreference(ItemSelectZeroKeyCharacter.NAME), activity))
.populate()
.enableClickHandler()
.preview();
(new ItemSelectABCAutoAccceptTime(findPreference(ItemSelectABCAutoAccceptTime.NAME), activity))
.populate()
.enableClickHandler()
.preview();
}
}

View file

@ -20,11 +20,11 @@ class ItemKeyPadDebounceTime extends ItemDropDown {
}
public ItemDropDown populate() {
LinkedHashMap<Integer, String> dropDownOptions = new LinkedHashMap<>();
dropDownOptions.put(0, context.getString(R.string.pref_hack_key_pad_debounce_off));
LinkedHashMap<String, String> dropDownOptions = new LinkedHashMap<>();
dropDownOptions.put("0", context.getString(R.string.pref_hack_key_pad_debounce_off));
int[] values = new int[] { 20, 30, 50, 75, 100, 150, 250, 350 };
for (int value : values) {
String[] values = new String[] { "20", "30", "50", "75", "100", "150", "250", "350" };
for (String value : values) {
dropDownOptions.put(value, value + " ms");
}
super.populate(dropDownOptions);

View file

@ -5,7 +5,16 @@ import android.content.Context;
class SettingsTyping extends SettingsInput {
SettingsTyping(Context context) { super(context); }
public int getAbcAutoAcceptTimeout() { return prefs.getBoolean("abc_auto_accept", true) ? 800 + getKeyPadDebounceTime() : -1; }
public int getAbcAutoAcceptTimeout() {
int time;
try {
time = Integer.parseInt(prefs.getString("pref_abc_auto_accept_time", "800"));
} catch (NumberFormatException e) {
time = 800;
}
return time > 0 ? time + getKeyPadDebounceTime() : time;
}
public boolean getAutoSpace() { return prefs.getBoolean("auto_space", true); }
public boolean getAutoTextCase() { return prefs.getBoolean("auto_text_case", true); }
public String getDoubleZeroChar() {

View file

@ -80,7 +80,11 @@
<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_abc_auto_accept_off">Изключен</string>
<string name="pref_abc_auto_accept_fastest">Много бърз</string>
<string name="pref_abc_auto_accept_fast">Бърз</string>
<string name="pref_abc_auto_accept_normal">Умерен</string>
<string name="pref_abc_auto_accept_slow">Бавен</string>
<string name="pref_alternative_suggestion_scrolling">Алтернативен метод за превъртане на думи</string>
<string name="pref_alternative_suggestion_scrolling_summary">Включете, ако понякога не виждате целия списък с думи или не може да стигнете до всички (Андроид 9 или по-стари)</string>
<string name="pref_auto_space">Автоматичен интервал</string>

View file

@ -21,6 +21,12 @@
<string name="pref_layout_tray">Nur Wortliste</string>
<string name="pref_help">Hilfe</string>
<string name="pref_dark_theme">Dunkles Thema</string>
<string name="pref_abc_auto_accept">Automatische Buchstabenauswahl</string>
<string name="pref_abc_auto_accept_off">Aus</string>
<string name="pref_abc_auto_accept_fastest">Sehr schnell</string>
<string name="pref_abc_auto_accept_fast">Schnell</string>
<string name="pref_abc_auto_accept_normal">Mäßig</string>
<string name="pref_abc_auto_accept_slow">Langsam</string>
<string name="pref_choose_languages">Sprachen</string>
<string name="pref_status_icon">Icon für den Schreibmodus</string>
@ -32,6 +38,7 @@
<string name="dictionary_loading_please_wait">Bitte warten Sie, bis das Wörterbuch geladen ist.</string>
<string name="dictionary_load_title">Ausgewählte laden</string>
<string name="dictionary_not_found">Wird nicht geladen. Wörterbuch für \"%1$s\" nicht gefunden.</string>
<string name="pref_category_abc_mode">ABC-Modus</string>
<string name="pref_category_custom_words">Hinzugefügte Wörter</string>
<string name="pref_category_delete_words">Hinzugefügte Wörter löschen</string>
<string name="pref_category_hacks">Kompatibilität</string>

View file

@ -50,7 +50,11 @@
<string name="pref_auto_text_case">Mayúsculas automáticas</string>
<string name="pref_auto_text_case_summary">Escribir la primera letra de cada frase en mayúscula.</string>
<string name="pref_abc_auto_accept">Selección automática de letra</string>
<string name="pref_abc_auto_accept_summary">Escribir automáticamente la letra seleccionada después de una breve pausa.</string>
<string name="pref_abc_auto_accept_off">Apagada</string>
<string name="pref_abc_auto_accept_fastest">Muy rápido</string>
<string name="pref_abc_auto_accept_fast">Rápido</string>
<string name="pref_abc_auto_accept_normal">Moderado</string>
<string name="pref_abc_auto_accept_slow">Lento</string>
<string name="pref_auto_space">Espacio automático</string>
<string name="pref_auto_space_summary">Insertar un espacio automático después de palabras y signos de puntuación.</string>
<string name="pref_double_zero_char">Carácter cuando se presiona \"0\" dos veces</string>

View file

@ -44,7 +44,11 @@
<string name="dictionary_load_cancelled">Chargement est annulé.</string>
<string name="pref_category_predictive_mode">Saisie intuitive</string>
<string name="pref_abc_auto_accept">Sélection de lettre automatique</string>
<string name="pref_abc_auto_accept_summary">Ajouter automatiquement la lettre sélectionnée après un court délai.</string>
<string name="pref_abc_auto_accept_off">Désactivée</string>
<string name="pref_abc_auto_accept_fastest">Très rapide</string>
<string name="pref_abc_auto_accept_fast">Rapide</string>
<string name="pref_abc_auto_accept_normal">Modérée</string>
<string name="pref_abc_auto_accept_slow">Lente</string>
<string name="pref_alternative_suggestion_scrolling">Méthode alternative de défilement des mots</string>
<string name="pref_auto_space">Espace automatique</string>
<string name="pref_auto_text_case">Majuscules automatiques</string>

View file

@ -22,6 +22,12 @@
<string name="pref_layout_tray">Solo elenco delle parole</string>
<string name="pref_help">Aiuto</string>
<string name="pref_dark_theme">Tema scuro</string>
<string name="pref_abc_auto_accept">Selezione automatica delle lettere</string>
<string name="pref_abc_auto_accept_off">Spenta</string>
<string name="pref_abc_auto_accept_fastest">Molto veloce</string>
<string name="pref_abc_auto_accept_fast">Veloce</string>
<string name="pref_abc_auto_accept_normal">Moderata</string>
<string name="pref_abc_auto_accept_slow">Lenta</string>
<string name="pref_choose_languages">Lingue</string>
<string name="pref_status_icon">Icona modalità di digitazione</string>
@ -32,6 +38,7 @@
<string name="dictionary_loading_please_wait">Attendi che il dizionario si carichi, per favore.</string>
<string name="dictionary_load_title">Carica le selezionate</string>
<string name="dictionary_not_found">Impossibile caricare. Dizionario per “%1$s” non trovato.</string>
<string name="pref_category_abc_mode">Modalità ABC</string>
<string name="pref_category_custom_words">Parole aggiunte</string>
<string name="pref_category_delete_words">Elimina parole aggiunte</string>
<string name="pref_category_hacks">Compatibilità</string>

View file

@ -16,6 +16,7 @@
<string name="add_word_title">הוסף מילה</string>
<string name="pref_category_about">אודות</string>
<string name="pref_category_abc_mode">מצב אבג</string>
<string name="pref_category_custom_words">מילים שהוספו</string>
<string name="pref_category_delete_words">מחק מילים שהוספו</string>
<string name="pref_category_hacks">הגדרות תאימות</string>
@ -24,6 +25,12 @@
<string name="pref_category_function_keys">בחר מקשי קיצור</string>
<string name="pref_category_keypad">מקלדת</string>
<string name="pref_abc_auto_accept">בחירת אותיות אוטומטית</string>
<string name="pref_abc_auto_accept_off">כבויה</string>
<string name="pref_abc_auto_accept_fastest">מאוד מהיר</string>
<string name="pref_abc_auto_accept_fast">מהיר</string>
<string name="pref_abc_auto_accept_normal">בינוני</string>
<string name="pref_abc_auto_accept_slow">איטי</string>
<string name="pref_auto_space">רווח אוטומטי</string>
<string name="pref_auto_space_summary">הוסף רווח אוטומטית לאחר סימני פיסוק או מילים.</string>
<string name="pref_auto_text_case">שימוש אוטומטי באותיות רישיות</string>

View file

@ -27,7 +27,11 @@
<string name="pref_category_setup">Pradiniai nustatymai</string>
<string name="pref_abc_auto_accept">Automatinis raidės pasirinkimas</string>
<string name="pref_abc_auto_accept_summary">Automatiškai įterpti pasirinktą raidę po trumpos delsos.</string>
<string name="pref_abc_auto_accept_off">Išjungtas</string>
<string name="pref_abc_auto_accept_fastest">Labai greitas</string>
<string name="pref_abc_auto_accept_fast">Greitas</string>
<string name="pref_abc_auto_accept_normal">Vidutinis</string>
<string name="pref_abc_auto_accept_slow">Lėtas</string>
<string name="pref_alternative_suggestion_scrolling">Alternatyvus slinkimo būdas per pasiūlytus žodžius</string>
<string name="pref_alternative_suggestion_scrolling_summary">Įjunkite, jei kartais nematote viso žodžių sąrašo arba kyla problemų juos pasirenkant („Android“ 9 ar senesnės versijos).</string>
<string name="pref_auto_space">Automatinis tarpas</string>

View file

@ -20,6 +20,12 @@
<string name="pref_layout_tray">Alleen suggestielijst</string>
<string name="pref_help">Helpen</string>
<string name="pref_dark_theme">Donker thema</string>
<string name="pref_abc_auto_accept">Automatische letterselectie</string>
<string name="pref_abc_auto_accept_off">Uit</string>
<string name="pref_abc_auto_accept_fastest">Zeer snel</string>
<string name="pref_abc_auto_accept_fast">Snel</string>
<string name="pref_abc_auto_accept_normal">Gematigd</string>
<string name="pref_abc_auto_accept_slow">Langzaam</string>
<string name="pref_choose_languages">Talen</string>
<string name="pref_status_icon">Typemodus-icoon</string>
<string name="pref_status_icon_summary">Geef de huidige typmodus aan met een icoon.</string>
@ -33,6 +39,7 @@
<string name="dictionary_truncate_title">Verwijder alle</string>
<string name="dictionary_truncate_unselected">Verwijder de niet-geselecteerde</string>
<string name="dictionary_truncated">Woordenboek succesvol gewist.</string>
<string name="pref_category_abc_mode">ABC-modus</string>
<string name="pref_category_custom_words">Toegevoegde woorden</string>
<string name="pref_category_delete_words">Verwijder toegevoegde woorden</string>
<string name="pref_category_hacks">Compatibiliteit</string>

View file

@ -16,6 +16,7 @@
<string name="add_word_title">Adicionar Palavra</string>
<string name="pref_category_about">Sobre</string>
<string name="pref_category_abc_mode">Modo ABC</string>
<string name="pref_category_custom_words">Palavras adicionadas</string>
<string name="pref_category_delete_words">Excluir palavras adicionadas</string>
<string name="pref_category_hacks">Compatibilidade</string>
@ -25,6 +26,12 @@
<string name="pref_category_keypad">Teclado</string>
<string name="pref_category_setup">Configuração inicial</string>
<string name="pref_abc_auto_accept">Seleção automática de letras</string>
<string name="pref_abc_auto_accept_off">Desligada</string>
<string name="pref_abc_auto_accept_fastest">Muito rápido</string>
<string name="pref_abc_auto_accept_fast">Rápido</string>
<string name="pref_abc_auto_accept_normal">Moderado</string>
<string name="pref_abc_auto_accept_slow">Lento</string>
<string name="pref_auto_space">Espaçamento Automático</string>
<string name="pref_auto_space_summary">Insere um espaçamento após ponto final.</string>
<string name="pref_auto_text_case">Maiúsculas Automáticas</string>

View file

@ -44,7 +44,11 @@
<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_abc_auto_accept_off">Выключено</string>
<string name="pref_abc_auto_accept_fastest">Очень быстро</string>
<string name="pref_abc_auto_accept_fast">Быстро</string>
<string name="pref_abc_auto_accept_normal">Умеренное</string>
<string name="pref_abc_auto_accept_slow">Медленное</string>
<string name="pref_alternative_suggestion_scrolling">Альтернативный метод прокрутки слов</string>
<string name="pref_alternative_suggestion_scrolling_summary">Включите, если иногда вы не видите все слова или у вас возникают проблемы с их прокруткой (Android 9 или старше).</string>
<string name="pref_auto_space">Авто пробел</string>

View file

@ -29,7 +29,11 @@
<string name="pref_category_setup">Початкові налаштування</string>
<string name="pref_abc_auto_accept">Автоматичний вибір літери</string>
<string name="pref_abc_auto_accept_summary">Автоматично вводить вибрану літеру після короткої затримки.</string>
<string name="pref_abc_auto_accept_off">Вимкнено</string>
<string name="pref_abc_auto_accept_fastest">Дуже швидко</string>
<string name="pref_abc_auto_accept_fast">Швидко</string>
<string name="pref_abc_auto_accept_normal">Середній</string>
<string name="pref_abc_auto_accept_slow">Повільний</string>
<string name="pref_alternative_suggestion_scrolling">Альтернативний метод прокрутки пропозицій</string>
<string name="pref_alternative_suggestion_scrolling_summary">Увімкніть, якщо ви іноді не бачите всіх пропозицій або не можете їх прокрутити (Android 9 або старіші).</string>
<string name="pref_auto_space">Автоматичний пробіл</string>

View file

@ -34,8 +34,12 @@
<string name="pref_category_setup">Initial Setup</string>
<string name="pref_category_usage_stats" translatable="false">Usage Stats</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_abc_auto_accept">Automatic Letter Selection</string>
<string name="pref_abc_auto_accept_off">Off</string>
<string name="pref_abc_auto_accept_fastest">Very Quick</string>
<string name="pref_abc_auto_accept_fast">Quick</string>
<string name="pref_abc_auto_accept_normal">Moderate</string>
<string name="pref_abc_auto_accept_slow">Slow</string>
<string name="pref_alternative_suggestion_scrolling">Alternative Suggestion Scrolling Method</string>
<string name="pref_alternative_suggestion_scrolling_summary">Enable if sometimes you can not see all suggestions or have trouble scrolling them (Android 9 or older).</string>
<string name="pref_auto_space">Automatic Space</string>

View file

@ -51,11 +51,10 @@
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"
<DropDownPreference
app:defaultValue="800"
app:key="pref_abc_auto_accept_time"
app:layout="@layout/pref_dropdown"
app:title="@string/pref_abc_auto_accept" />
</PreferenceCategory>