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

setImageAlpha() method added #277

Closed
wants to merge 2 commits 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 @@ -78,6 +78,7 @@ public class CircleImageView extends ImageView {
private float mBorderRadius;

private ColorFilter mColorFilter;
private int mAlpha = 255;

private boolean mReady;
private boolean mSetupPending;
Expand All @@ -103,7 +104,11 @@ public CircleImageView(Context context, AttributeSet attrs, int defStyle) {
mBorderColor = a.getColor(R.styleable.CircleImageView_civ_border_color, DEFAULT_BORDER_COLOR);
mBorderOverlay = a.getBoolean(R.styleable.CircleImageView_civ_border_overlay, DEFAULT_BORDER_OVERLAY);
mCircleBackgroundColor = a.getColor(R.styleable.CircleImageView_civ_circle_background_color, DEFAULT_CIRCLE_BACKGROUND_COLOR);

mAlpha = a.getInt(R.styleable.CircleImageView_civ_alpha, 255);
if (mAlpha > 255 || mAlpha < 0) {
throw new IllegalArgumentException("Alpha out of range!!.");
}

a.recycle();

init();
Expand Down Expand Up @@ -323,6 +328,19 @@ private Bitmap getBitmapFromDrawable(Drawable drawable) {
}
}

@Override
public int getImageAlpha() {
return this.mAlpha;
}

public void setImageAlpha(int alpha) {
this.mAlpha = alpha;
if (mAlpha > 255 || mAlpha < 0) {
throw new IllegalArgumentException("Alpha out of range!!.");
}
initializeBitmap();
}

private void initializeBitmap() {
if (mDisableCircularTransformation) {
mBitmap = null;
Expand Down Expand Up @@ -351,6 +369,7 @@ private void setup() {

mBitmapPaint.setAntiAlias(true);
mBitmapPaint.setShader(mBitmapShader);
mBitmapPaint.setAlpha(mAlpha);

mBorderPaint.setStyle(Paint.Style.STROKE);
mBorderPaint.setAntiAlias(true);
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 @@ -5,5 +5,6 @@
<attr name="civ_border_color" format="color" />
<attr name="civ_border_overlay" format="boolean" />
<attr name="civ_circle_background_color" format="color" />
<attr name="civ_alpha" format="integer" />
</declare-styleable>
</resources>