Java Code Examples for androidx.core.content.pm.ShortcutInfoCompat#Builder
The following examples show how to use
androidx.core.content.pm.ShortcutInfoCompat#Builder .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Shortcuts.java From FairEmail with GNU General Public License v3.0 | 5 votes |
@NotNull static ShortcutInfoCompat.Builder getShortcut(Context context, InternetAddress address) { String name = address.getPersonal(); String email = address.getAddress(); Uri lookupUri = null; boolean contacts = Helper.hasPermission(context, Manifest.permission.READ_CONTACTS); if (contacts) { ContentResolver resolver = context.getContentResolver(); try (Cursor cursor = resolver.query(ContactsContract.CommonDataKinds.Email.CONTENT_URI, new String[]{ ContactsContract.CommonDataKinds.Photo.CONTACT_ID, ContactsContract.Contacts.LOOKUP_KEY, ContactsContract.Contacts.DISPLAY_NAME }, ContactsContract.CommonDataKinds.Email.ADDRESS + " = ?", new String[]{email}, null)) { if (cursor != null && cursor.moveToNext()) { int colContactId = cursor.getColumnIndex(ContactsContract.CommonDataKinds.Photo.CONTACT_ID); int colLookupKey = cursor.getColumnIndex(ContactsContract.Contacts.LOOKUP_KEY); int colDisplayName = cursor.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME); long contactId = cursor.getLong(colContactId); String lookupKey = cursor.getString(colLookupKey); String displayName = cursor.getString(colDisplayName); lookupUri = ContactsContract.Contacts.getLookupUri(contactId, lookupKey); if (!TextUtils.isEmpty(displayName)) name = displayName; } } } return getShortcut(context, email, name, lookupUri); }
Example 2
Source File: AppsListFragment.java From J2ME-Loader with Apache License 2.0 | 5 votes |
@Override public boolean onContextItemSelected(MenuItem item) { AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) item.getMenuInfo(); int index = info.position; AppItem appItem = adapter.getItem(index); switch (item.getItemId()) { case R.id.action_context_shortcut: Bitmap bitmap = BitmapFactory.decodeFile(appItem.getImagePathExt()); Intent launchIntent = new Intent(Intent.ACTION_DEFAULT, Uri.parse(appItem.getPath()), getActivity(), ConfigActivity.class); ShortcutInfoCompat.Builder shortcutInfoCompatBuilder = new ShortcutInfoCompat.Builder(getActivity(), appItem.getTitle()) .setIntent(launchIntent) .setShortLabel(appItem.getTitle()); if (bitmap != null) { shortcutInfoCompatBuilder.setIcon(IconCompat.createWithBitmap(bitmap)); } else { shortcutInfoCompatBuilder.setIcon(IconCompat.createWithResource(getActivity(), R.mipmap.ic_launcher)); } ShortcutManagerCompat.requestPinShortcut(getActivity(), shortcutInfoCompatBuilder.build(), null); break; case R.id.action_context_rename: showRenameDialog(index); break; case R.id.action_context_settings: Config.startApp(getActivity(), appItem.getPath(), true); break; case R.id.action_context_delete: showDeleteDialog(index); break; } return super.onContextItemSelected(item); }
Example 3
Source File: DemoSettingFragment.java From DeviceConnect-Android with MIT License | 5 votes |
private void createShortcut() { Activity activity = getActivity(); if (activity == null) { return; } Context context = activity.getApplicationContext(); Intent shortcut = createDemoPageIntent(); ShortcutInfoCompat.Builder builder = new ShortcutInfoCompat.Builder(context, CAMERA_DEMO_SHORTCUT_ID) .setIcon(IconCompat.createWithResource(context, getShortcutIconResource(mDemoInstaller))) .setShortLabel(getShortcutShortLabel(mDemoInstaller)) .setLongLabel(getShortcutLongLabel(mDemoInstaller)) .setIntent(shortcut); ComponentName mainActivity = getMainActivity(context); if (mainActivity != null) { builder.setActivity(mainActivity); } ShortcutInfoCompat info = builder.build(); boolean result = ShortcutManagerCompat.requestPinShortcut(context, info, null); if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) { // OS 8以下の場合はOSが結果を表示しないので、自前で出す if (result) { showShurtcutResult(getString(R.string.demo_page_settings_button_create_shortcut_success)); } else { showShurtcutResult(getString(R.string.demo_page_settings_button_create_shortcut_error)); } } }
Example 4
Source File: Shortcuts.java From FairEmail with GNU General Public License v3.0 | 4 votes |
@NotNull static ShortcutInfoCompat.Builder getShortcut(Context context, EntityContact contact) { return getShortcut(context, contact.email, contact.name, contact.avatar); }
Example 5
Source File: Shortcuts.java From FairEmail with GNU General Public License v3.0 | 4 votes |
@NotNull private static ShortcutInfoCompat.Builder getShortcut(Context context, String email, String name, String avatar) { return getShortcut(context, email, name, avatar == null ? null : Uri.parse(avatar)); }
Example 6
Source File: Shortcuts.java From FairEmail with GNU General Public License v3.0 | 4 votes |
@NotNull private static ShortcutInfoCompat.Builder getShortcut(Context context, String email, String name, Uri avatar) { SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); boolean identicons = prefs.getBoolean("identicons", false); boolean circular = prefs.getBoolean("circular", true); Intent intent = new Intent(context, ActivityMain.class); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK); intent.setAction(Intent.ACTION_SEND); intent.addCategory(Intent.CATEGORY_DEFAULT); intent.setData(Uri.parse("mailto:" + email)); Bitmap bitmap = null; if (avatar != null && Helper.hasPermission(context, Manifest.permission.READ_CONTACTS)) { // Create icon from bitmap because launcher might not have contacts permission InputStream is = ContactsContract.Contacts.openContactPhotoInputStream( context.getContentResolver(), avatar); bitmap = BitmapFactory.decodeStream(is); } boolean identicon = false; if (bitmap == null) { int dp = Helper.dp2pixels(context, 96); if (identicons) { identicon = true; bitmap = ImageHelper.generateIdenticon(email, dp, 5, context); } else bitmap = ImageHelper.generateLetterIcon(email, name, dp, context); } bitmap = ImageHelper.makeCircular(bitmap, circular && !identicon ? null : Helper.dp2pixels(context, 3)); IconCompat icon = IconCompat.createWithBitmap(bitmap); String id = (name == null ? email : "\"" + name + "\" <" + email + ">"); Set<String> categories = new HashSet<>(Arrays.asList("eu.faircode.email.TEXT_SHARE_TARGET")); ShortcutInfoCompat.Builder builder = new ShortcutInfoCompat.Builder(context, id) .setIcon(icon) .setShortLabel(name == null ? email : name) .setLongLabel(name == null ? email : name) .setCategories(categories) .setIntent(intent); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) { Person.Builder person = new Person.Builder() .setIcon(icon) .setName(name == null ? email : name) .setImportant(true); if (avatar != null) person.setUri(avatar.toString()); builder.setPerson(person.build()); } return builder; }