Example usage for android.graphics Paint setFilterBitmap

List of usage examples for android.graphics Paint setFilterBitmap

Introduction

In this page you can find the example usage for android.graphics Paint setFilterBitmap.

Prototype

public void setFilterBitmap(boolean filter) 

Source Link

Document

Helper for setFlags(), setting or clearing the FILTER_BITMAP_FLAG bit.

Usage

From source file:com.dunrite.xpaper.utility.Utils.java

/**
 * TODO: DEPRECATE//from w w  w  .ja  v  a 2  s .  com
 * Combines two images into one while also coloring each separate image
 *
 * @param background the main background drawable
 * @param foreground the drawable in the front of the background]
 * @param context current context
 * @return colorized and combined drawable
 *
 * can add a 3rd parameter 'String loc' if you want to save the new image.
 * left some code to do that at the bottom
 */
public static Drawable combineImages(Drawable background, Drawable foreground, Drawable deviceMisc, int color1,
        int color2, String type, Context context) {
    Bitmap cs;
    Bitmap device = null;
    int width;
    int height;

    //convert from drawable to bitmap
    Bitmap back = ((BitmapDrawable) background).getBitmap();
    back = back.copy(Bitmap.Config.ARGB_8888, true);

    Bitmap x = ((BitmapDrawable) foreground).getBitmap();
    x = x.copy(Bitmap.Config.ARGB_8888, true);

    if (type.equals("device")) {
        device = ((BitmapDrawable) deviceMisc).getBitmap();
        device = device.copy(Bitmap.Config.ARGB_8888, true);
    }
    //initialize Canvas
    if (type.equals("preview") || type.equals("device")) {
        width = back.getWidth() / 2;
        height = back.getHeight() / 2;
    } else {
        width = back.getWidth();
        height = back.getHeight();
    }
    cs = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
    Canvas comboImage = new Canvas(cs);

    //Filter for Background
    Paint paint1 = new Paint();
    paint1.setFilterBitmap(false);
    paint1.setColorFilter(new PorterDuffColorFilter(color1, PorterDuff.Mode.SRC_ATOP));

    //Filter for Foreground
    Paint paint2 = new Paint();
    paint2.setFilterBitmap(false);
    paint2.setColorFilter(new PorterDuffColorFilter(color2, PorterDuff.Mode.SRC_ATOP));

    //Draw both images
    if (type.equals("preview") || type.equals("device")) {
        if (type.equals("device"))
            comboImage.drawBitmap(
                    Bitmap.createScaledBitmap(device, device.getWidth() / 2, device.getHeight() / 2, true), 0,
                    0, null);
        comboImage.drawBitmap(Bitmap.createScaledBitmap(back, back.getWidth() / 2, back.getHeight() / 2, true),
                0, 0, paint1);
        comboImage.drawBitmap(Bitmap.createScaledBitmap(x, x.getWidth() / 2, x.getHeight() / 2, true), 0, 0,
                paint2);
    } else {
        comboImage.drawBitmap(back, 0, 0, paint1);
        comboImage.drawBitmap(x, 0, 0, paint2);
    }

    return new BitmapDrawable(context.getResources(), cs);
}

From source file:com.dunrite.xpaper.utility.Utils.java

public static Drawable combineImages2(Drawable background, Drawable foreground, Drawable deviceMisc,
        int backgroundCol, int foregroundCol, String type, Context context) {
    Bitmap cs;// www  .j a v  a2s . c o  m
    Bitmap device = null;
    int width;
    int height;

    //TEXTURE TESTING
    String textureLocation = "";
    Bitmap foregroundTexture = null;
    //TODO: will need some type of way to know which location to put the texture (foreground/background/both)
    //        String textureLocation = "foreground";
    //        type = "";
    //TODO: will need some type of way to know which foreground texture drawable to pull from
    //        Bitmap foregroundTexture = ((BitmapDrawable) ContextCompat.getDrawable(context, R.drawable.texture_bamboo)).getBitmap();
    //        foregroundTexture = foregroundTexture.copy(Bitmap.Config.ARGB_8888, true);

    //convert from drawable to bitmap
    Bitmap back = ((BitmapDrawable) background).getBitmap();
    back = back.copy(Bitmap.Config.ARGB_8888, true);

    Bitmap fore = ((BitmapDrawable) foreground).getBitmap();
    fore = fore.copy(Bitmap.Config.ARGB_8888, true);

    if (type.equals("device")) {
        device = ((BitmapDrawable) deviceMisc).getBitmap();
        device = device.copy(Bitmap.Config.ARGB_8888, true);
    }
    //initialize Canvas
    if (type.equals("preview") || type.equals("device")) {
        width = back.getWidth() / 2;
        height = back.getHeight() / 2;
    } else {
        width = back.getWidth();
        height = back.getHeight();
    }
    cs = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
    Canvas comboImage = new Canvas(cs);

    Paint paint1 = new Paint();
    paint1.setFilterBitmap(false);
    //Filter for Background
    if (textureLocation.equals("background") || textureLocation.equals("both")) {
        paint1.setColorFilter(new PorterDuffColorFilter(backgroundCol, PorterDuff.Mode.DST_ATOP));
    } else {
        paint1.setColorFilter(new PorterDuffColorFilter(backgroundCol, PorterDuff.Mode.SRC_ATOP));
    }

    //Filter for Foreground
    Paint paint2 = new Paint();
    paint2.setFilterBitmap(false);
    if (textureLocation.equals("foreground") || textureLocation.equals("both")) {
        //DIFFICULT CASE
        //create new canvas to combine
        Canvas foreCanvas = new Canvas(fore);

        //set up paint for texture
        Paint paintTexture = new Paint();
        paintTexture.setFilterBitmap(false);
        paintTexture.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));

        //draw our combination
        foreCanvas.drawBitmap(foregroundTexture, 0, 0, paintTexture);

        //set up theme for outer image
        paint2.setColorFilter(new PorterDuffColorFilter(foregroundCol, PorterDuff.Mode.DST_IN));
    } else {
        paint2.setColorFilter(new PorterDuffColorFilter(foregroundCol, PorterDuff.Mode.SRC_ATOP));
    }

    //Draw both images
    if (type.equals("preview") || type.equals("device")) {
        if (type.equals("device") && device != null) {
            comboImage.drawBitmap(
                    Bitmap.createScaledBitmap(device, device.getWidth() / 2, device.getHeight() / 2, true), 0,
                    0, null);
            device.recycle();
        }
        comboImage.drawBitmap(Bitmap.createScaledBitmap(back, back.getWidth() / 2, back.getHeight() / 2, true),
                0, 0, paint1);
        comboImage.drawBitmap(Bitmap.createScaledBitmap(fore, fore.getWidth() / 2, fore.getHeight() / 2, true),
                0, 0, paint2);

    } else {
        comboImage.drawBitmap(back, 0, 0, paint1);
        comboImage.drawBitmap(fore, 0, 0, paint2);
    }
    back.recycle();
    fore.recycle();

    return new BitmapDrawable(context.getResources(), cs);
}

From source file:de.mrapp.android.util.BitmapUtil.java

/**
 * Clips the long edge of a bitmap, if its width and height are not equal, in order to transform
 * it into a square. Additionally, the bitmap is resized to a specific size and a border will be
 * added./* w ww.  j  a  v a2s.c o m*/
 *
 * @param bitmap
 *         The bitmap, which should be clipped, as an instance of the class {@link Bitmap}. The
 *         bitmap may not be null
 * @param size
 *         The size, the bitmap should be resized to, as an {@link Integer} value in pixels. The
 *         size must be at least 1
 * @param borderWidth
 *         The width of the border as an {@link Integer} value in pixels. The width must be at
 *         least 0
 * @param borderColor
 *         The color of the border as an {@link Integer} value
 * @return The clipped bitmap as an instance of the class {@link Bitmap}
 */
public static Bitmap clipSquare(@NonNull final Bitmap bitmap, final int size, final int borderWidth,
        @ColorInt final int borderColor) {
    ensureAtLeast(borderWidth, 0, "The border width must be at least 0");
    Bitmap clippedBitmap = clipSquare(bitmap, size);
    Bitmap result = Bitmap.createBitmap(clippedBitmap.getWidth(), clippedBitmap.getHeight(),
            Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(result);
    float offset = borderWidth / 2.0f;
    Rect src = new Rect(0, 0, clippedBitmap.getWidth(), clippedBitmap.getHeight());
    RectF dst = new RectF(offset, offset, result.getWidth() - offset, result.getHeight() - offset);
    canvas.drawBitmap(clippedBitmap, src, dst, null);

    if (borderWidth > 0 && Color.alpha(borderColor) != 0) {
        Paint paint = new Paint();
        paint.setFilterBitmap(false);
        paint.setStyle(Paint.Style.STROKE);
        paint.setStrokeWidth(borderWidth);
        paint.setColor(borderColor);
        offset = borderWidth / 2.0f;
        RectF bounds = new RectF(offset, offset, result.getWidth() - offset, result.getWidth() - offset);
        canvas.drawRect(bounds, paint);
    }

    return result;
}

From source file:de.mrapp.android.util.BitmapUtil.java

/**
 * Clips the corners of a bitmap in order to transform it into a round shape. Additionally, the
 * bitmap is resized to a specific size and a border will be added. Bitmaps, whose width and
 * height are not equal, will be clipped to a square beforehand.
 *
 * @param bitmap/*from  w  w w. j  a  v  a  2 s .c o m*/
 *         The bitmap, which should be clipped, as an instance of the class {@link Bitmap}. The
 *         bitmap may not be null
 * @param size
 *         The size, the bitmap should be resized to, as an {@link Integer} value in pixels. The
 *         size must be at least 1
 * @param borderWidth
 *         The width of the border as an {@link Integer} value in pixels. The width must be at
 *         least 0
 * @param borderColor
 *         The color of the border as an {@link Integer} value
 * @return The clipped bitmap as an instance of the class {@link Bitmap}
 */
public static Bitmap clipCircle(@NonNull final Bitmap bitmap, final int size, final int borderWidth,
        @ColorInt final int borderColor) {
    ensureAtLeast(borderWidth, 0, "The border width must be at least 0");
    Bitmap clippedBitmap = clipCircle(bitmap, size);
    Bitmap result = Bitmap.createBitmap(clippedBitmap.getWidth(), clippedBitmap.getHeight(),
            Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(result);
    float offset = borderWidth / 2.0f;
    Rect src = new Rect(0, 0, clippedBitmap.getWidth(), clippedBitmap.getHeight());
    RectF dst = new RectF(offset, offset, result.getWidth() - offset, result.getHeight() - offset);
    canvas.drawBitmap(clippedBitmap, src, dst, null);

    if (borderWidth > 0 && Color.alpha(borderColor) != 0) {
        Paint paint = new Paint();
        paint.setFilterBitmap(false);
        paint.setAntiAlias(true);
        paint.setStrokeCap(Paint.Cap.ROUND);
        paint.setStyle(Paint.Style.STROKE);
        paint.setStrokeWidth(borderWidth);
        paint.setColor(borderColor);
        offset = borderWidth / 2.0f;
        RectF bounds = new RectF(offset, offset, result.getWidth() - offset, result.getWidth() - offset);
        canvas.drawArc(bounds, 0, COMPLETE_ARC_ANGLE, false, paint);
    }

    return result;
}

From source file:com.dunrite.xpaper.utility.Utils.java

/**
 * Creates drawable for the wallpaper//from w w w  .j ava2  s  .  c  o m
 * @param context current app context
 * @param foreground foreground drawable
 * @param bgColor color of background
 * @param fgColor color of foreground
 * @param isPreview if this is for the preview or not
 * @return the final, constructed wallpaper
 */
public static Drawable constructWallpaper(Context context, Drawable foreground, int bgColor, int fgColor,
        boolean isPreview) {
    final int WIDTH = 2560;
    final int HEIGHT = 1440;
    Canvas comboImage;
    Bitmap cs, fg;
    Paint fgPaint = new Paint();

    //create bitmap from foreground drawable
    fg = ((BitmapDrawable) foreground).getBitmap();

    if (isPreview)
        cs = Bitmap.createBitmap(WIDTH / 2, HEIGHT / 2, Bitmap.Config.ARGB_8888);
    else
        cs = Bitmap.createBitmap(WIDTH, HEIGHT, Bitmap.Config.ARGB_8888);
    comboImage = new Canvas(cs);

    fgPaint.setFilterBitmap(false);
    fgPaint.setColorFilter(new PorterDuffColorFilter(fgColor, PorterDuff.Mode.SRC_ATOP));

    comboImage.drawRGB(Color.red(bgColor), Color.green(bgColor), Color.blue(bgColor));
    if (isPreview)
        comboImage.drawBitmap(Bitmap.createScaledBitmap(fg, WIDTH / 2, HEIGHT / 2, true), 0, 0, fgPaint);
    else
        comboImage.drawBitmap(fg, 0, 0, fgPaint);

    return new BitmapDrawable(context.getResources(), cs);
}

From source file:org.y20k.transistor.helpers.ImageHelper.java

public Bitmap createCircularFramedImage(int size) {

    // create empty bitmap and canvas
    Bitmap outputImage = Bitmap.createBitmap(size, size, Bitmap.Config.ARGB_8888);
    Canvas imageCanvas = new Canvas(outputImage);

    // construct circular background
    mBackgroundColor.setStyle(Paint.Style.FILL);
    float cx = size / 2;
    float cy = size / 2;
    float radius = size / 2;

    // draw circular background
    imageCanvas.drawCircle(cx, cy, radius, mBackgroundColor);

    // get size of original image
    float inputImageHeight = (float) mInputImage.getHeight();
    float inputImageWidth = (float) mInputImage.getWidth();

    // calculate padding
    float padding = (float) size / 4;

    // define variables needed for transformation matrix
    Matrix transformationMatrix = new Matrix();
    float aspectRatio = 0.0f;
    float xTranslation = 0.0f;
    float yTranslation = 0.0f;

    // landscape format and square
    if (inputImageWidth >= inputImageHeight) {
        aspectRatio = (size - padding * 2) / inputImageWidth;
        xTranslation = 0.0f + padding;//www  . j  a v a 2  s .c  om
        yTranslation = (size - inputImageHeight * aspectRatio) / 2.0f;
    }
    // portrait format
    else if (inputImageHeight > inputImageWidth) {
        aspectRatio = (size - padding * 2) / inputImageHeight;
        yTranslation = 0.0f + padding;
        xTranslation = (size - inputImageWidth * aspectRatio) / 2.0f;
    }

    // construct transformation matrix
    transformationMatrix.postTranslate(xTranslation, yTranslation);
    transformationMatrix.preScale(aspectRatio, aspectRatio);

    // draw input image onto canvas using transformation matrix
    Paint paint = new Paint();
    paint.setFilterBitmap(true);
    imageCanvas.drawBitmap(mInputImage, transformationMatrix, paint);

    return outputImage;
}

From source file:br.com.viniciuscr.notification2android.mediaPlayer.MusicUtils.java

static void setBackground(View v, Bitmap bm) {

    if (bm == null) {
        v.setBackgroundResource(0);/*from  w  ww  .ja v  a  2  s.c o  m*/
        return;
    }

    int vwidth = v.getWidth();
    int vheight = v.getHeight();
    int bwidth = bm.getWidth();
    int bheight = bm.getHeight();
    float scalex = (float) vwidth / bwidth;
    float scaley = (float) vheight / bheight;
    float scale = Math.max(scalex, scaley) * 1.3f;

    Bitmap.Config config = Bitmap.Config.ARGB_8888;
    Bitmap bg = Bitmap.createBitmap(vwidth, vheight, config);
    Canvas c = new Canvas(bg);
    Paint paint = new Paint();
    paint.setAntiAlias(true);
    paint.setFilterBitmap(true);
    ColorMatrix greymatrix = new ColorMatrix();
    greymatrix.setSaturation(0);
    ColorMatrix darkmatrix = new ColorMatrix();
    darkmatrix.setScale(.3f, .3f, .3f, 1.0f);
    greymatrix.postConcat(darkmatrix);
    ColorFilter filter = new ColorMatrixColorFilter(greymatrix);
    paint.setColorFilter(filter);
    Matrix matrix = new Matrix();
    matrix.setTranslate(-bwidth / 2, -bheight / 2); // move bitmap center to origin
    matrix.postRotate(10);
    matrix.postScale(scale, scale);
    matrix.postTranslate(vwidth / 2, vheight / 2); // Move bitmap center to view center
    c.drawBitmap(bm, matrix, paint);
    v.setBackgroundDrawable(new BitmapDrawable(bg));
}

From source file:com.silentcircle.contacts.list.ShortcutIntentBuilder.java

/**
 * Generates a phone number shortcut icon. Adds an overlay describing the type of the phone
 * number, and if there is a photo also adds the call action icon.
 *///ww w . jav  a2 s .  c om
private Bitmap generatePhoneNumberIcon(Drawable photo, int phoneType, String phoneLabel, int actionResId) {
    final Resources r = mContext.getResources();
    final float density = r.getDisplayMetrics().density;

    Bitmap phoneIcon = ((BitmapDrawable) r.getDrawableForDensity(actionResId, mIconDensity)).getBitmap();

    Bitmap icon = generateQuickContactIcon(photo);
    Canvas canvas = new Canvas(icon);

    // Copy in the photo
    Paint photoPaint = new Paint();
    photoPaint.setDither(true);
    photoPaint.setFilterBitmap(true);
    Rect dst = new Rect(0, 0, mIconSize, mIconSize);

    // Create an overlay for the phone number type
    CharSequence overlay = Phone.getTypeLabel(r, phoneType, phoneLabel);

    if (overlay != null) {
        TextPaint textPaint = new TextPaint(Paint.ANTI_ALIAS_FLAG | Paint.DEV_KERN_TEXT_FLAG);
        textPaint.setTextSize(r.getDimension(R.dimen.shortcut_overlay_text_size));
        textPaint.setColor(ContextCompat.getColor(mContext, R.color.textColorIconOverlay));
        textPaint.setShadowLayer(4f, 0, 2f,
                ContextCompat.getColor(mContext, R.color.textColorIconOverlayShadow));

        final FontMetricsInt fmi = textPaint.getFontMetricsInt();

        // First fill in a darker background around the text to be drawn
        final Paint workPaint = new Paint();
        workPaint.setColor(mOverlayTextBackgroundColor);
        workPaint.setStyle(Paint.Style.FILL);
        final int textPadding = r.getDimensionPixelOffset(R.dimen.shortcut_overlay_text_background_padding);
        final int textBandHeight = (fmi.descent - fmi.ascent) + textPadding * 2;
        dst.set(0, mIconSize - textBandHeight, mIconSize, mIconSize);
        canvas.drawRect(dst, workPaint);

        overlay = TextUtils.ellipsize(overlay, textPaint, mIconSize, TruncateAt.END);
        final float textWidth = textPaint.measureText(overlay, 0, overlay.length());
        canvas.drawText(overlay, 0, overlay.length(), (mIconSize - textWidth) / 2,
                mIconSize - fmi.descent - textPadding, textPaint);
    }

    // Draw the phone action icon as an overlay
    Rect src = new Rect(0, 0, phoneIcon.getWidth(), phoneIcon.getHeight());
    int iconWidth = icon.getWidth();
    dst.set(iconWidth - ((int) (20 * density)), -1, iconWidth, ((int) (19 * density)));
    canvas.drawBitmap(phoneIcon, src, dst, photoPaint);

    canvas.setBitmap(null);

    return icon;
}

From source file:com.android.contacts.common.list.ShortcutIntentBuilder.java

/**
 * Generates a phone number shortcut icon. Adds an overlay describing the type of the phone
 * number, and if there is a photo also adds the call action icon.
 *///from  w ww . java 2  s . com
private Bitmap generatePhoneNumberIcon(Drawable photo, int phoneType, String phoneLabel, int actionResId) {
    final Resources r = mContext.getResources();
    final float density = r.getDisplayMetrics().density;

    Bitmap phoneIcon = ((BitmapDrawable) r.getDrawableForDensity(actionResId, mIconDensity)).getBitmap();

    Bitmap icon = generateQuickContactIcon(photo);
    Canvas canvas = new Canvas(icon);

    // Copy in the photo
    Paint photoPaint = new Paint();
    photoPaint.setDither(true);
    photoPaint.setFilterBitmap(true);
    Rect dst = new Rect(0, 0, mIconSize, mIconSize);

    // Create an overlay for the phone number type
    CharSequence overlay = Phone.getTypeLabel(r, phoneType, phoneLabel);

    if (overlay != null) {
        TextPaint textPaint = new TextPaint(Paint.ANTI_ALIAS_FLAG | Paint.DEV_KERN_TEXT_FLAG);
        textPaint.setTextSize(r.getDimension(R.dimen.shortcut_overlay_text_size));
        textPaint.setColor(r.getColor(R.color.textColorIconOverlay));
        textPaint.setShadowLayer(4f, 0, 2f, r.getColor(R.color.textColorIconOverlayShadow));

        final FontMetricsInt fmi = textPaint.getFontMetricsInt();

        // First fill in a darker background around the text to be drawn
        final Paint workPaint = new Paint();
        workPaint.setColor(mOverlayTextBackgroundColor);
        workPaint.setStyle(Paint.Style.FILL);
        final int textPadding = r.getDimensionPixelOffset(R.dimen.shortcut_overlay_text_background_padding);
        final int textBandHeight = (fmi.descent - fmi.ascent) + textPadding * 2;
        dst.set(0, mIconSize - textBandHeight, mIconSize, mIconSize);
        canvas.drawRect(dst, workPaint);

        overlay = TextUtils.ellipsize(overlay, textPaint, mIconSize, TruncateAt.END);
        final float textWidth = textPaint.measureText(overlay, 0, overlay.length());
        canvas.drawText(overlay, 0, overlay.length(), (mIconSize - textWidth) / 2,
                mIconSize - fmi.descent - textPadding, textPaint);
    }

    // Draw the phone action icon as an overlay
    Rect src = new Rect(0, 0, phoneIcon.getWidth(), phoneIcon.getHeight());
    int iconWidth = icon.getWidth();
    dst.set(iconWidth - ((int) (20 * density)), -1, iconWidth, ((int) (19 * density)));
    canvas.drawBitmap(phoneIcon, src, dst, photoPaint);

    canvas.setBitmap(null);

    return icon;
}

From source file:com.android.contacts.ShortcutIntentBuilder.java

/**
 * Generates a phone number shortcut icon. Adds an overlay describing the type of the phone
 * number, and if there is a photo also adds the call action icon.
 *//*from ww w.  j a  v a2  s .  com*/
private Bitmap generatePhoneNumberIcon(Drawable photo, int phoneType, String phoneLabel, int actionResId) {
    final Resources r = mContext.getResources();
    final float density = r.getDisplayMetrics().density;

    final Drawable phoneDrawable = r.getDrawableForDensity(actionResId, mIconDensity);
    // These icons have the same height and width so either is fine for the size.
    final Bitmap phoneIcon = BitmapUtil.drawableToBitmap(phoneDrawable, phoneDrawable.getIntrinsicHeight());

    Bitmap icon = generateQuickContactIcon(photo);
    Canvas canvas = new Canvas(icon);

    // Copy in the photo
    Paint photoPaint = new Paint();
    photoPaint.setDither(true);
    photoPaint.setFilterBitmap(true);
    Rect dst = new Rect(0, 0, mIconSize, mIconSize);

    // Create an overlay for the phone number type if we're pre-O. O created shortcuts have the
    // app badge which overlaps the type overlay.
    CharSequence overlay = Phone.getTypeLabel(r, phoneType, phoneLabel);
    if (!BuildCompat.isAtLeastO() && overlay != null) {
        TextPaint textPaint = new TextPaint(Paint.ANTI_ALIAS_FLAG | Paint.DEV_KERN_TEXT_FLAG);
        textPaint.setTextSize(r.getDimension(R.dimen.shortcut_overlay_text_size));
        textPaint.setColor(r.getColor(R.color.textColorIconOverlay));
        textPaint.setShadowLayer(4f, 0, 2f, r.getColor(R.color.textColorIconOverlayShadow));

        final FontMetricsInt fmi = textPaint.getFontMetricsInt();

        // First fill in a darker background around the text to be drawn
        final Paint workPaint = new Paint();
        workPaint.setColor(mOverlayTextBackgroundColor);
        workPaint.setStyle(Paint.Style.FILL);
        final int textPadding = r.getDimensionPixelOffset(R.dimen.shortcut_overlay_text_background_padding);
        final int textBandHeight = (fmi.descent - fmi.ascent) + textPadding * 2;
        dst.set(0, mIconSize - textBandHeight, mIconSize, mIconSize);
        canvas.drawRect(dst, workPaint);

        overlay = TextUtils.ellipsize(overlay, textPaint, mIconSize, TruncateAt.END);
        final float textWidth = textPaint.measureText(overlay, 0, overlay.length());
        canvas.drawText(overlay, 0, overlay.length(), (mIconSize - textWidth) / 2,
                mIconSize - fmi.descent - textPadding, textPaint);
    }

    // Draw the phone action icon as an overlay
    int iconWidth = icon.getWidth();
    if (BuildCompat.isAtLeastO()) {
        // On O we need to calculate where the phone icon goes slightly differently. The whole
        // canvas area is 108dp, a centered circle with a diameter of 66dp is the "safe zone".
        // So we start the drawing the phone icon at
        // 108dp - 21 dp (distance from right edge of safe zone to the edge of the canvas)
        // - 24 dp (size of the phone icon) on the x axis (left)
        // The y axis is simply 21dp for the distance to the safe zone (top).
        // See go/o-icons-eng for more details and a handy picture.
        final int left = (int) (mIconSize - (45 * density));
        final int top = (int) (21 * density);
        canvas.drawBitmap(phoneIcon, left, top, photoPaint);
    } else {
        dst.set(iconWidth - ((int) (20 * density)), -1, iconWidth, ((int) (19 * density)));
        canvas.drawBitmap(phoneIcon, null, dst, photoPaint);
    }

    canvas.setBitmap(null);
    return icon;
}