Skip to content

Commit

Permalink
Bug fixing and renamed properties that ambiguous
Browse files Browse the repository at this point in the history
  • Loading branch information
anton46 committed Jul 1, 2015
1 parent 379b214 commit b27d593
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 26 deletions.
65 changes: 48 additions & 17 deletions library/src/main/java/com/anton46/stepsview/StepsView.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,10 @@ public class StepsView extends LinearLayout implements StepsViewIndicator.OnDraw
private StepsViewIndicator mStepsViewIndicator;
private FrameLayout mLabelsLayout;
private String[] mLabels;
private int mCompletedPosition;
private int mLabelColor = Color.BLACK;
private int mProgressColorIndicator = Color.YELLOW;
private int mLabelColorIndicator = Color.BLACK;
private int mBarColorIndicator = Color.BLACK;
private int mCompletedPosition = 0;

public StepsView(Context context) {
this(context, null);
Expand All @@ -43,39 +45,69 @@ private void init() {
mLabelsLayout = (FrameLayout) rootView.findViewById(R.id.labels_container);
}

public String[] getLabels() {
return mLabels;
}

public StepsView setLabels(String[] labels) {
mLabels = labels;
mStepsViewIndicator.setSize(mLabels.length);
mStepsViewIndicator.setStepSize(labels.length);
return this;
}

public int getCompletedPosition() {
return mCompletedPosition;
public int getProgressColorIndicator() {
return mProgressColorIndicator;
}

public StepsView setCompletedPosition(int completedPosition) {
mCompletedPosition = completedPosition;
mStepsViewIndicator.setCompletedPosition(completedPosition);
public StepsView setProgressColorIndicator(int progressColorIndicator) {
mProgressColorIndicator = progressColorIndicator;
mStepsViewIndicator.setProgressColor(mProgressColorIndicator);
return this;
}

public StepsView setColorIndicator(int color) {
mStepsViewIndicator.setThumbColor(color);
public int getLabelColorIndicator() {
return mLabelColorIndicator;
}

public StepsView setLabelColorIndicator(int labelColorIndicator) {
mLabelColorIndicator = labelColorIndicator;
return this;
}

public StepsView setBarColor(int color) {
mStepsViewIndicator.setBarColor(color);
public int getBarColorIndicator() {
return mBarColorIndicator;
}

public StepsView setBarColorIndicator(int barColorIndicator) {
mBarColorIndicator = barColorIndicator;
mStepsViewIndicator.setBarColor(mBarColorIndicator);
return this;
}

public StepsView setLabelColor(int labelColor) {
mLabelColor = labelColor;
public int getCompletedPosition() {
return mCompletedPosition;
}

public StepsView setCompletedPosition(int completedPosition) {
mCompletedPosition = completedPosition;
mStepsViewIndicator.setCompletedPosition(mCompletedPosition);
return this;
}

public void drawView() {
if (mLabels == null) {
throw new IllegalArgumentException("labels must not be null.");
}

if (mCompletedPosition < 0 || mCompletedPosition > mLabels.length - 1) {
throw new IndexOutOfBoundsException(String.format("Index : %s, Size : %s", mCompletedPosition, mLabels.length));
}

mStepsViewIndicator.invalidate();
}

@Override
public void onFinish() {
public void onReady() {
drawLabels();
}

Expand All @@ -86,7 +118,7 @@ private void drawLabels() {
for (int i = 0; i < mLabels.length; i++) {
TextView textView = new TextView(getContext());
textView.setText(mLabels[i]);
textView.setTextColor(mLabelColor);
textView.setTextColor(mLabelColorIndicator);
textView.setX(indicatorPosition.get(i));
textView.setLayoutParams(
new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
Expand All @@ -100,5 +132,4 @@ private void drawLabels() {
}
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public class StepsViewIndicator extends View {
private float mThumbRadius;
private float mCircleRadius;
private float mPadding;
private int mThumbColor = Color.YELLOW;
private int mProgressColor = Color.YELLOW;
private int mBarColor = Color.BLACK;

private float mCenterY;
Expand Down Expand Up @@ -61,7 +61,7 @@ private void init() {
mPadding = 0.5f * THUMB_SIZE;
}

public void setSize(int size) {
public void setStepSize(int size) {
mNumOfStep = size;
invalidate();
}
Expand Down Expand Up @@ -90,7 +90,7 @@ public void onSizeChanged(int w, int h, int oldw, int oldh) {
mThumbContainerXPosition.add(mLeftX + (i * mDelta));
}
mThumbContainerXPosition.add(mRightX);
mDrawListener.onFinish();
mDrawListener.onReady();
}

@Override
Expand All @@ -108,15 +108,14 @@ protected synchronized void onMeasure(int widthMeasureSpec, int heightMeasureSpe

public void setCompletedPosition(int position) {
mCompletedPosition = position;
invalidate();
}

public void reset() {
setCompletedPosition(0);
}

public void setThumbColor(int thumbColor) {
mThumbColor = thumbColor;
public void setProgressColor(int progressColor) {
mProgressColor = progressColor;
}

public void setBarColor(int barColor) {
Expand All @@ -126,14 +125,15 @@ public void setBarColor(int barColor) {
@Override
protected synchronized void onDraw(Canvas canvas) {
super.onDraw(canvas);
mDrawListener.onReady();
// Draw rect bounds
paint.setAntiAlias(true);
paint.setColor(mBarColor);
paint.setStyle(Paint.Style.STROKE);
paint.setStrokeWidth(2);

selectedPaint.setAntiAlias(true);
selectedPaint.setColor(mThumbColor);
selectedPaint.setColor(mProgressColor);
selectedPaint.setStyle(Paint.Style.STROKE);
selectedPaint.setStrokeWidth(2);

Expand All @@ -159,7 +159,7 @@ protected synchronized void onDraw(Canvas canvas) {
(i <= mCompletedPosition) ? selectedPaint : paint);

if (i == mCompletedPosition) {
selectedPaint.setColor(getColorWithAlpha(mThumbColor, 0.2f));
selectedPaint.setColor(getColorWithAlpha(mProgressColor, 0.2f));
canvas.drawCircle(pos, mCenterY, mCircleRadius * 1.8f, selectedPaint);
}
}
Expand All @@ -177,6 +177,6 @@ public static int getColorWithAlpha(int color, float ratio) {

public interface OnDrawListener {

public void onFinish();
public void onReady();
}
}

0 comments on commit b27d593

Please sign in to comment.