@@ -74,6 +74,7 @@ public class CircleProgressBar extends ImageView {
7474 private MaterialProgressDrawable mProgressDrawable ;
7575 private ShapeDrawable mBgCircle ;
7676 private boolean mCircleBackgroundEnabled ;
77+ private int [] mColors ;
7778
7879 public CircleProgressBar (Context context ) {
7980 super (context );
@@ -154,6 +155,8 @@ private void init(Context context, AttributeSet attrs, int defStyleAttr) {
154155 mTextPaint .setTextSize (mTextSize );
155156 mTextPaint .setAntiAlias (true );
156157 a .recycle ();
158+ mProgressDrawable = new MaterialProgressDrawable (getContext (), this );
159+ super .setImageDrawable (mProgressDrawable );
157160 }
158161
159162
@@ -201,23 +204,21 @@ protected void onLayout(boolean changed, int left, int top, int right, int botto
201204 mBgCircle .getPaint ().setColor (mBackGroundColor );
202205 setBackgroundDrawable (mBgCircle );
203206 }
204- if (getDrawable ()==null ) {
205- mProgressDrawable = new MaterialProgressDrawable (getContext (), this );
206- mProgressDrawable .setBackgroundColor (mBackGroundColor );
207- // mProgressDrawable.setStartEndTrim(0, 180);
208- mProgressDrawable .setSizeParameters (mDiameter , mDiameter ,
209- mInnerRadius <= 0 ? (mDiameter - mProgressStokeWidth * 2 ) / 4 : mInnerRadius ,
210- mProgressStokeWidth ,
211- mArrowWidth < 0 ? mProgressStokeWidth * 4 : mArrowWidth ,
212- mArrowHeight < 0 ? mProgressStokeWidth * 2 : mArrowHeight );
213- if (isShowArrow ()){
214- mProgressDrawable .setArrowScale (1f );
215- mProgressDrawable .showArrow (true );
216- }
217- super .setImageDrawable (mProgressDrawable );
218- mProgressDrawable .setAlpha (255 );
219- mProgressDrawable .start ();
207+ mProgressDrawable .setBackgroundColor (mBackGroundColor );
208+ mProgressDrawable .setColorSchemeColors (mColors );
209+ mProgressDrawable .setSizeParameters (mDiameter , mDiameter ,
210+ mInnerRadius <= 0 ? (mDiameter - mProgressStokeWidth * 2 ) / 4 : mInnerRadius ,
211+ mProgressStokeWidth ,
212+ mArrowWidth < 0 ? mProgressStokeWidth * 4 : mArrowWidth ,
213+ mArrowHeight < 0 ? mProgressStokeWidth * 2 : mArrowHeight );
214+ if (isShowArrow ()){
215+ mProgressDrawable .setArrowScale (1f );
216+ mProgressDrawable .showArrow (true );
220217 }
218+ super .setImageDrawable (null );
219+ super .setImageDrawable (mProgressDrawable );
220+ mProgressDrawable .setAlpha (255 );
221+ mProgressDrawable .start ();
221222 }
222223
223224 @ Override
@@ -276,6 +277,36 @@ public void onAnimationEnd() {
276277 }
277278 }
278279
280+
281+ /**
282+ * Set the color resources used in the progress animation from color resources.
283+ * The first color will also be the color of the bar that grows in response
284+ * to a user swipe gesture.
285+ *
286+ * @param colorResIds
287+ */
288+ public void setColorSchemeResources (int ... colorResIds ) {
289+ final Resources res = getResources ();
290+ int [] colorRes = new int [colorResIds .length ];
291+ for (int i = 0 ; i < colorResIds .length ; i ++) {
292+ colorRes [i ] = res .getColor (colorResIds [i ]);
293+ }
294+ setColorSchemeColors (colorRes );
295+ }
296+
297+ /**
298+ * Set the colors used in the progress animation. The first
299+ * color will also be the color of the bar that grows in response to a user
300+ * swipe gesture.
301+ *
302+ * @param colors
303+ */
304+ public void setColorSchemeColors (int ... colors ) {
305+ mColors = colors ;
306+ if (mProgressDrawable !=null ) {
307+ mProgressDrawable .setColorSchemeColors (colors );
308+ }
309+ }
279310 /**
280311 * Update the background color of the mBgCircle image view.
281312 */
0 commit comments