Add prefix to the arguments of getDictionary().

Bug: 13630847
Change-Id: Ib4513b8cb6981e01dd33fd9703cc01646a2c7ccc
This commit is contained in:
Keisuke Kuroyanagi 2014-06-10 18:05:10 +09:00
parent 1ffb7cd448
commit 18df192535
6 changed files with 24 additions and 21 deletions

View file

@ -74,11 +74,6 @@ public class ContactsBinaryDictionary extends ExpandableBinaryDictionary {
*/
private final boolean mUseFirstLastBigrams;
private ContactsBinaryDictionary(final Context context, final Locale locale,
final File dictFile) {
this(context, locale, dictFile, NAME);
}
protected ContactsBinaryDictionary(final Context context, final Locale locale,
final File dictFile, final String name) {
super(context, getDictName(name, locale, dictFile), locale, Dictionary.TYPE_CONTACTS,
@ -90,8 +85,8 @@ public class ContactsBinaryDictionary extends ExpandableBinaryDictionary {
@UsedForTesting
public static ContactsBinaryDictionary getDictionary(final Context context, final Locale locale,
final File dictFile) {
return new ContactsBinaryDictionary(context, locale, dictFile);
final File dictFile, final String dictNamePrefix) {
return new ContactsBinaryDictionary(context, locale, dictFile, dictNamePrefix + NAME);
}
private synchronized void registerObserver(final Context context) {

View file

@ -87,7 +87,7 @@ public class DictionaryFacilitator {
private static final String DICT_FACTORY_METHOD_NAME = "getDictionary";
private static final Class<?>[] DICT_FACTORY_METHOD_ARG_TYPES =
new Class[] { Context.class, Locale.class, File.class };
new Class[] { Context.class, Locale.class, File.class, String.class };
private static final String[] SUB_DICT_TYPES =
Arrays.copyOfRange(DICT_TYPES_ORDERED_TO_GET_SUGGESTIONS, 1 /* start */,
@ -185,7 +185,8 @@ public class DictionaryFacilitator {
}
private static ExpandableBinaryDictionary getSubDict(final String dictType,
final Context context, final Locale locale, final File dictFile) {
final Context context, final Locale locale, final File dictFile,
final String dictNamePrefix) {
final Class<? extends ExpandableBinaryDictionary> dictClass =
DICT_TYPE_TO_CLASS.get(dictType);
if (dictClass == null) {
@ -195,7 +196,7 @@ public class DictionaryFacilitator {
final Method factoryMethod = dictClass.getMethod(DICT_FACTORY_METHOD_NAME,
DICT_FACTORY_METHOD_ARG_TYPES);
final Object dict = factoryMethod.invoke(null /* obj */,
new Object[] { context, locale, dictFile });
new Object[] { context, locale, dictFile, dictNamePrefix });
return (ExpandableBinaryDictionary) dict;
} catch (final NoSuchMethodException | SecurityException | IllegalAccessException
| IllegalArgumentException | InvocationTargetException e) {
@ -208,6 +209,15 @@ public class DictionaryFacilitator {
final boolean useContactsDict, final boolean usePersonalizedDicts,
final boolean forceReloadMainDictionary,
final DictionaryInitializationListener listener) {
resetDictionariesWithDictNamePrefix(context, newLocale, useContactsDict,
usePersonalizedDicts, forceReloadMainDictionary, listener, "" /* dictNamePrefix */);
}
public void resetDictionariesWithDictNamePrefix(final Context context, final Locale newLocale,
final boolean useContactsDict, final boolean usePersonalizedDicts,
final boolean forceReloadMainDictionary,
final DictionaryInitializationListener listener,
final String dictNamePrefix) {
final boolean localeHasBeenChanged = !newLocale.equals(mDictionaries.mLocale);
// We always try to have the main dictionary. Other dictionaries can be unused.
final boolean reloadMainDictionary = localeHasBeenChanged || forceReloadMainDictionary;
@ -243,7 +253,8 @@ public class DictionaryFacilitator {
dict = mDictionaries.getSubDict(dictType);
} else {
// Start to use new dictionary.
dict = getSubDict(dictType, context, newLocale, null /* dictFile */);
dict = getSubDict(dictType, context, newLocale, null /* dictFile */,
dictNamePrefix);
}
subDicts.put(dictType, dict);
}
@ -312,7 +323,7 @@ public class DictionaryFacilitator {
} else {
final File dictFile = dictionaryFiles.get(dictType);
final ExpandableBinaryDictionary dict = getSubDict(
dictType, context, locale, dictFile);
dictType, context, locale, dictFile, "" /* dictNamePrefix */);
if (additionalDictAttributes.containsKey(dictType)) {
dict.clearAndFlushDictionaryWithAdditionalAttributes(
additionalDictAttributes.get(dictType));

View file

@ -67,10 +67,6 @@ public class UserBinaryDictionary extends ExpandableBinaryDictionary {
final private String mLocale;
final private boolean mAlsoUseMoreRestrictiveLocales;
private UserBinaryDictionary(final Context context, final Locale locale, final File dictFile) {
this(context, locale, false /* alsoUseMoreRestrictiveLocales */, dictFile, NAME);
}
protected UserBinaryDictionary(final Context context, final Locale locale,
final boolean alsoUseMoreRestrictiveLocales, final File dictFile, final String name) {
super(context, getDictName(name, locale, dictFile), locale, Dictionary.TYPE_USER, dictFile);
@ -107,8 +103,9 @@ public class UserBinaryDictionary extends ExpandableBinaryDictionary {
@UsedForTesting
public static UserBinaryDictionary getDictionary(final Context context, final Locale locale,
final File dictFile) {
return new UserBinaryDictionary(context, locale, dictFile);
final File dictFile, final String dictNamePrefix) {
return new UserBinaryDictionary(context, locale, false /* alsoUseMoreRestrictiveLocales */,
dictFile, dictNamePrefix + NAME);
}
@Override

View file

@ -37,7 +37,7 @@ public class ContextualDictionary extends ExpandableBinaryDictionary {
}
@UsedForTesting
public static ContextualDictionary getDictionary(final Context context, final Locale locale,
final File dictFile) {
final File dictFile, final String dictNamePrefix) {
return new ContextualDictionary(context, locale, dictFile);
}

View file

@ -35,7 +35,7 @@ public class PersonalizationDictionary extends DecayingExpandableBinaryDictionar
@UsedForTesting
public static PersonalizationDictionary getDictionary(final Context context,
final Locale locale, final File dictFile) {
final Locale locale, final File dictFile, final String dictNamePrefix) {
return PersonalizationHelper.getPersonalizationDictionary(context, locale);
}
}

View file

@ -43,7 +43,7 @@ public class UserHistoryDictionary extends DecayingExpandableBinaryDictionaryBas
@UsedForTesting
public static UserHistoryDictionary getDictionary(final Context context, final Locale locale,
final File dictFile) {
final File dictFile, final String dictNamePrefix) {
return PersonalizationHelper.getUserHistoryDictionary(context, locale);
}