Example usage for android.graphics Canvas drawCircle

List of usage examples for android.graphics Canvas drawCircle

Introduction

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

Prototype

public void drawCircle(float cx, float cy, float radius, @NonNull Paint paint) 

Source Link

Document

Draw the specified circle using the specified paint.

Usage

From source file:org.adw.library.widgets.discreteseekbar.internal.drawable.AlmostRippleDrawable.java

@Override
public void doDraw(Canvas canvas, Paint paint) {
    Rect bounds = getBounds();/*from w w w . jav a 2  s  .  co  m*/
    int size = Math.min(bounds.width(), bounds.height());
    float scale = mCurrentScale;
    int rippleColor = mRippleColor;
    int bgColor = mRippleBgColor;
    float radius = (size / 2);
    float radiusAnimated = radius * scale;
    if (scale > INACTIVE_SCALE) {
        if (bgColor != 0) {
            paint.setColor(bgColor);
            paint.setAlpha(decreasedAlpha(Color.alpha(bgColor)));
            canvas.drawCircle(bounds.centerX(), bounds.centerY(), radius, paint);
        }
        if (rippleColor != 0) {
            paint.setColor(rippleColor);
            paint.setAlpha(modulateAlpha(Color.alpha(rippleColor)));
            canvas.drawCircle(bounds.centerX(), bounds.centerY(), radiusAnimated, paint);
        }
    }
}

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

@SuppressLint("DrawAllocation")
@Override//  w ww. j ava2  s . c o 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) * 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:com.snippet.widget.ViewIndicator.java

@SuppressLint("DrawAllocation")
@Override//from   w  w  w .  j  a  va2  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) * 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.abhinavjhanwar.android.egg.neko.Cat.java

public Bitmap createLargeBitmap(Context context) {
    final Resources res = context.getResources();
    final int w = res.getDimensionPixelSize(android.R.dimen.notification_large_icon_width);
    final int h = res.getDimensionPixelSize(android.R.dimen.notification_large_icon_height);

    Bitmap result = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888);
    final Canvas canvas = new Canvas(result);
    final Paint pt = new Paint();
    float[] hsv = new float[3];
    Color.colorToHSV(mBodyColor, hsv);
    hsv[2] = (hsv[2] > 0.5f) ? (hsv[2] - 0.25f) : (hsv[2] + 0.25f);
    pt.setColor(Color.HSVToColor(hsv));
    pt.setFlags(Paint.ANTI_ALIAS_FLAG);
    float r = w / 2;
    canvas.drawCircle(r, r, r, pt);
    int m = w / 10;

    slowDraw(canvas, m, m, w - m - m, h - m - m);

    return result;
}

From source file:com.mianamiana.library.LiquidBallProgressBar.java

private void drawLiqiud(Canvas canvas) {
    float radius = getWidth() / 2.0f;
    float cx = getWidth() / 2.0f;
    float cy = getHeight() / 2.0f;

    if (mIsRunAnimation) {
        mWaveShaderMatrix.setTranslate(mWaveTranslationX, mWaveOffsetY + mWaveTranslationY);
        mWaveShader.setLocalMatrix(mWaveShaderMatrix);
    }/*  ww  w  .j  av  a 2 s.c  om*/
    if (mBorderWidth != 0) {
        canvas.drawCircle(cx, cy, radius, mBorderPaint);
        canvas.drawCircle(cx, cy, radius - mBorderWidth, mWavePaint);
    } else {
        canvas.drawCircle(cx, cy, radius, mWavePaint);
    }

}

From source file:com.andremion.counterfab.CounterFab.java

@Override
protected void onDraw(Canvas canvas) {
    super.onDraw(canvas);
    if (mCount > 0 || isAnimating()) {
        if (getContentRect(mContentBounds)) {
            mCircleBounds.offsetTo(mContentBounds.left + mContentBounds.width() - mCircleBounds.width(),
                    mContentBounds.top);
        }/*from   ww  w .j a  v  a  2 s .c o m*/
        float cx = mCircleBounds.centerX();
        float cy = mCircleBounds.centerY();
        float radius = mCircleBounds.width() / 2f * mAnimationFactor;
        // Solid circle
        canvas.drawCircle(cx, cy, radius, mCirclePaint);
        // Mask circle
        canvas.drawCircle(cx, cy, radius, mMaskPaint);
        // Count text
        mTextPaint.setTextSize(mTextSize * mAnimationFactor);
        canvas.drawText(mText, cx, cy + mTextHeight / 2f, mTextPaint);
    }
}

From source file:com.byagowi.persiancalendar.view.QiblaCompassView.java

public void drawSun(Canvas canvas) {
    sunPaint.reset();//from   w ww.  j  a  v  a2s.c om
    sunPaint.setColor(Color.YELLOW);
    sunPaint.setStyle(Paint.Style.FILL_AND_STROKE);
    // Horizontal sunPosition = new Horizontal(225, 45);

    if (sunPosition.getElevation() > -10) {
        canvas.rotate((float) sunPosition.getAzimuth() - 360, px, py);
        sunPaint.setPathEffect(dashPath);

        int ry = (int) (((90 - sunPosition.getElevation()) / 90) * Radius);
        canvas.drawCircle(px, py - ry, r, sunPaint);
        dashedPaint.setColor(Color.YELLOW);
        canvas.drawLine(px, py - Radius, px, py + Radius, dashedPaint);
        sunPaint.setPathEffect(null);
        canvas.restore();
    }

}

From source file:com.github.pockethub.android.ui.view.DotPageIndicator.java

/**
 * Draw the selected dot and when it moves
 *
 * @param canvas The canvas to draw on//from ww  w. ja v  a2  s  . c om
 */

private void drawSelectedDot(Canvas canvas) {
    float distance = (dotRadius * 2 + dotSpacing) * amount;

    float fromPosX = getDotCenterX(currentPos);
    float fromPosY = getDotCenterY(currentPos);

    float toPosX = getDotCenterX(nextPos);
    float toPosY = getDotCenterY(nextPos);

    if (toPosY != fromPosY) {
        PAINT_SELECTED.setAlpha(Math.round(dotAlpha * amount));
        canvas.drawCircle(toPosX - ((dotRadius * 2 + dotSpacing) - distance), toPosY, dotRadius,
                PAINT_SELECTED);
        PAINT_SELECTED.setAlpha(Math.round(dotAlpha * (1 - amount)));
    }

    canvas.drawCircle(fromPosX + distance, fromPosY, dotRadius, PAINT_SELECTED);
    PAINT_SELECTED.setAlpha(dotAlpha);
}

From source file:com.android.andryyu.lifehelper.widget.RippleView.java

private Bitmap getCircleBitmap(final int radius) {
    final Bitmap output = Bitmap.createBitmap(originBitmap.getWidth(), originBitmap.getHeight(),
            Bitmap.Config.ARGB_8888);/*from w ww. jav a 2s  . c  o m*/
    final Canvas canvas = new Canvas(output);
    final Paint paint = new Paint();
    final Rect rect = new Rect((int) (x - radius), (int) (y - radius), (int) (x + radius), (int) (y + radius));

    paint.setAntiAlias(true);
    canvas.drawARGB(0, 0, 0, 0);
    canvas.drawCircle(x, y, radius, paint);

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

    return output;
}

From source file:com.codetroopers.shakemytours.ui.activity.TripActivity.java

private Bitmap createMarker(int radius, int strokeWidth, String letter, int strokeColor, int backgroundColor) {
    int width = (radius * 2) + (strokeWidth * 2);
    Bitmap marker = Bitmap.createBitmap(width, width, Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(marker);

    Paint strokePaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    strokePaint.setColor(strokeColor);/*from  w  w w. jav  a  2s .  c o  m*/
    strokePaint.setShadowLayer(strokeWidth, 1.0f, 1.0f, Color.BLACK);
    canvas.drawCircle(width / 2, width / 2, radius, strokePaint);

    Paint backgroundPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    backgroundPaint.setColor(backgroundColor);
    canvas.drawCircle(width / 2, width / 2, radius - strokeWidth, backgroundPaint);

    if (letter != null) {
        Rect result = new Rect();
        Paint textPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
        textPaint.setTextAlign(Paint.Align.CENTER);
        textPaint.setTextSize(getResources().getDimensionPixelSize(R.dimen.map_marker_text_size));
        textPaint.setColor(strokeColor);
        textPaint.getTextBounds(letter, 0, letter.length(), result);
        int yOffset = result.height() / 2;

        canvas.drawText(letter, width / 2, (width / 2) + yOffset, textPaint);
    }
    return marker;
}