@@ -60,7 +60,9 @@ public interface OnProgressListener {
6060 private String mTypeface ;
6161 private boolean mShowImage = true ;
6262 private Drawable mImage ;
63+ private Drawable mBackgroundImage ;
6364 private Rect mImageRect ;
65+ private Rect mBackgroundImageRect ;
6466 private Paint mStrokePaint ;
6567 private Paint mTextPaint ;
6668 private Paint mProgressPaint ;
@@ -106,6 +108,7 @@ private void init(Context context, AttributeSet attrs) {
106108 mShowStroke = a .getBoolean (R .styleable .ProgressPieView_showStroke , mShowStroke );
107109 mShowText = a .getBoolean (R .styleable .ProgressPieView_showText , mShowText );
108110 mImage = a .getDrawable (R .styleable .ProgressPieView_image );
111+ mBackgroundImage = a .getDrawable (R .styleable .ProgressPieView_backgroundImage );
109112
110113 int backgroundColor = res .getColor (R .color .default_background_color );
111114 backgroundColor = a .getColor (R .styleable .ProgressPieView_backgroundColor , backgroundColor );
@@ -140,6 +143,7 @@ private void init(Context context, AttributeSet attrs) {
140143
141144 mInnerRectF = new RectF ();
142145 mImageRect = new Rect ();
146+ mBackgroundImageRect = new Rect ();
143147 }
144148
145149 @ Override
@@ -163,7 +167,15 @@ protected void onDraw(Canvas canvas) {
163167 float centerX = mInnerRectF .centerX ();
164168 float centerY = mInnerRectF .centerY ();
165169
166- canvas .drawArc (mInnerRectF , 0 , 360 , true , mBackgroundPaint );
170+ if (mBackgroundImage != null ) {
171+ int drawableSize = mBackgroundImage .getIntrinsicWidth ();
172+ mBackgroundImageRect .set (0 , 0 , drawableSize , drawableSize );
173+ mBackgroundImageRect .offset ((getWidth () - drawableSize ) / 2 , (getHeight () - drawableSize ) / 2 );
174+ mBackgroundImage .setBounds (mBackgroundImageRect );
175+ mBackgroundImage .draw (canvas );
176+ } else {
177+ canvas .drawArc (mInnerRectF , 0 , 360 , true , mBackgroundPaint );
178+ }
167179
168180 switch (mProgressFillType ) {
169181 case FILL_TYPE_RADIAL :
@@ -480,6 +492,33 @@ public void setShowStroke(boolean showStroke) {
480492 invalidate ();
481493 }
482494
495+ /**
496+ * Gets the background drawable of the view.
497+ */
498+ public Drawable getBackgroundImageDrawable () {
499+ return mBackgroundImage ;
500+ }
501+
502+ /**
503+ * Sets the background drawable of the view.
504+ * @param backgroundImage background drawable of the view
505+ */
506+ public void setBackgroundImageDrawable (Drawable backgroundImage ) {
507+ mBackgroundImage = backgroundImage ;
508+ invalidate ();
509+ }
510+
511+ /**
512+ * Sets the background drawable of the view.
513+ * @param resId resource id of the view's background drawable
514+ */
515+ public void setBackgroundImageResource (int resId ) {
516+ if (null != getResources ()) {
517+ mBackgroundImage = getResources ().getDrawable (resId );
518+ invalidate ();
519+ }
520+ }
521+
483522 /**
484523 * Gets the drawable of the view.
485524 */
0 commit comments