aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java/de/pixart/messenger/services/AvatarService.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/de/pixart/messenger/services/AvatarService.java')
-rw-r--r--src/main/java/de/pixart/messenger/services/AvatarService.java31
1 files changed, 27 insertions, 4 deletions
diff --git a/src/main/java/de/pixart/messenger/services/AvatarService.java b/src/main/java/de/pixart/messenger/services/AvatarService.java
index edc0a2e67..23e2da4d6 100644
--- a/src/main/java/de/pixart/messenger/services/AvatarService.java
+++ b/src/main/java/de/pixart/messenger/services/AvatarService.java
@@ -10,8 +10,11 @@ import android.graphics.PorterDuffXfermode;
import android.graphics.Rect;
import android.graphics.RectF;
import android.graphics.Typeface;
+import android.graphics.drawable.BitmapDrawable;
+import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.support.annotation.Nullable;
+import android.support.v4.content.res.ResourcesCompat;
import android.text.TextUtils;
import android.util.DisplayMetrics;
import android.util.Log;
@@ -131,10 +134,11 @@ public class AvatarService implements OnAdvancedStreamFeaturesLoaded {
}
private void drawIcon(Canvas canvas, Paint paint) {
- BitmapFactory.Options opts = new BitmapFactory.Options();
- opts.inSampleSize = 2;
- Resources resources = mXmppConnectionService.getResources();
- Bitmap icon = BitmapFactory.decodeResource(resources, R.drawable.ic_launcher, opts);
+ final Resources resources = mXmppConnectionService.getResources();
+ final Bitmap icon = getRoundLauncherIcon(resources);
+ if (icon == null) {
+ return;
+ }
paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_OVER));
int iconSize = Math.round(canvas.getHeight() / 2.6f);
@@ -145,6 +149,25 @@ public class AvatarService implements OnAdvancedStreamFeaturesLoaded {
canvas.drawBitmap(icon, null, rect, paint);
}
+ private static Bitmap getRoundLauncherIcon(Resources resources) {
+
+ final Drawable drawable = ResourcesCompat.getDrawable(resources, R.drawable.ic_launcher, null);
+ if (drawable == null) {
+ return null;
+ }
+
+ if (drawable instanceof BitmapDrawable) {
+ return ((BitmapDrawable) drawable).getBitmap();
+ }
+
+ Bitmap bitmap = Bitmap.createBitmap(drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight(), Bitmap.Config.ARGB_8888);
+ Canvas canvas = new Canvas(bitmap);
+ drawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight());
+ drawable.draw(canvas);
+
+ return bitmap;
+ }
+
public Bitmap get(final MucOptions.User user, final int size, boolean cachedOnly) {
Contact c = user.getContact();
if (c != null && (c.getProfilePhoto() != null || c.getAvatarFilename() != null || user.getAvatar() == null)) {