Class GifDrawable

  • All Implemented Interfaces:
    android.graphics.drawable.Animatable, androidx.vectordrawable.graphics.drawable.Animatable2Compat, com.bumptech.glide.load.resource.gif.GifFrameLoader.FrameCallback

    public class GifDrawable
    extends android.graphics.drawable.Drawable
    implements com.bumptech.glide.load.resource.gif.GifFrameLoader.FrameCallback, android.graphics.drawable.Animatable, androidx.vectordrawable.graphics.drawable.Animatable2Compat
    An animated Drawable that plays the frames of an animated GIF.
    • Nested Class Summary

      • Nested classes/interfaces inherited from class android.graphics.drawable.Drawable

        android.graphics.drawable.Drawable.Callback, android.graphics.drawable.Drawable.ConstantState
      • Nested classes/interfaces inherited from interface androidx.vectordrawable.graphics.drawable.Animatable2Compat

        androidx.vectordrawable.graphics.drawable.Animatable2Compat.AnimationCallback
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static int LOOP_FOREVER
      A constant indicating that an animated drawable should loop continuously.
      static int LOOP_INTRINSIC
      A constant indicating that an animated drawable should loop for its default number of times.
    • Constructor Summary

      Constructors 
      Constructor Description
      GifDrawable​(android.content.Context context, com.bumptech.glide.gifdecoder.GifDecoder gifDecoder, BitmapPool bitmapPool, Transformation<android.graphics.Bitmap> frameTransformation, int targetFrameWidth, int targetFrameHeight, android.graphics.Bitmap firstFrame)
      GifDrawable​(android.content.Context context, com.bumptech.glide.gifdecoder.GifDecoder gifDecoder, Transformation<android.graphics.Bitmap> frameTransformation, int targetFrameWidth, int targetFrameHeight, android.graphics.Bitmap firstFrame)
      Constructor for GifDrawable.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void clearAnimationCallbacks()  
      void draw​(android.graphics.Canvas canvas)  
      java.nio.ByteBuffer getBuffer()  
      android.graphics.drawable.Drawable.ConstantState getConstantState()  
      android.graphics.Bitmap getFirstFrame()  
      int getFrameCount()  
      int getFrameIndex()
      Returns the current frame index in the range 0..getFrameCount() - 1, or -1 if no frame is displayed.
      Transformation<android.graphics.Bitmap> getFrameTransformation()  
      int getIntrinsicHeight()  
      int getIntrinsicWidth()  
      int getOpacity()  
      int getSize()  
      boolean isRunning()  
      protected void onBoundsChange​(android.graphics.Rect bounds)  
      void onFrameReady()  
      void recycle()
      Clears any resources for loading frames that are currently held on to by this object.
      void registerAnimationCallback​(androidx.vectordrawable.graphics.drawable.Animatable2Compat.AnimationCallback animationCallback)
      Register callback to listen to GifDrawable animation end event after specific loop count set by setLoopCount(int).
      void setAlpha​(int i)  
      void setColorFilter​(android.graphics.ColorFilter colorFilter)  
      void setFrameTransformation​(Transformation<android.graphics.Bitmap> frameTransformation, android.graphics.Bitmap firstFrame)  
      void setLoopCount​(int loopCount)  
      boolean setVisible​(boolean visible, boolean restart)  
      void start()  
      void startFromFirstFrame()
      Starts the animation from the first frame.
      void stop()  
      boolean unregisterAnimationCallback​(androidx.vectordrawable.graphics.drawable.Animatable2Compat.AnimationCallback animationCallback)  
      • Methods inherited from class android.graphics.drawable.Drawable

        applyTheme, canApplyTheme, clearColorFilter, copyBounds, copyBounds, createFromPath, createFromResourceStream, createFromResourceStream, createFromStream, createFromXml, createFromXml, createFromXmlInner, createFromXmlInner, getAlpha, getBounds, getCallback, getChangingConfigurations, getColorFilter, getCurrent, getDirtyBounds, getHotspotBounds, getLayoutDirection, getLevel, getMinimumHeight, getMinimumWidth, getOpticalInsets, getOutline, getPadding, getState, getTransparentRegion, hasFocusStateSpecified, inflate, inflate, invalidateSelf, isAutoMirrored, isFilterBitmap, isProjected, isStateful, isVisible, jumpToCurrentState, mutate, onLayoutDirectionChanged, onLevelChange, onStateChange, resolveOpacity, scheduleSelf, setAutoMirrored, setBounds, setBounds, setCallback, setChangingConfigurations, setColorFilter, setDither, setFilterBitmap, setHotspot, setHotspotBounds, setLayoutDirection, setLevel, setState, setTint, setTintBlendMode, setTintList, setTintMode, unscheduleSelf
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • LOOP_FOREVER

        public static final int LOOP_FOREVER
        A constant indicating that an animated drawable should loop continuously.
        See Also:
        Constant Field Values
      • LOOP_INTRINSIC

        public static final int LOOP_INTRINSIC
        A constant indicating that an animated drawable should loop for its default number of times. For animated GIFs, this constant indicates the GIF should use the netscape loop count if present.
        See Also:
        Constant Field Values
    • Constructor Detail

      • GifDrawable

        @Deprecated
        public GifDrawable​(android.content.Context context,
                           com.bumptech.glide.gifdecoder.GifDecoder gifDecoder,
                           BitmapPool bitmapPool,
                           Transformation<android.graphics.Bitmap> frameTransformation,
                           int targetFrameWidth,
                           int targetFrameHeight,
                           android.graphics.Bitmap firstFrame)
        Constructor for GifDrawable.
        Parameters:
        context - A context.
        bitmapPool - Ignored, see deprecation note.
        frameTransformation - An Transformation that can be applied to each frame.
        targetFrameWidth - The desired width of the frames displayed by this drawable (the width of the view or Target this drawable is being loaded into).
        targetFrameHeight - The desired height of the frames displayed by this drawable (the height of the view or Target this drawable is being loaded into).
        gifDecoder - The decoder to use to decode GIF data.
        firstFrame - The decoded and transformed first frame of this GIF.
        See Also:
        setFrameTransformation(com.bumptech.glide.load.Transformation, android.graphics.Bitmap)
      • GifDrawable

        public GifDrawable​(android.content.Context context,
                           com.bumptech.glide.gifdecoder.GifDecoder gifDecoder,
                           Transformation<android.graphics.Bitmap> frameTransformation,
                           int targetFrameWidth,
                           int targetFrameHeight,
                           android.graphics.Bitmap firstFrame)
        Constructor for GifDrawable.
        Parameters:
        context - A context.
        frameTransformation - An Transformation that can be applied to each frame.
        targetFrameWidth - The desired width of the frames displayed by this drawable (the width of the view or Target this drawable is being loaded into).
        targetFrameHeight - The desired height of the frames displayed by this drawable (the height of the view or Target this drawable is being loaded into).
        gifDecoder - The decoder to use to decode GIF data.
        firstFrame - The decoded and transformed first frame of this GIF.
        See Also:
        setFrameTransformation(com.bumptech.glide.load.Transformation, android.graphics.Bitmap)
    • Method Detail

      • getSize

        public int getSize()
      • getFirstFrame

        public android.graphics.Bitmap getFirstFrame()
      • setFrameTransformation

        public void setFrameTransformation​(Transformation<android.graphics.Bitmap> frameTransformation,
                                           android.graphics.Bitmap firstFrame)
      • getFrameTransformation

        public Transformation<android.graphics.Bitmap> getFrameTransformation()
      • getBuffer

        public java.nio.ByteBuffer getBuffer()
      • getFrameCount

        public int getFrameCount()
      • getFrameIndex

        public int getFrameIndex()
        Returns the current frame index in the range 0..getFrameCount() - 1, or -1 if no frame is displayed.
      • startFromFirstFrame

        public void startFromFirstFrame()
        Starts the animation from the first frame. Can only be called while animation is not running.
      • start

        public void start()
        Specified by:
        start in interface android.graphics.drawable.Animatable
      • stop

        public void stop()
        Specified by:
        stop in interface android.graphics.drawable.Animatable
      • setVisible

        public boolean setVisible​(boolean visible,
                                  boolean restart)
        Overrides:
        setVisible in class android.graphics.drawable.Drawable
      • getIntrinsicWidth

        public int getIntrinsicWidth()
        Overrides:
        getIntrinsicWidth in class android.graphics.drawable.Drawable
      • getIntrinsicHeight

        public int getIntrinsicHeight()
        Overrides:
        getIntrinsicHeight in class android.graphics.drawable.Drawable
      • isRunning

        public boolean isRunning()
        Specified by:
        isRunning in interface android.graphics.drawable.Animatable
      • onBoundsChange

        protected void onBoundsChange​(android.graphics.Rect bounds)
        Overrides:
        onBoundsChange in class android.graphics.drawable.Drawable
      • draw

        public void draw​(@NonNull
                         android.graphics.Canvas canvas)
        Specified by:
        draw in class android.graphics.drawable.Drawable
      • setAlpha

        public void setAlpha​(int i)
        Specified by:
        setAlpha in class android.graphics.drawable.Drawable
      • setColorFilter

        public void setColorFilter​(android.graphics.ColorFilter colorFilter)
        Specified by:
        setColorFilter in class android.graphics.drawable.Drawable
      • getOpacity

        public int getOpacity()
        Specified by:
        getOpacity in class android.graphics.drawable.Drawable
      • onFrameReady

        public void onFrameReady()
        Specified by:
        onFrameReady in interface com.bumptech.glide.load.resource.gif.GifFrameLoader.FrameCallback
      • getConstantState

        public android.graphics.drawable.Drawable.ConstantState getConstantState()
        Overrides:
        getConstantState in class android.graphics.drawable.Drawable
      • recycle

        public void recycle()
        Clears any resources for loading frames that are currently held on to by this object.
      • setLoopCount

        public void setLoopCount​(int loopCount)
      • registerAnimationCallback

        public void registerAnimationCallback​(@NonNull
                                              androidx.vectordrawable.graphics.drawable.Animatable2Compat.AnimationCallback animationCallback)
        Register callback to listen to GifDrawable animation end event after specific loop count set by setLoopCount(int).

        Note: This will only be called if the Gif stop because it reaches the loop count. Unregister this in onLoadCleared to avoid potential memory leak.

        Specified by:
        registerAnimationCallback in interface androidx.vectordrawable.graphics.drawable.Animatable2Compat
        Parameters:
        animationCallback - Animation callback Animatable2Compat.AnimationCallback.
      • unregisterAnimationCallback

        public boolean unregisterAnimationCallback​(@NonNull
                                                   androidx.vectordrawable.graphics.drawable.Animatable2Compat.AnimationCallback animationCallback)
        Specified by:
        unregisterAnimationCallback in interface androidx.vectordrawable.graphics.drawable.Animatable2Compat
      • clearAnimationCallbacks

        public void clearAnimationCallbacks()
        Specified by:
        clearAnimationCallbacks in interface androidx.vectordrawable.graphics.drawable.Animatable2Compat