kyrie / com.github.alexjlockwood.kyrie / Animation

Animation

class Animation<T, V>

An Animation encapsulates the information required to animate a single property of a Node.

Parameters

T - The animation's original value type.

V - The animation's transformed value type.

Types

BidirectionalValueTransformer

interface BidirectionalValueTransformer<T, V> : Animation.ValueTransformer<T, V>

Interface that can transform type T to another type V and back again. This is necessary when the value types of an animation are different from the property type. This interface is only needed when working with an Animation with no explicitly set start value and that has been transformed using transform.

RepeatMode

enum class RepeatMode

Repeat mode determines how a repeating animation should behave once it completes.

ValueTransformer

interface ValueTransformer<T, V>

Interface that can transform type T to another type V. This is necessary when the original value type of an animation is different than the desired value type.

Properties

duration

var duration: Long

Gets the duration of the animation.

interpolator

var interpolator: TimeInterpolator?

Returns the timing interpolator that this animation uses. If null, a LinearInterpolator will be used by default.

repeatCount

var repeatCount: Long

Defines how many times the animation should repeat. The default value is 0.

repeatMode

var repeatMode: Animation.RepeatMode

Defines what this animation should do when it reaches the end.

startDelay

var startDelay: Long

Gets the start delay of the animation.

totalDuration

val totalDuration: Long

Gets the total duration of the animation in milliseconds, accounting for start delay and repeat count. Returns INFINITE if the repeat count is infinite.

Functions

duration

fun duration(duration: Long): Animation<T, V>

Sets the duration of the animation.

getAnimatedValue

fun getAnimatedValue(fraction: Float): V

Returns the animated value of this animation at the given fraction.

interpolator

fun interpolator(interpolator: TimeInterpolator?): Animation<T, V>

Sets the timing interpolator that this animation uses. If null, a LinearInterpolator will be used by default.

repeatCount

fun repeatCount(repeatCount: Long): Animation<T, V>

Sets how many times the animation should be repeated. If the repeat count is 0, the animation is never repeated. If the repeat count is greater than 0 or INFINITE, the repeat mode will be taken into account. The repeat count is 0 by default.

repeatMode

fun repeatMode(repeatMode: Animation.RepeatMode): Animation<T, V>

Defines what this animation should do when it reaches the end. This setting is applied only when the repeat count is either greater than 0 or INFINITE. Defaults to RepeatMode.RESTART.

startDelay

fun startDelay(startDelay: Long): Animation<T, V>

Sets the start delay of the animation.

transform

fun <W> transform(transformer: Animation.ValueTransformer<T, W>): Animation<T, W>
fun <W> transform(transformer: (value: T) -> W): Animation<T, W>

Creates a new animation with original value type T and a new transformed value type W.

Companion Object Properties

INFINITE

const val INFINITE: Long

This value used used with the repeatCount property to repeat the animation indefinitely. Also used to indicate infinite duration.

Companion Object Functions

ofArgb

fun ofArgb(vararg values: Int): Animation<Int, Int>

Constructs and returns an Animation that animates between color values. A single value implies that the value is the one being animated to, in which case the start value will be derived from the property being animated and the target object when the animation is started. Two values imply starting and ending values. More than two values imply a starting value, values to animate through along the way, and an ending value (these values will be distributed evenly across the duration of the animation).

fun ofArgb(vararg values: Keyframe<Int>): Animation<Int, Int>

Same as ofArgb except with Keyframes instead of color values.

ofFloat

fun ofFloat(vararg values: Float): Animation<Float, Float>

Constructs and returns an Animation that animates between float values. A single value implies that the value is the one being animated to, in which case the start value will be derived from the property being animated and the target object when the animation is started. Two values imply starting and ending values. More than two values imply a starting value, values to animate through along the way, and an ending value (these values will be distributed evenly across the duration of the animation).

fun ofFloat(vararg values: Keyframe<Float>): Animation<Float, Float>

Same as ofFloat except with Keyframes instead of float values.

ofFloatArray

fun ofFloatArray(vararg values: FloatArray): Animation<FloatArray, FloatArray>

Constructs and returns an Animation that animates between float[] values. A single value implies that the value is the one being animated to, in which case the start value will be derived from the property being animated and the target object when the animation is started. Two values imply starting and ending values. More than two values imply a starting value, values to animate through along the way, and an ending value (these values will be distributed evenly across the duration of the animation).

fun ofFloatArray(vararg values: Keyframe<FloatArray>): Animation<FloatArray, FloatArray>

Same as ofFloatArray except with Keyframes instead of float[] values.

ofPathMorph

fun ofPathMorph(vararg values: PathData): Animation<PathData, PathData>

Constructs and returns an Animation that animates between PathData values. A single value implies that the value is the one being animated to, in which case the start value will be derived from the property being animated and the target object when the animation is started. Two values imply starting and ending values. More than two values imply a starting value, values to animate through along the way, and an ending value (these values will be distributed evenly across the duration of the animation).

fun ofPathMorph(vararg values: Keyframe<PathData>): Animation<PathData, PathData>

Same as ofPathMorph except with Keyframes instead of float[] values.

ofPathMotion

fun ofPathMotion(path: Path): Animation<PointF, PointF>

Constructs and returns an Animation that animates through PointF values in order to simulate motion along the given path. Clients can use transform to transform the returned animation into one that outputs floats corresponding to the path's x/y coordinates.