import android.view.inputmethod.InputMethodManager;
import android.view.inputmethod.InputMethodSubtype;
+import java.text.Collator;
import java.util.ArrayList;
import java.util.Collections;
+import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
+import java.util.Locale;
public class InputMethodAndSubtypeEnabler extends SettingsPreferenceFragment {
private static final String TAG =InputMethodAndSubtypeEnabler.class.getSimpleName();
private String mInputMethodId;
private String mTitle;
private String mSystemLocale = "";
+ private Collator mCollator = Collator.getInstance();
@Override
public void onCreate(Bundle icicle) {
}
}
- mSystemLocale = config.locale.toString();
+ final Locale locale = config.locale;
+ mSystemLocale = locale.toString();
+ mCollator = Collator.getInstance(locale);
onCreateIMM();
setPreferenceScreen(createPreferenceHierarchy());
}
}
} else {
final CheckBoxPreference chkbxPref = new SubtypeCheckBoxPreference(
- context, subtype.getLocale(), mSystemLocale);
+ context, subtype.getLocale(), mSystemLocale, mCollator);
chkbxPref.setKey(imiId + subtype.hashCode());
chkbxPref.setTitle(subtypeLabel);
subtypePreferences.add(chkbxPref);
private static class SubtypeCheckBoxPreference extends CheckBoxPreference {
private final boolean mIsSystemLocale;
private final boolean mIsSystemLanguage;
+ private final Collator mCollator;
public SubtypeCheckBoxPreference(
- Context context, String subtypeLocale, String systemLocale) {
+ Context context, String subtypeLocale, String systemLocale, Collator collator) {
super(context);
if (TextUtils.isEmpty(subtypeLocale)) {
mIsSystemLocale = false;
mIsSystemLanguage = mIsSystemLocale
|| subtypeLocale.startsWith(systemLocale.substring(0, 2));
}
+ mCollator = collator;
}
@Override
if (TextUtils.isEmpty(t1)) {
return -1;
}
- return t0.toString().compareTo(t1.toString());
+ return mCollator.compare(t0.toString(), t1.toString());
} else {
Log.w(TAG, "Illegal preference type.");
- return -1;
+ return super.compareTo(p);
}
}
}
import android.content.res.Configuration;
import android.os.Bundle;
import android.preference.CheckBoxPreference;
+import android.preference.Preference;
import android.preference.PreferenceActivity;
import android.provider.Settings;
import android.text.TextUtils;
import android.widget.TextView;
import android.widget.Toast;
+import java.text.Collator;
import java.util.Comparator;
import java.util.List;
-public class InputMethodPreference extends CheckBoxPreference
- implements Comparator<InputMethodPreference> {
+public class InputMethodPreference extends CheckBoxPreference {
private static final String TAG = InputMethodPreference.class.getSimpleName();
private final SettingsPreferenceFragment mFragment;
private final InputMethodInfo mImi;
private final Intent mSettingsIntent;
private final boolean mAlwaysChecked;
private final boolean mIsSystemIme;
+ private final Collator mCollator;
private AlertDialog mDialog = null;
private ImageView mInputMethodSettingsButton;
if (mAlwaysChecked) {
setEnabled(false);
}
+ mCollator = Collator.getInstance(fragment.getResources().getConfiguration().locale);
}
@Override
}
@Override
- public int compare(InputMethodPreference arg0, InputMethodPreference arg1) {
- if (arg0.isEnabled() == arg0.isEnabled()) {
- return arg0.mImi.getId().compareTo(arg1.mImi.getId());
- } else {
- // Prefer system IMEs
- return arg0.isEnabled() ? 1 : -1;
+ public int compareTo(Preference p) {
+ if (!(p instanceof InputMethodPreference)) {
+ return super.compareTo(p);
+ }
+ final InputMethodPreference imp = (InputMethodPreference) p;
+ final boolean priority0 = mIsSystemIme && mAlwaysChecked;
+ final boolean priority1 = imp.mIsSystemIme && imp.mAlwaysChecked;
+ if (priority0 == priority1) {
+ final CharSequence t0 = getTitle();
+ final CharSequence t1 = imp.getTitle();
+ if (TextUtils.isEmpty(t0)) {
+ return 1;
+ }
+ if (TextUtils.isEmpty(t1)) {
+ return -1;
+ }
+ return mCollator.compare(t0.toString(), t1.toString());
}
+ // Prefer always checked system IMEs
+ return priority0 ? -1 : 1;
}
private void saveImeSettings() {