@Nullable private Icon loadRecipientIcon(Recipient recipient) { Bitmap bitmap = contactPictureLoader.getContactPicture(recipient); if (bitmap == null) { return null; } return Icon.createWithBitmap(bitmap); } }
private static void fixNotificationIcon(Context context, Notification notification, Notification.Builder builder) { if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) { //noinspection deprecation builder.setSmallIcon(notification.icon); //noinspection deprecation builder.setLargeIcon(notification.largeIcon); } else { Icon icon = notification.getSmallIcon(); if (icon != null) { Bitmap bitmap = drawableToBitMap(icon.loadDrawable(context)); if (bitmap != null) { Icon newIcon = Icon.createWithBitmap(bitmap); builder.setSmallIcon(newIcon); } } Icon largeIcon = notification.getLargeIcon(); if (largeIcon != null) { Bitmap bitmap = drawableToBitMap(largeIcon.loadDrawable(context)); if (bitmap != null) { Icon newIcon = Icon.createWithBitmap(bitmap); builder.setLargeIcon(newIcon); } } } }
try { Drawable applicationIcon = pm.getApplicationIcon(hostPackage); Icon icon = Icon.createWithBitmap(((BitmapDrawable) applicationIcon).getBitmap()); mirror.android.content.pm.ShortcutInfo.mIcon.set(shortcutInfo, icon); } catch (Throwable ignored) {
Icon withBitmap = Icon.createWithBitmap(icon); ShortcutInfo likeShortcut = new ShortcutInfo.Builder(context, id) .setShortLabel(name)
@Test public void testGetBitmap() { Bitmap bitmap = Bitmap.createBitmap(100, 100, Bitmap.Config.ARGB_8888); Icon icon = Icon.createWithBitmap(bitmap); assertThat(shadowOf(icon).getType()).isEqualTo(TYPE_BITMAP); assertThat(shadowOf(icon).getBitmap()).isEqualTo(bitmap); }
@Test @Config(minSdk = M) public void withBigPictureStyle() { Bitmap bigPicture = BitmapFactory.decodeResource( ApplicationProvider.getApplicationContext().getResources(), R.drawable.an_image); Icon bigLargeIcon = Icon.createWithBitmap(bigPicture); Notification notification = builder.setStyle(new Notification.BigPictureStyle(builder) .bigPicture(bigPicture) .bigLargeIcon(bigLargeIcon)) .build(); assertThat(shadowOf(notification).getBigPicture()).isEqualTo(bigPicture); } }
/** * Sets the small icon on {@code builder} using a {@code Bitmap} if a non-null bitmap is * provided and the API level is high enough, otherwise the resource id is used. */ @TargetApi(Build.VERSION_CODES.M) // For the Icon class. protected static void setSmallIconOnBuilder( Notification.Builder builder, int iconId, @Nullable Bitmap iconBitmap) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && iconBitmap != null) { builder.setSmallIcon(Icon.createWithBitmap(iconBitmap)); } else { builder.setSmallIcon(iconId); } }
@RequiresApi(api = Build.VERSION_CODES.M) public Icon createLargeIcon(Context context) { return Icon.createWithBitmap(createLargeBitmap(context)); }
void addUnfreezeShortcut(ApplicationInfoWrapper app, List<ApplicationInfoWrapper> linkedApps, Bitmap icon) { String id = "shelter-" + app.getPackageName(); // First, create an Intent to be sent when clicking on the shortcut Intent launchIntent = new Intent(DummyActivity.PUBLIC_UNFREEZE_AND_LAUNCH); launchIntent.setComponent(new ComponentName(getContext(), DummyActivity.class)); launchIntent.putExtra("packageName", app.getPackageName()); if (linkedApps != null) { String appListStr = linkedApps.stream() .map(ApplicationInfoWrapper::getPackageName).collect(Collectors.joining(",")); id += appListStr.hashCode(); // Multiple apps can be added so that // these "linked" apps are all unfrozen // before launching the main app // Note: PersistableBundle doesn't support String array lists inside them launchIntent.putExtra("linkedPackages", appListStr); } launchIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); // Then tell the launcher to add the shortcut Utility.createLauncherShortcut(getContext(), launchIntent, Icon.createWithBitmap(icon), id, app.getLabel()); } }
private Icon getIcon() { Bitmap color = Bitmap.createBitmap(DensityUtil.toDp(context, 148), DensityUtil.toDp(context, 148), Bitmap.Config.RGB_565); color.eraseColor(Color.BLUE); color = ImageUtil.clipToCircle(color); return Icon.createWithBitmap(color); } }
/** * Adds an action to {@code builder} using a {@code Bitmap} if a bitmap is provided and the API * level is high enough, otherwise a resource id is used. */ @SuppressWarnings("deprecation") // For addAction(int, CharSequence, PendingIntent) @TargetApi(Build.VERSION_CODES.M) // For the Icon class. protected static void addActionToBuilder(Notification.Builder builder, Action action) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && action.iconBitmap != null) { Icon icon = Icon.createWithBitmap(action.iconBitmap); builder.addAction( new Notification.Action.Builder(icon, action.title, action.intent).build()); } else { builder.addAction(action.iconId, action.title, action.intent); } }
@RequiresApi(api = Build.VERSION_CODES.N_MR1) private static void updataShortcuts(Context context, List<AppInfo> items) { ShortcutManager shortcutManager = context.getSystemService(ShortcutManager.class); List<ShortcutInfo> shortcutInfoList = new ArrayList<>(); int max = shortcutManager.getMaxShortcutCountPerActivity(); for (int i = 0; i < max && i < items.size(); i++) { AppInfo appInfo = items.get(i); ShortcutInfo.Builder shortcut = new ShortcutInfo.Builder(context, appInfo.packageName); shortcut.setShortLabel(appInfo.appName); shortcut.setLongLabel(appInfo.appName); shortcut.setIcon( Icon.createWithBitmap(drawableToBitmap(LocalImageLoader.getDrawable(context, appInfo)))); Intent intent = new Intent(context, AppPermissionActivity.class); intent.putExtra(AppPermissionActivity.EXTRA_APP_PKGNAME, appInfo.packageName); intent.putExtra(AppPermissionActivity.EXTRA_APP_NAME, appInfo.appName); intent.setAction(Intent.ACTION_DEFAULT); shortcut.setIntent(intent); shortcutInfoList.add(shortcut.build()); } shortcutManager.setDynamicShortcuts(shortcutInfoList); }
@RequiresApi(api = Build.VERSION_CODES.N_MR1) public static void buildShortcuts(Context context) { // TODO: Loop across all activities int tint_color = ContextCompat.getColor(context, R.color.accent); ShortcutManager shortcutManager = context.getSystemService(ShortcutManager.class); Bitmap nhentaiBitmap = Helper.getBitmapFromVectorDrawable(context, R.drawable.ic_menu_nhentai); nhentaiBitmap = Helper.tintBitmap(nhentaiBitmap, tint_color); Icon nhentaiIcon = Icon.createWithBitmap(nhentaiBitmap); Intent nhentaiIntent = new Intent(context, NhentaiActivity.class); nhentaiIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); nhentaiIntent.setAction(Intent.ACTION_VIEW); ShortcutInfo nhentai = new ShortcutInfo.Builder(context, "nhentai") .setShortLabel("nhentai") .setLongLabel("Open nhentai") .setIcon(nhentaiIcon) .setIntent(nhentaiIntent) .build(); shortcutManager.setDynamicShortcuts(Arrays.asList(nhentai)); } }
@Override public void onCreate() { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) { iconOff = iconOn = Icon.createWithResource(this, R.drawable.ic_tile); return; } final SlashDrawable icon = new SlashDrawable(getResources().getDrawable(R.drawable.ic_tile, Application.get().getTheme())); icon.setAnimationEnabled(false); /* Unfortunately we can't have animations, since Icons are marshaled. */ icon.setSlashed(false); Bitmap b = Bitmap.createBitmap(icon.getIntrinsicWidth(), icon.getIntrinsicHeight(), Bitmap.Config.ARGB_8888); Canvas c = new Canvas(b); icon.setBounds(0, 0, c.getWidth(), c.getHeight()); icon.draw(c); iconOn = Icon.createWithBitmap(b); icon.setSlashed(true); b = Bitmap.createBitmap(icon.getIntrinsicWidth(), icon.getIntrinsicHeight(), Bitmap.Config.ARGB_8888); c = new Canvas(b); icon.setBounds(0, 0, c.getWidth(), c.getHeight()); icon.draw(c); iconOff = Icon.createWithBitmap(b); }
private static void fixNotificationIcon(Context context, Notification notification, Notification.Builder builder) { if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) { //noinspection deprecation builder.setSmallIcon(notification.icon); //noinspection deprecation builder.setLargeIcon(notification.largeIcon); } else { Icon icon = notification.getSmallIcon(); if (icon != null) { Bitmap bitmap = drawableToBitMap(icon.loadDrawable(context)); if (bitmap != null) { Icon newIcon = Icon.createWithBitmap(bitmap); builder.setSmallIcon(newIcon); } } Icon largeIcon = notification.getLargeIcon(); if (largeIcon != null) { Bitmap bitmap = drawableToBitMap(largeIcon.loadDrawable(context)); if (bitmap != null) { Icon newIcon = Icon.createWithBitmap(bitmap); builder.setLargeIcon(newIcon); } } } }
private static void fixNotificationIcon(Context context, Notification notification, Notification.Builder builder) { if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) { //noinspection deprecation builder.setSmallIcon(notification.icon); //noinspection deprecation builder.setLargeIcon(notification.largeIcon); } else { Icon icon = notification.getSmallIcon(); if (icon != null) { Bitmap bitmap = drawableToBitMap(icon.loadDrawable(context)); if (bitmap != null) { Icon newIcon = Icon.createWithBitmap(bitmap); builder.setSmallIcon(newIcon); } } Icon largeIcon = notification.getLargeIcon(); if (largeIcon != null) { Bitmap bitmap = drawableToBitMap(largeIcon.loadDrawable(context)); if (bitmap != null) { Icon newIcon = Icon.createWithBitmap(bitmap); builder.setLargeIcon(newIcon); } } } }
/** * Prompts the user to install a shortcut. This is only available on API >= 25. * * @param context the context to use. * @param label the label to use for this shortcut. * @param cover the icon to use for this shortcut. * @param intent intent launched by the shortcut. * * @return true if the shortcut MAY have been created. */ private static boolean installShortcut(Context context, String label, Bitmap cover, Intent intent) { ShortcutManager manager = context.getSystemService(ShortcutManager.class); if (manager == null || !manager.isRequestPinShortcutSupported()) return false; String uniqueId = "vanilla:shortcut:" + System.currentTimeMillis(); ShortcutInfo pin = new ShortcutInfo.Builder(context, uniqueId) .setIntent(intent) .setShortLabel(label) .setIcon(Icon.createWithBitmap(cover)) .build(); manager.requestPinShortcut(pin, null); return true; }
private void addShortcut() { Intent intent = new Intent(this, MainActivity.class); intent.setData(Uri.parse(mWebView.getUrl())); intent.setAction(Intent.ACTION_MAIN); Icon launcherIcon; if (mUrlIcon != null) { launcherIcon = Icon.createWithBitmap( UiUtils.getShortcutIcon(mUrlIcon, getThemeColorWithFallback())); } else { launcherIcon = Icon.createWithResource(this, R.mipmap.ic_launcher); } String title = mWebView.getTitle(); ShortcutInfo shortcutInfo = new ShortcutInfo.Builder(this, title) .setShortLabel(title) .setIcon(launcherIcon) .setIntent(intent) .build(); getSystemService(ShortcutManager.class).requestPinShortcut(shortcutInfo, null); }
mBuilder.setSmallIcon(Icon.createWithBitmap(getSmallIconBitmap(text)));
mBuilder.setSmallIcon(Icon.createWithBitmap(getSmallIconBitmap(text)));