1
0
Fork 0

Fixed the text size on the Settings screen (#132)

* readjusted the font size of the suggestions and on the Settings screen

* moved the keypad shortcuts to a separate screen

* added bold+italic visual hint when fuzzy word filtering is on

* updated documentation
This commit is contained in:
Dimo Karaivanov 2023-01-16 15:14:25 +02:00 committed by GitHub
parent 6d1420dd09
commit 9ee31005b5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
35 changed files with 495 additions and 189 deletions

View file

@ -33,3 +33,6 @@ As with many other open-source projects, this one is also maintained by its auth
- [Silver foil photo created by rawpixel.com - www.freepik.com](https://www.freepik.com/photos/silver-foil)
- "Roboto" font is under [Apache License, Version 2.0](https://www.apache.org/licenses/LICENSE-2.0).
- "Negotiate" and "Vibrocentric" fonts are under [The Fontspring Desktop/Ebook Font End User License](docs/desktop-ebook-EULA-1.8.txt).
## Privacy Policy
Traditional T9 does not collect any information about you or about the way you are using using the application.

View file

@ -1,7 +1,7 @@
# Traditional T9
TT9 is an IME (Input Method Editor) for Android devices with hardware keypad. It supports multiple languages and predictive text typing. _NOTE: TT9 is not usable on touchscreen-only devices._
All Source code and documentation are available on Github: [https://github.com/sspanak/tt9](https://github.com/sspanak/tt9).
All source code, documentation and the privacy policy are available on Github: [https://github.com/sspanak/tt9](https://github.com/sspanak/tt9).
## Initial Setup
After installing, in order to use Traditional T9, you need to enable it as an Android keyboard. To do so:
@ -41,6 +41,8 @@ _Predictive mode only._
Filtering can also be used to type unknown words. Let's say you want to type "Anakin", which is not in the dictionary. Start with "A", then press Right to hide "B" and "C". Now press 6-key. Since the filter is on, in addition to the real dictionary words, it will provide all possible combinations for 6: "Am", "An", "Ao". Select "An" and press Right to confirm your selection. Now pressing 2-key, will provide "Ana", "Anb", "Anc". You can keep going, until you complete "Anakin".
When filtering is enabled, the base text will become bold and italicized.
#### D-pad Left (←):
_Predictive mode only._
@ -102,13 +104,4 @@ On the Settings screen, you can choose languages for typing, configure the keypa
To access it:
- Start typing in a text field to wake up TT9.
- Use the on-screen gear button or press the Settings Key.
## License
- The source code, the logo image and the icons are licensed under [Apache License, Version 2.0](https://www.apache.org/licenses/LICENSE-2.0).
- The dictionaries are licensed under the licenses provided in the [respective readme files](dictionaries/), where applicable. Detailed information about the dictionaries is also available there.
- [Silver foil photo created by rawpixel.com - www.freepik.com](https://www.freepik.com/photos/silver-foil)
- "Roboto" font is under [Apache License, Version 2.0](https://www.apache.org/licenses/LICENSE-2.0).
- "Negotiate" and "Vibrocentric" fonts are under [The Fontspring Desktop/Ebook Font End User License](desktop-ebook-EULA-1.8.txt).
## Privacy Policy
Traditional T9 does not collect any information about you or about the way you are using using the application.
-

View file

@ -0,0 +1,17 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingHorizontal="@dimen/pref_padding_horizontal"
android:paddingTop="@dimen/pref_category_padding_top"
android:paddingBottom="@dimen/pref_category_padding_bottom">
<TextView
android:id="@android:id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="@style/TextAppearance.AppCompat.Title"
android:textColor="?attr/colorAccent"
android:textSize="@dimen/pref_text_size" />
</LinearLayout>

View file

@ -0,0 +1,37 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:baselineAligned="false"
android:orientation="horizontal"
android:paddingHorizontal="@dimen/pref_padding_horizontal"
android:paddingVertical="@dimen/pref_padding_vertical">
<androidx.appcompat.widget.AppCompatSpinner
android:id="@+id/spinner"
android:layout_width="0dp"
android:layout_height="match_parent" />
<LinearLayout
android:layout_width="0px"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="start|center_vertical"
android:orientation="vertical">
<TextView
android:id="@android:id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="@android:style/TextAppearance.DeviceDefault.Widget.TextView"
android:textSize="@dimen/pref_text_size" />
<TextView
android:id="@android:id/summary"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="@style/TextAppearance.AppCompat.Caption"
android:textSize="@dimen/pref_summary_size" />
</LinearLayout>
</LinearLayout>

View file

@ -0,0 +1,41 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<LinearLayout
android:layout_width="0px"
android:layout_height="wrap_content"
android:layout_weight="3"
android:gravity="start|center_vertical"
android:orientation="vertical"
android:paddingStart="@dimen/pref_padding_horizontal"
android:paddingTop="@dimen/pref_padding_vertical"
android:paddingEnd="4dp"
android:paddingBottom="@dimen/pref_padding_vertical">
<TextView
android:id="@android:id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="@android:style/TextAppearance.DeviceDefault.Widget.TextView"
android:textSize="@dimen/pref_text_size" />
<TextView
android:id="@android:id/summary"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="@style/TextAppearance.AppCompat.Caption"
android:textSize="@dimen/pref_summary_size" />
</LinearLayout>
<androidx.appcompat.widget.SwitchCompat
android:id="@+id/switchWidget"
android:layout_width="0px"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="end|center_vertical"
android:paddingStart="2dp"
android:paddingEnd="@dimen/pref_padding_horizontal" />
</LinearLayout>

20
res/layout/pref_text.xml Normal file
View file

@ -0,0 +1,20 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingHorizontal="@dimen/pref_padding_horizontal"
android:paddingVertical="@dimen/pref_padding_vertical">
<TextView android:id="@android:id/title"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:textAppearance="@android:style/TextAppearance.DeviceDefault.Widget.TextView"
android:textSize="@dimen/pref_text_size" />
<TextView android:id="@android:id/summary"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:textAppearance="@style/TextAppearance.AppCompat.Caption"
android:textSize="@dimen/pref_summary_size" />
</LinearLayout>

View file

@ -5,5 +5,5 @@
android:id="@+id/preferences_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
tools:context=".preferences.PreferencesFragment">
tools:context=".preferences.screens.MainSettingsScreen">
</FrameLayout>

View file

@ -49,4 +49,5 @@
<string name="pref_auto_text_case_summary">Започвай автоматично изреченията с главни букви.</string>
<string name="pref_category_predictive_mode">Подсказващ режим</string>
<string name="dictionary_missing_go_load_it">Няма речник за език „%1$s“. Заредете го в Настройки.</string>
<string name="pref_category_keypad">Клавиатура</string>
</resources>

View file

@ -21,4 +21,5 @@
<string name="dictionary_load_title">Wörterbuch laden</string>
<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>
</resources>

View file

@ -40,4 +40,5 @@
<string name="pref_auto_text_case_summary">Commencer automatiquement les phrases avec une majuscule.</string>
<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>
</resources>

View file

@ -27,5 +27,6 @@
<string name="pref_category_function_keys">Scorciatoie da tastiera</string>
<string name="dictionary_loading_indeterminate">Caricamento del dizionario</string>
<string name="dictionary_load_cancelled">Caricamento annullato.</string>
<string name="pref_category_keypad">Tastiera</string>
</resources>

View file

@ -21,4 +21,5 @@
<string name="dictionary_not_found">Laden mislukt. Woordenboek voor %1$s niet gevonden.</string>
<string name="dictionary_truncated">Woordenboek succesvol gewist.</string>
<string name="dictionary_loading_indeterminate">Woordenboek laden</string>
<string name="pref_category_keypad">Toetsenbord</string>
</resources>

View file

@ -30,4 +30,5 @@
<string name="dictionary_loading_indeterminate">Загрузка словаря</string>
<string name="dictionary_load_cancelled">Загрузка отменена.</string>
<string name="pref_category_predictive_mode">Режим подсказки</string>
<string name="pref_category_keypad">Клавиатура</string>
</resources>

View file

@ -27,4 +27,5 @@
<string name="dictionary_not_found">Помилка завантаження. Словник «%1$s» не знайдено.</string>
<string name="dictionary_loading_indeterminate">Завантаження словника</string>
<string name="dictionary_load_cancelled">Завантаження скасовано.</string>
<string name="pref_category_keypad">Клавіатура</string>
</resources>

View file

@ -1,10 +1,17 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<dimen name="candidate_list_height">25sp</dimen>
<dimen name="candidate_font_size">17sp</dimen>
<dimen name="candidate_list_height">26sp</dimen>
<dimen name="candidate_font_size">18sp</dimen>
<dimen name="candidate_padding_horizontal">6sp</dimen>
<dimen name="candidate_padding_vertical">1sp</dimen>
<dimen name="soft_key_height">44dp</dimen>
<dimen name="soft_key_icon_size">24sp</dimen>
<dimen name="pref_category_padding_top">30dp</dimen>
<dimen name="pref_category_padding_bottom">12dp</dimen>
<dimen name="pref_padding_horizontal">16dp</dimen>
<dimen name="pref_padding_vertical">18dp</dimen>
<dimen name="pref_text_size">22sp</dimen>
<dimen name="pref_summary_size">19sp</dimen>
</resources>

View file

@ -19,6 +19,7 @@
<string name="pref_category_dictionaries">Dictionaries</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_auto_space">Automatic Space</string>
<string name="pref_auto_space_summary">Automatically add a space after punctuation or words.</string>

View file

@ -1,12 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
app:layout="@layout/pref_text"
app:orderingFromXml="true">
<Preference
app:iconSpaceReserved="false"
app:key="help"
app:layout="@layout/pref_text"
app:summary="github.com/sspanak/tt9"
app:title="@string/pref_help">
<intent
@ -17,19 +18,19 @@
<PreferenceCategory
android:title="@string/pref_category_appearance"
app:iconSpaceReserved="false"
app:layout="@layout/pref_category"
app:singleLineTitle="true">
<SwitchPreferenceCompat
app:defaultValue="true"
app:iconSpaceReserved="false"
app:key="pref_dark_theme"
app:layout="@layout/pref_switch"
app:title="@string/pref_dark_theme" />
<SwitchPreferenceCompat
app:defaultValue="true"
app:iconSpaceReserved="false"
app:key="pref_show_soft_keys"
app:layout="@layout/pref_switch"
app:title="@string/pref_show_soft_function_keys" />
</PreferenceCategory>
@ -37,92 +38,63 @@
<PreferenceCategory
android:title="@string/pref_category_dictionaries"
app:iconSpaceReserved="false"
app:layout="@layout/pref_category"
app:singleLineTitle="true">
<MultiSelectListPreference
app:iconSpaceReserved="false"
app:key="pref_languages"
app:layout="@layout/pref_text"
app:title="@string/pref_choose_languages" />
<Preference
app:iconSpaceReserved="false"
app:key="dictionary_load"
app:layout="@layout/pref_text"
app:title="@string/dictionary_load_title" />
<Preference
app:iconSpaceReserved="false"
app:key="dictionary_truncate"
app:layout="@layout/pref_text"
app:title="@string/dictionary_truncate_title" />
</PreferenceCategory>
<PreferenceCategory
android:title="@string/pref_category_predictive_mode"
app:iconSpaceReserved="false"
app:layout="@layout/pref_category"
app:singleLineTitle="true">
<SwitchPreferenceCompat
app:iconSpaceReserved="false"
app:key="auto_space"
app:layout="@layout/pref_switch"
app:title="@string/pref_auto_space"
app:summary="@string/pref_auto_space_summary" />
<SwitchPreferenceCompat
app:defaultValue="true"
app:iconSpaceReserved="false"
app:key="auto_text_case"
app:layout="@layout/pref_switch"
app:summary="@string/pref_auto_text_case_summary"
app:title="@string/pref_auto_text_case" />
</PreferenceCategory>
<PreferenceCategory
android:title="@string/pref_category_function_keys"
app:iconSpaceReserved="false"
app:singleLineTitle="true">
<DropDownPreference
app:iconSpaceReserved="false"
app:key="key_add_word"
app:title="@string/function_add_word_key" />
<DropDownPreference
app:iconSpaceReserved="false"
app:key="key_backspace"
app:title="@string/function_backspace_key" />
<DropDownPreference
app:iconSpaceReserved="false"
app:key="key_next_language"
app:title="@string/function_next_language_key" />
<DropDownPreference
app:iconSpaceReserved="false"
app:key="key_next_input_mode"
app:title="@string/function_next_mode_key" />
<DropDownPreference
app:iconSpaceReserved="false"
app:key="key_show_settings"
app:title="@string/function_show_settings_key" />
android:title="@string/pref_category_keypad"
app:layout="@layout/pref_category">
<Preference
app:iconSpaceReserved="false"
app:key="reset_keys"
app:title="@string/function_reset_keys_title" />
app:fragment="io.github.sspanak.tt9.preferences.PreferencesHotkeysFragment"
app:key="screen_hotkeys"
app:layout="@layout/pref_text"
app:title="@string/pref_category_function_keys" />
</PreferenceCategory>
<PreferenceCategory
android:title="@string/pref_category_about"
app:iconSpaceReserved="false"
app:layout="@layout/pref_category"
app:singleLineTitle="true">
<Preference
app:iconSpaceReserved="false"
app:key="version_info"
app:layout="@layout/pref_text"
app:title="@string/app_name" />
</PreferenceCategory>

View file

@ -0,0 +1,41 @@
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:app="http://schemas.android.com/apk/res-auto"
app:orderingFromXml="true">
<DropDownPreference
app:iconSpaceReserved="false"
app:key="key_add_word"
app:layout="@layout/pref_dropdown"
app:title="@string/function_add_word_key" />
<DropDownPreference
app:iconSpaceReserved="false"
app:key="key_backspace"
app:layout="@layout/pref_dropdown"
app:title="@string/function_backspace_key" />
<DropDownPreference
app:iconSpaceReserved="false"
app:key="key_next_language"
app:layout="@layout/pref_dropdown"
app:title="@string/function_next_language_key" />
<DropDownPreference
app:iconSpaceReserved="false"
app:key="key_next_input_mode"
app:layout="@layout/pref_dropdown"
app:title="@string/function_next_mode_key" />
<DropDownPreference
app:iconSpaceReserved="false"
app:key="key_show_settings"
app:layout="@layout/pref_dropdown"
app:title="@string/function_show_settings_key" />
<Preference
app:iconSpaceReserved="false"
app:key="reset_keys"
app:layout="@layout/pref_text"
app:title="@string/function_reset_keys_title" />
</PreferenceScreen>

View file

@ -9,7 +9,7 @@ import android.text.style.UnderlineSpan;
import io.github.sspanak.tt9.Logger;
public class TextHelper {
public static CharSequence highlightComposingText(CharSequence word, int start, int end) {
public static CharSequence highlightComposingText(CharSequence word, int start, int end, boolean highlightMore) {
if (end < start || start < 0) {
Logger.w("tt9.util.highlightComposingText", "Cannot highlight invalid composing text range: [" + start + ", " + end + "]");
return word;
@ -28,6 +28,15 @@ public class TextHelper {
Spannable.SPAN_EXCLUSIVE_EXCLUSIVE
);
if (highlightMore) {
styledWord.setSpan(
new StyleSpan(Typeface.BOLD_ITALIC),
start,
Math.min(word.length(), end),
Spannable.SPAN_EXCLUSIVE_EXCLUSIVE
);
}
return styledWord;
}
}

View file

@ -441,7 +441,7 @@ public class TraditionalT9 extends KeyPadHandler {
private void setComposingTextWithWordStemIndication(CharSequence word) {
if (mInputMode.getWordStem().length() > 0) {
setComposingText(TextHelper.highlightComposingText(word, 0, mInputMode.getWordStem().length()));
setComposingText(TextHelper.highlightComposingText(word, 0, mInputMode.getWordStem().length(), mInputMode.isStemFilterFuzzy()));
} else {
setComposingText(word);
}

View file

@ -115,6 +115,7 @@ abstract public class InputMode {
// Stem filtering.
// Where applicable, return "true" if the mode supports it and the operation was possible.
public boolean clearWordStem() { return false; }
public boolean isStemFilterFuzzy() { return false; }
public String getWordStem() { return ""; }
public boolean setWordStem(Language language, String stem, boolean exact) { return false; }

View file

@ -275,6 +275,15 @@ public class ModePredictive extends InputMode {
}
/**
* isStemFilterFuzzy
* Returns how strict the stem filter is.
*/
@Override
public boolean isStemFilterFuzzy() {
return isStemFuzzy;
}
/**
* loadStaticSuggestions
* Similar to "loadSuggestions()", but loads suggestions that are not in the database.

View file

@ -2,16 +2,24 @@ package io.github.sspanak.tt9.preferences;
import android.os.Bundle;
import androidx.annotation.NonNull;
import androidx.appcompat.app.ActionBar;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.app.AppCompatDelegate;
import androidx.fragment.app.Fragment;
import androidx.preference.Preference;
import androidx.preference.PreferenceFragmentCompat;
import io.github.sspanak.tt9.R;
import io.github.sspanak.tt9.db.DictionaryDb;
import io.github.sspanak.tt9.db.DictionaryLoader;
import io.github.sspanak.tt9.preferences.screens.MainSettingsScreen;
import io.github.sspanak.tt9.preferences.screens.HotkeysScreen;
import io.github.sspanak.tt9.ui.DictionaryLoadingBar;
public class PreferencesActivity extends AppCompatActivity {
SettingsStore settings;
public class PreferencesActivity extends AppCompatActivity implements PreferenceFragmentCompat.OnPreferenceStartFragmentCallback {
public SettingsStore settings;
@Override
protected void onCreate(Bundle savedInstanceState) {
@ -26,6 +34,27 @@ public class PreferencesActivity extends AppCompatActivity {
}
@Override
public boolean onPreferenceStartFragment(@NonNull PreferenceFragmentCompat caller, @NonNull Preference pref) {
// instantiate the new Fragment
Fragment fragment;
if (pref.getFragment() != null && pref.getFragment().contains("Hotkeys")) {
fragment = new HotkeysScreen(this);
} else {
fragment = new MainSettingsScreen(this);
}
fragment.setArguments(pref.getExtras());
// replace the existing Fragment with the new Fragment
getSupportFragmentManager().beginTransaction()
.replace(R.id.preferences_container, fragment)
.addToBackStack(null)
.commit();
return true;
}
private void applyTheme() {
AppCompatDelegate.setDefaultNightMode(
settings.getDarkTheme() ? AppCompatDelegate.MODE_NIGHT_YES : AppCompatDelegate.MODE_NIGHT_NO
@ -34,14 +63,29 @@ public class PreferencesActivity extends AppCompatActivity {
private void buildScreen() {
ActionBar actionBar = getSupportActionBar();
if (actionBar != null) {
actionBar.setDisplayShowHomeEnabled(true);
actionBar.setDisplayHomeAsUpEnabled(true); // hide the "back" button, if visible
}
setContentView(R.layout.preferences_container);
getSupportFragmentManager()
.beginTransaction()
.replace(R.id.preferences_container, new PreferencesFragment(this))
.replace(R.id.preferences_container, new MainSettingsScreen(this))
.commit();
}
public void setScreenTitle(int title) {
// set the title
ActionBar actionBar = getSupportActionBar();
if (actionBar != null) {
actionBar.setTitle(title);
}
}
private void validateFunctionKeys() {
if (!settings.areFunctionKeysSet()) {
settings.setDefaultKeys();
@ -49,12 +93,12 @@ public class PreferencesActivity extends AppCompatActivity {
}
DictionaryLoadingBar getDictionaryProgressBar() {
public DictionaryLoadingBar getDictionaryProgressBar() {
return DictionaryLoadingBar.getInstance(this);
}
DictionaryLoader getDictionaryLoader() {
public DictionaryLoader getDictionaryLoader() {
return DictionaryLoader.getInstance(this);
}
}

View file

@ -1,108 +0,0 @@
package io.github.sspanak.tt9.preferences;
import android.os.Bundle;
import androidx.preference.DropDownPreference;
import androidx.preference.Preference;
import androidx.preference.PreferenceFragmentCompat;
import java.util.Arrays;
import io.github.sspanak.tt9.BuildConfig;
import io.github.sspanak.tt9.Logger;
import io.github.sspanak.tt9.R;
public class PreferencesFragment extends PreferenceFragmentCompat {
private PreferencesActivity activity;
public PreferencesFragment() {
super();
init();
}
public PreferencesFragment(PreferencesActivity activity) {
super();
this.activity = activity;
init();
}
private void init() {
if (activity == null) {
activity = (PreferencesActivity) getActivity();
}
}
@Override
public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
setPreferencesFromResource(R.xml.prefs, rootKey);
if (activity == null) {
Logger.w(
"tt9/PreferencesFragment",
"Starting up without an Activity. Preference Items will not be fully initialized."
);
return;
}
createDictionarySection();
createAppearanceSection();
createKeymapSection();
createAboutSection();
}
private void createDictionarySection() {
ItemSelectLanguage multiSelect = new ItemSelectLanguage(
findPreference(ItemSelectLanguage.NAME),
activity.settings
);
multiSelect.populate().enableValidation();
ItemLoadDictionary loadItem = new ItemLoadDictionary(
findPreference(ItemLoadDictionary.NAME),
activity,
activity.settings,
activity.getDictionaryLoader(),
activity.getDictionaryProgressBar()
);
loadItem.enableClickHandler();
ItemTruncateDictionary truncateItem = new ItemTruncateDictionary(
findPreference(ItemTruncateDictionary.NAME),
loadItem,
activity,
activity.getDictionaryLoader()
);
truncateItem.enableClickHandler();
}
private void createAppearanceSection() {
(new ItemToggleDarkTheme(findPreference(ItemToggleDarkTheme.NAME))).enableToggleHandler();
}
private void createKeymapSection() {
DropDownPreference[] dropDowns = {
findPreference(SectionKeymap.ITEM_ADD_WORD),
findPreference(SectionKeymap.ITEM_BACKSPACE),
findPreference(SectionKeymap.ITEM_NEXT_INPUT_MODE),
findPreference(SectionKeymap.ITEM_NEXT_LANGUAGE),
findPreference(SectionKeymap.ITEM_SHOW_SETTINGS),
};
SectionKeymap section = new SectionKeymap(Arrays.asList(dropDowns), activity, activity.settings);
section.populate().activate();
(new ItemResetKeys(findPreference(ItemResetKeys.NAME), activity, activity.settings, section))
.enableClickHandler();
}
private void createAboutSection() {
Preference vi = findPreference("version_info");
if (vi != null) {
vi.setSummary(BuildConfig.VERSION_FULL);
}
}
}

View file

@ -15,6 +15,7 @@ import java.util.Set;
import io.github.sspanak.tt9.Logger;
import io.github.sspanak.tt9.ime.modes.InputMode;
import io.github.sspanak.tt9.languages.LanguageCollection;
import io.github.sspanak.tt9.preferences.items.SectionKeymap;
public class SettingsStore {

View file

@ -1,10 +1,10 @@
package io.github.sspanak.tt9.preferences;
package io.github.sspanak.tt9.preferences.items;
import androidx.preference.Preference;
import io.github.sspanak.tt9.Logger;
public abstract class ItemClickable {
abstract class ItemClickable {
protected final int CLICK_DEBOUNCE_TIME = 250;
private long lastClickTime = 0;

View file

@ -1,4 +1,4 @@
package io.github.sspanak.tt9.preferences;
package io.github.sspanak.tt9.preferences.items;
import android.content.Context;
import android.os.Handler;
@ -14,6 +14,7 @@ import io.github.sspanak.tt9.db.DictionaryImportAlreadyRunningException;
import io.github.sspanak.tt9.db.DictionaryLoader;
import io.github.sspanak.tt9.languages.Language;
import io.github.sspanak.tt9.languages.LanguageCollection;
import io.github.sspanak.tt9.preferences.SettingsStore;
import io.github.sspanak.tt9.ui.DictionaryLoadingBar;
import io.github.sspanak.tt9.ui.UI;
@ -27,7 +28,7 @@ public class ItemLoadDictionary extends ItemClickable {
private final DictionaryLoadingBar progressBar;
ItemLoadDictionary(Preference item, Context context, SettingsStore settings, DictionaryLoader loader, DictionaryLoadingBar progressBar) {
public ItemLoadDictionary(Preference item, Context context, SettingsStore settings, DictionaryLoader loader, DictionaryLoadingBar progressBar) {
super(item);
this.context = context;

View file

@ -1,10 +1,11 @@
package io.github.sspanak.tt9.preferences;
package io.github.sspanak.tt9.preferences.items;
import android.content.Context;
import androidx.preference.Preference;
import io.github.sspanak.tt9.R;
import io.github.sspanak.tt9.preferences.SettingsStore;
import io.github.sspanak.tt9.ui.UI;
@ -16,7 +17,7 @@ public class ItemResetKeys extends ItemClickable {
private final SettingsStore settings;
ItemResetKeys(Preference item, Context context, SettingsStore settings, SectionKeymap dropdowns) {
public ItemResetKeys(Preference item, Context context, SettingsStore settings, SectionKeymap dropdowns) {
super(item);
this.context = context;
this.dropdowns = dropdowns;

View file

@ -1,4 +1,4 @@
package io.github.sspanak.tt9.preferences;
package io.github.sspanak.tt9.preferences.items;
import androidx.preference.MultiSelectListPreference;
@ -7,6 +7,7 @@ import java.util.HashSet;
import io.github.sspanak.tt9.languages.Language;
import io.github.sspanak.tt9.languages.LanguageCollection;
import io.github.sspanak.tt9.preferences.SettingsStore;
public class ItemSelectLanguage {
public static final String NAME = "pref_languages";
@ -14,7 +15,7 @@ public class ItemSelectLanguage {
private final SettingsStore settings;
private final MultiSelectListPreference item;
ItemSelectLanguage(MultiSelectListPreference multiSelect, SettingsStore settings) {
public ItemSelectLanguage(MultiSelectListPreference multiSelect, SettingsStore settings) {
this.item = multiSelect;
this.settings = settings;
}

View file

@ -1,4 +1,4 @@
package io.github.sspanak.tt9.preferences;
package io.github.sspanak.tt9.preferences.items;
import androidx.appcompat.app.AppCompatDelegate;
import androidx.preference.Preference;

View file

@ -1,4 +1,4 @@
package io.github.sspanak.tt9.preferences;
package io.github.sspanak.tt9.preferences.items;
import android.content.Context;
import android.os.Handler;
@ -21,7 +21,7 @@ public class ItemTruncateDictionary extends ItemClickable {
private final ItemLoadDictionary loadItem;
ItemTruncateDictionary(Preference item, ItemLoadDictionary loadItem, Context context, DictionaryLoader loader) {
public ItemTruncateDictionary(Preference item, ItemLoadDictionary loadItem, Context context, DictionaryLoader loader) {
super(item);
this.context = context;
this.loadItem = loadItem;

View file

@ -1,4 +1,4 @@
package io.github.sspanak.tt9.preferences;
package io.github.sspanak.tt9.preferences.items;
import android.content.Context;
import android.content.res.Resources;
@ -15,6 +15,7 @@ import java.util.Objects;
import io.github.sspanak.tt9.Logger;
import io.github.sspanak.tt9.R;
import io.github.sspanak.tt9.preferences.SettingsStore;
public class SectionKeymap {
public static final String ITEM_ADD_WORD = "key_add_word";

View file

@ -0,0 +1,75 @@
package io.github.sspanak.tt9.preferences.screens;
import android.os.Bundle;
import android.view.MenuItem;
import androidx.annotation.NonNull;
import androidx.preference.PreferenceFragmentCompat;
import io.github.sspanak.tt9.Logger;
import io.github.sspanak.tt9.preferences.PreferencesActivity;
abstract class BaseScreenFragment extends PreferenceFragmentCompat {
protected PreferencesActivity activity;
protected void init(PreferencesActivity activity) {
this.activity = activity;
init();
}
protected void init() {
if (activity == null) {
activity = (PreferencesActivity) getActivity();
setScreenTitle();
}
}
private void setScreenTitle() {
if (activity != null) {
activity.setScreenTitle(getTitle());
}
}
@Override
public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
setHasOptionsMenu(true); // enable "back" in "onOptionsItemSelected()"
setPreferencesFromResource(getXml(), rootKey);
if (activity == null) {
Logger.w(
"tt9/MainSettingsScreen",
"Starting up without an Activity. Preference Items will not be fully initialized."
);
return;
}
onCreate();
}
@Override
public void onResume() {
super.onResume();
setScreenTitle();
}
@Override
public boolean onOptionsItemSelected(@NonNull MenuItem item) {
if (item.getItemId() == android.R.id.home && activity != null && !super.onOptionsItemSelected(item)) {
activity.onBackPressed();
return true;
}
return super.onOptionsItemSelected(item);
}
abstract protected int getTitle();
abstract protected int getXml();
abstract protected void onCreate();
}

View file

@ -0,0 +1,53 @@
package io.github.sspanak.tt9.preferences.screens;
import androidx.preference.DropDownPreference;
import java.util.Arrays;
import io.github.sspanak.tt9.R;
import io.github.sspanak.tt9.preferences.items.ItemResetKeys;
import io.github.sspanak.tt9.preferences.PreferencesActivity;
import io.github.sspanak.tt9.preferences.items.SectionKeymap;
public class HotkeysScreen extends BaseScreenFragment {
public HotkeysScreen() {
init();
}
public HotkeysScreen(PreferencesActivity activity) {
init(activity);
}
@Override
protected int getTitle() {
return R.string.pref_category_function_keys;
}
@Override
protected int getXml() {
return R.xml.prefs_screen_hotkeys;
}
@Override
public void onCreate() {
createKeymapSection();
}
private void createKeymapSection() {
DropDownPreference[] dropDowns = {
findPreference(SectionKeymap.ITEM_ADD_WORD),
findPreference(SectionKeymap.ITEM_BACKSPACE),
findPreference(SectionKeymap.ITEM_NEXT_INPUT_MODE),
findPreference(SectionKeymap.ITEM_NEXT_LANGUAGE),
findPreference(SectionKeymap.ITEM_SHOW_SETTINGS),
};
SectionKeymap section = new SectionKeymap(Arrays.asList(dropDowns), activity, activity.settings);
section.populate().activate();
(new ItemResetKeys(findPreference(ItemResetKeys.NAME), activity, activity.settings, section))
.enableClickHandler();
}
}

View file

@ -0,0 +1,79 @@
package io.github.sspanak.tt9.preferences.screens;
import androidx.preference.Preference;
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.ItemToggleDarkTheme;
import io.github.sspanak.tt9.preferences.items.ItemTruncateDictionary;
import io.github.sspanak.tt9.preferences.PreferencesActivity;
public class MainSettingsScreen extends BaseScreenFragment {
public MainSettingsScreen() {
init();
}
public MainSettingsScreen(PreferencesActivity activity) {
init(activity);
}
@Override
protected int getTitle() {
return R.string.app_settings;
}
@Override
protected int getXml() {
return R.xml.prefs;
}
@Override
public void onCreate() {
createDictionarySection();
createAppearanceSection();
createAboutSection();
}
private void createDictionarySection() {
ItemSelectLanguage multiSelect = new ItemSelectLanguage(
findPreference(ItemSelectLanguage.NAME),
activity.settings
);
multiSelect.populate().enableValidation();
ItemLoadDictionary loadItem = new ItemLoadDictionary(
findPreference(ItemLoadDictionary.NAME),
activity,
activity.settings,
activity.getDictionaryLoader(),
activity.getDictionaryProgressBar()
);
loadItem.enableClickHandler();
ItemTruncateDictionary truncateItem = new ItemTruncateDictionary(
findPreference(ItemTruncateDictionary.NAME),
loadItem,
activity,
activity.getDictionaryLoader()
);
truncateItem.enableClickHandler();
}
private void createAppearanceSection() {
(new ItemToggleDarkTheme(findPreference(ItemToggleDarkTheme.NAME))).enableToggleHandler();
}
private void createAboutSection() {
Preference vi = findPreference("version_info");
if (vi != null) {
vi.setSummary(BuildConfig.VERSION_FULL);
}
}
}