~singpolyma/cheogram-android

89c5e118dce8041cfa941e2c9dc0f316754ee7f5 — Stephen Paul Weber 1 year, 21 days ago d8e262d
Use ImageDecoder for avatars
M src/main/java/eu/siacs/conversations/persistance/FileBackend.java => src/main/java/eu/siacs/conversations/persistance/FileBackend.java +22 -2
@@ 2008,8 2008,28 @@ public class FileBackend {
        if (avatar == null) {
            return null;
        }
        Bitmap bm = cropCenter(getAvatarUri(avatar), size, size);
        return new BitmapDrawable(bm);

        if (android.os.Build.VERSION.SDK_INT >= 28) {
            try {
                ImageDecoder.Source source = ImageDecoder.createSource(getAvatarFile(avatar));
                return ImageDecoder.decodeDrawable(source, (decoder, info, src) -> {
                    int w = info.getSize().getWidth();
                    int h = info.getSize().getHeight();
                    Rect r = rectForSize(w, h, size);
                    decoder.setTargetSize(r.width(), r.height());

                    int newSize = Math.min(r.width(), r.height());
                    int left = (r.width() - newSize) / 2;
                    int top = (r.height() - newSize) / 2;
                    decoder.setCrop(new Rect(left, top, left + newSize, top + newSize));
                });
            } catch (final IOException e) {
                return null;
            }
        } else {
            Bitmap bm = cropCenter(getAvatarUri(avatar), size, size);
            return new BitmapDrawable(bm);
        }
    }

    private static class Dimensions {

M src/main/java/eu/siacs/conversations/services/AvatarService.java => src/main/java/eu/siacs/conversations/services/AvatarService.java +1 -1
@@ 154,7 154,7 @@ public class AvatarService implements OnAdvancedStreamFeaturesLoaded {
		canvas.drawARGB(0, 0, 0, 0);
		canvas.drawCircle(bitmap.getWidth() / 2, bitmap.getHeight() / 2, bitmap.getWidth() / 2, paint);
		paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));
		canvas.drawBitmap(bitmap, rect, rect, paint);
		canvas.drawBitmap(bitmap.copy(Bitmap.Config.ARGB_8888, false), rect, rect, paint);
	}

	private void drawIcon(Canvas canvas, Paint paint) {