TimeAnimator

public class TimeAnimator extends ValueAnimator


This class provides a simple callback mechanism to listeners that is synchronized with all other animators in the system. There is no duration, interpolation, or object value-setting with this Animator. Instead, it is simply started, after which it proceeds to send out events on every animation frame to its TimeListener (if set), with information about this animator, the total elapsed time, and the elapsed time since the previous animation frame.

Summary

Nested types

public interface TimeAnimator.TimeListener

Implementors of this interface can set themselves as update listeners to a TimeAnimator instance to receive callbacks on every animation frame to receive the total time since the animator started and the delta time since the last frame.

Public constructors

Public methods

void
setCurrentPlayTime(long playTime)

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

void

Sets a listener that is sent update events throughout the life of an animation.

void

Starts this animation.

Inherited Constants

From androidx.core.animation.Animator
static final long

The value used to indicate infinite duration (e.g. when Animators repeat infinitely).

From androidx.core.animation.ValueAnimator
static final int

This value used used with the setRepeatCount property to repeat the animation indefinitely.

static final int

When the animation reaches the end and repeatCount is INFINITE or a positive value, the animation restarts from the beginning.

static final int

When the animation reaches the end and repeatCount is INFINITE or a positive value, the animation reverses direction on every iteration.

Inherited methods

From androidx.core.animation.Animator
void

Adds a listener to the set of listeners that are sent events through the life of an animation, such as start, repeat, and end.

void

Adds a pause listener to this animator.

void

Adds a listener to the set of listeners that are sent update events through the life of an animation.

@NonNull Animator
boolean

Returns whether this animator is currently in a paused state.

void

Removes all listeners and pauseListeners from this object.

void

Removes all listeners from the set listening to frame updates for this animation.

void

Removes a listener from the set listening to this animation.

void

Removes a pause listener from the set listening to this animation.

void

Removes a listener from the set listening to frame updates for this animation.

abstract @NonNull Animator
setDuration(@IntRange(from = 0) long duration)

Sets the duration of the animation.

abstract void
setStartDelay(@IntRange(from = 0) long startDelay)

The amount of time, in milliseconds, to delay processing the animation after start is called.

void

Sets the target object whose property will be animated by this animation.

void

This method tells the object to use appropriate information to extract ending values for the animation.

void

This method tells the object to use appropriate information to extract starting values for the animation.

From androidx.core.animation.ValueAnimator
static boolean

Returns whether animators are currently enabled, system-wide.

void

Cancels the animation.

@NonNull ValueAnimator
void
end()

Ends the animation.

float

Returns the current animation fraction, which is the elapsed/interpolated fraction used in the most recent frame update on the animation.

@NonNull Object

The most recent value calculated by this ValueAnimator when there is just one property being animated.

@Nullable Object

The most recent value calculated by this ValueAnimator for propertyName.

long

Gets the current position of the animation in time, which is equal to the current time minus the time that the animation started.

long

Gets the length of the animation.

static long

The amount of time, in milliseconds, between each frame of the animation.

@Nullable Interpolator

Returns the timing interpolator that this ValueAnimator uses.

@NonNull String

Returns the name of this animator for debugging purposes.

int

Defines how many times the animation should repeat.

int

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

long

The amount of time, in milliseconds, to delay starting the animation after start is called.

long

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

@NonNull PropertyValuesHolder[]

Returns the values that this ValueAnimator animates between.

boolean

Returns whether this Animator is currently running (having been started and gone past any initial startDelay period and not yet ended).

boolean

Returns whether this Animator has been started and not yet ended.

static @NonNull ValueAnimator
ofArgb(@NonNull int[] values)

Constructs and returns a ValueAnimator that animates between color values.

static @NonNull ValueAnimator
ofFloat(@NonNull float[] values)

Constructs and returns a ValueAnimator that animates between float values.

static @NonNull ValueAnimator
ofInt(@NonNull int[] values)

Constructs and returns a ValueAnimator that animates between int values.

static @NonNull ValueAnimator
ofObject(@NonNull TypeEvaluator evaluator, @NonNull Object[] values)

Constructs and returns a ValueAnimator that animates between Object values.

static @NonNull ValueAnimator
ofPropertyValuesHolder(@NonNull PropertyValuesHolder[] values)

Constructs and returns a ValueAnimator that animates between the values specified in the PropertyValuesHolder objects.

void

Pauses a running animation.

void

Resumes a paused animation, causing the animator to pick up where it left off when it was paused.

void

Plays the ValueAnimator in reverse.

void
setCurrentFraction(float fraction)

Sets the position of the animation to the specified fraction.

@NonNull ValueAnimator
setDuration(long duration)

Sets the length of the animation.

void

The type evaluator to be used when calculating the animated values of this animation.

void
setFloatValues(@NonNull float[] values)

Sets float values that will be animated between.

static void
setFrameDelay(long frameDelay)

The amount of time, in milliseconds, between each frame of the animation.

void
setIntValues(@NonNull int[] values)

Sets int values that will be animated between.

void

The interpolator used in calculating the elapsed fraction of this animation.

void
setNameForTrace(@NonNull String animationName)

Sets a name for the animation to show up in the systrace.

void
setObjectValues(@NonNull Object[] values)

Sets the values to animate between for this animation.

void
setRepeatCount(int value)

Sets how many times the animation should be repeated.

void

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

void
setStartDelay(long startDelay)

The amount of time, in milliseconds, to delay starting the animation after start is called.

void
setValues(@NonNull PropertyValuesHolder[] values)

Sets the values, per property, being animated between.

@NonNull String

Public constructors

TimeAnimator

public TimeAnimator()

Public methods

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
long playTime

The time, in milliseconds, to which the animation is advanced or rewound.

setTimeListener

public void setTimeListener(@Nullable TimeAnimator.TimeListener listener)

Sets a listener that is sent update events throughout the life of an animation.

Parameters
@Nullable TimeAnimator.TimeListener listener

the listener to be set.

start

public void start()

Starts this animation. If the animation has a nonzero startDelay, the animation will start running after that delay elapses. A non-delayed animation will have its initial value(s) set immediately, followed by calls to onAnimationStart for any listeners of this animator.

The animation started by calling this method will be run on the thread that called this method. This thread should have a Looper on it (a runtime exception will be thrown if this is not the case). Also, if the animation will animate properties of objects in the view hierarchy, then the calling thread should be the UI thread for that view hierarchy.