Add an option to use or not the contacts dictionary.

Bug: 4586840
Change-Id: If62cd57e5ab661e6a51a5442d09bf0af8f08f263
main
Jean Chalard 2011-06-10 18:16:21 +09:00
parent 601b72cb1e
commit 699094f9b6
5 changed files with 31 additions and 4 deletions

View File

@ -58,6 +58,11 @@
<!-- Description for delay for dismissing a popup on screen: default value of the delay [CHAR LIMIT=15] --> <!-- 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> <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 --> <!-- Option to enable auto capitalization of sentences -->
<string name="auto_cap">Auto-capitalization</string> <string name="auto_cap">Auto-capitalization</string>

View File

@ -138,6 +138,12 @@
<ListPreference <ListPreference
android:key="pref_key_preview_popup_dismiss_delay" android:key="pref_key_preview_popup_dismiss_delay"
android:title="@string/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> </PreferenceScreen>
<!-- <Preference <!-- <Preference
android:title="Debug Settings" android:title="Debug Settings"

View File

@ -155,7 +155,6 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
private UserDictionary mUserDictionary; private UserDictionary mUserDictionary;
private UserBigramDictionary mUserBigramDictionary; private UserBigramDictionary mUserBigramDictionary;
private ContactsDictionary mContactsDictionary;
private AutoDictionary mAutoDictionary; private AutoDictionary mAutoDictionary;
// TODO: Create an inner class to group options and pseudo-options to improve readability. // 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 == mPrefs) mPrefs = PreferenceManager.getDefaultSharedPreferences(this);
if (null == mSubtypeSwitcher) mSubtypeSwitcher = SubtypeSwitcher.getInstance(); if (null == mSubtypeSwitcher) mSubtypeSwitcher = SubtypeSwitcher.getInstance();
mSettingsValues = new Settings.Values(mPrefs, this, mSubtypeSwitcher.getInputLocaleStr()); mSettingsValues = new Settings.Values(mPrefs, this, mSubtypeSwitcher.getInputLocaleStr());
resetContactsDictionary();
} }
private void initSuggest() { private void initSuggest() {
@ -429,8 +429,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
mUserDictionary = new UserDictionary(this, localeStr); mUserDictionary = new UserDictionary(this, localeStr);
mSuggest.setUserDictionary(mUserDictionary); mSuggest.setUserDictionary(mUserDictionary);
mContactsDictionary = new ContactsDictionary(this, Suggest.DIC_CONTACTS); resetContactsDictionary();
mSuggest.setContactsDictionary(mContactsDictionary);
mAutoDictionary = new AutoDictionary(this, this, localeStr, Suggest.DIC_AUTO); mAutoDictionary = new AutoDictionary(this, this, localeStr, Suggest.DIC_AUTO);
mSuggest.setAutoDictionary(mAutoDictionary); mSuggest.setAutoDictionary(mAutoDictionary);
@ -443,6 +442,13 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
Utils.setSystemLocale(res, savedLocale); 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() { /* package private */ void resetSuggestMainDict() {
final String localeStr = mSubtypeSwitcher.getInputLocaleStr(); final String localeStr = mSubtypeSwitcher.getInputLocaleStr();
final Locale keyboardLocale = Utils.constructLocaleFromString(localeStr); final Locale keyboardLocale = Utils.constructLocaleFromString(localeStr);

View File

@ -79,6 +79,8 @@ public class Settings extends PreferenceActivity
public static final String PREF_KEY_PREVIEW_POPUP_DISMISS_DELAY = public static final String PREF_KEY_PREVIEW_POPUP_DISMISS_DELAY =
"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"; public static final String PREF_USABILITY_STUDY_MODE = "usability_study_mode";
@ -114,6 +116,7 @@ public class Settings extends PreferenceActivity
public final boolean mBigramSuggestionEnabled; public final boolean mBigramSuggestionEnabled;
// Prediction: use bigrams to predict the next word when there is no input for it yet // Prediction: use bigrams to predict the next word when there is no input for it yet
public final boolean mBigramPredictionEnabled; public final boolean mBigramPredictionEnabled;
public final boolean mUseContactsDict;
public Values(final SharedPreferences prefs, final Context context, public Values(final SharedPreferences prefs, final Context context,
final String localeStr) { final String localeStr) {
@ -175,6 +178,8 @@ public class Settings extends PreferenceActivity
mAutoCorrectionThreshold = getAutoCorrectionThreshold(prefs, res); mAutoCorrectionThreshold = getAutoCorrectionThreshold(prefs, res);
mUseContactsDict = prefs.getBoolean(Settings.PREF_KEY_USE_CONTACTS_DICT, true);
Utils.setSystemLocale(res, savedLocale); Utils.setSystemLocale(res, savedLocale);
} }

View File

@ -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) { public void setContactsDictionary(Dictionary contactsDictionary) {
if (contactsDictionary != null) { if (contactsDictionary != null) {
mUnigramDictionaries.put(DICT_KEY_CONTACTS, contactsDictionary); mUnigramDictionaries.put(DICT_KEY_CONTACTS, contactsDictionary);
mBigramDictionaries.put(DICT_KEY_CONTACTS, contactsDictionary); mBigramDictionaries.put(DICT_KEY_CONTACTS, contactsDictionary);
} else {
mUnigramDictionaries.remove(DICT_KEY_CONTACTS);
mBigramDictionaries.remove(DICT_KEY_CONTACTS);
} }
} }