Class AnimationTime
Pluggable time source for animations across the framework. Defaults to
System.currentTimeMillis() but can be overridden with an explicit value to
support deterministic playback (e.g. UI tests), to advance animations at a
custom pace (slow-motion, fast-forward), or to step through animation frames
manually.
All methods are static and the class holds only primitive state to keep the
hot path cheap - now() is invoked from every animation tick.
-
Method Summary
Modifier and TypeMethodDescriptionstatic booleanReturns true when an override time is currently active.static longnow()Returns the current animation time in milliseconds.static voidreset()Clears any override and restores now() to delegate toSystem.currentTimeMillis().static voidresume()Clears an override without moving time: now() carries on from the overridden value at the wall clock's pace.static voidsetTime(long time) Overrides the value returned by now().
-
Method Details
-
now
public static long now()Returns the current animation time in milliseconds. Returns
System.currentTimeMillis()unless an override has been set via setTime(long).Returns
the current animation time in milliseconds
-
setTime
public static void setTime(long time) Overrides the value returned by now(). Once set, every animation reading the clock will see the same
timevalue until either this method is called again or reset() is invoked. Advancing animations while overridden requires repeatedly calling this method with increasing values.Parameters
time: the time in milliseconds that now() should return
-
reset
public static void reset()Clears any override and restores now() to delegate toSystem.currentTimeMillis(). -
resume
public static void resume()Clears an override without moving time: now() carries on from the overridden value at the wall clock's pace. Every start time an animation or timer recorded under the override stays in step, where reset() would jump to the wall clock and stall anything that started ahead of it. Does nothing when no override is active. The offset stays until reset(), so code that compares this clock withSystem.currentTimeMillis()sees the difference; read one clock throughout. -
isOverridden
public static boolean isOverridden()Returns true when an override time is currently active.
Returns
true when now() is returning an overridden value
-