-
- All Implemented Interfaces:
-
android.graphics.drawable.Animatable,androidx.vectordrawable.graphics.drawable.Animatable2Compat
public final class ApngDrawable extends Drawable implements Animatable2Compat
An animated Drawable that plays the frames of an animated PNG.
This drawable holds ApngState.apng which contains the width, height, image count, duration and repeat count from APNG meta data. These meta data can be obtained with decode function.
Also ApngState.apng has other responsibility to draw given frame to a canvas. ApngDrawable delegates ApngState.apng to draw a frame.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description public classApngDrawable.Companion
-
Field Summary
Fields Modifier and Type Field Description private final IntegerdurationMillisprivate final IntegerframeCountprivate final List<Integer>frameDurationsprivate final IntegerframeByteCountprivate final LongallocationByteCountprivate IntegerloopCountprivate final BooleanisRecycledprivate final IntegercurrentRepeatCountprivate final IntegercurrentLoopIndexprivate final IntegercurrentFrameIndex
-
Method Summary
Modifier and Type Method Description Unitdraw(Canvas canvas)UnitsetAlpha(Integer alpha)IntegergetOpacity()UnitsetColorFilter(ColorFilter colorFilter)IntegergetIntrinsicWidth()IntegergetIntrinsicHeight()BooleanisRunning()Unitstart()Unitstop()UnitregisterAnimationCallback(Animatable2Compat.AnimationCallback callback)Adds callback to listen animation start and end event of this apng image. BooleanunregisterAnimationCallback(Animatable2Compat.AnimationCallback callback)final UnitregisterRepeatAnimationCallback(RepeatAnimationCallback repeatCallback)final BooleanunregisterRepeatAnimationCallback(RepeatAnimationCallback repeatCallback)UnitclearAnimationCallbacks()Drawable.ConstantStategetConstantState()Drawablemutate()final UnitsetTargetDensity(DisplayMetrics metrics)Sets the density scale at which this drawable will be rendered. final UnitseekTo(Long positionMillis)Seeks frame to given position and show the image with target frame. final UnitseekToFrame(Integer loopIndex, Integer frameIndex)Seeks frame to given frame index with loop index. final Unitrecycle()Releases resources managed by the native layer. final IntegergetDurationMillis()The duration to animate one loop of APNG animation. final IntegergetFrameCount()The number of frames included in this APNG image. final List<Integer>getFrameDurations()A list of time to draw each frame in milliseconds. final IntegergetFrameByteCount()The number of bytes required for the non-native layer. final LonggetAllocationByteCount()The size of memory required for this image, including all frames loaded in the native layer. final IntegergetLoopCount()The number of times to loop this APNG image. final BooleangetIsRecycled()Whether this drawable has already been destroyed or not. final IntegergetCurrentRepeatCount()final IntegergetCurrentLoopIndex()final IntegergetCurrentFrameIndex()final UnitsetLoopCount(Integer loopCount)-
Methods inherited from class com.linecorp.apng.ApngDrawable
applyTheme, canApplyTheme, clearColorFilter, copyBounds, copyBounds, getAlpha, getBounds, getCallback, getChangingConfigurations, getColorFilter, getCurrent, getDirtyBounds, getHotspotBounds, getLayoutDirection, getLevel, getMinimumHeight, getMinimumWidth, getOpticalInsets, getOutline, getPadding, getState, getTransparentRegion, inflate, inflate, invalidateSelf, isAutoMirrored, isFilterBitmap, isProjected, isStateful, isVisible, jumpToCurrentState, onBoundsChange, onLayoutDirectionChanged, onLevelChange, onStateChange, scheduleSelf, setAutoMirrored, setBounds, setBounds, setCallback, setChangingConfigurations, setColorFilter, setDither, setFilterBitmap, setHotspot, setHotspotBounds, setLayoutDirection, setLevel, setState, setTint, setTintBlendMode, setTintList, setTintMode, setVisible, unscheduleSelf -
Methods inherited from class android.graphics.drawable.Drawable
equals, hashCode, toString -
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
-
Method Detail
-
getOpacity
Integer getOpacity()
-
setColorFilter
Unit setColorFilter(ColorFilter colorFilter)
-
getIntrinsicWidth
Integer getIntrinsicWidth()
-
getIntrinsicHeight
Integer getIntrinsicHeight()
-
registerAnimationCallback
Unit registerAnimationCallback(Animatable2Compat.AnimationCallback callback)
Adds callback to listen animation start and end event of this apng image. Animation end event will happen after exceeds loopCount.
Note: The animation end callback will be called only when animation stops beyond the loop count limit. In order to prevent potential memory leak, unregister the callback or clear all callbacks.
- Parameters:
callback- The Animatable2Compat.AnimationCallback to notify events.
-
unregisterAnimationCallback
Boolean unregisterAnimationCallback(Animatable2Compat.AnimationCallback callback)
-
registerRepeatAnimationCallback
final Unit registerRepeatAnimationCallback(RepeatAnimationCallback repeatCallback)
-
unregisterRepeatAnimationCallback
final Boolean unregisterRepeatAnimationCallback(RepeatAnimationCallback repeatCallback)
-
clearAnimationCallbacks
Unit clearAnimationCallbacks()
-
getConstantState
Drawable.ConstantState getConstantState()
-
setTargetDensity
final Unit setTargetDensity(DisplayMetrics metrics)
Sets the density scale at which this drawable will be rendered. If ApngState.sourceDensity is Bitmap.DENSITY_NONE, this value is ignored.
- Parameters:
metrics- The DisplayMetrics indicating the density scale for this drawable.
-
seekTo
final Unit seekTo(Long positionMillis)
Seeks frame to given position and show the image with target frame. If given position is larger than total duration of animation,
- Parameters:
positionMillis- Time to seek in milliseconds
-
seekToFrame
final Unit seekToFrame(Integer loopIndex, Integer frameIndex)
Seeks frame to given frame index with loop index.
- Parameters:
loopIndex- The target loop index to seek.frameIndex- The target frame index to seek.
-
recycle
final Unit recycle()
Releases resources managed by the native layer. Call this image when it is no longer used.
-
getDurationMillis
final Integer getDurationMillis()
The duration to animate one loop of APNG animation.
-
getFrameCount
final Integer getFrameCount()
The number of frames included in this APNG image.
-
getFrameDurations
final List<Integer> getFrameDurations()
A list of time to draw each frame in milliseconds.
-
getFrameByteCount
final Integer getFrameByteCount()
The number of bytes required for the non-native layer. In most cases, this is the number of bytes used to display one frame.
-
getAllocationByteCount
final Long getAllocationByteCount()
The size of memory required for this image, including all frames loaded in the native layer.
-
getLoopCount
final Integer getLoopCount()
The number of times to loop this APNG image. The value must be a signed value or special values.
The special values are:
LOOP_FOREVER indicates infinite looping.
LOOP_INTRINSIC indicated the default looping count.
-
getIsRecycled
final Boolean getIsRecycled()
Whether this drawable has already been destroyed or not.
-
getCurrentRepeatCount
final Integer getCurrentRepeatCount()
-
getCurrentLoopIndex
final Integer getCurrentLoopIndex()
-
getCurrentFrameIndex
final Integer getCurrentFrameIndex()
-
setLoopCount
final Unit setLoopCount(Integer loopCount)
-
-
-
-