@@ -2410,17 +2410,63 @@ public void onClick(DialogInterface dialog, int whichButton) {
24102410 }
24112411 }
24122412
2413- private static class ImeSubtypeListItem {
2413+ private static class ImeSubtypeListItem implements Comparable < ImeSubtypeListItem > {
24142414 public final CharSequence mImeName ;
24152415 public final CharSequence mSubtypeName ;
24162416 public final InputMethodInfo mImi ;
24172417 public final int mSubtypeId ;
2418+ private final boolean mIsSystemLocale ;
2419+ private final boolean mIsSystemLanguage ;
2420+
24182421 public ImeSubtypeListItem (CharSequence imeName , CharSequence subtypeName ,
2419- InputMethodInfo imi , int subtypeId ) {
2422+ InputMethodInfo imi , int subtypeId , String subtypeLocale , String systemLocale ) {
24202423 mImeName = imeName ;
24212424 mSubtypeName = subtypeName ;
24222425 mImi = imi ;
24232426 mSubtypeId = subtypeId ;
2427+ if (TextUtils .isEmpty (subtypeLocale )) {
2428+ mIsSystemLocale = false ;
2429+ mIsSystemLanguage = false ;
2430+ } else {
2431+ mIsSystemLocale = subtypeLocale .equals (systemLocale );
2432+ mIsSystemLanguage = mIsSystemLocale
2433+ || subtypeLocale .startsWith (systemLocale .substring (0 , 2 ));
2434+ }
2435+ }
2436+
2437+ @ Override
2438+ public int compareTo (ImeSubtypeListItem other ) {
2439+ if (TextUtils .isEmpty (mImeName )) {
2440+ return 1 ;
2441+ }
2442+ if (TextUtils .isEmpty (other .mImeName )) {
2443+ return -1 ;
2444+ }
2445+ if (!TextUtils .equals (mImeName , other .mImeName )) {
2446+ return mImeName .toString ().compareTo (other .mImeName .toString ());
2447+ }
2448+ if (TextUtils .equals (mSubtypeName , other .mSubtypeName )) {
2449+ return 0 ;
2450+ }
2451+ if (mIsSystemLocale ) {
2452+ return -1 ;
2453+ }
2454+ if (other .mIsSystemLocale ) {
2455+ return 1 ;
2456+ }
2457+ if (mIsSystemLanguage ) {
2458+ return -1 ;
2459+ }
2460+ if (other .mIsSystemLanguage ) {
2461+ return 1 ;
2462+ }
2463+ if (TextUtils .isEmpty (mSubtypeName )) {
2464+ return 1 ;
2465+ }
2466+ if (TextUtils .isEmpty (other .mSubtypeName )) {
2467+ return -1 ;
2468+ }
2469+ return mSubtypeName .toString ().compareTo (other .mSubtypeName .toString ());
24242470 }
24252471 }
24262472
@@ -2952,10 +2998,13 @@ private static class InputMethodAndSubtypeListManager {
29522998 private final Context mContext ;
29532999 private final PackageManager mPm ;
29543000 private final InputMethodManagerService mImms ;
3001+ private final String mSystemLocaleStr ;
29553002 public InputMethodAndSubtypeListManager (Context context , InputMethodManagerService imms ) {
29563003 mContext = context ;
29573004 mPm = context .getPackageManager ();
29583005 mImms = imms ;
3006+ mSystemLocaleStr =
3007+ imms .mLastSystemLocale != null ? imms .mLastSystemLocale .toString () : "" ;
29593008 }
29603009
29613010 private final TreeMap <InputMethodInfo , List <InputMethodSubtype >> mSortedImmis =
@@ -3043,7 +3092,8 @@ public List<ImeSubtypeListItem> getSortedInputMethodAndSubtypeList(boolean showS
30433092 subtype .overridesImplicitlyEnabledSubtype () ? null
30443093 : subtype .getDisplayName (mContext , imi .getPackageName (),
30453094 imi .getServiceInfo ().applicationInfo );
3046- imList .add (new ImeSubtypeListItem (imeLabel , subtypeLabel , imi , j ));
3095+ imList .add (new ImeSubtypeListItem (imeLabel , subtypeLabel , imi , j ,
3096+ subtype .getLocale (), mSystemLocaleStr ));
30473097
30483098 // Removing this subtype from enabledSubtypeSet because we no longer
30493099 // need to add an entry of this subtype to imList to avoid duplicated
@@ -3052,9 +3102,11 @@ public List<ImeSubtypeListItem> getSortedInputMethodAndSubtypeList(boolean showS
30523102 }
30533103 }
30543104 } else {
3055- imList .add (new ImeSubtypeListItem (imeLabel , null , imi , NOT_A_SUBTYPE_ID ));
3105+ imList .add (new ImeSubtypeListItem (imeLabel , null , imi , NOT_A_SUBTYPE_ID ,
3106+ null , mSystemLocaleStr ));
30563107 }
30573108 }
3109+ Collections .sort (imList );
30583110 return imList ;
30593111 }
30603112 }
0 commit comments