AnimatorListeners
added to them.
*/
public abstract class Animator implements Cloneable {
/**
* The value used to indicate infinite duration (e.g. when Animators repeat infinitely).
*/
public static final long DURATION_INFINITE = -1;
/**
* The set of listeners to be sent events through the life of an animation.
*/
ArrayListThe 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.
* */ public void start() { } /** * Cancels the animation. Unlike {@link #end()},cancel()
causes the animation to
* stop in its tracks, sending an
* {@link android.animation.Animator.AnimatorListener#onAnimationCancel(Animator)} to
* its listeners, followed by an
* {@link android.animation.Animator.AnimatorListener#onAnimationEnd(Animator)} message.
*
* This method must be called on the thread that is running the animation.
*/ public void cancel() { } /** * Ends the animation. This causes the animation to assign the end value of the property being * animated, then calling the * {@link android.animation.Animator.AnimatorListener#onAnimationEnd(Animator)} method on * its listeners. * *This method must be called on the thread that is running the animation.
*/ public void end() { } /** * 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 {@link * #isStarted() started} or has since ended, then the call is ignored. Paused * animations can be resumed by calling {@link #resume()}. * * @see #resume() * @see #isPaused() * @see AnimatorPauseListener */ public void pause() { // We only want to pause started Animators or animators that setCurrentPlayTime() // have been called on. mStartListenerCalled will be true if seek has happened. if ((isStarted() || mStartListenersCalled) && !mPaused) { mPaused = true; notifyPauseListeners(AnimatorCaller.ON_PAUSE); } } /** * Resumes a paused animation, causing the animator to pick up 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 to resume() on an animator that is * not currently paused will be ignored. * * @see #pause() * @see #isPaused() * @see AnimatorPauseListener */ public void resume() { if (mPaused) { mPaused = false; notifyPauseListeners(AnimatorCaller.ON_RESUME); } } /** * Returns whether this animator is currently in a paused state. * * @return True if the animator is currently paused, false otherwise. * * @see #pause() * @see #resume() */ public boolean isPaused() { return mPaused; } /** * The amount of time, in milliseconds, to delay processing the animation * after {@link #start()} is called. * * @return the number of milliseconds to delay running the animation */ public abstract long getStartDelay(); /** * The amount of time, in milliseconds, to delay processing the animation * after {@link #start()} is called. * @param startDelay The amount of the delay, in milliseconds */ public abstract void setStartDelay(long startDelay); /** * Sets the duration of the animation. * * @param duration The length of the animation, in milliseconds. */ public abstract Animator setDuration(long duration); /** * Gets the duration of the animation. * * @return The length of the animation, in milliseconds. */ public abstract long getDuration(); /** * Gets the total duration of the animation, accounting for animation sequences, start delay, * and repeating. Return {@link #DURATION_INFINITE} if the duration is infinite. * * @return Total time an animation takes to finish, starting from the time {@link #start()} * is called. {@link #DURATION_INFINITE} will be returned if the animation or any * child animation repeats infinite times. */ public long getTotalDuration() { long duration = getDuration(); if (duration == DURATION_INFINITE) { return DURATION_INFINITE; } else { return getStartDelay() + duration; } } /** * The time interpolator used in calculating the elapsed fraction of the * animation. The interpolator determines whether the animation runs with * linear or non-linear motion, such as acceleration and deceleration. The * default value is {@link android.view.animation.AccelerateDecelerateInterpolator}. * * @param value the interpolator to be used by this animation */ public abstract void setInterpolator(TimeInterpolator value); /** * Returns the timing interpolator that this animation uses. * * @return The timing interpolator for this animation. */ public TimeInterpolator getInterpolator() { return null; } /** * Returns whether this Animator is currently running (having been started and gone past any * initial startDelay period and not yet ended). * * @return Whether the Animator is running. */ public abstract boolean isRunning(); /** * Returns whether this Animator has been started and not yet ended. For reusable * Animators (which most Animators are, apart from the one-shot animator produced by * {@link android.view.ViewAnimationUtils#createCircularReveal( * android.view.View, int, int, float, float) createCircularReveal()}), * this state is a superset of {@link #isRunning()}, because an Animator with a * nonzero {@link #getStartDelay() startDelay} will return true for {@link #isStarted()} during * the delay phase, whereas {@link #isRunning()} will return true only after the delay phase * is complete. Non-reusable animators will always return true after they have been * started, because they cannot return to a non-started state. * * @return Whether the Animator has been started and not yet ended. */ public boolean isStarted() { // Default method returns value for isRunning(). Subclasses should override to return a // real value. return isRunning(); } /** * Adds a listener to the set of listeners that are sent events through the life of an * animation, such as start, repeat, and end. * * @param listener the listener to be added to the current set of listeners for this animation. */ public void addListener(AnimatorListener listener) { if (mListeners == null) { mListeners = new ArrayListAnimator
object.
*
* @return ArrayList
* This constant state is used to create new instances of this animator when needed, instead
* of re-loading it from resources. Default implementation creates a new
* {@link AnimatorConstantState}. You can override this method to provide your custom logic or
* return null if you don't want this animator to be cached.
*
* @return The ConfigurationBoundResourceCache.BaseConstantState associated to this Animator.
* @see android.content.res.ConstantState
* @see #clone()
* @hide
*/
public ConstantState
* Note: The target is stored as a weak reference internally to avoid leaking
* resources by having animators directly reference old targets. Therefore, you should
* ensure that animator targets always have a hard reference elsewhere.
*
* @param target The object being animated
*/
public void setTarget(@Nullable Object target) {
}
// Hide reverse() and canReverse() for now since reverse() only work for simple
// cases, like we don't support sequential, neither startDelay.
// TODO: make reverse() works for all the Animators.
/**
* @hide
*/
public boolean canReverse() {
return false;
}
/**
* @hide
*/
@UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553)
public void reverse() {
throw new IllegalStateException("Reverse is not supported");
}
// Pulse an animation frame into the animation.
boolean pulseAnimationFrame(long frameTime) {
// TODO: Need to find a better signal than this. There's a bug in SystemUI that's preventing
// returning !isStarted() from working.
return false;
}
/**
* Internal use only.
* This call starts the animation in regular or reverse direction without requiring them to
* register frame callbacks. The caller will be responsible for all the subsequent animation
* pulses. Specifically, the caller needs to call doAnimationFrame(...) for the animation on
* every frame.
*
* @param inReverse whether the animation should play in reverse direction
*/
void startWithoutPulsing(boolean inReverse) {
if (inReverse) {
reverse();
} else {
start();
}
}
/**
* Internal use only.
* Skips the animation value to end/start, depending on whether the play direction is forward
* or backward.
*
* @param inReverse whether the end value is based on a reverse direction. If yes, this is
* equivalent to skip to start value in a forward playing direction.
*/
void skipToEndValue(boolean inReverse) {}
/**
* Internal use only.
*
* Returns whether the animation has start/end values setup. For most of the animations, this
* should always be true. For ObjectAnimators, the start values are setup in the initialization
* of the animation.
*/
boolean isInitialized() {
return true;
}
/**
* Internal use only. Changes the value of the animator as if currentPlayTime has passed since
* the start of the animation. Therefore, currentPlayTime includes the start delay, and any
* repetition. lastPlayTime is similar and is used to calculate how many repeats have been
* done between the two times.
*/
void animateValuesInRange(long currentPlayTime, long lastPlayTime) {}
/**
* Internal use only. This animates any animation that has ended since lastPlayTime.
* If an animation hasn't been finished, no change will be made.
*/
void animateSkipToEnds(long currentPlayTime, long lastPlayTime) {}
/**
* Internal use only. Adds all start times (after delay) to and end times to times.
* The value must include offset.
*/
void getStartAndEndTimes(LongArray times, long offset) {
long startTime = offset + getStartDelay();
if (times.indexOf(startTime) < 0) {
times.add(startTime);
}
long duration = getTotalDuration();
if (duration != DURATION_INFINITE) {
long endTime = duration + offset;
if (times.indexOf(endTime) < 0) {
times.add(endTime);
}
}
}
/**
* Calls notification for each AnimatorListener.
*
* @param notification The notification method to call on each listener.
* @param isReverse When this is used with start/end, this is the isReverse parameter. For
* other calls, this is ignored.
*/
void notifyListeners(
AnimatorCaller An animation listener receives notifications from an animation.
* Notifications indicate animation related events, such as the end or the
* repetition of the animation. Notifies the start of the animation as well as the animation's overall play direction.
* This method's default behavior is to call {@link #onAnimationStart(Animator)}. This
* method can be overridden, though not required, to get the additional play direction info
* when an animation starts. Skipping calling super when overriding this method results in
* {@link #onAnimationStart(Animator)} not getting called.
*
* @param animation The started animation.
* @param isReverse Whether the animation is playing in reverse.
*/
default void onAnimationStart(@NonNull Animator animation, boolean isReverse) {
onAnimationStart(animation);
}
/**
* Notifies the end of the animation. This callback is not invoked
* for animations with repeat count set to INFINITE. This method's default behavior is to call {@link #onAnimationEnd(Animator)}. This
* method can be overridden, though not required, to get the additional play direction info
* when an animation ends. Skipping calling super when overriding this method results in
* {@link #onAnimationEnd(Animator)} not getting called.
*
* @param animation The animation which reached its end.
* @param isReverse Whether the animation is playing in reverse.
*/
default void onAnimationEnd(@NonNull Animator animation, boolean isReverse) {
onAnimationEnd(animation);
}
/**
* Notifies the start of the animation. Notifies the end of the animation. This callback is not invoked
* for animations with repeat count set to INFINITE. Notifies the cancellation of the animation. This callback is not invoked
* for animations with repeat count set to INFINITE. Notifies the repetition of the animation. Notifies that the animation was paused. Notifies that the animation was resumed, after being
* previously paused. Whether or not the Animator is allowed to run asynchronously off of
* the UI thread. This is a hint that informs the Animator that it is
* OK to run the animation off-thread, however the Animator may decide
* that it must run the animation on the UI thread anyway.
*
* Regardless of whether or not the animation runs asynchronously, all
* listener callbacks will be called on the UI thread. To be able to use this hint the following must be true:
* When {@link #newInstance()} is called, default implementation clones the Animator.
*/
private static class AnimatorConstantState extends ConstantStatecall
for every item in list
with animator
and
* isReverse
as parameters.
*
* @param list The list of items to make calls on.
* @param call The method to call for each item in list.
* @param animator The animator parameter of call.
* @param isReverse The isReverse parameter of call.
* @param
*
* @hide
*/
public void setAllowRunningAsynchronously(boolean mayRunAsync) {
// It is up to subclasses to support this, if they can.
}
/**
* Creates a {@link ConstantState} which holds changing configurations information associated
* with the given Animator.
*