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.-
Nested Class Summary
Nested classes/interfaces inherited from class android.graphics.drawable.Drawable
Drawable.Callback, Drawable.ConstantStateNested classes/interfaces inherited from interface androidx.vectordrawable.graphics.drawable.Animatable2Compat
androidx.vectordrawable.graphics.drawable.Animatable2Compat.AnimationCallback -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intA constant indicating that an animated drawable should loop continuously.static final intA constant indicating that an animated drawable should loop for its default number of times. -
Constructor Summary
ConstructorsConstructorDescriptionGifDrawable(Context context, com.bumptech.glide.gifdecoder.GifDecoder gifDecoder, BitmapPool bitmapPool, Transformation<Bitmap> frameTransformation, int targetFrameWidth, int targetFrameHeight, Bitmap firstFrame) Deprecated.GifDrawable(Context context, com.bumptech.glide.gifdecoder.GifDecoder gifDecoder, Transformation<Bitmap> frameTransformation, int targetFrameWidth, int targetFrameHeight, Bitmap firstFrame) Constructor for GifDrawable. -
Method Summary
Modifier and TypeMethodDescriptionvoidvoidintintReturns the current frame index in the range 0..getFrameCount()- 1, or -1 if no frame is displayed.intintintintgetSize()booleanprotected voidonBoundsChange(Rect bounds) voidvoidrecycle()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(ColorFilter colorFilter) voidsetFrameTransformation(Transformation<Bitmap> frameTransformation, Bitmap firstFrame) voidsetLoopCount(int loopCount) booleansetVisible(boolean visible, boolean restart) voidstart()voidStarts 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 Details
-
LOOP_FOREVER
public static final int LOOP_FOREVERA constant indicating that an animated drawable should loop continuously.- See Also:
-
LOOP_INTRINSIC
public static final int LOOP_INTRINSICA 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- 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:
-
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- 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:
-
-
Method Details
-
getSize
public int getSize() -
getFirstFrame
-
setFrameTransformation
-
getFrameTransformation
-
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 interfaceAnimatable
-
stop
public void stop()- Specified by:
stopin interfaceAnimatable
-
setVisible
public boolean setVisible(boolean visible, boolean restart) - Overrides:
setVisiblein classDrawable
-
getIntrinsicWidth
public int getIntrinsicWidth()- Overrides:
getIntrinsicWidthin classDrawable
-
getIntrinsicHeight
public int getIntrinsicHeight()- Overrides:
getIntrinsicHeightin classDrawable
-
isRunning
public boolean isRunning()- Specified by:
isRunningin interfaceAnimatable
-
onBoundsChange
- Overrides:
onBoundsChangein classDrawable
-
draw
-
setAlpha
public void setAlpha(int i) -
setColorFilter
- Specified by:
setColorFilterin classDrawable
-
getOpacity
public int getOpacity()- Specified by:
getOpacityin classDrawable
-
onFrameReady
public void onFrameReady()- Specified by:
onFrameReadyin interfacecom.bumptech.glide.load.resource.gif.GifFrameLoader.FrameCallback
-
getConstantState
- Overrides:
getConstantStatein classDrawable
-
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
-
GifDrawable(Context, GifDecoder, Transformation, int, int, Bitmap)