Search in sources :

Example 6 with Point

use of org.telegram.ui.Components.Point in project Telegram-FOSS by Telegram-FOSS-Team.

the class ImageLoader method generateMessageThumb.

public static MessageThumb generateMessageThumb(TLRPC.Message message) {
    TLRPC.PhotoSize photoSize = findPhotoCachedSize(message);
    if (photoSize != null && photoSize.bytes != null && photoSize.bytes.length != 0) {
        File file = FileLoader.getPathToAttach(photoSize, true);
        TLRPC.TL_photoSize newPhotoSize = new TLRPC.TL_photoSize_layer127();
        newPhotoSize.w = photoSize.w;
        newPhotoSize.h = photoSize.h;
        newPhotoSize.location = photoSize.location;
        newPhotoSize.size = photoSize.size;
        newPhotoSize.type = photoSize.type;
        if (file.exists() && message.grouped_id == 0) {
            int h = photoSize.h;
            int w = photoSize.w;
            Point point = ChatMessageCell.getMessageSize(w, h);
            String key = String.format(Locale.US, "%d_%d@%d_%d_b", photoSize.location.volume_id, photoSize.location.local_id, (int) (point.x / AndroidUtilities.density), (int) (point.y / AndroidUtilities.density));
            if (!getInstance().isInMemCache(key, false)) {
                Bitmap bitmap = ImageLoader.loadBitmap(file.getPath(), null, (int) (point.x / AndroidUtilities.density), (int) (point.y / AndroidUtilities.density), false);
                if (bitmap != null) {
                    Utilities.blurBitmap(bitmap, 3, 1, bitmap.getWidth(), bitmap.getHeight(), bitmap.getRowBytes());
                    Bitmap scaledBitmap = Bitmaps.createScaledBitmap(bitmap, (int) (point.x / AndroidUtilities.density), (int) (point.y / AndroidUtilities.density), true);
                    if (scaledBitmap != bitmap) {
                        bitmap.recycle();
                        bitmap = scaledBitmap;
                    }
                    return new MessageThumb(key, new BitmapDrawable(bitmap));
                }
            }
        }
    } else if (message.media instanceof TLRPC.TL_messageMediaDocument) {
        for (int a = 0, count = message.media.document.thumbs.size(); a < count; a++) {
            TLRPC.PhotoSize size = message.media.document.thumbs.get(a);
            if (size instanceof TLRPC.TL_photoStrippedSize) {
                TLRPC.PhotoSize thumbSize = FileLoader.getClosestPhotoSizeWithSize(message.media.document.thumbs, 320);
                int h = 0;
                int w = 0;
                if (thumbSize != null) {
                    h = thumbSize.h;
                    w = thumbSize.w;
                } else {
                    for (int k = 0; k < message.media.document.attributes.size(); k++) {
                        if (message.media.document.attributes.get(k) instanceof TLRPC.TL_documentAttributeVideo) {
                            TLRPC.TL_documentAttributeVideo videoAttribute = (TLRPC.TL_documentAttributeVideo) message.media.document.attributes.get(k);
                            h = videoAttribute.h;
                            w = videoAttribute.w;
                            break;
                        }
                    }
                }
                Point point = ChatMessageCell.getMessageSize(w, h);
                String key = String.format(Locale.US, "%s_false@%d_%d_b", ImageLocation.getStippedKey(message, message, size), (int) (point.x / AndroidUtilities.density), (int) (point.y / AndroidUtilities.density));
                if (!getInstance().isInMemCache(key, false)) {
                    Bitmap b = getStrippedPhotoBitmap(size.bytes, null);
                    if (b != null) {
                        Utilities.blurBitmap(b, 3, 1, b.getWidth(), b.getHeight(), b.getRowBytes());
                        Bitmap scaledBitmap = Bitmaps.createScaledBitmap(b, (int) (point.x / AndroidUtilities.density), (int) (point.y / AndroidUtilities.density), true);
                        if (scaledBitmap != b) {
                            b.recycle();
                            b = scaledBitmap;
                        }
                        return new MessageThumb(key, new BitmapDrawable(b));
                    }
                }
            }
        }
    }
    return null;
}
Also used : Point(org.telegram.ui.Components.Point) BitmapDrawable(android.graphics.drawable.BitmapDrawable) TLRPC(org.telegram.tgnet.TLRPC) Point(org.telegram.ui.Components.Point) Bitmap(android.graphics.Bitmap) RandomAccessFile(java.io.RandomAccessFile) File(java.io.File)

Aggregations

Point (org.telegram.ui.Components.Point)6 File (java.io.File)4 Paint (android.graphics.Paint)3 SuppressLint (android.annotation.SuppressLint)2 Bitmap (android.graphics.Bitmap)2 BitmapDrawable (android.graphics.drawable.BitmapDrawable)2 RandomAccessFile (java.io.RandomAccessFile)2 TLRPC (org.telegram.tgnet.TLRPC)2 Animator (android.animation.Animator)1 AnimatorListenerAdapter (android.animation.AnimatorListenerAdapter)1 AnimatorSet (android.animation.AnimatorSet)1 Keyframe (android.animation.Keyframe)1 ObjectAnimator (android.animation.ObjectAnimator)1 PropertyValuesHolder (android.animation.PropertyValuesHolder)1 ValueAnimator (android.animation.ValueAnimator)1 Activity (android.app.Activity)1 Context (android.content.Context)1 ColorStateList (android.content.res.ColorStateList)1 Configuration (android.content.res.Configuration)1 BitmapFactory (android.graphics.BitmapFactory)1