Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 699094f9 authored by Jean Chalard's avatar Jean Chalard
Browse files

Add an option to use or not the contacts dictionary.

Bug: 4586840
Change-Id: If62cd57e5ab661e6a51a5442d09bf0af8f08f263
parent 601b72cb
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -58,6 +58,11 @@
    <!-- Description for delay for dismissing a popup on screen: default value of the delay [CHAR LIMIT=15] -->
    <string name="key_preview_popup_dismiss_default_delay">Default</string>

    <!-- Option name for enabling or disabling the use of names of people in Contacts for suggestion and correction [CHAR LIMIT=25] -->
    <string name="use_contacts_dict">Suggest Contact names</string>
    <!-- Description for option enabling or disabling the use of names of people in Contacts for suggestion and correction [CHAR LIMIT=65] -->
    <string name="use_contacts_dict_summary">Use names from Contacts for suggestions and corrections</string>

    <!-- Option to enable auto capitalization of sentences -->
    <string name="auto_cap">Auto-capitalization</string>

+6 −0
Original line number Diff line number Diff line
@@ -138,6 +138,12 @@
          <ListPreference
              android:key="pref_key_preview_popup_dismiss_delay"
              android:title="@string/key_preview_popup_dismiss_delay" />
          <CheckBoxPreference
             android:key="pref_key_use_contacts_dict"
             android:title="@string/use_contacts_dict"
             android:summary="@string/use_contacts_dict_summary"
             android:persistent="true"
             android:defaultValue="true" />
    </PreferenceScreen>
    <!-- <Preference
        android:title="Debug Settings"
+9 −3
Original line number Diff line number Diff line
@@ -155,7 +155,6 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar

    private UserDictionary mUserDictionary;
    private UserBigramDictionary mUserBigramDictionary;
    private ContactsDictionary mContactsDictionary;
    private AutoDictionary mAutoDictionary;

    // TODO: Create an inner class to group options and pseudo-options to improve readability.
@@ -407,6 +406,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
        if (null == mPrefs) mPrefs = PreferenceManager.getDefaultSharedPreferences(this);
        if (null == mSubtypeSwitcher) mSubtypeSwitcher = SubtypeSwitcher.getInstance();
        mSettingsValues = new Settings.Values(mPrefs, this, mSubtypeSwitcher.getInputLocaleStr());
        resetContactsDictionary();
    }

    private void initSuggest() {
@@ -429,8 +429,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
        mUserDictionary = new UserDictionary(this, localeStr);
        mSuggest.setUserDictionary(mUserDictionary);

        mContactsDictionary = new ContactsDictionary(this, Suggest.DIC_CONTACTS);
        mSuggest.setContactsDictionary(mContactsDictionary);
        resetContactsDictionary();

        mAutoDictionary = new AutoDictionary(this, this, localeStr, Suggest.DIC_AUTO);
        mSuggest.setAutoDictionary(mAutoDictionary);
@@ -443,6 +442,13 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
        Utils.setSystemLocale(res, savedLocale);
    }

    private void resetContactsDictionary() {
        if (null == mSuggest) return;
        ContactsDictionary contactsDictionary = mSettingsValues.mUseContactsDict
                ? new ContactsDictionary(this, Suggest.DIC_CONTACTS) : null;
        mSuggest.setContactsDictionary(contactsDictionary);
    }

    /* package private */ void resetSuggestMainDict() {
        final String localeStr = mSubtypeSwitcher.getInputLocaleStr();
        final Locale keyboardLocale = Utils.constructLocaleFromString(localeStr);
+5 −0
Original line number Diff line number Diff line
@@ -79,6 +79,8 @@ public class Settings extends PreferenceActivity

    public static final String PREF_KEY_PREVIEW_POPUP_DISMISS_DELAY =
            "pref_key_preview_popup_dismiss_delay";
    public static final String PREF_KEY_USE_CONTACTS_DICT =
            "pref_key_use_contacts_dict";

    public static final String PREF_USABILITY_STUDY_MODE = "usability_study_mode";

@@ -114,6 +116,7 @@ public class Settings extends PreferenceActivity
        public final boolean mBigramSuggestionEnabled;
        // Prediction: use bigrams to predict the next word when there is no input for it yet
        public final boolean mBigramPredictionEnabled;
        public final boolean mUseContactsDict;

        public Values(final SharedPreferences prefs, final Context context,
                final String localeStr) {
@@ -175,6 +178,8 @@ public class Settings extends PreferenceActivity

            mAutoCorrectionThreshold = getAutoCorrectionThreshold(prefs, res);

            mUseContactsDict = prefs.getBoolean(Settings.PREF_KEY_USE_CONTACTS_DICT, true);

            Utils.setSystemLocale(res, savedLocale);
        }

+6 −1
Original line number Diff line number Diff line
@@ -184,12 +184,17 @@ public class Suggest implements Dictionary.WordCallback {
    }

    /**
     * Sets an optional contacts dictionary resource to be loaded.
     * Sets an optional contacts dictionary resource to be loaded. It is also possible to remove
     * the contacts dictionary by passing null to this method. In this case no contacts dictionary
     * won't be used.
     */
    public void setContactsDictionary(Dictionary contactsDictionary) {
        if (contactsDictionary != null) {
            mUnigramDictionaries.put(DICT_KEY_CONTACTS, contactsDictionary);
            mBigramDictionaries.put(DICT_KEY_CONTACTS, contactsDictionary);
        } else {
            mUnigramDictionaries.remove(DICT_KEY_CONTACTS);
            mBigramDictionaries.remove(DICT_KEY_CONTACTS);
        }
    }