Java Code Examples for android.graphics.drawable.Icon#getBitmap()

The following examples show how to use android.graphics.drawable.Icon#getBitmap() . 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: TextClassification.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
@Nullable
private static Drawable maybeLoadDrawable(Icon icon) {
    if (icon == null) {
        return null;
    }
    switch (icon.getType()) {
        case Icon.TYPE_BITMAP:
            return new BitmapDrawable(Resources.getSystem(), icon.getBitmap());
        case Icon.TYPE_ADAPTIVE_BITMAP:
            return new AdaptiveIconDrawable(null,
                    new BitmapDrawable(Resources.getSystem(), icon.getBitmap()));
        case Icon.TYPE_DATA:
            return new BitmapDrawable(
                    Resources.getSystem(),
                    BitmapFactory.decodeByteArray(
                            icon.getDataBytes(), icon.getDataOffset(), icon.getDataLength()));
    }
    return null;
}
 
Example 2
Source File: ShortcutService.java    From android_9.0.0_r45 with Apache License 2.0 4 votes vote down vote up
void saveIconAndFixUpShortcutLocked(ShortcutInfo shortcut) {
    if (shortcut.hasIconFile() || shortcut.hasIconResource()) {
        return;
    }

    final long token = injectClearCallingIdentity();
    try {
        // Clear icon info on the shortcut.
        removeIconLocked(shortcut);

        final Icon icon = shortcut.getIcon();
        if (icon == null) {
            return; // has no icon
        }
        int maxIconDimension = mMaxIconDimension;
        Bitmap bitmap;
        try {
            switch (icon.getType()) {
                case Icon.TYPE_RESOURCE: {
                    injectValidateIconResPackage(shortcut, icon);

                    shortcut.setIconResourceId(icon.getResId());
                    shortcut.addFlags(ShortcutInfo.FLAG_HAS_ICON_RES);
                    return;
                }
                case Icon.TYPE_BITMAP:
                    bitmap = icon.getBitmap(); // Don't recycle in this case.
                    break;
                case Icon.TYPE_ADAPTIVE_BITMAP: {
                    bitmap = icon.getBitmap(); // Don't recycle in this case.
                    maxIconDimension *= (1 + 2 * AdaptiveIconDrawable.getExtraInsetFraction());
                    break;
                }
                default:
                    // This shouldn't happen because we've already validated the icon, but
                    // just in case.
                    throw ShortcutInfo.getInvalidIconException();
            }
            mShortcutBitmapSaver.saveBitmapLocked(shortcut,
                    maxIconDimension, mIconPersistFormat, mIconPersistQuality);
        } finally {
            // Once saved, we won't use the original icon information, so null it out.
            shortcut.clearIcon();
        }
    } finally {
        injectRestoreCallingIdentity(token);
    }
}