mirror of
https://github.com/Helium314/HeliBoard.git
synced 2025-04-22 15:19:10 +00:00
add "block offensive words" setting to spell checker settings too
and make sure we have settingsValues when using spell checker only
This commit is contained in:
parent
d18c15d027
commit
21254d895c
9 changed files with 51 additions and 38 deletions
|
@ -10,7 +10,6 @@ import helium314.keyboard.latin.settings.Settings
|
||||||
import helium314.keyboard.latin.settings.USER_DICTIONARY_SUFFIX
|
import helium314.keyboard.latin.settings.USER_DICTIONARY_SUFFIX
|
||||||
import helium314.keyboard.latin.utils.DeviceProtectedUtils
|
import helium314.keyboard.latin.utils.DeviceProtectedUtils
|
||||||
import helium314.keyboard.latin.utils.DictionaryInfoUtils
|
import helium314.keyboard.latin.utils.DictionaryInfoUtils
|
||||||
import helium314.keyboard.latin.utils.Log
|
|
||||||
import helium314.keyboard.latin.utils.upgradeToolbarPref
|
import helium314.keyboard.latin.utils.upgradeToolbarPref
|
||||||
import java.io.File
|
import java.io.File
|
||||||
|
|
||||||
|
@ -35,7 +34,6 @@ class App : Application() {
|
||||||
fun checkVersionUpgrade(context: Context) {
|
fun checkVersionUpgrade(context: Context) {
|
||||||
val prefs = DeviceProtectedUtils.getSharedPreferences(context)
|
val prefs = DeviceProtectedUtils.getSharedPreferences(context)
|
||||||
val oldVersion = prefs.getInt(Settings.PREF_VERSION_CODE, 0)
|
val oldVersion = prefs.getInt(Settings.PREF_VERSION_CODE, 0)
|
||||||
Log.d("test", "old v $oldVersion, current ${BuildConfig.VERSION_CODE}")
|
|
||||||
if (oldVersion == BuildConfig.VERSION_CODE)
|
if (oldVersion == BuildConfig.VERSION_CODE)
|
||||||
return
|
return
|
||||||
upgradeToolbarPref(prefs)
|
upgradeToolbarPref(prefs)
|
||||||
|
@ -88,7 +86,6 @@ private fun upgradesWhenComingFromOldAppName(context: Context) {
|
||||||
}
|
}
|
||||||
prefs.all.toMap().forEach {
|
prefs.all.toMap().forEach {
|
||||||
if (it.key.startsWith("pref_key_") && it.key != "pref_key_longpress_timeout") {
|
if (it.key.startsWith("pref_key_") && it.key != "pref_key_longpress_timeout") {
|
||||||
Log.d("test", "adjusting ${it.key}")
|
|
||||||
var remove = true
|
var remove = true
|
||||||
when (val value = it.value) {
|
when (val value = it.value) {
|
||||||
is Boolean -> prefs.edit().putBoolean(it.key.substringAfter("pref_key_"), value).apply()
|
is Boolean -> prefs.edit().putBoolean(it.key.substringAfter("pref_key_"), value).apply()
|
||||||
|
@ -101,7 +98,6 @@ private fun upgradesWhenComingFromOldAppName(context: Context) {
|
||||||
if (remove)
|
if (remove)
|
||||||
prefs.edit().remove(it.key).apply()
|
prefs.edit().remove(it.key).apply()
|
||||||
} else if (it.key.startsWith("pref_")) {
|
} else if (it.key.startsWith("pref_")) {
|
||||||
Log.d("test", "adjusting ${it.key}")
|
|
||||||
var remove = true
|
var remove = true
|
||||||
when (val value = it.value) {
|
when (val value = it.value) {
|
||||||
is Boolean -> prefs.edit().putBoolean(it.key.substringAfter("pref_"), value).apply()
|
is Boolean -> prefs.edit().putBoolean(it.key.substringAfter("pref_"), value).apply()
|
||||||
|
@ -113,26 +109,25 @@ private fun upgradesWhenComingFromOldAppName(context: Context) {
|
||||||
}
|
}
|
||||||
if (remove)
|
if (remove)
|
||||||
prefs.edit().remove(it.key).apply()
|
prefs.edit().remove(it.key).apply()
|
||||||
} else {
|
|
||||||
Log.d("test", "keeping ${it.key}")
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// change more_keys to popup_keys
|
// change more_keys to popup_keys
|
||||||
if (prefs.contains("more_keys_order")) {
|
if (prefs.contains("more_keys_order")) {
|
||||||
Log.d("test", "more_keys_order")
|
|
||||||
prefs.edit().putString(Settings.PREF_POPUP_KEYS_ORDER, prefs.getString("more_keys_order", "")).apply()
|
prefs.edit().putString(Settings.PREF_POPUP_KEYS_ORDER, prefs.getString("more_keys_order", "")).apply()
|
||||||
prefs.edit().remove("more_keys_order").apply()
|
prefs.edit().remove("more_keys_order").apply()
|
||||||
}
|
}
|
||||||
if (prefs.contains("more_keys_labels_order")) {
|
if (prefs.contains("more_keys_labels_order")) {
|
||||||
Log.d("test", "more_keys_labels_order")
|
|
||||||
prefs.edit().putString(Settings.PREF_POPUP_KEYS_LABELS_ORDER, prefs.getString("more_keys_labels_order", "")).apply()
|
prefs.edit().putString(Settings.PREF_POPUP_KEYS_LABELS_ORDER, prefs.getString("more_keys_labels_order", "")).apply()
|
||||||
prefs.edit().remove("more_keys_labels_order").apply()
|
prefs.edit().remove("more_keys_labels_order").apply()
|
||||||
}
|
}
|
||||||
if (prefs.contains("more_more_keys")) {
|
if (prefs.contains("more_more_keys")) {
|
||||||
Log.d("test", "more_more_keys")
|
|
||||||
prefs.edit().putString(Settings.PREF_MORE_POPUP_KEYS, prefs.getString("more_more_keys", "")).apply()
|
prefs.edit().putString(Settings.PREF_MORE_POPUP_KEYS, prefs.getString("more_more_keys", "")).apply()
|
||||||
prefs.edit().remove("more_more_keys").apply()
|
prefs.edit().remove("more_more_keys").apply()
|
||||||
}
|
}
|
||||||
|
if (prefs.contains("spellcheck_use_contacts")) {
|
||||||
|
prefs.edit().putBoolean(Settings.PREF_USE_CONTACTS, prefs.getBoolean("spellcheck_use_contacts", false)).apply()
|
||||||
|
prefs.edit().remove("spellcheck_use_contacts").apply()
|
||||||
|
}
|
||||||
// upgrade additional subtype locale strings
|
// upgrade additional subtype locale strings
|
||||||
val additionalSubtypes = mutableListOf<String>()
|
val additionalSubtypes = mutableListOf<String>()
|
||||||
Settings.readPrefAdditionalSubtypes(prefs, context.resources).split(";").forEach {
|
Settings.readPrefAdditionalSubtypes(prefs, context.resources).split(";").forEach {
|
||||||
|
|
|
@ -12,6 +12,7 @@ import android.provider.UserDictionary;
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
|
|
||||||
import helium314.keyboard.latin.settings.SettingsValues;
|
import helium314.keyboard.latin.settings.SettingsValues;
|
||||||
|
import helium314.keyboard.latin.utils.DeviceProtectedUtils;
|
||||||
import helium314.keyboard.latin.utils.Log;
|
import helium314.keyboard.latin.utils.Log;
|
||||||
import android.util.LruCache;
|
import android.util.LruCache;
|
||||||
|
|
||||||
|
@ -29,6 +30,7 @@ import helium314.keyboard.latin.personalization.UserHistoryDictionary;
|
||||||
import helium314.keyboard.latin.settings.Settings;
|
import helium314.keyboard.latin.settings.Settings;
|
||||||
import helium314.keyboard.latin.settings.SettingsValuesForSuggestion;
|
import helium314.keyboard.latin.settings.SettingsValuesForSuggestion;
|
||||||
import helium314.keyboard.latin.utils.ExecutorUtils;
|
import helium314.keyboard.latin.utils.ExecutorUtils;
|
||||||
|
import helium314.keyboard.latin.utils.SubtypeUtilsKt;
|
||||||
import helium314.keyboard.latin.utils.SuggestionResults;
|
import helium314.keyboard.latin.utils.SuggestionResults;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
@ -342,7 +344,7 @@ public class DictionaryFacilitatorImpl implements DictionaryFacilitator {
|
||||||
subDictTypesToUse.add(Dictionary.TYPE_USER);
|
subDictTypesToUse.add(Dictionary.TYPE_USER);
|
||||||
final List<Locale> allLocales = new ArrayList<>() {{
|
final List<Locale> allLocales = new ArrayList<>() {{
|
||||||
add(newLocale);
|
add(newLocale);
|
||||||
addAll(Settings.getInstance().getCurrent().mSecondaryLocales);
|
addAll(Settings.getSecondaryLocales(DeviceProtectedUtils.getSharedPreferences(context), newLocale));
|
||||||
}};
|
}};
|
||||||
|
|
||||||
// Do not use contacts dictionary if we do not have permissions to read contacts.
|
// Do not use contacts dictionary if we do not have permissions to read contacts.
|
||||||
|
|
|
@ -19,7 +19,6 @@ import androidx.preference.TwoStatePreference;
|
||||||
import helium314.keyboard.latin.R;
|
import helium314.keyboard.latin.R;
|
||||||
import helium314.keyboard.latin.permissions.PermissionsManager;
|
import helium314.keyboard.latin.permissions.PermissionsManager;
|
||||||
import helium314.keyboard.latin.permissions.PermissionsUtil;
|
import helium314.keyboard.latin.permissions.PermissionsUtil;
|
||||||
import helium314.keyboard.latin.spellcheck.AndroidSpellCheckerService;
|
|
||||||
|
|
||||||
public final class CorrectionSettingsFragment extends SubScreenFragment
|
public final class CorrectionSettingsFragment extends SubScreenFragment
|
||||||
implements SharedPreferences.OnSharedPreferenceChangeListener,
|
implements SharedPreferences.OnSharedPreferenceChangeListener,
|
||||||
|
@ -32,14 +31,14 @@ public final class CorrectionSettingsFragment extends SubScreenFragment
|
||||||
super.onCreate(icicle);
|
super.onCreate(icicle);
|
||||||
addPreferencesFromResource(R.xml.prefs_screen_correction);
|
addPreferencesFromResource(R.xml.prefs_screen_correction);
|
||||||
|
|
||||||
mLookupContactsPreference = findPreference(AndroidSpellCheckerService.PREF_USE_CONTACTS_KEY);
|
mLookupContactsPreference = findPreference(Settings.PREF_USE_CONTACTS);
|
||||||
|
|
||||||
refreshEnabledSettings();
|
refreshEnabledSettings();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onSharedPreferenceChanged(final SharedPreferences prefs, final String key) {
|
public void onSharedPreferenceChanged(final SharedPreferences prefs, final String key) {
|
||||||
if (AndroidSpellCheckerService.PREF_USE_CONTACTS_KEY.equals(key)
|
if (Settings.PREF_USE_CONTACTS.equals(key)
|
||||||
&& prefs.getBoolean(key, false)
|
&& prefs.getBoolean(key, false)
|
||||||
&& !PermissionsUtil.checkAllPermissionsGranted(getActivity(), Manifest.permission.READ_CONTACTS)
|
&& !PermissionsUtil.checkAllPermissionsGranted(getActivity(), Manifest.permission.READ_CONTACTS)
|
||||||
) {
|
) {
|
||||||
|
|
|
@ -112,6 +112,7 @@ public final class Settings implements SharedPreferences.OnSharedPreferenceChang
|
||||||
public static final String PREF_GESTURE_FLOATING_PREVIEW_TEXT = "gesture_floating_preview_text";
|
public static final String PREF_GESTURE_FLOATING_PREVIEW_TEXT = "gesture_floating_preview_text";
|
||||||
public static final String PREF_GESTURE_SPACE_AWARE = "gesture_space_aware";
|
public static final String PREF_GESTURE_SPACE_AWARE = "gesture_space_aware";
|
||||||
public static final String PREF_SHOW_SETUP_WIZARD_ICON = "show_setup_wizard_icon";
|
public static final String PREF_SHOW_SETUP_WIZARD_ICON = "show_setup_wizard_icon";
|
||||||
|
public static final String PREF_USE_CONTACTS = "use_contacts";
|
||||||
|
|
||||||
// one-handed mode gravity, enablement and scale, stored separately per orientation
|
// one-handed mode gravity, enablement and scale, stored separately per orientation
|
||||||
public static final String PREF_ONE_HANDED_MODE_PREFIX = "one_handed_mode_enabled_p_";
|
public static final String PREF_ONE_HANDED_MODE_PREFIX = "one_handed_mode_enabled_p_";
|
||||||
|
|
|
@ -22,7 +22,6 @@ import helium314.keyboard.latin.InputAttributes;
|
||||||
import helium314.keyboard.latin.R;
|
import helium314.keyboard.latin.R;
|
||||||
import helium314.keyboard.latin.RichInputMethodManager;
|
import helium314.keyboard.latin.RichInputMethodManager;
|
||||||
import helium314.keyboard.latin.common.Colors;
|
import helium314.keyboard.latin.common.Colors;
|
||||||
import helium314.keyboard.latin.spellcheck.AndroidSpellCheckerService;
|
|
||||||
import helium314.keyboard.latin.utils.InputTypeUtils;
|
import helium314.keyboard.latin.utils.InputTypeUtils;
|
||||||
import helium314.keyboard.latin.utils.Log;
|
import helium314.keyboard.latin.utils.Log;
|
||||||
import helium314.keyboard.latin.utils.MoreKeysUtilsKt;
|
import helium314.keyboard.latin.utils.MoreKeysUtilsKt;
|
||||||
|
@ -222,7 +221,7 @@ public class SettingsValues {
|
||||||
mMoreKeyLabelSources = MoreKeysUtilsKt.getEnabledMoreKeys(prefs, Settings.PREF_POPUP_KEYS_LABELS_ORDER + "_" + selectedSubtype.getLocale(), moreKeyLabelDefault);
|
mMoreKeyLabelSources = MoreKeysUtilsKt.getEnabledMoreKeys(prefs, Settings.PREF_POPUP_KEYS_LABELS_ORDER + "_" + selectedSubtype.getLocale(), moreKeyLabelDefault);
|
||||||
|
|
||||||
mAddToPersonalDictionary = prefs.getBoolean(Settings.PREF_ADD_TO_PERSONAL_DICTIONARY, false);
|
mAddToPersonalDictionary = prefs.getBoolean(Settings.PREF_ADD_TO_PERSONAL_DICTIONARY, false);
|
||||||
mUseContactsDictionary = prefs.getBoolean(AndroidSpellCheckerService.PREF_USE_CONTACTS_KEY, false);
|
mUseContactsDictionary = prefs.getBoolean(Settings.PREF_USE_CONTACTS, false);
|
||||||
mCustomNavBarColor = prefs.getBoolean(Settings.PREF_NAVBAR_COLOR, false);
|
mCustomNavBarColor = prefs.getBoolean(Settings.PREF_NAVBAR_COLOR, false);
|
||||||
mNarrowKeyGaps = prefs.getBoolean(Settings.PREF_NARROW_KEY_GAPS, true);
|
mNarrowKeyGaps = prefs.getBoolean(Settings.PREF_NARROW_KEY_GAPS, true);
|
||||||
mSettingsValuesForSuggestion = new SettingsValuesForSuggestion(
|
mSettingsValuesForSuggestion = new SettingsValuesForSuggestion(
|
||||||
|
|
|
@ -21,11 +21,13 @@ import helium314.keyboard.keyboard.KeyboardId;
|
||||||
import helium314.keyboard.keyboard.KeyboardLayoutSet;
|
import helium314.keyboard.keyboard.KeyboardLayoutSet;
|
||||||
import helium314.keyboard.latin.DictionaryFacilitator;
|
import helium314.keyboard.latin.DictionaryFacilitator;
|
||||||
import helium314.keyboard.latin.DictionaryFacilitatorLruCache;
|
import helium314.keyboard.latin.DictionaryFacilitatorLruCache;
|
||||||
|
import helium314.keyboard.latin.InputAttributes;
|
||||||
import helium314.keyboard.latin.NgramContext;
|
import helium314.keyboard.latin.NgramContext;
|
||||||
import helium314.keyboard.latin.R;
|
import helium314.keyboard.latin.R;
|
||||||
import helium314.keyboard.latin.RichInputMethodSubtype;
|
import helium314.keyboard.latin.RichInputMethodSubtype;
|
||||||
import helium314.keyboard.latin.SuggestedWords;
|
import helium314.keyboard.latin.SuggestedWords;
|
||||||
import helium314.keyboard.latin.common.ComposedData;
|
import helium314.keyboard.latin.common.ComposedData;
|
||||||
|
import helium314.keyboard.latin.settings.Settings;
|
||||||
import helium314.keyboard.latin.settings.SettingsValuesForSuggestion;
|
import helium314.keyboard.latin.settings.SettingsValuesForSuggestion;
|
||||||
import helium314.keyboard.latin.utils.AdditionalSubtypeUtils;
|
import helium314.keyboard.latin.utils.AdditionalSubtypeUtils;
|
||||||
import helium314.keyboard.latin.utils.DeviceProtectedUtils;
|
import helium314.keyboard.latin.utils.DeviceProtectedUtils;
|
||||||
|
@ -43,8 +45,6 @@ import java.util.concurrent.Semaphore;
|
||||||
public final class AndroidSpellCheckerService extends SpellCheckerService
|
public final class AndroidSpellCheckerService extends SpellCheckerService
|
||||||
implements SharedPreferences.OnSharedPreferenceChangeListener {
|
implements SharedPreferences.OnSharedPreferenceChangeListener {
|
||||||
|
|
||||||
public static final String PREF_USE_CONTACTS_KEY = "spellcheck_use_contacts";
|
|
||||||
|
|
||||||
public static final int SPELLCHECKER_DUMMY_KEYBOARD_WIDTH = 480;
|
public static final int SPELLCHECKER_DUMMY_KEYBOARD_WIDTH = 480;
|
||||||
public static final int SPELLCHECKER_DUMMY_KEYBOARD_HEIGHT = 301;
|
public static final int SPELLCHECKER_DUMMY_KEYBOARD_HEIGHT = 301;
|
||||||
|
|
||||||
|
@ -53,20 +53,17 @@ public final class AndroidSpellCheckerService extends SpellCheckerService
|
||||||
private static final String[] EMPTY_STRING_ARRAY = new String[0];
|
private static final String[] EMPTY_STRING_ARRAY = new String[0];
|
||||||
|
|
||||||
private final int MAX_NUM_OF_THREADS_READ_DICTIONARY = 2;
|
private final int MAX_NUM_OF_THREADS_READ_DICTIONARY = 2;
|
||||||
private final Semaphore mSemaphore = new Semaphore(MAX_NUM_OF_THREADS_READ_DICTIONARY,
|
private final Semaphore mSemaphore = new Semaphore(MAX_NUM_OF_THREADS_READ_DICTIONARY, true);
|
||||||
true /* fair */);
|
|
||||||
// TODO: Make each spell checker session has its own session id.
|
// TODO: Make each spell checker session has its own session id.
|
||||||
private final ConcurrentLinkedQueue<Integer> mSessionIdPool = new ConcurrentLinkedQueue<>();
|
private final ConcurrentLinkedQueue<Integer> mSessionIdPool = new ConcurrentLinkedQueue<>();
|
||||||
|
|
||||||
private final DictionaryFacilitatorLruCache mDictionaryFacilitatorCache =
|
private final DictionaryFacilitatorLruCache mDictionaryFacilitatorCache =
|
||||||
new DictionaryFacilitatorLruCache(this /* context */, DICTIONARY_NAME_PREFIX);
|
new DictionaryFacilitatorLruCache(this, DICTIONARY_NAME_PREFIX);
|
||||||
private final ConcurrentHashMap<Locale, Keyboard> mKeyboardCache = new ConcurrentHashMap<>();
|
private final ConcurrentHashMap<Locale, Keyboard> mKeyboardCache = new ConcurrentHashMap<>();
|
||||||
|
|
||||||
// The threshold for a suggestion to be considered "recommended".
|
// The threshold for a suggestion to be considered "recommended".
|
||||||
private float mRecommendedThreshold;
|
private float mRecommendedThreshold;
|
||||||
// TODO: make a spell checker option to block offensive words or not
|
private SettingsValuesForSuggestion mSettingsValuesForSuggestion;
|
||||||
private final SettingsValuesForSuggestion mSettingsValuesForSuggestion =
|
|
||||||
new SettingsValuesForSuggestion(true, false);
|
|
||||||
|
|
||||||
public static final String SINGLE_QUOTE = "'";
|
public static final String SINGLE_QUOTE = "'";
|
||||||
public static final String APOSTROPHE = "’";
|
public static final String APOSTROPHE = "’";
|
||||||
|
@ -84,7 +81,9 @@ public final class AndroidSpellCheckerService extends SpellCheckerService
|
||||||
mRecommendedThreshold = Float.parseFloat(getString(R.string.spellchecker_recommended_threshold_value));
|
mRecommendedThreshold = Float.parseFloat(getString(R.string.spellchecker_recommended_threshold_value));
|
||||||
final SharedPreferences prefs = DeviceProtectedUtils.getSharedPreferences(this);
|
final SharedPreferences prefs = DeviceProtectedUtils.getSharedPreferences(this);
|
||||||
prefs.registerOnSharedPreferenceChangeListener(this);
|
prefs.registerOnSharedPreferenceChangeListener(this);
|
||||||
onSharedPreferenceChanged(prefs, PREF_USE_CONTACTS_KEY);
|
onSharedPreferenceChanged(prefs, Settings.PREF_USE_CONTACTS);
|
||||||
|
final boolean blockOffensive = Settings.readBlockPotentiallyOffensive(prefs, getResources());
|
||||||
|
mSettingsValuesForSuggestion = new SettingsValuesForSuggestion(blockOffensive, false);
|
||||||
SubtypeSettingsKt.init(this);
|
SubtypeSettingsKt.init(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -94,9 +93,13 @@ public final class AndroidSpellCheckerService extends SpellCheckerService
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onSharedPreferenceChanged(final SharedPreferences prefs, final String key) {
|
public void onSharedPreferenceChanged(final SharedPreferences prefs, final String key) {
|
||||||
if (!PREF_USE_CONTACTS_KEY.equals(key)) return;
|
if (Settings.PREF_USE_CONTACTS.equals(key)) {
|
||||||
final boolean useContactsDictionary = prefs.getBoolean(PREF_USE_CONTACTS_KEY, true);
|
final boolean useContactsDictionary = prefs.getBoolean(Settings.PREF_USE_CONTACTS, true);
|
||||||
mDictionaryFacilitatorCache.setUseContactsDictionary(useContactsDictionary);
|
mDictionaryFacilitatorCache.setUseContactsDictionary(useContactsDictionary);
|
||||||
|
} else if (Settings.PREF_BLOCK_POTENTIALLY_OFFENSIVE.equals(key)) {
|
||||||
|
final boolean blockOffensive = Settings.readBlockPotentiallyOffensive(prefs, getResources());
|
||||||
|
mSettingsValuesForSuggestion = new SettingsValuesForSuggestion(blockOffensive, false);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -121,8 +124,7 @@ public final class AndroidSpellCheckerService extends SpellCheckerService
|
||||||
* @return the empty SuggestionsInfo with the appropriate flags set.
|
* @return the empty SuggestionsInfo with the appropriate flags set.
|
||||||
*/
|
*/
|
||||||
public static SuggestionsInfo getInDictEmptySuggestions() {
|
public static SuggestionsInfo getInDictEmptySuggestions() {
|
||||||
return new SuggestionsInfo(SuggestionsInfo.RESULT_ATTR_IN_THE_DICTIONARY,
|
return new SuggestionsInfo(SuggestionsInfo.RESULT_ATTR_IN_THE_DICTIONARY, EMPTY_STRING_ARRAY);
|
||||||
EMPTY_STRING_ARRAY);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isValidWord(final Locale locale, final String word) {
|
public boolean isValidWord(final Locale locale, final String word) {
|
||||||
|
@ -142,8 +144,7 @@ public final class AndroidSpellCheckerService extends SpellCheckerService
|
||||||
mSemaphore.acquireUninterruptibly();
|
mSemaphore.acquireUninterruptibly();
|
||||||
try {
|
try {
|
||||||
sessionId = mSessionIdPool.poll();
|
sessionId = mSessionIdPool.poll();
|
||||||
DictionaryFacilitator dictionaryFacilitatorForLocale =
|
DictionaryFacilitator dictionaryFacilitatorForLocale = mDictionaryFacilitatorCache.get(locale);
|
||||||
mDictionaryFacilitatorCache.get(locale);
|
|
||||||
return dictionaryFacilitatorForLocale.getSuggestionResults(composedData, ngramContext,
|
return dictionaryFacilitatorForLocale.getSuggestionResults(composedData, ngramContext,
|
||||||
keyboard, mSettingsValuesForSuggestion,
|
keyboard, mSettingsValuesForSuggestion,
|
||||||
sessionId, SuggestedWords.INPUT_STYLE_TYPING);
|
sessionId, SuggestedWords.INPUT_STYLE_TYPING);
|
||||||
|
@ -188,6 +189,15 @@ public final class AndroidSpellCheckerService extends SpellCheckerService
|
||||||
}
|
}
|
||||||
|
|
||||||
private Keyboard createKeyboardForLocale(final Locale locale) {
|
private Keyboard createKeyboardForLocale(final Locale locale) {
|
||||||
|
if (Settings.getInstance().getCurrent() == null) {
|
||||||
|
// creating a keyboard reads SettingsValues from Settings instance
|
||||||
|
// maybe it would be "more correct" to create an instance of SettingsValues and use that one instead
|
||||||
|
// but creating a global one if not existing should be fine too
|
||||||
|
Settings.init(this);
|
||||||
|
final EditorInfo editorInfo = new EditorInfo();
|
||||||
|
editorInfo.inputType = InputType.TYPE_CLASS_TEXT;
|
||||||
|
Settings.getInstance().loadSettings(this, locale, new InputAttributes(editorInfo, false, getPackageName()));
|
||||||
|
}
|
||||||
final String keyboardLayoutName = SubtypeSettingsKt.getMatchingLayoutSetNameForLocale(locale);
|
final String keyboardLayoutName = SubtypeSettingsKt.getMatchingLayoutSetNameForLocale(locale);
|
||||||
final InputMethodSubtype subtype = AdditionalSubtypeUtils.createDummyAdditionalSubtype(locale, keyboardLayoutName);
|
final InputMethodSubtype subtype = AdditionalSubtypeUtils.createDummyAdditionalSubtype(locale, keyboardLayoutName);
|
||||||
final KeyboardLayoutSet keyboardLayoutSet = createKeyboardSetForSpellChecker(subtype);
|
final KeyboardLayoutSet keyboardLayoutSet = createKeyboardSetForSpellChecker(subtype);
|
||||||
|
@ -201,7 +211,7 @@ public final class AndroidSpellCheckerService extends SpellCheckerService
|
||||||
return builder
|
return builder
|
||||||
.setKeyboardGeometry(SPELLCHECKER_DUMMY_KEYBOARD_WIDTH, SPELLCHECKER_DUMMY_KEYBOARD_HEIGHT)
|
.setKeyboardGeometry(SPELLCHECKER_DUMMY_KEYBOARD_WIDTH, SPELLCHECKER_DUMMY_KEYBOARD_HEIGHT)
|
||||||
.setSubtype(RichInputMethodSubtype.getRichInputMethodSubtype(subtype))
|
.setSubtype(RichInputMethodSubtype.getRichInputMethodSubtype(subtype))
|
||||||
.setIsSpellChecker(true /* isSpellChecker */)
|
.setIsSpellChecker(true)
|
||||||
.disableTouchPositionCorrectionData()
|
.disableTouchPositionCorrectionData()
|
||||||
.build();
|
.build();
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,6 +16,7 @@ import androidx.preference.SwitchPreference;
|
||||||
import helium314.keyboard.latin.R;
|
import helium314.keyboard.latin.R;
|
||||||
import helium314.keyboard.latin.permissions.PermissionsManager;
|
import helium314.keyboard.latin.permissions.PermissionsManager;
|
||||||
import helium314.keyboard.latin.permissions.PermissionsUtil;
|
import helium314.keyboard.latin.permissions.PermissionsUtil;
|
||||||
|
import helium314.keyboard.latin.settings.Settings;
|
||||||
import helium314.keyboard.latin.settings.SubScreenFragment;
|
import helium314.keyboard.latin.settings.SubScreenFragment;
|
||||||
import helium314.keyboard.latin.utils.ActivityThemeUtils;
|
import helium314.keyboard.latin.utils.ActivityThemeUtils;
|
||||||
|
|
||||||
|
@ -32,7 +33,7 @@ public final class SpellCheckerSettingsFragment extends SubScreenFragment
|
||||||
public void onCreate(Bundle savedInstanceState) {
|
public void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
addPreferencesFromResource(R.xml.spell_checker_settings);
|
addPreferencesFromResource(R.xml.spell_checker_settings);
|
||||||
mLookupContactsPreference = findPreference(AndroidSpellCheckerService.PREF_USE_CONTACTS_KEY);
|
mLookupContactsPreference = findPreference(Settings.PREF_USE_CONTACTS);
|
||||||
turnOffLookupContactsIfNoPermission();
|
turnOffLookupContactsIfNoPermission();
|
||||||
|
|
||||||
ActivityThemeUtils.setActivityTheme(requireActivity());
|
ActivityThemeUtils.setActivityTheme(requireActivity());
|
||||||
|
@ -40,7 +41,7 @@ public final class SpellCheckerSettingsFragment extends SubScreenFragment
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
|
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
|
||||||
if (!TextUtils.equals(key, AndroidSpellCheckerService.PREF_USE_CONTACTS_KEY) || sharedPreferences.getBoolean(key, false)) {
|
if (!TextUtils.equals(key, Settings.PREF_USE_CONTACTS) || sharedPreferences.getBoolean(key, false)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -100,10 +100,10 @@
|
||||||
android:persistent="true" />
|
android:persistent="true" />
|
||||||
|
|
||||||
<SwitchPreference
|
<SwitchPreference
|
||||||
android:key="spellcheck_use_contacts"
|
android:key="use_contacts"
|
||||||
android:title="@string/use_contacts_dict"
|
android:title="@string/use_contacts_dict"
|
||||||
android:summary="@string/use_contacts_dict_summary"
|
android:summary="@string/use_contacts_dict_summary"
|
||||||
android:defaultValue="true"
|
android:defaultValue="false"
|
||||||
android:persistent="true" />
|
android:persistent="true" />
|
||||||
|
|
||||||
<SwitchPreference
|
<SwitchPreference
|
||||||
|
|
|
@ -9,9 +9,15 @@
|
||||||
android:title="@string/android_spell_checker_settings"
|
android:title="@string/android_spell_checker_settings"
|
||||||
>
|
>
|
||||||
<SwitchPreference
|
<SwitchPreference
|
||||||
android:key="spellcheck_use_contacts"
|
android:key="use_contacts"
|
||||||
android:title="@string/use_contacts_for_spellchecking_option_title"
|
android:title="@string/use_contacts_for_spellchecking_option_title"
|
||||||
android:summary="@string/use_contacts_for_spellchecking_option_summary"
|
android:summary="@string/use_contacts_for_spellchecking_option_summary"
|
||||||
android:defaultValue="true"
|
android:defaultValue="false"
|
||||||
|
android:persistent="true" />
|
||||||
|
|
||||||
|
<SwitchPreference
|
||||||
|
android:key="block_potentially_offensive"
|
||||||
|
android:title="@string/prefs_block_potentially_offensive_title"
|
||||||
|
android:defaultValue="@bool/config_block_potentially_offensive"
|
||||||
android:persistent="true" />
|
android:persistent="true" />
|
||||||
</PreferenceScreen>
|
</PreferenceScreen>
|
||||||
|
|
Loading…
Add table
Reference in a new issue