Class GifDrawable
- java.lang.Object
-
- android.graphics.drawable.Drawable
-
- com.bumptech.glide.load.resource.gif.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.Animatable2CompatAn animatedDrawablethat plays the frames of an animated GIF.
-
-
Field Summary
Fields Modifier and Type Field Description static intLOOP_FOREVERA constant indicating that an animated drawable should loop continuously.static intLOOP_INTRINSICA 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 voidclearAnimationCallbacks()voiddraw(android.graphics.Canvas canvas)java.nio.ByteBuffergetBuffer()android.graphics.drawable.Drawable.ConstantStategetConstantState()android.graphics.BitmapgetFirstFrame()intgetFrameCount()intgetFrameIndex()Returns the current frame index in the range 0..getFrameCount()- 1, or -1 if no frame is displayed.Transformation<android.graphics.Bitmap>getFrameTransformation()intgetIntrinsicHeight()intgetIntrinsicWidth()intgetOpacity()intgetSize()booleanisRunning()protected voidonBoundsChange(android.graphics.Rect bounds)voidonFrameReady()voidrecycle()Clears any resources for loading frames that are currently held on to by this object.voidregisterAnimationCallback(androidx.vectordrawable.graphics.drawable.Animatable2Compat.AnimationCallback animationCallback)Register callback to listen to GifDrawable animation end event after specific loop count set bysetLoopCount(int).voidsetAlpha(int i)voidsetColorFilter(android.graphics.ColorFilter colorFilter)voidsetFrameTransformation(Transformation<android.graphics.Bitmap> frameTransformation, android.graphics.Bitmap firstFrame)voidsetLoopCount(int loopCount)booleansetVisible(boolean visible, boolean restart)voidstart()voidstartFromFirstFrame()Starts the animation from the first frame.voidstop()booleanunregisterAnimationCallback(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
-
-
-
-
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- AnTransformationthat can be applied to each frame.targetFrameWidth- The desired width of the frames displayed by this drawable (the width of the view orTargetthis drawable is being loaded into).targetFrameHeight- The desired height of the frames displayed by this drawable (the height of the view orTargetthis 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- AnTransformationthat can be applied to each frame.targetFrameWidth- The desired width of the frames displayed by this drawable (the width of the view orTargetthis drawable is being loaded into).targetFrameHeight- The desired height of the frames displayed by this drawable (the height of the view orTargetthis 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:
startin interfaceandroid.graphics.drawable.Animatable
-
stop
public void stop()
- Specified by:
stopin interfaceandroid.graphics.drawable.Animatable
-
setVisible
public boolean setVisible(boolean visible, boolean restart)- Overrides:
setVisiblein classandroid.graphics.drawable.Drawable
-
getIntrinsicWidth
public int getIntrinsicWidth()
- Overrides:
getIntrinsicWidthin classandroid.graphics.drawable.Drawable
-
getIntrinsicHeight
public int getIntrinsicHeight()
- Overrides:
getIntrinsicHeightin classandroid.graphics.drawable.Drawable
-
isRunning
public boolean isRunning()
- Specified by:
isRunningin interfaceandroid.graphics.drawable.Animatable
-
onBoundsChange
protected void onBoundsChange(android.graphics.Rect bounds)
- Overrides:
onBoundsChangein classandroid.graphics.drawable.Drawable
-
draw
public void draw(@NonNull android.graphics.Canvas canvas)- Specified by:
drawin classandroid.graphics.drawable.Drawable
-
setAlpha
public void setAlpha(int i)
- Specified by:
setAlphain classandroid.graphics.drawable.Drawable
-
setColorFilter
public void setColorFilter(android.graphics.ColorFilter colorFilter)
- Specified by:
setColorFilterin classandroid.graphics.drawable.Drawable
-
getOpacity
public int getOpacity()
- Specified by:
getOpacityin classandroid.graphics.drawable.Drawable
-
onFrameReady
public void onFrameReady()
- Specified by:
onFrameReadyin interfacecom.bumptech.glide.load.resource.gif.GifFrameLoader.FrameCallback
-
getConstantState
public android.graphics.drawable.Drawable.ConstantState getConstantState()
- Overrides:
getConstantStatein classandroid.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 bysetLoopCount(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:
registerAnimationCallbackin interfaceandroidx.vectordrawable.graphics.drawable.Animatable2Compat- Parameters:
animationCallback- Animation callbackAnimatable2Compat.AnimationCallback.
-
unregisterAnimationCallback
public boolean unregisterAnimationCallback(@NonNull androidx.vectordrawable.graphics.drawable.Animatable2Compat.AnimationCallback animationCallback)- Specified by:
unregisterAnimationCallbackin interfaceandroidx.vectordrawable.graphics.drawable.Animatable2Compat
-
clearAnimationCallbacks
public void clearAnimationCallbacks()
- Specified by:
clearAnimationCallbacksin interfaceandroidx.vectordrawable.graphics.drawable.Animatable2Compat
-
-