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:com.microsoft.mimickeralarm.onboarding.BubblePagerIndicator.java

@Override
protected void onDraw(Canvas canvas) {
    int width = canvas.getWidth();
    int height = canvas.getHeight();
    if (mTotalPositions == 0) {
        return;/*from www.j a va 2  s .c  o  m*/
    }
    mPaint.setAlpha(122);
    float buckets = (float) width / mTotalPositions;
    float radius = Math.min(buckets / 2f, height / 2f);
    for (int i = 0; i < mTotalPositions; i++) {
        canvas.drawCircle(i * buckets + buckets / 2f, height / 2f, radius, mPaint);
    }
    mPaint.setAlpha(255);
    canvas.drawCircle(mPosition * buckets + buckets / 2f, height / 2f, radius, mPaint);
}

From source file:com.hirebuddy.util.CircleImageView.java

@Override
protected void onDraw(Canvas canvas) {
    if (mBitmap == null) {
        return;//  w  ww .  ja v a2 s .c  om
    }

    if (mFillColor != Color.TRANSPARENT) {
        canvas.drawCircle(getWidth() / 2.0f, getHeight() / 2.0f, mDrawableRadius, mFillPaint);
    }
    canvas.drawCircle(getWidth() / 2.0f, getHeight() / 2.0f, mDrawableRadius, mBitmapPaint);
    if (mBorderWidth != 0) {
        canvas.drawCircle(getWidth() / 2.0f, getHeight() / 2.0f, mBorderRadius, mBorderPaint);
    }
}

From source file:com.reddyetwo.hashmypass.app.view.ViewPagerIndicator.java

@Override
protected void onDraw(Canvas canvas) {
    float y = mHeightOffset + mRadius;
    for (int i = 0; i < mNumberOfItems; i++) {
        float x = mWidthOffset + i * mSpacing + (1 + RADIUS_TO_DIAMETER_RATIO * i) * mRadius;
        int alpha = i == mPosition ? mCurrentPositionAlpha : mAlpha;
        mPaint.setAlpha(alpha);/*from   w  ww  . j  a  v a 2 s.  c o m*/
        canvas.drawCircle(x, y, mRadius, mPaint);
    }
}

From source file:com.lovejjfg.arsenal.ui.widget.JumpBall.java

@Override
protected void onDraw(Canvas canvas) {
    super.onDraw(canvas);
    if (!isEnd) {
        drawCirclePath(canvas);/*from   w  ww  . j a  v  a 2 s  .co m*/
    } else {
        canvas.drawCircle(mWidth / 2, mHeight / 2 + mTranslateValue, mCurrentRadio, mPaint);
    }
}

From source file:net.simno.dmach.ui.view.SettingView.java

@Override
protected void onDraw(Canvas canvas) {
    canvas.drawColor(backgroundColor);/*from   w w w.  j  a  va  2  s .  c  o  m*/
    if (!TextUtils.isEmpty(hText)) {
        canvas.drawText(hText, originX, originY, textPaint);
    }
    if (!TextUtils.isEmpty(vText)) {
        canvas.drawTextOnPath(vText, path, hOffset, vOffset, textPaint);
    }
    canvas.drawCircle(x, y, circleRadius, shapePaint);
}

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;/*  w  w  w  .  j a v  a 2  s  . com*/
        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:com.dlazaro66.wheelindicatorview.WheelIndicatorView.java

private void draw(WheelIndicatorItem indicatorItem, RectF surfaceRectF, float angle, Canvas canvas) {
    itemArcPaint.setColor(indicatorItem.getColor());
    itemEndPointsPaint.setColor(indicatorItem.getColor());
    // Draw arc//from  w  w w .  j a v  a2s. c om
    canvas.drawArc(surfaceRectF, ANGLE_INIT_OFFSET, angle, false, itemArcPaint);
    // Draw top circle
    canvas.drawCircle(minDistViewSize / 2, 0 + itemsLineWidth, itemsLineWidth, itemEndPointsPaint);
    int topPosition = minDistViewSize / 2 - itemsLineWidth;
    // Draw end circle
    canvas.drawCircle(
            (float) (Math.cos(Math.toRadians(angle + ANGLE_INIT_OFFSET)) * topPosition + topPosition
                    + itemsLineWidth),
            (float) (Math.sin(Math.toRadians((angle + ANGLE_INIT_OFFSET))) * topPosition + topPosition
                    + itemsLineWidth),
            itemsLineWidth, itemEndPointsPaint);
}

From source file:br.com.leoleal.swipetorefresh.SwipeProgressBar.java

/**
 * Draws a circle centered in the view.//w  w w  . j  av  a  2s.  c o  m
 *
 * @param canvas the canvas to draw on
 * @param cx the center x coordinate
 * @param cy the center y coordinate
 * @param color the color to draw
 * @param pct the percentage of the view that the circle should cover
 */
private void drawCircle(Canvas canvas, float cx, float cy, int color, float pct) {
    mPaint.setColor(color);
    canvas.save();
    canvas.translate(cx, cy);
    float radiusScale = INTERPOLATOR.getInterpolation(pct);
    canvas.scale(radiusScale, radiusScale);
    canvas.drawCircle(0, 0, cx, mPaint);
    canvas.restore();
}

From source file:com.bamobile.fdtks.util.Tools.java

public static Bitmap getRoundedCornerBitmap(Bitmap bitmap) {
    Bitmap output;/*from  w  ww. j  a va 2s. co m*/

    if (bitmap.getWidth() > bitmap.getHeight()) {
        output = Bitmap.createBitmap(bitmap.getHeight(), bitmap.getHeight(), Config.ARGB_8888);
    } else {
        output = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getWidth(), Config.ARGB_8888);
    }

    Canvas canvas = new Canvas(output);

    final int color = 0xff424242;
    final Paint paint = new Paint();
    final Rect rect = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight());

    float r = 0;

    if (bitmap.getWidth() > bitmap.getHeight()) {
        r = bitmap.getHeight() / 2;
    } else {
        r = bitmap.getWidth() / 2;
    }

    paint.setAntiAlias(true);
    canvas.drawARGB(0, 0, 0, 0);
    paint.setColor(color);
    canvas.drawCircle(r, r, r, paint);
    paint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN));
    canvas.drawBitmap(bitmap, rect, rect, paint);

    return output;

}

From source file:com.dragon.lib.IndicatorView.java

private void drawCircle(Canvas canvas, float startX, float startY, float radius) {
    canvas.drawCircle(startX + radius, startY, radius, mIndicatorPaint);
}