Class GifDrawable

java.lang.Object
android.graphics.drawable.Drawable
com.bumptech.glide.load.resource.gif.GifDrawable
All Implemented Interfaces:
Animatable, androidx.vectordrawable.graphics.drawable.Animatable2Compat, com.bumptech.glide.load.resource.gif.GifFrameLoader.FrameCallback

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

    • LOOP_FOREVER

      public static final int LOOP_FOREVER
      A constant indicating that an animated drawable should loop continuously.
      See Also:
    • 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:
  • Constructor Details

    • GifDrawable

      @Deprecated public GifDrawable(Context context, com.bumptech.glide.gifdecoder.GifDecoder gifDecoder, BitmapPool bitmapPool, Transformation<Bitmap> frameTransformation, int targetFrameWidth, int targetFrameHeight, 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:
    • GifDrawable

      public GifDrawable(Context context, com.bumptech.glide.gifdecoder.GifDecoder gifDecoder, Transformation<Bitmap> frameTransformation, int targetFrameWidth, int targetFrameHeight, 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:
  • Method Details

    • getSize

      public int getSize()
    • getFirstFrame

      public Bitmap getFirstFrame()
    • setFrameTransformation

      public void setFrameTransformation(Transformation<Bitmap> frameTransformation, Bitmap firstFrame)
    • getFrameTransformation

      public Transformation<Bitmap> getFrameTransformation()
    • getBuffer

      public 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 Animatable
    • stop

      public void stop()
      Specified by:
      stop in interface Animatable
    • setVisible

      public boolean setVisible(boolean visible, boolean restart)
      Overrides:
      setVisible in class Drawable
    • getIntrinsicWidth

      public int getIntrinsicWidth()
      Overrides:
      getIntrinsicWidth in class Drawable
    • getIntrinsicHeight

      public int getIntrinsicHeight()
      Overrides:
      getIntrinsicHeight in class Drawable
    • isRunning

      public boolean isRunning()
      Specified by:
      isRunning in interface Animatable
    • onBoundsChange

      protected void onBoundsChange(Rect bounds)
      Overrides:
      onBoundsChange in class Drawable
    • draw

      public void draw(@NonNull Canvas canvas)
      Specified by:
      draw in class Drawable
    • setAlpha

      public void setAlpha(int i)
      Specified by:
      setAlpha in class Drawable
    • setColorFilter

      public void setColorFilter(ColorFilter colorFilter)
      Specified by:
      setColorFilter in class Drawable
    • getOpacity

      public int getOpacity()
      Specified by:
      getOpacity in class Drawable
    • onFrameReady

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

      public Drawable.ConstantState getConstantState()
      Overrides:
      getConstantState in class 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