-
- All Implemented Interfaces:
-
android.graphics.drawable.Animatable,com.mobwith.imgmodule.load.resource.Animatable2Compat,com.mobwith.imgmodule.load.resource.gif.GifFrameLoader.FrameCallback
public class GifDrawable extends Drawable implements GifFrameLoader.FrameCallback, Animatable, Animatable2Compat
An animated Drawable that plays the frames of an animated GIF.
-
-
Field Summary
Fields Modifier and Type Field Description public final static intLOOP_FOREVERpublic final static intLOOP_INTRINSICprivate booleanisRunningprivate intloopCount
-
Constructor Summary
Constructors Constructor Description GifDrawable(Context context, GifDecoder gifDecoder, BitmapPool bitmapPool, Transformation<Bitmap> frameTransformation, int targetFrameWidth, int targetFrameHeight, Bitmap firstFrame)Constructor for GifDrawable. GifDrawable(Context context, GifDecoder gifDecoder, Transformation<Bitmap> frameTransformation, int targetFrameWidth, int targetFrameHeight, Bitmap firstFrame)Constructor for GifDrawable.
-
Method Summary
Modifier and Type Method Description booleanisRunning()voidsetIsRunning(boolean isRunning)voidsetLoopCount(int loopCount)intgetSize()BitmapgetFirstFrame()voidsetFrameTransformation(Transformation<Bitmap> frameTransformation, Bitmap firstFrame)Transformation<Bitmap>getFrameTransformation()ByteBuffergetBuffer()intgetFrameCount()intgetFrameIndex()Returns the current frame index in the range 0.. voidstartFromFirstFrame()Starts the animation from the first frame. voidstart()voidstop()booleansetVisible(boolean visible, boolean restart)intgetIntrinsicWidth()intgetIntrinsicHeight()voiddraw(@NonNull() Canvas canvas)voidsetAlpha(int i)voidsetColorFilter(ColorFilter colorFilter)intgetOpacity()voidonFrameReady()Drawable.ConstantStategetConstantState()voidrecycle()Clears any resources for loading frames that are currently held on to by this object. voidregisterAnimationCallback(@NonNull() Animatable2Compat.AnimationCallback animationCallback)Register callback to listen to GifDrawable animation end event after specific loop count set by setLoopCount. booleanunregisterAnimationCallback(@NonNull() Animatable2Compat.AnimationCallback animationCallback)Removes the specified animation callback. voidclearAnimationCallbacks()Removes all existing animation callbacks. -
Methods inherited from class android.graphics.drawable.Drawable
applyTheme, canApplyTheme, clearColorFilter, copyBounds, copyBounds, createFromPath, createFromResourceStream, createFromStream, createFromXml, createFromXmlInner, draw, getAlpha, getBounds, getCallback, getChangingConfigurations, getColorFilter, getConstantState, getCurrent, getDirtyBounds, getHotspotBounds, getIntrinsicHeight, getIntrinsicWidth, getLayoutDirection, getLevel, getMinimumHeight, getMinimumWidth, getOpacity, getOpticalInsets, getOutline, getPadding, getState, getTransparentRegion, hasFocusStateSpecified, inflate, invalidateSelf, isAutoMirrored, isFilterBitmap, isProjected, isStateful, isVisible, jumpToCurrentState, mutate, onLayoutDirectionChanged, resolveOpacity, scheduleSelf, setAlpha, setAutoMirrored, setBounds, setCallback, setChangingConfigurations, setColorFilter, setDither, setFilterBitmap, setHotspot, setHotspotBounds, setLayoutDirection, setLevel, setState, setTint, setTintBlendMode, setTintList, setTintMode, setVisible, unscheduleSelf -
Methods inherited from class android.graphics.drawable.Animatable
isRunning, start, stop -
Methods inherited from class com.mobwith.imgmodule.load.resource.Animatable2Compat
registerAnimationCallback, unregisterAnimationCallback -
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
-
Constructor Detail
-
GifDrawable
GifDrawable(Context context, GifDecoder gifDecoder, BitmapPool bitmapPool, Transformation<Bitmap> frameTransformation, int targetFrameWidth, int targetFrameHeight, Bitmap firstFrame)
Constructor for GifDrawable.- Parameters:
context- A context.gifDecoder- The decoder to use to decode GIF data.bitmapPool- Ignored, see deprecation note.frameTransformation- An com.mobwith.imgmodule.load.Transformation that can beapplied to each frame.targetFrameWidth- The desired width of the frames displayed by this drawable (the widthof the view or com.mobwith.imgmodule.request.target.Target this drawable is beingloaded into).targetFrameHeight- The desired height of the frames displayed by this drawable (theheight of the view or com.mobwith.imgmodule.request.target.Target this drawable isbeing loaded into).firstFrame- The decoded and transformed first frame of this GIF.
-
GifDrawable
GifDrawable(Context context, GifDecoder gifDecoder, Transformation<Bitmap> frameTransformation, int targetFrameWidth, int targetFrameHeight, Bitmap firstFrame)
Constructor for GifDrawable.- Parameters:
context- A context.gifDecoder- The decoder to use to decode GIF data.frameTransformation- An com.mobwith.imgmodule.load.Transformation that can beapplied to each frame.targetFrameWidth- The desired width of the frames displayed by this drawable (the widthof the view or com.mobwith.imgmodule.request.target.Target this drawable is beingloaded into).targetFrameHeight- The desired height of the frames displayed by this drawable (theheight of the view or com.mobwith.imgmodule.request.target.Target this drawable isbeing loaded into).firstFrame- The decoded and transformed first frame of this GIF.
-
-
Method Detail
-
isRunning
boolean isRunning()
-
setIsRunning
void setIsRunning(boolean isRunning)
-
setLoopCount
void setLoopCount(int loopCount)
-
getSize
int getSize()
-
getFirstFrame
Bitmap getFirstFrame()
-
setFrameTransformation
void setFrameTransformation(Transformation<Bitmap> frameTransformation, Bitmap firstFrame)
-
getFrameTransformation
Transformation<Bitmap> getFrameTransformation()
-
getBuffer
ByteBuffer getBuffer()
-
getFrameCount
int getFrameCount()
-
getFrameIndex
int getFrameIndex()
Returns the current frame index in the range 0..getFrameCount - 1, or -1 if no frameis displayed.
-
startFromFirstFrame
void startFromFirstFrame()
Starts the animation from the first frame. Can only be called while animation is not running.
-
start
void start()
-
stop
void stop()
-
setVisible
boolean setVisible(boolean visible, boolean restart)
-
getIntrinsicWidth
int getIntrinsicWidth()
-
getIntrinsicHeight
int getIntrinsicHeight()
-
setAlpha
void setAlpha(int i)
-
setColorFilter
void setColorFilter(ColorFilter colorFilter)
-
getOpacity
int getOpacity()
-
onFrameReady
void onFrameReady()
-
getConstantState
Drawable.ConstantState getConstantState()
-
recycle
void recycle()
Clears any resources for loading frames that are currently held on to by this object.
-
registerAnimationCallback
void registerAnimationCallback(@NonNull() Animatable2Compat.AnimationCallback animationCallback)
Register callback to listen to GifDrawable animation end event after specific loop count set by setLoopCount.
Note: This will only be called if the Gif stop because it reaches the loop count. Unregisterthis in onLoadCleared to avoid potential memory leak.
- Parameters:
animationCallback- Animation callback Animatable2Compat.AnimationCallback.
-
unregisterAnimationCallback
boolean unregisterAnimationCallback(@NonNull() Animatable2Compat.AnimationCallback animationCallback)
Removes the specified animation callback.
-
clearAnimationCallbacks
void clearAnimationCallbacks()
Removes all existing animation callbacks.
-
-
-
-