SeekableAnimatedVectorDrawable
public
class
SeekableAnimatedVectorDrawable
extends Drawable
implements
Animatable
java.lang.Object | ||
↳ | android.graphics.drawable.Drawable | |
↳ | androidx.vectordrawable.graphics.drawable.SeekableAnimatedVectorDrawable |
This class animates properties of a VectorDrawableCompat
with animations defined using
ObjectAnimator
or AnimatorSet
.
SeekableAnimatedVectorDrawable is defined in the same XML format as
AnimatedVectorDrawable
.
Here are all the animatable attributes in VectorDrawableCompat
:
Element Name | Animatable attribute name |
---|---|
<vector> | alpha |
<group> | rotation |
pivotX | |
pivotY | |
scaleX | |
scaleY | |
translateX | |
translateY | |
<path> | fillColor |
pathData | |
strokeColor | |
strokeWidth | |
strokeAlpha | |
fillAlpha | |
trimPathStart | |
trimPathEnd | |
trimPathOffset |
You can always create a SeekableAnimatedVectorDrawable object and use it as a Drawable by the Java API. In order to refer to SeekableAnimatedVectorDrawable inside an XML file, you can use app:srcCompat attribute in AppCompat library's ImageButton or ImageView.
SeekableAnimatedVectorDrawable supports the following features too:
- Path Morphing (PathType evaluator). This is used for morphing one path into another.
- Path Interpolation. This is used to defined a flexible interpolator (represented as a path) instead of the system defined ones like LinearInterpolator.
- Animating 2 values in one ObjectAnimator according to one path's X value and Y value. One usage is moving one object in both X and Y dimensions along an path.
Unlike AnimatedVectorDrawableCompat
, this class does not delegate to the platform
AnimatedVectorDrawable
on any API levels.
Summary
Nested classes | |
---|---|
class |
SeekableAnimatedVectorDrawable.AnimationCallback
Abstract class for animation callback. |
Public methods | |
---|---|
void
|
applyTheme(Resources.Theme t)
|
boolean
|
canApplyTheme()
|
void
|
clearAnimationCallbacks()
Removes all existing animation callbacks. |
static
SeekableAnimatedVectorDrawable
|
create(Context context, int resId)
Create a SeekableAnimatedVectorDrawable object. |
static
SeekableAnimatedVectorDrawable
|
createFromXmlInner(Resources r, XmlPullParser parser, AttributeSet attrs, Resources.Theme theme)
Create a SeekableAnimatedVectorDrawable from inside an XML document using an optional
|
void
|
draw(Canvas canvas)
|
int
|
getAlpha()
|
int
|
getChangingConfigurations()
|
ColorFilter
|
getColorFilter()
|
Drawable.ConstantState
|
getConstantState()
|
long
|
getCurrentPlayTime()
Returns the milliseconds elapsed since the start of the animation. |
int
|
getIntrinsicHeight()
|
int
|
getIntrinsicWidth()
|
int
|
getOpacity()
This method is deprecated. This method is no longer used in graphics optimizations |
long
|
getTotalDuration()
Gets the total duration of the animation, accounting for animation sequences, start delay, and repeating. |
void
|
inflate(Resources res, XmlPullParser parser, AttributeSet attrs, Resources.Theme theme)
|
void
|
inflate(Resources res, XmlPullParser parser, AttributeSet attrs)
|
boolean
|
isAutoMirrored()
|
boolean
|
isPaused()
Returns whether the animation is currently in a paused state. |
boolean
|
isRunning()
Returns whether the animation is running (has started and not yet ended). |
boolean
|
isStateful()
|
Drawable
|
mutate()
mutate() is not supported. |
void
|
pause()
Pauses a running animation. |
void
|
registerAnimationCallback(SeekableAnimatedVectorDrawable.AnimationCallback callback)
Adds a callback to listen to the animation events. |
void
|
resume()
Resumes a paused animation. |
void
|
setAlpha(int alpha)
|
void
|
setAutoMirrored(boolean mirrored)
|
void
|
setColorFilter(ColorFilter colorFilter)
|
void
|
setCurrentPlayTime(long playTime)
Sets the position of the animation to the specified point in time. |
void
|
setTint(int tint)
|
void
|
setTintList(ColorStateList tint)
|
void
|
setTintMode(PorterDuff.Mode tintMode)
|
boolean
|
setVisible(boolean visible, boolean restart)
|
void
|
start()
|
void
|
stop()
|
boolean
|
unregisterAnimationCallback(SeekableAnimatedVectorDrawable.AnimationCallback callback)
Removes the specified animation callback. |
Protected methods | |
---|---|
void
|
onBoundsChange(Rect bounds)
|
boolean
|
onLevelChange(int level)
|
boolean
|
onStateChange(int[] state)
|
Inherited methods | |
---|---|
Public methods
canApplyTheme
public boolean canApplyTheme ()
Returns | |
---|---|
boolean |
clearAnimationCallbacks
public void clearAnimationCallbacks ()
Removes all existing animation callbacks.
create
public static SeekableAnimatedVectorDrawable create (Context context, int resId)
Create a SeekableAnimatedVectorDrawable object.
Parameters | |
---|---|
context |
Context : the context for creating the animators. |
resId |
int : the resource ID for SeekableAnimatedVectorDrawable object. |
Returns | |
---|---|
SeekableAnimatedVectorDrawable |
a new SeekableAnimatedVectorDrawable or null if parsing error is found. |
createFromXmlInner
public static SeekableAnimatedVectorDrawable createFromXmlInner (Resources r, XmlPullParser parser, AttributeSet attrs, Resources.Theme theme)
Create a SeekableAnimatedVectorDrawable from inside an XML document using an optional
Resources.Theme
. Called on a parser positioned at a tag in an XML
document, tries to create a Drawable from that tag. Returns null
if the tag is not a valid drawable.
Parameters | |
---|---|
r |
Resources |
parser |
XmlPullParser |
attrs |
AttributeSet |
theme |
Resources.Theme |
Returns | |
---|---|
SeekableAnimatedVectorDrawable |
Throws | |
---|---|
XmlPullParserException |
|
IOException |
getAlpha
public int getAlpha ()
Returns | |
---|---|
int |
Value is 255 or less. |
getChangingConfigurations
public int getChangingConfigurations ()
Returns | |
---|---|
int |
getCurrentPlayTime
public long getCurrentPlayTime ()
Returns the milliseconds elapsed since the start of the animation.
For ongoing animations, this method returns the current progress of the animation in
terms of play time. For an animation that has not yet been started: if the animation has been
seeked to a certain time via setCurrentPlayTime(long)
, the seeked play time will
be returned; otherwise, this method will return 0.
Returns | |
---|---|
long |
the current position in time of the animation in milliseconds |
getIntrinsicHeight
public int getIntrinsicHeight ()
Returns | |
---|---|
int |
getIntrinsicWidth
public int getIntrinsicWidth ()
Returns | |
---|---|
int |
getOpacity
public int getOpacity ()
This method is deprecated.
This method is no longer used in graphics optimizations
Returns | |
---|---|
int |
The opacity class of the Drawable. |
getTotalDuration
public long getTotalDuration ()
Gets the total duration of the animation, accounting for animation sequences, start delay,
and repeating. Return Animator.DURATION_INFINITE
if the duration is infinite.
Returns | |
---|---|
long |
Total time the animation takes to finish, starting from the time start()
is called. Animator.DURATION_INFINITE if the animation or any of the child
animations repeats infinite times.
|
inflate
public void inflate (Resources res, XmlPullParser parser, AttributeSet attrs, Resources.Theme theme)
Parameters | |
---|---|
res |
Resources |
parser |
XmlPullParser |
attrs |
AttributeSet |
theme |
Resources.Theme |
Throws | |
---|---|
XmlPullParserException |
|
IOException |
inflate
public void inflate (Resources res, XmlPullParser parser, AttributeSet attrs)
Parameters | |
---|---|
res |
Resources |
parser |
XmlPullParser |
attrs |
AttributeSet |
Throws | |
---|---|
XmlPullParserException |
|
IOException |
isAutoMirrored
public boolean isAutoMirrored ()
Returns | |
---|---|
boolean |
isPaused
public boolean isPaused ()
Returns whether the animation is currently in a paused state.
Returns | |
---|---|
boolean |
true if the animation is paused.
|
isRunning
public boolean isRunning ()
Returns whether the animation is running (has started and not yet ended).
Returns | |
---|---|
boolean |
true if the animation is running.
|
isStateful
public boolean isStateful ()
Returns | |
---|---|
boolean |
mutate
public Drawable mutate ()
mutate() is not supported. This method simply returns this
.
Returns | |
---|---|
Drawable |
pause
public void pause ()
Pauses a running animation. This method should only be called on the same thread on which
the animation was started. If the animation has not yet been started or has since ended,
then the call is ignored. Paused animations can be resumed by calling resume()
.
registerAnimationCallback
public void registerAnimationCallback (SeekableAnimatedVectorDrawable.AnimationCallback callback)
Adds a callback to listen to the animation events.
Parameters | |
---|---|
callback |
SeekableAnimatedVectorDrawable.AnimationCallback : Callback to add.
|
resume
public void resume ()
Resumes a paused animation. The animation resumes from where it left off when it was
paused. This method should only be called on the same thread on which the animation was
started. Calls will be ignored if this SeekableAnimatedVectorDrawable
is not
currently paused.
setAlpha
public void setAlpha (int alpha)
Parameters | |
---|---|
alpha |
int Value is 255 or less. |
setAutoMirrored
public void setAutoMirrored (boolean mirrored)
Parameters | |
---|---|
mirrored |
boolean |
setColorFilter
public void setColorFilter (ColorFilter colorFilter)
Parameters | |
---|---|
colorFilter |
ColorFilter |
setCurrentPlayTime
public void setCurrentPlayTime (long playTime)
Sets the position of the animation to the specified point in time. This time should be between 0 and the total duration of the animation, including any repetition. If the animation has not yet been started, then it will not advance forward after it is set to this time; it will simply set the time to this value and perform any appropriate actions based on that time. If the animation is already running, then setCurrentPlayTime() will set the current playing time to this value and continue playing from that point.
Parameters | |
---|---|
playTime |
long : The time, in milliseconds, to which the animation is advanced or rewound.
Unless the animation is reversing, the playtime is considered the time since
the end of the start delay of the AnimatorSet in a forward playing direction.
|
setTint
public void setTint (int tint)
Parameters | |
---|---|
tint |
int |
setVisible
public boolean setVisible (boolean visible, boolean restart)
Parameters | |
---|---|
visible |
boolean |
restart |
boolean |
Returns | |
---|---|
boolean |
start
public void start ()
stop
public void stop ()
unregisterAnimationCallback
public boolean unregisterAnimationCallback (SeekableAnimatedVectorDrawable.AnimationCallback callback)
Removes the specified animation callback.
Parameters | |
---|---|
callback |
SeekableAnimatedVectorDrawable.AnimationCallback : Callback to remove. |
Returns | |
---|---|
boolean |
false if callback didn't exist in the call back list, or true if
callback has been removed successfully.
|
Protected methods
onLevelChange
protected boolean onLevelChange (int level)
Parameters | |
---|---|
level |
int |
Returns | |
---|---|
boolean |
onStateChange
protected boolean onStateChange (int[] state)
Parameters | |
---|---|
state |
int |
Returns | |
---|---|
boolean |
Content and code samples on this page are subject to the licenses described in the Content License. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2020-09-30 UTC.