diff --git a/java/AndroidManifest.xml b/java/AndroidManifest.xml index e0eecfc7d..2fbf4c2be 100644 --- a/java/AndroidManifest.xml +++ b/java/AndroidManifest.xml @@ -33,7 +33,7 @@ - diff --git a/java/res/values/attrs.xml b/java/res/values/attrs.xml index 9b38139f0..e88b007a9 100644 --- a/java/res/values/attrs.xml +++ b/java/res/values/attrs.xml @@ -91,6 +91,8 @@ + + diff --git a/java/res/xml-ar/kbd_qwerty.xml b/java/res/xml-ar/kbd_qwerty.xml index 4c6a4f50a..5faf60336 100644 --- a/java/res/xml-ar/kbd_qwerty.xml +++ b/java/res/xml-ar/kbd_qwerty.xml @@ -28,6 +28,7 @@ latin:verticalGap="@dimen/key_bottom_gap" latin:popupKeyboardTemplate="@xml/kbd_popup_template" latin:maxPopupKeyboardColumn="@integer/config_max_popup_keyboard_column" + latin:keyboardLocale="ar" > diff --git a/java/res/xml-cs/kbd_qwerty.xml b/java/res/xml-cs/kbd_qwerty.xml index 010bdb3f7..0e6e40d7c 100644 --- a/java/res/xml-cs/kbd_qwerty.xml +++ b/java/res/xml-cs/kbd_qwerty.xml @@ -28,6 +28,7 @@ latin:verticalGap="@dimen/key_bottom_gap" latin:popupKeyboardTemplate="@xml/kbd_popup_template" latin:maxPopupKeyboardColumn="@integer/config_max_popup_keyboard_column" + latin:keyboardLocale="cs" > diff --git a/java/res/xml-da/kbd_qwerty.xml b/java/res/xml-da/kbd_qwerty.xml index 441b7cb17..d9847ae83 100644 --- a/java/res/xml-da/kbd_qwerty.xml +++ b/java/res/xml-da/kbd_qwerty.xml @@ -27,6 +27,7 @@ latin:verticalGap="@dimen/key_bottom_gap" latin:popupKeyboardTemplate="@xml/kbd_popup_template" latin:maxPopupKeyboardColumn="@integer/config_max_popup_keyboard_column" + latin:keyboardLocale="da" > diff --git a/java/res/xml-de/kbd_qwerty.xml b/java/res/xml-de/kbd_qwerty.xml index a23e4fbf0..6b5c22391 100644 --- a/java/res/xml-de/kbd_qwerty.xml +++ b/java/res/xml-de/kbd_qwerty.xml @@ -28,6 +28,7 @@ latin:verticalGap="@dimen/key_bottom_gap" latin:popupKeyboardTemplate="@xml/kbd_popup_template" latin:maxPopupKeyboardColumn="@integer/config_max_popup_keyboard_column" + latin:keyboardLocale="de" > diff --git a/java/res/xml-fi/kbd_qwerty.xml b/java/res/xml-fi/kbd_qwerty.xml index b0a7b3eb0..ea08d670b 100644 --- a/java/res/xml-fi/kbd_qwerty.xml +++ b/java/res/xml-fi/kbd_qwerty.xml @@ -27,6 +27,7 @@ latin:verticalGap="@dimen/key_bottom_gap" latin:popupKeyboardTemplate="@xml/kbd_popup_template" latin:maxPopupKeyboardColumn="@integer/config_max_popup_keyboard_column" + latin:keyboardLocale="fi" > diff --git a/java/res/xml-fr-rCA/kbd_qwerty.xml b/java/res/xml-fr-rCA/kbd_qwerty.xml index 92d92f0e6..f9c29698b 100644 --- a/java/res/xml-fr-rCA/kbd_qwerty.xml +++ b/java/res/xml-fr-rCA/kbd_qwerty.xml @@ -28,6 +28,7 @@ latin:verticalGap="@dimen/key_bottom_gap" latin:popupKeyboardTemplate="@xml/kbd_popup_template" latin:maxPopupKeyboardColumn="@integer/config_max_popup_keyboard_column" + latin:keyboardLocale="fr_CA" > diff --git a/java/res/xml-fr-rCH/kbd_qwerty.xml b/java/res/xml-fr-rCH/kbd_qwerty.xml index a23e4fbf0..e47cfd9b4 100644 --- a/java/res/xml-fr-rCH/kbd_qwerty.xml +++ b/java/res/xml-fr-rCH/kbd_qwerty.xml @@ -28,6 +28,7 @@ latin:verticalGap="@dimen/key_bottom_gap" latin:popupKeyboardTemplate="@xml/kbd_popup_template" latin:maxPopupKeyboardColumn="@integer/config_max_popup_keyboard_column" + latin:keyboardLocale="fr_CH" > diff --git a/java/res/xml-fr/kbd_qwerty.xml b/java/res/xml-fr/kbd_qwerty.xml index 2d0b42baf..e4b73bf21 100644 --- a/java/res/xml-fr/kbd_qwerty.xml +++ b/java/res/xml-fr/kbd_qwerty.xml @@ -28,6 +28,7 @@ latin:verticalGap="@dimen/key_bottom_gap" latin:popupKeyboardTemplate="@xml/kbd_popup_template" latin:maxPopupKeyboardColumn="@integer/config_max_popup_keyboard_column" + latin:keyboardLocale="fr" > diff --git a/java/res/xml-hu/kbd_qwerty.xml b/java/res/xml-hu/kbd_qwerty.xml index 010bdb3f7..db729cf02 100644 --- a/java/res/xml-hu/kbd_qwerty.xml +++ b/java/res/xml-hu/kbd_qwerty.xml @@ -28,6 +28,7 @@ latin:verticalGap="@dimen/key_bottom_gap" latin:popupKeyboardTemplate="@xml/kbd_popup_template" latin:maxPopupKeyboardColumn="@integer/config_max_popup_keyboard_column" + latin:keyboardLocale="hu" > diff --git a/java/res/xml-iw/kbd_qwerty.xml b/java/res/xml-iw/kbd_qwerty.xml index 72826d461..4cd565b88 100644 --- a/java/res/xml-iw/kbd_qwerty.xml +++ b/java/res/xml-iw/kbd_qwerty.xml @@ -28,6 +28,7 @@ latin:verticalGap="@dimen/key_bottom_gap" latin:popupKeyboardTemplate="@xml/kbd_popup_template" latin:maxPopupKeyboardColumn="@integer/config_max_popup_keyboard_column" + latin:keyboardLocale="iw" > diff --git a/java/res/xml-nb/kbd_qwerty.xml b/java/res/xml-nb/kbd_qwerty.xml index 441b7cb17..7b20ca28d 100644 --- a/java/res/xml-nb/kbd_qwerty.xml +++ b/java/res/xml-nb/kbd_qwerty.xml @@ -27,6 +27,7 @@ latin:verticalGap="@dimen/key_bottom_gap" latin:popupKeyboardTemplate="@xml/kbd_popup_template" latin:maxPopupKeyboardColumn="@integer/config_max_popup_keyboard_column" + latin:keyboardLocale="nb" > diff --git a/java/res/xml-ru/kbd_qwerty.xml b/java/res/xml-ru/kbd_qwerty.xml index 0eb311501..065cf3afc 100644 --- a/java/res/xml-ru/kbd_qwerty.xml +++ b/java/res/xml-ru/kbd_qwerty.xml @@ -27,6 +27,7 @@ latin:verticalGap="@dimen/key_bottom_gap" latin:popupKeyboardTemplate="@xml/kbd_popup_template" latin:maxPopupKeyboardColumn="@integer/config_max_popup_keyboard_column" + latin:keyboardLocale="ru" > diff --git a/java/res/xml-sr/kbd_qwerty.xml b/java/res/xml-sr/kbd_qwerty.xml index 3995e4e27..9782cd5eb 100644 --- a/java/res/xml-sr/kbd_qwerty.xml +++ b/java/res/xml-sr/kbd_qwerty.xml @@ -27,6 +27,7 @@ latin:verticalGap="@dimen/key_bottom_gap" latin:popupKeyboardTemplate="@xml/kbd_popup_template" latin:maxPopupKeyboardColumn="@integer/config_max_popup_keyboard_column" + latin:keyboardLocale="sr" > diff --git a/java/res/xml-sv/kbd_qwerty.xml b/java/res/xml-sv/kbd_qwerty.xml index 72bdc339e..3ff1679a2 100644 --- a/java/res/xml-sv/kbd_qwerty.xml +++ b/java/res/xml-sv/kbd_qwerty.xml @@ -27,6 +27,7 @@ latin:verticalGap="@dimen/key_bottom_gap" latin:popupKeyboardTemplate="@xml/kbd_popup_template" latin:maxPopupKeyboardColumn="@integer/config_max_popup_keyboard_column" + latin:keyboardLocale="sv" > diff --git a/java/res/xml-xlarge/kbd_qwerty.xml b/java/res/xml-xlarge/kbd_qwerty.xml deleted file mode 100644 index 1c8d51ffe..000000000 --- a/java/res/xml-xlarge/kbd_qwerty.xml +++ /dev/null @@ -1,33 +0,0 @@ - - - - - - diff --git a/java/res/xml/kbd_qwerty.xml b/java/res/xml/kbd_qwerty.xml index 92d92f0e6..6bf6b781d 100644 --- a/java/res/xml/kbd_qwerty.xml +++ b/java/res/xml/kbd_qwerty.xml @@ -28,6 +28,7 @@ latin:verticalGap="@dimen/key_bottom_gap" latin:popupKeyboardTemplate="@xml/kbd_popup_template" latin:maxPopupKeyboardColumn="@integer/config_max_popup_keyboard_column" + latin:keyboardLocale="en" > diff --git a/java/res/xml/prefs.xml b/java/res/xml/prefs.xml index cbfc3c39d..fb7b0ea40 100644 --- a/java/res/xml/prefs.xml +++ b/java/res/xml/prefs.xml @@ -64,6 +64,13 @@ android:key="subtype_settings" android:title="@string/language_selection_title" android:summary="@string/language_selection_summary" /> + + + mAvailableLanguages = new ArrayList(); - private static final String[] BLACKLIST_LANGUAGES = { - "ko", "ja", "zh", "el", "zz" - }; private static class Loc implements Comparable { private static Collator sCollator = Collator.getInstance(); @@ -78,8 +87,11 @@ public class InputLanguageSelection extends PreferenceActivity { mAvailableLanguages = getUniqueLocales(); PreferenceGroup parent = getPreferenceScreen(); for (int i = 0; i < mAvailableLanguages.size(); i++) { - CheckBoxPreference pref = new CheckBoxPreference(this); Locale locale = mAvailableLanguages.get(i).mLocale; + if (!hasDictionary(locale) && !hasLayout(locale)) { + continue; + } + CheckBoxPreference pref = new CheckBoxPreference(this); pref.setTitle(SubtypeSwitcher.getFullDisplayName(locale, true)); boolean checked = isLocaleIn(locale, languageList); pref.setChecked(checked); @@ -120,6 +132,32 @@ public class InputLanguageSelection extends PreferenceActivity { return haveDictionary; } + private boolean hasLayout(Locale locale) { + if (locale == null) return false; + final Resources res = getResources(); + final Configuration conf = res.getConfiguration(); + final Locale saveLocale = conf.locale; + conf.locale = locale; + res.updateConfiguration(conf, res.getDisplayMetrics()); + + try { + final String countryCode = locale.getLanguage(); + final String layoutCountryCode = KeyboardParser.parseKeyboardLocale( + this, R.xml.kbd_qwerty); + if (!TextUtils.isEmpty(countryCode) && !TextUtils.isEmpty(layoutCountryCode)) { + return countryCode.subSequence(0, 2).equals(layoutCountryCode.substring(0, 2)); + } + return false; + } catch (XmlPullParserException e) { + return false; + } catch (IOException e) { + return false; + } finally { + conf.locale = saveLocale; + res.updateConfiguration(conf, res.getDisplayMetrics()); + } + } + private String get5Code(Locale locale) { String country = locale.getCountry(); return locale.getLanguage() @@ -173,7 +211,7 @@ public class InputLanguageSelection extends PreferenceActivity { Locale l = new Locale(language, country); // Exclude languages that are not relevant to LatinIME - if (arrayContains(BLACKLIST_LANGUAGES, language) || TextUtils.isEmpty(language)) { + if (TextUtils.isEmpty(language)) { continue; } @@ -207,11 +245,4 @@ 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; - } } diff --git a/java/src/com/android/inputmethod/keyboard/KeyboardParser.java b/java/src/com/android/inputmethod/keyboard/KeyboardParser.java index 9c556c309..69ae7886a 100644 --- a/java/src/com/android/inputmethod/keyboard/KeyboardParser.java +++ b/java/src/com/android/inputmethod/keyboard/KeyboardParser.java @@ -22,6 +22,7 @@ import com.android.inputmethod.latin.R; import org.xmlpull.v1.XmlPullParser; import org.xmlpull.v1.XmlPullParserException; +import android.content.Context; import android.content.res.Resources; import android.content.res.TypedArray; import android.content.res.XmlResourceParser; @@ -163,6 +164,27 @@ public class KeyboardParser { } } + public static String parseKeyboardLocale( + Context context, int resId) throws XmlPullParserException, IOException { + final Resources res = context.getResources(); + final XmlResourceParser parser = res.getXml(resId); + if (parser == null) return ""; + int event; + while ((event = parser.next()) != XmlPullParser.END_DOCUMENT) { + if (event == XmlPullParser.START_TAG) { + final String tag = parser.getName(); + if (TAG_KEYBOARD.equals(tag)) { + final TypedArray keyboardAttr = res.obtainAttributes(Xml.asAttributeSet(parser), + R.styleable.Keyboard); + return keyboardAttr.getString(R.styleable.Keyboard_keyboardLocale); + } else { + throw new IllegalStartTag(parser, TAG_KEYBOARD); + } + } + } + return ""; + } + private void parseKeyboardAttributes(XmlResourceParser parser) { final Keyboard keyboard = mKeyboard; final TypedArray keyboardAttr = mResources.obtainAttributes(Xml.asAttributeSet(parser), diff --git a/java/src/com/android/inputmethod/latin/Settings.java b/java/src/com/android/inputmethod/latin/Settings.java index 8f7278e3a..1725ee7aa 100644 --- a/java/src/com/android/inputmethod/latin/Settings.java +++ b/java/src/com/android/inputmethod/latin/Settings.java @@ -18,6 +18,7 @@ package com.android.inputmethod.latin; import com.android.inputmethod.compat.CompatUtils; import com.android.inputmethod.compat.InputMethodManagerCompatWrapper; +import com.android.inputmethod.compat.InputMethodServiceCompatWrapper; import com.android.inputmethod.deprecated.VoiceProxy; import com.android.inputmethod.compat.VibratorCompatWrapper; @@ -67,6 +68,7 @@ public class Settings extends PreferenceActivity public static final String PREF_AUTO_CORRECTION_THRESHOLD = "auto_correction_threshold"; public static final String PREF_BIGRAM_SUGGESTIONS = "bigram_suggestion"; public static final String PREF_DEBUG_SETTINGS = "debug_settings"; + public static final String PREF_LANGUAGE_SELECTION = "language_selection"; public static final String PREF_USABILITY_STUDY_MODE = "usability_study_mode"; @@ -183,6 +185,10 @@ public class Settings extends PreferenceActivity if (!showUsabilityModeStudyOption) { getPreferenceScreen().removePreference(findPreference(PREF_USABILITY_STUDY_MODE)); } + + if (InputMethodServiceCompatWrapper.CAN_HANDLE_ON_CURRENT_INPUT_METHOD_SUBTYPE_CHANGED) { + generalSettings.removePreference(findPreference(PREF_LANGUAGE_SELECTION)); + } } @Override diff --git a/java/src/com/android/inputmethod/latin/Suggest.java b/java/src/com/android/inputmethod/latin/Suggest.java index cd7f71c2a..f37206223 100644 --- a/java/src/com/android/inputmethod/latin/Suggest.java +++ b/java/src/com/android/inputmethod/latin/Suggest.java @@ -75,7 +75,7 @@ public class Suggest implements Dictionary.WordCallback { public static final String DICT_KEY_USER_BIGRAM = "user_bigram"; public static final String DICT_KEY_WHITELIST ="whitelist"; - static final int LARGE_DICTIONARY_THRESHOLD = 200 * 1000; + public static final int LARGE_DICTIONARY_THRESHOLD = 200 * 1000; private static final boolean DBG = LatinImeLogger.sDBG;