Skip to content

Instantly share code, notes, and snippets.

@muthuraj57
Last active July 11, 2020 11:30
Show Gist options
  • Save muthuraj57/76c6c4aba1723c622dccc6e17cf2267d to your computer and use it in GitHub Desktop.
Save muthuraj57/76c6c4aba1723c622dccc6e17cf2267d to your computer and use it in GitHub Desktop.
/*
* 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