[ML16] Remove DictionaryFacilitator.getLocale()

Bug: 11230254
Change-Id: Ife99df42bc145fbd2d5c3128330bc0f88b104de9
diff --git a/java/src/com/android/inputmethod/latin/DictionaryFacilitator.java b/java/src/com/android/inputmethod/latin/DictionaryFacilitator.java
index 5683e3d..e4e3cdd 100644
--- a/java/src/com/android/inputmethod/latin/DictionaryFacilitator.java
+++ b/java/src/com/android/inputmethod/latin/DictionaryFacilitator.java
@@ -219,11 +219,6 @@
         mPersonalizationHelper.setIsMonolingualUser(isMonolingualUser);
     }
 
-    // TODO: remove this, replace with version returning multiple locales
-    public Locale getLocale() {
-        return mDictionaryGroups[0].mLocale;
-    }
-
     public boolean isActive() {
         return null != mDictionaryGroups[0].mLocale;
     }
@@ -240,6 +235,15 @@
         return getDictionaryGroupForMostProbableLanguage().mLocale;
     }
 
+    public Locale[] getLocales() {
+        final DictionaryGroup[] dictionaryGroups = mDictionaryGroups;
+        final Locale[] locales = new Locale[dictionaryGroups.length];
+        for (int i = 0; i < dictionaryGroups.length; ++i) {
+            locales[i] = dictionaryGroups[i].mLocale;
+        }
+        return locales;
+    }
+
     private DictionaryGroup getDictionaryGroupForMostProbableLanguage() {
         // TODO: implement this
         return mDictionaryGroups[0];
@@ -266,11 +270,11 @@
         }
     }
 
-    public void resetDictionaries(final Context context, final Locale newLocale,
+    public void resetDictionaries(final Context context, final Locale[] newLocales,
             final boolean useContactsDict, final boolean usePersonalizedDicts,
             final boolean forceReloadMainDictionary,
             final DictionaryInitializationListener listener) {
-        resetDictionariesWithDictNamePrefix(context, newLocale, useContactsDict,
+        resetDictionariesWithDictNamePrefix(context, newLocales, useContactsDict,
                 usePersonalizedDicts, forceReloadMainDictionary, listener, "" /* dictNamePrefix */);
     }
 
@@ -285,14 +289,12 @@
     }
 
     public void resetDictionariesWithDictNamePrefix(final Context context,
-            final Locale newLocaleToUse,
+            final Locale[] newLocales,
             final boolean useContactsDict, final boolean usePersonalizedDicts,
             final boolean forceReloadMainDictionary,
             final DictionaryInitializationListener listener,
             final String dictNamePrefix) {
         final HashMap<Locale, ArrayList<String>> existingDictsToCleanup = new HashMap<>();
-        // TODO: use several locales
-        final Locale[] newLocales = new Locale[] { newLocaleToUse };
         // TODO: Make subDictTypesToUse configurable by resource or a static final list.
         final HashSet<String> subDictTypesToUse = new HashSet<>();
         subDictTypesToUse.add(Dictionary.TYPE_USER);
diff --git a/java/src/com/android/inputmethod/latin/DictionaryFacilitatorLruCache.java b/java/src/com/android/inputmethod/latin/DictionaryFacilitatorLruCache.java
index ff4a6bd..1b33d91 100644
--- a/java/src/com/android/inputmethod/latin/DictionaryFacilitatorLruCache.java
+++ b/java/src/com/android/inputmethod/latin/DictionaryFacilitatorLruCache.java
@@ -101,7 +101,7 @@
 
     private void resetDictionariesForLocaleLocked(final DictionaryFacilitator dictionaryFacilitator,
             final Locale locale) {
-        dictionaryFacilitator.resetDictionariesWithDictNamePrefix(mContext, locale,
+        dictionaryFacilitator.resetDictionariesWithDictNamePrefix(mContext, new Locale[] { locale },
                 mUseContactsDictionary, false /* usePersonalizedDicts */,
                 false /* forceReloadMainDictionary */, null /* listener */,
                 mDictionaryNamePrefix);
diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java
index b91e4b4..2be99a9 100644
--- a/java/src/com/android/inputmethod/latin/LatinIME.java
+++ b/java/src/com/android/inputmethod/latin/LatinIME.java
@@ -675,9 +675,7 @@
     // TODO: make sure the current settings always have the right locales, and read from them
     private void resetDictionaryFacilitatorForLocale(final Locale[] locales) {
         final SettingsValues settingsValues = mSettings.getCurrent();
-        // TODO: pass the array instead
-        final Locale locale = locales[0];
-        mDictionaryFacilitator.resetDictionaries(this /* context */, locale,
+        mDictionaryFacilitator.resetDictionaries(this /* context */, locales,
                 settingsValues.mUseContactsDict, settingsValues.mUsePersonalizedDicts,
                 false /* forceReloadMainDictionary */, this);
         if (settingsValues.mAutoCorrectionEnabledPerUserSettings) {
@@ -692,7 +690,7 @@
     /* package private */ void resetSuggestMainDict() {
         final SettingsValues settingsValues = mSettings.getCurrent();
         mDictionaryFacilitator.resetDictionaries(this /* context */,
-                mDictionaryFacilitator.getLocale(), settingsValues.mUseContactsDict,
+                mDictionaryFacilitator.getLocales(), settingsValues.mUseContactsDict,
                 settingsValues.mUsePersonalizedDicts, true /* forceReloadMainDictionary */, this);
     }
 
@@ -1898,7 +1896,7 @@
     @UsedForTesting
     /* package for test */ void replaceDictionariesForTest(final Locale locale) {
         final SettingsValues settingsValues = mSettings.getCurrent();
-        mDictionaryFacilitator.resetDictionaries(this, locale,
+        mDictionaryFacilitator.resetDictionaries(this, new Locale[] { locale },
             settingsValues.mUseContactsDict, settingsValues.mUsePersonalizedDicts,
             false /* forceReloadMainDictionary */, this /* listener */);
     }
diff --git a/tests/src/com/android/inputmethod/latin/DictionaryFacilitatorLruCacheTests.java b/tests/src/com/android/inputmethod/latin/DictionaryFacilitatorLruCacheTests.java
index 5af30e5..ed3929d 100644
--- a/tests/src/com/android/inputmethod/latin/DictionaryFacilitatorLruCacheTests.java
+++ b/tests/src/com/android/inputmethod/latin/DictionaryFacilitatorLruCacheTests.java
@@ -50,15 +50,15 @@
     private void testGetFacilitator(final DictionaryFacilitatorLruCache cache) {
         final DictionaryFacilitator dictionaryFacilitatorEnUs = cache.get(Locale.US);
         assertNotNull(dictionaryFacilitatorEnUs);
-        assertEquals(Locale.US, dictionaryFacilitatorEnUs.getLocale());
+        assertTrue(dictionaryFacilitatorEnUs.isForLocales(new Locale[] { Locale.US }));
 
         final DictionaryFacilitator dictionaryFacilitatorFr = cache.get(Locale.FRENCH);
         assertNotNull(dictionaryFacilitatorEnUs);
-        assertEquals(Locale.FRENCH, dictionaryFacilitatorFr.getLocale());
+        assertTrue(dictionaryFacilitatorFr.isForLocales(new Locale[] { Locale.FRENCH }));
 
         final DictionaryFacilitator dictionaryFacilitatorDe = cache.get(Locale.GERMANY);
         assertNotNull(dictionaryFacilitatorDe);
-        assertEquals(Locale.GERMANY, dictionaryFacilitatorDe.getLocale());
+        assertTrue(dictionaryFacilitatorDe.isForLocales(new Locale[] { Locale.GERMANY }));
     }
 
     public void testSetUseContactsDictionary() {