-
-
Save virendersran01/ec3ca88ceb72cab13ffb98c582cfab69 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Initialize fields | |
* */ | |
protected void init() { | |
rectF = new RectF(); | |
clipPath = new Path(); | |
imageSize = getResources().getDimensionPixelSize(R.dimen.avatar_size); | |
cornerRadius = (int) Utils.dpToPixel(2, getResources()); | |
paint = new Paint(Paint.ANTI_ALIAS_FLAG); | |
textPaint = new TextPaint(Paint.ANTI_ALIAS_FLAG); | |
textPaint.setTextSize(16f * getResources().getDisplayMetrics().scaledDensity); | |
textPaint.setColor(Color.WHITE); | |
} | |
/* | |
* Get the user and set values based on the user | |
* This is the only exposed api to the developer | |
* */ | |
public void setUser(User user) { | |
this.user = user; | |
setValues(); | |
} | |
/* | |
* Set user specific fields in here | |
* */ | |
private void setValues() { | |
/* | |
* User specific color for initial background | |
* */ | |
paint.setColor(user.getColor()); | |
/* | |
* Initials of member | |
* */ | |
text = Helper.getShortName(user.getName()); | |
setDrawable(); | |
if (user.getAvatarUrl() != null) { | |
Glide.with(getContext()) | |
.load(user.getAvatarUrl()) | |
.placeholder(drawable) | |
.centerCrop() | |
.override(imageSize, imageSize) | |
.into(this); | |
} else { | |
setImageDrawable(drawable); | |
invalidate(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment