Fix sort order of InputMethodSubtype
Bug: 8638372 Change-Id: I65d30f968708dc836635f687aa51b51816daccdb
This commit is contained in:
@@ -28,6 +28,7 @@ import android.content.Intent;
|
||||
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;
|
||||
@@ -42,11 +43,11 @@ import android.widget.ImageView;
|
||||
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;
|
||||
@@ -54,6 +55,7 @@ public class InputMethodPreference extends CheckBoxPreference
|
||||
private final Intent mSettingsIntent;
|
||||
private final boolean mAlwaysChecked;
|
||||
private final boolean mIsSystemIme;
|
||||
private final Collator mCollator;
|
||||
|
||||
private AlertDialog mDialog = null;
|
||||
private ImageView mInputMethodSettingsButton;
|
||||
@@ -95,6 +97,7 @@ public class InputMethodPreference extends CheckBoxPreference
|
||||
if (mAlwaysChecked) {
|
||||
setEnabled(false);
|
||||
}
|
||||
mCollator = Collator.getInstance(fragment.getResources().getConfiguration().locale);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -276,13 +279,26 @@ public class InputMethodPreference extends CheckBoxPreference
|
||||
}
|
||||
|
||||
@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() {
|
||||
|
Reference in New Issue
Block a user