Add sort method to InputMethodSubtype

Bug: 3364167

Change-Id: I94ad55b8eab49dc9b233dcb4e74429863b406fb4
This commit is contained in:
satok
2011-02-14 15:47:30 +09:00
parent f3032e9d9d
commit 7265d9bd6d
2 changed files with 39 additions and 5 deletions

View File

@@ -16,10 +16,14 @@
package android.view.inputmethod;
import android.content.Context;
import android.os.Parcel;
import android.os.Parcelable;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
/**
* This class is used to specify meta information of a subtype contained in an input method.
@@ -148,4 +152,35 @@ public final class InputMethodSubtype implements Parcelable {
String mode, String extraValue) {
return Arrays.hashCode(new Object[] {nameResId, iconResId, locale, mode, extraValue});
}
/**
* Sort the list of InputMethodSubtype
* @param context Context will be used for getting localized strings from IME
* @param flags Flags for the sort order
* @param imi InputMethodInfo of which subtypes are subject to be sorted
* @param subtypeList List of InputMethodSubtype which will be sorted
* @return Sorted list of subtypes
* @hide
*/
public static List<InputMethodSubtype> sort(Context context, int flags, InputMethodInfo imi,
List<InputMethodSubtype> subtypeList) {
if (imi == null) return subtypeList;
final HashSet<InputMethodSubtype> inputSubtypesSet = new HashSet<InputMethodSubtype>(
subtypeList);
final ArrayList<InputMethodSubtype> sortedList = new ArrayList<InputMethodSubtype>();
int N = imi.getSubtypeCount();
for (int i = 0; i < N; ++i) {
InputMethodSubtype subtype = imi.getSubtypeAt(i);
if (inputSubtypesSet.contains(subtype)) {
sortedList.add(subtype);
inputSubtypesSet.remove(subtype);
}
}
// If subtypes in inputSubtypesSet remain, that means these subtypes are not
// contained in imi, so the remaining subtypes will be appended.
for (InputMethodSubtype subtype: inputSubtypesSet) {
sortedList.add(subtype);
}
return sortedList;
}
}

View File

@@ -596,13 +596,12 @@ public class InputMethodManagerService extends IInputMethodManager.Stub
if (imi == null && mCurMethodId != null) {
imi = mMethodMap.get(mCurMethodId);
}
final List<InputMethodSubtype> enabledSubtypes =
List<InputMethodSubtype> enabledSubtypes =
mSettings.getEnabledInputMethodSubtypeListLocked(imi);
if (!allowsImplicitlySelectedSubtypes || enabledSubtypes.size() > 0) {
return enabledSubtypes;
} else {
return getApplicableSubtypesLocked(mRes, getSubtypes(imi));
if (allowsImplicitlySelectedSubtypes && enabledSubtypes.isEmpty()) {
enabledSubtypes = getApplicableSubtypesLocked(mRes, getSubtypes(imi));
}
return InputMethodSubtype.sort(mContext, 0, imi, enabledSubtypes);
}
public List<InputMethodSubtype> getEnabledInputMethodSubtypeList(InputMethodInfo imi,