aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java/eu/siacs/conversations/services
diff options
context:
space:
mode:
authoriNPUTmice <daniel@gultsch.de>2014-11-09 17:02:39 +0100
committeriNPUTmice <daniel@gultsch.de>2014-11-09 17:02:39 +0100
commit61f046a675978fa53b725e6da18ed27c9f312015 (patch)
treea8f9c540821b6533757b07526b3c4d86c1315bf0 /src/main/java/eu/siacs/conversations/services
parent8c325dacf4be4028fbfdc1e175170237227c7e7e (diff)
make avatar service not break on empty names
Diffstat (limited to 'src/main/java/eu/siacs/conversations/services')
-rw-r--r--src/main/java/eu/siacs/conversations/services/AvatarService.java36
1 files changed, 22 insertions, 14 deletions
diff --git a/src/main/java/eu/siacs/conversations/services/AvatarService.java b/src/main/java/eu/siacs/conversations/services/AvatarService.java
index 778fd4dd1..bdf18f54b 100644
--- a/src/main/java/eu/siacs/conversations/services/AvatarService.java
+++ b/src/main/java/eu/siacs/conversations/services/AvatarService.java
@@ -22,6 +22,7 @@ public class AvatarService {
private static final int FG_COLOR = 0xFFFAFAFA;
private static final int TRANSPARENT = 0x00000000;
+ private static final int PLACEHOLDER_COLOR = 0xFF202020;
private static final String PREFIX_CONTACT = "contact";
private static final String PREFIX_CONVERSATION = "conversation";
@@ -140,7 +141,7 @@ public class AvatarService {
drawTile(canvas, users.get(0), 0, 0, size / 2 - 1, size / 2 - 1);
drawTile(canvas, users.get(1), 0, size / 2 + 1, size / 2 - 1, size);
drawTile(canvas, users.get(2), size / 2 + 1, 0, size, size / 2 - 1);
- drawTile(canvas, "\u2026", 0xFF202020, size / 2 + 1, size / 2 + 1,
+ drawTile(canvas, "\u2026", PLACEHOLDER_COLOR, size / 2 + 1, size / 2 + 1,
size, size);
}
this.mXmppConnectionService.getBitmapCache().put(KEY, bitmap);
@@ -204,8 +205,15 @@ public class AvatarService {
}
bitmap = Bitmap.createBitmap(size, size, Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(bitmap);
- String letter = name.substring(0, 1);
- int color = this.getColorForName(name);
+ String letter;
+ int color;
+ if (name.length() > 0) {
+ letter = name.substring(0, 1);
+ color = this.getColorForName(name);
+ } else {
+ letter = "X";
+ color = PLACEHOLDER_COLOR;
+ }
drawTile(canvas, letter, color, 0, 0, size, size);
mXmppConnectionService.getBitmapCache().put(KEY, bitmap);
return bitmap;
@@ -255,21 +263,21 @@ public class AvatarService {
.cropCenter(uri, bottom - top, right - left);
if (bitmap != null) {
drawTile(canvas, bitmap, left, top, right, bottom);
- } else {
- String letter = user.getName().substring(0, 1);
- int color = this.getColorForName(user.getName());
- drawTile(canvas, letter, color, left, top, right, bottom);
+ return;
}
- } else {
- String letter = user.getName().substring(0, 1);
- int color = this.getColorForName(user.getName());
- drawTile(canvas, letter, color, left, top, right, bottom);
}
+ }
+ String name = user.getName();
+ String letter;
+ int color;
+ if (name.length() > 0) {
+ letter = name.substring(0, 1);
+ color = this.getColorForName(name);
} else {
- String letter = user.getName().substring(0, 1);
- int color = this.getColorForName(user.getName());
- drawTile(canvas, letter, color, left, top, right, bottom);
+ letter = "X";
+ color = PLACEHOLDER_COLOR;
}
+ drawTile(canvas, letter, color, left, top, right, bottom);
}
private void drawTile(Canvas canvas, Bitmap bm, int dstleft, int dsttop,