Skip to content

Commit

Permalink
update progressbar
Browse files Browse the repository at this point in the history
Signed-off-by: wangdongdong <[email protected]>
  • Loading branch information
wangdongdong committed Apr 19, 2017
1 parent 3a13eb2 commit c3ac290
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 2 deletions.
3 changes: 3 additions & 0 deletions sample/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,8 @@
app:barMaxProgress="15"
app:barProgressLineColor="@color/colorPrimary"
app:barProgressLineWidth="3dp"
app:barProgressTextColor="@color/colorPrimary"
app:barProgressLineBgColor="#fff"
app:state="enabled"/>

<mazouri.statebutton.StateButton
Expand Down Expand Up @@ -351,6 +353,7 @@
app:barProgressLineColor="@color/colorPrimary"
app:barProgressLineWidth="3dp"
app:barProgressTextColor="@color/colorPrimary"
app:barProgressLineBgColor="#fff"
app:state="enabled"/>
</com.google.android.flexbox.FlexboxLayout>

Expand Down
2 changes: 2 additions & 0 deletions sample/src/main/res/values/colors.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,6 @@
<color name="colorPrimary">#3F51B5</color>
<color name="colorPrimaryDark">#303F9F</color>
<color name="colorAccent">#FF4081</color>

<color name="white">#fff</color>
</resources>
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ public class CircleTextProgressbar extends android.support.v7.widget.AppCompatTe
*/
private int progressLineColor = Color.BLUE;

private int progressLineBgColor = Color.GRAY;

/**
* 进度条的宽度。
*/
Expand Down Expand Up @@ -131,6 +133,7 @@ private void initialize(Context context, AttributeSet attributeSet) {
circleColor = inCircleColors.getColorForState(getDrawableState(), Color.TRANSPARENT);

progressLineColor = typedArray.getColor(R.styleable.CircleTextProgressbar_progressLineColor, Color.TRANSPARENT);
progressLineBgColor = typedArray.getColor(R.styleable.CircleTextProgressbar_progressLineBgColor, Color.GRAY);
progressLineWidth = typedArray.getDimensionPixelSize(R.styleable.CircleTextProgressbar_progressLineWidth, 8);
progressChangeDuration = typedArray.getInt(R.styleable.CircleTextProgressbar_progressChangeDuration, 0);
maxProgress = typedArray.getInt(R.styleable.CircleTextProgressbar_maxProgress, 100);
Expand Down Expand Up @@ -204,6 +207,14 @@ public void setProgressChangeDuration(int progressChangeDuration) {
this.progressChangeDuration = progressChangeDuration;
}

public void setProgressLineColor(int progressLineColor) {
this.progressLineColor = progressLineColor;
}

public void setProgressLineBgColor(int progressLineBgColor) {
this.progressLineBgColor = progressLineBgColor;
}

public void setMaxProgress(int maxProgress) {
this.maxProgress = ++maxProgress;
}
Expand Down Expand Up @@ -356,14 +367,17 @@ protected void onDraw(Canvas canvas) {
canvas.drawText(getText().toString(), bounds.centerX(), textY, paint);

//画进度条
mPaint.setColor(progressLineColor);
mPaint.setStyle(Paint.Style.STROKE);
mPaint.setStrokeWidth(progressLineWidth);
mPaint.setStrokeCap(Paint.Cap.ROUND);
int deleteWidth = progressLineWidth + outLineWidth;
mArcRect.set(bounds.left + deleteWidth / 2, bounds.top + deleteWidth / 2, bounds.right - deleteWidth / 2, bounds.bottom - deleteWidth / 2);

Log.d("progress", "progress : " + progress + ", maxProgress : " + maxProgress);
//画进度条背景
mPaint.setColor(progressLineBgColor);
canvas.drawArc(mArcRect, 0, 360, false, mPaint);

mPaint.setColor(progressLineColor);
canvas.drawArc(mArcRect, 0, 360 * progress / maxProgress, false, mPaint);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ public class StateButton extends RelativeLayout {
*/
private int progressLineColor = Color.BLUE;

private int progressLineBgColor = Color.GRAY;

private int progressTextColor;

/**
Expand Down Expand Up @@ -145,6 +147,7 @@ public StateButton(Context context, AttributeSet attrs, int defStyleAttr) {
int drawablePadding = a.getDimensionPixelSize(R.styleable.StateButton_drawablePadding, dip2px(10f));

progressLineColor = a.getColor(R.styleable.StateButton_barProgressLineColor, Color.TRANSPARENT);
progressLineBgColor = a.getColor(R.styleable.StateButton_barProgressLineBgColor, Color.GRAY);
progressTextColor = a.getColor(R.styleable.StateButton_barProgressTextColor, Color.WHITE);
progressLineWidth = a.getDimensionPixelSize(R.styleable.StateButton_barProgressLineWidth, 8);
progressChangeDuration = a.getInt(R.styleable.StateButton_barProgressChangeDuration, 0);
Expand All @@ -169,6 +172,7 @@ public StateButton(Context context, AttributeSet attrs, int defStyleAttr) {
lpProgressbar.height = iconHeight;
mCircleTextProgressbar.setId(ID_PROGRESS);
mCircleTextProgressbar.setProgressColor(progressLineColor);
mCircleTextProgressbar.setProgressLineBgColor(progressLineBgColor);
mCircleTextProgressbar.setProgressLineWidth(progressLineWidth);
mCircleTextProgressbar.setProgressChangeDuration(progressChangeDuration);
mCircleTextProgressbar.setMaxProgress(maxProgress);
Expand Down
2 changes: 2 additions & 0 deletions statebutton/src/main/res/values/attrs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
<!--progress bar-->
<attr name="barCircleColor" format="color" />
<attr name="barProgressLineColor" format="color"/>
<attr name="barProgressLineBgColor" format="color"/>
<attr name="barProgressTextColor" format="color"/>
<attr name="barProgressLineWidth" format="dimension"/>
<attr name="barProgressChangeDuration" format="integer"/>
Expand All @@ -55,6 +56,7 @@

<declare-styleable name="CircleTextProgressbar">
<attr name="inCircleColor" format="color" />
<attr name="progressLineBgColor" format="color"/>
<attr name="progressLineColor" format="color"/>
<attr name="progressLineWidth" format="dimension"/>
<attr name="progressChangeDuration" format="integer"/>
Expand Down

0 comments on commit c3ac290

Please sign in to comment.