@Implements(value=android.view.Choreographer.class) public class ShadowChoreographer extends java.lang.Object
Robolectric maintains its own concept of the current time from the Choreographer’s point of view, aimed at making animations work correctly. Time starts out at 0
and advances by frameInterval
every time Choreographer.getFrameTimeNanos()
is called.
Constructor and Description |
---|
ShadowChoreographer() |
Modifier and Type | Method and Description |
---|---|
static long |
getFrameInterval()
Return the current inter-frame interval.
|
protected long |
getFrameTimeNanos() |
protected static android.view.Choreographer |
getInstance() |
protected void |
postCallback(int callbackType,
java.lang.Runnable action,
java.lang.Object token)
The default implementation will call
postCallbackDelayed(int, Runnable, Object, long) with no delay. |
protected void |
postCallbackDelayed(int callbackType,
java.lang.Runnable action,
java.lang.Object token,
long delayMillis) |
protected void |
postFrameCallback(android.view.Choreographer.FrameCallback callback)
The default implementation will call
#postFrameCallbackDelayed(FrameCallback, long) with no delay. |
protected void |
postFrameCallbackDelayed(android.view.Choreographer.FrameCallback callback,
long delayMillis) |
protected void |
removeCallbacks(int callbackType,
java.lang.Runnable action,
java.lang.Object token) |
protected void |
removeFrameCallback(android.view.Choreographer.FrameCallback callback) |
static void |
reset() |
static void |
setFrameInterval(long frameInterval)
Set the inter-frame interval used to advance the clock.
|
static void |
setPostCallbackDelay(int delayMillis)
Allows application to specify a fixed amount of delay when
postCallback(int, Runnable,
Object) is invoked. |
static void |
setPostFrameCallbackDelay(int delayMillis)
Allows application to specify a fixed amount of delay when
#postFrameCallback(FrameCallback) is invoked. |
public static void setPostCallbackDelay(int delayMillis)
Allows application to specify a fixed amount of delay when postCallback(int, Runnable,
Object)
is invoked. The default delay value is 0
. This can be used to avoid infinite animation tasks to be spawned when the Robolectric Scheduler
is in Scheduler.IdleState.PAUSED
mode.
public static void setPostFrameCallbackDelay(int delayMillis)
Allows application to specify a fixed amount of delay when #postFrameCallback(FrameCallback)
is invoked. The default delay value is 0
. This can be used to avoid infinite animation tasks to be spawned when the Robolectric Scheduler
is in Scheduler.IdleState.PAUSED
mode.
@Implementation protected static android.view.Choreographer getInstance()
@Implementation protected void postCallback(int callbackType, java.lang.Runnable action, java.lang.Object token)
The default implementation will call postCallbackDelayed(int, Runnable, Object, long)
with no delay. AnimationHandler
calls this method to schedule animation updates infinitely. Because during a Robolectric test the system time is paused and execution of the event loop is invoked for each test instruction, the behavior of AnimationHandler would result in endless looping (the execution of the task results in a new animation task created and scheduled to the front of the event loop queue).
To prevent endless looping, a test may call setPostCallbackDelay(int)
to specify a small delay when animation is scheduled.
setPostCallbackDelay(int)
@Implementation protected void postCallbackDelayed(int callbackType, java.lang.Runnable action, java.lang.Object token, long delayMillis)
@Implementation protected void removeCallbacks(int callbackType, java.lang.Runnable action, java.lang.Object token)
@Implementation protected void postFrameCallback(android.view.Choreographer.FrameCallback callback)
The default implementation will call #postFrameCallbackDelayed(FrameCallback, long)
with no delay. AnimationHandler
calls this method to schedule animation updates infinitely. Because during a Robolectric test the system time is paused and execution of the event loop is invoked for each test instruction, the behavior of AnimationHandler would result in endless looping (the execution of the task results in a new animation task created and scheduled to the front of the event loop queue).
To prevent endless looping, a test may call setPostFrameCallbackDelay(int)
to specify a small delay when animation is scheduled.
setPostCallbackDelay(int)
@Implementation protected void postFrameCallbackDelayed(android.view.Choreographer.FrameCallback callback, long delayMillis)
@Implementation protected void removeFrameCallback(android.view.Choreographer.FrameCallback callback)
@Implementation protected long getFrameTimeNanos()
public static long getFrameInterval()
Return the current inter-frame interval.
public static void setFrameInterval(long frameInterval)
Set the inter-frame interval used to advance the clock. By default, this is set to 1ms.
frameInterval
- Inter-frame interval.@Resetter public static void reset()