use of android.view.KeyboardShortcutGroup in project platform_frameworks_base by android.
the class KeyboardShortcuts method getDefaultApplicationShortcuts.
private KeyboardShortcutGroup getDefaultApplicationShortcuts() {
final int userId = mContext.getUserId();
List<KeyboardShortcutInfo> keyboardShortcutInfoAppItems = new ArrayList<>();
// Assist.
final AssistUtils assistUtils = new AssistUtils(mContext);
final ComponentName assistComponent = assistUtils.getAssistComponentForUser(userId);
PackageInfo assistPackageInfo = null;
try {
assistPackageInfo = mPackageManager.getPackageInfo(assistComponent.getPackageName(), 0, userId);
} catch (RemoteException e) {
Log.e(TAG, "PackageManagerService is dead");
}
if (assistPackageInfo != null) {
final Icon assistIcon = Icon.createWithResource(assistPackageInfo.applicationInfo.packageName, assistPackageInfo.applicationInfo.icon);
keyboardShortcutInfoAppItems.add(new KeyboardShortcutInfo(mContext.getString(R.string.keyboard_shortcut_group_applications_assist), assistIcon, KeyEvent.KEYCODE_UNKNOWN, KeyEvent.META_META_ON));
}
// Browser.
final Icon browserIcon = getIconForIntentCategory(Intent.CATEGORY_APP_BROWSER, userId);
if (browserIcon != null) {
keyboardShortcutInfoAppItems.add(new KeyboardShortcutInfo(mContext.getString(R.string.keyboard_shortcut_group_applications_browser), browserIcon, KeyEvent.KEYCODE_B, KeyEvent.META_META_ON));
}
// Contacts.
final Icon contactsIcon = getIconForIntentCategory(Intent.CATEGORY_APP_CONTACTS, userId);
if (contactsIcon != null) {
keyboardShortcutInfoAppItems.add(new KeyboardShortcutInfo(mContext.getString(R.string.keyboard_shortcut_group_applications_contacts), contactsIcon, KeyEvent.KEYCODE_C, KeyEvent.META_META_ON));
}
// Email.
final Icon emailIcon = getIconForIntentCategory(Intent.CATEGORY_APP_EMAIL, userId);
if (emailIcon != null) {
keyboardShortcutInfoAppItems.add(new KeyboardShortcutInfo(mContext.getString(R.string.keyboard_shortcut_group_applications_email), emailIcon, KeyEvent.KEYCODE_E, KeyEvent.META_META_ON));
}
// Messaging.
final Icon messagingIcon = getIconForIntentCategory(Intent.CATEGORY_APP_MESSAGING, userId);
if (messagingIcon != null) {
keyboardShortcutInfoAppItems.add(new KeyboardShortcutInfo(mContext.getString(R.string.keyboard_shortcut_group_applications_im), messagingIcon, KeyEvent.KEYCODE_T, KeyEvent.META_META_ON));
}
// Music.
final Icon musicIcon = getIconForIntentCategory(Intent.CATEGORY_APP_MUSIC, userId);
if (musicIcon != null) {
keyboardShortcutInfoAppItems.add(new KeyboardShortcutInfo(mContext.getString(R.string.keyboard_shortcut_group_applications_music), musicIcon, KeyEvent.KEYCODE_P, KeyEvent.META_META_ON));
}
// Calendar.
final Icon calendarIcon = getIconForIntentCategory(Intent.CATEGORY_APP_CALENDAR, userId);
if (calendarIcon != null) {
keyboardShortcutInfoAppItems.add(new KeyboardShortcutInfo(mContext.getString(R.string.keyboard_shortcut_group_applications_calendar), calendarIcon, KeyEvent.KEYCODE_L, KeyEvent.META_META_ON));
}
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);
}
use of android.view.KeyboardShortcutGroup in project android_frameworks_base by DirtyUnicorns.
the class Activity method onProvideKeyboardShortcuts.
@Override
public void onProvideKeyboardShortcuts(List<KeyboardShortcutGroup> data, Menu menu, int deviceId) {
if (menu == null) {
return;
}
KeyboardShortcutGroup group = null;
int menuSize = menu.size();
for (int i = 0; i < menuSize; ++i) {
final MenuItem item = menu.getItem(i);
final CharSequence title = item.getTitle();
final char alphaShortcut = item.getAlphabeticShortcut();
if (title != null && alphaShortcut != MIN_VALUE) {
if (group == null) {
final int resource = mApplication.getApplicationInfo().labelRes;
group = new KeyboardShortcutGroup(resource != 0 ? getString(resource) : null);
}
group.addItem(new KeyboardShortcutInfo(title, alphaShortcut, KeyEvent.META_CTRL_ON));
}
}
if (group != null) {
data.add(group);
}
}
use of android.view.KeyboardShortcutGroup in project android_frameworks_base by AOSPA.
the class Activity method onProvideKeyboardShortcuts.
@Override
public void onProvideKeyboardShortcuts(List<KeyboardShortcutGroup> data, Menu menu, int deviceId) {
if (menu == null) {
return;
}
KeyboardShortcutGroup group = null;
int menuSize = menu.size();
for (int i = 0; i < menuSize; ++i) {
final MenuItem item = menu.getItem(i);
final CharSequence title = item.getTitle();
final char alphaShortcut = item.getAlphabeticShortcut();
if (title != null && alphaShortcut != MIN_VALUE) {
if (group == null) {
final int resource = mApplication.getApplicationInfo().labelRes;
group = new KeyboardShortcutGroup(resource != 0 ? getString(resource) : null);
}
group.addItem(new KeyboardShortcutInfo(title, alphaShortcut, KeyEvent.META_CTRL_ON));
}
}
if (group != null) {
data.add(group);
}
}
use of android.view.KeyboardShortcutGroup in project android_frameworks_base by AOSPA.
the class KeyboardShortcuts method showKeyboardShortcuts.
private void showKeyboardShortcuts(int deviceId) {
retrieveKeyCharacterMap(deviceId);
Recents.getSystemServices().requestKeyboardShortcuts(mContext, new KeyboardShortcutsReceiver() {
@Override
public void onKeyboardShortcutsReceived(final List<KeyboardShortcutGroup> result) {
result.add(getSystemShortcuts());
final KeyboardShortcutGroup appShortcuts = getDefaultApplicationShortcuts();
if (appShortcuts != null) {
result.add(appShortcuts);
}
showKeyboardShortcutsDialog(result);
}
}, deviceId);
}
use of android.view.KeyboardShortcutGroup in project android_frameworks_base by AOSPA.
the class KeyboardShortcuts method getSystemShortcuts.
private KeyboardShortcutGroup getSystemShortcuts() {
final KeyboardShortcutGroup systemGroup = new KeyboardShortcutGroup(mContext.getString(R.string.keyboard_shortcut_group_system), true);
systemGroup.addItem(new KeyboardShortcutInfo(mContext.getString(R.string.keyboard_shortcut_group_system_home), KeyEvent.KEYCODE_ENTER, KeyEvent.META_META_ON));
systemGroup.addItem(new KeyboardShortcutInfo(mContext.getString(R.string.keyboard_shortcut_group_system_back), KeyEvent.KEYCODE_DEL, KeyEvent.META_META_ON));
systemGroup.addItem(new KeyboardShortcutInfo(mContext.getString(R.string.keyboard_shortcut_group_system_recents), KeyEvent.KEYCODE_TAB, KeyEvent.META_ALT_ON));
systemGroup.addItem(new KeyboardShortcutInfo(mContext.getString(R.string.keyboard_shortcut_group_system_notifications), KeyEvent.KEYCODE_N, KeyEvent.META_META_ON));
systemGroup.addItem(new KeyboardShortcutInfo(mContext.getString(R.string.keyboard_shortcut_group_system_shortcuts_helper), KeyEvent.KEYCODE_SLASH, KeyEvent.META_META_ON));
systemGroup.addItem(new KeyboardShortcutInfo(mContext.getString(R.string.keyboard_shortcut_group_system_switch_input), KeyEvent.KEYCODE_SPACE, KeyEvent.META_META_ON));
return systemGroup;
}
Aggregations