Merge "Keyboard shortcuts: sort application items" into nyc-dev

am: fecb3b8

* commit 'fecb3b8fd10ce375b059b5caec304e0b0f4d0333':
  Keyboard shortcuts: sort application items

Change-Id: Idecb1ed72929ac75d7e95ca9da0c7ad91e6d8436
This commit is contained in:
Andrei Stingaceanu
2016-04-11 10:06:28 +00:00
committed by android-build-merger

View File

@@ -58,11 +58,15 @@ import com.android.systemui.R;
import com.android.systemui.recents.Recents; import com.android.systemui.recents.Recents;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List; import java.util.List;
import static android.content.Context.LAYOUT_INFLATER_SERVICE; import static android.content.Context.LAYOUT_INFLATER_SERVICE;
import static android.view.WindowManager.LayoutParams.TYPE_SYSTEM_DIALOG; import static android.view.WindowManager.LayoutParams.TYPE_SYSTEM_DIALOG;
import com.google.android.collect.Lists;
/** /**
* Contains functionality for handling keyboard shortcuts. * Contains functionality for handling keyboard shortcuts.
*/ */
@@ -76,11 +80,32 @@ public final class KeyboardShortcuts {
private final Handler mHandler = new Handler(Looper.getMainLooper()); private final Handler mHandler = new Handler(Looper.getMainLooper());
private final Context mContext; private final Context mContext;
private final IPackageManager mPackageManager; private final IPackageManager mPackageManager;
private final OnClickListener dialogCloseListener = new DialogInterface.OnClickListener() { private final OnClickListener mDialogCloseListener = new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) { public void onClick(DialogInterface dialog, int id) {
dismissKeyboardShortcutsDialog(); dismissKeyboardShortcutsDialog();
} }
}; };
private final Comparator<KeyboardShortcutInfo> mApplicationItemsComparator =
new Comparator<KeyboardShortcutInfo>() {
@Override
public int compare(KeyboardShortcutInfo ksh1, KeyboardShortcutInfo ksh2) {
boolean ksh1ShouldBeLast = ksh1.getLabel() == null
|| ksh1.getLabel().toString().isEmpty();
boolean ksh2ShouldBeLast = ksh2.getLabel() == null
|| ksh2.getLabel().toString().isEmpty();
if (ksh1ShouldBeLast && ksh2ShouldBeLast) {
return 0;
}
if (ksh1ShouldBeLast) {
return 1;
}
if (ksh2ShouldBeLast) {
return -1;
}
return (ksh1.getLabel().toString()).compareToIgnoreCase(
ksh2.getLabel().toString());
}
};
private Dialog mKeyboardShortcutsDialog; private Dialog mKeyboardShortcutsDialog;
private KeyCharacterMap mKeyCharacterMap; private KeyCharacterMap mKeyCharacterMap;
@@ -346,9 +371,7 @@ public final class KeyboardShortcuts {
private KeyboardShortcutGroup getDefaultApplicationShortcuts() { private KeyboardShortcutGroup getDefaultApplicationShortcuts() {
final int userId = mContext.getUserId(); final int userId = mContext.getUserId();
final KeyboardShortcutGroup applicationGroup = new KeyboardShortcutGroup( List<KeyboardShortcutInfo> keyboardShortcutInfoAppItems = Lists.newArrayList();
mContext.getString(R.string.keyboard_shortcut_group_applications),
true);
// Assist. // Assist.
final AssistUtils assistUtils = new AssistUtils(mContext); final AssistUtils assistUtils = new AssistUtils(mContext);
@@ -366,7 +389,7 @@ public final class KeyboardShortcuts {
assistPackageInfo.applicationInfo.packageName, assistPackageInfo.applicationInfo.packageName,
assistPackageInfo.applicationInfo.icon); assistPackageInfo.applicationInfo.icon);
applicationGroup.addItem(new KeyboardShortcutInfo( keyboardShortcutInfoAppItems.add(new KeyboardShortcutInfo(
mContext.getString(R.string.keyboard_shortcut_group_applications_assist), mContext.getString(R.string.keyboard_shortcut_group_applications_assist),
assistIcon, assistIcon,
KeyEvent.KEYCODE_UNKNOWN, KeyEvent.KEYCODE_UNKNOWN,
@@ -376,7 +399,7 @@ public final class KeyboardShortcuts {
// Browser. // Browser.
final Icon browserIcon = getIconForIntentCategory(Intent.CATEGORY_APP_BROWSER, userId); final Icon browserIcon = getIconForIntentCategory(Intent.CATEGORY_APP_BROWSER, userId);
if (browserIcon != null) { if (browserIcon != null) {
applicationGroup.addItem(new KeyboardShortcutInfo( keyboardShortcutInfoAppItems.add(new KeyboardShortcutInfo(
mContext.getString(R.string.keyboard_shortcut_group_applications_browser), mContext.getString(R.string.keyboard_shortcut_group_applications_browser),
browserIcon, browserIcon,
KeyEvent.KEYCODE_B, KeyEvent.KEYCODE_B,
@@ -387,7 +410,7 @@ public final class KeyboardShortcuts {
// Contacts. // Contacts.
final Icon contactsIcon = getIconForIntentCategory(Intent.CATEGORY_APP_CONTACTS, userId); final Icon contactsIcon = getIconForIntentCategory(Intent.CATEGORY_APP_CONTACTS, userId);
if (contactsIcon != null) { if (contactsIcon != null) {
applicationGroup.addItem(new KeyboardShortcutInfo( keyboardShortcutInfoAppItems.add(new KeyboardShortcutInfo(
mContext.getString(R.string.keyboard_shortcut_group_applications_contacts), mContext.getString(R.string.keyboard_shortcut_group_applications_contacts),
contactsIcon, contactsIcon,
KeyEvent.KEYCODE_C, KeyEvent.KEYCODE_C,
@@ -397,7 +420,7 @@ public final class KeyboardShortcuts {
// Email. // Email.
final Icon emailIcon = getIconForIntentCategory(Intent.CATEGORY_APP_EMAIL, userId); final Icon emailIcon = getIconForIntentCategory(Intent.CATEGORY_APP_EMAIL, userId);
if (emailIcon != null) { if (emailIcon != null) {
applicationGroup.addItem(new KeyboardShortcutInfo( keyboardShortcutInfoAppItems.add(new KeyboardShortcutInfo(
mContext.getString(R.string.keyboard_shortcut_group_applications_email), mContext.getString(R.string.keyboard_shortcut_group_applications_email),
emailIcon, emailIcon,
KeyEvent.KEYCODE_E, KeyEvent.KEYCODE_E,
@@ -407,7 +430,7 @@ public final class KeyboardShortcuts {
// Messaging. // Messaging.
final Icon messagingIcon = getIconForIntentCategory(Intent.CATEGORY_APP_MESSAGING, userId); final Icon messagingIcon = getIconForIntentCategory(Intent.CATEGORY_APP_MESSAGING, userId);
if (messagingIcon != null) { if (messagingIcon != null) {
applicationGroup.addItem(new KeyboardShortcutInfo( keyboardShortcutInfoAppItems.add(new KeyboardShortcutInfo(
mContext.getString(R.string.keyboard_shortcut_group_applications_im), mContext.getString(R.string.keyboard_shortcut_group_applications_im),
messagingIcon, messagingIcon,
KeyEvent.KEYCODE_T, KeyEvent.KEYCODE_T,
@@ -417,7 +440,7 @@ public final class KeyboardShortcuts {
// Music. // Music.
final Icon musicIcon = getIconForIntentCategory(Intent.CATEGORY_APP_MUSIC, userId); final Icon musicIcon = getIconForIntentCategory(Intent.CATEGORY_APP_MUSIC, userId);
if (musicIcon != null) { if (musicIcon != null) {
applicationGroup.addItem(new KeyboardShortcutInfo( keyboardShortcutInfoAppItems.add(new KeyboardShortcutInfo(
mContext.getString(R.string.keyboard_shortcut_group_applications_music), mContext.getString(R.string.keyboard_shortcut_group_applications_music),
musicIcon, musicIcon,
KeyEvent.KEYCODE_P, KeyEvent.KEYCODE_P,
@@ -427,14 +450,24 @@ public final class KeyboardShortcuts {
// Calendar. // Calendar.
final Icon calendarIcon = getIconForIntentCategory(Intent.CATEGORY_APP_CALENDAR, userId); final Icon calendarIcon = getIconForIntentCategory(Intent.CATEGORY_APP_CALENDAR, userId);
if (calendarIcon != null) { if (calendarIcon != null) {
applicationGroup.addItem(new KeyboardShortcutInfo( keyboardShortcutInfoAppItems.add(new KeyboardShortcutInfo(
mContext.getString(R.string.keyboard_shortcut_group_applications_calendar), mContext.getString(R.string.keyboard_shortcut_group_applications_calendar),
calendarIcon, calendarIcon,
KeyEvent.KEYCODE_L, KeyEvent.KEYCODE_L,
KeyEvent.META_META_ON)); KeyEvent.META_META_ON));
} }
return applicationGroup.getItems().size() == 0 ? null : applicationGroup; final int itemsSize = keyboardShortcutInfoAppItems.size();
if (itemsSize == 0) {
return null;
}
// Sorts by label, case insensitive with nulls and/or empty labels last.
Collections.sort(keyboardShortcutInfoAppItems, mApplicationItemsComparator);
return new KeyboardShortcutGroup(
mContext.getString(R.string.keyboard_shortcut_group_applications),
keyboardShortcutInfoAppItems,
true);
} }
private Icon getIconForIntentCategory(String intentCategory, int userId) { private Icon getIconForIntentCategory(String intentCategory, int userId) {
@@ -485,7 +518,7 @@ public final class KeyboardShortcuts {
populateKeyboardShortcuts((LinearLayout) keyboardShortcutsView.findViewById( populateKeyboardShortcuts((LinearLayout) keyboardShortcutsView.findViewById(
R.id.keyboard_shortcuts_container), keyboardShortcutGroups); R.id.keyboard_shortcuts_container), keyboardShortcutGroups);
dialogBuilder.setView(keyboardShortcutsView); dialogBuilder.setView(keyboardShortcutsView);
dialogBuilder.setPositiveButton(R.string.quick_settings_done, dialogCloseListener); dialogBuilder.setPositiveButton(R.string.quick_settings_done, mDialogCloseListener);
mKeyboardShortcutsDialog = dialogBuilder.create(); mKeyboardShortcutsDialog = dialogBuilder.create();
mKeyboardShortcutsDialog.setCanceledOnTouchOutside(true); mKeyboardShortcutsDialog.setCanceledOnTouchOutside(true);
Window keyboardShortcutsWindow = mKeyboardShortcutsDialog.getWindow(); Window keyboardShortcutsWindow = mKeyboardShortcutsDialog.getWindow();