aboutsummaryrefslogtreecommitdiffstats
path: root/src/eu/siacs/conversations/persistance
diff options
context:
space:
mode:
authoriNPUTmice <daniel@gultsch.de>2014-08-11 23:18:16 +0200
committeriNPUTmice <daniel@gultsch.de>2014-08-11 23:18:16 +0200
commit8a82586d5bfbdfa5fdefe0bf1b0538a405a0f871 (patch)
tree2ef41d6f468d0807c991b19672632c9d6e8e75ed /src/eu/siacs/conversations/persistance
parentf247abc2dc1aa7d19c8cd616f4654fc3a8d8109d (diff)
fixed avatar in notification
Diffstat (limited to 'src/eu/siacs/conversations/persistance')
-rw-r--r--src/eu/siacs/conversations/persistance/FileBackend.java45
1 files changed, 29 insertions, 16 deletions
diff --git a/src/eu/siacs/conversations/persistance/FileBackend.java b/src/eu/siacs/conversations/persistance/FileBackend.java
index c00b197b..6164f852 100644
--- a/src/eu/siacs/conversations/persistance/FileBackend.java
+++ b/src/eu/siacs/conversations/persistance/FileBackend.java
@@ -30,6 +30,7 @@ import eu.siacs.conversations.entities.Conversation;
import eu.siacs.conversations.entities.Message;
import eu.siacs.conversations.services.ImageProvider;
import eu.siacs.conversations.utils.CryptoHelper;
+import eu.siacs.conversations.utils.UIHelper;
import eu.siacs.conversations.xmpp.jingle.JingleFile;
import eu.siacs.conversations.xmpp.pep.Avatar;
@@ -330,26 +331,30 @@ public class FileBackend {
InputStream is = context.getContentResolver()
.openInputStream(image);
Bitmap input = BitmapFactory.decodeStream(is, null, options);
- int w = input.getWidth();
- int h = input.getHeight();
-
- float scale = Math.max((float) size / h, (float) size / w);
-
- float outWidth = scale * w;
- float outHeight = scale * h;
- float left = (size - outWidth) / 2;
- float top = (size - outHeight) / 2;
- RectF target = new RectF(left, top, left + outWidth, top
- + outHeight);
-
- Bitmap output = Bitmap.createBitmap(size, size, input.getConfig());
- Canvas canvas = new Canvas(output);
- canvas.drawBitmap(input, null, target, null);
- return output;
+ return cropCenterSquare(input, size);
} catch (FileNotFoundException e) {
return null;
}
}
+
+ public static Bitmap cropCenterSquare(Bitmap input, int size) {
+ int w = input.getWidth();
+ int h = input.getHeight();
+
+ float scale = Math.max((float) size / h, (float) size / w);
+
+ float outWidth = scale * w;
+ float outHeight = scale * h;
+ float left = (size - outWidth) / 2;
+ float top = (size - outHeight) / 2;
+ RectF target = new RectF(left, top, left + outWidth, top
+ + outHeight);
+
+ Bitmap output = Bitmap.createBitmap(size, size, input.getConfig());
+ Canvas canvas = new Canvas(output);
+ canvas.drawBitmap(input, null, target, null);
+ return output;
+ }
private int calcSampleSize(Uri image, int size)
throws FileNotFoundException {
@@ -395,4 +400,12 @@ public class FileBackend {
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));
+ }
}