diff --git a/java/src/com/android/inputmethod/latin/ContactsBinaryDictionary.java b/java/src/com/android/inputmethod/latin/ContactsBinaryDictionary.java index dd5b376a1..96160fa4e 100644 --- a/java/src/com/android/inputmethod/latin/ContactsBinaryDictionary.java +++ b/java/src/com/android/inputmethod/latin/ContactsBinaryDictionary.java @@ -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) { diff --git a/java/src/com/android/inputmethod/latin/DictionaryFacilitator.java b/java/src/com/android/inputmethod/latin/DictionaryFacilitator.java index bdf39238a..89fef7de4 100644 --- a/java/src/com/android/inputmethod/latin/DictionaryFacilitator.java +++ b/java/src/com/android/inputmethod/latin/DictionaryFacilitator.java @@ -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 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)); diff --git a/java/src/com/android/inputmethod/latin/UserBinaryDictionary.java b/java/src/com/android/inputmethod/latin/UserBinaryDictionary.java index b89ab84b2..debaad13e 100644 --- a/java/src/com/android/inputmethod/latin/UserBinaryDictionary.java +++ b/java/src/com/android/inputmethod/latin/UserBinaryDictionary.java @@ -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 diff --git a/java/src/com/android/inputmethod/latin/personalization/ContextualDictionary.java b/java/src/com/android/inputmethod/latin/personalization/ContextualDictionary.java index 96f03f9ff..96755a98f 100644 --- a/java/src/com/android/inputmethod/latin/personalization/ContextualDictionary.java +++ b/java/src/com/android/inputmethod/latin/personalization/ContextualDictionary.java @@ -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); } diff --git a/java/src/com/android/inputmethod/latin/personalization/PersonalizationDictionary.java b/java/src/com/android/inputmethod/latin/personalization/PersonalizationDictionary.java index 19fa29e5f..f2ad22ac7 100644 --- a/java/src/com/android/inputmethod/latin/personalization/PersonalizationDictionary.java +++ b/java/src/com/android/inputmethod/latin/personalization/PersonalizationDictionary.java @@ -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); } } diff --git a/java/src/com/android/inputmethod/latin/personalization/UserHistoryDictionary.java b/java/src/com/android/inputmethod/latin/personalization/UserHistoryDictionary.java index ea1035612..3916fc24c 100644 --- a/java/src/com/android/inputmethod/latin/personalization/UserHistoryDictionary.java +++ b/java/src/com/android/inputmethod/latin/personalization/UserHistoryDictionary.java @@ -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); }