From 120419d4c9f725d99feccd408c7f0cc2fb949309 Mon Sep 17 00:00:00 2001 From: pivinci Date: Sun, 23 Aug 2015 11:34:46 +0700 Subject: [PATCH 1/2] Add spacing attribute to CirclePageIndicator --- library/res/values/vpi__attrs.xml | 4 +++- .../com/viewpagerindicator/CirclePageIndicator.java | 12 +++++++----- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/library/res/values/vpi__attrs.xml b/library/res/values/vpi__attrs.xml index a4d1f1093..51040b4a8 100644 --- a/library/res/values/vpi__attrs.xml +++ b/library/res/values/vpi__attrs.xml @@ -45,8 +45,10 @@ - + + + diff --git a/library/src/com/viewpagerindicator/CirclePageIndicator.java b/library/src/com/viewpagerindicator/CirclePageIndicator.java index f441e89fd..07c68274c 100644 --- a/library/src/com/viewpagerindicator/CirclePageIndicator.java +++ b/library/src/com/viewpagerindicator/CirclePageIndicator.java @@ -45,6 +45,7 @@ public class CirclePageIndicator extends View implements PageIndicator { private static final int INVALID_POINTER = -1; private float mRadius; + private float mSpacing; private final Paint mPaintPageFill = new Paint(ANTI_ALIAS_FLAG); private final Paint mPaintStroke = new Paint(ANTI_ALIAS_FLAG); private final Paint mPaintFill = new Paint(ANTI_ALIAS_FLAG); @@ -100,6 +101,7 @@ public CirclePageIndicator(Context context, AttributeSet attrs, int defStyle) { mPaintFill.setStyle(Style.FILL); mPaintFill.setColor(a.getColor(R.styleable.CirclePageIndicator_fillColor, defaultFillColor)); mRadius = a.getDimension(R.styleable.CirclePageIndicator_radius, defaultRadius); + mSpacing = a.getDimension(R.styleable.CirclePageIndicator_spacing, mRadius); mSnap = a.getBoolean(R.styleable.CirclePageIndicator_snap, defaultSnap); Drawable background = a.getDrawable(R.styleable.CirclePageIndicator_android_background); @@ -227,11 +229,11 @@ protected void onDraw(Canvas canvas) { shortPaddingBefore = getPaddingLeft(); } - final float threeRadius = mRadius * 3; + final float offsetDiff = mRadius * 2 + mSpacing; final float shortOffset = shortPaddingBefore + mRadius; float longOffset = longPaddingBefore + mRadius; if (mCentered) { - longOffset += ((longSize - longPaddingBefore - longPaddingAfter) / 2.0f) - ((count * threeRadius) / 2.0f); + longOffset += ((longSize - longPaddingBefore - longPaddingAfter) / 2.0f) - (((count - 1) * offsetDiff + mRadius * 2) / 2.0f); } float dX; @@ -244,7 +246,7 @@ protected void onDraw(Canvas canvas) { //Draw stroked circles for (int iLoop = 0; iLoop < count; iLoop++) { - float drawLong = longOffset + (iLoop * threeRadius); + float drawLong = longOffset + (iLoop * offsetDiff); if (mOrientation == HORIZONTAL) { dX = drawLong; dY = shortOffset; @@ -264,9 +266,9 @@ protected void onDraw(Canvas canvas) { } //Draw the filled circle according to the current scroll - float cx = (mSnap ? mSnapPage : mCurrentPage) * threeRadius; + float cx = (mSnap ? mSnapPage : mCurrentPage) * offsetDiff; if (!mSnap) { - cx += mPageOffset * threeRadius; + cx += mPageOffset * offsetDiff; } if (mOrientation == HORIZONTAL) { dX = longOffset + cx; From 44dfc03059a36384b6178b7a6a38763b5a91faff Mon Sep 17 00:00:00 2001 From: pivinci Date: Sun, 23 Aug 2015 11:42:46 +0700 Subject: [PATCH 2/2] Add getter and setter for spacing attribute --- .../src/com/viewpagerindicator/CirclePageIndicator.java | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/library/src/com/viewpagerindicator/CirclePageIndicator.java b/library/src/com/viewpagerindicator/CirclePageIndicator.java index 07c68274c..919fa822a 100644 --- a/library/src/com/viewpagerindicator/CirclePageIndicator.java +++ b/library/src/com/viewpagerindicator/CirclePageIndicator.java @@ -187,6 +187,15 @@ public float getRadius() { return mRadius; } + public void setSpacing(float spacing) { + mSpacing = spacing; + invalidate(); + } + + public float getSpacing() { + return mSpacing; + } + public void setSnap(boolean snap) { mSnap = snap; invalidate();