Merge "Fix a bug with umlaut processing." into honeycomb-mr1
diff --git a/java/res/values-es-rUS-xlarge/strings.xml b/java/res/values-es-rUS-xlarge/strings.xml
deleted file mode 100644
index 24d2b4f..0000000
--- a/java/res/values-es-rUS-xlarge/strings.xml
+++ /dev/null
@@ -1,122 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<resources xmlns:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <!-- XL -->
-    <string name="sound_on_keypress" msgid="5115009797011251176">"Sonar al pulsar teclas"</string>
-    <!-- XL -->
-    <string name="auto_cap" msgid="6033382411344449470">"Uso de mayúsculas automático"</string>
-    <!-- XL -->
-    <string name="auto_correction" msgid="7961335093790493671">"Corrección automática"</string>
-    <!-- XL -->
-    <string name="auto_correction_summary" msgid="6260001790426244084">"La barra espaciadora o la puntuación insertan automáticamente la palabra resaltada."</string>
-    <!-- XL -->
-    <string name="bigram_suggestion" msgid="7146707435859263625">"Sugerencias de bigramas"</string>
-    <!-- XL -->
-    <string name="label_done_key" msgid="5392116476778838314">"Listo"</string>
-    <!-- XL -->
-    <string name="voice_warning_title" msgid="7559175513146431282">"Entrada de voz"</string>
-    <!-- XL -->
-    <string name="voice_warning_may_not_understand" msgid="5450473727606344027">"La entrada de voz utiliza el reconocimiento de voz de Google. "<a href="http://m.google.com/privacy">"Aplica la Política de privacidad de Google para celulares"</a>"."</string>
-    <!-- XL -->
-    <string name="voice_warning_how_to_turn_off" msgid="8461922898209345270">"Para desactivar la entrada por voz, ve a la configuración de métodos de entrada."</string>
-    <!-- XL -->
-    <string name="voice_hint_dialog_message" msgid="6099357096490592798">"Para utilizar entrada de voz, presiona el botón micrófono."</string>
-    <!-- XL -->
-    <string name="voice_input" msgid="6634874497844843576">"Entrada de voz"</string>
-    <!-- XL -->
-    <string name="prefs_enable_recorrection_summary" msgid="3119549956172710725">"Toca las palabras ingresadas que desees corregir, solo cuando las sugerencias estén visibles."</string>
-    <!-- XL -->
-    <string name="prefs_show_suggestions" msgid="1375526087676269770">"Mostrar sugerencias"</string>
-    <!-- XL -->
-    <string name="prefs_show_suggestions_summary" msgid="2564386479780335351">"Mostrar palabras sugeridas al escribir"</string>
-    <!-- XL -->
-    <string name="prefs_suggestion_visibility_show_name" msgid="8350173747634837929">"Mostrar siempre"</string>
-    <!-- XL -->
-    <string name="prefs_suggestion_visibility_show_only_portrait_name" msgid="670278993111469619">"Mostrar en modo retrato"</string>
-    <!-- XL -->
-    <string name="prefs_suggestion_visibility_hide_name" msgid="2750493093338023345">"Ocultar siempre"</string>
-    <!-- XL -->
-    <string name="auto_correction_threshold_mode_off" msgid="4899978031827517261">"Apagado"</string>
-    <!-- XL -->
-    <string name="auto_correction_threshold_mode_modest" msgid="3316394123368070951">"Moderado"</string>
-    <!-- XL -->
-    <string name="auto_correction_threshold_mode_aggeressive" msgid="6091003457668724585">"Intenso"</string>
-    <!-- XL -->
-    <string name="label_to_alpha_key" msgid="3103719164112604010">"ABC"</string>
-    <!-- XL -->
-    <string name="voice_input_modes_main_keyboard" msgid="1403596961453846365">"En el teclado principal"</string>
-    <!-- XL -->
-    <string name="voice_input_modes_symbols_keyboard" msgid="5916050323076830126">"En el teclado de símbolos"</string>
-    <!-- XL -->
-    <string name="voice_input_modes_off" msgid="1577817314089496020">"Apagado"</string>
-    <!-- XL -->
-    <string name="voice_input_modes_summary_main_keyboard" msgid="5118121899312172508">"Micrófono en el teclado principal"</string>
-    <!-- XL -->
-    <string name="voice_input_modes_summary_symbols_keyboard" msgid="8181616553734217736">"Micrófono en el teclado de símbolos"</string>
-    <!-- XL -->
-    <string name="voice_input_modes_summary_off" msgid="3854831353403775554">"La entrada por voz está inhabilitada."</string>
-    <!-- XL -->
-    <string name="subtype_mode_cs_keyboard" msgid="1186679497674833204">"Teclado en checo"</string>
-    <!-- XL -->
-    <string name="subtype_mode_da_keyboard" msgid="1395637124037817510">"Teclado en danés"</string>
-    <!-- XL -->
-    <string name="subtype_mode_de_keyboard" msgid="1145552122692431122">"Teclado en alemán"</string>
-    <!-- XL -->
-    <string name="subtype_mode_en_GB_keyboard" msgid="5050923189634470413">"Teclado en inglés (Reino Unido)"</string>
-    <!-- XL -->
-    <string name="subtype_mode_en_US_keyboard" msgid="3435344903704397043">"Teclado en inglés (EE.UU.)"</string>
-    <!-- XL -->
-    <string name="subtype_mode_es_keyboard" msgid="1030419781157491328">"Teclado en español"</string>
-    <!-- XL -->
-    <string name="subtype_mode_es_US_keyboard" msgid="5792199241357098918">"Teclado en español (EE.UU.)"</string>
-    <!-- XL -->
-    <string name="subtype_mode_fr_keyboard" msgid="4855416218650524164">"Teclado en francés"</string>
-    <!-- XL -->
-    <string name="subtype_mode_fr_CA_keyboard" msgid="6458285776720480201">"Teclado en francés (Canadá)"</string>
-    <!-- XL -->
-    <string name="subtype_mode_fr_CH_keyboard" msgid="5966960427086795964">"Teclado en francés (Suiza)"</string>
-    <!-- XL -->
-    <string name="subtype_mode_it_keyboard" msgid="6927754583816493555">"Teclado en italiano"</string>
-    <!-- XL -->
-    <string name="subtype_mode_nb_keyboard" msgid="771634025467668613">"Teclado en noruego"</string>
-    <!-- XL -->
-    <string name="subtype_mode_nl_keyboard" msgid="3397048533451717478">"Teclado en holandés"</string>
-    <!-- XL -->
-    <string name="subtype_mode_ru_keyboard" msgid="3812694929448916712">"Teclado en ruso"</string>
-    <!-- XL -->
-    <string name="subtype_mode_sr_keyboard" msgid="7947963963114184275">"Teclado en serbio"</string>
-    <!-- XL -->
-    <string name="subtype_mode_sv_keyboard" msgid="3874083866564515371">"Teclado en sueco"</string>
-    <!-- XL -->
-    <string name="subtype_mode_af_voice">"Voz en Afrikáans"</string>
-    <!-- XL -->
-    <string name="subtype_mode_cs_voice" msgid="8290007904951946296">"Voz en checo"</string>
-    <!-- XL -->
-    <string name="subtype_mode_de_voice" msgid="672328729666823853">"Voz en alemán"</string>
-    <!-- XL -->
-    <string name="subtype_mode_en_voice">"Voz en inglés"</string>
-    <!-- XL -->
-    <string name="subtype_mode_es_voice" msgid="1243071504878834350">"Voz en español"</string>
-    <!-- XL -->
-    <string name="subtype_mode_fr_voice" msgid="2048805677248981105">"Voz en francés"</string>
-    <!-- XL -->
-    <string name="subtype_mode_ja_voice" msgid="1855513591711108481">"Voz en japonés"</string>
-    <!-- XL -->
-    <string name="subtype_mode_ko_voice" msgid="3453153041889151316">"Voz en coreano"</string>
-    <!-- XL -->
-    <string name="subtype_mode_pl_voice" msgid="6730658974157645735">"Voz en polaco"</string>
-    <!-- XL -->
-    <string name="subtype_mode_pt_voice" msgid="4508062762756741654">"Voz en portugués"</string>
-    <!-- XL -->
-    <string name="subtype_mode_ru_voice" msgid="554299262138845594">"Voz en ruso"</string>
-    <!-- XL -->
-    <string name="subtype_mode_tr_voice" msgid="5242644971865917801">"Voz en turco"</string>
-    <!-- XL -->
-    <string name="subtype_mode_yue_voice">"Voz en chino, yue"</string>
-    <!-- XL -->
-    <string name="subtype_mode_zh_voice">"Voz en chino, mandarín"</string>
-    <!-- XL -->
-    <string name="subtype_mode_zu_voice">"Voz en isiZulu"</string>
-    <!-- XL -->
-    <string name="prefs_usability_study_mode" msgid="8423000345880575687">"Modo estudio de usabilidad"</string>
-</resources>
diff --git a/java/src/com/android/inputmethod/latin/AutoCorrection.java b/java/src/com/android/inputmethod/latin/AutoCorrection.java
index d1154d9..f177f6a 100644
--- a/java/src/com/android/inputmethod/latin/AutoCorrection.java
+++ b/java/src/com/android/inputmethod/latin/AutoCorrection.java
@@ -19,6 +19,7 @@
 import android.util.Log;
 
 import java.util.ArrayList;
+import java.util.Collection;
 
 public class AutoCorrection {
     private static final boolean DBG = LatinImeLogger.sDBG;
@@ -45,12 +46,12 @@
         return mNormalizedScore;
     }
 
-    public void updateAutoCorrectionStatus(Suggest suggest,
+    public void updateAutoCorrectionStatus(Collection<Dictionary> dictionaries,
             WordComposer wordComposer, ArrayList<CharSequence> suggestions, int[] priorities,
             CharSequence typedWord, double autoCorrectionThreshold, int correctionMode,
             CharSequence quickFixedWord) {
         if (hasAutoCorrectionForTypedWord(
-                suggest, wordComposer, suggestions, typedWord, correctionMode)) {
+                dictionaries, wordComposer, suggestions, typedWord, correctionMode)) {
             mHasAutoCorrection = true;
             mAutoCorrectionWord = typedWord;
         } else if (hasAutoCorrectForBinaryDictionary(wordComposer, suggestions, correctionMode,
@@ -63,9 +64,17 @@
         }
     }
 
-    private boolean hasAutoCorrectionForTypedWord(Suggest suggest, WordComposer wordComposer,
-            ArrayList<CharSequence> suggestions, CharSequence typedWord, int correctionMode) {
-        return wordComposer.size() > 1 && suggestions.size() > 0 && suggest.isValidWord(typedWord)
+    private boolean hasAutoCorrectionForTypedWord(Collection<Dictionary> dictionaries,
+            WordComposer wordComposer, ArrayList<CharSequence> suggestions, CharSequence typedWord,
+            int correctionMode) {
+        boolean isValidWord = false;
+        for (final Dictionary dictionary : dictionaries) {
+            if (dictionary.isValidWord(typedWord)) {
+                isValidWord = true;
+                break;
+            }
+        }
+        return wordComposer.size() > 1 && suggestions.size() > 0 && isValidWord
                 && (correctionMode == Suggest.CORRECTION_FULL
                 || correctionMode == Suggest.CORRECTION_FULL_BIGRAM);
     }
diff --git a/java/src/com/android/inputmethod/latin/Suggest.java b/java/src/com/android/inputmethod/latin/Suggest.java
index 95a2d63..ec86a39 100644
--- a/java/src/com/android/inputmethod/latin/Suggest.java
+++ b/java/src/com/android/inputmethod/latin/Suggest.java
@@ -25,6 +25,10 @@
 import java.io.File;
 import java.util.ArrayList;
 import java.util.Arrays;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
 
 /**
  * This class loads a dictionary and provides a list of suggestions for a given sequence of
@@ -70,14 +74,13 @@
     private AutoCorrection mAutoCorrection;
 
     private BinaryDictionary mMainDict;
-
-    private Dictionary mUserDictionary;
-
-    private Dictionary mAutoDictionary;
-
-    private Dictionary mContactsDictionary;
-
-    private Dictionary mUserBigramDictionary;
+    private static final String DICT_KEY_MAIN = "main";
+    private static final String DICT_KEY_CONTACTS = "contacts";
+    private static final String DICT_KEY_AUTO = "auto";
+    private static final String DICT_KEY_USER = "user";
+    private static final String DICT_KEY_USER_BIGRAM = "user_bigram";
+    private final Map<String, Dictionary> mUnigramDictionaries = new HashMap<String, Dictionary>();
+    private final Map<String, Dictionary> mBigramDictionaries = new HashMap<String, Dictionary>();
 
     private int mPrefMaxSuggestions = 12;
 
@@ -101,16 +104,19 @@
     private int mCorrectionMode = CORRECTION_BASIC;
 
     public Suggest(Context context, int dictionaryResId) {
-        mMainDict = BinaryDictionary.initDictionary(context, dictionaryResId, DIC_MAIN);
-        init();
+        init(BinaryDictionary.initDictionary(context, dictionaryResId, DIC_MAIN));
     }
 
     /* package for test */ Suggest(File dictionary, long startOffset, long length) {
-        mMainDict = BinaryDictionary.initDictionary(dictionary, startOffset, length, DIC_MAIN);
-        init();
+        init(BinaryDictionary.initDictionary(dictionary, startOffset, length, DIC_MAIN));
     }
 
-    private void init() {
+    private void init(BinaryDictionary mainDict) {
+        if (mainDict != null) {
+            mMainDict = mainDict;
+            mUnigramDictionaries.put(DICT_KEY_MAIN, mainDict);
+            mBigramDictionaries.put(DICT_KEY_MAIN, mainDict);
+        }
         mAutoCorrection = new AutoCorrection();
         initPool();
     }
@@ -147,22 +153,28 @@
      * before the main dictionary, if set.
      */
     public void setUserDictionary(Dictionary userDictionary) {
-        mUserDictionary = userDictionary;
+        if (userDictionary != null)
+            mUnigramDictionaries.put(DICT_KEY_USER, userDictionary);
     }
 
     /**
      * Sets an optional contacts dictionary resource to be loaded.
      */
-    public void setContactsDictionary(Dictionary userDictionary) {
-        mContactsDictionary = userDictionary;
+    public void setContactsDictionary(Dictionary contactsDictionary) {
+        if (contactsDictionary != null) {
+            mUnigramDictionaries.put(DICT_KEY_CONTACTS, contactsDictionary);
+            mBigramDictionaries.put(DICT_KEY_CONTACTS, contactsDictionary);
+        }
     }
 
     public void setAutoDictionary(Dictionary autoDictionary) {
-        mAutoDictionary = autoDictionary;
+        if (autoDictionary != null)
+            mUnigramDictionaries.put(DICT_KEY_AUTO, autoDictionary);
     }
 
     public void setUserBigramDictionary(Dictionary userBigramDictionary) {
-        mUserBigramDictionary = userBigramDictionary;
+        if (userBigramDictionary != null)
+            mBigramDictionaries.put(DICT_KEY_USER_BIGRAM, userBigramDictionary);
     }
 
     public void setAutoCorrectionThreshold(double threshold) {
@@ -240,14 +252,8 @@
                 if (mMainDict != null && mMainDict.isValidWord(lowerPrevWord)) {
                     prevWordForBigram = lowerPrevWord;
                 }
-                if (mUserBigramDictionary != null) {
-                    mUserBigramDictionary.getBigrams(wordComposer, prevWordForBigram, this);
-                }
-                if (mContactsDictionary != null) {
-                    mContactsDictionary.getBigrams(wordComposer, prevWordForBigram, this);
-                }
-                if (mMainDict != null) {
-                    mMainDict.getBigrams(wordComposer, prevWordForBigram, this);
+                for (final Dictionary dictionary : mBigramDictionaries.values()) {
+                    dictionary.getBigrams(wordComposer, prevWordForBigram, this);
                 }
                 char currentChar = wordComposer.getTypedWord().charAt(0);
                 char currentCharUpper = Character.toUpperCase(currentChar);
@@ -270,15 +276,13 @@
 
         } else if (wordComposer.size() > 1) {
             // At second character typed, search the unigrams (scores being affected by bigrams)
-            if (mUserDictionary != null || mContactsDictionary != null) {
-                if (mUserDictionary != null) {
-                    mUserDictionary.getWords(wordComposer, this);
-                }
-                if (mContactsDictionary != null) {
-                    mContactsDictionary.getWords(wordComposer, this);
-                }
+            for (final String key : mUnigramDictionaries.keySet()) {
+                // Skip AutoDictionary to lookup
+                if (key.equals(DICT_KEY_AUTO))
+                    continue;
+                final Dictionary dictionary = mUnigramDictionaries.get(key);
+                dictionary.getWords(wordComposer, this);
             }
-            if (mMainDict != null) mMainDict.getWords(wordComposer, this);
         }
         CharSequence autoText = null;
         final String typedWordString = typedWord == null ? null : typedWord.toString();
@@ -324,8 +328,9 @@
             }
         }
 
-        mAutoCorrection.updateAutoCorrectionStatus(this, wordComposer, mSuggestions, mPriorities,
-                typedWord, mAutoCorrectionThreshold, mCorrectionMode, autoText);
+        mAutoCorrection.updateAutoCorrectionStatus(mUnigramDictionaries.values(), wordComposer,
+                mSuggestions, mPriorities, typedWord, mAutoCorrectionThreshold, mCorrectionMode,
+                autoText);
 
         if (autoText != null) {
             mSuggestions.add(0, autoText);
@@ -515,10 +520,11 @@
         if (word == null || word.length() == 0 || mMainDict == null) {
             return false;
         }
-        return mMainDict.isValidWord(word)
-                || (mUserDictionary != null && mUserDictionary.isValidWord(word))
-                || (mAutoDictionary != null && mAutoDictionary.isValidWord(word))
-                || (mContactsDictionary != null && mContactsDictionary.isValidWord(word));
+        for (final Dictionary dictionary : mUnigramDictionaries.values()) {
+            if (dictionary.isValidWord(word))
+                return true;
+        }
+        return false;
     }
 
     private void collectGarbage(ArrayList<CharSequence> suggestions, int prefMaxSuggestions) {
@@ -539,25 +545,12 @@
     }
 
     public void close() {
-        if (mMainDict != null) {
-            mMainDict.close();
-            mMainDict = null;
+        final Set<Dictionary> dictionaries = new HashSet<Dictionary>();
+        dictionaries.addAll(mUnigramDictionaries.values());
+        dictionaries.addAll(mBigramDictionaries.values());
+        for (final Dictionary dictionary : dictionaries) {
+            dictionary.close();
         }
-        if (mUserDictionary != null) {
-            mUserDictionary.close();
-            mUserDictionary = null;
-        }
-        if (mUserBigramDictionary != null) {
-            mUserBigramDictionary.close();
-            mUserBigramDictionary = null;
-        }
-        if (mContactsDictionary != null) {
-            mContactsDictionary.close();
-            mContactsDictionary = null;
-        }
-        if (mAutoDictionary != null) {
-            mAutoDictionary.close();
-            mAutoDictionary = null;
-        }
+        mMainDict = null;
     }
 }