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.android.settings.widget.DotsPageIndicator.java

private void drawUnselected(Canvas canvas) {
    combinedUnselectedPath.rewind();//from w w  w  . j  a  va2 s .  c o  m

    // draw any settled, revealing or joining dots
    for (int page = 0; page < pageCount; page++) {
        int nextXIndex = page == pageCount - 1 ? page : page + 1;
        // todo Path.op should be supported in KitKat but causes the app to hang for Nexus 5.
        // For now disabling for all pre-L devices.
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            Path unselectedPath = getUnselectedPath(page, dotCenterX[page], dotCenterX[nextXIndex],
                    page == pageCount - 1 ? INVALID_FRACTION : joiningFractions[page],
                    dotRevealFractions[page]);
            combinedUnselectedPath.op(unselectedPath, Path.Op.UNION);
        } else {
            canvas.drawCircle(dotCenterX[page], dotCenterY, dotRadius, unselectedPaint);
        }
    }

    // draw any retreating joins
    if (retreatingJoinX1 != INVALID_FRACTION) {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            combinedUnselectedPath.op(getRetreatingJoinPath(), Path.Op.UNION);
        }
    }
    canvas.drawPath(combinedUnselectedPath, unselectedPaint);
}

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

private void drawWithSlideAnimation(@NonNull Canvas canvas, int position, int x, int y) {
    fillPaint.setColor(unselectedColor);
    canvas.drawCircle(x, y, radiusPx, fillPaint);

    int from = orientation == Orientation.HORIZONTAL ? frameSlideFrom : x;
    int to = orientation == Orientation.HORIZONTAL ? y : frameSlideFrom;

    if (interactiveAnimation && (position == selectingPosition || position == selectedPosition)) {
        fillPaint.setColor(selectedColor);
        canvas.drawCircle(from, to, radiusPx, fillPaint);

    } else if (!interactiveAnimation && (position == selectedPosition || position == lastSelectedPosition)) {
        fillPaint.setColor(selectedColor);
        canvas.drawCircle(from, to, radiusPx, fillPaint);
    }//  w  w  w.j  av a  2  s  . co m
}

From source file:io.doist.datetimepicker.time.RadialTimePickerView.java

private void drawDebug(Canvas canvas) {
    // Draw outer numbers circle
    final float outerRadius = mCircleRadius[HOURS] * mNumbersRadiusMultiplier[HOURS];
    canvas.drawCircle(mXCenter, mYCenter, outerRadius, mPaintDebug);

    // Draw inner numbers circle
    final float innerRadius = mCircleRadius[HOURS] * mNumbersRadiusMultiplier[HOURS_INNER];
    canvas.drawCircle(mXCenter, mYCenter, innerRadius, mPaintDebug);

    // Draw outer background circle
    canvas.drawCircle(mXCenter, mYCenter, mCircleRadius[HOURS], mPaintDebug);

    // Draw outer rectangle for circles
    float left = mXCenter - outerRadius;
    float top = mYCenter - outerRadius;
    float right = mXCenter + outerRadius;
    float bottom = mYCenter + outerRadius;
    canvas.drawRect(left, top, right, bottom, mPaintDebug);

    // Draw outer rectangle for background
    left = mXCenter - mCircleRadius[HOURS];
    top = mYCenter - mCircleRadius[HOURS];
    right = mXCenter + mCircleRadius[HOURS];
    bottom = mYCenter + mCircleRadius[HOURS];
    canvas.drawRect(left, top, right, bottom, mPaintDebug);

    // Draw outer view rectangle
    canvas.drawRect(0, 0, getWidth(), getHeight(), mPaintDebug);

    // Draw selected time
    final String selected = String.format("%02d:%02d", getCurrentHour(), getCurrentMinute());

    ViewGroup.LayoutParams lp = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
            ViewGroup.LayoutParams.WRAP_CONTENT);
    TextView tv = new TextView(getContext());
    tv.setLayoutParams(lp);/*from w  w  w .j av  a 2s . c o m*/
    tv.setText(selected);
    tv.measure(MeasureSpec.UNSPECIFIED, MeasureSpec.UNSPECIFIED);
    Paint paint = tv.getPaint();
    paint.setColor(DEBUG_TEXT_COLOR);

    final int width = tv.getMeasuredWidth();

    float height = paint.descent() - paint.ascent();
    float x = mXCenter - width / 2;
    float y = mYCenter + 1.5f * height;

    canvas.drawText(selected, x, y, paint);
}

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

@Override
public void onDraw(Canvas canvas) {
    int viewWidth = getWidth();
    if (viewWidth == 0 || !mIsInitialized) {
        return;// w ww . j  ava  2  s .  c  om
    }

    if (!mDrawValuesReady) {
        mXCenter = getWidth() / 2;
        mYCenter = getHeight() / 2;
        mCircleRadius = (int) (Math.min(mXCenter, mYCenter) * mCircleRadiusMultiplier);

        if (!mIs24HourMode) {
            // We'll need to draw the AM/PM circles, so the main circle will need to have
            // a slightly higher center. To keep the entire view centered vertically, we'll
            // have to push it up by half the radius of the AM/PM circles.
            int amPmCircleRadius = (int) (mCircleRadius * mAmPmCircleRadiusMultiplier);
            mYCenter -= amPmCircleRadius / 2;
        }

        mSelectionRadius = (int) (mCircleRadius * mSelectionRadiusMultiplier);

        mDrawValuesReady = true;
    }

    // Calculate the current radius at which to place the selection circle.
    mLineLength = (int) (mCircleRadius * mNumbersRadiusMultiplier * mAnimationRadiusMultiplier);
    int pointX = mXCenter + (int) (mLineLength * Math.sin(mSelectionRadians));
    int pointY = mYCenter - (int) (mLineLength * Math.cos(mSelectionRadians));

    // Draw the selection circle.
    mPaint.setAlpha(mSelectionAlpha);
    canvas.drawCircle(pointX, pointY, mSelectionRadius, mPaint);

    if (mForceDrawDot | mSelectionDegrees % 30 != 0) {
        // We're not on a direct tick (or we've been told to draw the dot anyway).
        mPaint.setAlpha(FULL_ALPHA);
        canvas.drawCircle(pointX, pointY, (mSelectionRadius * 2 / 7), mPaint);
    } else {
        // We're not drawing the dot, so shorten the line to only go as far as the edge of the
        // selection circle.
        int lineLength = mLineLength;
        lineLength -= mSelectionRadius;
        pointX = mXCenter + (int) (lineLength * Math.sin(mSelectionRadians));
        pointY = mYCenter - (int) (lineLength * Math.cos(mSelectionRadians));
    }

    // Draw the line from the center of the circle.
    mPaint.setAlpha(255);
    mPaint.setStrokeWidth(1);
    canvas.drawLine(mXCenter, mYCenter, pointX, pointY, mPaint);
}

From source file:com.zwj.customview.gesturelock.PatternView.java

/**
 * @param partOfPattern Whether this circle is part of the pattern.
 *///www . j a v  a2 s  .  co  m
private void drawCircle(Canvas canvas, float centerX, float centerY, float radius, boolean partOfPattern,
        float alpha) {

    mPaint.setColor(getCurrentColor(partOfPattern));
    mPaint.setAlpha((int) (alpha * 255));
    canvas.drawCircle(centerX, centerY, radius, mPaint);

    // TODO 
    // 
    mPaintExcircle.setStyle(Paint.Style.STROKE);
    mPaintExcircle.setStrokeWidth(2);
    canvas.drawCircle(centerX, centerY, mExcircleRadius, mPaintExcircle);
}

From source file:com.skumar.flexibleciruclarseekbar.CircularSeekBar.java

/**
 * Method to draw the dots over needle scale
 *
 * @param canvas drawable element//from ww w.  j av a  2s . c  o  m
 */
private void drawDotMarker(Canvas canvas) {
    float cx = canvas.getWidth() / 2;
    float cy = canvas.getHeight() / 2;
    float scaleMarkSize = getResources().getDisplayMetrics().density * 10;
    int radius = mArcRadius + mNeedleDistance + mIncreaseCenterNeedle + 15;

    for (float progress = 0; progress <= mMax; progress += 0.2f) {
        float progressSweep = progress / mMax * mSweepAngle;
        int thumbAngle = (int) (mStartAngle + progressSweep + mRotation);

        float stopX = (float) (cx + (radius + scaleMarkSize) * Math.sin(Math.toRadians(thumbAngle)));
        float stopY = (float) (cy - (radius + scaleMarkSize) * Math.cos(Math.toRadians(thumbAngle)));

        canvas.drawCircle(stopX, stopY, mDotSize, mNeedleScalePaint);
    }
}

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

private void drawWithSwapAnimation(@NonNull Canvas canvas, int position, int x, int y) {
    fillPaint.setColor(unselectedColor);

    if (position == selectedPosition) {
        fillPaint.setColor(selectedColor);
        canvas.drawCircle(frameSlideFrom, y, radiusPx, fillPaint);

    } else if (interactiveAnimation && position == selectingPosition) {
        canvas.drawCircle(x - (frameSlideFrom - getXCoordinate(selectedPosition)), y, radiusPx, fillPaint);

    } else if (!interactiveAnimation) {
        canvas.drawCircle(x - (frameSlideFrom - getXCoordinate(selectedPosition)), y, radiusPx, fillPaint);

    } else {// w w w .j a  va2 s .c  o m
        canvas.drawCircle(x, y, radiusPx, fillPaint);
    }
}

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

private void drawWithSwapAnimationVertically(@NonNull Canvas canvas, int position, int x, int y) {
    fillPaint.setColor(unselectedColor);

    if (position == selectedPosition) {
        fillPaint.setColor(selectedColor);
        canvas.drawCircle(x, frameSlideFrom, radiusPx, fillPaint);

    } else if (interactiveAnimation && position == selectingPosition) {
        canvas.drawCircle(x, y - (frameSlideFrom - getYCoordinate(selectedPosition)), radiusPx, fillPaint);

    } else if (!interactiveAnimation) {
        canvas.drawCircle(x, y - (frameSlideFrom - getYCoordinate(selectedPosition)), radiusPx, fillPaint);

    } else {//from   www  .  ja v  a2  s  . c o m
        canvas.drawCircle(x, y, radiusPx, fillPaint);
    }
}

From source file:com.shawnway.nav.app.yylg.view.PagerSlidingTabStrip.java

@Override
protected void onDraw(Canvas canvas) {

    if (isInEditMode() || tabCount == 0) {
        return;/*w ww.jav a  2 s .co  m*/
    }

    final int height = getHeight();

    // draw indicator line

    rectPaint.setColor(indicatorColor);

    // default: line below current tab
    View currentTab = tabsContainer.getChildAt(currentPosition);
    float lineLeft = currentTab.getLeft();
    float lineRight = currentTab.getRight();

    // if there is an offset, start interpolating left and right coordinates
    // between current and next tab
    if (currentPositionOffset > 0f && currentPosition < tabCount - 1) {

        View nextTab = tabsContainer.getChildAt(currentPosition + 1);
        final float nextTabLeft = nextTab.getLeft();
        final float nextTabRight = nextTab.getRight();

        lineLeft = (currentPositionOffset * nextTabLeft + (1f - currentPositionOffset) * lineLeft);
        lineRight = (currentPositionOffset * nextTabRight + (1f - currentPositionOffset) * lineRight);
    }
    switch (indicatorStyle) {
    case STYLE_CIRCLE:
        canvas.drawCircle((lineLeft + lineRight) / 2, (currentTab.getTop() + currentTab.getBottom()) / 2,
                circleSize, rectPaint);
        break;
    case STYLE_RECTANGLE:
        drawRectangle(canvas, height, currentTab, lineLeft, lineRight);
        break;
    case STYLE_NORMAL:
        drawNormalUnderLine(canvas, height, currentTab, lineLeft, lineRight);
    default:
        break;
    }
    super.onDraw(canvas);

    // // draw underline
    //
    // rectPaint.setColor(underlineColor);
    // canvas.drawRect(0, height - underlineHeight,
    // tabsContainer.getWidth(), height, rectPaint);

    // draw divider
    //
    // dividerPaint.setColor(dividerColor);
    // for (int i = 0; i < tabCount - 1; i++) {
    // View tab = tabsContainer.getChildAt(i);
    // canvas.drawLine(tab.getRight(), dividerPadding, tab.getRight(),
    // height - dividerPadding, dividerPaint);
    // }
}

From source file:com.andexert.calendarlistview.library.SimpleMonthView.java

protected void drawMonthNums(Canvas canvas) {
    int y = (mRowHeight + MINI_DAY_NUMBER_TEXT_SIZE) / 2 - DAY_SEPARATOR_WIDTH + MONTH_HEADER_SIZE;
    int paddingDay = (mWidth - 2 * mPadding) / (2 * mNumDays);
    int dayOffset = findDayOffset();
    int day = 1;/*w  w  w . j a  v  a2 s . c o m*/
    String toDayRes = getResources().getString(R.string.today);
    while (day <= mNumCells) {
        boolean isShowTrain = true;
        int x = paddingDay * (1 + dayOffset * 2) + mPadding;
        if ((mMonth == mSelectedBeginMonth && mSelectedBeginDay == day && mSelectedBeginYear == mYear)
                || (mMonth == mSelectedLastMonth && mSelectedLastDay == day && mSelectedLastYear == mYear)) {
            if (mDrawRect) {
                RectF rectF = new RectF(x - DAY_SELECTED_CIRCLE_SIZE,
                        (y - MINI_DAY_NUMBER_TEXT_SIZE / 3) - DAY_SELECTED_CIRCLE_SIZE,
                        x + DAY_SELECTED_CIRCLE_SIZE,
                        (y - MINI_DAY_NUMBER_TEXT_SIZE / 3) + DAY_SELECTED_CIRCLE_SIZE);
                canvas.drawRoundRect(rectF, 10.0f, 10.0f, mSelectedCirclePaint);
            } else {
                canvas.drawCircle(x, y - MINI_DAY_NUMBER_TEXT_SIZE / 3, DAY_SELECTED_CIRCLE_SIZE,
                        mSelectedCirclePaint);
            }
            isShowTrain = false;
        }
        if (mHasToday && (mToday == day)) {
            mMonthNumPaint.setColor(mCurrentDayTextColor);
        } else {
            mMonthNumPaint.setColor(mDayNumColor);
            mMonthNumPaint.setTypeface(Typeface.defaultFromStyle(Typeface.NORMAL));
        }

        if ((mMonth == mSelectedBeginMonth && mSelectedBeginDay == day && mSelectedBeginYear == mYear)
                || (mMonth == mSelectedLastMonth && mSelectedLastDay == day && mSelectedLastYear == mYear))
            mMonthNumPaint.setColor(mMonthTitleBGColor);

        if ((mSelectedBeginDay != -1 && mSelectedLastDay != -1 && mSelectedBeginYear == mSelectedLastYear
                && mSelectedBeginMonth == mSelectedLastMonth && mSelectedBeginDay == mSelectedLastDay
                && day == mSelectedBeginDay && mMonth == mSelectedBeginMonth && mYear == mSelectedBeginYear)) {
            mMonthNumPaint.setColor(mSelectedDaysColor);
        }
        //?
        if ((mSelectedBeginDay != -1 && mSelectedLastDay != -1 && mSelectedBeginYear == mSelectedLastYear
                && mSelectedBeginYear == mYear)
                && (((mMonth == mSelectedBeginMonth && mSelectedLastMonth == mSelectedBeginMonth)
                        && ((mSelectedBeginDay < mSelectedLastDay && day > mSelectedBeginDay
                                && day < mSelectedLastDay)
                                || (mSelectedBeginDay > mSelectedLastDay && day < mSelectedBeginDay
                                        && day > mSelectedLastDay)))
                        || ((mSelectedBeginMonth < mSelectedLastMonth && mMonth == mSelectedBeginMonth
                                && day > mSelectedBeginDay)
                                || (mSelectedBeginMonth < mSelectedLastMonth && mMonth == mSelectedLastMonth
                                        && day < mSelectedLastDay))
                        || ((mSelectedBeginMonth > mSelectedLastMonth && mMonth == mSelectedBeginMonth
                                && day < mSelectedBeginDay)
                                || (mSelectedBeginMonth > mSelectedLastMonth && mMonth == mSelectedLastMonth
                                        && day > mSelectedLastDay)))) {
            mMonthNumPaint.setColor(mSelectedDaysColor);
        }

        if ((mSelectedBeginDay != -1 && mSelectedLastDay != -1 && mSelectedBeginYear != mSelectedLastYear
                && ((mSelectedBeginYear == mYear && mMonth == mSelectedBeginMonth)
                        || (mSelectedLastYear == mYear && mMonth == mSelectedLastMonth))
                && (((mSelectedBeginMonth < mSelectedLastMonth && mMonth == mSelectedBeginMonth
                        && day < mSelectedBeginDay)
                        || (mSelectedBeginMonth < mSelectedLastMonth && mMonth == mSelectedLastMonth
                                && day > mSelectedLastDay))
                        || ((mSelectedBeginMonth > mSelectedLastMonth && mMonth == mSelectedBeginMonth
                                && day > mSelectedBeginDay)
                                || (mSelectedBeginMonth > mSelectedLastMonth && mMonth == mSelectedLastMonth
                                        && day < mSelectedLastDay))))) {
            mMonthNumPaint.setColor(mSelectedDaysColor);
        }

        if ((mSelectedBeginDay != -1 && mSelectedLastDay != -1 && mSelectedBeginYear == mSelectedLastYear
                && mYear == mSelectedBeginYear)
                && ((mMonth > mSelectedBeginMonth && mMonth < mSelectedLastMonth
                        && mSelectedBeginMonth < mSelectedLastMonth)
                        || (mMonth < mSelectedBeginMonth && mMonth > mSelectedLastMonth
                                && mSelectedBeginMonth > mSelectedLastMonth))) {
            mMonthNumPaint.setColor(mSelectedDaysColor);
        }

        if ((mSelectedBeginDay != -1 && mSelectedLastDay != -1 && mSelectedBeginYear != mSelectedLastYear)
                && ((mSelectedBeginYear < mSelectedLastYear
                        && ((mMonth > mSelectedBeginMonth && mYear == mSelectedBeginYear)
                                || (mMonth < mSelectedLastMonth && mYear == mSelectedLastYear)))
                        || (mSelectedBeginYear > mSelectedLastYear
                                && ((mMonth < mSelectedBeginMonth && mYear == mSelectedBeginYear)
                                        || (mMonth > mSelectedLastMonth && mYear == mSelectedLastYear))))) {
            mMonthNumPaint.setColor(mSelectedDaysColor);
        }

        if ((!isPrevDayEnabled && prevDay(day, today)) || nextDay(day)) {
            mMonthNumPaint.setColor(mPreviousDayColor);
        }
        if (mHasToday && (mToday == day)) {
            canvas.drawText(toDayRes, x, y, mMonthNumPaint);
        } else {
            canvas.drawText(String.format("%d", day), x, y, mMonthNumPaint);
        }
        dayOffset++;
        if (dayOffset == mNumDays) {
            dayOffset = 0;
            y += mRowHeight;
        }
        day++;
    }
}