Skip to content
Snippets Groups Projects
Commit d68604d7 authored by Adrien Béraud's avatar Adrien Béraud
Browse files

AvatarDrawable: cleanup

Change-Id: Ia13f38a93c9a377ae06b2e1046aeeb56512990cb
parent 4890219b
No related branches found
No related tags found
No related merge requests found
...@@ -288,7 +288,7 @@ public class AvatarDrawable extends Drawable { ...@@ -288,7 +288,7 @@ public class AvatarDrawable extends Drawable {
@Override @Override
protected void onBoundsChange(Rect bounds) { protected void onBoundsChange(Rect bounds) {
setAvatarTextValues(); if (showPresence)
setupPresenceIndicator(bounds); setupPresenceIndicator(bounds);
int d = Math.min(bounds.width(), bounds.height()); int d = Math.min(bounds.width(), bounds.height());
if (placeholder != null) { if (placeholder != null) {
...@@ -313,6 +313,8 @@ public class AvatarDrawable extends Drawable { ...@@ -313,6 +313,8 @@ public class AvatarDrawable extends Drawable {
int cx = (iw - w)/2; int cx = (iw - w)/2;
int cy = (ih - h)/2; int cy = (ih - h)/2;
backgroundBounds.set(cx, cy, cx + w, h + cy); backgroundBounds.set(cx, cy, cx + w, h + cy);
} else {
setAvatarTextValues(bounds);
} }
if (cropCircle) { if (cropCircle) {
if (d > 0) { if (d > 0) {
...@@ -380,21 +382,13 @@ public class AvatarDrawable extends Drawable { ...@@ -380,21 +382,13 @@ public class AvatarDrawable extends Drawable {
return PixelFormat.TRANSLUCENT; return PixelFormat.TRANSLUCENT;
} }
private void setAvatarTextValues() { private void setAvatarTextValues(Rect bounds) {
if (avatarText != null) { if (avatarText != null) {
textPaint.setTextSize(getBounds().height() * DEFAULT_TEXT_SIZE_PERCENTAGE); textPaint.setTextSize(bounds.height() * DEFAULT_TEXT_SIZE_PERCENTAGE);
textStartXPoint = calculateTextStartXPoint();
textStartYPoint = calculateTextStartYPoint();
}
}
private float calculateTextStartXPoint() {
float stringWidth = textPaint.measureText(avatarText); float stringWidth = textPaint.measureText(avatarText);
return (getBounds().width() / 2f) - (stringWidth / 2f); textStartXPoint = (bounds.width() / 2f) - (stringWidth / 2f);
textStartYPoint = (bounds.height() / 2f) - ((textPaint.ascent() + textPaint.descent()) / 2f);
} }
private float calculateTextStartYPoint() {
return (getBounds().height() / 2f) - ((textPaint.ascent() + textPaint.descent()) / 2f);
} }
private String convertNameToAvatarText(String name) { private String convertNameToAvatarText(String name) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment