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

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

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

Icon.loadDrawable介绍

暂无

代码示例

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

  1. private static void fixNotificationIcon(Context context, Notification notification, Notification.Builder builder) {
  2. if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) {
  3. //noinspection deprecation
  4. builder.setSmallIcon(notification.icon);
  5. //noinspection deprecation
  6. builder.setLargeIcon(notification.largeIcon);
  7. } else {
  8. Icon icon = notification.getSmallIcon();
  9. if (icon != null) {
  10. Bitmap bitmap = drawableToBitMap(icon.loadDrawable(context));
  11. if (bitmap != null) {
  12. Icon newIcon = Icon.createWithBitmap(bitmap);
  13. builder.setSmallIcon(newIcon);
  14. }
  15. }
  16. Icon largeIcon = notification.getLargeIcon();
  17. if (largeIcon != null) {
  18. Bitmap bitmap = drawableToBitMap(largeIcon.loadDrawable(context));
  19. if (bitmap != null) {
  20. Icon newIcon = Icon.createWithBitmap(bitmap);
  21. builder.setLargeIcon(newIcon);
  22. }
  23. }
  24. }
  25. }

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

  1. @TargetApi(Build.VERSION_CODES.M)
  2. void fixIcon(Icon icon, Context appContext, boolean installed) {
  3. if (icon == null) {
  4. return;
  5. }
  6. int type = mirror.android.graphics.drawable.Icon.mType.get(icon);
  7. if (type == mirror.android.graphics.drawable.Icon.TYPE_RESOURCE) {
  8. if (installed) {
  9. mirror.android.graphics.drawable.Icon.mObj1.set(icon, appContext.getResources());
  10. mirror.android.graphics.drawable.Icon.mString1.set(icon, appContext.getPackageName());
  11. } else {
  12. Drawable drawable = icon.loadDrawable(appContext);
  13. Bitmap bitmap = drawableToBitMap(drawable);
  14. mirror.android.graphics.drawable.Icon.mObj1.set(icon, bitmap);
  15. mirror.android.graphics.drawable.Icon.mString1.set(icon, null);
  16. mirror.android.graphics.drawable.Icon.mType.set(icon, mirror.android.graphics.drawable.Icon.TYPE_BITMAP);
  17. }
  18. }
  19. }

代码示例来源:origin: fennifith/Status

  1. @Nullable
  2. public Drawable getLargeIcon(Context context) {
  3. Drawable drawable = null;
  4. if (largeIcon != null) drawable = new BitmapDrawable(context.getResources(), largeIcon);
  5. if (drawable == null && unloadedLargeIcon != null && Build.VERSION.SDK_INT >= Build.VERSION_CODES.M)
  6. drawable = unloadedLargeIcon.loadDrawable(context);
  7. return drawable;
  8. }

代码示例来源:origin: geniusgithub/AndroidDialer

  1. @Nullable
  2. private static Drawable createIconDrawableMarshmallow(PhoneAccount phoneAccount,
  3. Context context) {
  4. Icon accountIcon = getIcon(phoneAccount);
  5. if (accountIcon == null) {
  6. return null;
  7. }
  8. return accountIcon.loadDrawable(context);
  9. }

代码示例来源:origin: KDE/kdeconnect-android

  1. @RequiresApi(Build.VERSION_CODES.M)
  2. private Bitmap iconToBitmap(Context foreignContext, Icon icon) {
  3. if (icon == null) return null;
  4. return drawableToBitmap(icon.loadDrawable(foreignContext));
  5. }

代码示例来源:origin: fennifith/Status

  1. @Nullable
  2. public Bitmap getIcon(Context context) {
  3. if (icon == null) {
  4. Drawable drawable = null;
  5. if (iconRes != 0) drawable = getDrawable(context, iconRes, packageName);
  6. if (drawable == null && unloadedIcon != null && Build.VERSION.SDK_INT >= Build.VERSION_CODES.M)
  7. drawable = unloadedIcon.loadDrawable(context);
  8. if (drawable != null) {
  9. Bitmap bitmap = ImageUtils.drawableToBitmap(drawable);
  10. if (bitmap != null) {
  11. icon = bitmap;
  12. scaledIcon = null;
  13. }
  14. }
  15. }
  16. return icon;
  17. }

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

  1. public static void createLauncherShortcut(Context context, Intent launchIntent, Icon icon, String id, String label) {
  2. if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
  3. ShortcutManager shortcutManager = context.getSystemService(ShortcutManager.class);
  4. if (shortcutManager.isRequestPinShortcutSupported()) {
  5. ShortcutInfo info = new ShortcutInfo.Builder(context, id)
  6. .setIntent(launchIntent)
  7. .setIcon(icon)
  8. .setShortLabel(label)
  9. .setLongLabel(label)
  10. .build();
  11. Intent addIntent = shortcutManager.createShortcutResultIntent(info);
  12. shortcutManager.requestPinShortcut(info,
  13. PendingIntent.getBroadcast(context, 0, addIntent, 0).getIntentSender());
  14. } else {
  15. // TODO: Maybe implement this for launchers without pin shortcut support?
  16. // TODO: Should be the same with the fallback for Android < O
  17. // for now just show unsupported
  18. Toast.makeText(context, context.getString(R.string.unsupported_launcher), Toast.LENGTH_LONG).show();
  19. }
  20. } else {
  21. Intent shortcutIntent = new Intent("com.android.launcher.action.INSTALL_SHORTCUT");
  22. shortcutIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, launchIntent);
  23. shortcutIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, label);
  24. shortcutIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON, drawableToBitmap(icon.loadDrawable(context)));
  25. context.sendBroadcast(shortcutIntent);
  26. Toast.makeText(context, R.string.shortcut_create_success, Toast.LENGTH_SHORT).show();
  27. }
  28. }

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

  1. Drawable catIcon;
  2. if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
  3. catIcon = cat.createLargeIcon(this).loadDrawable(this);
  4. } else {
  5. catIcon = new BitmapDrawable(getResources(), cat.createLargeBitmap(this));

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

  1. private static void fixNotificationIcon(Context context, Notification notification, Notification.Builder builder) {
  2. if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) {
  3. //noinspection deprecation
  4. builder.setSmallIcon(notification.icon);
  5. //noinspection deprecation
  6. builder.setLargeIcon(notification.largeIcon);
  7. } else {
  8. Icon icon = notification.getSmallIcon();
  9. if (icon != null) {
  10. Bitmap bitmap = drawableToBitMap(icon.loadDrawable(context));
  11. if (bitmap != null) {
  12. Icon newIcon = Icon.createWithBitmap(bitmap);
  13. builder.setSmallIcon(newIcon);
  14. }
  15. }
  16. Icon largeIcon = notification.getLargeIcon();
  17. if (largeIcon != null) {
  18. Bitmap bitmap = drawableToBitMap(largeIcon.loadDrawable(context));
  19. if (bitmap != null) {
  20. Icon newIcon = Icon.createWithBitmap(bitmap);
  21. builder.setLargeIcon(newIcon);
  22. }
  23. }
  24. }
  25. }

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

  1. @TargetApi(Build.VERSION_CODES.M)
  2. void fixIcon(Icon icon, Context appContext, boolean installed) {
  3. if (icon == null) {
  4. return;
  5. }
  6. int type = mirror.android.graphics.drawable.Icon.mType.get(icon);
  7. if (type == mirror.android.graphics.drawable.Icon.TYPE_RESOURCE) {
  8. if (installed) {
  9. mirror.android.graphics.drawable.Icon.mObj1.set(icon, appContext.getResources());
  10. mirror.android.graphics.drawable.Icon.mString1.set(icon, appContext.getPackageName());
  11. } else {
  12. Drawable drawable = icon.loadDrawable(appContext);
  13. Bitmap bitmap = drawableToBitMap(drawable);
  14. mirror.android.graphics.drawable.Icon.mObj1.set(icon, bitmap);
  15. mirror.android.graphics.drawable.Icon.mString1.set(icon, null);
  16. mirror.android.graphics.drawable.Icon.mType.set(icon, mirror.android.graphics.drawable.Icon.TYPE_BITMAP);
  17. }
  18. }
  19. }

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

  1. private static void fixNotificationIcon(Context context, Notification notification, Notification.Builder builder) {
  2. if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) {
  3. //noinspection deprecation
  4. builder.setSmallIcon(notification.icon);
  5. //noinspection deprecation
  6. builder.setLargeIcon(notification.largeIcon);
  7. } else {
  8. Icon icon = notification.getSmallIcon();
  9. if (icon != null) {
  10. Bitmap bitmap = drawableToBitMap(icon.loadDrawable(context));
  11. if (bitmap != null) {
  12. Icon newIcon = Icon.createWithBitmap(bitmap);
  13. builder.setSmallIcon(newIcon);
  14. }
  15. }
  16. Icon largeIcon = notification.getLargeIcon();
  17. if (largeIcon != null) {
  18. Bitmap bitmap = drawableToBitMap(largeIcon.loadDrawable(context));
  19. if (bitmap != null) {
  20. Icon newIcon = Icon.createWithBitmap(bitmap);
  21. builder.setLargeIcon(newIcon);
  22. }
  23. }
  24. }
  25. }

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

  1. @TargetApi(Build.VERSION_CODES.M)
  2. void fixIcon(Icon icon, Context appContext, boolean installed) {
  3. if (icon == null) {
  4. return;
  5. }
  6. int type = mirror.android.graphics.drawable.Icon.mType.get(icon);
  7. if (type == mirror.android.graphics.drawable.Icon.TYPE_RESOURCE) {
  8. if (installed) {
  9. mirror.android.graphics.drawable.Icon.mObj1.set(icon, appContext.getResources());
  10. mirror.android.graphics.drawable.Icon.mString1.set(icon, appContext.getPackageName());
  11. } else {
  12. Drawable drawable = icon.loadDrawable(appContext);
  13. Bitmap bitmap = drawableToBitMap(drawable);
  14. mirror.android.graphics.drawable.Icon.mObj1.set(icon, bitmap);
  15. mirror.android.graphics.drawable.Icon.mString1.set(icon, null);
  16. mirror.android.graphics.drawable.Icon.mType.set(icon, mirror.android.graphics.drawable.Icon.TYPE_BITMAP);
  17. }
  18. }
  19. }

代码示例来源:origin: enricocid/LaunchEnr

  1. Resources res = context.getPackageManager().getResourcesForApplication(statusBarNotification.getPackageName());
  2. if (AndroidVersion.isAtLeastMarshmallow) {
  3. mIconDrawable = notification.getSmallIcon().loadDrawable(context);
  4. } else {
  5. mIconDrawable = res.getDrawable(notification.icon, context.getTheme());
  6. mIconDrawable = icon.loadDrawable(context);
  7. mIsIconLarge = true;

代码示例来源:origin: fg607/RelaxFinger

  1. public void newNotification(String pkg, int notifyId, Object icon){
  2. Drawable notifyIcon = null;
  3. if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && icon != null) {
  4. notifyIcon = ((Icon) icon).loadDrawable(mContext);
  5. } else {
  6. notifyIcon = AppUtils.getAppIcon(pkg);
  7. }
  8. NotificationInfo notify = new NotificationInfo(pkg,notifyId,notifyIcon);
  9. mNotifyStack.push(notify);
  10. if(mIsHalfHide){
  11. showFromEdge();
  12. resetHalfHideTime();
  13. }
  14. if(notifyIcon != null){
  15. mBallView.showNotification(notifyIcon);
  16. }
  17. }

相关文章