List of usage examples for android.graphics Canvas drawCircle
public void drawCircle(float cx, float cy, float radius, @NonNull Paint paint)
From source file:com.appeaser.sublimepickerlibrary.timepicker.RadialTimePickerView.java
private void drawSelector(Canvas canvas, int index, Path selectorPath, float alphaMod) { final int alpha = (int) (mAlpha[index % 2].getValue() * alphaMod + 0.5f); final int color = applyAlpha(mSelectorColor, alpha); // Calculate the current radius at which to place the selection circle. final int selRadius = mSelectorRadius; final int selLength = mCircleRadius - mTextInset[index]; final double selAngleRad = Math.toRadians(mSelectionDegrees[index % 2]); final float selCenterX = mXCenter + selLength * (float) Math.sin(selAngleRad); final float selCenterY = mYCenter - selLength * (float) Math.cos(selAngleRad); // Draw the selection circle. final Paint paint = mPaintSelector[index % 2][SELECTOR_CIRCLE]; paint.setColor(color);/*w w w.ja va2 s . c o m*/ canvas.drawCircle(selCenterX, selCenterY, selRadius, paint); // If needed, set up the clip path for later. if (selectorPath != null) { selectorPath.reset(); selectorPath.addCircle(selCenterX, selCenterY, selRadius, Path.Direction.CCW); } // Draw the dot if we're between two items. final boolean shouldDrawDot = mSelectionDegrees[index % 2] % 30 != 0; if (shouldDrawDot) { final Paint dotPaint = mPaintSelector[index % 2][SELECTOR_DOT]; dotPaint.setColor(mSelectorDotColor); canvas.drawCircle(selCenterX, selCenterY, mSelectorDotRadius, dotPaint); } // Shorten the line to only go from the edge of the center dot to the // edge of the selection circle. final double sin = Math.sin(selAngleRad); final double cos = Math.cos(selAngleRad); final int lineLength = selLength - selRadius; final int centerX = mXCenter + (int) (mCenterDotRadius * sin); final int centerY = mYCenter - (int) (mCenterDotRadius * cos); final float linePointX = centerX + (int) (lineLength * sin); final float linePointY = centerY - (int) (lineLength * cos); // Draw the line. final Paint linePaint = mPaintSelector[index % 2][SELECTOR_LINE]; linePaint.setColor(color); linePaint.setStrokeWidth(mSelectorStroke); canvas.drawLine(mXCenter, mYCenter, linePointX, linePointY, linePaint); }
From source file:com.kerkr.edu.widget.viewpager.CircleZoomPageIndicator.java
@Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); if (mViewPager == null || mTrueSize <= 0) return;/*ww w. j a va 2s . c o m*/ final int count = mTrueSize; 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; } if (iLoop == mCurrentPage % mTrueSize && mTrueSize > 1) { canvas.drawCircle(dX, dY, mRadiusCur, mPaintCur); } else if (iLoop == mTargetPage % mTrueSize) { canvas.drawCircle(dX, dY, mRadiusTarget, mPaintTarget); } else { canvas.drawCircle(dX, dY, mRadius, mPaintNormal); } } // // // 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.viewpagerindicator.EgouCirclePageIndicator.java
@Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); if (mViewPager == null || mCount == 0) { return;/*from w w w . j ava 2s . c o m*/ } 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 * 4; final float shortOffset = shortPaddingBefore + mRadius; float longOffset = longPaddingBefore + mRadius / 2.0f; if (mCentered) { longOffset = ((longSize - longPaddingBefore - longPaddingAfter) / 2.0f) - (((mCount - 1) * mCirclePadding) / 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 < mCount; iLoop++) { float drawLong = longOffset + (iLoop * mCirclePadding); 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 = mCurrentPage * mCirclePadding; if (!mSnap) { cx += mPageOffset * mCirclePadding; } if (mOrientation == HORIZONTAL) { dX = longOffset + cx; dY = shortOffset; } else { dX = shortOffset; dY = longOffset + cx; } canvas.drawCircle(dX, dY, mRadius, mPaintFill); }
From source file:connect.app.com.connect.calendar.SimpleMonthView.java
/** * Draws the month days.//from w w w .j a v a2s . c o m */ private void drawDays(Canvas canvas) { final TextPaint p = mDayPaint; final int headerHeight = mMonthHeight + mDayOfWeekHeight; final int rowHeight = mDayHeight; final int colWidth = mCellWidth; // Text is vertically centered within the row height. final float halfLineHeight = (p.ascent() + p.descent()) / 2f; int rowCenter = headerHeight + rowHeight / 2; for (int day = 1, col = findDayOffset(); day <= mDaysInMonth; day++) { final int colCenter = colWidth * col + colWidth / 2; final int colCenterRtl = colCenter; // if (isLayoutRtl()) { // colCenterRtl = mPaddedWidth - colCenter; // } else { // colCenterRtl = colCenter; // } int stateMask = 0; final boolean isDayEnabled = isDayEnabled(day); // if (isDayEnabled) { // stateMask |= StateSet.VIEW_STATE_ENABLED; // } final boolean isDayActivated = mActivatedDay == day; if (isDayActivated) { // stateMask |= StateSet.VIEW_STATE_ACTIVATED; // Adjust the circle to be centered on the row. canvas.drawCircle(colCenterRtl, rowCenter, mDaySelectorRadius, mDaySelectorPaint); } else if (mTouchedItem == day) { // stateMask |= StateSet.VIEW_STATE_PRESSED; if (isDayEnabled) { // Adjust the circle to be centered on the row. canvas.drawCircle(colCenterRtl, rowCenter, mDaySelectorRadius, mDayHighlightPaint); } } final boolean isDayToday = mToday == day; int dayTextColor = 0; if (isDayToday && !isDayActivated) { dayTextColor = mDaySelectorPaint.getColor(); } else { // final int[] stateSet = StateSet.get(stateMask); // 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; } } }
From source file:com.gm.common.ui.widget.pageindicator.PageIndicatorView.java
private void drawWithColorAnimation(@NonNull Canvas canvas, int position, int x, int y) { int color = unselectedColor; if (interactiveAnimation) { if (position == selectingPosition) { color = frameColor;/*w ww .j a v a2 s. co m*/ } else if (position == selectedPosition) { color = frameColorReverse; } } else { if (position == selectedPosition) { color = frameColor; } else if (position == lastSelectedPosition) { color = frameColorReverse; } } fillPaint.setColor(color); canvas.drawCircle(x, y, radiusPx, fillPaint); }
From source file:com.android.tabletcustomui.views.LeftCircleContainer.java
private void addCircle(int position, final int value, float diff, double ratio) { final int radius = value / 2; final RectF mOval = new RectF(); mOval.set(0 + diff, 0 + diff, value - diff, value - diff); final Paint mPaintClip = new Paint(); mPaintClip.setStyle(Paint.Style.FILL); mPaintClip.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.OVERLAY)); mPaintClip.setAntiAlias(true);/*w w w . ja v a 2 s .co m*/ final PointF pointF = new PointF(mOval.centerX(), mOval.centerY()); final Path clipPath = new Path(); clipPath.addCircle(pointF.x, pointF.y, (float) (radius * ratio), Path.Direction.CW); View circleView; if (position == 0) { mPaintClip.setColor(getContext().getResources().getColor(R.color.circle_light_blue)); circleView = new View(getContext()) { @Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); canvas.clipPath(clipPath, Region.Op.DIFFERENCE); canvas.drawArc(mOval, 330, 10, true, mPaintClip); canvas.drawArc(mOval, 342, 20, true, mPaintClip); canvas.drawArc(mOval, 4, 10, true, mPaintClip); canvas.drawArc(mOval, 240, 10, true, mPaintClip); canvas.drawArc(mOval, 252, 20, true, mPaintClip); canvas.drawArc(mOval, 275, 10, true, mPaintClip); canvas.drawArc(mOval, 150, 10, true, mPaintClip); canvas.drawArc(mOval, 162, 20, true, mPaintClip); canvas.drawArc(mOval, 185, 10, true, mPaintClip); canvas.drawArc(mOval, 60, 10, true, mPaintClip); canvas.drawArc(mOval, 72, 20, true, mPaintClip); canvas.drawArc(mOval, 95, 10, true, mPaintClip); } }; FrameLayout.LayoutParams layoutParams = new FrameLayout.LayoutParams(value, value); layoutParams.gravity = Gravity.CENTER_VERTICAL | Gravity.CENTER_HORIZONTAL; circleView.setLayoutParams(layoutParams); this.addView(circleView); animateClockWise(circleView); } else if (position == 1) { mPaintClip.setColor(getContext().getResources().getColor(R.color.circle_dark_blue)); circleView = new View(getContext()) { @Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); canvas.clipPath(clipPath, Region.Op.DIFFERENCE); canvas.drawCircle(pointF.x, pointF.y, radius, mPaintClip); } }; FrameLayout.LayoutParams layoutParams = new FrameLayout.LayoutParams(value, value); layoutParams.gravity = Gravity.CENTER_VERTICAL | Gravity.CENTER_HORIZONTAL; circleView.setLayoutParams(layoutParams); this.addView(circleView); animateClockWise(circleView); } else if (position == 2) { mPaintClip.setColor(getContext().getResources().getColor(R.color.circle_light_blue)); circleView = new View(getContext()) { @Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); canvas.clipPath(clipPath, Region.Op.DIFFERENCE); canvas.drawArc(mOval, 55, 190, true, mPaintClip); } }; FrameLayout.LayoutParams layoutParams = new FrameLayout.LayoutParams(value, value); layoutParams.gravity = Gravity.CENTER_VERTICAL | Gravity.CENTER_HORIZONTAL; circleView.setLayoutParams(layoutParams); this.addView(circleView); animateClockWise(circleView); } else if (position == 3) { mPaintClip.setColor(getContext().getResources().getColor(R.color.circle_light_blue)); circleView = new View(getContext()) { @Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); canvas.clipPath(clipPath, Region.Op.DIFFERENCE); canvas.drawArc(mOval, 240, 190, true, mPaintClip); canvas.drawArc(mOval, 80, 150, true, mPaintClip); } }; FrameLayout.LayoutParams layoutParams = new FrameLayout.LayoutParams(value, value); layoutParams.gravity = Gravity.CENTER_VERTICAL | Gravity.CENTER_HORIZONTAL; circleView.setLayoutParams(layoutParams); this.addView(circleView); animateClockWise(circleView); } else if (position == 4) { mPaintClip.setColor(getContext().getResources().getColor(R.color.circle_light_blue)); circleView = new View(getContext()) { @Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); canvas.clipPath(clipPath, Region.Op.DIFFERENCE); canvas.drawArc(mOval, 335, 150, true, mPaintClip); canvas.drawArc(mOval, 140, 180, true, mPaintClip); } }; FrameLayout.LayoutParams layoutParams = new FrameLayout.LayoutParams(value, value); layoutParams.gravity = Gravity.CENTER_VERTICAL | Gravity.CENTER_HORIZONTAL; circleView.setLayoutParams(layoutParams); this.addView(circleView); animateClockWise(circleView); } else if (position == 5) { mPaintClip.setColor(getContext().getResources().getColor(R.color.circle_light_grey)); circleView = new View(getContext()) { @Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); canvas.clipPath(clipPath, Region.Op.DIFFERENCE); canvas.drawArc(mOval, 330, 150, true, mPaintClip); canvas.drawArc(mOval, 140, 150, true, mPaintClip); } }; FrameLayout.LayoutParams layoutParams = new FrameLayout.LayoutParams(value, value); layoutParams.gravity = Gravity.CENTER_VERTICAL | Gravity.CENTER_HORIZONTAL; circleView.setLayoutParams(layoutParams); this.addView(circleView); animateClockWise(circleView); } else if (position == 6) { mPaintClip.setColor(getContext().getResources().getColor(R.color.circle_purple_color)); circleView = new View(getContext()) { @Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); canvas.clipPath(clipPath, Region.Op.DIFFERENCE); canvas.drawArc(mOval, 290, 5, true, mPaintClip); canvas.drawArc(mOval, 297, 20, true, mPaintClip); canvas.drawArc(mOval, 319, 20, true, mPaintClip); canvas.drawArc(mOval, 60, 15, true, mPaintClip); canvas.drawArc(mOval, 77, 8, true, mPaintClip); } }; FrameLayout.LayoutParams layoutParams = new FrameLayout.LayoutParams(value, value); layoutParams.gravity = Gravity.CENTER_VERTICAL | Gravity.CENTER_HORIZONTAL; circleView.setLayoutParams(layoutParams); this.addView(circleView); animateClockWise(circleView); } else if (position == 7) { mPaintClip.setColor(getContext().getResources().getColor(R.color.circle_dark_blue)); circleView = new View(getContext()) { @Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); canvas.clipPath(clipPath, Region.Op.DIFFERENCE); canvas.drawArc(mOval, 160, 10, true, mPaintClip); canvas.drawArc(mOval, 172, 30, true, mPaintClip); canvas.drawArc(mOval, 204, 30, true, mPaintClip); canvas.drawArc(mOval, 236, 10, true, mPaintClip); canvas.drawArc(mOval, 20, 20, true, mPaintClip); canvas.drawArc(mOval, 42, 8, true, mPaintClip); } }; FrameLayout.LayoutParams layoutParams = new FrameLayout.LayoutParams(value, value); layoutParams.gravity = Gravity.CENTER_VERTICAL | Gravity.CENTER_HORIZONTAL; circleView.setLayoutParams(layoutParams); this.addView(circleView); animateAntiClockWise(circleView); } }
From source file:com.layer_net.stepindicator.StepIndicator.java
@Override protected void onDraw(Canvas canvas) { if (stepsCount <= 1) { setVisibility(GONE);//from ww w. j av a 2 s . co m return; } super.onDraw(canvas); int pointX = startX; int pointOffset; /** draw Line */ for (int i = 0; i < stepsCount - 1; i++) { if (i < currentStepPosition) { paint.setColor(stepColor); canvas.drawLine(pointX, centerY, pointX + stepDistance, centerY, paint); } else if (i == currentStepPosition) { paint.setColor(backgroundColor); canvas.drawLine(pointX, centerY, pointX + stepDistance, centerY, paint); } else { paint.setColor(backgroundColor); canvas.drawLine(pointX, centerY, pointX + stepDistance, centerY, paint); } pointX = pointX + stepDistance; } /**draw progress Line */ if (offsetPixel != 0 && pagerScrollState == 1) { pointOffset = startX + (currentStepPosition * stepDistance); int drawOffset = pointOffset + offsetPixel; if (drawOffset >= startX && drawOffset <= endX) { if (offsetPixel < 0) { paint.setColor(backgroundColor); } else { paint.setColor(stepColor); } canvas.drawLine(pointOffset, centerY, drawOffset, centerY, paint); } } /**draw Circle */ pointX = startX; for (int i = 0; i < stepsCount; i++) { if (i < currentStepPosition) { //draw previous step paint.setColor(stepColor); canvas.drawCircle(pointX, centerY, radius, paint); //draw transition if (i == currentStepPosition - 1 && offsetPixel < 0 && pagerScrollState == 1) { pStoke.setAlpha(255); pStoke.setStrokeWidth(strokeWidth - Math.round(strokeWidth * offset)); canvas.drawCircle(pointX, centerY, radius, pStoke); } pText.setColor(secondaryTextColor); } else if (i == currentStepPosition) { //draw current step if (offsetPixel == 0 || pagerScrollState == 0) { //set stroke default paint.setColor(currentColor); pStoke.setStrokeWidth(Math.round(strokeWidth)); pStoke.setAlpha(255); } else if (offsetPixel < 0) { pStoke.setStrokeWidth(Math.round(strokeWidth * offset)); pStoke.setAlpha(Math.round(offset * 255f)); paint.setColor(getColorToBG(offset)); } else { //set stroke transition paint.setColor(getColorToProgess(offset)); pStoke.setStrokeWidth(strokeWidth - Math.round(strokeWidth * offset)); pStoke.setAlpha(255 - Math.round(offset * 255f)); } canvas.drawCircle(pointX, centerY, radius, paint); canvas.drawCircle(pointX, centerY, radius, pStoke); pText.setColor(textColor); } else { //draw next step paint.setColor(backgroundColor); canvas.drawCircle(pointX, centerY, radius, paint); pText.setColor(secondaryTextColor); //draw transition if (i == currentStepPosition + 1 && offsetPixel > 0 && pagerScrollState == 1) { pStoke.setStrokeWidth(Math.round(strokeWidth * offset)); pStoke.setAlpha(Math.round(offset * 255f)); canvas.drawCircle(pointX, centerY, radius, pStoke); } } drawTextCentred(canvas, pText, String.valueOf(i + 1), pointX, centerY); pointX = pointX + stepDistance; } }
From source file:com.cleveroad.slidingtutorial.CirclePageIndicator.java
@Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); if (mViewPager == null) { return;/*from w w w . j a va2 s . c o m*/ } final int count = mRealPagesCount; 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 = 0; float dY = 0; 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); } } float lastDx = dX; float lastDy = dY; //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; } if (mOrientation == HORIZONTAL) { canvas.clipRect(longOffset - mRadius, 0, lastDx + mRadius, canvas.getHeight()); } else { canvas.clipRect(0, 0, getWidth(), lastDy + mRadius); } canvas.drawCircle(dX, dY, mRadius, mPaintFill); if (mOrientation == HORIZONTAL && dX > lastDx || mOrientation == VERTICAL && dY > lastDy) { if (mOrientation == HORIZONTAL) { canvas.drawCircle(longOffset + dX - lastDx - threeRadius, dY, mRadius, mPaintFill); } else { canvas.drawCircle(dX, longOffset + dY - lastDy - threeRadius, mRadius, mPaintFill); } } }
From source file:org.smart.library.widget.CircleIndicator.java
@Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); if (mViewCounts == 0) { return;//from w w w. j a va 2 s. co m } if (mCurrentPage >= mViewCounts) { setCurrentItem(mViewCounts - 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) - ((mViewCounts * 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 < mViewCounts; 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 mCurrent 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.viewpagerindicator.ViewCirclePageIndicator.java
@Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); if (count == 0) { return;/*from ww w . ja v a 2 s . c o m*/ } 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 + 2; 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 : 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 + 2, mPaintFill); }