diff options
Diffstat (limited to 'java/src/com/android/inputmethod/latin/InputLanguageSelection.java')
-rw-r--r-- | java/src/com/android/inputmethod/latin/InputLanguageSelection.java | 133 |
1 files changed, 65 insertions, 68 deletions
diff --git a/java/src/com/android/inputmethod/latin/InputLanguageSelection.java b/java/src/com/android/inputmethod/latin/InputLanguageSelection.java index c32713983..5587c685f 100644 --- a/java/src/com/android/inputmethod/latin/InputLanguageSelection.java +++ b/java/src/com/android/inputmethod/latin/InputLanguageSelection.java @@ -16,11 +16,6 @@ package com.android.inputmethod.latin; -import java.text.Collator; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Locale; - import android.content.SharedPreferences; import android.content.SharedPreferences.Editor; import android.content.res.Configuration; @@ -32,42 +27,43 @@ import android.preference.PreferenceGroup; import android.preference.PreferenceManager; import android.text.TextUtils; +import java.text.Collator; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Locale; + public class InputLanguageSelection extends PreferenceActivity { + private SharedPreferences mPrefs; private String mSelectedLanguages; private ArrayList<Loc> mAvailableLanguages = new ArrayList<Loc>(); - - private static final String[] WHITELIST_LANGUAGES = { - "cs", "da", "de", "en_GB", "en_US", "es", "es_US", "fr", "it", "nb", "nl", "pl", "pt", "ru" + private static final String[] BLACKLIST_LANGUAGES = { + "ko", "ja", "zh", "el", "zz" }; - private static boolean isWhitelisted(String lang) { - for (String s : WHITELIST_LANGUAGES) { - if (s.equalsIgnoreCase(lang)) { - return true; - } - } - return false; - } - private static class Loc implements Comparable<Object> { - static Collator sCollator = Collator.getInstance(); + private static Collator sCollator = Collator.getInstance(); - String label; - Locale locale; + private String mLabel; + public final Locale mLocale; public Loc(String label, Locale locale) { - this.label = label; - this.locale = locale; + this.mLabel = label; + this.mLocale = locale; + } + + public void setLabel(String label) { + this.mLabel = label; } @Override public String toString() { - return this.label; + return this.mLabel; } + @Override public int compareTo(Object o) { - return sCollator.compare(this.label, ((Loc) o).label); + return sCollator.compare(this.mLabel, ((Loc) o).mLabel); } } @@ -76,15 +72,15 @@ public class InputLanguageSelection extends PreferenceActivity { super.onCreate(icicle); addPreferencesFromResource(R.xml.language_prefs); // Get the settings preferences - SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(this); - mSelectedLanguages = sp.getString(LatinIME.PREF_SELECTED_LANGUAGES, ""); + mPrefs = PreferenceManager.getDefaultSharedPreferences(this); + mSelectedLanguages = mPrefs.getString(Settings.PREF_SELECTED_LANGUAGES, ""); String[] languageList = mSelectedLanguages.split(","); mAvailableLanguages = getUniqueLocales(); PreferenceGroup parent = getPreferenceScreen(); for (int i = 0; i < mAvailableLanguages.size(); i++) { CheckBoxPreference pref = new CheckBoxPreference(this); - Locale locale = mAvailableLanguages.get(i).locale; - pref.setTitle(LanguageSwitcher.toTitleCase(locale.getDisplayName(locale))); + Locale locale = mAvailableLanguages.get(i).mLocale; + pref.setTitle(SubtypeSwitcher.getFullDisplayName(locale, true)); boolean checked = isLocaleIn(locale, languageList); pref.setChecked(checked); if (hasDictionary(locale)) { @@ -103,15 +99,15 @@ public class InputLanguageSelection extends PreferenceActivity { } private boolean hasDictionary(Locale locale) { - Resources res = getResources(); - Configuration conf = res.getConfiguration(); - Locale saveLocale = conf.locale; + final Resources res = getResources(); + final Configuration conf = res.getConfiguration(); + final Locale saveLocale = conf.locale; boolean haveDictionary = false; conf.locale = locale; res.updateConfiguration(conf, res.getDisplayMetrics()); - int[] dictionaries = LatinIME.getDictionary(res); - BinaryDictionary bd = new BinaryDictionary(this, dictionaries, Suggest.DIC_MAIN); + int mainDicResId = Utils.getMainDictionaryResourceId(res); + BinaryDictionary bd = BinaryDictionary.initDictionary(this, mainDicResId, Suggest.DIC_MAIN); // Is the dictionary larger than a placeholder? Arbitrarily chose a lower limit of // 4000-5000 words, whereas the LARGE_DICTIONARY is about 20000+ words. @@ -145,18 +141,17 @@ public class InputLanguageSelection extends PreferenceActivity { for (int i = 0; i < count; i++) { CheckBoxPreference pref = (CheckBoxPreference) parent.getPreference(i); if (pref.isChecked()) { - Locale locale = mAvailableLanguages.get(i).locale; + Locale locale = mAvailableLanguages.get(i).mLocale; checkedLanguages += get5Code(locale) + ","; } } if (checkedLanguages.length() < 1) checkedLanguages = null; // Save null - SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(this); - Editor editor = sp.edit(); - editor.putString(LatinIME.PREF_SELECTED_LANGUAGES, checkedLanguages); + Editor editor = mPrefs.edit(); + editor.putString(Settings.PREF_SELECTED_LANGUAGES, checkedLanguages); SharedPreferencesCompat.apply(editor); } - ArrayList<Loc> getUniqueLocales() { + public ArrayList<Loc> getUniqueLocales() { String[] locales = getAssets().getLocales(); Arrays.sort(locales); ArrayList<Loc> uniqueLocales = new ArrayList<Loc>(); @@ -167,41 +162,36 @@ public class InputLanguageSelection extends PreferenceActivity { for (int i = 0 ; i < origSize; i++ ) { String s = locales[i]; int len = s.length(); - final Locale l; - final String language; if (len == 5) { - language = s.substring(0, 2); + String language = s.substring(0, 2); String country = s.substring(3, 5); - l = new Locale(language, country); - } else if (len == 2) { - language = s; - l = new Locale(language); - } else { - continue; - } - // Exclude languages that are not relevant to LatinIME - if (!isWhitelisted(s)) continue; - - if (finalSize == 0) { - preprocess[finalSize++] = - new Loc(LanguageSwitcher.toTitleCase(l.getDisplayName(l)), l); - } else { - // check previous entry: - // same lang and a country -> upgrade to full name and - // insert ours with full name - // diff lang -> insert ours with lang-only name - if (preprocess[finalSize-1].locale.getLanguage().equals( - language)) { - preprocess[finalSize-1].label = LanguageSwitcher.toTitleCase( - preprocess[finalSize-1].locale.getDisplayName()); + Locale l = new Locale(language, country); + + // Exclude languages that are not relevant to LatinIME + if (arrayContains(BLACKLIST_LANGUAGES, language)) continue; + + if (finalSize == 0) { preprocess[finalSize++] = - new Loc(LanguageSwitcher.toTitleCase(l.getDisplayName()), l); + new Loc(SubtypeSwitcher.getFullDisplayName(l, true), l); } else { - String displayName; - if (s.equals("zz_ZZ")) { + // check previous entry: + // same lang and a country -> upgrade to full name and + // insert ours with full name + // diff lang -> insert ours with lang-only name + if (preprocess[finalSize-1].mLocale.getLanguage().equals( + language)) { + preprocess[finalSize-1].setLabel(SubtypeSwitcher.getFullDisplayName( + preprocess[finalSize-1].mLocale, false)); + preprocess[finalSize++] = + new Loc(SubtypeSwitcher.getFullDisplayName(l, false), l); } else { - displayName = LanguageSwitcher.toTitleCase(l.getDisplayName(l)); - preprocess[finalSize++] = new Loc(displayName, l); + String displayName; + if (s.equals("zz_ZZ")) { + // ignore this locale + } else { + displayName = SubtypeSwitcher.getFullDisplayName(l, true); + preprocess[finalSize++] = new Loc(displayName, l); + } } } } @@ -211,4 +201,11 @@ public class InputLanguageSelection extends PreferenceActivity { } return uniqueLocales; } + + private boolean arrayContains(String[] array, String value) { + for (int i = 0; i < array.length; i++) { + if (array[i].equalsIgnoreCase(value)) return true; + } + return false; + } } |