diff --git a/java/res/values/strings.xml b/java/res/values/strings.xml index f24b43320..a7d2bd9de 100644 --- a/java/res/values/strings.xml +++ b/java/res/values/strings.xml @@ -428,6 +428,8 @@ Keypress sound volume Read external dictionary file + + Use only personalization dictionary No dictionary files in the Downloads folder diff --git a/java/res/xml/prefs_for_debug.xml b/java/res/xml/prefs_for_debug.xml index 8efd1c9e8..6958ddac6 100644 --- a/java/res/xml/prefs_for_debug.xml +++ b/java/res/xml/prefs_for_debug.xml @@ -51,6 +51,12 @@ android:persistent="true" android:defaultValue="false" /> + + diff --git a/java/src/com/android/inputmethod/latin/Suggest.java b/java/src/com/android/inputmethod/latin/Suggest.java index 2879e2e32..c2fdcb552 100644 --- a/java/src/com/android/inputmethod/latin/Suggest.java +++ b/java/src/com/android/inputmethod/latin/Suggest.java @@ -17,13 +17,16 @@ package com.android.inputmethod.latin; import android.content.Context; +import android.preference.PreferenceManager; import android.text.TextUtils; +import android.util.Log; import com.android.inputmethod.annotations.UsedForTesting; import com.android.inputmethod.keyboard.ProximityInfo; import com.android.inputmethod.latin.SuggestedWords.SuggestedWordInfo; import com.android.inputmethod.latin.personalization.PersonalizationPredictionDictionary; import com.android.inputmethod.latin.personalization.UserHistoryPredictionDictionary; +import com.android.inputmethod.latin.settings.Settings; import com.android.inputmethod.latin.utils.AutoCorrectionUtils; import com.android.inputmethod.latin.utils.BoundedTreeSet; import com.android.inputmethod.latin.utils.CollectionUtils; @@ -55,21 +58,22 @@ public final class Suggest { // Close to -2**31 private static final int SUPPRESS_SUGGEST_THRESHOLD = -2000000000; + public static final int MAX_SUGGESTIONS = 18; + public interface SuggestInitializationListener { public void onUpdateMainDictionaryAvailability(boolean isMainDictionaryAvailable); } private static final boolean DBG = LatinImeLogger.sDBG; - private Dictionary mMainDictionary; - private ContactsBinaryDictionary mContactsDict; private final ConcurrentHashMap mDictionaries = CollectionUtils.newConcurrentHashMap(); + private HashSet mOnlyDictionarySetForDebug = null; + private Dictionary mMainDictionary; + private ContactsBinaryDictionary mContactsDict; @UsedForTesting private boolean mIsCurrentlyWaitingForMainDictionary = false; - public static final int MAX_SUGGESTIONS = 18; - private float mAutoCorrectionThreshold; // Locale used for upper- and title-casing words @@ -79,6 +83,13 @@ public final class Suggest { final SuggestInitializationListener listener) { initAsynchronously(context, locale, listener); mLocale = locale; + // initialize a debug flag for the personalization + if (Settings.readUseOnlyPersonalizationDictionaryForDebug( + PreferenceManager.getDefaultSharedPreferences(context))) { + mOnlyDictionarySetForDebug = new HashSet(); + mOnlyDictionarySetForDebug.add(Dictionary.TYPE_PERSONALIZATION); + mOnlyDictionarySetForDebug.add(Dictionary.TYPE_PERSONALIZATION_PREDICTION_IN_JAVA); + } } @UsedForTesting @@ -87,7 +98,7 @@ public final class Suggest { false /* useFullEditDistance */, locale); mLocale = locale; mMainDictionary = mainDict; - addOrReplaceDictionary(mDictionaries, Dictionary.TYPE_MAIN, mainDict); + addOrReplaceDictionaryInternal(Dictionary.TYPE_MAIN, mainDict); } private void initAsynchronously(final Context context, final Locale locale, @@ -95,6 +106,14 @@ public final class Suggest { resetMainDict(context, locale, listener); } + private void addOrReplaceDictionaryInternal(final String key, final Dictionary dict) { + if (mOnlyDictionarySetForDebug != null && mOnlyDictionarySetForDebug.contains(key)) { + Log.w(TAG, "Ignore add " + key + " dictionary for debug."); + return; + } + addOrReplaceDictionary(mDictionaries, key, dict); + } + private static void addOrReplaceDictionary( final ConcurrentHashMap dictionaries, final String key, final Dictionary dict) { @@ -118,7 +137,7 @@ public final class Suggest { public void run() { final DictionaryCollection newMainDict = DictionaryFactory.createMainDictionaryFromManager(context, locale); - addOrReplaceDictionary(mDictionaries, Dictionary.TYPE_MAIN, newMainDict); + addOrReplaceDictionaryInternal(Dictionary.TYPE_MAIN, newMainDict); mMainDictionary = newMainDict; if (listener != null) { listener.onUpdateMainDictionaryAvailability(hasMainDictionary()); @@ -156,7 +175,7 @@ public final class Suggest { * before the main dictionary, if set. This refers to the system-managed user dictionary. */ public void setUserDictionary(final UserBinaryDictionary userDictionary) { - addOrReplaceDictionary(mDictionaries, Dictionary.TYPE_USER, userDictionary); + addOrReplaceDictionaryInternal(Dictionary.TYPE_USER, userDictionary); } /** @@ -166,18 +185,18 @@ public final class Suggest { */ public void setContactsDictionary(final ContactsBinaryDictionary contactsDictionary) { mContactsDict = contactsDictionary; - addOrReplaceDictionary(mDictionaries, Dictionary.TYPE_CONTACTS, contactsDictionary); + addOrReplaceDictionaryInternal(Dictionary.TYPE_CONTACTS, contactsDictionary); } public void setUserHistoryPredictionDictionary( final UserHistoryPredictionDictionary userHistoryPredictionDictionary) { - addOrReplaceDictionary(mDictionaries, Dictionary.TYPE_USER_HISTORY, + addOrReplaceDictionaryInternal(Dictionary.TYPE_USER_HISTORY, userHistoryPredictionDictionary); } public void setPersonalizationPredictionDictionary( final PersonalizationPredictionDictionary personalizationPredictionDictionary) { - addOrReplaceDictionary(mDictionaries, Dictionary.TYPE_PERSONALIZATION_PREDICTION_IN_JAVA, + addOrReplaceDictionaryInternal(Dictionary.TYPE_PERSONALIZATION_PREDICTION_IN_JAVA, personalizationPredictionDictionary); } diff --git a/java/src/com/android/inputmethod/latin/settings/DebugSettings.java b/java/src/com/android/inputmethod/latin/settings/DebugSettings.java index e675f428e..b1cd88729 100644 --- a/java/src/com/android/inputmethod/latin/settings/DebugSettings.java +++ b/java/src/com/android/inputmethod/latin/settings/DebugSettings.java @@ -37,6 +37,8 @@ public final class DebugSettings extends PreferenceFragment public static final String PREF_FORCE_NON_DISTINCT_MULTITOUCH = "force_non_distinct_multitouch"; public static final String PREF_USABILITY_STUDY_MODE = "usability_study_mode"; public static final String PREF_STATISTICS_LOGGING = "enable_logging"; + public static final String PREF_USE_ONLY_PERSONALIZATION_DICTIONARY_FOR_DEBUG = + "use_only_personalization_dictionary_for_debug"; private static final String PREF_READ_EXTERNAL_DICTIONARY = "read_external_dictionary"; private static final boolean SHOW_STATISTICS_LOGGING = false; @@ -66,7 +68,7 @@ public final class DebugSettings extends PreferenceFragment } } - PreferenceScreen readExternalDictionary = + final PreferenceScreen readExternalDictionary = (PreferenceScreen) findPreference(PREF_READ_EXTERNAL_DICTIONARY); if (null != readExternalDictionary) { readExternalDictionary.setOnPreferenceClickListener( @@ -111,6 +113,8 @@ public final class DebugSettings extends PreferenceFragment } else if (key.equals(PREF_FORCE_NON_DISTINCT_MULTITOUCH) || key.equals(KeyboardSwitcher.PREF_KEYBOARD_LAYOUT)) { mServiceNeedsRestart = true; + } else if (key.equals(PREF_USE_ONLY_PERSONALIZATION_DICTIONARY_FOR_DEBUG)) { + mServiceNeedsRestart = true; } } diff --git a/java/src/com/android/inputmethod/latin/settings/Settings.java b/java/src/com/android/inputmethod/latin/settings/Settings.java index 2631cd317..e6a0c07d7 100644 --- a/java/src/com/android/inputmethod/latin/settings/Settings.java +++ b/java/src/com/android/inputmethod/latin/settings/Settings.java @@ -324,4 +324,10 @@ public final class Settings implements SharedPreferences.OnSharedPreferenceChang public static boolean isInternal(final SharedPreferences prefs) { return prefs.getBoolean(Settings.PREF_KEY_IS_INTERNAL, false); } + + public static boolean readUseOnlyPersonalizationDictionaryForDebug( + final SharedPreferences prefs) { + return prefs.getBoolean( + DebugSettings.PREF_USE_ONLY_PERSONALIZATION_DICTIONARY_FOR_DEBUG, false); + } }