change icon size
This commit is contained in:
parent
044ea5c5a9
commit
c86bc08c23
|
@ -48,7 +48,7 @@ public class AvatarService implements OnAdvancedStreamFeaturesLoaded {
|
||||||
private static final String PREFIX_GENERIC = "generic";
|
private static final String PREFIX_GENERIC = "generic";
|
||||||
|
|
||||||
final private ArrayList<Integer> sizes = new ArrayList<>();
|
final private ArrayList<Integer> sizes = new ArrayList<>();
|
||||||
final private HashMap<String,Set<String>> conversationDependentKeys = new HashMap<>();
|
final private HashMap<String, Set<String>> conversationDependentKeys = new HashMap<>();
|
||||||
|
|
||||||
protected XmppConnectionService mXmppConnectionService = null;
|
protected XmppConnectionService mXmppConnectionService = null;
|
||||||
|
|
||||||
|
@ -58,7 +58,7 @@ public class AvatarService implements OnAdvancedStreamFeaturesLoaded {
|
||||||
|
|
||||||
private Bitmap get(final Contact contact, final int size, boolean cachedOnly) {
|
private Bitmap get(final Contact contact, final int size, boolean cachedOnly) {
|
||||||
if (contact.isSelf()) {
|
if (contact.isSelf()) {
|
||||||
return get(contact.getAccount(),size,cachedOnly);
|
return get(contact.getAccount(), size, cachedOnly);
|
||||||
}
|
}
|
||||||
final String KEY = key(contact, size);
|
final String KEY = key(contact, size);
|
||||||
Bitmap avatar = this.mXmppConnectionService.getBitmapCache().get(KEY);
|
Bitmap avatar = this.mXmppConnectionService.getBitmapCache().get(KEY);
|
||||||
|
@ -72,30 +72,30 @@ public class AvatarService implements OnAdvancedStreamFeaturesLoaded {
|
||||||
avatar = mXmppConnectionService.getFileBackend().getAvatar(contact.getAvatar(), size);
|
avatar = mXmppConnectionService.getFileBackend().getAvatar(contact.getAvatar(), size);
|
||||||
}
|
}
|
||||||
if (avatar == null) {
|
if (avatar == null) {
|
||||||
avatar = get(contact.getDisplayName(), contact.getJid().asBareJid().toString(), size, cachedOnly);
|
avatar = get(contact.getDisplayName(), contact.getJid().asBareJid().toString(), size, cachedOnly);
|
||||||
}
|
}
|
||||||
this.mXmppConnectionService.getBitmapCache().put(KEY, avatar);
|
this.mXmppConnectionService.getBitmapCache().put(KEY, avatar);
|
||||||
return avatar;
|
return avatar;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Bitmap getRoundedShortcut(final Contact contact) {
|
public Bitmap getRoundedShortcut(final Contact contact) {
|
||||||
return getRoundedShortcut(contact,false);
|
return getRoundedShortcut(contact, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Bitmap getRoundedShortcutWithIcon(final Contact contact){
|
public Bitmap getRoundedShortcutWithIcon(final Contact contact) {
|
||||||
return getRoundedShortcut(contact,true);
|
return getRoundedShortcut(contact, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
private Bitmap getRoundedShortcut(final Contact contact,boolean withIcon) {
|
private Bitmap getRoundedShortcut(final Contact contact, boolean withIcon) {
|
||||||
DisplayMetrics metrics = mXmppConnectionService.getResources().getDisplayMetrics();
|
DisplayMetrics metrics = mXmppConnectionService.getResources().getDisplayMetrics();
|
||||||
int size = Math.round(metrics.density * 48);
|
int size = Math.round(metrics.density * 48);
|
||||||
Bitmap bitmap = get(contact,size);
|
Bitmap bitmap = get(contact, size);
|
||||||
Bitmap output = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), Bitmap.Config.ARGB_8888);
|
Bitmap output = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), Bitmap.Config.ARGB_8888);
|
||||||
Canvas canvas = new Canvas(output);
|
Canvas canvas = new Canvas(output);
|
||||||
final Paint paint = new Paint();
|
final Paint paint = new Paint();
|
||||||
|
|
||||||
drawAvatar(bitmap, canvas, paint);
|
drawAvatar(bitmap, canvas, paint);
|
||||||
if(withIcon){
|
if (withIcon) {
|
||||||
drawIcon(canvas, paint);
|
drawIcon(canvas, paint);
|
||||||
}
|
}
|
||||||
return output;
|
return output;
|
||||||
|
@ -112,14 +112,16 @@ public class AvatarService implements OnAdvancedStreamFeaturesLoaded {
|
||||||
|
|
||||||
private void drawIcon(Canvas canvas, Paint paint) {
|
private void drawIcon(Canvas canvas, Paint paint) {
|
||||||
BitmapFactory.Options opts = new BitmapFactory.Options();
|
BitmapFactory.Options opts = new BitmapFactory.Options();
|
||||||
opts.inSampleSize = 3;
|
opts.inSampleSize = 2;
|
||||||
Resources resources = mXmppConnectionService.getResources();
|
Resources resources = mXmppConnectionService.getResources();
|
||||||
Bitmap icon = BitmapFactory.decodeResource(resources, R.drawable.ic_launcher, opts);
|
Bitmap icon = BitmapFactory.decodeResource(resources, R.drawable.ic_launcher, opts);
|
||||||
paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_OVER));
|
paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_OVER));
|
||||||
|
|
||||||
int left = canvas.getWidth() - icon.getWidth();
|
int iconSize = Math.round(canvas.getHeight() / 2.6f);
|
||||||
int top = canvas.getHeight() - icon.getHeight();
|
|
||||||
final Rect rect = new Rect(left, top, left + icon.getWidth(), top + icon.getHeight());
|
int left = canvas.getWidth() - iconSize;
|
||||||
|
int top = canvas.getHeight() - iconSize;
|
||||||
|
final Rect rect = new Rect(left, top, left + iconSize, top + iconSize);
|
||||||
canvas.drawBitmap(icon, null, rect, paint);
|
canvas.drawBitmap(icon, null, rect, paint);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -161,7 +163,7 @@ public class AvatarService implements OnAdvancedStreamFeaturesLoaded {
|
||||||
key(contact, size));
|
key(contact, size));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for(Conversation conversation : mXmppConnectionService.findAllConferencesWith(contact)) {
|
for (Conversation conversation : mXmppConnectionService.findAllConferencesWith(contact)) {
|
||||||
clear(conversation);
|
clear(conversation);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -199,12 +201,12 @@ public class AvatarService implements OnAdvancedStreamFeaturesLoaded {
|
||||||
}
|
}
|
||||||
|
|
||||||
public Bitmap get(ListItem item, int size) {
|
public Bitmap get(ListItem item, int size) {
|
||||||
return get(item,size,false);
|
return get(item, size, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Bitmap get(ListItem item, int size, boolean cachedOnly) {
|
public Bitmap get(ListItem item, int size, boolean cachedOnly) {
|
||||||
if (item instanceof Contact) {
|
if (item instanceof Contact) {
|
||||||
return get((Contact) item, size,cachedOnly);
|
return get((Contact) item, size, cachedOnly);
|
||||||
} else if (item instanceof Bookmark) {
|
} else if (item instanceof Bookmark) {
|
||||||
Bookmark bookmark = (Bookmark) item;
|
Bookmark bookmark = (Bookmark) item;
|
||||||
if (bookmark.getConversation() != null) {
|
if (bookmark.getConversation() != null) {
|
||||||
|
@ -220,7 +222,7 @@ public class AvatarService implements OnAdvancedStreamFeaturesLoaded {
|
||||||
}
|
}
|
||||||
|
|
||||||
public Bitmap get(Conversation conversation, int size) {
|
public Bitmap get(Conversation conversation, int size) {
|
||||||
return get(conversation,size,false);
|
return get(conversation, size, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Bitmap get(Conversation conversation, int size, boolean cachedOnly) {
|
public Bitmap get(Conversation conversation, int size, boolean cachedOnly) {
|
||||||
|
@ -242,7 +244,7 @@ public class AvatarService implements OnAdvancedStreamFeaturesLoaded {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
LruCache<String, Bitmap> cache = this.mXmppConnectionService.getBitmapCache();
|
LruCache<String, Bitmap> cache = this.mXmppConnectionService.getBitmapCache();
|
||||||
for(String key : keys) {
|
for (String key : keys) {
|
||||||
cache.remove(key);
|
cache.remove(key);
|
||||||
}
|
}
|
||||||
keys.clear();
|
keys.clear();
|
||||||
|
@ -250,7 +252,7 @@ public class AvatarService implements OnAdvancedStreamFeaturesLoaded {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private Bitmap get(MucOptions mucOptions, int size, boolean cachedOnly) {
|
private Bitmap get(MucOptions mucOptions, int size, boolean cachedOnly) {
|
||||||
final String KEY = key(mucOptions, size);
|
final String KEY = key(mucOptions, size);
|
||||||
Bitmap bitmap = this.mXmppConnectionService.getBitmapCache().get(KEY);
|
Bitmap bitmap = this.mXmppConnectionService.getBitmapCache().get(KEY);
|
||||||
if (bitmap != null || cachedOnly) {
|
if (bitmap != null || cachedOnly) {
|
||||||
|
@ -259,9 +261,9 @@ public class AvatarService implements OnAdvancedStreamFeaturesLoaded {
|
||||||
final List<MucOptions.User> users = mucOptions.getUsersRelevantForNameAndAvatar();
|
final List<MucOptions.User> users = mucOptions.getUsersRelevantForNameAndAvatar();
|
||||||
if (users.size() == 0) {
|
if (users.size() == 0) {
|
||||||
Conversation c = mucOptions.getConversation();
|
Conversation c = mucOptions.getConversation();
|
||||||
bitmap = getImpl(c.getName().toString(),c.getJid().asBareJid().toString(),size);
|
bitmap = getImpl(c.getName().toString(), c.getJid().asBareJid().toString(), size);
|
||||||
} else {
|
} else {
|
||||||
bitmap = getImpl(users,size);
|
bitmap = getImpl(users, size);
|
||||||
}
|
}
|
||||||
this.mXmppConnectionService.getBitmapCache().put(KEY, bitmap);
|
this.mXmppConnectionService.getBitmapCache().put(KEY, bitmap);
|
||||||
return bitmap;
|
return bitmap;
|
||||||
|
@ -274,7 +276,7 @@ public class AvatarService implements OnAdvancedStreamFeaturesLoaded {
|
||||||
return bitmap;
|
return bitmap;
|
||||||
}
|
}
|
||||||
bitmap = getImpl(users, size);
|
bitmap = getImpl(users, size);
|
||||||
this.mXmppConnectionService.getBitmapCache().put(KEY,bitmap);
|
this.mXmppConnectionService.getBitmapCache().put(KEY, bitmap);
|
||||||
return bitmap;
|
return bitmap;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -335,7 +337,7 @@ public class AvatarService implements OnAdvancedStreamFeaturesLoaded {
|
||||||
StringBuilder builder = new StringBuilder("TILE_");
|
StringBuilder builder = new StringBuilder("TILE_");
|
||||||
builder.append(conversation.getUuid());
|
builder.append(conversation.getUuid());
|
||||||
|
|
||||||
for(MucOptions.User user : users) {
|
for (MucOptions.User user : users) {
|
||||||
builder.append("\0");
|
builder.append("\0");
|
||||||
builder.append(emptyOnNull(user.getRealJid()));
|
builder.append(emptyOnNull(user.getRealJid()));
|
||||||
builder.append("\0");
|
builder.append("\0");
|
||||||
|
@ -350,7 +352,7 @@ public class AvatarService implements OnAdvancedStreamFeaturesLoaded {
|
||||||
keys = this.conversationDependentKeys.get(conversation.getUuid());
|
keys = this.conversationDependentKeys.get(conversation.getUuid());
|
||||||
} else {
|
} else {
|
||||||
keys = new HashSet<>();
|
keys = new HashSet<>();
|
||||||
this.conversationDependentKeys.put(conversation.getUuid(),keys);
|
this.conversationDependentKeys.put(conversation.getUuid(), keys);
|
||||||
}
|
}
|
||||||
keys.add(key);
|
keys.add(key);
|
||||||
}
|
}
|
||||||
|
@ -369,7 +371,7 @@ public class AvatarService implements OnAdvancedStreamFeaturesLoaded {
|
||||||
}
|
}
|
||||||
avatar = mXmppConnectionService.getFileBackend().getAvatar(account.getAvatar(), size);
|
avatar = mXmppConnectionService.getFileBackend().getAvatar(account.getAvatar(), size);
|
||||||
if (avatar == null) {
|
if (avatar == null) {
|
||||||
avatar = get(account.getJid().asBareJid().toString(), null, size,false);
|
avatar = get(account.getJid().asBareJid().toString(), null, size, false);
|
||||||
}
|
}
|
||||||
mXmppConnectionService.getBitmapCache().put(KEY, avatar);
|
mXmppConnectionService.getBitmapCache().put(KEY, avatar);
|
||||||
return avatar;
|
return avatar;
|
||||||
|
@ -378,12 +380,12 @@ public class AvatarService implements OnAdvancedStreamFeaturesLoaded {
|
||||||
public Bitmap get(Message message, int size, boolean cachedOnly) {
|
public Bitmap get(Message message, int size, boolean cachedOnly) {
|
||||||
final Conversation conversation = message.getConversation();
|
final Conversation conversation = message.getConversation();
|
||||||
if (message.getType() == Message.TYPE_STATUS && message.getCounterparts() != null && message.getCounterparts().size() > 1) {
|
if (message.getType() == Message.TYPE_STATUS && message.getCounterparts() != null && message.getCounterparts().size() > 1) {
|
||||||
return get(message.getCounterparts(),size,cachedOnly);
|
return get(message.getCounterparts(), size, cachedOnly);
|
||||||
} else if (message.getStatus() == Message.STATUS_RECEIVED) {
|
} else if (message.getStatus() == Message.STATUS_RECEIVED) {
|
||||||
Contact c = message.getContact();
|
Contact c = message.getContact();
|
||||||
if (c != null && (c.getProfilePhoto() != null || c.getAvatar() != null)) {
|
if (c != null && (c.getProfilePhoto() != null || c.getAvatar() != null)) {
|
||||||
return get(c, size, cachedOnly);
|
return get(c, size, cachedOnly);
|
||||||
} else if (message.getConversation().getMode() == Conversation.MODE_MULTI){
|
} else if (message.getConversation().getMode() == Conversation.MODE_MULTI) {
|
||||||
final Jid trueCounterpart = message.getTrueCounterpart();
|
final Jid trueCounterpart = message.getTrueCounterpart();
|
||||||
MucOptions.User user;
|
MucOptions.User user;
|
||||||
if (trueCounterpart != null) {
|
if (trueCounterpart != null) {
|
||||||
|
@ -392,15 +394,15 @@ public class AvatarService implements OnAdvancedStreamFeaturesLoaded {
|
||||||
user = conversation.getMucOptions().findUserByFullJid(message.getCounterpart());
|
user = conversation.getMucOptions().findUserByFullJid(message.getCounterpart());
|
||||||
}
|
}
|
||||||
if (user != null) {
|
if (user != null) {
|
||||||
return getImpl(user,size,cachedOnly);
|
return getImpl(user, size, cachedOnly);
|
||||||
}
|
}
|
||||||
} else if (c != null) {
|
} else if (c != null) {
|
||||||
return get(c, size, cachedOnly);
|
return get(c, size, cachedOnly);
|
||||||
}
|
}
|
||||||
Jid tcp = message.getTrueCounterpart();
|
Jid tcp = message.getTrueCounterpart();
|
||||||
String seed = tcp != null ? tcp.asBareJid().toString() :null;
|
String seed = tcp != null ? tcp.asBareJid().toString() : null;
|
||||||
return get(UIHelper.getMessageDisplayName(message), seed, size, cachedOnly);
|
return get(UIHelper.getMessageDisplayName(message), seed, size, cachedOnly);
|
||||||
} else {
|
} else {
|
||||||
return get(conversation.getAccount(), size, cachedOnly);
|
return get(conversation.getAccount(), size, cachedOnly);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -536,7 +538,7 @@ public class AvatarService implements OnAdvancedStreamFeaturesLoaded {
|
||||||
}
|
}
|
||||||
|
|
||||||
private static String getFirstLetter(String name) {
|
private static String getFirstLetter(String name) {
|
||||||
for(Character c : name.toCharArray()) {
|
for (Character c : name.toCharArray()) {
|
||||||
if (Character.isLetterOrDigit(c)) {
|
if (Character.isLetterOrDigit(c)) {
|
||||||
return c.toString();
|
return c.toString();
|
||||||
}
|
}
|
||||||
|
@ -566,7 +568,7 @@ public class AvatarService implements OnAdvancedStreamFeaturesLoaded {
|
||||||
public void onAdvancedStreamFeaturesAvailable(Account account) {
|
public void onAdvancedStreamFeaturesAvailable(Account account) {
|
||||||
XmppConnection.Features features = account.getXmppConnection().getFeatures();
|
XmppConnection.Features features = account.getXmppConnection().getFeatures();
|
||||||
if (features.pep() && !features.pepPersistent()) {
|
if (features.pep() && !features.pepPersistent()) {
|
||||||
Log.d(Config.LOGTAG,account.getJid().asBareJid()+": has pep but is not persistent");
|
Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": has pep but is not persistent");
|
||||||
if (account.getAvatar() != null) {
|
if (account.getAvatar() != null) {
|
||||||
mXmppConnectionService.republishAvatarIfNeeded(account);
|
mXmppConnectionService.republishAvatarIfNeeded(account);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue