diff --git a/README.md b/README.md
index 512168c..aed9260 100644
--- a/README.md
+++ b/README.md
@@ -10,6 +10,7 @@ Choose from the broad spectre of styleable elements:
* `ppvStrokeWidth` - The width of stroke around the view.
* `ppvStrokeColor` - The color of stroke around the view.
* `ppvBackgroundColor` - The color of the views background.
+ * `ppvBackgroundImage` - The background image for the view (takes precedence over the background color).
* `ppvProgressColor` - The color view of the views progress.
* `ppvInverted` - Inverts the drawing of progress (fill radial only).
* `ppvCounterclockwise` - Draws the progress counterclockwise (fill radial only).
diff --git a/library/src/main/java/com/filippudak/ProgressPieView/ProgressPieView.java b/library/src/main/java/com/filippudak/ProgressPieView/ProgressPieView.java
index 55f7e31..a8cfd0e 100644
--- a/library/src/main/java/com/filippudak/ProgressPieView/ProgressPieView.java
+++ b/library/src/main/java/com/filippudak/ProgressPieView/ProgressPieView.java
@@ -62,7 +62,9 @@ public interface OnProgressListener {
private String mTypeface;
private boolean mShowImage = true;
private Drawable mImage;
+ private Drawable mBackgroundImage;
private Rect mImageRect;
+ private Rect mBackgroundImageRect;
private Paint mStrokePaint;
private Paint mTextPaint;
private Paint mProgressPaint;
@@ -110,6 +112,7 @@ private void init(Context context, AttributeSet attrs) {
mShowStroke = a.getBoolean(R.styleable.ProgressPieView_ppvShowStroke, mShowStroke);
mShowText = a.getBoolean(R.styleable.ProgressPieView_ppvShowText, mShowText);
mImage = a.getDrawable(R.styleable.ProgressPieView_ppvImage);
+ mBackgroundImage = a.getDrawable(R.styleable.ProgressPieView_ppvBackgroundImage);
int backgroundColor = res.getColor(R.color.default_background_color);
backgroundColor = a.getColor(R.styleable.ProgressPieView_ppvBackgroundColor, backgroundColor);
@@ -144,6 +147,7 @@ private void init(Context context, AttributeSet attrs) {
mInnerRectF = new RectF();
mImageRect = new Rect();
+ mBackgroundImageRect = new Rect();
}
@Override
@@ -169,7 +173,15 @@ protected void onDraw(Canvas canvas) {
float centerX = mInnerRectF.centerX();
float centerY = mInnerRectF.centerY();
- canvas.drawArc(mInnerRectF, 0, 360, true, mBackgroundPaint);
+ if (mBackgroundImage != null) {
+ int drawableSize = mBackgroundImage.getIntrinsicWidth();
+ mBackgroundImageRect.set(0, 0, drawableSize, drawableSize);
+ mBackgroundImageRect.offset((getWidth() - drawableSize) / 2, (getHeight() - drawableSize) / 2);
+ mBackgroundImage.setBounds(mBackgroundImageRect);
+ mBackgroundImage.draw(canvas);
+ } else {
+ canvas.drawArc(mInnerRectF, 0, 360, true, mBackgroundPaint);
+ }
switch (mProgressFillType) {
case FILL_TYPE_RADIAL:
@@ -525,6 +537,33 @@ public void setShowStroke(boolean showStroke) {
invalidate();
}
+ /**
+ * Gets the background drawable of the view.
+ */
+ public Drawable getBackgroundImageDrawable() {
+ return mBackgroundImage;
+ }
+
+ /**
+ * Sets the background drawable of the view.
+ * @param backgroundImage background drawable of the view
+ */
+ public void setBackgroundImageDrawable(Drawable backgroundImage) {
+ mBackgroundImage = backgroundImage;
+ invalidate();
+ }
+
+ /**
+ * Sets the background drawable of the view.
+ * @param resId resource id of the view's background drawable
+ */
+ public void setBackgroundImageResource(int resId) {
+ if (null != getResources()) {
+ mBackgroundImage = getResources().getDrawable(resId);
+ invalidate();
+ }
+ }
+
/**
* Gets the drawable of the view.
*/
diff --git a/library/src/main/res/values/attrs.xml b/library/src/main/res/values/attrs.xml
index bb34fae..8c0e82c 100644
--- a/library/src/main/res/values/attrs.xml
+++ b/library/src/main/res/values/attrs.xml
@@ -11,6 +11,7 @@
+