Last active
July 11, 2020 11:30
-
-
Save muthuraj57/76c6c4aba1723c622dccc6e17cf2267d 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