cleaned up avatar / tile creation

This commit is contained in:
iNPUTmice 2014-12-02 23:59:02 +01:00
parent 9dd445a507
commit 241de062da
2 changed files with 9 additions and 20 deletions

View file

@ -121,8 +121,8 @@ public class AvatarService {
if (count == 0) { if (count == 0) {
String name = mucOptions.getConversation().getName(); String name = mucOptions.getConversation().getName();
String letter = name.substring(0, 1); final String letter = name.isEmpty() ? "X" : name.substring(0,1);
int color = UIHelper.getColorForName(name); final int color = UIHelper.getColorForName(name);
drawTile(canvas, letter, color, 0, 0, size, size); drawTile(canvas, letter, color, 0, 0, size, size);
} else if (count == 1) { } else if (count == 1) {
drawTile(canvas, users.get(0), 0, 0, size, size); drawTile(canvas, users.get(0), 0, 0, size, size);
@ -212,15 +212,8 @@ public class AvatarService {
} }
bitmap = Bitmap.createBitmap(size, size, Bitmap.Config.ARGB_8888); bitmap = Bitmap.createBitmap(size, size, Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(bitmap); Canvas canvas = new Canvas(bitmap);
String letter; final String letter = name.isEmpty() ? "X" : name.substring(0,1);
int color; final int color = UIHelper.getColorForName(name);
if (name.length() > 0) {
letter = name.substring(0, 1);
color = UIHelper.getColorForName(name);
} else {
letter = "X";
color = PLACEHOLDER_COLOR;
}
drawTile(canvas, letter, color, 0, 0, size, size); drawTile(canvas, letter, color, 0, 0, size, size);
mXmppConnectionService.getBitmapCache().put(KEY, bitmap); mXmppConnectionService.getBitmapCache().put(KEY, bitmap);
return bitmap; return bitmap;
@ -275,15 +268,8 @@ public class AvatarService {
} }
} }
String name = contact != null ? contact.getDisplayName() : user.getName(); String name = contact != null ? contact.getDisplayName() : user.getName();
String letter; final String letter = name.isEmpty() ? "X" : name.substring(0,1);
int color; final int color = UIHelper.getColorForName(name);
if (name.length() > 0) {
letter = name.substring(0, 1);
color = UIHelper.getColorForName(name);
} else {
letter = "X";
color = PLACEHOLDER_COLOR;
}
drawTile(canvas, letter, color, left, top, right, bottom); drawTile(canvas, letter, color, left, top, right, bottom);
} }

View file

@ -128,6 +128,9 @@ public class UIHelper {
} }
public static int getColorForName(String name) { public static int getColorForName(String name) {
if (name.isEmpty()) {
return 0xFF202020;
}
int colors[] = {0xFFe91e63, 0xFF9c27b0, 0xFF673ab7, 0xFF3f51b5, int colors[] = {0xFFe91e63, 0xFF9c27b0, 0xFF673ab7, 0xFF3f51b5,
0xFF5677fc, 0xFF03a9f4, 0xFF00bcd4, 0xFF009688, 0xFFff5722, 0xFF5677fc, 0xFF03a9f4, 0xFF00bcd4, 0xFF009688, 0xFFff5722,
0xFF795548, 0xFF607d8b}; 0xFF795548, 0xFF607d8b};