Java Code Examples for android.graphics.drawable.AdaptiveIconDrawable#setBounds()

The following examples show how to use android.graphics.drawable.AdaptiveIconDrawable#setBounds() . 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: LauncherIcons.java    From LaunchEnr with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Creates a normalized bitmap suitable for the all apps view. The bitmap is also visually
 * normalized with other icons and has enough spacing to add shadow.
 */
public static Bitmap createScaledBitmapWithoutShadow(Drawable icon, Context context, int iconAppTargetSdk) {
    RectF iconBounds = new RectF();
    IconNormalizer normalizer;
    float scale = 1f;
        normalizer = IconNormalizer.getInstance(context);
        if (AndroidVersion.isAtLeastOreo() && iconAppTargetSdk >= Build.VERSION_CODES.O) {
            boolean[] outShape = new boolean[1];
            AdaptiveIconDrawable dr = (AdaptiveIconDrawable)
                    context.getDrawable(R.drawable.adaptive_icon_drawable_wrapper).mutate();
            dr.setBounds(0, 0, 1, 1);
            scale = normalizer.getScale(icon, iconBounds, dr.getIconMask(), outShape);
            if (AndroidVersion.isAtLeastOreo() &&
                    !outShape[0]) {
                Drawable wrappedIcon = wrapToAdaptiveIconDrawable(context, icon, scale);
                if (wrappedIcon != icon) {
                    icon = wrappedIcon;
                    scale = normalizer.getScale(icon, iconBounds, null, null);
                }
            }

    }
    scale = Math.min(scale, ShadowGenerator.getScaleForBounds(iconBounds));
    return createIconBitmap(icon, context, scale);
}
 
Example 2
Source File: IconPackManager.java    From emerald with GNU General Public License v3.0 6 votes vote down vote up
public Bitmap getDefaultBitmap(Drawable d) {
	if (d instanceof BitmapDrawable) {
		return ((BitmapDrawable) d).getBitmap();
	} else if ((Build.VERSION.SDK_INT >= 26)
		&& (d instanceof AdaptiveIconDrawable)) {
			AdaptiveIconDrawable icon = ((AdaptiveIconDrawable)d);
			int w = icon.getIntrinsicWidth();
			int h = icon.getIntrinsicHeight();
			Bitmap result = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888);
			Canvas canvas = new Canvas(result);
			icon.setBounds(0, 0, w, h);
			icon.draw(canvas);
			return result;
	}
	float density = context.getResources().getDisplayMetrics().density;
	int defaultWidth = (int)(48* density);
	int defaultHeight = (int)(48* density);
	return Bitmap.createBitmap(defaultWidth, defaultHeight, Bitmap.Config.ARGB_8888);
}
 
Example 3
Source File: LauncherIcons.java    From LaunchEnr with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Returns a bitmap suitable for the all apps view. The icon is badged for {@param user}.
 * The bitmap is also visually normalized with other icons.
 */
public static Bitmap createBadgedIconBitmap(
        Drawable icon, UserHandle user, Context context, int iconAppTargetSdk) {

    IconNormalizer normalizer;
    float scale = 1f;
        normalizer = IconNormalizer.getInstance(context);
        if (AndroidVersion.isAtLeastOreo() && iconAppTargetSdk >= Build.VERSION_CODES.O) {
            boolean[] outShape = new boolean[1];
            AdaptiveIconDrawable dr = (AdaptiveIconDrawable)
                    context.getDrawable(R.drawable.adaptive_icon_drawable_wrapper).mutate();
            dr.setBounds(0, 0, 1, 1);
            scale = normalizer.getScale(icon, null, dr.getIconMask(), outShape);
            if (!outShape[0]){
                Drawable wrappedIcon = wrapToAdaptiveIconDrawable(context, icon, scale);
                if (wrappedIcon != icon) {
                    icon = wrappedIcon;
                    scale = normalizer.getScale(icon, null, null, null);
                }
            }
    }
    Bitmap bitmap = createIconBitmap(icon, context, scale);
    if (AndroidVersion.isAtLeastOreo() &&
            icon instanceof AdaptiveIconDrawable) {
        bitmap = ShadowGenerator.getInstance(context).recreateIcon(bitmap);
    }
    return badgeIconForUser(bitmap, user, context);
}
 
Example 4
Source File: ShortcutIcons.java    From island with Apache License 2.0 5 votes vote down vote up
@RequiresApi(O) static Icon createAdaptiveIcon(final AdaptiveIconDrawable drawable) {
	final int width = drawable.getIntrinsicWidth() * 3 / 2, height = drawable.getIntrinsicHeight() * 3 / 2,
			start = drawable.getIntrinsicWidth() / 4, top = drawable.getIntrinsicHeight() / 4;
	drawable.setBounds(start, top, width - start, height - top);
	final Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
	final Canvas canvas = new Canvas(bitmap);
	drawable.draw(canvas);
	return Icon.createWithAdaptiveBitmap(bitmap);
}
 
Example 5
Source File: Image.java    From DistroHopper with GNU General Public License v3.0 5 votes vote down vote up
@RequiresApi(Build.VERSION_CODES.O)
private static Drawable adaptiveIconToDrawable(AdaptiveIconDrawable adaptive) {
	final Bitmap bitmap = Bitmap.createBitmap(adaptive.getIntrinsicWidth(), adaptive.getIntrinsicHeight(), Bitmap.Config.ARGB_8888);
	final Canvas canvas = new Canvas(bitmap);

	adaptive.setBounds(0, 0, canvas.getWidth(), canvas.getHeight());
	adaptive.draw(canvas);

	return new BitmapDrawable(bitmap);
}