Java Code Examples for androidx.core.graphics.drawable.IconCompat#createWithAdaptiveBitmap()

The following examples show how to use androidx.core.graphics.drawable.IconCompat#createWithAdaptiveBitmap() . 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 vote down vote up
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: AppShortcutIconGenerator.java    From Music-Player with GNU General Public License v3.0 6 votes vote down vote up
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 3
Source File: AppShortcutIconGenerator.java    From VinylMusicPlayer with GNU General Public License v3.0 6 votes vote down vote up
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 4
Source File: AppShortcutIconGenerator.java    From Phonograph with GNU General Public License v3.0 6 votes vote down vote up
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: HomeScreen.java    From focus-android with Mozilla Public License 2.0 5 votes vote down vote up
/**
 * 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);
    }
}