Example usage for android.graphics Canvas drawOval

List of usage examples for android.graphics Canvas drawOval

Introduction

In this page you can find the example usage for android.graphics Canvas drawOval.

Prototype

public void drawOval(@NonNull RectF oval, @NonNull Paint paint) 

Source Link

Document

Draw the specified oval using the specified paint.

Usage

From source file:com.linute.linute.API.MyGcmListenerService.java

private static Bitmap getCircleBitmap(Bitmap bitmap) {
    //returns square image for older phones that prefer square notifs
    /*if(Build.VERSION.SDK_INT <= Build.VERSION_CODES.KITKAT){
    return bitmap;//from   ww w.  j  a  va2s.  c o m
    }*/
    final Bitmap output = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), Bitmap.Config.ARGB_8888);
    final Canvas canvas = new Canvas(output);

    final int color = Color.RED;
    final Paint paint = new Paint();
    final Rect rect = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight());
    final RectF rectF = new RectF(rect);

    paint.setAntiAlias(true);
    canvas.drawARGB(0, 0, 0, 0);
    paint.setColor(color);
    canvas.drawOval(rectF, paint);

    paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));
    canvas.drawBitmap(bitmap, rect, rect, paint);

    bitmap.recycle();

    return output;
}

From source file:Main.java

public static Bitmap getCircleBitmap(Bitmap bitmap) {
    final Bitmap output = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), Bitmap.Config.ARGB_8888);
    final Canvas canvas = new Canvas(output);

    final int color = Color.RED;
    final Paint paint = new Paint();
    final Rect rect = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight());
    final RectF rectF = new RectF(rect);
    //final Paint paintBorder = new Paint();
    // paintBorder.setColor(Color.GREEN);
    //paintBorder.setShadowLayer(4.0f, 0.0f, 2.0f, Color.BLACK);
    //BitmapShader shader = new BitmapShader(Bitmap.createScaledBitmap(output, canvas.getWidth(), canvas.getHeight(), false), Shader.TileMode.CLAMP, Shader.TileMode.CLAMP);
    //paint.setShader(shader);
    paint.setAntiAlias(true);//from  ww  w.ja va  2s .c o  m
    //paintBorder.setAntiAlias(true);
    canvas.drawARGB(0, 0, 0, 0);
    paint.setColor(color);
    canvas.drawOval(rectF, paint);
    //int circleCenter = bitmap.getWidth() / 2;
    //int borderWidth = 2;
    //canvas.drawCircle(circleCenter + borderWidth, circleCenter + borderWidth, circleCenter + borderWidth - 4.0f, paintBorder);
    //canvas.drawCircle(circleCenter + borderWidth, circleCenter + borderWidth, circleCenter - 4.0f, paint);

    paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));
    canvas.drawBitmap(bitmap, rect, rect, paint);
    //canvas.drawBitmap(bitmap, circleCenter + borderWidth, circleCenter + borderWidth, paint);
    bitmap.recycle();
    return output;
}

From source file:nu.yona.app.utils.AppUtils.java

/**
 * Gets circle bitmap./*from  ww w . j a  v  a  2s .  co  m*/
 *
 * @param bitmap the bitmap
 * @return the circle bitmap
 */
public static Bitmap getCircleBitmap(Bitmap bitmap) {
    final Bitmap output = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), Bitmap.Config.ARGB_8888);
    final Canvas canvas = new Canvas(output);

    final int color = Color.BLUE;
    final Paint paint = new Paint();
    final Rect rect = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight());
    final RectF rectF = new RectF(rect);

    paint.setAntiAlias(true);
    canvas.drawARGB(0, 0, 0, 0);
    paint.setColor(color);
    canvas.drawOval(rectF, paint);

    paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));
    canvas.drawBitmap(bitmap, rect, rect, paint);

    bitmap.recycle();

    return output;
}

From source file:cn.finalteam.galleryfinal.widget.FloatingActionButton.java

private Drawable createCircleDrawable(RectF circleRect, int color) {
    final Bitmap bitmap = Bitmap.createBitmap(mDrawableSize, mDrawableSize, Config.ARGB_8888);
    final Canvas canvas = new Canvas(bitmap);

    final Paint paint = new Paint();
    paint.setAntiAlias(true);//from   ww w  .ja  v a 2  s.  c om
    paint.setColor(color);

    canvas.drawOval(circleRect, paint);

    return new BitmapDrawable(getResources(), bitmap);
}

From source file:id.satusatudua.sigap.ui.fragment.GuardingLocationFragment.java

private Bitmap getCircleBitmap(Bitmap bitmap) {
    final Bitmap output = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), Bitmap.Config.ARGB_8888);
    final Canvas canvas = new Canvas(output);

    final int color = Color.RED;
    final Paint paint = new Paint();
    final Rect rect = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight());
    final RectF rectF = new RectF(rect);

    paint.setAntiAlias(true);//  w  ww  .  j  av  a  2  s . c o m
    canvas.drawARGB(0, 0, 0, 0);
    paint.setColor(color);
    canvas.drawOval(rectF, paint);

    paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));
    canvas.drawBitmap(bitmap, rect, rect, paint);

    bitmap.recycle();

    return output;
}

From source file:net.networksaremadeofstring.rhybudd.RhybuddDock.java

private void DrawEvents() {
    Bitmap charty = Bitmap.createBitmap(200, 200, Bitmap.Config.ARGB_8888);
    Canvas EventsCanvas = new Canvas(charty);
    final Paint paint = new Paint();

    paint.setStyle(Paint.Style.FILL);
    paint.setColor(getResources().getColor(R.color.DarkBlue));
    paint.setAntiAlias(true);/*from   w ww.java2 s  . c  o  m*/
    EventsCanvas.drawOval(new RectF(1, 1, 199, 199), paint);

    RadialGradient gradient = new RadialGradient(200, 200, 200, 0xFF6b7681, 0xFF000000,
            android.graphics.Shader.TileMode.CLAMP);
    paint.setDither(true);
    paint.setShader(gradient);
    EventsCanvas.drawOval(new RectF(6, 6, 194, 194), paint);

    //Special Bits
    int Scale = 100;

    if (EventCount > 100)
        ;
    Scale = EventCount + 50;

    drawScale(EventsCanvas, true, EventCount, Scale);
    drawGaugeTitle(EventsCanvas, "Events Count");
    drawGaugeNeedle(EventsCanvas, EventCount, Scale);
    //drawGloss(EventsCanvas);

    ((ImageView) findViewById(R.id.EventsGauge)).setImageBitmap(charty);
}

From source file:net.networksaremadeofstring.rhybudd.RhybuddDock.java

private void DrawDevices() {
    Bitmap charty = Bitmap.createBitmap(200, 200, Bitmap.Config.ARGB_8888);
    Canvas DeviceCanvas = new Canvas(charty);
    final Paint paint = new Paint();

    paint.setStyle(Paint.Style.FILL);
    paint.setColor(getResources().getColor(R.color.DarkBlue));
    paint.setAntiAlias(true);//  ww w . j  a  va 2s.  co m
    DeviceCanvas.drawOval(new RectF(1, 1, 199, 199), paint);

    RadialGradient gradient = new RadialGradient(100, 50, 150, 0xFF6b7681, 0xFF000000,
            android.graphics.Shader.TileMode.CLAMP);
    paint.setDither(true);
    paint.setShader(gradient);
    DeviceCanvas.drawOval(new RectF(6, 6, 194, 194), paint);

    int Scale = 10;

    //Special Bits
    if (DeviceCount < 500)
        Scale = 750;

    if (DeviceCount < 250)
        Scale = 350;

    if (DeviceCount < 100)
        Scale = 150;

    if (DeviceCount < 50)
        Scale = 50;
    try {
        drawScale(DeviceCanvas, false, DeviceCount, Scale);
        drawGaugeTitle(DeviceCanvas, "Device Count");
        drawGaugeNeedle(DeviceCanvas, DeviceCount, Scale);
        //drawGloss(EventsCanvas);
        ((ImageView) findViewById(R.id.DeviceGauge)).setImageBitmap(charty);
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:de.vanita5.twittnuker.view.ShapedImageView.java

@Override
protected void onDraw(@NonNull Canvas canvas) {

    mDestination.set(getPaddingLeft(), getPaddingTop(), getWidth() - getPaddingRight(),
            getHeight() - getPaddingBottom());

    if (getStyle() == SHAPE_CIRCLE) {
        canvas.drawOval(mDestination, mBackgroundPaint);
    } else {/* w  w  w.  j a  v  a 2  s.co m*/
        final float radius = getCalculatedCornerRadius();
        canvas.drawRoundRect(mDestination, radius, radius, mBackgroundPaint);
    }

    if (OUTLINE_DRAW) {
        super.onDraw(canvas);
    } else {
        final int contentLeft = getPaddingLeft(), contentTop = getPaddingTop(),
                contentRight = getWidth() - getPaddingRight(), contentBottom = getHeight() - getPaddingBottom();
        final int contentWidth = contentRight - contentLeft, contentHeight = contentBottom - contentTop;
        final int size = Math.min(contentWidth, contentHeight);
        if (mShadowBitmap != null) {
            canvas.drawBitmap(mShadowBitmap, contentLeft + (contentWidth - size) / 2 - mShadowRadius,
                    contentTop + (contentHeight - size) / 2 - mShadowRadius, null);
        }
        Drawable drawable = getDrawable();
        BitmapDrawable bitmapDrawable = null;
        // support state list drawable by getting the current state
        if (drawable instanceof StateListDrawable) {
            if (drawable.getCurrent() != null) {
                bitmapDrawable = (BitmapDrawable) drawable.getCurrent();
            }
        } else if (drawable instanceof BitmapDrawable) {
            bitmapDrawable = (BitmapDrawable) drawable;
        } else if (drawable instanceof ColorDrawable) {
            mSolidColorPaint.setColor(((ColorDrawable) drawable).getColor());
        } else {
            mSolidColorPaint.setColor(0);
        }

        Bitmap bitmap = null;
        if (bitmapDrawable != null) {
            bitmap = bitmapDrawable.getBitmap();
        }
        if (bitmap != null) {
            mSource.set(0, 0, bitmap.getWidth(), bitmap.getHeight());
        }
        drawBitmapWithCircleOnCanvas(bitmap, canvas, mSource, mDestination);
    }

    // Then draw the border.
    if (mBorderEnabled) {
        drawBorder(canvas);
    }
}

From source file:com.keylesspalace.tusky.view.ProgressImageView.java

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

    float angle = (progress / 100f) * 360 - 90;
    float halfWidth = canvas.getWidth() / 2;
    float halfHeight = canvas.getHeight() / 2;
    progressRect.set(halfWidth * 0.75f, halfHeight * 0.75f, halfWidth * 1.25f, halfHeight * 1.25f);
    biggerRect.set(progressRect);/*from w  w w .  j av a  2 s.  co m*/
    int margin = 8;
    biggerRect.set(progressRect.left - margin, progressRect.top - margin, progressRect.right + margin,
            progressRect.bottom + margin);
    canvas.saveLayer(biggerRect, null, Canvas.ALL_SAVE_FLAG);
    if (progress != -1) {
        canvas.drawOval(progressRect, circlePaint);
        canvas.drawArc(biggerRect, angle, 360 - angle - 90, true, clearPaint);
    }
    canvas.restore();

    int circleRadius = Utils.dpToPx(getContext(), 14);
    int circleMargin = Utils.dpToPx(getContext(), 14);

    int circleY = canvas.getHeight() - circleMargin - circleRadius / 2;
    int circleX = canvas.getWidth() - circleMargin - circleRadius / 2;

    canvas.drawCircle(circleX, circleY, circleRadius, markBgPaint);

    captionDrawable.setBounds(canvas.getWidth() - circleMargin - circleRadius,
            canvas.getHeight() - circleMargin - circleRadius, canvas.getWidth() - circleMargin,
            canvas.getHeight() - circleMargin);
    DrawableCompat.setTint(captionDrawable, Color.WHITE);
    captionDrawable.draw(canvas);
}

From source file:org.getlantern.firetweet.view.ShapedImageView.java

@Override
protected void onDraw(@NonNull Canvas canvas) {
    mDestination.set(getPaddingLeft(), getPaddingTop(), getWidth() - getPaddingRight(),
            getHeight() - getPaddingBottom());

    if (getStyle() == SHAPE_CIRCLE) {
        canvas.drawOval(mDestination, mBackgroundPaint);
    } else {/*from ww w  .java  2s.  com*/
        final float radius = getCalculatedCornerRadius();
        canvas.drawRoundRect(mDestination, radius, radius, mBackgroundPaint);
    }

    if (OUTLINE_DRAW) {
        super.onDraw(canvas);
    } else {
        final int contentLeft = getPaddingLeft(), contentTop = getPaddingTop(),
                contentRight = getWidth() - getPaddingRight(), contentBottom = getHeight() - getPaddingBottom();
        final int contentWidth = contentRight - contentLeft, contentHeight = contentBottom - contentTop;
        final int size = Math.min(contentWidth, contentHeight);
        if (mShadowBitmap != null) {
            canvas.drawBitmap(mShadowBitmap, contentLeft + (contentWidth - size) / 2 - mShadowRadius,
                    contentTop + (contentHeight - size) / 2 - mShadowRadius, null);
        }
        Drawable drawable = getDrawable();
        BitmapDrawable bitmapDrawable = null;
        // support state list drawable by getting the current state
        if (drawable instanceof StateListDrawable) {
            if (drawable.getCurrent() != null) {
                bitmapDrawable = (BitmapDrawable) drawable.getCurrent();
            }
        } else if (drawable instanceof BitmapDrawable) {
            bitmapDrawable = (BitmapDrawable) drawable;
        } else if (drawable instanceof ColorDrawable) {
            mSolidColorPaint.setColor(((ColorDrawable) drawable).getColor());
        } else {
            mSolidColorPaint.setColor(0);
        }

        Bitmap bitmap = null;
        if (bitmapDrawable != null) {
            bitmap = bitmapDrawable.getBitmap();
        }
        if (bitmap != null) {
            mSource.set(0, 0, bitmap.getWidth(), bitmap.getHeight());
        }
        drawBitmapWithCircleOnCanvas(bitmap, canvas, mSource, mDestination);
    }

    // Then draw the border.
    if (mBorderEnabled) {
        drawBorder(canvas, mDestination);
    }
}