@Implements(value=android.os.Looper.class, isInAndroidSdk=false) public final class ShadowPausedLooper extends ShadowLooper
The shadow Looper for LooperMode.Mode.PAUSED
.
This shadow differs from the legacy ShadowLegacyLooper
in the following ways:\ * - Has no connection to Scheduler
. Its APIs are standalone - The main looper is always paused. Posted messages are not executed unless idle()
is called. - Just like in real Android, each looper has its own thread, and posted tasks get executed in that thread. - - There is only a single SystemClock
value that all loopers read from. Unlike legacy behavior where each Scheduler
kept their own clock value.
This class should not be used directly; use ShadowLooper
instead.
ShadowLooper.Picker
Constructor and Description |
---|
ShadowPausedLooper() |
Modifier and Type | Method and Description |
---|---|
protected void |
__constructor__(boolean quitAllowed) |
Duration |
getLastScheduledTaskTime() |
Duration |
getNextScheduledTaskTime() |
Scheduler |
getScheduler()
Returns the
Scheduler that is being used to manage the enqueued tasks. |
boolean |
hasQuit() |
void |
idle()
Executes all posted tasks scheduled before or at the current time.
|
void |
idleConstantly(boolean shouldIdleConstantly) |
void |
idleFor(long time,
TimeUnit timeUnit)
Advances the system clock by the given time, then executes all posted tasks scheduled before or at the given time.
|
void |
idleIfPaused()
Helper method to selectively call idle() only if LooperMode is PAUSED.
|
boolean |
isIdle()
Returns true if the looper has any pending tasks scheduled to be executed before current time.
|
boolean |
isPaused() |
void |
pause()
Pause the looper.
|
boolean |
post(Runnable runnable,
long delayMillis)
Enqueue a task to be run later.
|
boolean |
postAtFrontOfQueue(Runnable runnable)
Enqueue a task to be run ahead of all other delayed tasks.
|
protected static void |
prepareMainLooper() |
protected void |
quit() |
protected void |
quitSafely() |
void |
quitUnchecked() |
void |
reset()
Causes all enqueued tasks to be discarded, and pause state to be reset
|
static void |
resetLoopers() |
void |
resetScheduler()
Only supported for
LooperMode.Mode.PAUSED . |
void |
runOneTask()
Causes only one of the next
Runnable s that have been scheduled to run while advancing the clock to its start time. |
void |
runPaused(Runnable runnable)
Runs the current task with the looper paused.
|
void |
runToEndOfTasks()
|
void |
runToNextTask()
Causes the next
Runnable (s) that have been scheduled to run while advancing the clock to its start time. |
boolean |
setPaused(boolean shouldPause)
Control the paused state of the Looper.
|
void |
unPause()
Not supported for the main Looper in
LooperMode.Mode.PAUSED . |
assertLooperMode, getLooperForThread, getShadowMainLooper, idle, idle, idleFor, idleMainLooper, idleMainLooper, idleMainLooper, idleMainLooperConstantly, looperMode, pauseLooper, pauseMainLooper, resetThreadLoopers, runMainLooperOneTask, runMainLooperToNextTask, runUiThreadTasks, runUiThreadTasksIncludingDelayedTasks, shadowMainLooper, unPauseLooper, unPauseMainLooper
@Implementation protected void __constructor__(boolean quitAllowed)
public void quitUnchecked()
quitUnchecked
in class ShadowLooper
public boolean hasQuit()
hasQuit
in class ShadowLooper
public void idle()
ShadowLooper
Executes all posted tasks scheduled before or at the current time.
idle
in class ShadowLooper
public void idleFor(long time, TimeUnit timeUnit)
ShadowLooper
Advances the system clock by the given time, then executes all posted tasks scheduled before or at the given time.
idleFor
in class ShadowLooper
public boolean isIdle()
ShadowLooper
Returns true if the looper has any pending tasks scheduled to be executed before current time.
isIdle
in class ShadowLooper
public void unPause()
ShadowLooper
Not supported for the main Looper in LooperMode.Mode.PAUSED
.
unPause
in class ShadowLooper
public void pause()
ShadowLooper
Pause the looper.
Has no practical effect for realistic looper, since it is always paused.
pause
in class ShadowLooper
public boolean isPaused()
isPaused
in class ShadowLooper
public boolean setPaused(boolean shouldPause)
ShadowLooper
Control the paused state of the Looper.
Not supported for the main Looper in LooperMode.Mode.PAUSED
.
setPaused
in class ShadowLooper
public void resetScheduler()
ShadowLooper
Only supported for LooperMode.Mode.PAUSED
.
resetScheduler
in class ShadowLooper
public void reset()
ShadowLooper
Causes all enqueued tasks to be discarded, and pause state to be reset
reset
in class ShadowLooper
public void idleIfPaused()
ShadowLooper
Helper method to selectively call idle() only if LooperMode is PAUSED.
Intended for backwards compatibility, to avoid changing behavior for tests still using LEGACY LooperMode.
idleIfPaused
in class ShadowLooper
public void idleConstantly(boolean shouldIdleConstantly)
idleConstantly
in class ShadowLooper
public void runToEndOfTasks()
ShadowLooper
Causes all of the Runnable
s that have been scheduled to run while advancing the clock to the start time of the last scheduled Runnable
.
runToEndOfTasks
in class ShadowLooper
public void runToNextTask()
ShadowLooper
Causes the next Runnable
(s) that have been scheduled to run while advancing the clock to its start time. If more than one Runnable
is scheduled to run at this time then they will all be run.
runToNextTask
in class ShadowLooper
public void runOneTask()
ShadowLooper
Causes only one of the next Runnable
s that have been scheduled to run while advancing the clock to its start time. Only one Runnable
will run even if more than one has been scheduled to run at the same time.
runOneTask
in class ShadowLooper
public boolean post(Runnable runnable, long delayMillis)
ShadowLooper
Enqueue a task to be run later.
post
in class ShadowLooper
runnable
- the task to be rundelayMillis
- how many milliseconds into the (virtual) future to run itHandler.postDelayed(Runnable,long)
public boolean postAtFrontOfQueue(Runnable runnable)
ShadowLooper
Enqueue a task to be run ahead of all other delayed tasks.
postAtFrontOfQueue
in class ShadowLooper
runnable
- the task to be runHandler.postAtFrontOfQueue(Runnable)
public void runPaused(Runnable runnable)
ShadowLooper
Runs the current task with the looper paused.
When LooperMode is PAUSED, this will execute all pending tasks scheduled before the current time.
runPaused
in class ShadowLooper
public Duration getNextScheduledTaskTime()
getNextScheduledTaskTime
in class ShadowLooper
public Duration getLastScheduledTaskTime()
getLastScheduledTaskTime
in class ShadowLooper
@Resetter public static void resetLoopers()
@Implementation protected static void prepareMainLooper()
@Implementation protected void quit()
@Implementation(minSdk=18) protected void quitSafely()
public Scheduler getScheduler()
ShadowLooper
Returns the Scheduler
that is being used to manage the enqueued tasks. This scheduler is managed by the Looper’s associated queue.
Only supported for LooperMode.Mode.PAUSED
.
getScheduler
in class ShadowLooper
Scheduler
that is being used to manage the enqueued tasks.