Use the same colors for dummy-avatars and group-name-paint.

This commit is contained in:
B. Petersen
2016-11-12 16:02:19 +01:00
parent d1d38b64e2
commit 41ff097bb8
14 changed files with 51 additions and 77 deletions
@@ -106,7 +106,7 @@ public class ChatActionCell extends BaseCell {
}
}
}
avatarDrawable.setInfo(null, null, false);
avatarDrawable.setInfoByName(null);
if (currentMessageObject.messageOwner.action instanceof TLRPC.TL_messageActionUserUpdatedPhoto) {
imageReceiver.setImage(currentMessageObject.messageOwner.action.newUserPhoto.photo_small, "50_50", avatarDrawable, null, false);
} else {
@@ -2196,23 +2196,14 @@ public class ChatMessageCell extends BaseCell implements SeekBar.SeekBarDelegate
if (user.photo != null) {
currentPhoto = user.photo.photo_small;
}
contactAvatarDrawable.setInfo(user);
contactAvatarDrawable.setInfoByUser(user);
}
photoImage.setImage(currentPhoto, "50_50", user != null ? contactAvatarDrawable : Theme.contactDrawable[messageObject.isOutOwner() ? 1 : 0], null, false);
String phone = messageObject.messageOwner.media.phone_number;
if (phone != null && phone.length() != 0) {
phone = "";//PhoneFormat.getInstance().format(phone);
} else {
phone = LocaleController.getString("NumberUnknown", R.string.NumberUnknown);
}
CharSequence currentNameString = ContactsController.formatName(messageObject.messageOwner.media.first_name, messageObject.messageOwner.media.last_name).replace('\n', ' ');
if (currentNameString.length() == 0) {
currentNameString = phone;
}
titleLayout = new StaticLayout(TextUtils.ellipsize(currentNameString, contactNamePaint, maxWidth, TextUtils.TruncateAt.END), contactNamePaint, maxWidth + dp(2), Layout.Alignment.ALIGN_NORMAL, 1.0f, 0.0f, false);
docTitleLayout = new StaticLayout(TextUtils.ellipsize(phone.replace('\n', ' '), contactPhonePaint, maxWidth, TextUtils.TruncateAt.END), contactPhonePaint, maxWidth + dp(2), Layout.Alignment.ALIGN_NORMAL, 1.0f, 0.0f, false);
docTitleLayout = new StaticLayout(TextUtils.ellipsize("", contactPhonePaint, maxWidth, TextUtils.TruncateAt.END), contactPhonePaint, maxWidth + dp(2), Layout.Alignment.ALIGN_NORMAL, 1.0f, 0.0f, false);
setMessageObjectInternal(messageObject);
@@ -3697,7 +3688,7 @@ public class ChatMessageCell extends BaseCell implements SeekBar.SeekBarDelegate
*/
// MrAvatar ...
avatarDrawable.setInfo(cname, null, false);
avatarDrawable.setInfoByName(cname);
avatarImage.setImage(currentPhoto, "50_50", avatarDrawable, null, false);
}
@@ -3999,7 +3990,6 @@ public class ChatMessageCell extends BaseCell implements SeekBar.SeekBarDelegate
if (currentMessageObject.type == 13) {
namePaint.setColor(Theme.MSG_STICKER_NAME_TEXT_COLOR);
int backWidth;
if (currentMessageObject.isOutOwner()) {
nameX = dp(28);
} else {
@@ -4015,13 +4005,7 @@ public class ChatMessageCell extends BaseCell implements SeekBar.SeekBarDelegate
} else {
nameX = currentBackgroundDrawable.getBounds().left + dp(17) - nameOffsetX;
}
if (currentUser != null) {
namePaint.setColor(AvatarDrawable.getNameColorForId(currentUser.id));
} else if (currentChat != null) {
namePaint.setColor(AvatarDrawable.getNameColorForId(currentChat.id));
} else {
namePaint.setColor(AvatarDrawable.getNameColorForId(0));
}
namePaint.setColor(AvatarDrawable.getNameColor(currentNameString));
nameY = dp(10);
}
canvas.translate(nameX, nameY);
@@ -690,7 +690,7 @@ public class DialogCell extends BaseCell {
// MrAvatar
String cname = MrMailbox.MrChatGetName(m_hChat);
avatarDrawable.setInfo(cname, null, false);
avatarDrawable.setInfoByName(cname);
avatarImage.setImage(photo, "50_50", avatarDrawable, null, false);
@@ -127,7 +127,7 @@ public class HintDialogCell extends FrameLayout {
} else {
nameTextView.setText("");
}
avatarDrawable.setInfo(user);
avatarDrawable.setInfoByUser(user);
if (user != null && user.photo != null) {
photo = user.photo.photo_small;
}
@@ -140,7 +140,7 @@ public class HintDialogCell extends FrameLayout {
} else {
nameTextView.setText("");
}
avatarDrawable.setInfo(chat);
avatarDrawable.setInfoByChat(chat);
if (chat != null && chat.photo != null) {
photo = chat.photo.photo_small;
}
@@ -86,7 +86,7 @@ public class MentionCell extends LinearLayout {
imageView.setImageDrawable(null);
return;
}
avatarDrawable.setInfo(user);
avatarDrawable.setInfoByUser(user);
if (user.photo != null && user.photo.photo_small != null) {
imageView.setImage(user.photo.photo_small, "50_50", avatarDrawable);
} else {
@@ -111,7 +111,7 @@ public class MentionCell extends LinearLayout {
public void setBotCommand(String command, String help, TLRPC.User user) {
if (user != null) {
imageView.setVisibility(VISIBLE);
avatarDrawable.setInfo(user);
avatarDrawable.setInfoByUser(user);
if (user.photo != null && user.photo.photo_small != null) {
imageView.setImage(user.photo.photo_small, "50_50", avatarDrawable);
} else {
@@ -409,14 +409,14 @@ public class ProfileSearchCell extends BaseCell {
if (user.photo != null) {
photo = user.photo.photo_small;
}
avatarDrawable.setInfo(user);
avatarDrawable.setInfoByUser(user);
} else if (chat != null) {
if (chat.photo != null) {
photo = chat.photo.photo_small;
}
avatarDrawable.setInfo(chat);
avatarDrawable.setInfoByChat(chat);
} else {
avatarDrawable.setInfo(null, null, false);
avatarDrawable.setInfoByName(null);
}
if (mask != 0) {
@@ -85,7 +85,7 @@ public class ShareDialogCell extends FrameLayout {
} else {
nameTextView.setText("");
}
avatarDrawable.setInfo(user);
avatarDrawable.setInfoByUser(user);
if (user != null && user.photo != null) {
photo = user.photo.photo_small;
}
@@ -98,7 +98,7 @@ public class ShareDialogCell extends FrameLayout {
} else {
nameTextView.setText("");
}
avatarDrawable.setInfo(chat);
avatarDrawable.setInfoByChat(chat);
if (chat != null && chat.photo != null) {
photo = chat.photo.photo_small;
}
@@ -205,14 +205,14 @@ public class UserCell extends FrameLayout {
}
if (currentUser != null) {
avatarDrawable.setInfo(currentUser);
avatarDrawable.setInfoByUser(currentUser);
if (currentUser.status != null) {
lastStatus = currentUser.status.expires;
} else {
lastStatus = 0;
}
} else {
avatarDrawable.setInfo(currentChat);
avatarDrawable.setInfoByChat(currentChat);
}
if (currentName != null) {
@@ -31,14 +31,12 @@ public class AvatarDrawable extends Drawable {
private static Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
private static TextPaint namePaint;
private static TextPaint namePaintSmall;
private static int[] arrColors = {0xffe56555, 0xfff28c48, 0xff8e85ee, 0xff76c84d, 0xff5fbed5, 0xff549cdd, 0xff8e85ee, 0xff8cdc99};
private static int[] arrColors = {0xffe56555, 0xfff28c48, 0xff8e85ee, 0xff76c84d, 0xff5bb6cc, 0xff549cdd, 0xffd25c99, 0xffb37800}; /* the colors should contrast to typical action bar colors as well as to white (more important, is used as text color)*/
private static int[] arrColorsProfiles = {0xffd86f65, 0xfff69d61, 0xff8c79d2, 0xff67b35d, 0xff56a2bb, Theme.ACTION_BAR_MAIN_AVATAR_COLOR, 0xff8c79d2, 0xfff37fa6};
private static int[] arrColorsProfilesText = {0xfff9cbc5, 0xfffdddc8, 0xffcdc4ed, 0xffc0edba, 0xffb8e2f0, Theme.ACTION_BAR_PROFILE_SUBTITLE_COLOR, 0xffcdc4ed, 0xffb3d7f7};
private static int[] arrColorsNames = {0xffca5650, 0xffd87b29, 0xff4e92cc, 0xff50b232, 0xff42b1a8, 0xff4e92cc, 0xff4e92cc, 0xff4e92cc};
private static int[] arrColorsButtons = {Theme.ACTION_BAR_RED_SELECTOR_COLOR, Theme.ACTION_BAR_ORANGE_SELECTOR_COLOR, Theme.ACTION_BAR_VIOLET_SELECTOR_COLOR,
Theme.ACTION_BAR_GREEN_SELECTOR_COLOR, Theme.ACTION_BAR_CYAN_SELECTOR_COLOR, Theme.ACTION_BAR_BLUE_SELECTOR_COLOR, Theme.ACTION_BAR_VIOLET_SELECTOR_COLOR, Theme.ACTION_BAR_BLUE_SELECTOR_COLOR};
private static Drawable broadcastDrawable;
private static Drawable photoDrawable;
private int color;
@@ -47,7 +45,6 @@ public class AvatarDrawable extends Drawable {
private float textHeight;
private float textLeft;
private boolean isProfile;
private boolean drawBrodcast;
private boolean drawPhoto;
private boolean smallStyle;
private StringBuilder stringBuilder = new StringBuilder(5);
@@ -63,8 +60,6 @@ public class AvatarDrawable extends Drawable {
namePaintSmall = new TextPaint(Paint.ANTI_ALIAS_FLAG);
namePaintSmall.setColor(0xffffffff);
namePaintSmall.setTextSize(AndroidUtilities.dp(14));
broadcastDrawable = ApplicationLoader.applicationContext.getResources().getDrawable(R.drawable.broadcast_w);
}
}
@@ -80,7 +75,7 @@ public class AvatarDrawable extends Drawable {
this();
isProfile = profile;
if (user != null) {
setInfo(user.first_name, user.last_name, false);
setInfoByName(user.first_name+" "+ user.last_name);
}
}
@@ -88,7 +83,7 @@ public class AvatarDrawable extends Drawable {
this();
isProfile = profile;
if (chat != null) {
setInfo(chat.title, null, chat.id < 0);
setInfoByName(chat.title);
}
}
@@ -120,27 +115,28 @@ public class AvatarDrawable extends Drawable {
return arrColorsProfilesText[getColorIndex(id)];
}
public static int getNameColorForId(int id) {
return arrColorsNames[getColorIndex(id)];
public static int getNameColor(String name) {
int id = strChecksum(name);
return arrColors[getColorIndex(id)];
}
public void setInfo(TLRPC.User user) {
public void setInfoByUser(TLRPC.User user) {
if (user != null) {
setInfo(user.first_name, user.last_name, false);
setInfoByName(user.first_name +" "+ user.last_name);
}
}
public void setInfo(TLRPC.Chat chat) {
public void setInfoByChat(TLRPC.Chat chat) {
if (chat != null) {
setInfo(chat.title, null, chat.id < 0);
setInfoByName(chat.title);
}
}
public void setColor(int value) {
public void setColor_(int value) {
color = value;
}
private int strChecksum(String str) {
private static int strChecksum(String str) {
int ret = 0;
if( str!=null ) {
int i;
@@ -152,8 +148,10 @@ public class AvatarDrawable extends Drawable {
return ret;
}
public void setInfo(String firstName, String lastName, boolean isBroadcast) {
int id = strChecksum(firstName) + strChecksum(lastName);
public void setInfoByName(String firstName) {
String lastName = null;
int id = strChecksum(firstName);
if (isProfile) {
color = arrColorsProfiles[getColorIndex(id)];
@@ -161,8 +159,6 @@ public class AvatarDrawable extends Drawable {
color = arrColors[getColorIndex(id)];
}
drawBrodcast = isBroadcast;
if (firstName == null || firstName.length() == 0) {
firstName = lastName;
lastName = null;
@@ -234,22 +230,16 @@ public class AvatarDrawable extends Drawable {
canvas.translate(bounds.left, bounds.top);
canvas.drawCircle(size / 2, size / 2, size / 2, paint);
if (drawBrodcast && broadcastDrawable != null) {
int x = (size - broadcastDrawable.getIntrinsicWidth()) / 2;
int y = (size - broadcastDrawable.getIntrinsicHeight()) / 2;
broadcastDrawable.setBounds(x, y, x + broadcastDrawable.getIntrinsicWidth(), y + broadcastDrawable.getIntrinsicHeight());
broadcastDrawable.draw(canvas);
} else {
if (textLayout != null) {
canvas.translate((size - textWidth) / 2 - textLeft, (size - textHeight) / 2);
textLayout.draw(canvas);
} else if (drawPhoto && photoDrawable != null) {
int x = (size - photoDrawable.getIntrinsicWidth()) / 2;
int y = (size - photoDrawable.getIntrinsicHeight()) / 2;
photoDrawable.setBounds(x, y, x + photoDrawable.getIntrinsicWidth(), y + photoDrawable.getIntrinsicHeight());
photoDrawable.draw(canvas);
}
if (textLayout != null) {
canvas.translate((size - textWidth) / 2 - textLeft, (size - textHeight) / 2);
textLayout.draw(canvas);
} else if (drawPhoto && photoDrawable != null) {
int x = (size - photoDrawable.getIntrinsicWidth()) / 2;
int y = (size - photoDrawable.getIntrinsicHeight()) / 2;
photoDrawable.setBounds(x, y, x + photoDrawable.getIntrinsicWidth(), y + photoDrawable.getIntrinsicHeight());
photoDrawable.draw(canvas);
}
canvas.restore();
}
@@ -240,7 +240,7 @@ public class ChatAttachAlert extends BottomSheet implements NotificationCenter.N
currentUser = user;
TLRPC.FileLocation photo = null;
nameTextView.setText(ContactsController.formatName(user.first_name, user.last_name));
avatarDrawable.setInfo(user);
avatarDrawable.setInfoByUser(user);
if (user != null && user.photo != null) {
photo = user.photo.photo_small;
}
@@ -302,7 +302,7 @@ public class ChatAvatarContainer extends FrameLayout {
*/
// MrAvatar ...
avatarDrawable.setInfo(MrMailbox.MrChatGetName(parentFragment.m_hChat), null, false);
avatarDrawable.setInfoByName(MrMailbox.MrChatGetName(parentFragment.m_hChat));
if (avatarImageView != null) {
avatarImageView.setImage(newPhoto, "50_50", avatarDrawable);
@@ -212,7 +212,7 @@ public class GroupCreateFinalActivity extends BaseFragment implements Notificati
avatarImage = new BackupImageView(context);
avatarImage.setRoundRadius(AndroidUtilities.dp(32));
avatarDrawable.setInfo(null, null, chatType == ChatObject.CHAT_TYPE_BROADCAST);
avatarDrawable.setInfoByName(null);
avatarImage.setImageDrawable(avatarDrawable);
frameLayout.addView(avatarImage);
FrameLayout.LayoutParams layoutParams1 = (FrameLayout.LayoutParams) avatarImage.getLayoutParams();
@@ -301,7 +301,7 @@ public class GroupCreateFinalActivity extends BaseFragment implements Notificati
@Override
public void afterTextChanged(Editable s) {
avatarDrawable.setInfo(nameTextView.length() > 0 ? nameTextView.getText().toString() : null, null, false);
avatarDrawable.setInfoByName(nameTextView.length() > 0 ? nameTextView.getText().toString() : null);
avatarImage.invalidate();
}
});
@@ -1577,7 +1577,7 @@ public class ProfileActivity extends BaseFragment implements NotificationCenter.
rD = (int) ((Color.red(color) - Color.red(color2)) * progress);
gD = (int) ((Color.green(color) - Color.green(color2)) * progress);
bD = (int) ((Color.blue(color) - Color.blue(color2)) * progress);
avatarDrawable.setColor(Color.rgb(Color.red(color2) + rD, Color.green(color2) + gD, Color.blue(color2) + bD));
avatarDrawable.setColor_(Color.rgb(Color.red(color2) + rD, Color.green(color2) + gD, Color.blue(color2) + bD));
avatarImage.invalidate();
}
@@ -2036,7 +2036,7 @@ public class ProfileActivity extends BaseFragment implements NotificationCenter.
photo = user.photo.photo_small;
photoBig = user.photo.photo_big;
}
avatarDrawable.setInfo(user);
avatarDrawable.setInfoByUser(user);
avatarImage.setImage(photo, "50_50", avatarDrawable);
String newString = UserObject.getUserName(user);
@@ -2161,7 +2161,7 @@ public class ProfileActivity extends BaseFragment implements NotificationCenter.
photo = chat.photo.photo_small;
photoBig = chat.photo.photo_big;
}
avatarDrawable.setInfo(chat);
avatarDrawable.setInfoByChat(chat);
avatarImage.setImage(photo, "50_50", avatarDrawable);
avatarImage.getImageReceiver().setVisible(!PhotoViewer.getInstance().isShowingImage(photoBig), false);
}
@@ -1204,7 +1204,7 @@ public class SettingsActivity extends BaseFragment implements NotificationCenter
}
AvatarDrawable avatarDrawable = new AvatarDrawable(user, true);
avatarDrawable.setColor(Theme.ACTION_BAR_MAIN_AVATAR_COLOR);
avatarDrawable.setColor_(Theme.ACTION_BAR_MAIN_AVATAR_COLOR);
/* EDIT BY MR
if (avatarImage != null) {
avatarImage.setImage(photo, "50_50", avatarDrawable);