fixed avatar in notification

This commit is contained in:
iNPUTmice 2014-08-11 23:18:16 +02:00
parent f247abc2dc
commit 8a82586d5b
3 changed files with 32 additions and 19 deletions

View file

@ -321,7 +321,7 @@ public class Contact implements ListItem {
@Override @Override
public Bitmap getImage(int size, Context context) { public Bitmap getImage(int size, Context context) {
if (this.avatar!=null) { if (this.avatar!=null) {
Bitmap bm = BitmapFactory.decodeFile(FileBackend.getAvatarPath(context, avatar)); Bitmap bm = FileBackend.getAvatar(avatar, size, context);
if (bm==null) { if (bm==null) {
return UIHelper.getContactPicture(this, size, context, false); return UIHelper.getContactPicture(this, size, context, false);
} else { } else {

View file

@ -30,6 +30,7 @@ import eu.siacs.conversations.entities.Conversation;
import eu.siacs.conversations.entities.Message; import eu.siacs.conversations.entities.Message;
import eu.siacs.conversations.services.ImageProvider; import eu.siacs.conversations.services.ImageProvider;
import eu.siacs.conversations.utils.CryptoHelper; import eu.siacs.conversations.utils.CryptoHelper;
import eu.siacs.conversations.utils.UIHelper;
import eu.siacs.conversations.xmpp.jingle.JingleFile; import eu.siacs.conversations.xmpp.jingle.JingleFile;
import eu.siacs.conversations.xmpp.pep.Avatar; import eu.siacs.conversations.xmpp.pep.Avatar;
@ -330,6 +331,13 @@ public class FileBackend {
InputStream is = context.getContentResolver() InputStream is = context.getContentResolver()
.openInputStream(image); .openInputStream(image);
Bitmap input = BitmapFactory.decodeStream(is, null, options); Bitmap input = BitmapFactory.decodeStream(is, null, options);
return cropCenterSquare(input, size);
} catch (FileNotFoundException e) {
return null;
}
}
public static Bitmap cropCenterSquare(Bitmap input, int size) {
int w = input.getWidth(); int w = input.getWidth();
int h = input.getHeight(); int h = input.getHeight();
@ -346,9 +354,6 @@ public class FileBackend {
Canvas canvas = new Canvas(output); Canvas canvas = new Canvas(output);
canvas.drawBitmap(input, null, target, null); canvas.drawBitmap(input, null, target, null);
return output; return output;
} catch (FileNotFoundException e) {
return null;
}
} }
private int calcSampleSize(Uri image, int size) private int calcSampleSize(Uri image, int size)
@ -395,4 +400,12 @@ public class FileBackend {
return resId; return resId;
} }
} }
public static Bitmap getAvatar(String avatar, int size, Context context) {
Bitmap bm = BitmapFactory.decodeFile(FileBackend.getAvatarPath(context, avatar));
if (bm==null) {
return null;
}
return cropCenterSquare(bm, UIHelper.getRealPx(size, context));
}
} }

View file

@ -15,6 +15,7 @@ import eu.siacs.conversations.entities.Contact;
import eu.siacs.conversations.entities.Conversation; import eu.siacs.conversations.entities.Conversation;
import eu.siacs.conversations.entities.Message; import eu.siacs.conversations.entities.Message;
import eu.siacs.conversations.entities.MucOptions.User; import eu.siacs.conversations.entities.MucOptions.User;
import eu.siacs.conversations.persistance.FileBackend;
import eu.siacs.conversations.ui.ConversationActivity; import eu.siacs.conversations.ui.ConversationActivity;
import eu.siacs.conversations.ui.ManageAccountActivity; import eu.siacs.conversations.ui.ManageAccountActivity;
import android.app.Activity; import android.app.Activity;
@ -376,8 +377,7 @@ public class UIHelper {
} else if (unread.size() == 1) { } else if (unread.size() == 1) {
Conversation conversation = unread.get(0); Conversation conversation = unread.get(0);
targetUuid = conversation.getUuid(); targetUuid = conversation.getUuid();
mBuilder.setLargeIcon(UIHelper.getContactPicture(conversation, 64, mBuilder.setLargeIcon(conversation.getImage(context, 64));
context, true));
mBuilder.setContentTitle(conversation.getName(useSubject)); mBuilder.setContentTitle(conversation.getName(useSubject));
if (notify) { if (notify) {
mBuilder.setTicker(conversation.getLatestMessage() mBuilder.setTicker(conversation.getLatestMessage()