android.graphics.drawable.Icon.createWithBitmap()方法的使用及代码示例

x33g5p2x  于2022-01-21 转载在 其他  
字(11.2k)|赞(0)|评价(0)|浏览(281)

本文整理了Java中android.graphics.drawable.Icon.createWithBitmap()方法的一些代码示例,展示了Icon.createWithBitmap()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Icon.createWithBitmap()方法的具体详情如下:
包路径:android.graphics.drawable.Icon
类名称:Icon
方法名:createWithBitmap

Icon.createWithBitmap介绍

暂无

代码示例

代码示例来源:origin: k9mail/k-9

@Nullable
  private Icon loadRecipientIcon(Recipient recipient) {
    Bitmap bitmap = contactPictureLoader.getContactPicture(recipient);
    if (bitmap == null) {
      return null;
    }

    return Icon.createWithBitmap(bitmap);
  }
}

代码示例来源:origin: android-hacker/VirtualXposed

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);
      }
    }
  }
}

代码示例来源:origin: android-hacker/VirtualXposed

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) {

代码示例来源:origin: android-hacker/VirtualXposed

Icon withBitmap = Icon.createWithBitmap(icon);
ShortcutInfo likeShortcut = new ShortcutInfo.Builder(context, id)
    .setShortLabel(name)

代码示例来源:origin: robolectric/robolectric

@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);
}

代码示例来源:origin: robolectric/robolectric

@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);
 }
}

代码示例来源:origin: derry/delion

/**
 * 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);
  }
}

代码示例来源:origin: Abhinav1997/NekoCollector

@RequiresApi(api = Build.VERSION_CODES.M)
public Icon createLargeIcon(Context context) {
  return Icon.createWithBitmap(createLargeBitmap(context));
}

代码示例来源:origin: PeterCxy/Shelter

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());
  }
}

代码示例来源:origin: klinker24/nougat-7.1-playground

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);
  }
}

代码示例来源:origin: derry/delion

/**
 * 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);
  }
}

代码示例来源:origin: 8enet/AppOpsX

@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);
}

代码示例来源:origin: avluis/Hentoid

@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));
  }
}

代码示例来源:origin: WireGuard/wireguard-android

@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);
}

代码示例来源:origin: bzsome/VirtualApp-x326

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);
      }
    }
  }
}

代码示例来源:origin: darkskygit/VirtualApp

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);
      }
    }
  }
}

代码示例来源:origin: vanilla-music/vanilla

/**
 * 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;
}

代码示例来源:origin: LineageOS/android_packages_apps_Jelly

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);
}

代码示例来源:origin: NightscoutFoundation/xDrip

mBuilder.setSmallIcon(Icon.createWithBitmap(getSmallIconBitmap(text)));

代码示例来源:origin: jamorham/xDrip-plus

mBuilder.setSmallIcon(Icon.createWithBitmap(getSmallIconBitmap(text)));

相关文章