Search in sources :

Example 6 with AnimatedFileDrawable

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

the class ImageReceiver method didReceivedNotification.

@Override
public void didReceivedNotification(int id, int account, Object... args) {
    if (id == NotificationCenter.didReplacedPhotoInMemCache) {
        String oldKey = (String) args[0];
        if (currentMediaKey != null && currentMediaKey.equals(oldKey)) {
            currentMediaKey = (String) args[1];
            currentMediaLocation = (ImageLocation) args[2];
            if (setImageBackup != null) {
                setImageBackup.mediaLocation = (ImageLocation) args[2];
            }
        }
        if (currentImageKey != null && currentImageKey.equals(oldKey)) {
            currentImageKey = (String) args[1];
            currentImageLocation = (ImageLocation) args[2];
            if (setImageBackup != null) {
                setImageBackup.imageLocation = (ImageLocation) args[2];
            }
        }
        if (currentThumbKey != null && currentThumbKey.equals(oldKey)) {
            currentThumbKey = (String) args[1];
            currentThumbLocation = (ImageLocation) args[2];
            if (setImageBackup != null) {
                setImageBackup.thumbLocation = (ImageLocation) args[2];
            }
        }
    } else if (id == NotificationCenter.stopAllHeavyOperations) {
        Integer layer = (Integer) args[0];
        if (currentLayerNum >= layer) {
            return;
        }
        currentOpenedLayerFlags |= layer;
        if (currentOpenedLayerFlags != 0) {
            RLottieDrawable lottieDrawable = getLottieAnimation();
            if (lottieDrawable != null && lottieDrawable.isHeavyDrawable()) {
                lottieDrawable.stop();
            }
            AnimatedFileDrawable animatedFileDrawable = getAnimation();
            if (animatedFileDrawable != null) {
                animatedFileDrawable.stop();
            }
        }
    } else if (id == NotificationCenter.startAllHeavyOperations) {
        Integer layer = (Integer) args[0];
        if (currentLayerNum >= layer || currentOpenedLayerFlags == 0) {
            return;
        }
        currentOpenedLayerFlags &= ~layer;
        if (currentOpenedLayerFlags == 0) {
            RLottieDrawable lottieDrawable = getLottieAnimation();
            if (allowStartLottieAnimation && lottieDrawable != null && lottieDrawable.isHeavyDrawable()) {
                lottieDrawable.start();
            }
            AnimatedFileDrawable animatedFileDrawable = getAnimation();
            if (allowStartAnimation && animatedFileDrawable != null) {
                animatedFileDrawable.start();
                if (parentView != null) {
                    parentView.invalidate();
                }
            }
        }
    }
}
Also used : AnimatedFileDrawable(org.telegram.ui.Components.AnimatedFileDrawable) RLottieDrawable(org.telegram.ui.Components.RLottieDrawable)

Example 7 with AnimatedFileDrawable

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

the class ImageReceiver method onAttachedToWindow.

public boolean onAttachedToWindow() {
    attachedToWindow = true;
    currentOpenedLayerFlags = NotificationCenter.getGlobalInstance().getCurrentHeavyOperationFlags();
    currentOpenedLayerFlags &= ~currentLayerNum;
    NotificationCenter.getGlobalInstance().addObserver(this, NotificationCenter.didReplacedPhotoInMemCache);
    NotificationCenter.getGlobalInstance().addObserver(this, NotificationCenter.stopAllHeavyOperations);
    NotificationCenter.getGlobalInstance().addObserver(this, NotificationCenter.startAllHeavyOperations);
    if (setBackupImage()) {
        return true;
    }
    RLottieDrawable lottieDrawable = getLottieAnimation();
    if (lottieDrawable != null && allowStartLottieAnimation && (!lottieDrawable.isHeavyDrawable() || currentOpenedLayerFlags == 0)) {
        lottieDrawable.start();
    }
    AnimatedFileDrawable animatedFileDrawable = getAnimation();
    if (animatedFileDrawable != null && parentView != null) {
        animatedFileDrawable.addParent(parentView);
    }
    if (animatedFileDrawable != null && allowStartAnimation && currentOpenedLayerFlags == 0) {
        animatedFileDrawable.start();
        if (parentView != null) {
            parentView.invalidate();
        }
    }
    if (NotificationCenter.getGlobalInstance().isAnimationInProgress()) {
        didReceivedNotification(NotificationCenter.stopAllHeavyOperations, currentAccount, 512);
    }
    return false;
}
Also used : AnimatedFileDrawable(org.telegram.ui.Components.AnimatedFileDrawable) RLottieDrawable(org.telegram.ui.Components.RLottieDrawable)

Example 8 with AnimatedFileDrawable

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

the class ImageReceiver method getBitmapHeight.

public int getBitmapHeight() {
    Drawable drawable = getDrawable();
    AnimatedFileDrawable animation = getAnimation();
    if (animation != null) {
        return imageOrientation % 360 == 0 || imageOrientation % 360 == 180 ? animation.getIntrinsicHeight() : animation.getIntrinsicWidth();
    }
    RLottieDrawable lottieDrawable = getLottieAnimation();
    if (lottieDrawable != null) {
        return lottieDrawable.getIntrinsicHeight();
    }
    Bitmap bitmap = getBitmap();
    if (bitmap == null) {
        if (staticThumbDrawable != null) {
            return staticThumbDrawable.getIntrinsicHeight();
        }
        return 1;
    }
    return imageOrientation % 360 == 0 || imageOrientation % 360 == 180 ? bitmap.getHeight() : bitmap.getWidth();
}
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)

Example 9 with AnimatedFileDrawable

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

the class ImageReceiver method setImageBitmap.

public void setImageBitmap(Drawable bitmap) {
    ImageLoader.getInstance().cancelLoadingForImageReceiver(this, true);
    if (crossfadeWithOldImage) {
        if (currentImageDrawable != null) {
            recycleBitmap(null, TYPE_THUMB);
            recycleBitmap(null, TYPE_CROSSFDADE);
            recycleBitmap(null, TYPE_MEDIA);
            crossfadeShader = imageShader;
            crossfadeImage = currentImageDrawable;
            crossfadeKey = currentImageKey;
            crossfadingWithThumb = true;
        } else if (currentThumbDrawable != null) {
            recycleBitmap(null, TYPE_IMAGE);
            recycleBitmap(null, TYPE_CROSSFDADE);
            recycleBitmap(null, TYPE_MEDIA);
            crossfadeShader = thumbShader;
            crossfadeImage = currentThumbDrawable;
            crossfadeKey = currentThumbKey;
            crossfadingWithThumb = true;
        } else if (staticThumbDrawable != null) {
            recycleBitmap(null, TYPE_IMAGE);
            recycleBitmap(null, TYPE_THUMB);
            recycleBitmap(null, TYPE_CROSSFDADE);
            recycleBitmap(null, TYPE_MEDIA);
            crossfadeShader = thumbShader;
            crossfadeImage = staticThumbDrawable;
            crossfadingWithThumb = true;
            crossfadeKey = null;
        } else {
            for (int a = 0; a < 4; a++) {
                recycleBitmap(null, a);
            }
            crossfadeShader = null;
        }
    } else {
        for (int a = 0; a < 4; a++) {
            recycleBitmap(null, a);
        }
    }
    if (staticThumbDrawable instanceof RecyclableDrawable) {
        RecyclableDrawable drawable = (RecyclableDrawable) staticThumbDrawable;
        drawable.recycle();
    }
    if (bitmap instanceof AnimatedFileDrawable) {
        AnimatedFileDrawable fileDrawable = (AnimatedFileDrawable) bitmap;
        fileDrawable.setParentView(parentView);
        if (attachedToWindow) {
            fileDrawable.addParent(parentView);
        }
        fileDrawable.setUseSharedQueue(useSharedAnimationQueue || fileDrawable.isWebmSticker);
        if (allowStartAnimation && currentOpenedLayerFlags == 0) {
            fileDrawable.start();
        }
        fileDrawable.setAllowDecodeSingleFrame(allowDecodeSingleFrame);
    } else if (bitmap instanceof RLottieDrawable) {
        RLottieDrawable fileDrawable = (RLottieDrawable) bitmap;
        fileDrawable.addParentView(parentView);
        if (allowStartLottieAnimation && (!fileDrawable.isHeavyDrawable() || currentOpenedLayerFlags == 0)) {
            fileDrawable.start();
        }
        fileDrawable.setAllowDecodeSingleFrame(true);
    }
    thumbShader = null;
    roundPaint.setShader(null);
    staticThumbDrawable = bitmap;
    updateDrawableRadius(bitmap);
    currentMediaLocation = null;
    currentMediaFilter = null;
    currentMediaDrawable = null;
    currentMediaKey = null;
    mediaShader = null;
    currentImageLocation = null;
    currentImageFilter = null;
    currentImageDrawable = null;
    currentImageKey = null;
    imageShader = null;
    composeShader = null;
    legacyShader = null;
    legacyCanvas = null;
    if (legacyBitmap != null) {
        legacyBitmap.recycle();
        legacyBitmap = null;
    }
    currentThumbLocation = null;
    currentThumbFilter = null;
    currentThumbKey = null;
    currentKeyQuality = false;
    currentExt = null;
    currentSize = 0;
    currentCacheType = 0;
    currentAlpha = 1;
    previousAlpha = 1f;
    if (setImageBackup != null) {
        setImageBackup.clear();
    }
    if (delegate != null) {
        delegate.didSetImage(this, currentThumbDrawable != null || staticThumbDrawable != null, true, false);
    }
    if (parentView != null) {
        if (invalidateAll) {
            parentView.invalidate();
        } else {
            parentView.invalidate((int) imageX, (int) imageY, (int) (imageX + imageW), (int) (imageY + imageH));
        }
    }
    if (forceCrossfade && crossfadeWithOldImage && crossfadeImage != null) {
        currentAlpha = 0.0f;
        lastUpdateAlphaTime = System.currentTimeMillis();
        crossfadeWithThumb = currentThumbDrawable != null || staticThumbDrawable != null;
    }
}
Also used : AnimatedFileDrawable(org.telegram.ui.Components.AnimatedFileDrawable) RLottieDrawable(org.telegram.ui.Components.RLottieDrawable) RecyclableDrawable(org.telegram.ui.Components.RecyclableDrawable) Paint(android.graphics.Paint)

Example 10 with AnimatedFileDrawable

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

the class ImageReceiver method setImage.

public void setImage(ImageLocation mediaLocation, String mediaFilter, ImageLocation imageLocation, String imageFilter, ImageLocation thumbLocation, String thumbFilter, Drawable thumb, int size, String ext, Object parentObject, int cacheType) {
    if (ignoreImageSet) {
        return;
    }
    if (crossfadeWithOldImage && setImageBackup != null && setImageBackup.isWebfileSet()) {
        setBackupImage();
    }
    if (setImageBackup != null) {
        setImageBackup.clear();
    }
    if (imageLocation == null && thumbLocation == null && mediaLocation == null) {
        for (int a = 0; a < 4; a++) {
            recycleBitmap(null, a);
        }
        currentImageLocation = null;
        currentImageFilter = null;
        currentImageKey = null;
        currentMediaLocation = null;
        currentMediaFilter = null;
        currentMediaKey = null;
        currentThumbLocation = null;
        currentThumbFilter = null;
        currentThumbKey = null;
        currentMediaDrawable = null;
        mediaShader = null;
        currentImageDrawable = null;
        imageShader = null;
        composeShader = null;
        thumbShader = null;
        crossfadeShader = null;
        legacyShader = null;
        legacyCanvas = null;
        if (legacyBitmap != null) {
            legacyBitmap.recycle();
            legacyBitmap = null;
        }
        currentExt = ext;
        currentParentObject = null;
        currentCacheType = 0;
        roundPaint.setShader(null);
        staticThumbDrawable = thumb;
        currentAlpha = 1.0f;
        previousAlpha = 1f;
        currentSize = 0;
        if (staticThumbDrawable instanceof SvgHelper.SvgDrawable) {
            ((SvgHelper.SvgDrawable) staticThumbDrawable).setParent(this);
        }
        ImageLoader.getInstance().cancelLoadingForImageReceiver(this, true);
        if (parentView != null) {
            if (invalidateAll) {
                parentView.invalidate();
            } else {
                parentView.invalidate((int) imageX, (int) imageY, (int) (imageX + imageW), (int) (imageY + imageH));
            }
        }
        if (delegate != null) {
            delegate.didSetImage(this, currentImageDrawable != null || currentThumbDrawable != null || staticThumbDrawable != null || currentMediaDrawable != null, currentImageDrawable == null && currentMediaDrawable == null, false);
        }
        return;
    }
    String imageKey = imageLocation != null ? imageLocation.getKey(parentObject, null, false) : null;
    if (imageKey == null && imageLocation != null) {
        imageLocation = null;
    }
    currentKeyQuality = false;
    if (imageKey == null && needsQualityThumb && (parentObject instanceof MessageObject || qulityThumbDocument != null)) {
        TLRPC.Document document = qulityThumbDocument != null ? qulityThumbDocument : ((MessageObject) parentObject).getDocument();
        if (document != null && document.dc_id != 0 && document.id != 0) {
            imageKey = "q_" + document.dc_id + "_" + document.id;
            currentKeyQuality = true;
        }
    }
    if (imageKey != null && imageFilter != null) {
        imageKey += "@" + imageFilter;
    }
    if (uniqKeyPrefix != null) {
        imageKey = uniqKeyPrefix + imageKey;
    }
    String mediaKey = mediaLocation != null ? mediaLocation.getKey(parentObject, null, false) : null;
    if (mediaKey == null && mediaLocation != null) {
        mediaLocation = null;
    }
    if (mediaKey != null && mediaFilter != null) {
        mediaKey += "@" + mediaFilter;
    }
    if (mediaKey == null && currentImageKey != null && currentImageKey.equals(imageKey) || currentMediaKey != null && currentMediaKey.equals(mediaKey)) {
        if (delegate != null) {
            delegate.didSetImage(this, currentImageDrawable != null || currentThumbDrawable != null || staticThumbDrawable != null || currentMediaDrawable != null, currentImageDrawable == null && currentMediaDrawable == null, false);
        }
        if (!canceledLoading) {
            return;
        }
    }
    ImageLocation strippedLoc;
    if (strippedLocation != null) {
        strippedLoc = strippedLocation;
    } else {
        strippedLoc = mediaLocation != null ? mediaLocation : imageLocation;
    }
    if (strippedLoc == null) {
        strippedLoc = thumbLocation;
    }
    String thumbKey = thumbLocation != null ? thumbLocation.getKey(parentObject, strippedLoc, false) : null;
    if (thumbKey != null && thumbFilter != null) {
        thumbKey += "@" + thumbFilter;
    }
    if (crossfadeWithOldImage) {
        if (currentMediaDrawable != null) {
            if (currentMediaDrawable instanceof AnimatedFileDrawable) {
                ((AnimatedFileDrawable) currentMediaDrawable).stop();
            }
            recycleBitmap(thumbKey, TYPE_THUMB);
            recycleBitmap(null, TYPE_CROSSFDADE);
            recycleBitmap(mediaKey, TYPE_IMAGE);
            crossfadeImage = currentMediaDrawable;
            crossfadeShader = mediaShader;
            crossfadeKey = currentImageKey;
            crossfadingWithThumb = false;
            currentMediaDrawable = null;
            currentMediaKey = null;
        } else if (currentImageDrawable != null) {
            recycleBitmap(thumbKey, TYPE_THUMB);
            recycleBitmap(null, TYPE_CROSSFDADE);
            recycleBitmap(mediaKey, TYPE_MEDIA);
            crossfadeShader = imageShader;
            crossfadeImage = currentImageDrawable;
            crossfadeKey = currentImageKey;
            crossfadingWithThumb = false;
            currentImageDrawable = null;
            currentImageKey = null;
        } else if (currentThumbDrawable != null) {
            recycleBitmap(imageKey, TYPE_IMAGE);
            recycleBitmap(null, TYPE_CROSSFDADE);
            recycleBitmap(mediaKey, TYPE_MEDIA);
            crossfadeShader = thumbShader;
            crossfadeImage = currentThumbDrawable;
            crossfadeKey = currentThumbKey;
            crossfadingWithThumb = false;
            currentThumbDrawable = null;
            currentThumbKey = null;
        } else if (staticThumbDrawable != null) {
            recycleBitmap(imageKey, TYPE_IMAGE);
            recycleBitmap(thumbKey, TYPE_THUMB);
            recycleBitmap(null, TYPE_CROSSFDADE);
            recycleBitmap(mediaKey, TYPE_MEDIA);
            crossfadeShader = thumbShader;
            crossfadeImage = staticThumbDrawable;
            crossfadingWithThumb = false;
            crossfadeKey = null;
            currentThumbDrawable = null;
            currentThumbKey = null;
        } else {
            recycleBitmap(imageKey, TYPE_IMAGE);
            recycleBitmap(thumbKey, TYPE_THUMB);
            recycleBitmap(null, TYPE_CROSSFDADE);
            recycleBitmap(mediaKey, TYPE_MEDIA);
            crossfadeShader = null;
        }
    } else {
        recycleBitmap(imageKey, TYPE_IMAGE);
        recycleBitmap(thumbKey, TYPE_THUMB);
        recycleBitmap(null, TYPE_CROSSFDADE);
        recycleBitmap(mediaKey, TYPE_MEDIA);
        crossfadeShader = null;
    }
    currentImageLocation = imageLocation;
    currentImageFilter = imageFilter;
    currentImageKey = imageKey;
    currentMediaLocation = mediaLocation;
    currentMediaFilter = mediaFilter;
    currentMediaKey = mediaKey;
    currentThumbLocation = thumbLocation;
    currentThumbFilter = thumbFilter;
    currentThumbKey = thumbKey;
    currentParentObject = parentObject;
    currentExt = ext;
    currentSize = size;
    currentCacheType = cacheType;
    staticThumbDrawable = thumb;
    imageShader = null;
    composeShader = null;
    thumbShader = null;
    mediaShader = null;
    legacyShader = null;
    legacyCanvas = null;
    roundPaint.setShader(null);
    if (legacyBitmap != null) {
        legacyBitmap.recycle();
        legacyBitmap = null;
    }
    currentAlpha = 1.0f;
    previousAlpha = 1f;
    if (staticThumbDrawable instanceof SvgHelper.SvgDrawable) {
        ((SvgHelper.SvgDrawable) staticThumbDrawable).setParent(this);
    }
    if (delegate != null) {
        delegate.didSetImage(this, currentImageDrawable != null || currentThumbDrawable != null || staticThumbDrawable != null || currentMediaDrawable != null, currentImageDrawable == null && currentMediaDrawable == null, false);
    }
    ImageLoader.getInstance().loadImageForImageReceiver(this);
    if (parentView != null) {
        if (invalidateAll) {
            parentView.invalidate();
        } else {
            parentView.invalidate((int) imageX, (int) imageY, (int) (imageX + imageW), (int) (imageY + imageH));
        }
    }
    isRoundVideo = parentObject instanceof MessageObject && ((MessageObject) parentObject).isRoundVideo();
}
Also used : AnimatedFileDrawable(org.telegram.ui.Components.AnimatedFileDrawable) Paint(android.graphics.Paint) TLRPC(org.telegram.tgnet.TLRPC)

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