Skip to content

Commit b28f4ec

Browse files
committed
Fix bug not support pv_progress, pv_secondaryProgress, pv_progressMode attribute of ProgressView class.
1 parent f65c0cb commit b28f4ec

File tree

4 files changed

+41
-23
lines changed

4 files changed

+41
-23
lines changed

lib/src/main/java/com/rey/material/drawable/CircularProgressDrawable.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,13 @@ public int getProgressMode(){
275275
return mProgressMode;
276276
}
277277

278+
public void setProgressMode(int mode){
279+
if(mProgressMode != mode) {
280+
mProgressMode = mode;
281+
invalidateSelf();
282+
}
283+
}
284+
278285
public float getProgress(){
279286
return mProgressPercent;
280287
}

lib/src/main/java/com/rey/material/drawable/LinearProgressDrawable.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -434,6 +434,13 @@ public int getProgressMode(){
434434
return mProgressMode;
435435
}
436436

437+
public void setProgressMode(int mode){
438+
if(mProgressMode != mode) {
439+
mProgressMode = mode;
440+
invalidateSelf();
441+
}
442+
}
443+
437444
public float getProgress(){
438445
return mProgressPercent;
439446
}

lib/src/main/java/com/rey/material/widget/ProgressView.java

Lines changed: 24 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -61,41 +61,42 @@ private void applyStyle(Context context, AttributeSet attrs, int defStyleAttr, i
6161
mCircular = a.getBoolean(R.styleable.ProgressView_pv_circular, true);
6262
mProgressId = a.getResourceId(R.styleable.ProgressView_pv_progressStyle, 0);
6363

64-
a.recycle();
65-
6664
if(mProgressId == 0)
6765
mProgressId = mCircular ? R.style.Material_Drawable_CircularProgress : R.style.Material_Drawable_LinearProgress;
6866

69-
if(mCircular)
67+
if(mCircular) {
7068
mProgressDrawable = new CircularProgressDrawable.Builder(context, mProgressId).build();
71-
else
69+
if(a.hasValue(R.styleable.ProgressView_pv_progressMode))
70+
((CircularProgressDrawable)mProgressDrawable).setProgressMode(a.getInt(R.styleable.ProgressView_pv_progressMode, MODE_INDETERMINATE));
71+
}
72+
else{
7273
mProgressDrawable = new LinearProgressDrawable.Builder(context, mProgressId).build();
74+
if(a.hasValue(R.styleable.ProgressView_pv_progressMode))
75+
((LinearProgressDrawable)mProgressDrawable).setProgressMode(a.getInt(R.styleable.ProgressView_pv_progressMode, MODE_INDETERMINATE));
76+
}
77+
78+
if(a.hasValue(R.styleable.ProgressView_pv_progress))
79+
setProgress(a.getFloat(R.styleable.ProgressView_pv_progress, 0));
80+
81+
if(a.hasValue(R.styleable.ProgressView_pv_secondaryProgress))
82+
setSecondaryProgress(a.getFloat(R.styleable.ProgressView_pv_secondaryProgress, 0));
83+
84+
a.recycle();
7385

7486
if(android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.JELLY_BEAN)
7587
setBackground(mProgressDrawable);
7688
else
7789
setBackgroundDrawable(mProgressDrawable);
7890
}
79-
80-
@Override
81-
public void setVisibility(int v) {
82-
if(getVisibility() != v) {
83-
super.setVisibility(v);
84-
85-
if (getProgressMode() == MODE_INDETERMINATE && mAutostart) {
86-
if (v == GONE || v == INVISIBLE)
87-
stop();
88-
else
89-
start();
90-
}
91-
}
92-
}
93-
91+
9492
@Override
9593
protected void onVisibilityChanged(@NonNull View changedView, int visibility) {
9694
super.onVisibilityChanged(changedView, visibility);
9795

98-
if (getProgressMode() == MODE_INDETERMINATE && mAutostart) {
96+
if(changedView != this)
97+
return;
98+
99+
if (mAutostart) {
99100
if (visibility == GONE || visibility == INVISIBLE)
100101
stop();
101102
else
@@ -106,18 +107,18 @@ protected void onVisibilityChanged(@NonNull View changedView, int visibility) {
106107
@Override
107108
protected void onAttachedToWindow() {
108109
super.onAttachedToWindow();
109-
if (getProgressMode() == MODE_INDETERMINATE && mAutostart)
110+
if(getVisibility() == View.VISIBLE && mAutostart)
110111
start();
111112
}
112113

113114
@Override
114115
protected void onDetachedFromWindow() {
115-
if (getProgressMode() == MODE_INDETERMINATE && mAutostart)
116+
if (mAutostart)
116117
stop();
117118

118119
super.onDetachedFromWindow();
119120
}
120-
121+
121122
public int getProgressMode(){
122123
if(mCircular)
123124
return ((CircularProgressDrawable)mProgressDrawable).getProgressMode();

lib/src/main/res/values/attrs.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,9 @@
6565
<attr name="pv_autostart" format="boolean"/>
6666
<attr name="pv_circular" format="boolean"/>
6767
<attr name="pv_progressStyle" format="reference"/>
68+
<attr name="pv_progressMode"/>
69+
<attr name="pv_progress" />
70+
<attr name="pv_secondaryProgress" />
6871
</declare-styleable>
6972

7073
<declare-styleable name="RippleView">

0 commit comments

Comments
 (0)