Java Code Examples for android.graphics.drawable.Icon#loadDrawable()
The following examples show how to use
android.graphics.drawable.Icon#loadDrawable() .
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: NotificationListenerService.java From android_9.0.0_r45 with Apache License 2.0 | 6 votes |
/** Convert new-style Icons to legacy representations for pre-M clients. */ private void createLegacyIconExtras(Notification n) { Icon smallIcon = n.getSmallIcon(); Icon largeIcon = n.getLargeIcon(); if (smallIcon != null && smallIcon.getType() == Icon.TYPE_RESOURCE) { n.extras.putInt(Notification.EXTRA_SMALL_ICON, smallIcon.getResId()); n.icon = smallIcon.getResId(); } if (largeIcon != null) { Drawable d = largeIcon.loadDrawable(getContext()); if (d != null && d instanceof BitmapDrawable) { final Bitmap largeIconBits = ((BitmapDrawable) d).getBitmap(); n.extras.putParcelable(Notification.EXTRA_LARGE_ICON, largeIconBits); n.largeIcon = largeIconBits; } } }
Example 2
Source File: ModStatusbarColor.java From GravityBox with Apache License 2.0 | 6 votes |
private static Drawable getColoredDrawable(Context ctx, String pkg, Icon icon) { if (icon == null) return null; Drawable d = null; if (pkg == null || PACKAGE_NAME.equals(pkg)) { final int iconId = (int) XposedHelpers.callMethod(icon, "getResId"); d = SysUiManagers.IconManager.getBasicIcon(iconId); if (d != null) { return d; } } d = icon.loadDrawable(ctx); if (d != null) { if (SysUiManagers.IconManager.isColoringEnabled()) { d = SysUiManagers.IconManager.applyColorFilter(d.mutate(), PorterDuff.Mode.SRC_IN); } else { d.clearColorFilter(); } } return d; }
Example 3
Source File: NotificationFixer.java From container with GNU General Public License v3.0 | 6 votes |
@TargetApi(Build.VERSION_CODES.M) void fixIcon(Icon icon, Context pluginContext, boolean isInstall) { if (icon == null) return; int type = Reflect.on(icon).get("mType"); // Log.i(TAG, "smallIcon type=" + type); if (type == 2) { if (isInstall) { Reflect.on(icon).set("mObj1", pluginContext.getResources()); Reflect.on(icon).set("mString1", pluginContext.getPackageName()); } else { Drawable drawable = icon.loadDrawable(pluginContext); Bitmap bitmap = drawableToBitMap(drawable); Reflect.on(icon).set("mObj1", bitmap); Reflect.on(icon).set("mString1", null); Reflect.on(icon).set("mType", 1); } } }
Example 4
Source File: PrinterInfo.java From android_9.0.0_r45 with Apache License 2.0 | 5 votes |
/** * Get the icon to be used for this printer. If no per printer icon is available, the printer's * service's icon is returned. If the printer has a custom icon this icon might get requested * asynchronously. Once the icon is loaded the discovery sessions will be notified that the * printer changed. * * @param context The context that will be using the icons * @return The icon to be used for the printer or null if no icon could be found. * @hide */ @TestApi public @Nullable Drawable loadIcon(@NonNull Context context) { Drawable drawable = null; PackageManager packageManager = context.getPackageManager(); if (mHasCustomPrinterIcon) { PrintManager printManager = (PrintManager) context .getSystemService(Context.PRINT_SERVICE); Icon icon = printManager.getCustomPrinterIcon(mId); if (icon != null) { drawable = icon.loadDrawable(context); } } if (drawable == null) { try { String packageName = mId.getServiceName().getPackageName(); PackageInfo packageInfo = packageManager.getPackageInfo(packageName, 0); ApplicationInfo appInfo = packageInfo.applicationInfo; // If no custom icon is available, try the icon from the resources if (mIconResourceId != 0) { drawable = packageManager.getDrawable(packageName, mIconResourceId, appInfo); } // Fall back to the printer's service's icon if no per printer icon could be found if (drawable == null) { drawable = appInfo.loadIcon(packageManager); } } catch (NameNotFoundException e) { } } return drawable; }
Example 5
Source File: LauncherApps.java From android_9.0.0_r45 with Apache License 2.0 | 4 votes |
/** * Returns the icon for this shortcut, without any badging for the profile. * * <p>The calling launcher application must be allowed to access the shortcut information, * as defined in {@link #hasShortcutHostPermission()}. * * @param density The preferred density of the icon, zero for default density. Use * density DPI values from {@link DisplayMetrics}. * * @return The drawable associated with the shortcut. * @throws IllegalStateException when the user is locked, or when the {@code user} user * is locked or not running. * * @see ShortcutManager * @see #getShortcutBadgedIconDrawable(ShortcutInfo, int) * @see DisplayMetrics */ public Drawable getShortcutIconDrawable(@NonNull ShortcutInfo shortcut, int density) { if (shortcut.hasIconFile()) { final ParcelFileDescriptor pfd = getShortcutIconFd(shortcut); if (pfd == null) { return null; } try { final Bitmap bmp = BitmapFactory.decodeFileDescriptor(pfd.getFileDescriptor()); if (bmp != null) { BitmapDrawable dr = new BitmapDrawable(mContext.getResources(), bmp); if (shortcut.hasAdaptiveBitmap()) { return new AdaptiveIconDrawable(null, dr); } else { return dr; } } return null; } finally { try { pfd.close(); } catch (IOException ignore) { } } } else if (shortcut.hasIconResource()) { return loadDrawableResourceFromPackage(shortcut.getPackage(), shortcut.getIconResourceId(), shortcut.getUserHandle(), density); } else if (shortcut.getIcon() != null) { // This happens if a shortcut is pending-approval. final Icon icon = shortcut.getIcon(); switch (icon.getType()) { case Icon.TYPE_RESOURCE: { return loadDrawableResourceFromPackage(shortcut.getPackage(), icon.getResId(), shortcut.getUserHandle(), density); } case Icon.TYPE_BITMAP: case Icon.TYPE_ADAPTIVE_BITMAP: { return icon.loadDrawable(mContext); } default: return null; // Shouldn't happen though. } } else { return null; // Has no icon. } }
Example 6
Source File: ImageView.java From android_9.0.0_r45 with Apache License 2.0 | 4 votes |
/** @hide **/ public Runnable setImageIconAsync(@Nullable Icon icon) { return new ImageDrawableCallback(icon == null ? null : icon.loadDrawable(mContext), null, 0); }