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.elderly.elderly.component.ElderlyCirclePageIndicator.java

@Override
protected void onDraw(Canvas canvas) {
    super.onDraw(canvas);
    // Log.v(TAG, "onDraw");
    if (mViewPager == null) {
        return;/*from ww w .  j av  a2  s.  c om*/
    }
    final int count = mViewPager.getAdapter().getCount();
    if (count == 0) {
        return;
    }
    if (mViewPager.isLooper() && mCurrentPage >= count) {
        setCurrentItem(count - 1);
        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 * 5;
    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;

    float pageFillRadius = mRadius;
    if (mPaintStroke.getStrokeWidth() > 0) {
        pageFillRadius -= mPaintStroke.getStrokeWidth() / 2.0f;
    }

    // Draw stroked circles
    for (int iLoop = 0; iLoop < count; iLoop++) {
        // Log.v(TAG, "onDraw>>"+iLoop);
        if (mViewPager.isLooper() && (iLoop == 0 || iLoop == count - 1)) {
            continue;
        }
        float drawLong = longOffset + (iLoop * threeRadius);
        if (mOrientation == HORIZONTAL) {
            dX = drawLong;
            dY = shortOffset;
        } else {
            dX = shortOffset;
            dY = drawLong;
        }
        // Only paint fill if not completely transparent
        if (mPaintPageFill.getAlpha() > 0) {
            canvas.drawCircle(dX, dY, pageFillRadius, mPaintPageFill);
        }

        // Only paint stroke if a stroke width was non-zero
        if (pageFillRadius != mRadius) {
            canvas.drawCircle(dX, dY, mRadius, mPaintStroke);
        }
        float cx = (mSnap ? mSnapPage : mCurrentPage) * threeRadius;
        if (!mSnap) {
            cx += mPageOffset * threeRadius;
        }
        float nDx;
        float nDy;
        if (mOrientation == HORIZONTAL) {
            nDx = longOffset + cx;
            nDy = shortOffset;
        } else {
            nDx = shortOffset;
            nDy = longOffset + cx;
        }
        if (iLoop == mCurrentPage) {
            // Log.v(TAG, "draw current point>>"+nDx+","+nDy+",mSnap>>"+mSnap+",cx>>"+cx);
            canvas.drawCircle(nDx, nDy, mRadius, mPaintFill);
        }
    }

    // Draw the filled circle according to the current scroll

}

From source file:com.tsingning.view.TabPageIndicators.CirclePageIndicator.java

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

    if (mViewPager == null) {
        return;//from w ww. j  ava  2s  . com
    }
    int count = realCount;
    if (count <= 0)
        count = mViewPager.getAdapter().getCount();
    if (count <= 0) {
        return;
    }

    if (mCurrentPage >= count) {
        setCurrentItem(count - 1);
        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;
    float shortOffset = shortPaddingBefore + mRadius;
    float longOffset = longPaddingBefore + mRadius;
    if (mCentered) {
        longOffset += (longSize - longPaddingBefore - longPaddingAfter) / 2.0f - count * threeRadius / 2.0f;
        if (mOrientation == HORIZONTAL) {
            shortOffset = getHeight() / 2.0f;
        } else {
            shortOffset = getWidth() / 2.0f;
        }

    }

    float dX;
    float dY;

    float pageFillRadius = mRadius;
    if (mPaintStroke.getStrokeWidth() > 0) {
        pageFillRadius -= mPaintStroke.getStrokeWidth() / 2.0f;
    }

    //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;
        }
        // Only paint fill if not completely transparent
        if (mPaintPageFill.getAlpha() > 0) {
            canvas.drawCircle(dX, dY, pageFillRadius, mPaintPageFill);
        }

        // Only paint stroke if a stroke width was non-zero
        if (pageFillRadius != mRadius) {
            canvas.drawCircle(dX, dY, mRadius, mPaintStroke);
        }
    }

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

From source file:net.cpacm.library.indicator.ViewpagerIndicator.CirclePageIndicator.java

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

    if (mViewPager == null) {
        return;/*  w w  w .jav a2 s .co m*/
    }
    int count = mViewPager.getAdapter().getCount();
    if (mViewPager.getAdapter() instanceof InfinitePagerAdapter) {
        count = ((InfinitePagerAdapter) mViewPager.getAdapter()).getRealCount();
        mCurrentPage = mCurrentPage % count;
    }
    if (count == 0) {
        return;
    }

    if (mCurrentPage >= count) {
        setCurrentItem(count - 1);
        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 - mRadius) / 2.0f);
    }

    float dX;
    float dY;

    float pageFillRadius = mRadius;
    if (mPaintStroke.getStrokeWidth() > 0) {
        pageFillRadius -= mPaintStroke.getStrokeWidth() / 2.0f;
    }

    //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;
        }
        // Only paint fill if not completely transparent
        if (mPaintPageFill.getAlpha() > 0) {
            canvas.drawCircle(dX, dY, pageFillRadius, mPaintPageFill);
        }

        // Only paint stroke if a stroke width was non-zero
        if (pageFillRadius != mRadius) {
            canvas.drawCircle(dX, dY, mRadius, mPaintStroke);
        }
    }

    //Draw the filled circle according to the current scroll
    float cx = (mSnap ? mSnapPage : mCurrentPage) * threeRadius;
    if (!mSnap && mCurrentPage < count - 1) {
        cx += mPageOffset * 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.wecook.uikit.widget.indicator.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 = mPageCount;
    if (count == 0) {
        return;
    }

    //        if (mCurrentPage >= count) {
    //            setCurrentItem(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);
    }
    if (mRighted) {
        longOffset = longPaddingBefore + mRadius;
        longOffset += (longSize - longPaddingBefore - longPaddingAfter) - (count * threeRadius) + mRadius;
    }

    float dX;
    float dY;

    float pageFillRadius = mRadius;
    if (mPaintStroke.getStrokeWidth() > 0) {
        pageFillRadius -= mPaintStroke.getStrokeWidth() / 2.0f;
    }

    //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;
        }
        // Only paint fill if not completely transparent
        if (mPaintPageFill.getAlpha() > 0) {
            canvas.drawCircle(dX, dY, pageFillRadius, mPaintPageFill);
        }

        // Only paint stroke if a stroke width was non-zero
        if (pageFillRadius != mRadius) {
            canvas.drawCircle(dX, dY, mRadius, mPaintStroke);
        }
    }

    //Draw the filled circle according to the current scroll
    float cx = (mSnap ? mSnapPage : mCurrentPage % count) * threeRadius;
    if (!mSnap) {
        cx += mPageOffset * 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.zxly.o2o.viewpagerindicator.CirclePageIndicator.java

@Override
protected void onDraw(Canvas canvas) {
    super.onDraw(canvas);
    if (mViewPager == null) {
        return;/* w w  w. j a  v  a2  s .c  o  m*/
    }

    //?? 
    final int count = (realCount > 0) ? realCount : mViewPager.getAdapter().getCount();
    if (count <= 1) {
        return;
    }
    repeatedRoll();

    if (mCurrentPage >= count && realCount == 0) {
        setCurrentItem(count - 1);
    }

    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();
    }

    mItemMargin = (mItemMargin > 0) ? mItemMargin : mRadius;

    final float threeRadius = mRadius * 2 + mItemMargin;
    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;

    float pageFillRadius = mRadius;
    if (mPaintStroke.getStrokeWidth() > 0) {
        pageFillRadius -= mPaintStroke.getStrokeWidth() / 2.0f;
    }

    //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;
        }
        // Only paint fill if not completely transparent
        if (mPaintPageFill.getAlpha() > 0) {
            canvas.drawCircle(dX, dY, pageFillRadius, mPaintPageFill);
        }

        // Only paint stroke if a stroke width was non-zero
        if (pageFillRadius != mRadius) {
            canvas.drawCircle(dX, dY, mRadius, mPaintStroke);
        }
    }

    if (realCount > 0 && (mCurrentPage > realCount || mSnapPage > realCount))
        setCurrentPos(mCurrentPage);

    Log.d("currentItem",
            "mSnapPage :" + mSnapPage + "  mCurrentPage :" + mCurrentPage + " mPageOffset :" + mPageOffset);
    //Draw the filled circle according to the current scroll
    float cx = (mSnap ? mSnapPage : mCurrentPage) * threeRadius;
    if (!mSnap) {
        cx += mPageOffset * 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.cdhxqh.travel_ticket_app.viewpagerindicator.CirclePageIndicator.java

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

    if (mViewPager == null) {
        return;//from w  w w.  ja  v a 2s.  com
    }
    int length = mViewPager.getAdapter().getCount();
    if (mViewPager.getAdapter() instanceof Bee_PageAdapter) {
        length = ((Bee_PageAdapter) mViewPager.getAdapter()).getRealCount(); // ??
    }

    final int count = length;
    if (count == 0) {
        return;
    }

    int curSelectPage = mCurrentPage % count;
    if (curSelectPage >= count) {
        setCurrentItem(count - 1);
        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;

    float pageFillRadius = mRadius;
    if (mPaintStroke.getStrokeWidth() > 0) {
        pageFillRadius -= mPaintStroke.getStrokeWidth() / 2.0f;
    }

    //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;
        }
        // Only paint fill if not completely transparent
        if (mPaintPageFill.getAlpha() > 0) {
            canvas.drawCircle(dX, dY, pageFillRadius, mPaintPageFill);
        }

        // Only paint stroke if a stroke width was non-zero
        if (pageFillRadius != mRadius) {
            canvas.drawCircle(dX, dY, mRadius, mPaintStroke);
        }
    }

    //Draw the filled circle according to the current scroll
    float cx = (mSnap ? mSnapPage : curSelectPage) * threeRadius;
    if (!mSnap) {
        cx += mPageOffset * 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.miuhouse.yourcompany.student.view.widget.date.datepicker.SimpleMonthView.java

/**
 * Draws the month days./*from  ww  w. ja va2  s . c  o m*/
 */
@SuppressWarnings("ConstantConditions")
private void drawDays(Canvas canvas) {
    final TextPaint p = mDayPaint;
    final int headerHeight = mMonthHeight + mDayOfWeekHeight;

    final float rowHeight = mDayHeight;

    final float colWidth = mCellWidth;

    // Text is vertically centered within the row height.
    final float halfLineHeight = (p.ascent() + p.descent()) / 2f;
    //        int rowCenter = headerHeight + rowHeight / 2;
    float rowCenter = headerHeight + rowHeight / 2f;
    //mDaysInMonth303129
    for (int day = 1, col = findDayOffset(); day <= mDaysInMonth; day++) {
        final float colCenter = colWidth * col + colWidth / 2f;
        //final int colCenterRtl;
        final float colCenterRtl;
        if (SUtils.isLayoutRtlCompat(this)) {
            colCenterRtl = mPaddedWidth - colCenter;
        } else {
            colCenterRtl = colCenter;
        }

        int stateMask = 0;

        final boolean isDayEnabled = isDayEnabled(day);
        if (isDayEnabled) {
            stateMask |= SUtils.STATE_ENABLED;
        }

        final boolean isDayInActivatedRange = mActivatedDays.isValid() && mActivatedDays.isActivated(day);
        final boolean isSelected = mActivatedDays.isSelected(day);
        final boolean isSelectedAndTogether = mActivatedDays.isSelectedAndTogether(day);
        if (isSelectedAndTogether) {
            if ((!disable && !isDisable) || isFill) {
                stateMask |= SUtils.STATE_ACTIVATED;
                canvas.drawCircle(colCenterRtl, rowCenter, mDaySelectorRadius, mDaySelectorPaint);
            }
        }
        if (!isSelected && isDayInActivatedRange) {

            stateMask |= SUtils.STATE_ACTIVATED;
            int bgShape = DRAW_RECT;
            if (mActivatedDays.isSingleDay()) {
                if (mActivatedDays.isStartOfMonth()) {
                    bgShape = DRAW_RECT_WITH_CURVE_ON_RIGHT;
                } else {
                    bgShape = DRAW_RECT_WITH_CURVE_ON_LEFT;
                }
            } else if (mActivatedDays.isStartingDayOfRange(day)) {
                bgShape = DRAW_RECT_WITH_CURVE_ON_LEFT;
            } else if (mActivatedDays.isEndingDayOfRange(day)) {
                bgShape = DRAW_RECT_WITH_CURVE_ON_RIGHT;
            }

            // Use height to constrain the protrusion of the arc
            boolean constrainProtrusion = colWidth > (rowHeight - (2 * mPaddingRangeIndicator));

            float horDistFromCenter = constrainProtrusion ? rowHeight / 2f - mPaddingRangeIndicator
                    : colWidth / 2f;
            switch (bgShape) {
            case DRAW_RECT_WITH_CURVE_ON_LEFT:

                int leftRectArcLeft = (int) (colCenterRtl - horDistFromCenter) % 2 == 1
                        ? (int) (colCenterRtl - horDistFromCenter) + 1
                        : (int) (colCenterRtl - horDistFromCenter);

                int leftRectArcRight = (int) (colCenterRtl + horDistFromCenter) % 2 == 1
                        ? (int) (colCenterRtl + horDistFromCenter) + 1
                        : (int) (colCenterRtl + horDistFromCenter);

                RectF leftArcRect = new RectF(leftRectArcLeft,
                        rowCenter - rowHeight / 2f + mPaddingRangeIndicator, leftRectArcRight,
                        rowCenter + rowHeight / 2f - mPaddingRangeIndicator);

                canvas.drawArc(leftArcRect, 90, 180, true, mDayRangeSelectorPaint);

                canvas.drawRect(new RectF(leftArcRect.centerX(),
                        rowCenter - rowHeight / 2f + mPaddingRangeIndicator, colCenterRtl + colWidth / 2f,
                        rowCenter + rowHeight / 2f - mPaddingRangeIndicator), mDayRangeSelectorPaint);
                break;
            case DRAW_RECT_WITH_CURVE_ON_RIGHT:
                int rightRectArcLeft = (int) (colCenterRtl - horDistFromCenter) % 2 == 1
                        ? (int) (colCenterRtl - horDistFromCenter) + 1
                        : (int) (colCenterRtl - horDistFromCenter);

                int rightRectArcRight = (int) (colCenterRtl + horDistFromCenter) % 2 == 1
                        ? (int) (colCenterRtl + horDistFromCenter) + 1
                        : (int) (colCenterRtl + horDistFromCenter);

                RectF rightArcRect = new RectF(rightRectArcLeft,
                        rowCenter - rowHeight / 2f + mPaddingRangeIndicator, rightRectArcRight,
                        rowCenter + rowHeight / 2f - mPaddingRangeIndicator);

                canvas.drawArc(rightArcRect, 270, 180, true, mDayRangeSelectorPaint);

                canvas.drawRect(new RectF(colCenterRtl - colWidth / 2f,
                        rowCenter - rowHeight / 2f + mPaddingRangeIndicator, rightArcRect.centerX(),
                        rowCenter + rowHeight / 2f - mPaddingRangeIndicator), mDayRangeSelectorPaint);
                break;
            default:
                canvas.drawRect(new RectF(colCenterRtl - colWidth / 2f,
                        rowCenter - rowHeight / 2f + mPaddingRangeIndicator, colCenterRtl + colWidth / 2f,
                        rowCenter + rowHeight / 2f - mPaddingRangeIndicator), mDayRangeSelectorPaint);
                break;
            }
        }

        final boolean isDayToday = mToday == day;
        final int dayTextColor;
        if (isDayToday) {
            if (mActivatedDays.isClick && isSelected) {
                final int[] stateSet = SUtils.resolveStateSet(stateMask);
                dayTextColor = mDayTextColor.getColorForState(stateSet, 0);
            } else {
                dayTextColor = mDaySelectorPaint.getColor();
            }
        } else {
            final int[] stateSet = SUtils.resolveStateSet(stateMask);
            if (!mActivatedDays.isSingleDay()) {
                if (stateMask == 1) {
                    dayTextColor = mContext.getResources().getColor(R.color.textDarkfour);
                } else {
                    dayTextColor = mDayTextColor.getColorForState(stateSet, 0);
                }
            } else {
                dayTextColor = mDayTextColor.getColorForState(stateSet, 0);
            }
        }
        p.setColor(dayTextColor);

        canvas.drawText(mDayFormatter.format(day), colCenterRtl, rowCenter - halfLineHeight, p);

        col++;

        if (col == DAYS_IN_WEEK) {
            col = 0;
            rowCenter += rowHeight;
        }
        if (mDaysInMonth == day)
            mOnRangeClickListener.onRangeSelected(calendars, position);
    }
}

From source file:com.taobao.luaview.view.indicator.circle.CirclePageIndicator.java

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

    if (mViewPager == null) {
        return;//from  w  ww .ja v  a  2  s  . co  m
    }
    final int count = getActualCount();
    if (count == 0) {
        return;
    }
    final int instanceCount = getInstanceCount();
    if (instanceCount == 0) {
        return;
    }

    int totalCount = mViewPager.getAdapter() == null ? 0 : mViewPager.getAdapter().getCount();
    if (mCurrentPage >= totalCount) {
        setCurrentItem(totalCount - 1);
        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)
                - ((instanceCount * threeRadius) / 2.0f);
    }

    float dX;
    float dY;

    float pageFillRadius = mRadius;
    if (mPaintStroke.getStrokeWidth() > 0) {
        pageFillRadius -= mPaintStroke.getStrokeWidth() / 2.0f;
    }

    //Draw stroked circles
    for (int iLoop = 0; iLoop < instanceCount; iLoop++) {
        float drawLong = longOffset + (iLoop * threeRadius);
        if (mOrientation == HORIZONTAL) {
            dX = drawLong;
            dY = shortOffset;
        } else {
            dX = shortOffset;
            dY = drawLong;
        }
        // Only paint fill if not completely transparent
        if (mPaintPageFill.getAlpha() > 0) {
            canvas.drawCircle(dX, dY, pageFillRadius, mPaintPageFill);
        }

        // Only paint stroke if a stroke width was non-zero
        if (pageFillRadius != mRadius) {
            canvas.drawCircle(dX, dY, mRadius, mPaintStroke);
        }
    }

    //Draw the filled circle according to the current scroll
    float cx = (mSnap ? mSnapPage % instanceCount : mCurrentPage % count) * threeRadius;
    if (!mSnap) {
        cx += mPageOffset * threeRadius;
    } else {
        cx = (mCurrentPage % instanceCount) * 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.example.myttpod3.indicator.CirclePageIndicator.java

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

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

    if (mCurrentPage >= count) {
        setCurrentItem(count - 1);
        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 twoRadius = mRadius * 2;
    final float shortOffset = shortPaddingBefore + mRadius;
    float longOffset = longPaddingBefore + mRadius;
    if (mCentered) {
        longOffset += ((longSize - longPaddingBefore - longPaddingAfter) / 2.0f) - ((count * twoRadius) / 2.0f)
                - ((count * mInterval) / 2.0f);
        //            longOffset += ((longSize - longPaddingBefore - longPaddingAfter) / 2.0f) - ((count * threeRadius) / 2.0f);
    }

    float dX;
    float dY;

    float pageFillRadius = mRadius;
    if (mPaintStroke.getStrokeWidth() > 0) {
        pageFillRadius -= mPaintStroke.getStrokeWidth() / 2.0f;
    }

    //Draw stroked circles
    for (int iLoop = 0; iLoop < count; iLoop++) {
        float drawLong = longOffset + (iLoop * twoRadius) + (iLoop * mInterval);
        //            float drawLong = longOffset + (iLoop * threeRadius);
        if (mOrientation == HORIZONTAL) {
            dX = drawLong;
            dY = shortOffset;
        } else {
            dX = shortOffset;
            dY = drawLong;
        }
        // Only paint fill if not completely transparent
        if (mPaintPageFill.getAlpha() > 0) {
            canvas.drawCircle(dX, dY, pageFillRadius, mPaintPageFill);
        }

        // Only paint stroke if a stroke width was non-zero
        if (pageFillRadius != mRadius) {
            canvas.drawCircle(dX, dY, mRadius, mPaintStroke);
        }
    }

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

From source file:com.icloud.listenbook.base.view.viewpagerindicator.CirclePageIndicator.java

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

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

    if (mCurrentPage >= count) {
        setCurrentItem(count - 1);
        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();
    }
    //  3  1? ??? 2
    final float threeRadius = (mRadius) * 3 + spacing;
    final float shortOffset = shortPaddingBefore + mRadius;
    float longOffset = longPaddingBefore + threeRadius / 2;
    if (mCentered) {
        // 
        longOffset += ((longSize - longPaddingBefore - longPaddingAfter) / 2.0f)
                - ((count * threeRadius) / 2.0f);
    }

    float dX;
    float dY;

    float pageFillRadius = mRadius;
    if (mPaintStroke.getStrokeWidth() > 0) {
        pageFillRadius -= mPaintStroke.getStrokeWidth() / 2.0f;
    }

    //  ????
    for (int iLoop = 0; iLoop < count; iLoop++) {
        float drawLong = longOffset + (iLoop * threeRadius);
        // ??  ?X Y
        if (mOrientation == HORIZONTAL) {
            dX = drawLong;
            dY = shortOffset;
        } else {
            dX = shortOffset;
            dY = drawLong;
        }
        // ?? ?
        if (mPaintPageFill.getAlpha() > 0) {
            canvas.drawCircle(dX, dY, pageFillRadius, mPaintPageFill);
        }

        // 
        if (pageFillRadius != mRadius) {
            canvas.drawCircle(dX, dY, mRadius, mPaintStroke);
        }
    }

    /*
     * ?  ,? ? ?  X?
     */
    float cx = (mSnap ? mSnapPage : mCurrentPage) * threeRadius;
    // 
    if (!mSnap) {
        // ??
        cx += mPageOffset * threeRadius;
    }
    if (mOrientation == HORIZONTAL) {
        dX = longOffset + cx;
        dY = shortOffset;
    } else {
        dX = shortOffset;
        dY = longOffset + cx;
    }
    // 
    canvas.drawCircle(dX, dY, mRadius, mPaintFill);
}