Merge "Fix the sort order of the input methods & subtypes in the settings." into honeycomb-mr1

This commit is contained in:
Ken Wakasa
2011-03-04 02:57:20 -08:00
committed by Android (Google) Code Review
2 changed files with 39 additions and 20 deletions

View File

@ -89,14 +89,12 @@ public class InputMethodsPanel extends LinearLayout implements StatusBarPanel,
public int compare(InputMethodInfo imi1, InputMethodInfo imi2) { public int compare(InputMethodInfo imi1, InputMethodInfo imi2) {
if (imi2 == null) return 0; if (imi2 == null) return 0;
if (imi1 == null) return 1; if (imi1 == null) return 1;
if (mPackageManager != null) { if (mPackageManager == null) {
CharSequence imiId1 = imi1.loadLabel(mPackageManager) + "/" + imi1.getId(); return imi1.getId().compareTo(imi2.getId());
CharSequence imiId2 = imi2.loadLabel(mPackageManager) + "/" + imi2.getId();
if (imiId1 != null && imiId2 != null) {
return imiId1.toString().compareTo(imiId2.toString());
}
} }
return imi1.getId().compareTo(imi2.getId()); CharSequence imiId1 = imi1.loadLabel(mPackageManager) + "/" + imi1.getId();
CharSequence imiId2 = imi2.loadLabel(mPackageManager) + "/" + imi2.getId();
return imiId1.toString().compareTo(imiId2.toString());
} }
} }
@ -267,7 +265,6 @@ public class InputMethodsPanel extends LinearLayout implements StatusBarPanel,
Map<InputMethodInfo, List<InputMethodSubtype>> enabledIMIs = Map<InputMethodInfo, List<InputMethodSubtype>> enabledIMIs =
getEnabledInputMethodAndSubtypeList(); getEnabledInputMethodAndSubtypeList();
// TODO: Sort by alphabet and mode.
Set<InputMethodInfo> cachedImiSet = enabledIMIs.keySet(); Set<InputMethodInfo> cachedImiSet = enabledIMIs.keySet();
for (InputMethodInfo imi: cachedImiSet) { for (InputMethodInfo imi: cachedImiSet) {
List<InputMethodSubtype> subtypes = enabledIMIs.get(imi); List<InputMethodSubtype> subtypes = enabledIMIs.get(imi);

View File

@ -82,8 +82,8 @@ import android.view.inputmethod.InputMethodSubtype;
import java.io.FileDescriptor; import java.io.FileDescriptor;
import java.io.IOException; import java.io.IOException;
import java.io.PrintWriter; import java.io.PrintWriter;
import java.text.Collator;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Comparator;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
import java.util.List; import java.util.List;
@ -1750,10 +1750,28 @@ public class InputMethodManagerService extends IInputMethodManager.Stub
hideInputMethodMenuLocked(); hideInputMethodMenuLocked();
final Map<CharSequence, Pair<InputMethodInfo, Integer>> imMap = final TreeMap<InputMethodInfo, List<InputMethodSubtype>> sortedImmis =
new TreeMap<CharSequence, Pair<InputMethodInfo, Integer>>(Collator.getInstance()); new TreeMap<InputMethodInfo, List<InputMethodSubtype>>(
new Comparator<InputMethodInfo>() {
@Override
public int compare(InputMethodInfo imi1, InputMethodInfo imi2) {
if (imi2 == null) return 0;
if (imi1 == null) return 1;
if (pm == null) {
return imi1.getId().compareTo(imi2.getId());
}
CharSequence imiId1 = imi1.loadLabel(pm) + "/" + imi1.getId();
CharSequence imiId2 = imi2.loadLabel(pm) + "/" + imi2.getId();
return imiId1.toString().compareTo(imiId2.toString());
}
});
for (InputMethodInfo imi: immis.keySet()) { sortedImmis.putAll(immis);
final ArrayList<Pair<CharSequence, Pair<InputMethodInfo, Integer>>> imList =
new ArrayList<Pair<CharSequence, Pair<InputMethodInfo, Integer>>>();
for (InputMethodInfo imi : sortedImmis.keySet()) {
if (imi == null) continue; if (imi == null) continue;
List<InputMethodSubtype> explicitlyOrImplicitlyEnabledSubtypeList = immis.get(imi); List<InputMethodSubtype> explicitlyOrImplicitlyEnabledSubtypeList = immis.get(imi);
HashSet<String> enabledSubtypeSet = new HashSet<String>(); HashSet<String> enabledSubtypeSet = new HashSet<String>();
@ -1767,35 +1785,39 @@ public class InputMethodManagerService extends IInputMethodManager.Stub
for (int j = 0; j < subtypeCount; ++j) { for (int j = 0; j < subtypeCount; ++j) {
InputMethodSubtype subtype = imi.getSubtypeAt(j); InputMethodSubtype subtype = imi.getSubtypeAt(j);
if (enabledSubtypeSet.contains(String.valueOf(subtype.hashCode()))) { if (enabledSubtypeSet.contains(String.valueOf(subtype.hashCode()))) {
CharSequence title; final CharSequence title;
int nameResId = subtype.getNameResId(); int nameResId = subtype.getNameResId();
String mode = subtype.getMode(); String mode = subtype.getMode();
if (nameResId != 0) { if (nameResId != 0) {
title = TextUtils.concat(pm.getText(imi.getPackageName(), title = TextUtils.concat(pm.getText(imi.getPackageName(),
nameResId, imi.getServiceInfo().applicationInfo), nameResId, imi.getServiceInfo().applicationInfo),
" (", label, ")"); (TextUtils.isEmpty(label) ? "" : " (" + label + ")"));
} else { } else {
CharSequence language = subtype.getLocale(); CharSequence language = subtype.getLocale();
// TODO: Use more friendly Title and UI // TODO: Use more friendly Title and UI
title = label + "," + (mode == null ? "" : mode) + "," title = label + "," + (mode == null ? "" : mode) + ","
+ (language == null ? "" : language); + (language == null ? "" : language);
} }
imMap.put(title, new Pair<InputMethodInfo, Integer>(imi, j)); imList.add(new Pair<CharSequence, Pair<InputMethodInfo, Integer>>(
title, new Pair<InputMethodInfo, Integer>(imi, j)));
} }
} }
} else { } else {
imMap.put(label, imList.add(new Pair<CharSequence, Pair<InputMethodInfo, Integer>>(
new Pair<InputMethodInfo, Integer>(imi, NOT_A_SUBTYPE_ID)); label, new Pair<InputMethodInfo, Integer>(imi, NOT_A_SUBTYPE_ID)));
} }
} }
final int N = imMap.size(); final int N = imList.size();
mItems = imMap.keySet().toArray(new CharSequence[N]); mItems = new CharSequence[N];
for (int i = 0; i < N; ++i) {
mItems[i] = imList.get(i).first;
}
mIms = new InputMethodInfo[N]; mIms = new InputMethodInfo[N];
mSubtypeIds = new int[N]; mSubtypeIds = new int[N];
int checkedItem = 0; int checkedItem = 0;
for (int i = 0; i < N; ++i) { for (int i = 0; i < N; ++i) {
Pair<InputMethodInfo, Integer> value = imMap.get(mItems[i]); Pair<InputMethodInfo, Integer> value = imList.get(i).second;
mIms[i] = value.first; mIms[i] = value.first;
mSubtypeIds[i] = value.second; mSubtypeIds[i] = value.second;
if (mIms[i].getId().equals(lastInputMethodId)) { if (mIms[i].getId().equals(lastInputMethodId)) {