1
0
Fork 0

added a setting for 0-key double press function

This commit is contained in:
sspanak 2023-01-16 17:39:30 +02:00 committed by Dimo Karaivanov
parent 363f9611f7
commit 88797898d8
13 changed files with 107 additions and 5 deletions

View file

@ -50,4 +50,7 @@
<string name="pref_category_predictive_mode">Подсказващ режим</string>
<string name="dictionary_missing_go_load_it">Няма речник за език „%1$s“. Заредете го в Настройки.</string>
<string name="pref_category_keypad">Клавиатура</string>
<string name="pref_double_zero_char">Символ при двойно натисната \"0\"</string>
<string name="char_newline">Нов ред</string>
<string name="char_space">Интервал</string>
</resources>

View file

@ -22,4 +22,6 @@
<string name="dictionary_not_found">Wird nicht geladen. Wörterbuch für \"%1$s\" nicht gefunden.</string>
<string name="dictionary_loading_indeterminate">Lade Wörterbuch</string>
<string name="pref_category_keypad">Tastenfeld</string>
<string name="char_space">Leerzeichen</string>
<string name="char_newline">Neue Zeile</string>
</resources>

View file

@ -41,4 +41,6 @@
<string name="dictionary_missing_go_load_it">Pas de dictionnaire pour langue «%1$s». Veuillez le charger à l\'écran Paramètres.</string>
<string name="add_word_invalid_language">Impossible d\'ajouter un mot, si aucune langue n\'est choisie.</string>
<string name="pref_category_keypad">Clavier</string>
<string name="char_space">Espace</string>
<string name="char_newline">Nouvelle ligne</string>
</resources>

View file

@ -28,5 +28,7 @@
<string name="dictionary_loading_indeterminate">Caricamento del dizionario</string>
<string name="dictionary_load_cancelled">Caricamento annullato.</string>
<string name="pref_category_keypad">Tastiera</string>
<string name="char_space">Spazio</string>
<string name="char_newline">Nuova riga</string>
</resources>

View file

@ -22,4 +22,6 @@
<string name="dictionary_truncated">Woordenboek succesvol gewist.</string>
<string name="dictionary_loading_indeterminate">Woordenboek laden</string>
<string name="pref_category_keypad">Toetsenbord</string>
<string name="char_space">Spatie</string>
<string name="char_newline">Nieuwe regel</string>
</resources>

View file

@ -31,4 +31,6 @@
<string name="dictionary_load_cancelled">Загрузка отменена.</string>
<string name="pref_category_predictive_mode">Режим подсказки</string>
<string name="pref_category_keypad">Клавиатура</string>
<string name="char_space">Пробел</string>
<string name="char_newline">Новая строка</string>
</resources>

View file

@ -28,4 +28,6 @@
<string name="dictionary_loading_indeterminate">Завантаження словника</string>
<string name="dictionary_load_cancelled">Завантаження скасовано.</string>
<string name="pref_category_keypad">Клавіатура</string>
<string name="char_space">Пробіл</string>
<string name="char_newline">Новий рядок</string>
</resources>

View file

@ -27,7 +27,8 @@
<string name="pref_auto_text_case_summary">Automatically start sentences with a capital letter.</string>
<string name="pref_choose_languages">Languages</string>
<string name="pref_dark_theme">Dark Theme</string>
<string name="pref_show_soft_function_keys">Show on-screen keys</string>
<string name="pref_double_zero_char">Character for 0-key Double Press</string>
<string name="pref_show_soft_function_keys">Show On-Screen Keys</string>
<string name="pref_help">Help</string>
<string name="dictionary_cancel_load">Cancel loading</string>
@ -64,4 +65,8 @@
<string name="key_menu" translatable="false">Menu</string>
<string name="key_pound" translatable="false">#</string>
<string name="key_star" translatable="false"></string>
<string name="char_dot" translatable="false">.</string>
<string name="char_newline">New Line</string>
<string name="char_space">Space</string>
</resources>

View file

@ -76,6 +76,13 @@
app:summary="@string/pref_auto_text_case_summary"
app:title="@string/pref_auto_text_case" />
<DropDownPreference
app:defaultValue=" "
app:iconSpaceReserved="false"
app:key="pref_double_zero_char"
app:layout="@layout/pref_dropdown"
app:title="@string/pref_double_zero_char" />
</PreferenceCategory>
<PreferenceCategory

View file

@ -87,9 +87,9 @@ public class ModePredictive extends InputMode {
reset();
word = String.valueOf(key);
} else if (key == 0 && repeat > 0) {
// repeat "0" to type spaces
// repeat "0" is a shortcut for the preferred character (default: space)
reset();
word = " ";
word = settings.getDoubleZeroChar();
} else {
// words
super.reset();

View file

@ -208,6 +208,7 @@ public class SettingsStore {
public boolean getAutoSpace() { return prefs.getBoolean("auto_space", false); }
public boolean getAutoTextCase() { return prefs.getBoolean("auto_text_case", true); }
public String getDoubleZeroChar() { return prefs.getString("pref_double_zero_char", " "); }
/************* internal settings *************/

View file

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

View file

@ -6,6 +6,7 @@ import io.github.sspanak.tt9.BuildConfig;
import io.github.sspanak.tt9.R;
import io.github.sspanak.tt9.preferences.items.ItemLoadDictionary;
import io.github.sspanak.tt9.preferences.items.ItemSelectLanguage;
import io.github.sspanak.tt9.preferences.items.ItemSelectZeroKeyCharacter;
import io.github.sspanak.tt9.preferences.items.ItemToggleDarkTheme;
import io.github.sspanak.tt9.preferences.items.ItemTruncateDictionary;
import io.github.sspanak.tt9.preferences.PreferencesActivity;
@ -33,9 +34,10 @@ public class MainSettingsScreen extends BaseScreenFragment {
@Override
public void onCreate() {
createDictionarySection();
createAppearanceSection();
createAboutSection();
createAppearanceSection();
createDictionarySection();
createPredictiveModeSection();
}
@ -70,6 +72,11 @@ public class MainSettingsScreen extends BaseScreenFragment {
}
private void createPredictiveModeSection() {
(new ItemSelectZeroKeyCharacter(findPreference(ItemSelectZeroKeyCharacter.NAME), activity)).populate().activate();
}
private void createAboutSection() {
Preference vi = findPreference("version_info");
if (vi != null) {