public class LooperDelegatingScheduler extends Scheduler
A foreground Scheduler implementation used for LooperMode.Mode#PAUSED.
All API calls will delegate to ShadowLooper.
Scheduler.IdleState| Constructor and Description |
|---|
LooperDelegatingScheduler(Looper looper) |
| Modifier and Type | Method and Description |
|---|---|
boolean |
advanceBy(long interval)
Run all runnables that are scheduled to run in the next time interval.
|
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 this Scheduler.
|
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 this Scheduler.
|
int |
size()
Return the number of enqueued runnables.
|
void |
unPause()
Un-pause the scheduler.
|
public LooperDelegatingScheduler(Looper looper)
public Scheduler.IdleState getIdleState()
SchedulerRetrieves the current idling state of this Scheduler.
getIdleState in class SchedulerScheduler.setIdleState(IdleState),
Scheduler.isPaused()public void setIdleState(Scheduler.IdleState idleState)
SchedulerSets the current idling state of this Scheduler. If transitioning to the Scheduler.IdleState.UNPAUSED state any tasks scheduled to be run at or before the current time will be run, and if transitioning to the Scheduler.IdleState.CONSTANT_IDLE state all scheduled tasks will be run and the clock advanced to the time of the last runnable.
setIdleState in class ScheduleridleState - The new idle state of this Scheduler.Scheduler.setIdleState(IdleState),
Scheduler.isPaused()public long getCurrentTime()
SchedulerGet the current time (as seen by the scheduler), in milliseconds.
getCurrentTime in class Schedulerpublic void pause()
SchedulerPause the scheduler. Equivalent to setIdleState(PAUSED).
pause in class SchedulerScheduler.unPause(),
Scheduler.setIdleState(IdleState)public void unPause()
SchedulerUn-pause the scheduler. Equivalent to setIdleState(UNPAUSED).
unPause in class SchedulerScheduler.pause(),
Scheduler.setIdleState(IdleState)public boolean isPaused()
SchedulerDetermine if the scheduler is paused.
public void post(Runnable runnable)
SchedulerAdd a runnable to the queue.
public void postDelayed(Runnable runnable, long delayMillis)
SchedulerAdd a runnable to the queue to be run after a delay.
postDelayed in class Schedulerrunnable - Runnable to add.delayMillis - Delay in millis.public void postDelayed(Runnable runnable, long delay, TimeUnit unit)
SchedulerAdd a runnable to the queue to be run after a delay.
postDelayed in class Schedulerpublic void postAtFrontOfQueue(Runnable runnable)
SchedulerAdd a runnable to the head of the queue.
postAtFrontOfQueue in class Schedulerrunnable - Runnable to add.public void remove(Runnable runnable)
SchedulerRemove a runnable from the queue.
public boolean advanceToLastPostedRunnable()
SchedulerRun all runnables in the queue, and any additional runnables they schedule that are scheduled before the latest scheduled runnable currently in the queue.
advanceToLastPostedRunnable in class Schedulerpublic boolean advanceToNextPostedRunnable()
SchedulerRun the next runnable in the queue.
advanceToNextPostedRunnable in class Schedulerpublic boolean advanceBy(long interval)
SchedulerRun all runnables that are scheduled to run in the next time interval.
public boolean advanceBy(long amount,
TimeUnit unit)
SchedulerRun all runnables that are scheduled to run in the next time interval.
public boolean advanceTo(long endTime)
SchedulerRun all runnables that are scheduled before the endTime.
public boolean runOneTask()
SchedulerRun the next runnable in the queue.
runOneTask in class Schedulerpublic boolean areAnyRunnable()
SchedulerDetermine if any enqueued runnables are enqueued before the current time.
areAnyRunnable in class Schedulerpublic void reset()
SchedulerReset the internal state of the Scheduler.
public int size()
SchedulerReturn the number of enqueued runnables.
public Duration getNextScheduledTaskTime()
getNextScheduledTaskTime in class Schedulerpublic Duration getLastScheduledTaskTime()
getLastScheduledTaskTime in class Scheduler@Deprecated public void idleConstantly(boolean shouldIdleConstantly)
SchedulerSet the idle state of the Scheduler. If necessary, the clock will be advanced and runnables executed as required by the newly-set state.
idleConstantly in class SchedulershouldIdleConstantly - If true the idle state will be set to Scheduler.IdleState.CONSTANT_IDLE, otherwise it will be set to Scheduler.IdleState.UNPAUSED.