Package org.robolectric.android.internal
Class LooperDelegatingScheduler
java.lang.Object
org.robolectric.util.Scheduler
org.robolectric.android.internal.LooperDelegatingScheduler
public class LooperDelegatingScheduler extends Scheduler
A foreground Scheduler implementation used for
LooperMode.Mode.PAUSED
.
All API calls will delegate to ShadowLooper.
-
Nested Class Summary
-
Constructor Summary
Constructors Constructor Description LooperDelegatingScheduler(Looper looper)
-
Method Summary
Modifier and Type Method Description boolean
advanceBy(long amount, TimeUnit unit)
Run all runnables that are scheduled to run in the next time interval.boolean
advanceTo(long endTime)
Run all runnables that are scheduled before the endTime.boolean
advanceToLastPostedRunnable()
Run all runnables in the queue, and any additional runnables they schedule that are scheduled before the latest scheduled runnable currently in the queue.boolean
advanceToNextPostedRunnable()
Run the next runnable in the queue.boolean
areAnyRunnable()
Determine if any enqueued runnables are enqueued before the current time.long
getCurrentTime()
Get the current time (as seen by the scheduler), in milliseconds.Scheduler.IdleState
getIdleState()
Retrieves the current idling state of thisScheduler
.Duration
getLastScheduledTaskTime()
Duration
getNextScheduledTaskTime()
void
idleConstantly(boolean shouldIdleConstantly)
Deprecated.boolean
isPaused()
Determine if the scheduler is paused.void
pause()
Pause the scheduler.void
post(Runnable runnable)
Add a runnable to the queue.void
postAtFrontOfQueue(Runnable runnable)
Add a runnable to the head of the queue.void
postDelayed(Runnable runnable, long delayMillis)
Add a runnable to the queue to be run after a delay.void
postDelayed(Runnable runnable, long delay, TimeUnit unit)
Add a runnable to the queue to be run after a delay.void
remove(Runnable runnable)
Remove a runnable from the queue.void
reset()
Reset the internal state of the Scheduler.boolean
runOneTask()
Run the next runnable in the queue.void
setIdleState(Scheduler.IdleState idleState)
Sets the current idling state of thisScheduler
.int
size()
Return the number of enqueued runnables.void
unPause()
Un-pause the scheduler.
-
Constructor Details
-
Method Details
-
getIdleState
Description copied from class:Scheduler
Retrieves the current idling state of thisScheduler
.- Overrides:
getIdleState
in classScheduler
- Returns:
- The current idle state of this
Scheduler
. - See Also:
Scheduler.setIdleState(IdleState)
,Scheduler.isPaused()
-
setIdleState
Description copied from class:Scheduler
Sets the current idling state of thisScheduler
. If transitioning to theScheduler.IdleState.UNPAUSED
state any tasks scheduled to be run at or before the current time will be run, and if transitioning to theScheduler.IdleState.CONSTANT_IDLE
state all scheduled tasks will be run and the clock advanced to the time of the last runnable.- Overrides:
setIdleState
in classScheduler
- Parameters:
idleState
- The new idle state of thisScheduler
.- See Also:
Scheduler.setIdleState(IdleState)
,Scheduler.isPaused()
-
getCurrentTime
public long getCurrentTime()Description copied from class:Scheduler
Get the current time (as seen by the scheduler), in milliseconds.- Overrides:
getCurrentTime
in classScheduler
- Returns:
- Current time in milliseconds.
-
pause
public void pause()Description copied from class:Scheduler
Pause the scheduler. Equivalent tosetIdleState(PAUSED)
.- Overrides:
pause
in classScheduler
- See Also:
Scheduler.unPause()
,Scheduler.setIdleState(IdleState)
-
unPause
public void unPause()Description copied from class:Scheduler
Un-pause the scheduler. Equivalent tosetIdleState(UNPAUSED)
.- Overrides:
unPause
in classScheduler
- See Also:
Scheduler.pause()
,Scheduler.setIdleState(IdleState)
-
isPaused
public boolean isPaused()Description copied from class:Scheduler
Determine if the scheduler is paused. -
post
Description copied from class:Scheduler
Add a runnable to the queue. -
postDelayed
Description copied from class:Scheduler
Add a runnable to the queue to be run after a delay.- Overrides:
postDelayed
in classScheduler
- Parameters:
runnable
- Runnable to add.delayMillis
- Delay in millis.
-
postDelayed
Description copied from class:Scheduler
Add a runnable to the queue to be run after a delay.- Overrides:
postDelayed
in classScheduler
-
postAtFrontOfQueue
Description copied from class:Scheduler
Add a runnable to the head of the queue.- Overrides:
postAtFrontOfQueue
in classScheduler
- Parameters:
runnable
- Runnable to add.
-
remove
Description copied from class:Scheduler
Remove a runnable from the queue. -
advanceToLastPostedRunnable
public boolean advanceToLastPostedRunnable()Description copied from class:Scheduler
Run all runnables in the queue, and any additional runnables they schedule that are scheduled before the latest scheduled runnable currently in the queue.- Overrides:
advanceToLastPostedRunnable
in classScheduler
- Returns:
- True if a runnable was executed.
-
advanceToNextPostedRunnable
public boolean advanceToNextPostedRunnable()Description copied from class:Scheduler
Run the next runnable in the queue.- Overrides:
advanceToNextPostedRunnable
in classScheduler
- Returns:
- True if a runnable was executed.
-
advanceBy
Description copied from class:Scheduler
Run all runnables that are scheduled to run in the next time interval. -
advanceTo
public boolean advanceTo(long endTime)Description copied from class:Scheduler
Run all runnables that are scheduled before the endTime. -
runOneTask
public boolean runOneTask()Description copied from class:Scheduler
Run the next runnable in the queue.- Overrides:
runOneTask
in classScheduler
- Returns:
- True if a runnable was executed.
-
areAnyRunnable
public boolean areAnyRunnable()Description copied from class:Scheduler
Determine if any enqueued runnables are enqueued before the current time.- Overrides:
areAnyRunnable
in classScheduler
- Returns:
- True if any runnables can be executed.
-
reset
public void reset()Description copied from class:Scheduler
Reset the internal state of the Scheduler. -
size
public int size()Description copied from class:Scheduler
Return the number of enqueued runnables. -
getNextScheduledTaskTime
- Overrides:
getNextScheduledTaskTime
in classScheduler
-
getLastScheduledTaskTime
- Overrides:
getLastScheduledTaskTime
in classScheduler
-
idleConstantly
Deprecated.Description copied from class:Scheduler
Set the idle state of the Scheduler. If necessary, the clock will be advanced and runnables executed as required by the newly-set state.- Overrides:
idleConstantly
in classScheduler
- Parameters:
shouldIdleConstantly
- If true the idle state will be set toScheduler.IdleState.CONSTANT_IDLE
, otherwise it will be set toScheduler.IdleState.UNPAUSED
.
-