本文整理了Java中org.robolectric.util.Scheduler.postDelayed()
方法的一些代码示例,展示了Scheduler.postDelayed()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Scheduler.postDelayed()
方法的具体详情如下:
包路径:org.robolectric.util.Scheduler
类名称:Scheduler
方法名:postDelayed
[英]Add a runnable to the queue to be run after a delay.
[中]向要在延迟后运行的队列添加runnable。
代码示例来源:origin: robolectric/robolectric
/**
* Add a runnable to the queue.
*
* @param runnable Runnable to add.
*/
public synchronized void post(Runnable runnable) {
postDelayed(runnable, 0, TimeUnit.MILLISECONDS);
}
代码示例来源:origin: robolectric/robolectric
/**
* Add a runnable to the queue to be run after a delay.
*
* @param runnable Runnable to add.
* @param delayMillis Delay in millis.
*/
public synchronized void postDelayed(Runnable runnable, long delayMillis) {
postDelayed(runnable, delayMillis, TimeUnit.MILLISECONDS);
}
代码示例来源:origin: robolectric/robolectric
/**
* Enqueue a task to be run later.
*
* @param runnable the task to be run
* @param delayMillis how many milliseconds into the (virtual) future to run it
* @return true if the runnable is enqueued
* @see android.os.Handler#postDelayed(Runnable,long)
* @deprecated Use a {@link android.os.Handler} instance to post to a looper.
*/
@Deprecated
public boolean post(Runnable runnable, long delayMillis) {
if (!quit) {
getScheduler().postDelayed(runnable, delayMillis, TimeUnit.MILLISECONDS);
return true;
} else {
return false;
}
}
代码示例来源:origin: robolectric/robolectric
@Override
public void run() {
transcript.add("one");
scheduler.postDelayed(new Runnable() {
@Override
public void run() {
transcript.add("two");
scheduler.postDelayed(new AddToTranscript("three"), 1000);
}
}, 1000);
}
}, 1000);
代码示例来源:origin: robolectric/robolectric
@Override
public void run() {
order.add(1);
scheduler.postDelayed(new Runnable() {
@Override
public void run() {
order.add(3);
}
}, 1);
order.add(2);
}
}, 0);
代码示例来源:origin: robolectric/robolectric
@Override
public void run() {
order.add(1);
scheduler.postDelayed(new Runnable() {
@Override
public void run() {
order.add(3);
}
}, 1);
order.add(2);
}
}, 0);
代码示例来源:origin: robolectric/robolectric
@Implementation
protected void postInvalidateDelayed(long delayMilliseconds) {
ShadowApplication.getInstance().getForegroundThreadScheduler().postDelayed(new Runnable() {
@Override
public void run() {
realView.invalidate();
}
}, delayMilliseconds);
}
代码示例来源:origin: robolectric/robolectric
@Implementation
protected boolean postDelayed(Runnable action, long delayMills) {
ShadowApplication.getInstance().getForegroundThreadScheduler().postDelayed(action, delayMills);
return true;
}
代码示例来源:origin: robolectric/robolectric
@Implementation
protected void startScroll(int startX, int startY, int dx, int dy, int duration) {
this.startX = startX;
this.startY = startY;
finalX = startX + dx;
finalY = startY + dy;
startTime = getScheduler().getCurrentTime();
this.duration = duration;
started = true;
// post a task so that the scheduler will actually run
getScheduler().postDelayed(new Runnable() {
@Override
public void run() {
// do nothing
}
}, duration);
}
代码示例来源:origin: robolectric/robolectric
@Test
public void advanceBy_returnsTrueIffSomeJobWasRun() throws Exception {
scheduler.postDelayed(new AddToTranscript("one"), 0);
scheduler.postDelayed(new AddToTranscript("two"), 0);
scheduler.postDelayed(new AddToTranscript("three"), 1000);
assertThat(scheduler.advanceBy(0)).isTrue();
assertThat(transcript).containsExactly("one", "two");
transcript.clear();
assertThat(scheduler.advanceBy(0)).isFalse();
assertThat(transcript).isEmpty();
assertThat(scheduler.advanceBy(1000)).isTrue();
assertThat(transcript).containsExactly("three");
}
代码示例来源:origin: robolectric/robolectric
@Test
public void unPause_shouldRunPendingTasks() {
scheduler.postDelayed(new AddToTranscript("one"), 0);
scheduler.postDelayed(new AddToTranscript("two"), 0);
scheduler.postDelayed(new AddToTranscript("three"), 1000);
assertThat(transcript).isEmpty();
final long time = scheduler.getCurrentTime();
scheduler.unPause();
assertThat(transcript).containsExactly("one", "two");
assertThat(scheduler.getCurrentTime()).named("time").isEqualTo(time);
}
代码示例来源:origin: robolectric/robolectric
@Test
public void setIdleStateToUnPause_shouldRunPendingTasks() {
scheduler.postDelayed(new AddToTranscript("one"), 0);
scheduler.postDelayed(new AddToTranscript("two"), 0);
scheduler.postDelayed(new AddToTranscript("three"), 1000);
assertThat(transcript).isEmpty();
final long time = scheduler.getCurrentTime();
scheduler.setIdleState(UNPAUSED);
assertThat(transcript).containsExactly("one", "two");
assertThat(scheduler.getCurrentTime()).named("time").isEqualTo(time);
}
代码示例来源:origin: robolectric/robolectric
@Test
public void setIdleStateToConstantIdle_shouldRunAllTasks() {
scheduler.postDelayed(new AddToTranscript("one"), 0);
scheduler.postDelayed(new AddToTranscript("two"), 0);
scheduler.postDelayed(new AddToTranscript("three"), 1000);
assertThat(transcript).isEmpty();
final long time = scheduler.getCurrentTime();
scheduler.setIdleState(CONSTANT_IDLE);
assertThat(transcript).containsExactly("one", "two", "three");
assertThat(scheduler.getCurrentTime()).named("time").isEqualTo(time + 1000);
}
代码示例来源:origin: robolectric/robolectric
@Test
@SuppressWarnings("deprecation")
public void idleConstantlyTrue_shouldRunAllTasks() {
scheduler.postDelayed(new AddToTranscript("one"), 0);
scheduler.postDelayed(new AddToTranscript("two"), 0);
scheduler.postDelayed(new AddToTranscript("three"), 1000);
assertThat(transcript).isEmpty();
final long time = scheduler.getCurrentTime();
scheduler.idleConstantly(true);
assertThat(transcript).containsExactly("one", "two", "three");
assertThat(scheduler.getCurrentTime()).named("time").isEqualTo(time + 1000);
}
代码示例来源:origin: robolectric/robolectric
@Test
public void postDelayed_whileIdlingConstantly_executesImmediately() {
scheduler.setIdleState(CONSTANT_IDLE);
scheduler.postDelayed(new AddToTranscript("one"), 1000);
assertThat(transcript).containsExactly("one");
}
代码示例来源:origin: robolectric/robolectric
@Test
public void postDelayed_addsAJobToBeRunInTheFuture() throws Exception {
scheduler.postDelayed(new AddToTranscript("one"), 1000);
scheduler.postDelayed(new AddToTranscript("two"), 2000);
scheduler.postDelayed(new AddToTranscript("three"), 3000);
scheduler.advanceBy(1000);
assertThat(transcript).containsExactly("one");
transcript.clear();
scheduler.advanceBy(500);
assertThat(transcript).isEmpty();
scheduler.advanceBy(501);
assertThat(transcript).containsExactly("two");
transcript.clear();
scheduler.advanceBy(999);
assertThat(transcript).containsExactly("three");
}
代码示例来源:origin: robolectric/robolectric
@Implementation
protected void startScroll(int startX, int startY, int dx, int dy, int duration) {
this.startX = startX;
this.startY = startY;
finalX = startX + dx;
finalY = startY + dy;
startTime = ShadowApplication.getInstance().getForegroundThreadScheduler().getCurrentTime();
this.duration = duration;
started = true;
// enque a dummy task so that the scheduler will actually run
ShadowApplication.getInstance().getForegroundThreadScheduler().postDelayed(new Runnable() {
@Override
public void run() {
// do nothing
}
}, duration);
}
代码示例来源:origin: robolectric/robolectric
@Test
public void postDelayed_whileIdlingConstantly_advancesTime() {
scheduler.setIdleState(CONSTANT_IDLE);
scheduler.postDelayed(new AddToTranscript("one"), 1000);
assertThat(scheduler.getCurrentTime()).isEqualTo(1000 + startTime);
}
代码示例来源:origin: robolectric/robolectric
@Test
public void testTimeNotChangedByNegativeDelay() throws Exception {
long currentTime = scheduler.getCurrentTime();
long[] observedTime = new long[1];
scheduler.postDelayed(
new Runnable() {
@Override
public void run() {
observedTime[0] = scheduler.getCurrentTime();
}
},
-1000);
scheduler.advanceToLastPostedRunnable();
assertThat(observedTime[0]).isEqualTo(currentTime);
assertThat(scheduler.getCurrentTime()).isEqualTo(currentTime);
}
代码示例来源:origin: robolectric/robolectric
@Test
public void nestedPost_whileUnpaused_automaticallyExecutes3After() {
final List<Integer> order = new ArrayList<>();
scheduler.unPause();
scheduler.postDelayed(new Runnable() {
@Override
public void run() {
order.add(1);
scheduler.post(new Runnable() {
@Override
public void run() {
order.add(3);
}
});
order.add(2);
}
}, 0);
assertThat(order).named("order").containsExactly(1, 2, 3);
assertThat(scheduler.size()).named("size").isEqualTo(0);
}
内容来源于网络,如有侵权,请联系作者删除!