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

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

本文整理了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

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

@TargetApi(Build.VERSION_CODES.M)
void fixIcon(Icon icon, Context appContext, boolean installed) {
  if (icon == null) {
    return;
  }
  int type = mirror.android.graphics.drawable.Icon.mType.get(icon);
  if (type == mirror.android.graphics.drawable.Icon.TYPE_RESOURCE) {
    if (installed) {
      mirror.android.graphics.drawable.Icon.mObj1.set(icon, appContext.getResources());
      mirror.android.graphics.drawable.Icon.mString1.set(icon, appContext.getPackageName());
    } else {
      Drawable drawable = icon.loadDrawable(appContext);
      Bitmap bitmap = drawableToBitMap(drawable);
      mirror.android.graphics.drawable.Icon.mObj1.set(icon, bitmap);
      mirror.android.graphics.drawable.Icon.mString1.set(icon, null);
      mirror.android.graphics.drawable.Icon.mType.set(icon, mirror.android.graphics.drawable.Icon.TYPE_BITMAP);
    }
  }
}

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

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

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

@Nullable
private static Drawable createIconDrawableMarshmallow(PhoneAccount phoneAccount,
    Context context) {
  Icon accountIcon = getIcon(phoneAccount);
  if (accountIcon == null) {
    return null;
  }
  return accountIcon.loadDrawable(context);
}

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

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

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

@Nullable
public Bitmap getIcon(Context context) {
  if (icon == null) {
    Drawable drawable = null;
    if (iconRes != 0) drawable = getDrawable(context, iconRes, packageName);
    if (drawable == null && unloadedIcon != null && Build.VERSION.SDK_INT >= Build.VERSION_CODES.M)
      drawable = unloadedIcon.loadDrawable(context);
    if (drawable != null) {
      Bitmap bitmap = ImageUtils.drawableToBitmap(drawable);
      if (bitmap != null) {
        icon = bitmap;
        scaledIcon = null;
      }
    }
  }
  return icon;
}

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

public static void createLauncherShortcut(Context context, Intent launchIntent, Icon icon, String id, String label) {
  if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
    ShortcutManager shortcutManager = context.getSystemService(ShortcutManager.class);
    if (shortcutManager.isRequestPinShortcutSupported()) {
      ShortcutInfo info = new ShortcutInfo.Builder(context, id)
          .setIntent(launchIntent)
          .setIcon(icon)
          .setShortLabel(label)
          .setLongLabel(label)
          .build();
      Intent addIntent = shortcutManager.createShortcutResultIntent(info);
      shortcutManager.requestPinShortcut(info,
          PendingIntent.getBroadcast(context, 0, addIntent, 0).getIntentSender());
    } else {
      // TODO: Maybe implement this for launchers without pin shortcut support?
      // TODO: Should be the same with the fallback for Android < O
      // for now just show unsupported
      Toast.makeText(context, context.getString(R.string.unsupported_launcher), Toast.LENGTH_LONG).show();
    }
  } else {
    Intent shortcutIntent = new Intent("com.android.launcher.action.INSTALL_SHORTCUT");
    shortcutIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, launchIntent);
    shortcutIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, label);
    shortcutIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON, drawableToBitmap(icon.loadDrawable(context)));
    context.sendBroadcast(shortcutIntent);
    Toast.makeText(context, R.string.shortcut_create_success, Toast.LENGTH_SHORT).show();
  }
}

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

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

代码示例来源: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: bzsome/VirtualApp-x326

@TargetApi(Build.VERSION_CODES.M)
void fixIcon(Icon icon, Context appContext, boolean installed) {
  if (icon == null) {
    return;
  }
  int type = mirror.android.graphics.drawable.Icon.mType.get(icon);
  if (type == mirror.android.graphics.drawable.Icon.TYPE_RESOURCE) {
    if (installed) {
      mirror.android.graphics.drawable.Icon.mObj1.set(icon, appContext.getResources());
      mirror.android.graphics.drawable.Icon.mString1.set(icon, appContext.getPackageName());
    } else {
      Drawable drawable = icon.loadDrawable(appContext);
      Bitmap bitmap = drawableToBitMap(drawable);
      mirror.android.graphics.drawable.Icon.mObj1.set(icon, bitmap);
      mirror.android.graphics.drawable.Icon.mString1.set(icon, null);
      mirror.android.graphics.drawable.Icon.mType.set(icon, mirror.android.graphics.drawable.Icon.TYPE_BITMAP);
    }
  }
}

代码示例来源: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: darkskygit/VirtualApp

@TargetApi(Build.VERSION_CODES.M)
void fixIcon(Icon icon, Context appContext, boolean installed) {
  if (icon == null) {
    return;
  }
  int type = mirror.android.graphics.drawable.Icon.mType.get(icon);
  if (type == mirror.android.graphics.drawable.Icon.TYPE_RESOURCE) {
    if (installed) {
      mirror.android.graphics.drawable.Icon.mObj1.set(icon, appContext.getResources());
      mirror.android.graphics.drawable.Icon.mString1.set(icon, appContext.getPackageName());
    } else {
      Drawable drawable = icon.loadDrawable(appContext);
      Bitmap bitmap = drawableToBitMap(drawable);
      mirror.android.graphics.drawable.Icon.mObj1.set(icon, bitmap);
      mirror.android.graphics.drawable.Icon.mString1.set(icon, null);
      mirror.android.graphics.drawable.Icon.mType.set(icon, mirror.android.graphics.drawable.Icon.TYPE_BITMAP);
    }
  }
}

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

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

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

public void newNotification(String pkg, int notifyId, Object icon){
  Drawable notifyIcon = null;
  if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && icon != null) {
    notifyIcon = ((Icon) icon).loadDrawable(mContext);
  } else {
    notifyIcon = AppUtils.getAppIcon(pkg);
  }
  NotificationInfo notify = new NotificationInfo(pkg,notifyId,notifyIcon);
  mNotifyStack.push(notify);
  if(mIsHalfHide){
    showFromEdge();
    resetHalfHideTime();
  }
  if(notifyIcon != null){
    mBallView.showNotification(notifyIcon);
  }
}

相关文章