Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding border gap #215

Closed
wants to merge 1 commit into from
Closed
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
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +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_BORDER_GAP = 0;
private static final int DEFAULT_FILL_COLOR = Color.TRANSPARENT;
private static final boolean DEFAULT_BORDER_OVERLAY = false;

Expand All @@ -59,7 +60,8 @@ public class CircleImageView extends ImageView {
private int mBorderColor = DEFAULT_BORDER_COLOR;
private int mBorderWidth = DEFAULT_BORDER_WIDTH;
private int mFillColor = DEFAULT_FILL_COLOR;

private int mBorderGap = DEFAULT_BORDER_GAP;

private Bitmap mBitmap;
private BitmapShader mBitmapShader;
private int mBitmapWidth;
Expand Down Expand Up @@ -93,6 +95,8 @@ 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);
mBorderGap = a.getDimensionPixelSize(R.styleable.CircleImageView_civ_border_gap, 0);

mFillColor = a.getColor(R.styleable.CircleImageView_civ_fill_color, DEFAULT_FILL_COLOR);

a.recycle();
Expand Down Expand Up @@ -234,6 +238,30 @@ public void setFillColorResource(@ColorRes int fillColorRes) {
setFillColor(getContext().getResources().getColor(fillColorRes));
}

/**
* Return the gap between image and it's border.
*
* @return The color drawn behind the drawable
*/
public int getBorderGap() {
return mBorderGap;
}

/**
* Set a desired gap between image and it's border.
*
* @param borderGap The gap between image and border.
*/
public void setBorderGap(@ColorInt int borderGap) {
if (borderGap == mBorderGap) {
return;
}

mBorderGap = borderGap;
setup();
}


public int getBorderWidth() {
return mBorderWidth;
}
Expand Down Expand Up @@ -395,7 +423,7 @@ private void setup() {
if (!mBorderOverlay && mBorderWidth > 0) {
mDrawableRect.inset(mBorderWidth - 1.0f, mBorderWidth - 1.0f);
}
mDrawableRadius = Math.min(mDrawableRect.height() / 2.0f, mDrawableRect.width() / 2.0f);
mDrawableRadius = Math.min(mDrawableRect.height() / 2.0f, mDrawableRect.width() / 2.0f) - mBorderGap;

applyColorFilter();
updateShaderMatrix();
Expand Down
1 change: 1 addition & 0 deletions circleimageview/src/main/res/values/attrs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
<attr name="civ_border_width" format="dimension" />
<attr name="civ_border_color" format="color" />
<attr name="civ_border_overlay" format="boolean" />
<attr name="civ_border_gap" format="dimension" />
<attr name="civ_fill_color" format="color" />
</declare-styleable>
</resources>