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

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