@Implements(value=android.os.Looper.class, isInAndroidSdk=false) public class ShadowLegacyLooper extends ShadowLooper
The shadow Looper implementation for LooperMode.Mode.LEGACY
.
Robolectric enqueues posted Runnable
s to be run (on this thread) later. Runnable
s that are scheduled to run immediately can be triggered by calling idle()
.
ShadowMessageQueue
ShadowLooper.Picker
Constructor and Description |
---|
ShadowLegacyLooper() |
Modifier and Type | Method and Description |
---|---|
protected void |
__constructor__(boolean quitAllowed) |
Duration |
getLastScheduledTaskTime() |
static Looper |
getLooperForThread(Thread thread) |
protected static Looper |
getMainLooper() |
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 |
idle(long intervalMillis)
Deprecated.
Use
idle(long, TimeUnit) . |
void |
idle(long amount,
TimeUnit unit)
Causes
Runnable s that have been scheduled to run within the next specified amount of time to run while advancing the clock. |
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() |
protected static void |
loop() |
protected static Looper |
myLooper() |
void |
pause()
Pause the looper.
|
boolean |
post(Runnable runnable,
long delayMillis)
Deprecated.
Use a
Handler instance to post to a looper. |
boolean |
postAtFrontOfQueue(Runnable runnable)
Deprecated.
Use a
Handler instance to post to a looper. |
protected void |
quit() |
protected void |
quitSafely() |
void |
quitUnchecked() |
void |
reset()
Causes all enqueued tasks to be discarded, and pause state to be reset
|
void |
resetScheduler()
Only supported for
LooperMode.Mode.PAUSED . |
static void |
resetThreadLoopers() |
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 r)
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, getShadowMainLooper, idleFor, idleMainLooper, idleMainLooper, idleMainLooper, idleMainLooperConstantly, looperMode, pauseLooper, pauseMainLooper, runMainLooperOneTask, runMainLooperToNextTask, runUiThreadTasks, runUiThreadTasksIncludingDelayedTasks, shadowMainLooper, unPauseLooper, unPauseMainLooper
@Resetter public static void resetThreadLoopers()
@Implementation protected void __constructor__(boolean quitAllowed)
@Implementation protected static Looper getMainLooper()
@Implementation protected static Looper myLooper()
@Implementation protected static void loop()
@Implementation protected void quit()
@Implementation(minSdk=18) protected void quitSafely()
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 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
@Deprecated public void idle(long intervalMillis)
idle(long, TimeUnit)
.Causes Runnable
s that have been scheduled to run within the next intervalMillis
milliseconds to run while advancing the scheduler’s clock.
idle
in class ShadowLooper
public void idle(long amount, TimeUnit unit)
ShadowLooper
Causes Runnable
s that have been scheduled to run within the next specified amount of time to run while advancing the clock.
idle
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
@Deprecated public boolean post(Runnable runnable, long delayMillis)
Handler
instance to post to a looper.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)
@Deprecated public boolean postAtFrontOfQueue(Runnable runnable)
Handler
instance to post to a looper.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 pause()
ShadowLooper
Pause the looper.
Has no practical effect for realistic looper, since it is always paused.
pause
in class ShadowLooper
public Duration getNextScheduledTaskTime()
getNextScheduledTaskTime
in class ShadowLooper
public Duration getLastScheduledTaskTime()
getLastScheduledTaskTime
in class ShadowLooper
public void unPause()
ShadowLooper
Not supported for the main Looper in LooperMode.Mode.PAUSED
.
unPause
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()
Causes all enqueued tasks to be discarded, and pause state to be reset
reset
in class ShadowLooper
public Scheduler getScheduler()
Returns the Scheduler
that is being used to manage the enqueued tasks. This scheduler is managed by the Looper’s associated queue.
getScheduler
in class ShadowLooper
Scheduler
that is being used to manage the enqueued tasks.public void runPaused(Runnable r)
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