diff options
Diffstat (limited to 'java/src/com/android/inputmethod/latin/userdictionary')
-rw-r--r-- | java/src/com/android/inputmethod/latin/userdictionary/UserDictionaryList.java | 38 |
1 files changed, 33 insertions, 5 deletions
diff --git a/java/src/com/android/inputmethod/latin/userdictionary/UserDictionaryList.java b/java/src/com/android/inputmethod/latin/userdictionary/UserDictionaryList.java index e7cf0d3af..be5f11620 100644 --- a/java/src/com/android/inputmethod/latin/userdictionary/UserDictionaryList.java +++ b/java/src/com/android/inputmethod/latin/userdictionary/UserDictionaryList.java @@ -17,6 +17,7 @@ package com.android.inputmethod.latin.userdictionary; import android.app.Activity; +import android.content.Context; import android.content.Intent; import android.database.Cursor; import android.os.Bundle; @@ -25,10 +26,14 @@ import android.preference.PreferenceFragment; import android.preference.PreferenceGroup; import android.provider.UserDictionary; import android.text.TextUtils; +import android.view.inputmethod.InputMethodInfo; +import android.view.inputmethod.InputMethodManager; +import android.view.inputmethod.InputMethodSubtype; import com.android.inputmethod.latin.R; import com.android.inputmethod.latin.utils.LocaleUtils; +import java.util.List; import java.util.Locale; import java.util.TreeSet; @@ -52,7 +57,7 @@ public class UserDictionaryList extends PreferenceFragment { final Cursor cursor = activity.managedQuery(UserDictionary.Words.CONTENT_URI, new String[] { UserDictionary.Words.LOCALE }, null, null, null); - final TreeSet<String> localeList = new TreeSet<String>(); + final TreeSet<String> localeSet = new TreeSet<String>(); boolean addedAllLocale = false; if (null == cursor) { // The user dictionary service is not present or disabled. Return null. @@ -62,7 +67,7 @@ public class UserDictionaryList extends PreferenceFragment { do { final String locale = cursor.getString(columnIndex); final boolean allLocale = TextUtils.isEmpty(locale); - localeList.add(allLocale ? "" : locale); + localeSet.add(allLocale ? "" : locale); if (allLocale) { addedAllLocale = true; } @@ -71,10 +76,33 @@ public class UserDictionaryList extends PreferenceFragment { if (!UserDictionarySettings.IS_SHORTCUT_API_SUPPORTED && !addedAllLocale) { // For ICS, we need to show "For all languages" in case that the keyboard locale // is different from the system locale - localeList.add(""); + localeSet.add(""); } - localeList.add(Locale.getDefault().toString()); - return localeList; + + final InputMethodManager imm = + (InputMethodManager)activity.getSystemService(Context.INPUT_METHOD_SERVICE); + final List<InputMethodInfo> imis = imm.getEnabledInputMethodList(); + for (final InputMethodInfo imi : imis) { + final List<InputMethodSubtype> subtypes = + imm.getEnabledInputMethodSubtypeList( + imi, true /* allowsImplicitlySelectedSubtypes */); + for (InputMethodSubtype subtype : subtypes) { + final String locale = subtype.getLocale(); + if (!TextUtils.isEmpty(locale)) { + localeSet.add(locale); + } + } + } + + // We come here after we have collected locales from existing user dictionary entries and + // enabled subtypes. If we already have the locale-without-country version of the system + // locale, we don't add the system locale to avoid confusion even though it's technically + // correct to add it. + if (!localeSet.contains(Locale.getDefault().getLanguage().toString())) { + localeSet.add(Locale.getDefault().toString()); + } + + return localeSet; } /** |