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.akop.crosswords.view.CrosswordView.java

private void renderCell(Canvas canvas, Cell cell, RectF cellRect, Paint fillPaint) {
    canvas.drawRect(cellRect, fillPaint);
    canvas.drawRect(cellRect, mCellStrokePaint);

    if (cell.mCircled) {
        canvas.drawCircle(cellRect.centerX(), cellRect.centerY(), mCircleRadius, mCircleStrokePaint);
    }//w w  w . jav a2 s .c o  m

    if (cell.mNumber != null) {
        mNumberTextPaint.getTextBounds(cell.mNumber, 0, cell.mNumber.length(), mTempRect);

        float numberX = cellRect.left + mNumberTextPadding + (mTempRect.width() / 2);
        float numberY = cellRect.top + mNumberTextPadding + mTempRect.height();

        if (cell.mCircled) {
            canvas.drawText(cell.mNumber, numberX, numberY, mNumberStrokePaint);
        }

        canvas.drawText(cell.mNumber, numberX, numberY, mNumberTextPaint);
    }

    if (cell.mCheated) {
        Path path = new Path();
        path.moveTo(cellRect.right, cellRect.bottom);
        path.lineTo(cellRect.right - mMarkerSideLength, cellRect.bottom);
        path.lineTo(cellRect.right, cellRect.bottom - mMarkerSideLength);
        path.close();

        canvas.drawPath(path, mCheatedCellFillPaint);
        canvas.drawPath(path, mCellStrokePaint);
    }

    if (cell.mError) {
        Path path = new Path();
        path.moveTo(cellRect.left, cellRect.bottom);
        path.lineTo(cellRect.left + mMarkerSideLength, cellRect.bottom);
        path.lineTo(cellRect.left, cellRect.bottom - mMarkerSideLength);
        path.close();

        canvas.drawPath(path, mMistakeCellFillPaint);
        canvas.drawPath(path, mCellStrokePaint);
    }

    if (!cell.isEmpty()) {
        mAnswerTextPaint.getTextBounds(cell.mCharStr, 0, cell.mCharStr.length(), mTempRect);
        canvas.drawText(cell.mCharStr, cellRect.left + mCellSize / 2,
                cellRect.top + mCellSize - mAnswerTextPadding, mAnswerTextPaint);
    }
}

From source file:com.moblin.cellcomsms.utils.CirclePageIndicator.java

@Override
protected void onDraw(Canvas canvas) {

    if (isInEditMode())
        return;/*w ww .  j  a v  a  2s  .co m*/

    super.onDraw(canvas);

    int longSize;
    int longPaddingBefore;
    int longPaddingAfter;
    int shortPaddingBefore;
    if (mOrientation == HORIZONTAL) {
        longSize = getWidth();
        longPaddingBefore = getPaddingLeft();
        longPaddingAfter = getPaddingRight();
        shortPaddingBefore = getPaddingTop();
    } else {
        longSize = getHeight();
        longPaddingBefore = getPaddingTop();
        longPaddingAfter = getPaddingBottom();
        shortPaddingBefore = getPaddingLeft();
    }
    int count = 0;
    if (mViewPager != null) {
        if (mViewPager.getAdapter() != null) {
            count = mViewPager.getAdapter().getCount();
        }
    }
    final float threeRadius = mRadius * 3;
    final float shortOffset = shortPaddingBefore + mRadius;
    float longOffset = longPaddingBefore + mRadius;
    if (mCentered) {
        longOffset += ((longSize - longPaddingBefore - longPaddingAfter) / 2.0f)
                - ((count * threeRadius) / 2.0f);
    }

    float dX;
    float dY;

    // Draw stroked circles
    for (int iLoop = 0; iLoop < count; iLoop++) {
        float drawLong = longOffset + (iLoop * threeRadius);
        if (mOrientation == HORIZONTAL) {
            dX = drawLong;
            dY = shortOffset;
        } else {
            dX = shortOffset;
            dY = drawLong;
        }
        canvas.drawCircle(dX, dY, mRadius, mPaintStroke);
    }

    // Draw the filled circle according to the current scroll
    float cx = (mSnap ? mSnapPage : mCurrentPage) * threeRadius;
    if (!mSnap && (mPageSize != 0)) {
        cx += (mCurrentOffset * 1.0f / mPageSize) * threeRadius;
    }
    if (mOrientation == HORIZONTAL) {
        dX = longOffset + cx;
        dY = shortOffset;
    } else {
        dX = shortOffset;
        dY = longOffset + cx;
    }
    canvas.drawCircle(dX, dY, mRadius, mPaintFill);
}

From source file:com.hippo.widget.Slider.java

@Override
protected void onDraw(@NonNull Canvas canvas) {
    int width = getWidth();
    int height = getHeight();
    if (width < LayoutUtils.dp2pix(mContext, 24)) {
        canvas.drawRect(0, 0, width, getHeight(), mPaint);
    } else {/*from   ww  w  .j ava  2  s.  c  o m*/
        int paddingLeft = getPaddingLeft();
        int paddingTop = getPaddingTop();
        int paddingRight = getPaddingRight();
        int paddingBottom = getPaddingBottom();
        float thickness = mThickness;
        float radius = mRadius;
        float halfThickness = thickness / 2;

        int saved = canvas.save();

        canvas.translate(0, paddingTop + ((height - paddingTop - paddingBottom) / 2));

        float currentX = paddingLeft + radius + (width - radius - radius - paddingLeft - paddingRight)
                * (mReverse ? (1.0f - mDrawPercent) : mDrawPercent);

        mLeftRectF.set(paddingLeft + radius, -halfThickness, currentX, halfThickness);
        mRightRectF.set(currentX, -halfThickness, width - paddingRight - radius, halfThickness);

        // Draw bar
        if (mReverse) {
            canvas.drawRect(mRightRectF, mPaint);
            canvas.drawRect(mLeftRectF, mBgPaint);
        } else {
            canvas.drawRect(mLeftRectF, mPaint);
            canvas.drawRect(mRightRectF, mBgPaint);
        }

        // Draw controller
        float scale = 1.0f - mDrawBubbleScale;
        if (scale != 0.0f) {
            canvas.scale(scale, scale, currentX, 0);
            canvas.drawCircle(currentX, 0, radius, mPaint);
        }

        canvas.restoreToCount(saved);
    }
}

From source file:com.dotit.gireve.ihm.viewpager.CirclePageIndicator.java

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

    if (mViewPager == null) {
        return;//w w w.j av  a  2s .  c o m
    }
    final int count = mViewPager.getAdapter().getCount();
    if (count == 0) {
        return;
    }

    int longSize;
    int longPaddingBefore;
    int longPaddingAfter;
    int shortPaddingBefore;
    if (mOrientation == HORIZONTAL) {
        longSize = getWidth();
        longPaddingBefore = getPaddingLeft();
        longPaddingAfter = getPaddingRight();
        shortPaddingBefore = getPaddingTop();
    } else {
        longSize = getHeight();
        longPaddingBefore = getPaddingTop();
        longPaddingAfter = getPaddingBottom();
        shortPaddingBefore = getPaddingLeft();
    }

    final float threeRadius = mRadius * 3;
    final float shortOffset = shortPaddingBefore + mRadius;
    float longOffset = longPaddingBefore + mRadius;
    if (mCentered) {
        longOffset += ((longSize - longPaddingBefore - longPaddingAfter) / 2.0f)
                - ((count * threeRadius) / 2.0f);
    }

    float dX;
    float dY;

    //Draw stroked circles
    for (int iLoop = 0; iLoop < count; iLoop++) {
        float drawLong = longOffset + (iLoop * threeRadius);
        if (mOrientation == HORIZONTAL) {
            dX = drawLong;
            dY = shortOffset;
        } else {
            dX = shortOffset;
            dY = drawLong;
        }
        canvas.drawCircle(dX, dY, mRadius, mPaintStroke);
    }

    //Draw the filled circle according to the current scroll
    float cx = (mSnap ? mSnapPage : mCurrentPage) * threeRadius;
    if (!mSnap && (mPageSize != 0)) {
        cx += (mCurrentOffset * 1.0f / mPageSize) * threeRadius;
    }
    if (mOrientation == HORIZONTAL) {
        dX = longOffset + cx;
        dY = shortOffset;
    } else {
        dX = shortOffset;
        dY = longOffset + cx;
    }
    canvas.drawCircle(dX, dY, mRadius, mPaintFill);
}

From source file:com.google.blockly.android.ui.AbstractBlockView.java

/**
 * This is a developer testing function subclasses can call to draw dots at the model's location
 * of all connections on this block.  Never called by default.
 *
 * @param c The canvas to draw on.//w ww . j av a2 s  . c om
 */
protected void drawConnectorCenters(Canvas c) {
    List<Connection> connections = mBlock.getAllConnections();
    Paint paint = new Paint();
    paint.setStyle(Paint.Style.FILL);
    for (int i = 0; i < connections.size(); i++) {
        Connection conn = connections.get(i);
        if (conn.inDragMode()) {
            if (conn.isConnected()) {
                paint.setColor(Color.RED);
            } else {
                paint.setColor(Color.MAGENTA);
            }
        } else {
            if (conn.isConnected()) {
                paint.setColor(Color.GREEN);
            } else {
                paint.setColor(Color.CYAN);
            }
        }

        // Compute connector position relative to this view from its offset to block origin in
        // Workspace coordinates.
        mTempWorkspacePoint.set(conn.getPosition().x - mBlock.getPosition().x,
                conn.getPosition().y - mBlock.getPosition().y);
        mHelper.workspaceToVirtualViewDelta(mTempWorkspacePoint, mTempConnectionPosition);
        if (mHelper.useRtl()) {
            // In RTL mode, add block view size to x coordinate. This is counter-intuitive, but
            // equivalent to "x = size - (-x)", with the inner negation "-x" undoing the
            // side-effect of workspaceToVirtualViewDelta reversing the x coordinate. This is,
            // the addition mirrors the re-negated in-block x coordinate w.r.t. the right-hand
            // side of the block view, which is the origin of the block in RTL mode.
            mTempConnectionPosition.x += mBlockViewSize.x;
        }
        c.drawCircle(mTempConnectionPosition.x, mTempConnectionPosition.y, 10, paint);
    }
}

From source file:com.dean.phonesafe.ui.SlideSwitch.java

@Override
protected void onDraw(Canvas canvas) {
    if (shape == SHAPE_RECT) {
        paint.setColor(Color.GRAY);
        canvas.drawRect(backRect, paint);
        paint.setColor(color_theme);//  w  w  w .  j  a  v a 2  s  .  c  o  m
        paint.setAlpha(alpha);
        canvas.drawRect(backRect, paint);
        frontRect.set(frontRect_left, RIM_SIZE, frontRect_left + getMeasuredWidth() / 2 - RIM_SIZE,
                getMeasuredHeight() - RIM_SIZE);
        paint.setColor(Color.WHITE);
        canvas.drawRect(frontRect, paint);
    } else {
        // draw circle
        int radius;
        radius = backRect.height() / 2 - RIM_SIZE;
        paint.setColor(Color.GRAY);
        backCircleRect.set(backRect);
        canvas.drawRoundRect(backCircleRect, radius, radius, paint);
        paint.setColor(color_theme);
        paint.setAlpha(alpha);
        canvas.drawRoundRect(backCircleRect, radius, radius, paint);
        frontRect.set(frontRect_left, RIM_SIZE, frontRect_left + backRect.height() - 2 * RIM_SIZE,
                backRect.height() - RIM_SIZE);
        frontCircleRect.set(frontRect);
        paint.setColor(Color.WHITE);
        canvas.drawRoundRect(frontCircleRect, radius, radius, paint);

    }
    //??
    //?
    paint.setStrokeWidth(2);
    paint.setAlpha(alpha);
    paint.setStyle(Paint.Style.STROKE);

    float gap = backRect.width() - frontRect.width();
    float left = frontRect.left - gap + frontRect.width() / 2;
    canvas.drawLine(left, backRect.height() / 4, left, backRect.height() / 4 * 3, paint);

    //??
    paint.setAlpha(255 - alpha);
    left = frontRect.left + gap + frontRect.width() / 2;
    canvas.drawCircle(left, backRect.height() / 2, frontRect.width() / 5, paint);
    //
    paint.setStyle(Paint.Style.FILL);
}

From source file:com.gm.common.ui.widget.pageindicator.PageIndicatorView.java

private void drawWithWormAnimation(@NonNull Canvas canvas, int x, int y) {
    int radius = radiusPx;

    if (orientation == Orientation.HORIZONTAL) {
        rect.left = frameFrom;//from w  w  w . ja  v  a2 s . c  o m
        rect.right = frameTo;
        rect.top = y - radius;
        rect.bottom = y + radius;

    } else {
        rect.left = x - radiusPx;
        rect.right = x + radiusPx;
        rect.top = frameFrom;
        rect.bottom = frameTo;
    }

    fillPaint.setColor(unselectedColor);
    canvas.drawCircle(x, y, radius, fillPaint);

    fillPaint.setColor(selectedColor);
    canvas.drawRoundRect(rect, radiusPx, radiusPx, fillPaint);
}

From source file:com.codetroopers.betterpickers.radialtimepicker.AmPmCirclesView.java

@Override
public void onDraw(Canvas canvas) {
    int viewWidth = getWidth();
    if (viewWidth == 0 || !mIsInitialized) {
        return;//from   w ww  . j a  v  a2s  .  co  m
    }

    if (!mDrawValuesReady) {
        int layoutXCenter = getWidth() / 2;
        int layoutYCenter = getHeight() / 2;
        int circleRadius = (int) (Math.min(layoutXCenter, layoutYCenter) * mCircleRadiusMultiplier);
        mAmPmCircleRadius = (int) (circleRadius * mAmPmCircleRadiusMultiplier);
        int textSize = mAmPmCircleRadius * 3 / 4;
        mPaint.setTextSize(textSize);

        // Line up the vertical center of the AM/PM circles with the bottom of the main circle.
        mAmPmYCenter = layoutYCenter - mAmPmCircleRadius / 2 + circleRadius;
        // Line up the horizontal edges of the AM/PM circles with the horizontal edges
        // of the main circle.
        mAmXCenter = layoutXCenter - circleRadius + mAmPmCircleRadius;
        mPmXCenter = layoutXCenter + circleRadius - mAmPmCircleRadius;

        mDrawValuesReady = true;
    }

    // We'll need to draw either a lighter blue (for selection), a darker blue (for touching)
    // or white (for not selected).
    int amColor = mUnselectedColor;
    int amAlpha = mUnselectedAlpha;
    int pmColor = mUnselectedColor;
    int pmAlpha = mUnselectedAlpha;
    if (mAmOrPm == AM) {
        amColor = mSelectedColor;
        amAlpha = mSelectedAlpha;
    } else if (mAmOrPm == PM) {
        pmColor = mSelectedColor;
        pmAlpha = mSelectedAlpha;
    }
    if (mAmOrPmPressed == AM) {
        amColor = mSelectedColor;
        amAlpha = mSelectedAlpha;
    } else if (mAmOrPmPressed == PM) {
        pmColor = mSelectedColor;
        pmAlpha = mSelectedAlpha;
    }

    // Draw the two circles.
    mPaint.setColor(amColor);
    mPaint.setAlpha(amAlpha);
    canvas.drawCircle(mAmXCenter, mAmPmYCenter, mAmPmCircleRadius, mPaint);
    mPaint.setColor(pmColor);
    mPaint.setAlpha(pmAlpha);
    canvas.drawCircle(mPmXCenter, mAmPmYCenter, mAmPmCircleRadius, mPaint);

    // Draw the AM/PM texts on top.
    mPaint.setColor(mAmPmTextColor);
    int textYCenter = mAmPmYCenter - (int) (mPaint.descent() + mPaint.ascent()) / 2;
    canvas.drawText(mAmText, mAmXCenter, textYCenter, mPaint);
    canvas.drawText(mPmText, mPmXCenter, textYCenter, mPaint);
}

From source file:com.gm.common.ui.widget.pageindicator.PageIndicatorView.java

private void drawWithThinWormAnimation(@NonNull Canvas canvas, int x, int y) {
    int radius = radiusPx;

    if (orientation == Orientation.HORIZONTAL) {
        rect.left = frameFrom;/* ww w  .j ava2s  . co  m*/
        rect.right = frameTo;
        rect.top = y - (frameHeight / 2);
        rect.bottom = y + (frameHeight / 2);

    } else {
        rect.left = x - (frameHeight / 2);
        rect.right = x + (frameHeight / 2);
        rect.top = frameFrom;
        rect.bottom = frameTo;
    }

    fillPaint.setColor(unselectedColor);
    canvas.drawCircle(x, y, radius, fillPaint);

    fillPaint.setColor(selectedColor);
    canvas.drawRoundRect(rect, radiusPx, radiusPx, fillPaint);
}

From source file:com.gm.common.ui.widget.pageindicator.PageIndicatorView.java

private void drawWithNoEffect(@NonNull Canvas canvas, int position, int x, int y) {
    float radius = radiusPx;
    if (animationType == AnimationType.SCALE) {
        radius *= scaleFactor;//w  ww  .ja  v a  2 s  .c o m
    }

    int color = unselectedColor;
    if (position == selectedPosition) {
        color = selectedColor;
    }

    Paint paint;
    if (animationType == AnimationType.FILL) {
        paint = strokePaint;
        paint.setStrokeWidth(strokePx);
    } else {
        paint = fillPaint;
    }

    paint.setColor(color);
    canvas.drawCircle(x, y, radius, paint);
}