Search in sources :

Example 21 with AnimatedFileDrawable

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

the class SendMessagesHelper method createVideoThumbnailAtTime.

public static Bitmap createVideoThumbnailAtTime(String filePath, long time, int[] orientation, boolean precise) {
    Bitmap bitmap = null;
    if (precise) {
        AnimatedFileDrawable fileDrawable = new AnimatedFileDrawable(new File(filePath), true, 0, null, null, null, 0, 0, true);
        bitmap = fileDrawable.getFrameAtTime(time, precise);
        if (orientation != null) {
            orientation[0] = fileDrawable.getOrientation();
        }
        fileDrawable.recycle();
        if (bitmap == null) {
            return createVideoThumbnailAtTime(filePath, time, orientation, false);
        }
    } else {
        MediaMetadataRetriever retriever = new MediaMetadataRetriever();
        try {
            retriever.setDataSource(filePath);
            bitmap = retriever.getFrameAtTime(time, MediaMetadataRetriever.OPTION_NEXT_SYNC);
            if (bitmap == null) {
                bitmap = retriever.getFrameAtTime(time, MediaMetadataRetriever.OPTION_CLOSEST);
            }
        } catch (Exception ignore) {
        // Assume this is a corrupt video file.
        } finally {
            try {
                retriever.release();
            } catch (RuntimeException ex) {
            // Ignore failures while cleaning up.
            }
        }
    }
    return bitmap;
}
Also used : Bitmap(android.graphics.Bitmap) AnimatedFileDrawable(org.telegram.ui.Components.AnimatedFileDrawable) MediaMetadataRetriever(android.media.MediaMetadataRetriever) RandomAccessFile(java.io.RandomAccessFile) File(java.io.File)

Example 22 with AnimatedFileDrawable

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

the class ImageLoader method getFromLottieCahce.

private BitmapDrawable getFromLottieCahce(String imageKey) {
    BitmapDrawable drawable = lottieMemCache.get(imageKey);
    if (drawable instanceof AnimatedFileDrawable) {
        if (((AnimatedFileDrawable) drawable).isRecycled()) {
            lottieMemCache.remove(imageKey);
            drawable = null;
        }
    }
    return drawable;
}
Also used : AnimatedFileDrawable(org.telegram.ui.Components.AnimatedFileDrawable) BitmapDrawable(android.graphics.drawable.BitmapDrawable)

Example 23 with AnimatedFileDrawable

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

the class ImageReceiver method onDetachedFromWindow.

public void onDetachedFromWindow() {
    attachedToWindow = false;
    if (currentImageLocation != null || currentMediaLocation != null || currentThumbLocation != null || staticThumbDrawable != null) {
        if (setImageBackup == null) {
            setImageBackup = new SetImageBackup();
        }
        setImageBackup.mediaLocation = currentMediaLocation;
        setImageBackup.mediaFilter = currentMediaFilter;
        setImageBackup.imageLocation = currentImageLocation;
        setImageBackup.imageFilter = currentImageFilter;
        setImageBackup.thumbLocation = currentThumbLocation;
        setImageBackup.thumbFilter = currentThumbFilter;
        setImageBackup.thumb = staticThumbDrawable;
        setImageBackup.size = currentSize;
        setImageBackup.ext = currentExt;
        setImageBackup.cacheType = currentCacheType;
        setImageBackup.parentObject = currentParentObject;
    }
    NotificationCenter.getGlobalInstance().removeObserver(this, NotificationCenter.didReplacedPhotoInMemCache);
    NotificationCenter.getGlobalInstance().removeObserver(this, NotificationCenter.stopAllHeavyOperations);
    NotificationCenter.getGlobalInstance().removeObserver(this, NotificationCenter.startAllHeavyOperations);
    if (staticThumbDrawable != null) {
        staticThumbDrawable = null;
        thumbShader = null;
        roundPaint.setShader(null);
    }
    clearImage();
    if (isPressed == 0) {
        pressedProgress = 0f;
    }
    AnimatedFileDrawable animatedFileDrawable = getAnimation();
    if (animatedFileDrawable != null) {
        animatedFileDrawable.removeParent(parentView);
    }
}
Also used : AnimatedFileDrawable(org.telegram.ui.Components.AnimatedFileDrawable)

Example 24 with AnimatedFileDrawable

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

the class ImageReceiver method startAnimation.

public void startAnimation() {
    AnimatedFileDrawable animation = getAnimation();
    if (animation != null) {
        animation.setUseSharedQueue(useSharedAnimationQueue);
        animation.start();
    } else {
        RLottieDrawable rLottieDrawable = getLottieAnimation();
        if (rLottieDrawable != null && !rLottieDrawable.isRunning()) {
            rLottieDrawable.restart();
        }
    }
}
Also used : AnimatedFileDrawable(org.telegram.ui.Components.AnimatedFileDrawable) RLottieDrawable(org.telegram.ui.Components.RLottieDrawable)

Example 25 with AnimatedFileDrawable

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

the class ImageReceiver method recycleBitmap.

private void recycleBitmap(String newKey, int type) {
    String key;
    Drawable image;
    if (type == TYPE_MEDIA) {
        key = currentMediaKey;
        image = currentMediaDrawable;
    } else if (type == TYPE_CROSSFDADE) {
        key = crossfadeKey;
        image = crossfadeImage;
    } else if (type == TYPE_THUMB) {
        key = currentThumbKey;
        image = currentThumbDrawable;
    } else {
        key = currentImageKey;
        image = currentImageDrawable;
    }
    if (key != null && (key.startsWith("-") || key.startsWith("strippedmessage-"))) {
        String replacedKey = ImageLoader.getInstance().getReplacedKey(key);
        if (replacedKey != null) {
            key = replacedKey;
        }
    }
    if (image instanceof RLottieDrawable) {
        RLottieDrawable lottieDrawable = (RLottieDrawable) image;
        lottieDrawable.removeParentView(parentView);
    }
    if (image instanceof AnimatedFileDrawable) {
        AnimatedFileDrawable lottieDrawable = (AnimatedFileDrawable) image;
        lottieDrawable.removeParent(parentView);
    }
    if (key != null && (newKey == null || !newKey.equals(key)) && image != null) {
        if (image instanceof RLottieDrawable) {
            RLottieDrawable fileDrawable = (RLottieDrawable) image;
            boolean canDelete = ImageLoader.getInstance().decrementUseCount(key);
            if (!ImageLoader.getInstance().isInMemCache(key, true)) {
                if (canDelete) {
                    fileDrawable.recycle();
                }
            }
        } else if (image instanceof AnimatedFileDrawable) {
            AnimatedFileDrawable fileDrawable = (AnimatedFileDrawable) image;
            if (fileDrawable.isWebmSticker) {
                boolean canDelete = ImageLoader.getInstance().decrementUseCount(key);
                if (!ImageLoader.getInstance().isInMemCache(key, true)) {
                    if (canDelete) {
                        fileDrawable.recycle();
                    }
                } else if (canDelete) {
                    fileDrawable.stop();
                }
            } else {
                fileDrawable.recycle();
            }
        } else if (image instanceof BitmapDrawable) {
            Bitmap bitmap = ((BitmapDrawable) image).getBitmap();
            boolean canDelete = ImageLoader.getInstance().decrementUseCount(key);
            if (!ImageLoader.getInstance().isInMemCache(key, false)) {
                if (canDelete) {
                    bitmap.recycle();
                }
            }
        }
    }
    if (type == TYPE_MEDIA) {
        currentMediaKey = null;
        currentMediaDrawable = null;
    } else if (type == TYPE_CROSSFDADE) {
        crossfadeKey = null;
        crossfadeImage = null;
    } else if (type == TYPE_THUMB) {
        currentThumbDrawable = null;
        currentThumbKey = null;
    } else {
        currentImageDrawable = null;
        currentImageKey = null;
    }
}
Also used : Bitmap(android.graphics.Bitmap) AnimatedFileDrawable(org.telegram.ui.Components.AnimatedFileDrawable) LoadingStickerDrawable(org.telegram.ui.Components.LoadingStickerDrawable) AnimatedFileDrawable(org.telegram.ui.Components.AnimatedFileDrawable) Drawable(android.graphics.drawable.Drawable) BitmapDrawable(android.graphics.drawable.BitmapDrawable) RecyclableDrawable(org.telegram.ui.Components.RecyclableDrawable) RLottieDrawable(org.telegram.ui.Components.RLottieDrawable) RLottieDrawable(org.telegram.ui.Components.RLottieDrawable) BitmapDrawable(android.graphics.drawable.BitmapDrawable)

Aggregations

AnimatedFileDrawable (org.telegram.ui.Components.AnimatedFileDrawable)31 RLottieDrawable (org.telegram.ui.Components.RLottieDrawable)17 Paint (android.graphics.Paint)14 Bitmap (android.graphics.Bitmap)11 Drawable (android.graphics.drawable.Drawable)11 BitmapDrawable (android.graphics.drawable.BitmapDrawable)10 SuppressLint (android.annotation.SuppressLint)9 TextPaint (android.text.TextPaint)9 MessageObject (org.telegram.messenger.MessageObject)6 ClippingImageView (org.telegram.ui.Components.ClippingImageView)6 LoadingStickerDrawable (org.telegram.ui.Components.LoadingStickerDrawable)6 TextureView (android.view.TextureView)5 View (android.view.View)5 HorizontalScrollView (android.widget.HorizontalScrollView)5 ImageView (android.widget.ImageView)5 TextView (android.widget.TextView)5 RecyclerView (androidx.recyclerview.widget.RecyclerView)5 ImageReceiver (org.telegram.messenger.ImageReceiver)5 Canvas (android.graphics.Canvas)3 StaticLayout (android.text.StaticLayout)3