Add a debug preference for using only personalization dictionary
Bug: 9429906 Change-Id: I2003060c7065e736d42f3b3303fbba549358dd18
This commit is contained in:
parent
ed56ea86d0
commit
d7491e6e81
5 changed files with 48 additions and 11 deletions
|
@ -428,6 +428,8 @@
|
|||
<string name="prefs_keypress_sound_volume_settings">Keypress sound volume</string>
|
||||
<!-- Title of the settings for reading an external dictionary file -->
|
||||
<string name="prefs_read_external_dictionary">Read external dictionary file</string>
|
||||
<!-- Title of the settings for using only personalization dictionary -->
|
||||
<string name="prefs_use_only_personalization_dictionary" translatable="false">Use only personalization dictionary</string>
|
||||
<!-- Message to show when there are no files to install as an external dictionary [CHAR LIMIT=100] -->
|
||||
<string name="read_external_dictionary_no_files_message">No dictionary files in the Downloads folder</string>
|
||||
<!-- Title of the dialog that selects a file to install as an external dictionary [CHAR LIMIT=50] -->
|
||||
|
|
|
@ -51,6 +51,12 @@
|
|||
android:persistent="true"
|
||||
android:defaultValue="false" />
|
||||
|
||||
<CheckBoxPreference
|
||||
android:defaultValue="false"
|
||||
android:key="use_only_personalization_dictionary"
|
||||
android:persistent="true"
|
||||
android:title="@string/prefs_use_only_personalization_dictionary_for_debug" />
|
||||
|
||||
<PreferenceScreen
|
||||
android:key="read_external_dictionary"
|
||||
android:title="@string/prefs_read_external_dictionary" />
|
||||
|
|
|
@ -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<String, Dictionary> mDictionaries =
|
||||
CollectionUtils.newConcurrentHashMap();
|
||||
private HashSet<String> 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<String>();
|
||||
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<String, Dictionary> 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);
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue