From d68604d7270db26b2a7e9d5166f890a9e192b442 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adrien=20B=C3=A9raud?= <adrien.beraud@savoirfairelinux.com> Date: Mon, 13 Jan 2020 02:21:50 -0500 Subject: [PATCH] AvatarDrawable: cleanup Change-Id: Ia13f38a93c9a377ae06b2e1046aeeb56512990cb --- .../java/cx/ring/views/AvatarDrawable.java | 24 +++++++------------ 1 file changed, 9 insertions(+), 15 deletions(-) diff --git a/ring-android/app/src/main/java/cx/ring/views/AvatarDrawable.java b/ring-android/app/src/main/java/cx/ring/views/AvatarDrawable.java index 2bb509635..8b4a3f95b 100644 --- a/ring-android/app/src/main/java/cx/ring/views/AvatarDrawable.java +++ b/ring-android/app/src/main/java/cx/ring/views/AvatarDrawable.java @@ -288,8 +288,8 @@ public class AvatarDrawable extends Drawable { @Override protected void onBoundsChange(Rect bounds) { - setAvatarTextValues(); - setupPresenceIndicator(bounds); + if (showPresence) + setupPresenceIndicator(bounds); int d = Math.min(bounds.width(), bounds.height()); if (placeholder != null) { int cx = (bounds.width()-d)/2; @@ -313,6 +313,8 @@ public class AvatarDrawable extends Drawable { int cx = (iw - w)/2; int cy = (ih - h)/2; backgroundBounds.set(cx, cy, cx + w, h + cy); + } else { + setAvatarTextValues(bounds); } if (cropCircle) { if (d > 0) { @@ -380,23 +382,15 @@ public class AvatarDrawable extends Drawable { return PixelFormat.TRANSLUCENT; } - private void setAvatarTextValues() { + private void setAvatarTextValues(Rect bounds) { if (avatarText != null) { - textPaint.setTextSize(getBounds().height() * DEFAULT_TEXT_SIZE_PERCENTAGE); - textStartXPoint = calculateTextStartXPoint(); - textStartYPoint = calculateTextStartYPoint(); + textPaint.setTextSize(bounds.height() * DEFAULT_TEXT_SIZE_PERCENTAGE); + float stringWidth = textPaint.measureText(avatarText); + textStartXPoint = (bounds.width() / 2f) - (stringWidth / 2f); + textStartYPoint = (bounds.height() / 2f) - ((textPaint.ascent() + textPaint.descent()) / 2f); } } - private float calculateTextStartXPoint() { - float stringWidth = textPaint.measureText(avatarText); - return (getBounds().width() / 2f) - (stringWidth / 2f); - } - - private float calculateTextStartYPoint() { - return (getBounds().height() / 2f) - ((textPaint.ascent() + textPaint.descent()) / 2f); - } - private String convertNameToAvatarText(String name) { if (TextUtils.isEmpty(name)) { return null; -- GitLab