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
Drawable that plays the frames of an animated GIF.| Modifier and Type | Field and 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 and Description |
|---|
GifDrawable(android.content.Context context,
GifDecoder gifDecoder,
BitmapPool bitmapPool,
Transformation<android.graphics.Bitmap> frameTransformation,
int targetFrameWidth,
int targetFrameHeight,
android.graphics.Bitmap firstFrame)
|
GifDrawable(android.content.Context context,
GifDecoder gifDecoder,
Transformation<android.graphics.Bitmap> frameTransformation,
int targetFrameWidth,
int targetFrameHeight,
android.graphics.Bitmap firstFrame)
Constructor for GifDrawable.
|
| Modifier and Type | Method and 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) |
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, getOutline, getPadding, getState, getTransparentRegion, inflate, inflate, invalidateSelf, isAutoMirrored, isFilterBitmap, isStateful, isVisible, jumpToCurrentState, mutate, onLayoutDirectionChanged, onLevelChange, onStateChange, resolveOpacity, scheduleSelf, setAutoMirrored, setBounds, setBounds, setCallback, setChangingConfigurations, setColorFilter, setDither, setFilterBitmap, setHotspot, setHotspotBounds, setLayoutDirection, setLevel, setState, setTint, setTintList, setTintMode, unscheduleSelfpublic static final int LOOP_FOREVER
public static final int LOOP_INTRINSIC
@Deprecated
public GifDrawable(android.content.Context context,
GifDecoder gifDecoder,
BitmapPool bitmapPool,
Transformation<android.graphics.Bitmap> frameTransformation,
int targetFrameWidth,
int targetFrameHeight,
android.graphics.Bitmap firstFrame)
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.setFrameTransformation(com.bumptech.glide.load.Transformation, android.graphics.Bitmap)public GifDrawable(android.content.Context context,
GifDecoder gifDecoder,
Transformation<android.graphics.Bitmap> frameTransformation,
int targetFrameWidth,
int targetFrameHeight,
android.graphics.Bitmap firstFrame)
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.setFrameTransformation(com.bumptech.glide.load.Transformation, android.graphics.Bitmap)public int getSize()
public android.graphics.Bitmap getFirstFrame()
public void setFrameTransformation(Transformation<android.graphics.Bitmap> frameTransformation, android.graphics.Bitmap firstFrame)
public Transformation<android.graphics.Bitmap> getFrameTransformation()
public java.nio.ByteBuffer getBuffer()
public int getFrameCount()
public int getFrameIndex()
getFrameCount() - 1, or -1 if no frame
is displayed.public void startFromFirstFrame()
public void start()
start in interface android.graphics.drawable.Animatablepublic void stop()
stop in interface android.graphics.drawable.Animatablepublic boolean setVisible(boolean visible,
boolean restart)
setVisible in class android.graphics.drawable.Drawablepublic int getIntrinsicWidth()
getIntrinsicWidth in class android.graphics.drawable.Drawablepublic int getIntrinsicHeight()
getIntrinsicHeight in class android.graphics.drawable.Drawablepublic boolean isRunning()
isRunning in interface android.graphics.drawable.Animatableprotected void onBoundsChange(android.graphics.Rect bounds)
onBoundsChange in class android.graphics.drawable.Drawablepublic void draw(@NonNull
android.graphics.Canvas canvas)
draw in class android.graphics.drawable.Drawablepublic void setAlpha(int i)
setAlpha in class android.graphics.drawable.Drawablepublic void setColorFilter(android.graphics.ColorFilter colorFilter)
setColorFilter in class android.graphics.drawable.Drawablepublic int getOpacity()
getOpacity in class android.graphics.drawable.Drawablepublic void onFrameReady()
onFrameReady in interface com.bumptech.glide.load.resource.gif.GifFrameLoader.FrameCallbackpublic android.graphics.drawable.Drawable.ConstantState getConstantState()
getConstantState in class android.graphics.drawable.Drawablepublic void recycle()
public void setLoopCount(int loopCount)
public void registerAnimationCallback(@NonNull
androidx.vectordrawable.graphics.drawable.Animatable2Compat.AnimationCallback animationCallback)
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.
registerAnimationCallback in interface androidx.vectordrawable.graphics.drawable.Animatable2CompatanimationCallback - Animation callback Animatable2Compat.AnimationCallback.Animatable2Compat.unregisterAnimationCallback(AnimationCallback).public boolean unregisterAnimationCallback(@NonNull
androidx.vectordrawable.graphics.drawable.Animatable2Compat.AnimationCallback animationCallback)
unregisterAnimationCallback in interface androidx.vectordrawable.graphics.drawable.Animatable2Compatpublic void clearAnimationCallbacks()
clearAnimationCallbacks in interface androidx.vectordrawable.graphics.drawable.Animatable2Compat