Merge "Fix sort order of InputMethodSubtype" into jb-mr2-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
b5b541a577
@@ -36,10 +36,13 @@ import android.view.inputmethod.InputMethodInfo;
|
|||||||
import android.view.inputmethod.InputMethodManager;
|
import android.view.inputmethod.InputMethodManager;
|
||||||
import android.view.inputmethod.InputMethodSubtype;
|
import android.view.inputmethod.InputMethodSubtype;
|
||||||
|
|
||||||
|
import java.text.Collator;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
|
import java.util.Comparator;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Locale;
|
||||||
|
|
||||||
public class InputMethodAndSubtypeEnabler extends SettingsPreferenceFragment {
|
public class InputMethodAndSubtypeEnabler extends SettingsPreferenceFragment {
|
||||||
private static final String TAG =InputMethodAndSubtypeEnabler.class.getSimpleName();
|
private static final String TAG =InputMethodAndSubtypeEnabler.class.getSimpleName();
|
||||||
@@ -54,6 +57,7 @@ public class InputMethodAndSubtypeEnabler extends SettingsPreferenceFragment {
|
|||||||
private String mInputMethodId;
|
private String mInputMethodId;
|
||||||
private String mTitle;
|
private String mTitle;
|
||||||
private String mSystemLocale = "";
|
private String mSystemLocale = "";
|
||||||
|
private Collator mCollator = Collator.getInstance();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreate(Bundle icicle) {
|
public void onCreate(Bundle icicle) {
|
||||||
@@ -84,7 +88,9 @@ public class InputMethodAndSubtypeEnabler extends SettingsPreferenceFragment {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
mSystemLocale = config.locale.toString();
|
final Locale locale = config.locale;
|
||||||
|
mSystemLocale = locale.toString();
|
||||||
|
mCollator = Collator.getInstance(locale);
|
||||||
onCreateIMM();
|
onCreateIMM();
|
||||||
setPreferenceScreen(createPreferenceHierarchy());
|
setPreferenceScreen(createPreferenceHierarchy());
|
||||||
}
|
}
|
||||||
@@ -259,7 +265,7 @@ public class InputMethodAndSubtypeEnabler extends SettingsPreferenceFragment {
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
final CheckBoxPreference chkbxPref = new SubtypeCheckBoxPreference(
|
final CheckBoxPreference chkbxPref = new SubtypeCheckBoxPreference(
|
||||||
context, subtype.getLocale(), mSystemLocale);
|
context, subtype.getLocale(), mSystemLocale, mCollator);
|
||||||
chkbxPref.setKey(imiId + subtype.hashCode());
|
chkbxPref.setKey(imiId + subtype.hashCode());
|
||||||
chkbxPref.setTitle(subtypeLabel);
|
chkbxPref.setTitle(subtypeLabel);
|
||||||
subtypePreferences.add(chkbxPref);
|
subtypePreferences.add(chkbxPref);
|
||||||
@@ -370,9 +376,10 @@ public class InputMethodAndSubtypeEnabler extends SettingsPreferenceFragment {
|
|||||||
private static class SubtypeCheckBoxPreference extends CheckBoxPreference {
|
private static class SubtypeCheckBoxPreference extends CheckBoxPreference {
|
||||||
private final boolean mIsSystemLocale;
|
private final boolean mIsSystemLocale;
|
||||||
private final boolean mIsSystemLanguage;
|
private final boolean mIsSystemLanguage;
|
||||||
|
private final Collator mCollator;
|
||||||
|
|
||||||
public SubtypeCheckBoxPreference(
|
public SubtypeCheckBoxPreference(
|
||||||
Context context, String subtypeLocale, String systemLocale) {
|
Context context, String subtypeLocale, String systemLocale, Collator collator) {
|
||||||
super(context);
|
super(context);
|
||||||
if (TextUtils.isEmpty(subtypeLocale)) {
|
if (TextUtils.isEmpty(subtypeLocale)) {
|
||||||
mIsSystemLocale = false;
|
mIsSystemLocale = false;
|
||||||
@@ -382,6 +389,7 @@ public class InputMethodAndSubtypeEnabler extends SettingsPreferenceFragment {
|
|||||||
mIsSystemLanguage = mIsSystemLocale
|
mIsSystemLanguage = mIsSystemLocale
|
||||||
|| subtypeLocale.startsWith(systemLocale.substring(0, 2));
|
|| subtypeLocale.startsWith(systemLocale.substring(0, 2));
|
||||||
}
|
}
|
||||||
|
mCollator = collator;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -411,10 +419,10 @@ public class InputMethodAndSubtypeEnabler extends SettingsPreferenceFragment {
|
|||||||
if (TextUtils.isEmpty(t1)) {
|
if (TextUtils.isEmpty(t1)) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
return t0.toString().compareTo(t1.toString());
|
return mCollator.compare(t0.toString(), t1.toString());
|
||||||
} else {
|
} else {
|
||||||
Log.w(TAG, "Illegal preference type.");
|
Log.w(TAG, "Illegal preference type.");
|
||||||
return -1;
|
return super.compareTo(p);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -28,6 +28,7 @@ import android.content.Intent;
|
|||||||
import android.content.res.Configuration;
|
import android.content.res.Configuration;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.preference.CheckBoxPreference;
|
import android.preference.CheckBoxPreference;
|
||||||
|
import android.preference.Preference;
|
||||||
import android.preference.PreferenceActivity;
|
import android.preference.PreferenceActivity;
|
||||||
import android.provider.Settings;
|
import android.provider.Settings;
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
@@ -42,11 +43,11 @@ import android.widget.ImageView;
|
|||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
|
||||||
|
import java.text.Collator;
|
||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class InputMethodPreference extends CheckBoxPreference
|
public class InputMethodPreference extends CheckBoxPreference {
|
||||||
implements Comparator<InputMethodPreference> {
|
|
||||||
private static final String TAG = InputMethodPreference.class.getSimpleName();
|
private static final String TAG = InputMethodPreference.class.getSimpleName();
|
||||||
private final SettingsPreferenceFragment mFragment;
|
private final SettingsPreferenceFragment mFragment;
|
||||||
private final InputMethodInfo mImi;
|
private final InputMethodInfo mImi;
|
||||||
@@ -54,6 +55,7 @@ public class InputMethodPreference extends CheckBoxPreference
|
|||||||
private final Intent mSettingsIntent;
|
private final Intent mSettingsIntent;
|
||||||
private final boolean mAlwaysChecked;
|
private final boolean mAlwaysChecked;
|
||||||
private final boolean mIsSystemIme;
|
private final boolean mIsSystemIme;
|
||||||
|
private final Collator mCollator;
|
||||||
|
|
||||||
private AlertDialog mDialog = null;
|
private AlertDialog mDialog = null;
|
||||||
private ImageView mInputMethodSettingsButton;
|
private ImageView mInputMethodSettingsButton;
|
||||||
@@ -95,6 +97,7 @@ public class InputMethodPreference extends CheckBoxPreference
|
|||||||
if (mAlwaysChecked) {
|
if (mAlwaysChecked) {
|
||||||
setEnabled(false);
|
setEnabled(false);
|
||||||
}
|
}
|
||||||
|
mCollator = Collator.getInstance(fragment.getResources().getConfiguration().locale);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -276,13 +279,26 @@ public class InputMethodPreference extends CheckBoxPreference
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int compare(InputMethodPreference arg0, InputMethodPreference arg1) {
|
public int compareTo(Preference p) {
|
||||||
if (arg0.isEnabled() == arg0.isEnabled()) {
|
if (!(p instanceof InputMethodPreference)) {
|
||||||
return arg0.mImi.getId().compareTo(arg1.mImi.getId());
|
return super.compareTo(p);
|
||||||
} else {
|
|
||||||
// Prefer system IMEs
|
|
||||||
return arg0.isEnabled() ? 1 : -1;
|
|
||||||
}
|
}
|
||||||
|
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() {
|
private void saveImeSettings() {
|
||||||
|
Reference in New Issue
Block a user