Skip to content
This repository has been archived by the owner on Apr 19, 2018. It is now read-only.

extra spacing option for CirclePagerIndicator #425

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions library/res/values/vpi__attrs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@
<attr name="strokeColor" format="color" />
<!-- Width of the stroke used to draw the circles. -->
<attr name="strokeWidth" />
<!-- Extra space between the circles. -->
<attr name="extraSpacing" format="dimension" />
<!-- View background -->
<attr name="android:background"/>
</declare-styleable>
Expand Down
1 change: 1 addition & 0 deletions library/res/values/vpi__defaults.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
<bool name="default_circle_indicator_snap">false</bool>
<color name="default_circle_indicator_stroke_color">#FFDDDDDD</color>
<dimen name="default_circle_indicator_stroke_width">1dp</dimen>
<dimen name="default_circle_indicator_extra_spacing">0dp</dimen>

<dimen name="default_line_indicator_line_width">12dp</dimen>
<dimen name="default_line_indicator_gap_width">4dp</dimen>
Expand Down
12 changes: 9 additions & 3 deletions library/src/com/viewpagerindicator/CirclePageIndicator.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public class CirclePageIndicator extends View implements PageIndicator {
private float mLastMotionX = -1;
private int mActivePointerId = INVALID_POINTER;
private boolean mIsDragging;

private float mExtraSpacing;

public CirclePageIndicator(Context context) {
this(context, null);
Expand All @@ -84,6 +84,7 @@ public CirclePageIndicator(Context context, AttributeSet attrs, int defStyle) {
final int defaultStrokeColor = res.getColor(R.color.default_circle_indicator_stroke_color);
final float defaultStrokeWidth = res.getDimension(R.dimen.default_circle_indicator_stroke_width);
final float defaultRadius = res.getDimension(R.dimen.default_circle_indicator_radius);
final float defaultExtraSpacing = res.getDimension(R.dimen.default_circle_indicator_extra_spacing);
final boolean defaultCentered = res.getBoolean(R.bool.default_circle_indicator_centered);
final boolean defaultSnap = res.getBoolean(R.bool.default_circle_indicator_snap);

Expand All @@ -101,6 +102,7 @@ public CirclePageIndicator(Context context, AttributeSet attrs, int defStyle) {
mPaintFill.setColor(a.getColor(R.styleable.CirclePageIndicator_fillColor, defaultFillColor));
mRadius = a.getDimension(R.styleable.CirclePageIndicator_radius, defaultRadius);
mSnap = a.getBoolean(R.styleable.CirclePageIndicator_snap, defaultSnap);
mExtraSpacing = a.getDimension(R.styleable.CirclePageIndicator_extraSpacing, defaultExtraSpacing);

Drawable background = a.getDrawable(R.styleable.CirclePageIndicator_android_background);
if (background != null) {
Expand Down Expand Up @@ -194,6 +196,10 @@ public boolean isSnap() {
return mSnap;
}

public void setExtraSpacing(float extraSpacing) {
mExtraSpacing = extraSpacing;
}

@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
Expand Down Expand Up @@ -227,7 +233,7 @@ protected void onDraw(Canvas canvas) {
shortPaddingBefore = getPaddingLeft();
}

final float threeRadius = mRadius * 3;
final float threeRadius = mRadius * 3 + mExtraSpacing;
final float shortOffset = shortPaddingBefore + mRadius;
float longOffset = longPaddingBefore + mRadius;
if (mCentered) {
Expand Down Expand Up @@ -469,7 +475,7 @@ private int measureLong(int measureSpec) {
//Calculate the width according the views count
final int count = mViewPager.getAdapter().getCount();
result = (int)(getPaddingLeft() + getPaddingRight()
+ (count * 2 * mRadius) + (count - 1) * mRadius + 1);
+ (count * 2 * mRadius) + (count - 1) * (mRadius + mExtraSpacing) + 1);
//Respect AT_MOST value if that was what is called for by measureSpec
if (specMode == MeasureSpec.AT_MOST) {
result = Math.min(result, specSize);
Expand Down