Skip to content

Commit cf06e2c

Browse files
Mac WangMac Wang
authored andcommitted
Sort the IME list before showing to user
The original list is unsorted so the order is random to users. For users who installed two or more Chinese IMEs, they may see Chinese IME, English IME, Chinese IME. That's odd to users.
1 parent f34a7fb commit cf06e2c

File tree

1 file changed

+13
-9
lines changed

1 file changed

+13
-9
lines changed

services/java/com/android/server/InputMethodManagerService.java

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,12 @@
7878
import java.io.FileDescriptor;
7979
import java.io.IOException;
8080
import java.io.PrintWriter;
81+
import java.text.Collator;
8182
import java.util.ArrayList;
8283
import java.util.HashMap;
8384
import java.util.List;
85+
import java.util.Map;
86+
import java.util.TreeMap;
8487

8588
/**
8689
* This class provides a system service that manages input methods.
@@ -1513,21 +1516,22 @@ void showInputMethodMenu() {
15131516
hideInputMethodMenuLocked();
15141517

15151518
int N = immis.size();
1516-
1517-
mItems = new CharSequence[N];
1518-
mIms = new InputMethodInfo[N];
1519-
1520-
int j = 0;
1519+
1520+
final Map<CharSequence, InputMethodInfo> imMap =
1521+
new TreeMap<CharSequence, InputMethodInfo>(Collator.getInstance());
1522+
15211523
for (int i = 0; i < N; ++i) {
15221524
InputMethodInfo property = immis.get(i);
15231525
if (property == null) {
15241526
continue;
15251527
}
1526-
mItems[j] = property.loadLabel(pm);
1527-
mIms[j] = property;
1528-
j++;
1528+
imMap.put(property.loadLabel(pm), property);
15291529
}
1530-
1530+
1531+
N = imMap.size();
1532+
mItems = imMap.keySet().toArray(new CharSequence[N]);
1533+
mIms = imMap.values().toArray(new InputMethodInfo[N]);
1534+
15311535
int checkedItem = 0;
15321536
for (int i = 0; i < N; ++i) {
15331537
if (mIms[i].getId().equals(lastInputMethodId)) {

0 commit comments

Comments
 (0)