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.uoyabause.android.PadButton.java

public void draw(Canvas canvas, Paint nomal_back, Paint active_back, Paint front) {
    super.draw(canvas, nomal_back, active_back, front);
    canvas.drawCircle(rect.centerX(), rect.centerY(), width * this.scale, back);
    //front.setTextSize(textsize);
    //front.setTextAlign(Paint.Align.CENTER);
    //canvas.drawText(text, rect.centerX() , rect.centerY() , front);
}

From source file:com.amaze.carbonfilemanager.ui.views.Indicator.java

private void drawSelected(Canvas canvas) {
    canvas.drawCircle(selectedDotX, dotCenterY, dotRadius, selectedPaint);
}

From source file:ru.tinkoff.acquiring.sdk.views.KeyView.java

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

    if (contentText != null) {
        final float x = (getWidth() / 2) - (textWidth / 2);
        final float y = (getHeight() / 2) - ((contentPaint.descent() + contentPaint.ascent()) / 2);
        canvas.drawText(contentText, x, y, contentPaint);
    }//from w  ww .ja va 2 s  . c o  m

    if (contentImage != null) {
        canvas.drawBitmap(contentImage, getWidth() / 2 - contentImage.getWidth() / 2,
                getHeight() / 2 - contentImage.getHeight() / 2, contentPaint);
    }

    if (drawingPressAnimation) {
        canvas.drawCircle(circleCenter.x, circleCenter.y, circleRadius, circlePaint);
    }
}

From source file:com.morninz.ninepinview.widget.NinePINView.java

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

    // draw circles around center points and connection line
    int drawnCount = mDrawnPoints.size();
    for (int j = 0; j < drawnCount; j++) {
        Point p1 = mDrawnPoints.get(j);
        canvas.drawCircle(p1.x, p1.y, mCircleRadius, mCirclePaint);
        if (j + 1 < drawnCount) {
            Point p2 = mDrawnPoints.get(j + 1);
            canvas.drawCircle(p2.x, p2.y, mCircleRadius, mCirclePaint);
            canvas.drawLine(p1.x, p1.y, p2.x, p2.y, mLinePaint);
            if (mWillDrawWrongTriangle) {
                // compute the wrong triangle's direction of this point.
                float angle = 0.f;
                if (p2.y == p1.y) {// x-axis
                    angle = p2.x > p1.x ? 0.f : 180.f;
                } else if (p2.x == p1.x) { // y-axis
                    angle = p2.y > p1.y ? 90.f : -90.f;
                } else {// in quadrants
                    double tanA = ((double) p2.y - (double) p1.y) / ((double) p2.x - (double) p1.x);
                    // in 1 or 4 quadrant
                    angle = (float) (Math.atan(tanA) * 180 / Math.PI);
                    // in 2 or 3 quadrant
                    if (p2.x < p1.x) {
                        angle += 180.f;/*from  www  . ja v  a 2  s  .  c o  m*/
                    }
                }
                Log.d(TAG, "angle " + angle);
                canvas.save();
                canvas.rotate(angle, p1.x, p1.y);
                canvas.drawPath(mWrongPaths[p1.index], mWrongPaint);
                canvas.restore();
            }
        }
    }

    // draw extra connection line
    if (mLastDrawnPoint != null) {
        canvas.drawLine(mLastDrawnPoint.x, mLastDrawnPoint.y, mCurrX, mCurrY, mLinePaint);
    }

    // draw 9 center points
    for (int i = 0; i < POINT_COUNT; i++) {
        Point p = mCenterPoints[i];
        canvas.drawCircle(p.x, p.y, mPointSize, mPointPaint);
    }
}

From source file:ir.hatamiarash.calendar.view.QiblaCompassView.java

public void drawDial(Canvas canvas) {
    // over here/*from w  w w  . j a v a  2  s  .  c o m*/
    circlePaint.reset();
    circlePaint.setColor(ContextCompat.getColor(getContext(), R.color.qibla_color));
    circlePaint.setStrokeWidth(1);
    circlePaint.setStyle(Paint.Style.STROKE); // Sadece Cember ciziyor.

    int textHeight = (int) textPaint.measureText("yY");
    markerPaint.reset();
    markerPaint.setColor(ContextCompat.getColor(getContext(), R.color.qibla_color));
    // Draw the background
    canvas.drawCircle(px, py, Radius, circlePaint);
    canvas.drawCircle(px, py, Radius - 20, circlePaint);
    // Rotate our perspective so that the "top" is
    // facing the current bearing.

    int textWidth = (int) textPaint.measureText("W");
    int cardinalX = px - textWidth / 2;
    int cardinalY = py - Radius + textHeight;

    // Draw the marker every 15 degrees and text every 45.
    for (int i = 0; i < 24; i++) {
        // Draw a marker.
        canvas.drawLine(px, py - Radius, px, py - Radius + 10, markerPaint);
        canvas.save();
        canvas.translate(0, textHeight);
        // Draw the cardinal points
        if (i % 6 == 0) {
            String dirString = "";
            switch (i) {
            case (0): {
                dirString = northString;
                break;
            }
            case (6):
                dirString = eastString;
                break;
            case (12):
                dirString = southString;
                break;
            case (18):
                dirString = westString;
                break;
            }
            canvas.drawText(dirString, cardinalX, cardinalY, textPaint);
        } else if (i % 3 == 0) {
            // Draw the text every alternate 45deg
            String angle = String.valueOf(i * 15);
            float angleTextWidth = textPaint.measureText(angle);
            int angleTextX = (int) (px - angleTextWidth / 2);
            int angleTextY = py - Radius + textHeight;
            canvas.drawText(angle, angleTextX, angleTextY, textPaint);
        }
        canvas.restore();
        canvas.rotate(15, px, py);
    }
}

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

public void drawDial(Canvas canvas) {
    // over here//w  ww.  j  a  v a2 s  .c  o m
    circlePaint.reset();
    circlePaint.setColor(ContextCompat.getColor(getContext(), R.color.qibla_color));
    circlePaint.setStrokeWidth(1);
    circlePaint.setStyle(Paint.Style.STROKE); // Sadece Cember ciziyor.

    int textHeight = (int) textPaint.measureText("yY");
    markerPaint.reset();
    markerPaint.setColor(ContextCompat.getColor(getContext(), R.color.qibla_color));
    // Draw the background
    canvas.drawCircle(px, py, Radius, circlePaint);
    canvas.drawCircle(px, py, Radius - 20, circlePaint);
    // Rotate our perspective so that the "top" is
    // facing the current bearing.

    int textWidth = (int) textPaint.measureText("W");
    int cardinalX = px - textWidth / 2;
    int cardinalY = py - Radius + textHeight;

    // Draw the marker every 15 degrees and text every 45.
    for (int i = 0; i < 24; i++) {
        // Draw a marker.
        canvas.drawLine(px, py - Radius, px, py - Radius + 10, markerPaint);
        canvas.save();
        canvas.translate(0, textHeight);
        // Draw the cardinal points
        if (i % 6 == 0) {
            String dirString = "";
            switch (i) {
            case (0): {
                dirString = northString;
                break;
            }
            case (6):
                dirString = eastString;
                break;
            case (12):
                dirString = southString;
                break;
            case (18):
                dirString = westString;
                break;
            }
            canvas.drawText(dirString, cardinalX, cardinalY, textPaint);
        } else if (i % 3 == 0) {
            // Draw the text every alternate 45deg
            String angle = String.valueOf(i * 15);
            float angleTextWidth = textPaint.measureText(angle);
            int angleTextX = (int) (px - angleTextWidth / 2);
            int angleTextY = py - Radius + textHeight;
            canvas.drawText(angle, angleTextX, angleTextY, textPaint);
        }
        canvas.restore();

        canvas.rotate(15, px, py);
    }

}

From source file:com.crs4.roodin.moduletester.CustomView.java

/**
 * @param canvas/*from   w ww  .j  a  v  a 2s.c  o m*/
 */
private void drawRadar(Canvas canvas) {
    Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
    paint.setColor(Color.RED);
    paint.setAlpha(100);

    float rotation = currentRotation; //gRotationZ_deg + initialMapRotation;

    for (int i = -35; i < 35; i = i + 2) {
        float arrowX1 = (float) (translateX - Math.sin(Math.toRadians(rotation + i)) * 45);
        float arrowY1 = (float) (translateY - Math.cos(Math.toRadians(rotation + i)) * 45);
        canvas.drawLine(translateX, translateY, arrowX1, arrowY1, paint);

    }

    paint.setAlpha(100);
    paint.setColor(Color.RED);
    canvas.drawCircle(translateX, translateY, 7, paint);

    paint.setColor(Color.YELLOW);
    canvas.drawCircle(translateX, translateY, 6, paint);

    paint.setColor(Color.RED);
    canvas.drawCircle(translateX, translateY, 1, paint);
}

From source file:cn.refactor.ultraindicator.lib.UltraIndicatorView.java

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

    int position = 0;
    for (int rowChildCount = 3; rowChildCount > 0; rowChildCount--) {
        for (int i = 0; i < rowChildCount; i++) {
            mPaint.setColor(position == mCheckedPosition ? mCheckedColor : mUnCheckedColor);
            float cx = getPaddingLeft() + (i + 1) * mGap + ((i * 2 + 1) * mRadius); // 2n + 1 (n = 0,1,2)
            float cy = getPaddingTop() + ((3 - rowChildCount) + 1) * mGap
                    + (((3 - rowChildCount) * 2 + 1) * mRadius);
            canvas.drawCircle(cx, cy, position == mCheckedPosition ? mCheckedRunningRadius : mRadius, mPaint);
            position++;/*from w  w w .j  a va 2s.  c o  m*/
        }
    }
}

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

private void doRippleWork(Canvas canvas, int offect) {
    canvas.save();/*from  w w w  .j ava  2 s  .c o m*/
    if (rippleDuration <= timer * frameRate) {
        // There is problem on Android M where canvas.restore() seems to be called automatically
        // For now, don't call canvas.restore() manually on Android M (API 23)
        canvas.drawCircle(x, y, (radiusMax * (((float) timer * frameRate) / rippleDuration)), paint);

        if (onCompletionListener != null && rippleStatus != RIPPLE_ACTION_MOVE
                && rippleStatus != RIPPLE_LONG_PRESS) {
            onCompletionListener.onComplete(this);
        }
        if (rippleStatus != RIPPLE_LONG_PRESS) {
            animationRunning = false;
            rippleStatus = RIPPLE_NORMAL;
            timer = 0;
            durationEmpty = -1;
            timerEmpty = 0;
            if (Build.VERSION.SDK_INT != 23) {
                canvas.restore();
            }
        }
        invalidate();
        return;
    } else
        canvasHandler.postDelayed(runnable, frameRate);

    if (timer == 0)
        canvas.save();

    canvas.drawCircle(x, y, (radiusMax * (((float) timer * frameRate) / rippleDuration)), paint);

    paint.setColor(Color.parseColor("#ffff4444"));

    if (rippleType == 1 && originBitmap != null && (((float) timer * frameRate) / rippleDuration) > 0.4f) {
        if (durationEmpty == -1)
            durationEmpty = rippleDuration - timer * frameRate;

        timerEmpty++;
        final Bitmap tmpBitmap = getCircleBitmap(
                (int) ((radiusMax) * (((float) timerEmpty * frameRate) / (durationEmpty))));
        canvas.drawBitmap(tmpBitmap, 0, 0, paint);
        tmpBitmap.recycle();
    }

    paint.setColor(rippleColor);
    if (!isListMode) {
        if (rippleType == 1) {
            if ((((float) timer * frameRate) / rippleDuration) > 0.6f)
                paint.setAlpha((int) (rippleAlpha
                        - ((rippleAlpha) * (((float) timerEmpty * frameRate) / (durationEmpty)))));
            else
                paint.setAlpha(rippleAlpha);
        } else
            paint.setAlpha(
                    (int) (rippleAlpha - ((rippleAlpha) * (((float) timer * frameRate) / rippleDuration))));
    }
    timer += offect;
}

From source file:com.google.android.apps.santatracker.doodles.shared.physics.Polygon.java

public void draw(Canvas canvas) {
    if (!(SwimmingFragment.editorMode)) {
        return;//from   www.j a va 2  s  . c  om
    }
    for (int i = 0; i < vertices.size(); i++) {
        Vector2D start = vertices.get(i);
        Vector2D end;
        if (i < vertices.size() - 1) {
            end = vertices.get(i + 1);
        } else {
            end = vertices.get(0);
        }
        Vector2D midpoint = Util.getMidpoint(start, end);
        Vector2D normal = Vector2D.get(end).subtract(start).toNormal();

        canvas.drawCircle(start.x, start.y, VERTEX_RADIUS, vertexPaint);
        canvas.drawLine(start.x, start.y, end.x, end.y, linePaint);
        canvas.drawCircle(midpoint.x, midpoint.y, VERTEX_RADIUS / 2, midpointPaint);
        canvas.drawLine(midpoint.x, midpoint.y, midpoint.x + normal.x * 20, midpoint.y + normal.y * 20,
                linePaint);

        midpoint.release();
        normal.release();
    }
}