[go: nahoru, domu]

Skip to content

Commit

Permalink
Rename fillColor to circleBackgroundColor
Browse files Browse the repository at this point in the history
  • Loading branch information
hdodenhof committed Sep 29, 2017
1 parent f6c348c commit 8c7f69e
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public class CircleImageView extends ImageView {

private static final int DEFAULT_BORDER_WIDTH = 0;
private static final int DEFAULT_BORDER_COLOR = Color.BLACK;
private static final int DEFAULT_FILL_COLOR = Color.TRANSPARENT;
private static final int DEFAULT_CIRCLE_BACKGROUND_COLOR = Color.TRANSPARENT;
private static final boolean DEFAULT_BORDER_OVERLAY = false;

private final RectF mDrawableRect = new RectF();
Expand All @@ -54,11 +54,11 @@ public class CircleImageView extends ImageView {
private final Matrix mShaderMatrix = new Matrix();
private final Paint mBitmapPaint = new Paint();
private final Paint mBorderPaint = new Paint();
private final Paint mFillPaint = new Paint();
private final Paint mCircleBackgroundPaint = new Paint();

private int mBorderColor = DEFAULT_BORDER_COLOR;
private int mBorderWidth = DEFAULT_BORDER_WIDTH;
private int mFillColor = DEFAULT_FILL_COLOR;
private int mCircleBackgroundColor = DEFAULT_CIRCLE_BACKGROUND_COLOR;

private Bitmap mBitmap;
private BitmapShader mBitmapShader;
Expand Down Expand Up @@ -93,7 +93,15 @@ public CircleImageView(Context context, AttributeSet attrs, int defStyle) {
mBorderWidth = a.getDimensionPixelSize(R.styleable.CircleImageView_civ_border_width, DEFAULT_BORDER_WIDTH);
mBorderColor = a.getColor(R.styleable.CircleImageView_civ_border_color, DEFAULT_BORDER_COLOR);
mBorderOverlay = a.getBoolean(R.styleable.CircleImageView_civ_border_overlay, DEFAULT_BORDER_OVERLAY);
mFillColor = a.getColor(R.styleable.CircleImageView_civ_fill_color, DEFAULT_FILL_COLOR);

// Look for deprecated civ_fill_color if civ_circle_background_color is not set
if (a.hasValue(R.styleable.CircleImageView_civ_circle_background_color)) {
mCircleBackgroundColor = a.getColor(R.styleable.CircleImageView_civ_circle_background_color,
DEFAULT_CIRCLE_BACKGROUND_COLOR);
} else if (a.hasValue(R.styleable.CircleImageView_civ_fill_color)) {
mCircleBackgroundColor = a.getColor(R.styleable.CircleImageView_civ_fill_color,
DEFAULT_CIRCLE_BACKGROUND_COLOR);
}

a.recycle();

Expand Down Expand Up @@ -140,8 +148,8 @@ protected void onDraw(Canvas canvas) {
return;
}

if (mFillColor != Color.TRANSPARENT) {
canvas.drawCircle(mDrawableRect.centerX(), mDrawableRect.centerY(), mDrawableRadius, mFillPaint);
if (mCircleBackgroundColor != Color.TRANSPARENT) {
canvas.drawCircle(mDrawableRect.centerX(), mDrawableRect.centerY(), mDrawableRadius, mCircleBackgroundPaint);
}
canvas.drawCircle(mDrawableRect.centerX(), mDrawableRect.centerY(), mDrawableRadius, mBitmapPaint);
if (mBorderWidth > 0) {
Expand Down Expand Up @@ -189,16 +197,34 @@ public void setBorderColorResource(@ColorRes int borderColorRes) {
setBorderColor(getContext().getResources().getColor(borderColorRes));
}

public int getCircleBackgroundColor() {
return mCircleBackgroundColor;
}

public void setCircleBackgroundColor(@ColorInt int circleBackgroundColor) {
if (circleBackgroundColor == mCircleBackgroundColor) {
return;
}

mCircleBackgroundColor = circleBackgroundColor;
mCircleBackgroundPaint.setColor(circleBackgroundColor);
invalidate();
}

public void setCircleBackgroundColorResource(@ColorRes int circleBackgroundRes) {
setCircleBackgroundColor(getContext().getResources().getColor(circleBackgroundRes));
}

/**
* Return the color drawn behind the circle-shaped drawable.
*
* @return The color drawn behind the drawable
*
* @deprecated Fill color support is going to be removed in the future
* @deprecated Use {@link #getCircleBackgroundColor()} instead.
*/
@Deprecated
public int getFillColor() {
return mFillColor;
return getCircleBackgroundColor();
}

/**
Expand All @@ -207,17 +233,11 @@ public int getFillColor() {
*
* @param fillColor The color to be drawn behind the drawable
*
* @deprecated Fill color support is going to be removed in the future
* @deprecated Use {@link #setCircleBackgroundColor(int)} instead.
*/
@Deprecated
public void setFillColor(@ColorInt int fillColor) {
if (fillColor == mFillColor) {
return;
}

mFillColor = fillColor;
mFillPaint.setColor(fillColor);
invalidate();
setCircleBackgroundColor(fillColor);
}

/**
Expand All @@ -227,11 +247,11 @@ public void setFillColor(@ColorInt int fillColor) {
* @param fillColorRes The color resource to be resolved to a color and
* drawn behind the drawable
*
* @deprecated Fill color support is going to be removed in the future
* @deprecated Use {@link #setCircleBackgroundColorResource(int)} instead.
*/
@Deprecated
public void setFillColorResource(@ColorRes int fillColorRes) {
setFillColor(getContext().getResources().getColor(fillColorRes));
setCircleBackgroundColorResource(fillColorRes);
}

public int getBorderWidth() {
Expand Down Expand Up @@ -381,9 +401,9 @@ private void setup() {
mBorderPaint.setColor(mBorderColor);
mBorderPaint.setStrokeWidth(mBorderWidth);

mFillPaint.setStyle(Paint.Style.FILL);
mFillPaint.setAntiAlias(true);
mFillPaint.setColor(mFillColor);
mCircleBackgroundPaint.setStyle(Paint.Style.FILL);
mCircleBackgroundPaint.setAntiAlias(true);
mCircleBackgroundPaint.setColor(mCircleBackgroundColor);

mBitmapHeight = mBitmap.getHeight();
mBitmapWidth = mBitmap.getWidth();
Expand Down
2 changes: 2 additions & 0 deletions circleimageview/src/main/res/values/attrs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
<attr name="civ_border_width" format="dimension" />
<attr name="civ_border_color" format="color" />
<attr name="civ_border_overlay" format="boolean" />
<!-- {@deprecated Use civ_circlebackground_color instead.} -->
<attr name="civ_fill_color" format="color" />
<attr name="civ_circle_background_color" format="color" />
</declare-styleable>
</resources>

0 comments on commit 8c7f69e

Please sign in to comment.