diff options
| author | 2017-08-31 13:08:56 -0700 | |
|---|---|---|
| committer | 2017-09-15 16:46:12 +0900 | |
| commit | 9f240ad69726d2454fb8f9e34a6133c0d6d20b9f (patch) | |
| tree | 993890090640625c5dea8d2bd010e4df89ace4e5 /packages/SettingsLib/src | |
| parent | 52ec920914198fab2537ca2e23712139c7d44ff6 (diff) | |
Fix InputMethodPreference.compareTo method
Fixes: 64232283
Test: bit SettingsLibTests:com.android.settingslib.inputmethod.InputMethodPreferenceTest
bit SettingsLibTests:com.android.settingslib.inputmethod.InputMethodSubtypePreferenceTest
Change-Id: I5b18e8c854dc6a8e4ff35aa356c9acd63acd3a53
Diffstat (limited to 'packages/SettingsLib/src')
| -rw-r--r--[-rwxr-xr-x] | packages/SettingsLib/src/com/android/settingslib/inputmethod/InputMethodPreference.java | 43 |
1 files changed, 26 insertions, 17 deletions
diff --git a/packages/SettingsLib/src/com/android/settingslib/inputmethod/InputMethodPreference.java b/packages/SettingsLib/src/com/android/settingslib/inputmethod/InputMethodPreference.java index 1bbc878b56c9..5e25f519a130 100755..100644 --- a/packages/SettingsLib/src/com/android/settingslib/inputmethod/InputMethodPreference.java +++ b/packages/SettingsLib/src/com/android/settingslib/inputmethod/InputMethodPreference.java @@ -34,6 +34,7 @@ import android.view.inputmethod.InputMethodManager; import android.view.inputmethod.InputMethodSubtype; import android.widget.Toast; +import com.android.internal.annotations.VisibleForTesting; import com.android.internal.inputmethod.InputMethodUtils; import com.android.settingslib.R; import com.android.settingslib.RestrictedLockUtils; @@ -91,20 +92,28 @@ public class InputMethodPreference extends RestrictedSwitchPreference implements public InputMethodPreference(final Context context, final InputMethodInfo imi, final boolean isImeEnabler, final boolean isAllowedByOrganization, final OnSavePreferenceListener onSaveListener) { + this(context, imi, imi.loadLabel(context.getPackageManager()), isAllowedByOrganization, + onSaveListener); + if (!isImeEnabler) { + // Remove switch widget. + setWidgetLayoutResource(NO_WIDGET); + } + } + + @VisibleForTesting + InputMethodPreference(final Context context, final InputMethodInfo imi, + final CharSequence title, final boolean isAllowedByOrganization, + final OnSavePreferenceListener onSaveListener) { super(context); setPersistent(false); mImi = imi; mIsAllowedByOrganization = isAllowedByOrganization; mOnSaveListener = onSaveListener; - if (!isImeEnabler) { - // Remove switch widget. - setWidgetLayoutResource(NO_WIDGET); - } // Disable on/off switch texts. setSwitchTextOn(EMPTY_TEXT); setSwitchTextOff(EMPTY_TEXT); setKey(imi.getId()); - setTitle(imi.loadLabel(context.getPackageManager())); + setTitle(title); final String settingsActivity = imi.getSettingsActivity(); if (TextUtils.isEmpty(settingsActivity)) { setIntent(null); @@ -283,18 +292,18 @@ public class InputMethodPreference extends RestrictedSwitchPreference implements if (this == rhs) { return 0; } - if (mHasPriorityInSorting == rhs.mHasPriorityInSorting) { - final CharSequence t0 = getTitle(); - final CharSequence t1 = rhs.getTitle(); - if (TextUtils.isEmpty(t0)) { - return 1; - } - if (TextUtils.isEmpty(t1)) { - return -1; - } - return collator.compare(t0.toString(), t1.toString()); + if (mHasPriorityInSorting != rhs.mHasPriorityInSorting) { + // Prefer always checked system IMEs + return mHasPriorityInSorting ? -1 : 1; + } + final CharSequence title = getTitle(); + final CharSequence rhsTitle = rhs.getTitle(); + final boolean emptyTitle = TextUtils.isEmpty(title); + final boolean rhsEmptyTitle = TextUtils.isEmpty(rhsTitle); + if (!emptyTitle && !rhsEmptyTitle) { + return collator.compare(title.toString(), rhsTitle.toString()); } - // Prefer always checked system IMEs - return mHasPriorityInSorting ? -1 : 1; + // For historical reasons, an empty text needs to be put at the first. + return (emptyTitle ? -1 : 0) - (rhsEmptyTitle ? -1 : 0); } } |