androidx.core.graphics.drawable.IconCompat Java Examples
The following examples show how to use
androidx.core.graphics.drawable.IconCompat.
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: ConversationActivity.java From mollyim-android with GNU General Public License v3.0 | 6 votes |
private static void addIconToHomeScreen(@NonNull Context context, @NonNull Bitmap bitmap, @NonNull Recipient recipient) { IconCompat icon = IconCompat.createWithAdaptiveBitmap(bitmap); String name = recipient.isLocalNumber() ? context.getString(R.string.note_to_self) : recipient.getDisplayName(context); ShortcutInfoCompat shortcutInfoCompat = new ShortcutInfoCompat.Builder(context, recipient.getId().serialize() + '-' + System.currentTimeMillis()) .setShortLabel(name) .setIcon(icon) .setIntent(ShortcutLauncherActivity.createIntent(context, recipient.getId())) .build(); if (ShortcutManagerCompat.requestPinShortcut(context, shortcutInfoCompat, null)) { Toast.makeText(context, context.getString(R.string.ConversationActivity_added_to_home_screen), Toast.LENGTH_LONG).show(); } bitmap.recycle(); }
Example #2
Source File: MainActivity.java From c3nav-android with Apache License 2.0 | 6 votes |
@JavascriptInterface public void createShortcut(String url, String title) { Intent shortcutIntent = new Intent(getApplicationContext(), MainActivity.class); shortcutIntent.setAction(Intent.ACTION_MAIN); shortcutIntent.setData(Uri.parse(url)); if (!ShortcutManagerCompat.isRequestPinShortcutSupported(getApplicationContext())) { Toast.makeText(MainActivity.this, R.string.shortcut_not_supported, Toast.LENGTH_LONG).show(); } final ShortcutInfoCompat shortcutInfo = new ShortcutInfoCompat.Builder(getApplicationContext(), url) .setShortLabel(title) .setLongLabel(title) .setIcon(IconCompat.createWithResource(getApplicationContext(), R.mipmap.ic_launcher_36c3)) .setIntent(shortcutIntent) .build(); ShortcutManagerCompat.requestPinShortcut(getApplicationContext(), shortcutInfo, null); if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) { Toast.makeText(MainActivity.this, R.string.shortcut_created, Toast.LENGTH_SHORT).show(); } }
Example #3
Source File: NotificationService.java From Pix-Art-Messenger with GNU General Public License v3.0 | 6 votes |
private Person getPerson(Message message) { final Contact contact = message.getContact(); final Person.Builder builder = new Person.Builder(); if (contact != null) { builder.setName(contact.getDisplayName()); final Uri uri = contact.getSystemAccount(); if (uri != null) { builder.setUri(uri.toString()); } } else { builder.setName(UIHelper.getColoredUsername(mXmppConnectionService, message)); } if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) { builder.setIcon(IconCompat.createWithBitmap(mXmppConnectionService.getAvatarService().get(message, AvatarService.getSystemUiAvatarSize(mXmppConnectionService), false))); } return builder.build(); }
Example #4
Source File: AppShortcutIconGenerator.java From Phonograph with GNU General Public License v3.0 | 6 votes |
private static IconCompat generateThemedIcon(Context context, int iconId, int foregroundColor, int backgroundColor) { // Get and tint foreground and background drawables Drawable vectorDrawable = ImageUtil.getTintedVectorDrawable(context, iconId, foregroundColor); Drawable backgroundDrawable = ImageUtil.getTintedVectorDrawable(context, R.drawable.ic_app_shortcut_background, backgroundColor); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { AdaptiveIconDrawable adaptiveIconDrawable = new AdaptiveIconDrawable(backgroundDrawable, vectorDrawable); return IconCompat.createWithAdaptiveBitmap(ImageUtil.createBitmap(adaptiveIconDrawable)); } else { // Squash the two drawables together LayerDrawable layerDrawable = new LayerDrawable(new Drawable[]{backgroundDrawable, vectorDrawable}); // Return as an Icon return IconCompat.createWithBitmap(ImageUtil.createBitmap(layerDrawable)); } }
Example #5
Source File: PrivateActivity.java From SimplicityBrowser with MIT License | 6 votes |
private AlertDialog createExitDialog() { return new AlertDialog.Builder(PrivateActivity.this) .setPositiveButton(getString(R.string.ok), (dialog, which) -> { Intent intent1 = new Intent(getApplicationContext(), MainActivity.class); intent1.setAction(Intent.ACTION_MAIN); intent1.setData(Uri.parse(mSearchView.getText().toString())); ShortcutInfoCompat pinShortcutInfo = new ShortcutInfoCompat.Builder(PrivateActivity.this, shortcutNameEditText.getText().toString()) .setShortLabel(shortcutNameEditText.getText().toString()) .setIcon(IconCompat.createWithBitmap(StaticUtils.createScaledBitmap(StaticUtils.getCroppedBitmap(favoriteIcon), 300, 300))) .setIntent(intent1) .build(); ShortcutManagerCompat.requestPinShortcut(PrivateActivity.this, pinShortcutInfo, null); }) .setNegativeButton(getString(R.string.cancel), (dialog, which) -> { // nothing to do here }) .setCancelable(true) .create(); }
Example #6
Source File: AppShortcutIconGenerator.java From VinylMusicPlayer with GNU General Public License v3.0 | 6 votes |
private static IconCompat generateThemedIcon(Context context, int iconId, int foregroundColor, int backgroundColor) { // Get and tint foreground and background drawables Drawable vectorDrawable = ImageUtil.getTintedVectorDrawable(context, iconId, foregroundColor); Drawable backgroundDrawable = ImageUtil.getTintedVectorDrawable(context, R.drawable.ic_app_shortcut_background, backgroundColor); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { AdaptiveIconDrawable adaptiveIconDrawable = new AdaptiveIconDrawable(backgroundDrawable, vectorDrawable); return IconCompat.createWithAdaptiveBitmap(ImageUtil.createBitmap(adaptiveIconDrawable)); } else { // Squash the two drawables together LayerDrawable layerDrawable = new LayerDrawable(new Drawable[]{backgroundDrawable, vectorDrawable}); // Return as an Icon return IconCompat.createWithBitmap(ImageUtil.createBitmap(layerDrawable)); } }
Example #7
Source File: PhonkScriptHelper.java From PHONK with GNU General Public License v3.0 | 6 votes |
public static void addShortcut(Context c, String folder, String name) { Project p = new Project(folder, name); Intent.ShortcutIconResource icon; icon = Intent.ShortcutIconResource.fromContext(c, R.drawable.app_icon); if (ShortcutManagerCompat.isRequestPinShortcutSupported(c)) { Intent shortcutIntent = new Intent(c, AppRunnerActivity.class); shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); shortcutIntent.putExtra(Project.NAME, p.getName()); shortcutIntent.putExtra(Project.FOLDER, p.getFolder()); shortcutIntent.setAction(Intent.ACTION_MAIN); ShortcutInfoCompat shortcutInfo = new ShortcutInfoCompat.Builder(c, folder + "/" + name) .setIntent(shortcutIntent) // !!! intent's action must be set on oreo .setShortLabel(name) .setIcon(IconCompat.createWithResource(c, R.drawable.app_icon)) .build(); ShortcutManagerCompat.requestPinShortcut(c, shortcutInfo, null); } }
Example #8
Source File: GettingStartedSliceProvider.java From snippets with Apache License 2.0 | 6 votes |
public SliceAction createActivityAction() { if (getContext() == null) { return null; } return SliceAction.create( PendingIntent.getActivity( getContext(), 0, new Intent(getContext(), MainActivity.class), 0 ), IconCompat.createWithResource(getContext(), R.drawable.ic_home), ListBuilder.ICON_IMAGE, "Enter app" ); }
Example #9
Source File: MySliceProvider.java From snippets with Apache License 2.0 | 6 votes |
public Slice seeMoreRowSlice(Uri sliceUri) { if (getContext() == null) { return null; } ListBuilder listBuilder = new ListBuilder(getContext(), sliceUri, ListBuilder.INFINITY) // [START_EXCLUDE] .addRow(new RowBuilder() .setTitle("Hello") .setPrimaryAction(createActivityAction()) ) // [END_EXCLUDE] .setSeeMoreRow(new RowBuilder() .setTitle("See all available networks") .addEndItem(IconCompat .createWithResource(getContext(), R.drawable .ic_right_caret), ListBuilder.ICON_IMAGE) .setPrimaryAction(SliceAction.create(seeAllNetworksPendingIntent, IconCompat.createWithResource(getContext(), R.drawable.ic_wifi), ListBuilder.ICON_IMAGE, "Wi-Fi Networks")) ); // [START_EXCLUDE] // [END_EXCLUDE] return listBuilder.build(); }
Example #10
Source File: MySliceProvider.java From snippets with Apache License 2.0 | 6 votes |
public Slice createSliceShowingLoading(Uri sliceUri) { if (getContext() == null) { return null; } // Construct the parent. ListBuilder listBuilder = new ListBuilder(getContext(), sliceUri, ListBuilder.INFINITY) // Construct the row. .addRow(new RowBuilder() .setPrimaryAction(createActivityAction()) .setTitle("Ride to work") // We’re waiting to load the time to work so indicate that on the slice by // setting the subtitle with the overloaded method and indicate true. .setSubtitle(null, true) .addEndItem(IconCompat.createWithResource(getContext(), R.drawable.ic_work), ListBuilder.ICON_IMAGE) ); return listBuilder.build(); }
Example #11
Source File: MySliceProvider.java From snippets with Apache License 2.0 | 6 votes |
public Slice createSliceWithHeader(Uri sliceUri) { if (getContext() == null) { return null; } // Construct the parent. ListBuilder listBuilder = new ListBuilder(getContext(), sliceUri, ListBuilder.INFINITY) .setAccentColor(0xff0F9D58) // Specify color for tinting icons. .setHeader( // Create the header and add to slice. new HeaderBuilder() .setTitle("Get a ride") .setSubtitle("Ride in 4 min.") .setSummary("Work in 1 hour 45 min | Home in 12 min.") ).addRow(new RowBuilder() // Add a row. .setPrimaryAction( createActivityAction()) // A slice always needs a SliceAction. .setTitle("Home") .setSubtitle("12 miles | 12 min | $9.00") .addEndItem(IconCompat.createWithResource(getContext(), R.drawable.ic_home), SliceHints.ICON_IMAGE) ); // Add more rows if needed... return listBuilder.build(); }
Example #12
Source File: AppShortcutIconGenerator.java From Music-Player with GNU General Public License v3.0 | 6 votes |
private static IconCompat generateThemedIcon(Context context, int iconId, int foregroundColor, int backgroundColor) { // Get and tint foreground and background drawables Drawable vectorDrawable = ImageUtil.getTintedVectorDrawable(context, iconId, foregroundColor); Drawable backgroundDrawable = ImageUtil.getTintedVectorDrawable(context, R.drawable.ic_app_shortcut_background, backgroundColor); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { AdaptiveIconDrawable adaptiveIconDrawable = new AdaptiveIconDrawable(backgroundDrawable, vectorDrawable); return IconCompat.createWithAdaptiveBitmap(ImageUtil.createBitmap(adaptiveIconDrawable)); } else { // Squash the two drawables together LayerDrawable layerDrawable = new LayerDrawable(new Drawable[]{backgroundDrawable, vectorDrawable}); // Return as an Icon return IconCompat.createWithBitmap(ImageUtil.createBitmap(layerDrawable)); } }
Example #13
Source File: PixivArtProvider.java From PixivforMuzei3 with GNU General Public License v3.0 | 6 votes |
@Nullable private RemoteActionCompat deleteArtwork(Artwork artwork) { if (!running) { return null; } final Context context = checkContext(); Intent deleteArtworkIntent = new Intent(context, DeleteArtworkReceiver.class); deleteArtworkIntent.putExtra("artworkId", artwork.getToken()); PendingIntent pendingIntent = PendingIntent.getBroadcast(context, 0, deleteArtworkIntent, PendingIntent.FLAG_UPDATE_CURRENT); String title = "Delete current artwork"; RemoteActionCompat remoteActionCompat = new RemoteActionCompat( IconCompat.createWithResource(context, R.drawable.ic_delete_white_24dp), title, title, pendingIntent ); remoteActionCompat.setShouldShowIcon(false); return remoteActionCompat; }
Example #14
Source File: PixivArtProvider.java From PixivforMuzei3 with GNU General Public License v3.0 | 6 votes |
@Nullable private RemoteActionCompat addToBookmarks(Artwork artwork) { if (!running) { return null; } Log.v("BOOKMARK", "adding to bookmarks"); final Context context = checkContext(); Intent addToBookmarkIntent = new Intent(context, AddToBookmarkService.class); addToBookmarkIntent.putExtra("artworkId", artwork.getToken()); PendingIntent pendingIntent = PendingIntent.getService(context, 0, addToBookmarkIntent, PendingIntent.FLAG_UPDATE_CURRENT); String label = context.getString(R.string.command_addToBookmark); RemoteActionCompat remoteActionCompat = new RemoteActionCompat( IconCompat.createWithResource(context, R.drawable.muzei_launch_command), label, label, pendingIntent); remoteActionCompat.setShouldShowIcon(false); return remoteActionCompat; }
Example #15
Source File: PixivArtProvider.java From PixivforMuzei3 with GNU General Public License v3.0 | 6 votes |
@Nullable private RemoteActionCompat viewArtworkDetailsAlternate(Artwork artwork) { if (!running) { return null; } String token = artwork.getToken(); Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.pixiv.net/member_illust.php?mode=medium&illust_id=" + token)); intent.setFlags(FLAG_ACTIVITY_NEW_TASK); final Context context = checkContext(); String title = context.getString(R.string.command_viewArtworkDetails); RemoteActionCompat remoteActionCompat = new RemoteActionCompat( IconCompat.createWithResource(context, R.drawable.muzei_launch_command), title, title, PendingIntent.getActivity(context, (int) artwork.getId(), intent, PendingIntent.FLAG_UPDATE_CURRENT)); remoteActionCompat.setShouldShowIcon(false); return remoteActionCompat; }
Example #16
Source File: AppShortcutIconGenerator.java From VinylMusicPlayer with GNU General Public License v3.0 | 5 votes |
private static IconCompat generateDefaultThemedIcon(Context context, int iconId) { // Return an Icon of iconId with default colors return generateThemedIcon(context, iconId, context.getColor(R.color.app_shortcut_default_foreground), context.getColor(R.color.app_shortcut_default_background) ); }
Example #17
Source File: SingleRecipientNotificationBuilder.java From mollyim-android with GNU General Public License v3.0 | 5 votes |
public void addMessageBody(@NonNull Recipient threadRecipient, @NonNull Recipient individualRecipient, @Nullable CharSequence messageBody, long timestamp) { SpannableStringBuilder stringBuilder = new SpannableStringBuilder(); Person.Builder personBuilder = new Person.Builder() .setKey(individualRecipient.getId().serialize()) .setBot(false); this.threadRecipient = threadRecipient; if (privacy.isDisplayContact()) { personBuilder.setName(individualRecipient.getDisplayName(context)); Bitmap bitmap = getLargeBitmap(getContactDrawable(individualRecipient)); if (bitmap != null) { personBuilder.setIcon(IconCompat.createWithBitmap(bitmap)); } } else { personBuilder.setName(""); } final CharSequence text; if (privacy.isDisplayMessage()) { text = messageBody == null ? "" : messageBody; } else { text = stringBuilder.append(context.getString(R.string.SingleRecipientNotificationBuilder_new_message)); } messages.add(new NotificationCompat.MessagingStyle.Message(text, timestamp, personBuilder.build())); }
Example #18
Source File: AvatarUtil.java From mollyim-android with GNU General Public License v3.0 | 5 votes |
@WorkerThread public static IconCompat getIconForNotification(@NonNull Context context, @NonNull Recipient recipient) { try { return IconCompat.createWithBitmap(request(GlideApp.with(context).asBitmap(), context, recipient).submit().get()); } catch (ExecutionException | InterruptedException e) { return null; } }
Example #19
Source File: AppShortcutIconGenerator.java From Phonograph with GNU General Public License v3.0 | 5 votes |
private static IconCompat generateUserThemedIcon(Context context, int iconId) { // Get background color from context's theme final TypedValue typedColorBackground = new TypedValue(); context.getTheme().resolveAttribute(android.R.attr.colorBackground, typedColorBackground, true); // Return an Icon of iconId with those colors return generateThemedIcon(context, iconId, ThemeStore.primaryColor(context), typedColorBackground.data ); }
Example #20
Source File: AppShortcutIconGenerator.java From Phonograph with GNU General Public License v3.0 | 5 votes |
private static IconCompat generateDefaultThemedIcon(Context context, int iconId) { // Return an Icon of iconId with default colors return generateThemedIcon(context, iconId, context.getColor(R.color.app_shortcut_default_foreground), context.getColor(R.color.app_shortcut_default_background) ); }
Example #21
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 #22
Source File: MainActivity.java From journaldev with MIT License | 5 votes |
private void notificationWithIcon() { Person anupam = new Person.Builder() .setName("Anupam") .setIcon(IconCompat.createWithResource(this, R.drawable.sample_photo)) .setImportant(true) .build(); new NotificationCompat.MessagingStyle(anupam) .addMessage("Check out my latest article!", new Date().getTime(), anupam) .setBuilder(builder); notificationManager.notify(2, builder.build()); }
Example #23
Source File: SharingShortcutsManager.java From android-SharingShortcuts with Apache License 2.0 | 5 votes |
/** * Publish the list of dynamics shortcuts that will be used in Direct Share. * <p> * For each shortcut, we specify the categories that it will be associated to, * the intent that will trigger when opened as a static launcher shortcut, * and the Shortcut ID between other things. * <p> * The Shortcut ID that we specify in the {@link ShortcutInfoCompat.Builder} constructor will * be received in the intent as {@link Intent#EXTRA_SHORTCUT_ID}. * <p> * In this code sample, this method is completely static. We are always setting the same sharing * shortcuts. In a real-world example, we would replace existing shortcuts depending on * how the user interacts with the app as often as we want to. */ public void pushDirectShareTargets(@NonNull Context context) { ArrayList<ShortcutInfoCompat> shortcuts = new ArrayList<>(); // Category that our sharing shortcuts will be assigned to Set<String> contactCategories = new HashSet<>(); contactCategories.add(CATEGORY_TEXT_SHARE_TARGET); // Adding maximum number of shortcuts to the list for (int id = 0; id < MAX_SHORTCUTS; ++id) { Contact contact = Contact.byId(id); // Item that will be sent if the shortcut is opened as a static launcher shortcut Intent staticLauncherShortcutIntent = new Intent(Intent.ACTION_DEFAULT); // Creates a new Sharing Shortcut and adds it to the list // The id passed in the constructor will become EXTRA_SHORTCUT_ID in the received Intent shortcuts.add(new ShortcutInfoCompat.Builder(context, Integer.toString(id)) .setShortLabel(contact.getName()) // Icon that will be displayed in the share target .setIcon(IconCompat.createWithResource(context, contact.getIcon())) .setIntent(staticLauncherShortcutIntent) // Make this sharing shortcut cached by the system // Even if it is unpublished, it can still appear on the sharesheet .setLongLived() .setCategories(contactCategories) // Person objects are used to give better suggestions .setPerson(new Person.Builder() .setName(contact.getName()) .build()) .build()); } ShortcutManagerCompat.addDynamicShortcuts(context, shortcuts); }
Example #24
Source File: HomeScreen.java From focus-android with Mozilla Public License 2.0 | 5 votes |
/** * Create a shortcut via the AppCompat's shortcut manager. * <p> * On Android versions up to 7 shortcut will be created via system broadcast internally. * <p> * On Android 8+ the user will have the ability to add the shortcut manually * or let the system place it automatically. */ private static void installShortCutViaManager(Context context, Bitmap bitmap, String url, String title, boolean blockingEnabled, boolean requestDesktop) { if (ShortcutManagerCompat.isRequestPinShortcutSupported(context)) { final IconCompat icon = (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) ? IconCompat.createWithAdaptiveBitmap(bitmap) : IconCompat.createWithBitmap(bitmap); final ShortcutInfoCompat shortcut = new ShortcutInfoCompat.Builder(context, UUID.randomUUID().toString()) .setShortLabel(title) .setLongLabel(title) .setIcon(icon) .setIntent(createShortcutIntent(context, url, blockingEnabled, requestDesktop)) .build(); ShortcutManagerCompat.requestPinShortcut(context, shortcut, null); } }
Example #25
Source File: AppShortcutIconGenerator.java From VinylMusicPlayer with GNU General Public License v3.0 | 5 votes |
private static IconCompat generateUserThemedIcon(Context context, int iconId) { // Get background color from context's theme final TypedValue typedColorBackground = new TypedValue(); context.getTheme().resolveAttribute(android.R.attr.colorBackground, typedColorBackground, true); // Return an Icon of iconId with those colors return generateThemedIcon(context, iconId, ThemeStore.primaryColor(context), typedColorBackground.data ); }
Example #26
Source File: PixivArtProvider.java From PixivforMuzei3 with GNU General Public License v3.0 | 5 votes |
@Nullable private RemoteActionCompat shareImage(Artwork artwork) { if (!running) { return null; } final Context context = checkContext(); File newFile = new File(context.getExternalFilesDir(Environment.DIRECTORY_PICTURES), artwork.getToken() + ".png"); Uri uri = FileProvider.getUriForFile(context, BuildConfig.APPLICATION_ID + ".fileprovider", newFile); Intent sharingIntent = new Intent() .setAction(Intent.ACTION_SEND) .setType("image/*") .putExtra(Intent.EXTRA_STREAM, uri); String title = context.getString(R.string.command_shareImage); return new RemoteActionCompat( IconCompat.createWithResource(context, R.drawable.ic_baseline_share_24), title, title, PendingIntent.getActivity( context, (int) artwork.getId(), IntentUtils.chooseIntent(sharingIntent, SHARE_IMAGE_INTENT_CHOOSER_TITLE, context), PendingIntent.FLAG_UPDATE_CURRENT ) ); }
Example #27
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 #28
Source File: NotificationBuilderImplP.java From FCM-for-Mojo with GNU General Public License v3.0 | 5 votes |
@Override public NotificationCompat.Style createStyle(Context context, Chat chat) { MessagingStyle style = new MessagingStyle(new Person.Builder() .setName(context.getString(R.string.you)) .setIcon(IconCompat.createWithBitmap(UserIcon.requestIcon(context, User.getSelf().getUid(), Chat.ChatType.FRIEND))) .build()); style.setConversationTitle(chat.getName()); style.setGroupConversation(chat.isGroup()); for (int i = chat.getMessages().size() - NOTIFICATION_MAX_MESSAGES, count = 0; i < chat.getMessages().size() && count <= 8; i++, count++) { if (i < 0) { continue; } Message message = chat.getMessages().get(i); User sender = message.getSenderUser(); IconCompat icon = null; Bitmap bitmap = UserIcon.getIcon(context, sender.getUid(), Chat.ChatType.FRIEND); if (bitmap != null) { icon = IconCompat.createWithBitmap(bitmap); } Person person = null; if (message.getSenderUser() != User.getSelf()) { person = new Person.Builder() .setKey(sender.getName()) .setName(sender.getName()) .setIcon(icon) .build(); } style.addMessage(message.getContent(context), message.getTimestamp(), person); } style.setSummaryText(context.getString(R.string.notification_messages, chat.getMessages().getSize())); return style; }
Example #29
Source File: MySliceProvider.java From snippets with Apache License 2.0 | 5 votes |
private SliceAction createActivityAction() { return SliceAction.create( PendingIntent.getActivity( getContext(), 0, new Intent(getContext(), MainActivity.class), 0 ), IconCompat.createWithResource(getContext(), R.drawable.ic_home), ListBuilder.ICON_IMAGE, "Enter app" ); }
Example #30
Source File: MySliceProvider.java From snippets with Apache License 2.0 | 5 votes |
public Slice createActionWithActionInRow(Uri sliceUri) { if (getContext() == null) { return null; } // Primary action - open wifi settings. SliceAction primaryAction = SliceAction.create(wifiSettingsPendingIntent, IconCompat.createWithResource(getContext(), R.drawable.ic_wifi), ListBuilder.ICON_IMAGE, "Wi-Fi Settings" ); // Toggle action - toggle wifi. SliceAction toggleAction = SliceAction.createToggle(wifiTogglePendingIntent, "Toggle Wi-Fi", isConnected /* isChecked */); // Create the parent builder. ListBuilder listBuilder = new ListBuilder(getContext(), wifiUri, ListBuilder.INFINITY) // Specify color for tinting icons / controls. .setAccentColor(0xff4285f4) // Create and add a row. .addRow(new RowBuilder() .setTitle("Wi-Fi") .setPrimaryAction(primaryAction) .addEndItem(toggleAction)); // Build the slice. return listBuilder.build(); }