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()
Scheduler
Retrieves the current idling state of this Scheduler.
getIdleState
in class Scheduler
Scheduler.setIdleState(IdleState)
,
Scheduler.isPaused()
public void setIdleState(Scheduler.IdleState idleState)
Scheduler
Sets 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 Scheduler
idleState
- The new idle state of this Scheduler.Scheduler.setIdleState(IdleState)
,
Scheduler.isPaused()
public long getCurrentTime()
Scheduler
Get the current time (as seen by the scheduler), in milliseconds.
getCurrentTime
in class Scheduler
public void pause()
Scheduler
Pause the scheduler. Equivalent to setIdleState(PAUSED).
pause
in class Scheduler
Scheduler.unPause()
,
Scheduler.setIdleState(IdleState)
public void unPause()
Scheduler
Un-pause the scheduler. Equivalent to setIdleState(UNPAUSED).
unPause
in class Scheduler
Scheduler.pause()
,
Scheduler.setIdleState(IdleState)
public boolean isPaused()
Scheduler
Determine if the scheduler is paused.
public void post(Runnable runnable)
Scheduler
Add a runnable to the queue.
public void postDelayed(Runnable runnable, long delayMillis)
Scheduler
Add a runnable to the queue to be run after a delay.
postDelayed
in class Scheduler
runnable
- Runnable to add.delayMillis
- Delay in millis.public void postDelayed(Runnable runnable, long delay, TimeUnit unit)
Scheduler
Add a runnable to the queue to be run after a delay.
postDelayed
in class Scheduler
public void postAtFrontOfQueue(Runnable runnable)
Scheduler
Add a runnable to the head of the queue.
postAtFrontOfQueue
in class Scheduler
runnable
- Runnable to add.public void remove(Runnable runnable)
Scheduler
Remove a runnable from the queue.
public boolean advanceToLastPostedRunnable()
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.
advanceToLastPostedRunnable
in class Scheduler
public boolean advanceToNextPostedRunnable()
Scheduler
Run the next runnable in the queue.
advanceToNextPostedRunnable
in class Scheduler
public boolean advanceBy(long interval)
Scheduler
Run all runnables that are scheduled to run in the next time interval.
public boolean advanceBy(long amount, TimeUnit unit)
Scheduler
Run all runnables that are scheduled to run in the next time interval.
public boolean advanceTo(long endTime)
Scheduler
Run all runnables that are scheduled before the endTime.
public boolean runOneTask()
Scheduler
Run the next runnable in the queue.
runOneTask
in class Scheduler
public boolean areAnyRunnable()
Scheduler
Determine if any enqueued runnables are enqueued before the current time.
areAnyRunnable
in class Scheduler
public void reset()
Scheduler
Reset the internal state of the Scheduler.
public int size()
Scheduler
Return the number of enqueued runnables.
public Duration getNextScheduledTaskTime()
getNextScheduledTaskTime
in class Scheduler
public Duration getLastScheduledTaskTime()
getLastScheduledTaskTime
in class Scheduler
@Deprecated public void idleConstantly(boolean shouldIdleConstantly)
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.
idleConstantly
in class Scheduler
shouldIdleConstantly
- If true the idle state will be set to Scheduler.IdleState.CONSTANT_IDLE
, otherwise it will be set to Scheduler.IdleState.UNPAUSED
.