Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -144,6 +147,7 @@ private void init(Context context, AttributeSet attrs) {

mInnerRectF = new RectF();
mImageRect = new Rect();
mBackgroundImageRect = new Rect();
}

@Override
Expand All @@ -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:
Expand Down Expand Up @@ -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.
*/
Expand Down
1 change: 1 addition & 0 deletions library/src/main/res/values/attrs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
<attr name="ppvCounterclockwise" format="boolean"/>
<attr name="ppvStrokeWidth" format="dimension"/>
<attr name="ppvBackgroundColor" format="reference|color"/>
<attr name="ppvBackgroundImage" format="reference"/>
<attr name="ppvProgressColor" format="reference|color"/>
<attr name="ppvStrokeColor" format="reference|color"/>
<attr name="ppvShowStroke" format="boolean"/>
Expand Down