Package icyllis.modernui.animation
Class Animator
java.lang.Object
icyllis.modernui.animation.Animator
- All Implemented Interfaces:
Cloneable
- Direct Known Subclasses:
AnimatorSet
,ValueAnimator
This is the base for classes which provide basic support for animations which can be
started, ended, and have listeners added to them.
-
Field Summary
Modifier and TypeFieldDescriptionstatic final long
The value used to indicate infinite duration (e.g.static final org.apache.logging.log4j.Marker
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionfinal void
addListener
(AnimatorListener listener) Adds a listener to the set of listeners that are sent events through the life of an animation, such as start, repeat, and end.abstract void
cancel()
Cancels the animation.boolean
clone()
abstract void
end()
Ends the animation.abstract long
Gets the duration of the animation.abstract TimeInterpolator
Returns the timing interpolator that this animation uses.final List
<AnimatorListener> Gets the set ofAnimatorListener
objects that are currently listening for events on thisAnimator
object.abstract long
The amount of time, in milliseconds, to delay processing the animation afterstart()
is called.abstract long
Gets the total duration of the animation, accounting for animation sequences, start delay, and repeating.final boolean
isPaused()
Returns whether this animator is currently in a paused state.abstract boolean
Returns whether this Animator is currently running (having been started and gone past any initial startDelay period and not yet ended).abstract boolean
Returns whether this Animator has been started and not yet ended.void
pause()
Pauses a running animation.final void
Removes alllisteners
from this object.final void
removeListener
(AnimatorListener listener) Removes a listener from the set listening to this animation.void
resume()
Resumes a paused animation, causing the animator to pick up where it left off when it was paused.void
reverse()
abstract Animator
setDuration
(long duration) Sets the duration of the animation.abstract void
setInterpolator
(TimeInterpolator value) The time interpolator used in calculating the elapsed fraction of the animation.abstract void
setStartDelay
(long startDelay) The amount of time, in milliseconds, to delay processing the animation afterstart()
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.abstract void
start()
Starts this animation.
-
Field Details
-
MARKER
public static final org.apache.logging.log4j.Marker MARKER -
DURATION_INFINITE
public static final long DURATION_INFINITEThe value used to indicate infinite duration (e.g. when Animators repeat infinitely).- See Also:
-
-
Constructor Details
-
Animator
public Animator()
-
-
Method Details
-
start
public abstract 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 toAnimatorListener.onAnimationStart(Animator, boolean)
for any listeners of this animator.The animation started by calling this method will be run on the thread that called this method.
-
cancel
public abstract void cancel()Cancels the animation. Unlikeend()
,cancel()
causes the animation to stop in its tracks, sending anAnimatorListener.onAnimationCancel(Animator)
to its listeners, followed by anAnimatorListener.onAnimationEnd(Animator, boolean)
message.This method must be called on the thread that is running the animation.
-
end
public abstract void end()Ends the animation. This causes the animation to assign the end value of the property being animated, then calling theAnimatorListener.onAnimationEnd(Animator, boolean)
method on its listeners.This method must be called on the thread that is running the animation.
-
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 beenstarted
or has since ended, then the call is ignored. Paused animations can be resumed by callingresume()
.- See Also:
-
resume
public void resume()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 Also:
-
isPaused
public final boolean isPaused()Returns whether this animator is currently in a paused state.- Returns:
- True if the animator is currently paused, false otherwise.
- See Also:
-
setStartDelay
public abstract void setStartDelay(long startDelay) The amount of time, in milliseconds, to delay processing the animation afterstart()
is called.- Parameters:
startDelay
- The amount of the delay, in milliseconds
-
getStartDelay
public abstract long getStartDelay()The amount of time, in milliseconds, to delay processing the animation afterstart()
is called.- Returns:
- the number of milliseconds to delay running the animation
-
setDuration
Sets the duration of the animation.- Parameters:
duration
- The length of the animation, in milliseconds.
-
getDuration
public abstract long getDuration()Gets the duration of the animation.- Returns:
- The length of the animation, in milliseconds.
-
getTotalDuration
public abstract long getTotalDuration()Gets the total duration of the animation, accounting for animation sequences, start delay, and repeating. ReturnDURATION_INFINITE
if the duration is infinite.- Returns:
- Total time an animation takes to finish, starting from the time
start()
is called.DURATION_INFINITE
will be returned if the animation or any child animation repeats infinite times.
-
setInterpolator
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 isTimeInterpolator.ACCELERATE_DECELERATE
.- Parameters:
value
- the interpolator to be used by this animation
-
getInterpolator
Returns the timing interpolator that this animation uses.- Returns:
- The timing interpolator for this animation.
-
isRunning
public abstract boolean isRunning()Returns whether this Animator is currently running (having been started and gone past any initial startDelay period and not yet ended).- Returns:
- Whether the Animator is running.
-
isStarted
public abstract boolean isStarted()Returns whether this Animator has been started and not yet ended. For reusable Animators (which most Animators are, apart from the one-shot animator), this state is a superset ofisRunning()
, because an Animator with a nonzerogetStartDelay()
will return true during the delay phase, whereasisRunning()
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.- Returns:
- whether the Animator has been started and not yet ended.
-
addListener
Adds a listener to the set of listeners that are sent events through the life of an animation, such as start, repeat, and end.- Parameters:
listener
- the listener to be added to the current set of listeners for this animation.
-
removeListener
Removes a listener from the set listening to this animation.- Parameters:
listener
- the listener to be removed from the current set of listeners for this animation.
-
removeAllListeners
public final void removeAllListeners()Removes alllisteners
from this object. -
getListeners
Gets the set ofAnimatorListener
objects that are currently listening for events on thisAnimator
object.- Returns:
- The set of listeners.
-
clone
-
setupStartValues
public void setupStartValues()This method tells the object to use appropriate information to extract starting values for the animation. For example, a AnimatorSet object will pass this call to its child objects to tell them to set up the values. A ObjectAnimator object will use the information it has about its target object and PropertyValuesHolder objects to get the start values for its properties. A ValueAnimator object will ignore the request since it does not have enough information (such as a target object) to gather these values. -
setupEndValues
public void setupEndValues()This method tells the object to use appropriate information to extract ending values for the animation. For example, a AnimatorSet object will pass this call to its child objects to tell them to set up the values. A ObjectAnimator object will use the information it has about its target object and PropertyValuesHolder objects to get the start values for its properties. A ValueAnimator object will ignore the request since it does not have enough information (such as a target object) to gather these values. -
setTarget
Sets the target object whose property will be animated by this animation. Not all subclasses operate on target objects, but this method is on the superclass for the convenience of dealing generically with those subclasses that do handle targets.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.
- Parameters:
target
- The object being animated
-
canReverse
@Internal public boolean canReverse() -
reverse
@Internal public void reverse()
-