am 64ead8d2: Merge "Add required header attributes for user/contacts dictionary."

* commit '64ead8d29311cfb55b43f1ace9f3be6da200f9c1':
  Add required header attributes for user/contacts dictionary.
main
Ken Wakasa 2013-12-03 02:27:54 -08:00 committed by Android Git Automerger
commit b7bfd79eba
12 changed files with 77 additions and 62 deletions

View File

@ -72,8 +72,8 @@ public class ContactsBinaryDictionary extends ExpandableBinaryDictionary {
private final boolean mUseFirstLastBigrams; private final boolean mUseFirstLastBigrams;
public ContactsBinaryDictionary(final Context context, final Locale locale) { public ContactsBinaryDictionary(final Context context, final Locale locale) {
super(context, getFilenameWithLocale(NAME, locale.toString()), Dictionary.TYPE_CONTACTS, super(context, getFilenameWithLocale(NAME, locale), locale,
false /* isUpdatable */); Dictionary.TYPE_CONTACTS, false /* isUpdatable */);
mLocale = locale; mLocale = locale;
mUseFirstLastBigrams = useFirstLastBigramsForLocale(locale); mUseFirstLastBigrams = useFirstLastBigramsForLocale(locale);
registerObserver(context); registerObserver(context);

View File

@ -33,8 +33,10 @@ import com.android.inputmethod.latin.utils.StringUtils;
import java.io.File; import java.io.File;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.Locale;
import java.util.Map; import java.util.Map;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicReference; import java.util.concurrent.atomic.AtomicReference;
@ -99,6 +101,9 @@ abstract public class ExpandableBinaryDictionary extends Dictionary {
*/ */
private final String mFilename; private final String mFilename;
/** Dictionary locale */
private final Locale mLocale;
/** Whether to support dynamically updating the dictionary */ /** Whether to support dynamically updating the dictionary */
private final boolean mIsUpdatable; private final boolean mIsUpdatable;
@ -183,15 +188,17 @@ abstract public class ExpandableBinaryDictionary extends Dictionary {
* @param context The application context of the parent. * @param context The application context of the parent.
* @param filename The filename for this binary dictionary. Multiple dictionaries with the same * @param filename The filename for this binary dictionary. Multiple dictionaries with the same
* filename is supported. * filename is supported.
* @param locale the dictionary locale.
* @param dictType the dictionary type, as a human-readable string * @param dictType the dictionary type, as a human-readable string
* @param isUpdatable whether to support dynamically updating the dictionary. Please note that * @param isUpdatable whether to support dynamically updating the dictionary. Please note that
* dynamic dictionary has negative effects on memory space and computation time. * dynamic dictionary has negative effects on memory space and computation time.
*/ */
public ExpandableBinaryDictionary(final Context context, final String filename, public ExpandableBinaryDictionary(final Context context, final String filename,
final String dictType, final boolean isUpdatable) { final Locale locale, final String dictType, final boolean isUpdatable) {
super(dictType); super(dictType);
mFilename = filename; mFilename = filename;
mContext = context; mContext = context;
mLocale = locale;
mIsUpdatable = isUpdatable; mIsUpdatable = isUpdatable;
mBinaryDictionary = null; mBinaryDictionary = null;
mFilenameDictionaryUpdateController = getDictionaryUpdateController(filename); mFilenameDictionaryUpdateController = getDictionaryUpdateController(filename);
@ -199,8 +206,8 @@ abstract public class ExpandableBinaryDictionary extends Dictionary {
mDictionaryWriter = getDictionaryWriter(context, dictType, isUpdatable); mDictionaryWriter = getDictionaryWriter(context, dictType, isUpdatable);
} }
protected static String getFilenameWithLocale(final String name, final String localeStr) { protected static String getFilenameWithLocale(final String name, final Locale locale) {
return name + "." + localeStr + DICT_FILE_EXTENSION; return name + "." + locale.toString() + DICT_FILE_EXTENSION;
} }
/** /**
@ -237,9 +244,10 @@ abstract public class ExpandableBinaryDictionary extends Dictionary {
protected Map<String, String> getHeaderAttributeMap() { protected Map<String, String> getHeaderAttributeMap() {
HashMap<String, String> attributeMap = new HashMap<String, String>(); HashMap<String, String> attributeMap = new HashMap<String, String>();
attributeMap.put(FormatSpec.FileHeader.SUPPORTS_DYNAMIC_UPDATE_ATTRIBUTE,
SUPPORTS_DYNAMIC_UPDATE);
attributeMap.put(FormatSpec.FileHeader.DICTIONARY_ID_ATTRIBUTE, mFilename); attributeMap.put(FormatSpec.FileHeader.DICTIONARY_ID_ATTRIBUTE, mFilename);
attributeMap.put(FormatSpec.FileHeader.DICTIONARY_LOCALE_ATTRIBUTE, mLocale.toString());
attributeMap.put(FormatSpec.FileHeader.DICTIONARY_VERSION_ATTRIBUTE,
String.valueOf(TimeUnit.MILLISECONDS.toSeconds(System.currentTimeMillis())));
return attributeMap; return attributeMap;
} }

View File

@ -614,7 +614,6 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
final Locale switcherSubtypeLocale = mSubtypeSwitcher.getCurrentSubtypeLocale(); final Locale switcherSubtypeLocale = mSubtypeSwitcher.getCurrentSubtypeLocale();
final String switcherLocaleStr = switcherSubtypeLocale.toString(); final String switcherLocaleStr = switcherSubtypeLocale.toString();
final Locale subtypeLocale; final Locale subtypeLocale;
final String localeStr;
if (TextUtils.isEmpty(switcherLocaleStr)) { if (TextUtils.isEmpty(switcherLocaleStr)) {
// This happens in very rare corner cases - for example, immediately after a switch // This happens in very rare corner cases - for example, immediately after a switch
// to LatinIME has been requested, about a frame later another switch happens. In this // to LatinIME has been requested, about a frame later another switch happens. In this
@ -624,10 +623,8 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
// of knowing anyway. // of knowing anyway.
Log.e(TAG, "System is reporting no current subtype."); Log.e(TAG, "System is reporting no current subtype.");
subtypeLocale = getResources().getConfiguration().locale; subtypeLocale = getResources().getConfiguration().locale;
localeStr = subtypeLocale.toString();
} else { } else {
subtypeLocale = switcherSubtypeLocale; subtypeLocale = switcherSubtypeLocale;
localeStr = switcherLocaleStr;
} }
final Suggest newSuggest = new Suggest(this /* Context */, subtypeLocale, final Suggest newSuggest = new Suggest(this /* Context */, subtypeLocale,
@ -642,19 +639,20 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
ResearchLogger.getInstance().initSuggest(newSuggest); ResearchLogger.getInstance().initSuggest(newSuggest);
} }
mUserDictionary = new UserBinaryDictionary(this, localeStr); mUserDictionary = new UserBinaryDictionary(this, subtypeLocale);
mIsUserDictionaryAvailable = mUserDictionary.isEnabled(); mIsUserDictionaryAvailable = mUserDictionary.isEnabled();
newSuggest.setUserDictionary(mUserDictionary); newSuggest.setUserDictionary(mUserDictionary);
final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
mUserHistoryDictionary = PersonalizationHelper.getUserHistoryDictionary(this, localeStr); mUserHistoryDictionary = PersonalizationHelper.getUserHistoryDictionary(
this, subtypeLocale);
newSuggest.setUserHistoryDictionary(mUserHistoryDictionary); newSuggest.setUserHistoryDictionary(mUserHistoryDictionary);
mPersonalizationDictionary = mPersonalizationDictionary =
PersonalizationHelper.getPersonalizationDictionary(this, localeStr); PersonalizationHelper.getPersonalizationDictionary(this, subtypeLocale);
newSuggest.setPersonalizationDictionary(mPersonalizationDictionary); newSuggest.setPersonalizationDictionary(mPersonalizationDictionary);
mPersonalizationPredictionDictionary = mPersonalizationPredictionDictionary =
PersonalizationHelper.getPersonalizationPredictionDictionary(this, localeStr); PersonalizationHelper.getPersonalizationPredictionDictionary(this, subtypeLocale);
newSuggest.setPersonalizationPredictionDictionary(mPersonalizationPredictionDictionary); newSuggest.setPersonalizationPredictionDictionary(mPersonalizationPredictionDictionary);
final Suggest oldSuggest = mSuggest; final Suggest oldSuggest = mSuggest;

View File

@ -22,14 +22,15 @@ import com.android.inputmethod.keyboard.ProximityInfo;
import com.android.inputmethod.latin.SuggestedWords.SuggestedWordInfo; import com.android.inputmethod.latin.SuggestedWords.SuggestedWordInfo;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Locale;
public final class SynchronouslyLoadedUserBinaryDictionary extends UserBinaryDictionary { public final class SynchronouslyLoadedUserBinaryDictionary extends UserBinaryDictionary {
public SynchronouslyLoadedUserBinaryDictionary(final Context context, final String locale) { public SynchronouslyLoadedUserBinaryDictionary(final Context context, final Locale locale) {
this(context, locale, false); this(context, locale, false);
} }
public SynchronouslyLoadedUserBinaryDictionary(final Context context, final String locale, public SynchronouslyLoadedUserBinaryDictionary(final Context context, final Locale locale,
final boolean alsoUseMoreRestrictiveLocales) { final boolean alsoUseMoreRestrictiveLocales) {
super(context, locale, alsoUseMoreRestrictiveLocales); super(context, locale, alsoUseMoreRestrictiveLocales);
} }

View File

@ -75,20 +75,21 @@ public class UserBinaryDictionary extends ExpandableBinaryDictionary {
final private String mLocale; final private String mLocale;
final private boolean mAlsoUseMoreRestrictiveLocales; final private boolean mAlsoUseMoreRestrictiveLocales;
public UserBinaryDictionary(final Context context, final String locale) { public UserBinaryDictionary(final Context context, final Locale locale) {
this(context, locale, false); this(context, locale, false);
} }
public UserBinaryDictionary(final Context context, final String locale, public UserBinaryDictionary(final Context context, final Locale locale,
final boolean alsoUseMoreRestrictiveLocales) { final boolean alsoUseMoreRestrictiveLocales) {
super(context, getFilenameWithLocale(NAME, locale), Dictionary.TYPE_USER, super(context, getFilenameWithLocale(NAME, locale), locale, Dictionary.TYPE_USER,
false /* isUpdatable */); false /* isUpdatable */);
if (null == locale) throw new NullPointerException(); // Catch the error earlier if (null == locale) throw new NullPointerException(); // Catch the error earlier
if (SubtypeLocaleUtils.NO_LANGUAGE.equals(locale)) { final String localeStr = locale.toString();
if (SubtypeLocaleUtils.NO_LANGUAGE.equals(localeStr)) {
// If we don't have a locale, insert into the "all locales" user dictionary. // If we don't have a locale, insert into the "all locales" user dictionary.
mLocale = USER_DICTIONARY_ALL_LANGUAGES; mLocale = USER_DICTIONARY_ALL_LANGUAGES;
} else { } else {
mLocale = locale; mLocale = localeStr;
} }
mAlsoUseMoreRestrictiveLocales = alsoUseMoreRestrictiveLocales; mAlsoUseMoreRestrictiveLocales = alsoUseMoreRestrictiveLocales;
// Perform a managed query. The Activity will handle closing and re-querying the cursor // Perform a managed query. The Activity will handle closing and re-querying the cursor

View File

@ -35,7 +35,9 @@ import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.Locale;
import java.util.Map; import java.util.Map;
import java.util.concurrent.TimeUnit;
/** /**
* This class is a base class of a dictionary that supports decaying for the personalized language * This class is a base class of a dictionary that supports decaying for the personalized language
@ -55,7 +57,7 @@ public abstract class DecayingExpandableBinaryDictionaryBase extends ExpandableB
public static final int REQUIRED_BINARY_DICTIONARY_VERSION = 4; public static final int REQUIRED_BINARY_DICTIONARY_VERSION = 4;
/** Locale for which this user history dictionary is storing words */ /** Locale for which this user history dictionary is storing words */
private final String mLocale; private final Locale mLocale;
private final String mFileName; private final String mFileName;
@ -66,11 +68,11 @@ public abstract class DecayingExpandableBinaryDictionaryBase extends ExpandableB
@UsedForTesting boolean mIsTest = false; @UsedForTesting boolean mIsTest = false;
/* package */ DecayingExpandableBinaryDictionaryBase(final Context context, /* package */ DecayingExpandableBinaryDictionaryBase(final Context context,
final String locale, final String dictionaryType, final String fileName) { final Locale locale, final String dictionaryType, final String fileName) {
super(context, fileName, dictionaryType, true); super(context, fileName, locale, dictionaryType, true);
mLocale = locale; mLocale = locale;
mFileName = fileName; mFileName = fileName;
if (mLocale != null && mLocale.length() > 1) { if (mLocale != null && mLocale.toString().length() > 1) {
reloadDictionaryIfRequired(); reloadDictionaryIfRequired();
} }
} }
@ -93,7 +95,9 @@ public abstract class DecayingExpandableBinaryDictionaryBase extends ExpandableB
attributeMap.put(FormatSpec.FileHeader.USES_FORGETTING_CURVE_ATTRIBUTE, attributeMap.put(FormatSpec.FileHeader.USES_FORGETTING_CURVE_ATTRIBUTE,
FormatSpec.FileHeader.ATTRIBUTE_VALUE_TRUE); FormatSpec.FileHeader.ATTRIBUTE_VALUE_TRUE);
attributeMap.put(FormatSpec.FileHeader.DICTIONARY_ID_ATTRIBUTE, mFileName); attributeMap.put(FormatSpec.FileHeader.DICTIONARY_ID_ATTRIBUTE, mFileName);
attributeMap.put(FormatSpec.FileHeader.DICTIONARY_LOCALE_ATTRIBUTE, mLocale); attributeMap.put(FormatSpec.FileHeader.DICTIONARY_LOCALE_ATTRIBUTE, mLocale.toString());
attributeMap.put(FormatSpec.FileHeader.DICTIONARY_VERSION_ATTRIBUTE,
String.valueOf(TimeUnit.MILLISECONDS.toSeconds(System.currentTimeMillis())));
return attributeMap; return attributeMap;
} }
@ -164,10 +168,6 @@ public abstract class DecayingExpandableBinaryDictionaryBase extends ExpandableB
// Never loaded to memory in Java side. // Never loaded to memory in Java side.
} }
protected String getLocale() {
return mLocale;
}
public void registerUpdateSession(PersonalizationDictionaryUpdateSession session) { public void registerUpdateSession(PersonalizationDictionaryUpdateSession session) {
session.setPredictionDictionary(this); session.setPredictionDictionary(this);
mSessions.add(session); mSessions.add(session);

View File

@ -21,9 +21,9 @@ import com.android.inputmethod.latin.ExpandableBinaryDictionary;
import com.android.inputmethod.latin.utils.CollectionUtils; import com.android.inputmethod.latin.utils.CollectionUtils;
import android.content.Context; import android.content.Context;
import android.content.SharedPreferences;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Locale;
/** /**
* This class is a dictionary for the personalized language model that uses binary dictionary. * This class is a dictionary for the personalized language model that uses binary dictionary.
@ -33,14 +33,10 @@ public class PersonalizationDictionary extends ExpandableBinaryDictionary {
private final ArrayList<PersonalizationDictionaryUpdateSession> mSessions = private final ArrayList<PersonalizationDictionaryUpdateSession> mSessions =
CollectionUtils.newArrayList(); CollectionUtils.newArrayList();
/** Locale for which this user history dictionary is storing words */ public PersonalizationDictionary(final Context context, final Locale locale) {
private final String mLocale;
public PersonalizationDictionary(final Context context, final String locale) {
// TODO: Make isUpdatable true. // TODO: Make isUpdatable true.
super(context, getFilenameWithLocale(NAME, locale), Dictionary.TYPE_PERSONALIZATION, super(context, getFilenameWithLocale(NAME, locale), locale,
false /* isUpdatable */); Dictionary.TYPE_PERSONALIZATION, false /* isUpdatable */);
mLocale = locale;
// TODO: Restore last updated time // TODO: Restore last updated time
loadDictionary(); loadDictionary();
} }

View File

@ -24,6 +24,7 @@ import android.preference.PreferenceManager;
import android.util.Log; import android.util.Log;
import java.lang.ref.SoftReference; import java.lang.ref.SoftReference;
import java.util.Locale;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
public class PersonalizationHelper { public class PersonalizationHelper {
@ -41,11 +42,12 @@ public class PersonalizationHelper {
CollectionUtils.newConcurrentHashMap(); CollectionUtils.newConcurrentHashMap();
public static UserHistoryDictionary getUserHistoryDictionary( public static UserHistoryDictionary getUserHistoryDictionary(
final Context context, final String locale) { final Context context, final Locale locale) {
final String localeStr = locale.toString();
synchronized (sLangUserHistoryDictCache) { synchronized (sLangUserHistoryDictCache) {
if (sLangUserHistoryDictCache.containsKey(locale)) { if (sLangUserHistoryDictCache.containsKey(localeStr)) {
final SoftReference<UserHistoryDictionary> ref = final SoftReference<UserHistoryDictionary> ref =
sLangUserHistoryDictCache.get(locale); sLangUserHistoryDictCache.get(localeStr);
final UserHistoryDictionary dict = ref == null ? null : ref.get(); final UserHistoryDictionary dict = ref == null ? null : ref.get();
if (dict != null) { if (dict != null) {
if (DEBUG) { if (DEBUG) {
@ -56,7 +58,8 @@ public class PersonalizationHelper {
} }
} }
final UserHistoryDictionary dict = new UserHistoryDictionary(context, locale); final UserHistoryDictionary dict = new UserHistoryDictionary(context, locale);
sLangUserHistoryDictCache.put(locale, new SoftReference<UserHistoryDictionary>(dict)); sLangUserHistoryDictCache.put(localeStr,
new SoftReference<UserHistoryDictionary>(dict));
return dict; return dict;
} }
} }
@ -74,7 +77,7 @@ public class PersonalizationHelper {
} }
public static void registerPersonalizationDictionaryUpdateSession(final Context context, public static void registerPersonalizationDictionaryUpdateSession(final Context context,
final PersonalizationDictionaryUpdateSession session, String locale) { final PersonalizationDictionaryUpdateSession session, Locale locale) {
final PersonalizationPredictionDictionary predictionDictionary = final PersonalizationPredictionDictionary predictionDictionary =
getPersonalizationPredictionDictionary(context, locale); getPersonalizationPredictionDictionary(context, locale);
predictionDictionary.registerUpdateSession(session); predictionDictionary.registerUpdateSession(session);
@ -83,11 +86,12 @@ public class PersonalizationHelper {
} }
public static PersonalizationDictionary getPersonalizationDictionary( public static PersonalizationDictionary getPersonalizationDictionary(
final Context context, final String locale) { final Context context, final Locale locale) {
final String localeStr = locale.toString();
synchronized (sLangPersonalizationDictCache) { synchronized (sLangPersonalizationDictCache) {
if (sLangPersonalizationDictCache.containsKey(locale)) { if (sLangPersonalizationDictCache.containsKey(localeStr)) {
final SoftReference<PersonalizationDictionary> ref = final SoftReference<PersonalizationDictionary> ref =
sLangPersonalizationDictCache.get(locale); sLangPersonalizationDictCache.get(localeStr);
final PersonalizationDictionary dict = ref == null ? null : ref.get(); final PersonalizationDictionary dict = ref == null ? null : ref.get();
if (dict != null) { if (dict != null) {
if (DEBUG) { if (DEBUG) {
@ -98,17 +102,18 @@ public class PersonalizationHelper {
} }
final PersonalizationDictionary dict = new PersonalizationDictionary(context, locale); final PersonalizationDictionary dict = new PersonalizationDictionary(context, locale);
sLangPersonalizationDictCache.put( sLangPersonalizationDictCache.put(
locale, new SoftReference<PersonalizationDictionary>(dict)); localeStr, new SoftReference<PersonalizationDictionary>(dict));
return dict; return dict;
} }
} }
public static PersonalizationPredictionDictionary getPersonalizationPredictionDictionary( public static PersonalizationPredictionDictionary getPersonalizationPredictionDictionary(
final Context context, final String locale) { final Context context, final Locale locale) {
final String localeStr = locale.toString();
synchronized (sLangPersonalizationPredictionDictCache) { synchronized (sLangPersonalizationPredictionDictCache) {
if (sLangPersonalizationPredictionDictCache.containsKey(locale)) { if (sLangPersonalizationPredictionDictCache.containsKey(localeStr)) {
final SoftReference<PersonalizationPredictionDictionary> ref = final SoftReference<PersonalizationPredictionDictionary> ref =
sLangPersonalizationPredictionDictCache.get(locale); sLangPersonalizationPredictionDictCache.get(localeStr);
final PersonalizationPredictionDictionary dict = ref == null ? null : ref.get(); final PersonalizationPredictionDictionary dict = ref == null ? null : ref.get();
if (dict != null) { if (dict != null) {
if (DEBUG) { if (DEBUG) {
@ -120,7 +125,7 @@ public class PersonalizationHelper {
final PersonalizationPredictionDictionary dict = final PersonalizationPredictionDictionary dict =
new PersonalizationPredictionDictionary(context, locale); new PersonalizationPredictionDictionary(context, locale);
sLangPersonalizationPredictionDictCache.put( sLangPersonalizationPredictionDictCache.put(
locale, new SoftReference<PersonalizationPredictionDictionary>(dict)); localeStr, new SoftReference<PersonalizationPredictionDictionary>(dict));
return dict; return dict;
} }
} }

View File

@ -19,14 +19,16 @@ package com.android.inputmethod.latin.personalization;
import com.android.inputmethod.latin.Dictionary; import com.android.inputmethod.latin.Dictionary;
import com.android.inputmethod.latin.ExpandableBinaryDictionary; import com.android.inputmethod.latin.ExpandableBinaryDictionary;
import java.util.Locale;
import android.content.Context; import android.content.Context;
public class PersonalizationPredictionDictionary extends DecayingExpandableBinaryDictionaryBase { public class PersonalizationPredictionDictionary extends DecayingExpandableBinaryDictionaryBase {
private static final String NAME = PersonalizationPredictionDictionary.class.getSimpleName(); private static final String NAME = PersonalizationPredictionDictionary.class.getSimpleName();
/* package */ PersonalizationPredictionDictionary(final Context context, final String locale) { /* package */ PersonalizationPredictionDictionary(final Context context, final Locale locale) {
super(context, locale, Dictionary.TYPE_PERSONALIZATION_PREDICTION_IN_JAVA, super(context, locale, Dictionary.TYPE_PERSONALIZATION_PREDICTION_IN_JAVA,
getDictionaryFileName(locale)); getDictionaryFileName(locale.toString()));
} }
private static String getDictionaryFileName(final String locale) { private static String getDictionaryFileName(final String locale) {

View File

@ -19,6 +19,8 @@ package com.android.inputmethod.latin.personalization;
import com.android.inputmethod.latin.Dictionary; import com.android.inputmethod.latin.Dictionary;
import com.android.inputmethod.latin.ExpandableBinaryDictionary; import com.android.inputmethod.latin.ExpandableBinaryDictionary;
import java.util.Locale;
import android.content.Context; import android.content.Context;
/** /**
@ -28,8 +30,9 @@ import android.content.Context;
public class UserHistoryDictionary extends DecayingExpandableBinaryDictionaryBase { public class UserHistoryDictionary extends DecayingExpandableBinaryDictionaryBase {
/* package for tests */ static final String NAME = /* package for tests */ static final String NAME =
UserHistoryDictionary.class.getSimpleName(); UserHistoryDictionary.class.getSimpleName();
/* package */ UserHistoryDictionary(final Context context, final String locale) { /* package */ UserHistoryDictionary(final Context context, final Locale locale) {
super(context, locale, Dictionary.TYPE_USER_HISTORY, getDictionaryFileName(locale)); super(context, locale, Dictionary.TYPE_USER_HISTORY,
getDictionaryFileName(locale.toString()));
} }
private static String getDictionaryFileName(final String locale) { private static String getDictionaryFileName(final String locale) {

View File

@ -428,7 +428,7 @@ public final class AndroidSpellCheckerService extends SpellCheckerService
final String localeStr = locale.toString(); final String localeStr = locale.toString();
UserBinaryDictionary userDictionary = mUserDictionaries.get(localeStr); UserBinaryDictionary userDictionary = mUserDictionaries.get(localeStr);
if (null == userDictionary) { if (null == userDictionary) {
userDictionary = new SynchronouslyLoadedUserBinaryDictionary(this, localeStr, true); userDictionary = new SynchronouslyLoadedUserBinaryDictionary(this, locale, true);
mUserDictionaries.put(localeStr, userDictionary); mUserDictionaries.put(localeStr, userDictionary);
} }
dictionaryCollection.addDictionary(userDictionary); dictionaryCollection.addDictionary(userDictionary);

View File

@ -26,6 +26,7 @@ import com.android.inputmethod.latin.utils.CollectionUtils;
import java.io.File; import java.io.File;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Locale;
import java.util.Random; import java.util.Random;
import java.util.Set; import java.util.Set;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
@ -84,7 +85,7 @@ public class UserHistoryDictionaryTests extends AndroidTestCase {
final List<String> words = generateWords(numberOfWords, random); final List<String> words = generateWords(numberOfWords, random);
final UserHistoryDictionary dict = final UserHistoryDictionary dict =
PersonalizationHelper.getUserHistoryDictionary(getContext(), PersonalizationHelper.getUserHistoryDictionary(getContext(),
testFilenameSuffix /* locale */); new Locale(testFilenameSuffix));
// Add random words to the user history dictionary. // Add random words to the user history dictionary.
addToDict(dict, words); addToDict(dict, words);
if (checkContents) { if (checkContents) {
@ -108,7 +109,7 @@ public class UserHistoryDictionaryTests extends AndroidTestCase {
private void clearHistory(final String testFilenameSuffix) { private void clearHistory(final String testFilenameSuffix) {
final UserHistoryDictionary dict = final UserHistoryDictionary dict =
PersonalizationHelper.getUserHistoryDictionary(getContext(), PersonalizationHelper.getUserHistoryDictionary(getContext(),
testFilenameSuffix /* locale */); new Locale(testFilenameSuffix));
dict.clearAndFlushDictionary(); dict.clearAndFlushDictionary();
dict.close(); dict.close();
} }
@ -121,7 +122,7 @@ public class UserHistoryDictionaryTests extends AndroidTestCase {
try { try {
final UserHistoryDictionary dict = final UserHistoryDictionary dict =
PersonalizationHelper.getUserHistoryDictionary(getContext(), PersonalizationHelper.getUserHistoryDictionary(getContext(),
testFilenameSuffix); new Locale(testFilenameSuffix));
dict.shutdownExecutorForTests(); dict.shutdownExecutorForTests();
while (!dict.isTerminatedForTests()) { while (!dict.isTerminatedForTests()) {
Thread.sleep(WAIT_TERMINATING_IN_MILLISECONDS); Thread.sleep(WAIT_TERMINATING_IN_MILLISECONDS);
@ -134,7 +135,7 @@ public class UserHistoryDictionaryTests extends AndroidTestCase {
public void testRandomWords() { public void testRandomWords() {
Log.d(TAG, "This test can be used for profiling."); Log.d(TAG, "This test can be used for profiling.");
Log.d(TAG, "Usage: please set UserHistoryDictionary.PROFILE_SAVE_RESTORE to true."); Log.d(TAG, "Usage: please set UserHistoryDictionary.PROFILE_SAVE_RESTORE to true.");
final String testFilenameSuffix = "testRandomWords" + System.currentTimeMillis(); final String testFilenameSuffix = "test_random_words" + System.currentTimeMillis();
final String fileName = UserHistoryDictionary.NAME + "." + testFilenameSuffix final String fileName = UserHistoryDictionary.NAME + "." + testFilenameSuffix
+ ExpandableBinaryDictionary.DICT_FILE_EXTENSION; + ExpandableBinaryDictionary.DICT_FILE_EXTENSION;
@ -169,7 +170,7 @@ public class UserHistoryDictionaryTests extends AndroidTestCase {
// Create filename suffixes for this test. // Create filename suffixes for this test.
for (int i = 0; i < numberOfLanguages; i++) { for (int i = 0; i < numberOfLanguages; i++) {
testFilenameSuffixes[i] = "testSwitchingLanguages" + i; testFilenameSuffixes[i] = "test_switching_languages" + i;
final String fileName = UserHistoryDictionary.NAME + "." + final String fileName = UserHistoryDictionary.NAME + "." +
testFilenameSuffixes[i] + ExpandableBinaryDictionary.DICT_FILE_EXTENSION; testFilenameSuffixes[i] + ExpandableBinaryDictionary.DICT_FILE_EXTENSION;
dictFiles[i] = new File(getContext().getFilesDir(), fileName); dictFiles[i] = new File(getContext().getFilesDir(), fileName);
@ -205,7 +206,7 @@ public class UserHistoryDictionaryTests extends AndroidTestCase {
} }
public void testAddManyWords() { public void testAddManyWords() {
final String testFilenameSuffix = "testRandomWords" + System.currentTimeMillis(); final String testFilenameSuffix = "test_random_words" + System.currentTimeMillis();
final int numberOfWords = 10000; final int numberOfWords = 10000;
final Random random = new Random(123456); final Random random = new Random(123456);
clearHistory(testFilenameSuffix); clearHistory(testFilenameSuffix);