Example usage for android.graphics.drawable.shapes OvalShape resize

List of usage examples for android.graphics.drawable.shapes OvalShape resize

Introduction

In this page you can find the example usage for android.graphics.drawable.shapes OvalShape resize.

Prototype

public final void resize(float width, float height) 

Source Link

Document

Resizes the dimensions of this shape.

Usage

From source file:org.chromium.chrome.browser.download.DownloadNotificationService.java

private Bitmap getLargeNotificationIcon(Bitmap bitmap) {
    Resources resources = mContext.getResources();
    int height = (int) resources.getDimension(android.R.dimen.notification_large_icon_height);
    int width = (int) resources.getDimension(android.R.dimen.notification_large_icon_width);
    final OvalShape circle = new OvalShape();
    circle.resize(width, height);
    final Paint paint = new Paint();
    paint.setColor(ApiCompatibilityUtils.getColor(resources, R.color.google_blue_grey_500));

    final Bitmap result = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(result);
    circle.draw(canvas, paint);/*from w  ww .ja v a2s.  c o  m*/
    float leftOffset = (width - bitmap.getWidth()) / 2f;
    float topOffset = (height - bitmap.getHeight()) / 2f;
    if (leftOffset >= 0 && topOffset >= 0) {
        canvas.drawBitmap(bitmap, leftOffset, topOffset, null);
    } else {
        // Scale down the icon into the notification icon dimensions
        canvas.drawBitmap(bitmap, new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight()),
                new Rect(0, 0, width, height), null);
    }
    return result;
}