Java Code Examples for org.telegram.ui.Components.AnimatedFileDrawable#hasBitmap()

The following examples show how to use org.telegram.ui.Components.AnimatedFileDrawable#hasBitmap() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ImageReceiver.java    From Telegram-FOSS with GNU General Public License v2.0 6 votes vote down vote up
public Bitmap getBitmap() {
    AnimatedFileDrawable animation = getAnimation();
    RLottieDrawable lottieDrawable = getLottieAnimation();
    if (lottieDrawable != null && lottieDrawable.hasBitmap()) {
        return lottieDrawable.getAnimatedBitmap();
    } else if (animation != null && animation.hasBitmap()) {
        return animation.getAnimatedBitmap();
    } else if (currentMediaDrawable instanceof BitmapDrawable && !(currentMediaDrawable instanceof AnimatedFileDrawable) && !(currentMediaDrawable instanceof RLottieDrawable)) {
        return ((BitmapDrawable) currentMediaDrawable).getBitmap();
    } else if (currentImageDrawable instanceof BitmapDrawable && !(currentImageDrawable instanceof AnimatedFileDrawable) && !(currentMediaDrawable instanceof RLottieDrawable)) {
        return ((BitmapDrawable) currentImageDrawable).getBitmap();
    } else if (currentThumbDrawable instanceof BitmapDrawable && !(currentThumbDrawable instanceof AnimatedFileDrawable) && !(currentMediaDrawable instanceof RLottieDrawable)) {
        return ((BitmapDrawable) currentThumbDrawable).getBitmap();
    } else if (staticThumbDrawable instanceof BitmapDrawable) {
        return ((BitmapDrawable) staticThumbDrawable).getBitmap();
    }
    return null;
}
 
Example 2
Source File: ImageReceiver.java    From Telegram-FOSS with GNU General Public License v2.0 6 votes vote down vote up
public BitmapHolder getBitmapSafe() {
    Bitmap bitmap = null;
    String key = null;
    AnimatedFileDrawable animation = getAnimation();
    RLottieDrawable lottieDrawable = getLottieAnimation();
    if (lottieDrawable != null && lottieDrawable.hasBitmap()) {
        bitmap = lottieDrawable.getAnimatedBitmap();
    } else if (animation != null && animation.hasBitmap()) {
        bitmap = animation.getAnimatedBitmap();
    } else if (currentMediaDrawable instanceof BitmapDrawable && !(currentMediaDrawable instanceof AnimatedFileDrawable) && !(currentMediaDrawable instanceof RLottieDrawable)) {
        bitmap = ((BitmapDrawable) currentMediaDrawable).getBitmap();
        key = currentMediaKey;
    } else if (currentImageDrawable instanceof BitmapDrawable && !(currentImageDrawable instanceof AnimatedFileDrawable) && !(currentMediaDrawable instanceof RLottieDrawable)) {
        bitmap = ((BitmapDrawable) currentImageDrawable).getBitmap();
        key = currentImageKey;
    } else if (currentThumbDrawable instanceof BitmapDrawable && !(currentThumbDrawable instanceof AnimatedFileDrawable) && !(currentMediaDrawable instanceof RLottieDrawable)) {
        bitmap = ((BitmapDrawable) currentThumbDrawable).getBitmap();
        key = currentThumbKey;
    } else if (staticThumbDrawable instanceof BitmapDrawable) {
        bitmap = ((BitmapDrawable) staticThumbDrawable).getBitmap();
    }
    if (bitmap != null) {
        return new BitmapHolder(bitmap, key);
    }
    return null;
}
 
Example 3
Source File: ImageReceiver.java    From Telegram with GNU General Public License v2.0 6 votes vote down vote up
public Bitmap getBitmap() {
    AnimatedFileDrawable animation = getAnimation();
    RLottieDrawable lottieDrawable = getLottieAnimation();
    if (lottieDrawable != null && lottieDrawable.hasBitmap()) {
        return lottieDrawable.getAnimatedBitmap();
    } else if (animation != null && animation.hasBitmap()) {
        return animation.getAnimatedBitmap();
    } else if (currentMediaDrawable instanceof BitmapDrawable && !(currentMediaDrawable instanceof AnimatedFileDrawable) && !(currentMediaDrawable instanceof RLottieDrawable)) {
        return ((BitmapDrawable) currentMediaDrawable).getBitmap();
    } else if (currentImageDrawable instanceof BitmapDrawable && !(currentImageDrawable instanceof AnimatedFileDrawable) && !(currentMediaDrawable instanceof RLottieDrawable)) {
        return ((BitmapDrawable) currentImageDrawable).getBitmap();
    } else if (currentThumbDrawable instanceof BitmapDrawable && !(currentThumbDrawable instanceof AnimatedFileDrawable) && !(currentMediaDrawable instanceof RLottieDrawable)) {
        return ((BitmapDrawable) currentThumbDrawable).getBitmap();
    } else if (staticThumbDrawable instanceof BitmapDrawable) {
        return ((BitmapDrawable) staticThumbDrawable).getBitmap();
    }
    return null;
}
 
Example 4
Source File: ImageReceiver.java    From Telegram with GNU General Public License v2.0 6 votes vote down vote up
public BitmapHolder getBitmapSafe() {
    Bitmap bitmap = null;
    String key = null;
    AnimatedFileDrawable animation = getAnimation();
    RLottieDrawable lottieDrawable = getLottieAnimation();
    if (lottieDrawable != null && lottieDrawable.hasBitmap()) {
        bitmap = lottieDrawable.getAnimatedBitmap();
    } else if (animation != null && animation.hasBitmap()) {
        bitmap = animation.getAnimatedBitmap();
    } else if (currentMediaDrawable instanceof BitmapDrawable && !(currentMediaDrawable instanceof AnimatedFileDrawable) && !(currentMediaDrawable instanceof RLottieDrawable)) {
        bitmap = ((BitmapDrawable) currentMediaDrawable).getBitmap();
        key = currentMediaKey;
    } else if (currentImageDrawable instanceof BitmapDrawable && !(currentImageDrawable instanceof AnimatedFileDrawable) && !(currentMediaDrawable instanceof RLottieDrawable)) {
        bitmap = ((BitmapDrawable) currentImageDrawable).getBitmap();
        key = currentImageKey;
    } else if (currentThumbDrawable instanceof BitmapDrawable && !(currentThumbDrawable instanceof AnimatedFileDrawable) && !(currentMediaDrawable instanceof RLottieDrawable)) {
        bitmap = ((BitmapDrawable) currentThumbDrawable).getBitmap();
        key = currentThumbKey;
    } else if (staticThumbDrawable instanceof BitmapDrawable) {
        bitmap = ((BitmapDrawable) staticThumbDrawable).getBitmap();
    }
    if (bitmap != null) {
        return new BitmapHolder(bitmap, key);
    }
    return null;
}
 
Example 5
Source File: ImageReceiver.java    From Telegram-FOSS with GNU General Public License v2.0 4 votes vote down vote up
public boolean draw(Canvas canvas) {
    try {
        Drawable drawable = null;
        AnimatedFileDrawable animation = getAnimation();
        RLottieDrawable lottieDrawable = getLottieAnimation();
        boolean animationNotReady = animation != null && !animation.hasBitmap() || lottieDrawable != null && !lottieDrawable.hasBitmap();
        if (lottieDrawable != null) {
            lottieDrawable.setCurrentParentView(parentView);
        }
        if ((animation != null || lottieDrawable != null) && !animationNotReady && !animationReadySent) {
            animationReadySent = true;
            if (delegate != null) {
                delegate.onAnimationReady(this);
            }
        }
        int orientation = 0;
        BitmapShader shaderToUse = null;
        if (!forcePreview && currentMediaDrawable != null && !animationNotReady) {
            drawable = currentMediaDrawable;
            shaderToUse = mediaShader;
            orientation = imageOrientation;
        } else if (!forcePreview && currentImageDrawable != null && (!animationNotReady || currentMediaDrawable != null)) {
            drawable = currentImageDrawable;
            shaderToUse = imageShader;
            orientation = imageOrientation;
            animationNotReady = false;
        } else if (crossfadeImage != null && !crossfadingWithThumb) {
            drawable = crossfadeImage;
            shaderToUse = crossfadeShader;
            orientation = imageOrientation;
        } else if (staticThumbDrawable instanceof BitmapDrawable) {
            drawable = staticThumbDrawable;
            shaderToUse = thumbShader;
            orientation = thumbOrientation;
        } else if (currentThumbDrawable != null) {
            drawable = currentThumbDrawable;
            shaderToUse = thumbShader;
            orientation = thumbOrientation;
        }
        if (drawable != null) {
            if (crossfadeAlpha != 0) {
                if (crossfadeWithThumb && animationNotReady) {
                    drawDrawable(canvas, drawable, (int) (overrideAlpha * 255), shaderToUse, orientation);
                } else {
                    if (crossfadeWithThumb && currentAlpha != 1.0f) {
                        Drawable thumbDrawable = null;
                        BitmapShader thumbShaderToUse = null;
                        if (drawable == currentImageDrawable || drawable == currentMediaDrawable) {
                            if (crossfadeImage != null) {
                                thumbDrawable = crossfadeImage;
                                thumbShaderToUse = crossfadeShader;
                            } else if (currentThumbDrawable != null) {
                                thumbDrawable = currentThumbDrawable;
                                thumbShaderToUse = thumbShader;
                            } else if (staticThumbDrawable != null) {
                                thumbDrawable = staticThumbDrawable;
                                thumbShaderToUse = thumbShader;
                            }
                        } else if (drawable == currentThumbDrawable || drawable == crossfadeImage) {
                            if (staticThumbDrawable != null) {
                                thumbDrawable = staticThumbDrawable;
                                thumbShaderToUse = thumbShader;
                            }
                        } else if (drawable == staticThumbDrawable) {
                            if (crossfadeImage != null) {
                                thumbDrawable = crossfadeImage;
                                thumbShaderToUse = crossfadeShader;
                            }
                        }
                        if (thumbDrawable != null) {
                            drawDrawable(canvas, thumbDrawable, (int) (overrideAlpha * 255), thumbShaderToUse, thumbOrientation);
                        }
                    }
                    drawDrawable(canvas, drawable, (int) (overrideAlpha * currentAlpha * 255), shaderToUse, orientation);
                }
            } else {
                drawDrawable(canvas, drawable, (int) (overrideAlpha * 255), shaderToUse, orientation);
            }

            checkAlphaAnimation(animationNotReady && crossfadeWithThumb);
            return true;
        } else if (staticThumbDrawable != null) {
            drawDrawable(canvas, staticThumbDrawable, (int) (overrideAlpha * 255), null, thumbOrientation);
            checkAlphaAnimation(animationNotReady);
            return true;
        } else {
            checkAlphaAnimation(animationNotReady);
        }
    } catch (Exception e) {
        FileLog.e(e);
    }
    return false;
}
 
Example 6
Source File: ImageReceiver.java    From Telegram with GNU General Public License v2.0 4 votes vote down vote up
public boolean draw(Canvas canvas) {
    try {
        Drawable drawable = null;
        AnimatedFileDrawable animation = getAnimation();
        RLottieDrawable lottieDrawable = getLottieAnimation();
        boolean animationNotReady = animation != null && !animation.hasBitmap() || lottieDrawable != null && !lottieDrawable.hasBitmap();
        if (lottieDrawable != null) {
            lottieDrawable.setCurrentParentView(parentView);
        }
        if ((animation != null || lottieDrawable != null) && !animationNotReady && !animationReadySent) {
            animationReadySent = true;
            if (delegate != null) {
                delegate.onAnimationReady(this);
            }
        }
        int orientation = 0;
        BitmapShader shaderToUse = null;
        if (!forcePreview && currentMediaDrawable != null && !animationNotReady) {
            drawable = currentMediaDrawable;
            shaderToUse = mediaShader;
            orientation = imageOrientation;
        } else if (!forcePreview && currentImageDrawable != null && (!animationNotReady || currentMediaDrawable != null)) {
            drawable = currentImageDrawable;
            shaderToUse = imageShader;
            orientation = imageOrientation;
            animationNotReady = false;
        } else if (crossfadeImage != null && !crossfadingWithThumb) {
            drawable = crossfadeImage;
            shaderToUse = crossfadeShader;
            orientation = imageOrientation;
        } else if (staticThumbDrawable instanceof BitmapDrawable) {
            drawable = staticThumbDrawable;
            shaderToUse = thumbShader;
            orientation = thumbOrientation;
        } else if (currentThumbDrawable != null) {
            drawable = currentThumbDrawable;
            shaderToUse = thumbShader;
            orientation = thumbOrientation;
        }
        if (drawable != null) {
            if (crossfadeAlpha != 0) {
                if (crossfadeWithThumb && animationNotReady) {
                    drawDrawable(canvas, drawable, (int) (overrideAlpha * 255), shaderToUse, orientation);
                } else {
                    if (crossfadeWithThumb && currentAlpha != 1.0f) {
                        Drawable thumbDrawable = null;
                        BitmapShader thumbShaderToUse = null;
                        if (drawable == currentImageDrawable || drawable == currentMediaDrawable) {
                            if (crossfadeImage != null) {
                                thumbDrawable = crossfadeImage;
                                thumbShaderToUse = crossfadeShader;
                            } else if (currentThumbDrawable != null) {
                                thumbDrawable = currentThumbDrawable;
                                thumbShaderToUse = thumbShader;
                            } else if (staticThumbDrawable != null) {
                                thumbDrawable = staticThumbDrawable;
                                thumbShaderToUse = thumbShader;
                            }
                        } else if (drawable == currentThumbDrawable || drawable == crossfadeImage) {
                            if (staticThumbDrawable != null) {
                                thumbDrawable = staticThumbDrawable;
                                thumbShaderToUse = thumbShader;
                            }
                        } else if (drawable == staticThumbDrawable) {
                            if (crossfadeImage != null) {
                                thumbDrawable = crossfadeImage;
                                thumbShaderToUse = crossfadeShader;
                            }
                        }
                        if (thumbDrawable != null) {
                            drawDrawable(canvas, thumbDrawable, (int) (overrideAlpha * 255), thumbShaderToUse, thumbOrientation);
                        }
                    }
                    drawDrawable(canvas, drawable, (int) (overrideAlpha * currentAlpha * 255), shaderToUse, orientation);
                }
            } else {
                drawDrawable(canvas, drawable, (int) (overrideAlpha * 255), shaderToUse, orientation);
            }

            checkAlphaAnimation(animationNotReady && crossfadeWithThumb);
            return true;
        } else if (staticThumbDrawable != null) {
            drawDrawable(canvas, staticThumbDrawable, (int) (overrideAlpha * 255), null, thumbOrientation);
            checkAlphaAnimation(animationNotReady);
            return true;
        } else {
            checkAlphaAnimation(animationNotReady);
        }
    } catch (Exception e) {
        FileLog.e(e);
    }
    return false;
}