Example usage for android.graphics Paint setStyle

List of usage examples for android.graphics Paint setStyle

Introduction

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

Prototype

public void setStyle(Style style) 

Source Link

Document

Set the paint's style, used for controlling how primitives' geometries are interpreted (except for drawBitmap, which always assumes Fill).

Usage

From source file:com.blogspot.ksoichiro.viewIndicator.ViewIndicator.java

@SuppressLint("DrawAllocation")
@Override//ww w  .ja  va 2 s. c om
protected void onDraw(Canvas canvas) {
    super.onDraw(canvas);

    Paint paint = new Paint();
    paint.setStrokeWidth(1);
    paint.setStrokeCap(Paint.Cap.ROUND);
    paint.setColor(Color.BLACK);
    paint.setAntiAlias(true);

    for (int i = 0; i < mNumOfViews; i++) {
        float cx = (getWidth() - (mNumOfViews - 1) * DISTANCE) / 2 + i * DISTANCE;
        float cy = getHeight() / 2.0f;
        if (mPosition == i) {
            paint.setStyle(Paint.Style.FILL_AND_STROKE);
        } else {
            paint.setStyle(Paint.Style.STROKE);
        }
        canvas.drawCircle(cx, cy, RADIUS, paint);
    }
}

From source file:org.jraf.android.piclabel.app.form.FormActivity.java

private void drawText(Canvas canvas) {
    Paint paint = new Paint();
    paint.setStyle(Paint.Style.FILL);
    paint.setAntiAlias(true);/* w ww. j a v  a2  s  .c o m*/
    paint.setTypeface(Typeface.createFromAsset(getAssets(), "fonts/" + getSelectedFontName()));

    int textSize = canvas.getHeight() / 35;
    paint.setTextSize(textSize);
    int margin = textSize / 5;

    // Measure date/time
    String dateTime = mEdtDateTime.getText().toString();
    Rect boundsDateTime = new Rect();
    paint.getTextBounds(dateTime, 0, dateTime.length(), boundsDateTime);

    // Measure location
    String location = mEdtLocation.getText().toString();
    Rect boundsLocation = new Rect();
    paint.getTextBounds(location, 0, location.length(), boundsLocation);

    int totalWidth = boundsDateTime.width() + textSize * 2 + boundsLocation.width();
    if (totalWidth > canvas.getWidth()) {
        // Draw on 2 lines

        // Draw a rectangle
        paint.setColor(Color.argb(180, 0, 0, 0));
        canvas.drawRect(0, 0, canvas.getWidth(), -boundsDateTime.top + boundsDateTime.bottom
                + -boundsLocation.top + boundsLocation.bottom + margin * 3, paint);

        // Draw date/time
        paint.setColor(Color.WHITE);
        canvas.drawText(dateTime, margin, margin + -boundsDateTime.top, paint);

        // Draw location
        canvas.drawText(location, canvas.getWidth() - boundsLocation.right - boundsLocation.left - margin,
                margin + -boundsDateTime.top + boundsDateTime.bottom + margin + -boundsLocation.top, paint);

    } else {
        // Draw on 1 line

        // Draw a rectangle
        paint.setColor(Color.argb(180, 0, 0, 0));
        canvas.drawRect(0, 0, canvas.getWidth(),
                margin + Math.max(boundsDateTime.height(), boundsLocation.height()) + margin, paint);

        // Draw date/time
        paint.setColor(Color.WHITE);
        canvas.drawText(dateTime, margin, margin + -boundsDateTime.top, paint);

        // Draw location
        canvas.drawText(location, canvas.getWidth() - boundsLocation.right - boundsLocation.left - margin,
                margin + -boundsLocation.top, paint);
    }
}

From source file:com.snippet.widget.ViewIndicator.java

@SuppressLint("DrawAllocation")
@Override//from w ww  .java  2  s  . co m
protected void onDraw(Canvas canvas) {
    super.onDraw(canvas);

    Paint paint = new Paint();
    paint.setStrokeWidth(1);
    paint.setStrokeCap(Paint.Cap.ROUND);
    paint.setColor(Color.BLACK);
    paint.setAntiAlias(true);

    for (int i = 0; i < mNumOfViews; i++) {
        float cx = (getWidth() - (mNumOfViews - 1) * mDistance) / 2 + i * mDistance;
        float cy = getHeight() / 2.0f;
        if (mPosition == i) {
            paint.setStyle(Paint.Style.FILL_AND_STROKE);
        } else {
            paint.setStyle(Paint.Style.STROKE);
        }
        canvas.drawCircle(cx, cy, mRadius, paint);
    }
}

From source file:com.nextgis.maplibui.fragment.ReorderedLayerView.java

/**
 * Returns a bitmap showing a screenshot of the view passed in.
 *///from w w w. j  a  v a2 s. co  m
protected Bitmap getBitmapFromView(View v) {
    Bitmap bitmap = Bitmap.createBitmap(v.getWidth(), v.getHeight(), Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(bitmap);

    Paint paint = new Paint();
    paint.setStyle(Paint.Style.FILL);
    paint.setColor(getResources().getColor(R.color.background_floating_material_light));
    Rect rect = new Rect(0, 0, v.getWidth(), v.getHeight());
    canvas.drawRect(rect, paint);

    v.draw(canvas);
    return bitmap;
}

From source file:com.nextgis.maplibui.fragment.ReorderedLayerView.java

/**
 * Draws a black border over the screenshot of the view passed in.
 *//* ww  w. j a  v  a  2  s  .  c o m*/
protected Bitmap getBitmapWithBorder(View v) {
    Bitmap bitmap = getBitmapFromView(v);
    Canvas canvas = new Canvas(bitmap);

    Rect rect = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight());

    canvas.drawBitmap(bitmap, 0, 0, null);

    Paint paint = new Paint();
    paint.setStyle(Paint.Style.STROKE);
    paint.setStrokeWidth(LINE_THICKNESS);

    int accentColor = ControlHelper.getColor(getContext(), R.attr.colorAccent);

    paint.setColor(accentColor);
    canvas.drawRect(rect, paint);

    return bitmap;
}

From source file:org.stockchart.core.Appearance.java

public void applyText(Paint p) {
    p.reset();/*from w  w w  .ja  v  a  2s . co  m*/
    p.setTextSize(fFont.getSize());
    p.setColor(fFont.getColor());
    p.setTypeface(fFont.getTypeface());
    p.setAntiAlias(fIsAntialias);
    p.setPathEffect(null);
    p.setStyle(Style.FILL);
}

From source file:com.binu.LogarithmicGraph.DrawGraphAsyncTask.java

@Override
protected Object doInBackground(Object[] params) {

    Bitmap bitmapBackground = Bitmap.createBitmap(mViewWidth, mViewHeight, Bitmap.Config.ARGB_8888);

    Canvas canvasBackground = new Canvas(bitmapBackground);
    Paint paint = new Paint();
    paint.setStrokeWidth(1f);//from   w w  w . j  a  va  2  s .  co m
    int starty = 0;
    int endy = mViewHeight;
    canvasBackground.drawColor(Color.BLACK);
    double ratio = Math.pow(Math.E, Math.log(MAX_FREQUENCY / MIN_FREQUENCY) / mViewWidth);
    mLogScaledX_values = new double[mViewWidth];
    for (int i = 0; i < mViewWidth; i++) {
        if (i == 0) {
            mLogScaledX_values[i] = 20;
        } else {
            mLogScaledX_values[i] = mLogScaledX_values[i - 1] * ratio;
        }
    }

    //Major lines
    for (int i = 0; i < MAJOR_GRIDLINE_POINTS.length; i++) {
        paint.setColor(ContextCompat.getColor(mContext, R.color.graph_grid_color));
        float xStart = (float) findNearestNumberPosition(mLogScaledX_values, MAJOR_GRIDLINE_POINTS[i]);
        float textSize = (getPixelDensity(mContext) * mLabelTextSize) / 480;
        paint.setTextSize(textSize);
        Log.i("Density", "" + getPixelDensity(mContext));
        if (Math.round(MAJOR_GRIDLINE_POINTS[i]) == 20) {
            if (isShowLabels())
                canvasBackground.drawText(getFormattedLabel(MAJOR_GRIDLINE_POINTS[i]),
                        xStart + (getPixelDensity(mContext) * 10) / 480,
                        endy - (getPixelDensity(mContext) * 10) / 480, paint);
        } else if (Math.round(MAJOR_GRIDLINE_POINTS[i]) == 20000) {
            if (isShowLabels())
                canvasBackground.drawText(getFormattedLabel(MAJOR_GRIDLINE_POINTS[i]),
                        xStart - (getPixelDensity(mContext) * 70) / 480,
                        endy - (getPixelDensity(mContext) * 10) / 480, paint);
        } else {
            if (isShowLabels())
                canvasBackground.drawText(getFormattedLabel(MAJOR_GRIDLINE_POINTS[i]),
                        xStart - (getPixelDensity(mContext) * 30) / 480,
                        endy - (getPixelDensity(mContext) * 10) / 480, paint);
            canvasBackground.drawLine(xStart, starty, xStart + 1, endy, paint);
        }
    }

    //Minor lines
    for (int i = 0; i < MINOR_GRIDLINE_POINTS.length; i++) {
        paint.setColor(ContextCompat.getColor(mContext, R.color.graph_grid_color_dull));
        float xStart = (float) findNearestNumberPosition(mLogScaledX_values, MINOR_GRIDLINE_POINTS[i]);
        canvasBackground.drawLine(xStart, starty, xStart + 1, endy, paint);

        if (isShowLabels()) {
            paint.setColor(ContextCompat.getColor(mContext, R.color.graph_grid_color));
            if (MINOR_GRIDLINE_POINTS[i] == 50 || MINOR_GRIDLINE_POINTS[i] == 500
                    || MINOR_GRIDLINE_POINTS[i] == 5000)
                canvasBackground.drawText(getFormattedLabel(MINOR_GRIDLINE_POINTS[i]),
                        xStart - (getPixelDensity(mContext) * 30) / 480,
                        endy - (getPixelDensity(mContext) * 10) / 480, paint);
        }
    }

    float[] Y_points = calculateGraphYAxis();
    float div = mViewHeight / (Y_points.length - 1);
    //Level lines
    for (int i = 0; i < Y_points.length - 1; i++) {
        paint.setColor(ContextCompat.getColor(mContext, R.color.graph_grid_color_dull));
        canvasBackground.drawLine(0, div * (i + 1), mViewWidth, (div * (i + 1)) + 1, paint);
    }

    //Level labels
    if (isShowLabels()) {
        for (int i = 0; i < Y_points.length; i++) {
            paint.setColor(ContextCompat.getColor(mContext, R.color.graph_grid_color));
            if (i == 0)
                canvasBackground.drawText("dB", 0, (div * i) + (getPixelDensity(mContext) * 50) / 480, paint);
            else if (i == Y_points.length - 1)
                canvasBackground.drawText("", 0, div * i, paint);
            else
                canvasBackground.drawText("" + Math.round(Y_points[i]), 0, div * i, paint);
        }
    }

    BitmapDrawable drawable = new BitmapDrawable(mContext.getResources(), bitmapBackground);
    mDrawableBackground = drawable;

    //Plotting the curve points

    Bitmap bitmapForeground = Bitmap.createBitmap(mViewWidth, mViewHeight, Bitmap.Config.ARGB_8888);
    Canvas canvasForeground = new Canvas(bitmapForeground);
    Paint plotPaint = new Paint();
    plotPaint.setStyle(Paint.Style.STROKE);
    plotPaint.setStrokeCap(Paint.Cap.ROUND);
    plotPaint.setStrokeWidth(PLOT_THICKNESS);
    plotPaint.setAntiAlias(true);
    plotPaint.setColor(ContextCompat.getColor(mContext, R.color.graph_plot_color));

    for (int i = 0; i < X_values.length; i++) {
        //            canvasForeground.drawCircle(i, mViewHeight - mPlotPoint[i], 2f, plotPaint);
        /*float startX, float startY, float stopX, float stopY,
        @NonNull Paint paint*/
        float startX = (float) getGetPixelValueForX(X_values[i]);
        float startY = mViewHeight
                - getPixelValueFromdB((int) GAIN_MAX, (int) GAIN_MIN, mViewHeight, Y_values[i]);
        float stopX;
        float stopY;
        if (i == X_values.length - 1) {
            stopX = (float) getGetPixelValueForX(X_values[i]);
            stopY = mViewHeight - getPixelValueFromdB((int) GAIN_MAX, (int) GAIN_MIN, mViewHeight, Y_values[i]);
        } else {
            stopX = (float) getGetPixelValueForX(X_values[i + 1]);
            stopY = mViewHeight
                    - getPixelValueFromdB((int) GAIN_MAX, (int) GAIN_MIN, mViewHeight, Y_values[i + 1]);
        }

        canvasForeground.drawLine(startX, startY, stopX, stopY, plotPaint);

    }

    BitmapDrawable drawableFore = new BitmapDrawable(mContext.getResources(), bitmapForeground);
    mDrawableForeground = drawableFore;
    return null;
}

From source file:com.android.tabletcustomui.views.LeftCircleContainer.java

private void addCircle(int position, final int value, float diff, double ratio) {
    final int radius = value / 2;
    final RectF mOval = new RectF();
    mOval.set(0 + diff, 0 + diff, value - diff, value - diff);

    final Paint mPaintClip = new Paint();
    mPaintClip.setStyle(Paint.Style.FILL);
    mPaintClip.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.OVERLAY));
    mPaintClip.setAntiAlias(true);/*ww  w. j  a v  a 2  s. co  m*/

    final PointF pointF = new PointF(mOval.centerX(), mOval.centerY());
    final Path clipPath = new Path();
    clipPath.addCircle(pointF.x, pointF.y, (float) (radius * ratio), Path.Direction.CW);

    View circleView;
    if (position == 0) {
        mPaintClip.setColor(getContext().getResources().getColor(R.color.circle_light_blue));
        circleView = new View(getContext()) {

            @Override
            protected void onDraw(Canvas canvas) {
                super.onDraw(canvas);

                canvas.clipPath(clipPath, Region.Op.DIFFERENCE);

                canvas.drawArc(mOval, 330, 10, true, mPaintClip);
                canvas.drawArc(mOval, 342, 20, true, mPaintClip);
                canvas.drawArc(mOval, 4, 10, true, mPaintClip);

                canvas.drawArc(mOval, 240, 10, true, mPaintClip);
                canvas.drawArc(mOval, 252, 20, true, mPaintClip);
                canvas.drawArc(mOval, 275, 10, true, mPaintClip);

                canvas.drawArc(mOval, 150, 10, true, mPaintClip);
                canvas.drawArc(mOval, 162, 20, true, mPaintClip);
                canvas.drawArc(mOval, 185, 10, true, mPaintClip);

                canvas.drawArc(mOval, 60, 10, true, mPaintClip);
                canvas.drawArc(mOval, 72, 20, true, mPaintClip);
                canvas.drawArc(mOval, 95, 10, true, mPaintClip);
            }
        };

        FrameLayout.LayoutParams layoutParams = new FrameLayout.LayoutParams(value, value);
        layoutParams.gravity = Gravity.CENTER_VERTICAL | Gravity.CENTER_HORIZONTAL;
        circleView.setLayoutParams(layoutParams);

        this.addView(circleView);

        animateClockWise(circleView);

    } else if (position == 1) {

        mPaintClip.setColor(getContext().getResources().getColor(R.color.circle_dark_blue));
        circleView = new View(getContext()) {

            @Override
            protected void onDraw(Canvas canvas) {
                super.onDraw(canvas);

                canvas.clipPath(clipPath, Region.Op.DIFFERENCE);

                canvas.drawCircle(pointF.x, pointF.y, radius, mPaintClip);
            }
        };

        FrameLayout.LayoutParams layoutParams = new FrameLayout.LayoutParams(value, value);
        layoutParams.gravity = Gravity.CENTER_VERTICAL | Gravity.CENTER_HORIZONTAL;
        circleView.setLayoutParams(layoutParams);

        this.addView(circleView);
        animateClockWise(circleView);

    } else if (position == 2) {

        mPaintClip.setColor(getContext().getResources().getColor(R.color.circle_light_blue));
        circleView = new View(getContext()) {

            @Override
            protected void onDraw(Canvas canvas) {
                super.onDraw(canvas);

                canvas.clipPath(clipPath, Region.Op.DIFFERENCE);

                canvas.drawArc(mOval, 55, 190, true, mPaintClip);

            }
        };

        FrameLayout.LayoutParams layoutParams = new FrameLayout.LayoutParams(value, value);
        layoutParams.gravity = Gravity.CENTER_VERTICAL | Gravity.CENTER_HORIZONTAL;
        circleView.setLayoutParams(layoutParams);

        this.addView(circleView);
        animateClockWise(circleView);

    } else if (position == 3) {
        mPaintClip.setColor(getContext().getResources().getColor(R.color.circle_light_blue));
        circleView = new View(getContext()) {

            @Override
            protected void onDraw(Canvas canvas) {
                super.onDraw(canvas);

                canvas.clipPath(clipPath, Region.Op.DIFFERENCE);

                canvas.drawArc(mOval, 240, 190, true, mPaintClip);
                canvas.drawArc(mOval, 80, 150, true, mPaintClip);
            }
        };

        FrameLayout.LayoutParams layoutParams = new FrameLayout.LayoutParams(value, value);
        layoutParams.gravity = Gravity.CENTER_VERTICAL | Gravity.CENTER_HORIZONTAL;
        circleView.setLayoutParams(layoutParams);

        this.addView(circleView);
        animateClockWise(circleView);

    } else if (position == 4) {
        mPaintClip.setColor(getContext().getResources().getColor(R.color.circle_light_blue));
        circleView = new View(getContext()) {

            @Override
            protected void onDraw(Canvas canvas) {
                super.onDraw(canvas);

                canvas.clipPath(clipPath, Region.Op.DIFFERENCE);

                canvas.drawArc(mOval, 335, 150, true, mPaintClip);
                canvas.drawArc(mOval, 140, 180, true, mPaintClip);
            }
        };

        FrameLayout.LayoutParams layoutParams = new FrameLayout.LayoutParams(value, value);
        layoutParams.gravity = Gravity.CENTER_VERTICAL | Gravity.CENTER_HORIZONTAL;
        circleView.setLayoutParams(layoutParams);

        this.addView(circleView);
        animateClockWise(circleView);

    } else if (position == 5) {
        mPaintClip.setColor(getContext().getResources().getColor(R.color.circle_light_grey));
        circleView = new View(getContext()) {

            @Override
            protected void onDraw(Canvas canvas) {
                super.onDraw(canvas);

                canvas.clipPath(clipPath, Region.Op.DIFFERENCE);

                canvas.drawArc(mOval, 330, 150, true, mPaintClip);
                canvas.drawArc(mOval, 140, 150, true, mPaintClip);
            }
        };

        FrameLayout.LayoutParams layoutParams = new FrameLayout.LayoutParams(value, value);
        layoutParams.gravity = Gravity.CENTER_VERTICAL | Gravity.CENTER_HORIZONTAL;
        circleView.setLayoutParams(layoutParams);

        this.addView(circleView);
        animateClockWise(circleView);

    } else if (position == 6) {
        mPaintClip.setColor(getContext().getResources().getColor(R.color.circle_purple_color));
        circleView = new View(getContext()) {

            @Override
            protected void onDraw(Canvas canvas) {
                super.onDraw(canvas);

                canvas.clipPath(clipPath, Region.Op.DIFFERENCE);

                canvas.drawArc(mOval, 290, 5, true, mPaintClip);
                canvas.drawArc(mOval, 297, 20, true, mPaintClip);
                canvas.drawArc(mOval, 319, 20, true, mPaintClip);

                canvas.drawArc(mOval, 60, 15, true, mPaintClip);
                canvas.drawArc(mOval, 77, 8, true, mPaintClip);

            }
        };

        FrameLayout.LayoutParams layoutParams = new FrameLayout.LayoutParams(value, value);
        layoutParams.gravity = Gravity.CENTER_VERTICAL | Gravity.CENTER_HORIZONTAL;
        circleView.setLayoutParams(layoutParams);

        this.addView(circleView);

        animateClockWise(circleView);

    } else if (position == 7) {
        mPaintClip.setColor(getContext().getResources().getColor(R.color.circle_dark_blue));
        circleView = new View(getContext()) {

            @Override
            protected void onDraw(Canvas canvas) {
                super.onDraw(canvas);

                canvas.clipPath(clipPath, Region.Op.DIFFERENCE);

                canvas.drawArc(mOval, 160, 10, true, mPaintClip);
                canvas.drawArc(mOval, 172, 30, true, mPaintClip);
                canvas.drawArc(mOval, 204, 30, true, mPaintClip);
                canvas.drawArc(mOval, 236, 10, true, mPaintClip);

                canvas.drawArc(mOval, 20, 20, true, mPaintClip);
                canvas.drawArc(mOval, 42, 8, true, mPaintClip);

            }
        };

        FrameLayout.LayoutParams layoutParams = new FrameLayout.LayoutParams(value, value);
        layoutParams.gravity = Gravity.CENTER_VERTICAL | Gravity.CENTER_HORIZONTAL;
        circleView.setLayoutParams(layoutParams);

        this.addView(circleView);
        animateAntiClockWise(circleView);
    }
}

From source file:com.richtodd.android.quiltdesign.block.PaperPiecedBlockPiece.java

private Paint createShadowPaint(int left, int top, int width, int height, int shadowStrokeWidth) {
    List<PointF> points = getPoints(width, height);
    PointF fromPoint = new PointF(left + points.get(0).x, top + points.get(0).y);
    PointF toPoint = new PointF(left + points.get(1).x, top + points.get(1).y);

    PointF midpoint = new PointF((fromPoint.x + toPoint.x) * 0.5f, (fromPoint.y + toPoint.y) * 0.5f);

    PointF vector = new PointF(fromPoint.x - midpoint.x, fromPoint.y - midpoint.y);

    PointF rotatedVector = new PointF(vector.y, -vector.x);

    float vectorLength = (float) Math.sqrt((vector.x * vector.x) + (vector.y * vector.y));

    PointF shadowVector = new PointF(rotatedVector.x * (shadowStrokeWidth * 0.5f) / vectorLength,
            rotatedVector.y * (shadowStrokeWidth * 0.5f) / vectorLength);

    LinearGradient gradient = new LinearGradient(midpoint.x, midpoint.y, midpoint.x + shadowVector.x,
            midpoint.y + shadowVector.y, Color.argb(100, 0, 0, 0), Color.argb(0, 0, 0, 0), TileMode.MIRROR);

    Paint paint = new Paint();
    paint.setStyle(Style.STROKE);
    paint.setShader(gradient);//from w ww .jav a2 s  .  com
    paint.setStrokeWidth(shadowStrokeWidth);
    paint.setStrokeCap(Cap.SQUARE);

    return paint;
}

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.
 */// w  ww. j  ava2s  .  c  om
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;
}