SeekableAnimatedVectorDrawable


class SeekableAnimatedVectorDrawable : Drawable, Animatable


This class animates properties of a VectorDrawableCompat with animations defined using ObjectAnimator or AnimatorSet.

SeekableAnimatedVectorDrawable is defined in the same XML format as android.graphics.drawable.AnimatedVectorDrawable.

Here are all the animatable attributes in VectorDrawableCompat:

Element Name Animatable attribute name
alpha
rotation
pivotX
pivotY
scaleX
scaleY
translateX
translateY
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 android.graphics.drawable.AnimatedVectorDrawable on any API levels.

Summary

Nested types

Abstract class for animation callback.

Public functions

Unit
Boolean
Unit

Removes all existing animation callbacks.

java-static SeekableAnimatedVectorDrawable?
create(context: Context, resId: @DrawableRes Int)

Create a SeekableAnimatedVectorDrawable object.

java-static SeekableAnimatedVectorDrawable
createFromXmlInner(
    r: Resources,
    parser: XmlPullParser,
    attrs: AttributeSet,
    theme: Resources.Theme?
)

Create a SeekableAnimatedVectorDrawable from inside an XML document using an optional Theme.

Unit
draw(canvas: Canvas)
@IntRange(from = 0, to = 255) Int
Int
ColorFilter?
Drawable.ConstantState?
@IntRange(from = 0) Long

Returns the milliseconds elapsed since the start of the animation.

Int
Int
Int

This function is deprecated.

This method is no longer used in graphics optimizations

Long

Gets the total duration of the animation, accounting for animation sequences, start delay, and repeating.

Unit
inflate(res: Resources, parser: XmlPullParser, attrs: AttributeSet)
Unit
inflate(
    res: Resources,
    parser: XmlPullParser,
    attrs: AttributeSet,
    theme: Resources.Theme?
)
Boolean
Boolean

Returns whether the animation is currently in a paused state.

Boolean

Returns whether the animation is running (has started and not yet ended).

Boolean
Drawable

mutate() is not supported.

Unit

Pauses a running animation.

Unit

Adds a callback to listen to the animation events.

Unit

Resumes a paused animation.

Unit
setAlpha(alpha: @IntRange(from = 0, to = 255) Int)
Unit
Unit
setColorFilter(colorFilter: ColorFilter?)
Unit
setCurrentPlayTime(playTime: @IntRange(from = 0) Long)

Sets the position of the animation to the specified point in time.

Unit
Unit
Unit
Boolean
setVisible(visible: Boolean, restart: Boolean)
Unit
Unit
Boolean

Removes the specified animation callback.

Protected functions

Unit
Boolean
Boolean

Inherited functions

From android.graphics.drawable.Drawable
Unit
Rect!
Unit
copyBounds(bounds: Rect!)
java-static Drawable!
createFromPath(pathName: String!)
java-static Drawable!
createFromResourceStream(
    res: Resources!,
    value: TypedValue!,
    is: InputStream!,
    srcName: String!
)
java-static Drawable!
createFromStream(is: InputStream!, srcName: String!)
java-static Drawable!
java-static Drawable!
createFromXmlInner(
    r: Resources!,
    parser: XmlPullParser!,
    attrs: AttributeSet!
)
Rect!
Drawable.Callback!
Drawable!
Rect!
Unit
Int
Int
Int
Int
Insets!
Unit
getOutline(outline: Outline!)
Boolean
getPadding(padding: Rect!)
IntArray<Int>!
Region!
Boolean
Unit
Boolean
Boolean
Boolean
Unit
Boolean
onLayoutDirectionChanged(layoutDirection: Int)
java-static Int
resolveOpacity(op1: Int, op2: Int)
Unit
scheduleSelf(what: Runnable!, when: Long)
Unit
setBounds(left: Int, top: Int, right: Int, bottom: Int)
Unit
Unit
Unit
setDither(dither: Boolean)

This function is deprecated.

Unit
Unit
Unit
setHotspotBounds(left: Int, top: Int, right: Int, bottom: Int)
Boolean
setLayoutDirection(layoutDirection: Int)
Boolean
setLevel(level: Int)
Boolean
setState(stateSet: IntArray!)
Unit
Unit

Public functions

applyTheme

fun applyTheme(t: Resources.Theme): Unit

canApplyTheme

fun canApplyTheme(): Boolean

clearAnimationCallbacks

Added in 1.0.0
fun clearAnimationCallbacks(): Unit

Removes all existing animation callbacks.

create

Added in 1.0.0
java-static fun create(context: Context, resId: @DrawableRes Int): SeekableAnimatedVectorDrawable?

Create a SeekableAnimatedVectorDrawable object.

Parameters
context: Context

the context for creating the animators.

resId: @DrawableRes Int

the resource ID for SeekableAnimatedVectorDrawable object.

Returns
SeekableAnimatedVectorDrawable?

a new SeekableAnimatedVectorDrawable or null if parsing error is found.

createFromXmlInner

Added in 1.0.0
java-static fun createFromXmlInner(
    r: Resources,
    parser: XmlPullParser,
    attrs: AttributeSet,
    theme: Resources.Theme?
): SeekableAnimatedVectorDrawable

Create a SeekableAnimatedVectorDrawable from inside an XML document using an optional 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.

draw

Added in 1.0.0
fun draw(canvas: Canvas): Unit

getAlpha

fun getAlpha(): @IntRange(from = 0, to = 255) Int

getChangingConfigurations

fun getChangingConfigurations(): Int

getColorFilter

fun getColorFilter(): ColorFilter?

getConstantState

fun getConstantState(): Drawable.ConstantState?

getCurrentPlayTime

Added in 1.0.0
fun getCurrentPlayTime(): @IntRange(from = 0) Long

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, the seeked play time will be returned; otherwise, this method will return 0.

Returns
@IntRange(from = 0) Long

the current position in time of the animation in milliseconds

getIntrinsicHeight

fun getIntrinsicHeight(): Int

getIntrinsicWidth

fun getIntrinsicWidth(): Int

getOpacity

Added in 1.0.0
Deprecated in 1.0.0
fun getOpacity(): Int
Returns
Int

The opacity class of the Drawable.

getTotalDuration

Added in 1.0.0
fun getTotalDuration(): Long

Gets the total duration of the animation, accounting for animation sequences, start delay, and repeating. Return DURATION_INFINITE if the duration is infinite.

Returns
Long

Total time the animation takes to finish, starting from the time start is called. DURATION_INFINITE if the animation or any of the child animations repeats infinite times.

inflate

fun inflate(
    res: Resources,
    parser: XmlPullParser,
    attrs: AttributeSet,
    theme: Resources.Theme?
): Unit

isAutoMirrored

fun isAutoMirrored(): Boolean

isPaused

Added in 1.0.0
fun isPaused(): Boolean

Returns whether the animation is currently in a paused state.

Returns
Boolean

true if the animation is paused.

isRunning

Added in 1.0.0
fun isRunning(): Boolean

Returns whether the animation is running (has started and not yet ended).

Returns
Boolean

true if the animation is running.

isStateful

fun isStateful(): Boolean

mutate

fun mutate(): Drawable

mutate() is not supported. This method simply returns this.

pause

Added in 1.0.0
fun pause(): Unit

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

Added in 1.0.0
fun registerAnimationCallback(
    callback: SeekableAnimatedVectorDrawable.AnimationCallback
): Unit

Adds a callback to listen to the animation events.

Parameters
callback: SeekableAnimatedVectorDrawable.AnimationCallback

Callback to add.

resume

Added in 1.0.0
fun resume(): Unit

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

Added in 1.0.0
fun setAlpha(alpha: @IntRange(from = 0, to = 255) Int): Unit

setAutoMirrored

fun setAutoMirrored(mirrored: Boolean): Unit

setColorFilter

Added in 1.0.0
fun setColorFilter(colorFilter: ColorFilter?): Unit

setCurrentPlayTime

Added in 1.0.0
fun setCurrentPlayTime(playTime: @IntRange(from = 0) Long): Unit

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: @IntRange(from = 0) 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

fun setTint(tint: @ColorInt Int): Unit

setTintList

fun setTintList(tint: ColorStateList?): Unit

setTintMode

fun setTintMode(tintMode: PorterDuff.Mode?): Unit

setVisible

fun setVisible(visible: Boolean, restart: Boolean): Boolean

start

Added in 1.0.0
fun start(): Unit

stop

Added in 1.0.0
fun stop(): Unit

unregisterAnimationCallback

Added in 1.0.0
fun unregisterAnimationCallback(
    callback: SeekableAnimatedVectorDrawable.AnimationCallback
): Boolean

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 functions

onBoundsChange

protected fun onBoundsChange(bounds: Rect): Unit

onLevelChange

protected fun onLevelChange(level: Int): Boolean

onStateChange

protected fun onStateChange(state: IntArray): Boolean