Add prefix to the arguments of getDictionary().
Bug: 13630847 Change-Id: Ib4513b8cb6981e01dd33fd9703cc01646a2c7cccmain
parent
1ffb7cd448
commit
18df192535
|
@ -74,11 +74,6 @@ public class ContactsBinaryDictionary extends ExpandableBinaryDictionary {
|
||||||
*/
|
*/
|
||||||
private final boolean mUseFirstLastBigrams;
|
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,
|
protected ContactsBinaryDictionary(final Context context, final Locale locale,
|
||||||
final File dictFile, final String name) {
|
final File dictFile, final String name) {
|
||||||
super(context, getDictName(name, locale, dictFile), locale, Dictionary.TYPE_CONTACTS,
|
super(context, getDictName(name, locale, dictFile), locale, Dictionary.TYPE_CONTACTS,
|
||||||
|
@ -90,8 +85,8 @@ public class ContactsBinaryDictionary extends ExpandableBinaryDictionary {
|
||||||
|
|
||||||
@UsedForTesting
|
@UsedForTesting
|
||||||
public static ContactsBinaryDictionary getDictionary(final Context context, final Locale locale,
|
public static ContactsBinaryDictionary getDictionary(final Context context, final Locale locale,
|
||||||
final File dictFile) {
|
final File dictFile, final String dictNamePrefix) {
|
||||||
return new ContactsBinaryDictionary(context, locale, dictFile);
|
return new ContactsBinaryDictionary(context, locale, dictFile, dictNamePrefix + NAME);
|
||||||
}
|
}
|
||||||
|
|
||||||
private synchronized void registerObserver(final Context context) {
|
private synchronized void registerObserver(final Context context) {
|
||||||
|
|
|
@ -87,7 +87,7 @@ public class DictionaryFacilitator {
|
||||||
|
|
||||||
private static final String DICT_FACTORY_METHOD_NAME = "getDictionary";
|
private static final String DICT_FACTORY_METHOD_NAME = "getDictionary";
|
||||||
private static final Class<?>[] DICT_FACTORY_METHOD_ARG_TYPES =
|
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 =
|
private static final String[] SUB_DICT_TYPES =
|
||||||
Arrays.copyOfRange(DICT_TYPES_ORDERED_TO_GET_SUGGESTIONS, 1 /* start */,
|
Arrays.copyOfRange(DICT_TYPES_ORDERED_TO_GET_SUGGESTIONS, 1 /* start */,
|
||||||
|
@ -185,7 +185,8 @@ public class DictionaryFacilitator {
|
||||||
}
|
}
|
||||||
|
|
||||||
private static ExpandableBinaryDictionary getSubDict(final String dictType,
|
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 =
|
final Class<? extends ExpandableBinaryDictionary> dictClass =
|
||||||
DICT_TYPE_TO_CLASS.get(dictType);
|
DICT_TYPE_TO_CLASS.get(dictType);
|
||||||
if (dictClass == null) {
|
if (dictClass == null) {
|
||||||
|
@ -195,7 +196,7 @@ public class DictionaryFacilitator {
|
||||||
final Method factoryMethod = dictClass.getMethod(DICT_FACTORY_METHOD_NAME,
|
final Method factoryMethod = dictClass.getMethod(DICT_FACTORY_METHOD_NAME,
|
||||||
DICT_FACTORY_METHOD_ARG_TYPES);
|
DICT_FACTORY_METHOD_ARG_TYPES);
|
||||||
final Object dict = factoryMethod.invoke(null /* obj */,
|
final Object dict = factoryMethod.invoke(null /* obj */,
|
||||||
new Object[] { context, locale, dictFile });
|
new Object[] { context, locale, dictFile, dictNamePrefix });
|
||||||
return (ExpandableBinaryDictionary) dict;
|
return (ExpandableBinaryDictionary) dict;
|
||||||
} catch (final NoSuchMethodException | SecurityException | IllegalAccessException
|
} catch (final NoSuchMethodException | SecurityException | IllegalAccessException
|
||||||
| IllegalArgumentException | InvocationTargetException e) {
|
| IllegalArgumentException | InvocationTargetException e) {
|
||||||
|
@ -208,6 +209,15 @@ public class DictionaryFacilitator {
|
||||||
final boolean useContactsDict, final boolean usePersonalizedDicts,
|
final boolean useContactsDict, final boolean usePersonalizedDicts,
|
||||||
final boolean forceReloadMainDictionary,
|
final boolean forceReloadMainDictionary,
|
||||||
final DictionaryInitializationListener listener) {
|
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);
|
final boolean localeHasBeenChanged = !newLocale.equals(mDictionaries.mLocale);
|
||||||
// We always try to have the main dictionary. Other dictionaries can be unused.
|
// We always try to have the main dictionary. Other dictionaries can be unused.
|
||||||
final boolean reloadMainDictionary = localeHasBeenChanged || forceReloadMainDictionary;
|
final boolean reloadMainDictionary = localeHasBeenChanged || forceReloadMainDictionary;
|
||||||
|
@ -243,7 +253,8 @@ public class DictionaryFacilitator {
|
||||||
dict = mDictionaries.getSubDict(dictType);
|
dict = mDictionaries.getSubDict(dictType);
|
||||||
} else {
|
} else {
|
||||||
// Start to use new dictionary.
|
// Start to use new dictionary.
|
||||||
dict = getSubDict(dictType, context, newLocale, null /* dictFile */);
|
dict = getSubDict(dictType, context, newLocale, null /* dictFile */,
|
||||||
|
dictNamePrefix);
|
||||||
}
|
}
|
||||||
subDicts.put(dictType, dict);
|
subDicts.put(dictType, dict);
|
||||||
}
|
}
|
||||||
|
@ -312,7 +323,7 @@ public class DictionaryFacilitator {
|
||||||
} else {
|
} else {
|
||||||
final File dictFile = dictionaryFiles.get(dictType);
|
final File dictFile = dictionaryFiles.get(dictType);
|
||||||
final ExpandableBinaryDictionary dict = getSubDict(
|
final ExpandableBinaryDictionary dict = getSubDict(
|
||||||
dictType, context, locale, dictFile);
|
dictType, context, locale, dictFile, "" /* dictNamePrefix */);
|
||||||
if (additionalDictAttributes.containsKey(dictType)) {
|
if (additionalDictAttributes.containsKey(dictType)) {
|
||||||
dict.clearAndFlushDictionaryWithAdditionalAttributes(
|
dict.clearAndFlushDictionaryWithAdditionalAttributes(
|
||||||
additionalDictAttributes.get(dictType));
|
additionalDictAttributes.get(dictType));
|
||||||
|
|
|
@ -67,10 +67,6 @@ public class UserBinaryDictionary extends ExpandableBinaryDictionary {
|
||||||
final private String mLocale;
|
final private String mLocale;
|
||||||
final private boolean mAlsoUseMoreRestrictiveLocales;
|
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,
|
protected UserBinaryDictionary(final Context context, final Locale locale,
|
||||||
final boolean alsoUseMoreRestrictiveLocales, final File dictFile, final String name) {
|
final boolean alsoUseMoreRestrictiveLocales, final File dictFile, final String name) {
|
||||||
super(context, getDictName(name, locale, dictFile), locale, Dictionary.TYPE_USER, dictFile);
|
super(context, getDictName(name, locale, dictFile), locale, Dictionary.TYPE_USER, dictFile);
|
||||||
|
@ -107,8 +103,9 @@ public class UserBinaryDictionary extends ExpandableBinaryDictionary {
|
||||||
|
|
||||||
@UsedForTesting
|
@UsedForTesting
|
||||||
public static UserBinaryDictionary getDictionary(final Context context, final Locale locale,
|
public static UserBinaryDictionary getDictionary(final Context context, final Locale locale,
|
||||||
final File dictFile) {
|
final File dictFile, final String dictNamePrefix) {
|
||||||
return new UserBinaryDictionary(context, locale, dictFile);
|
return new UserBinaryDictionary(context, locale, false /* alsoUseMoreRestrictiveLocales */,
|
||||||
|
dictFile, dictNamePrefix + NAME);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -37,7 +37,7 @@ public class ContextualDictionary extends ExpandableBinaryDictionary {
|
||||||
}
|
}
|
||||||
@UsedForTesting
|
@UsedForTesting
|
||||||
public static ContextualDictionary getDictionary(final Context context, final Locale locale,
|
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);
|
return new ContextualDictionary(context, locale, dictFile);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -35,7 +35,7 @@ public class PersonalizationDictionary extends DecayingExpandableBinaryDictionar
|
||||||
|
|
||||||
@UsedForTesting
|
@UsedForTesting
|
||||||
public static PersonalizationDictionary getDictionary(final Context context,
|
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);
|
return PersonalizationHelper.getPersonalizationDictionary(context, locale);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -43,7 +43,7 @@ public class UserHistoryDictionary extends DecayingExpandableBinaryDictionaryBas
|
||||||
|
|
||||||
@UsedForTesting
|
@UsedForTesting
|
||||||
public static UserHistoryDictionary getDictionary(final Context context, final Locale locale,
|
public static UserHistoryDictionary getDictionary(final Context context, final Locale locale,
|
||||||
final File dictFile) {
|
final File dictFile, final String dictNamePrefix) {
|
||||||
return PersonalizationHelper.getUserHistoryDictionary(context, locale);
|
return PersonalizationHelper.getUserHistoryDictionary(context, locale);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue