From ae70ee49492bd89c949946562b43a75f3c81b0ad Mon Sep 17 00:00:00 2001 From: satok Date: Tue, 6 Sep 2011 15:49:25 +0900 Subject: [PATCH] Sort subtypes in subtype enabler settings Bug: 3377334 Change-Id: Ie8dab8f6fb52610e783803cb902b032508d2b250 --- .../InputMethodAndSubtypeEnabler.java | 66 ++++++++++++++++++- 1 file changed, 63 insertions(+), 3 deletions(-) diff --git a/src/com/android/settings/inputmethod/InputMethodAndSubtypeEnabler.java b/src/com/android/settings/inputmethod/InputMethodAndSubtypeEnabler.java index f956a4ef347..d36e33cec68 100644 --- a/src/com/android/settings/inputmethod/InputMethodAndSubtypeEnabler.java +++ b/src/com/android/settings/inputmethod/InputMethodAndSubtypeEnabler.java @@ -37,6 +37,8 @@ import android.view.inputmethod.InputMethodManager; import android.view.inputmethod.InputMethodSubtype; import java.util.ArrayList; +import java.util.Collections; +import java.util.Comparator; import java.util.HashMap; import java.util.List; @@ -52,12 +54,13 @@ public class InputMethodAndSubtypeEnabler extends SettingsPreferenceFragment { private List mInputMethodProperties; private String mInputMethodId; private String mTitle; + private String mSystemLocale = ""; @Override public void onCreate(Bundle icicle) { super.onCreate(icicle); mImm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); - Configuration config = getResources().getConfiguration(); + final Configuration config = getResources().getConfiguration(); mHaveHardKeyboard = (config.keyboard == Configuration.KEYBOARD_QWERTY); final Bundle arguments = getArguments(); @@ -82,6 +85,7 @@ public class InputMethodAndSubtypeEnabler extends SettingsPreferenceFragment { } } + mSystemLocale = config.locale.toString(); onCreateIMM(); setPreferenceScreen(createPreferenceHierarchy()); } @@ -255,13 +259,17 @@ public class InputMethodAndSubtypeEnabler extends SettingsPreferenceFragment { autoSubtypeLabel = subtypeLabel; } } else { - final CheckBoxPreference chkbxPref = new CheckBoxPreference(context); + final CheckBoxPreference chkbxPref = new SubtypeCheckBoxPreference( + context, subtype.getLocale(), mSystemLocale); chkbxPref.setKey(imiId + subtype.hashCode()); chkbxPref.setTitle(subtypeLabel); - activeInputMethodsCategory.addPreference(chkbxPref); subtypePreferences.add(chkbxPref); } } + Collections.sort(subtypePreferences); + for (int j = 0; j < subtypePreferences.size(); ++j) { + activeInputMethodsCategory.addPreference(subtypePreferences.get(j)); + } mInputMethodAndSubtypePrefsMap.put(imiId, subtypePreferences); } if (isAutoSubtype) { @@ -359,4 +367,56 @@ public class InputMethodAndSubtypeEnabler extends SettingsPreferenceFragment { } setCheckedImplicitlyEnabledSubtypes(null); } + + private static class SubtypeCheckBoxPreference extends CheckBoxPreference { + private final boolean mIsSystemLocale; + private final boolean mIsSystemLanguage; + + public SubtypeCheckBoxPreference( + Context context, String subtypeLocale, String systemLocale) { + super(context); + if (TextUtils.isEmpty(subtypeLocale)) { + mIsSystemLocale = false; + mIsSystemLanguage = false; + } else { + mIsSystemLocale = subtypeLocale.equals(systemLocale); + mIsSystemLanguage = mIsSystemLocale + || subtypeLocale.startsWith(systemLocale.substring(0, 2)); + } + } + + @Override + public int compareTo(Preference p) { + if (p instanceof SubtypeCheckBoxPreference) { + final SubtypeCheckBoxPreference pref = ((SubtypeCheckBoxPreference)p); + final CharSequence t0 = getTitle(); + final CharSequence t1 = pref.getTitle(); + if (TextUtils.equals(t0, t1)) { + return 0; + } + if (mIsSystemLocale) { + return -1; + } + if (pref.mIsSystemLocale) { + return 1; + } + if (mIsSystemLanguage) { + return -1; + } + if (pref.mIsSystemLanguage) { + return 1; + } + if (TextUtils.isEmpty(t0)) { + return 1; + } + if (TextUtils.isEmpty(t1)) { + return -1; + } + return t0.toString().compareTo(t1.toString()); + } else { + Log.w(TAG, "Illegal preference type."); + return -1; + } + } + } }