本文整理了Java中android.os.Handler.postDelayed()
方法的一些代码示例,展示了Handler.postDelayed()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Handler.postDelayed()
方法的具体详情如下:
包路径:android.os.Handler
类名称:Handler
方法名:postDelayed
暂无
代码示例来源:origin: chrisbanes/PhotoView
private void rotateLoop() {
handler.postDelayed(new Runnable() {
@Override
public void run() {
photo.setRotationBy(1);
rotateLoop();
}
}, 15);
}
}
代码示例来源:origin: google/ExoPlayer
@Override
public boolean postDelayed(Runnable runnable, long delayMs) {
return handler.postDelayed(runnable, delayMs);
}
}
代码示例来源:origin: facebook/stetho
@Override
public void postDelayed(Runnable r, long delayMillis) {
if (!mHandler.postDelayed(r, delayMillis)) {
throw new RuntimeException("Handler.postDelayed() returned false");
}
}
代码示例来源:origin: square/leakcanary
private void postToBackgroundWithDelay(final Retryable retryable, final int failedAttempts) {
long exponentialBackoffFactor = (long) Math.min(Math.pow(2, failedAttempts), maxBackoffFactor);
long delayMillis = initialDelayMillis * exponentialBackoffFactor;
backgroundHandler.postDelayed(new Runnable() {
@Override public void run() {
Retryable.Result result = retryable.run();
if (result == RETRY) {
postWaitForIdle(retryable, failedAttempts + 1);
}
}
}, delayMillis);
}
}
代码示例来源:origin: google/ExoPlayer
private void scheduleManifestRefresh() {
if (!manifest.isLive) {
return;
}
long nextLoadTimestamp = manifestLoadStartTimestamp + MINIMUM_MANIFEST_REFRESH_PERIOD_MS;
long delayUntilNextLoad = Math.max(0, nextLoadTimestamp - SystemClock.elapsedRealtime());
manifestRefreshHandler.postDelayed(this::startLoadingManifest, delayUntilNextLoad);
}
代码示例来源:origin: facebook/stetho
private void setHighlightedViewImpl(@Nullable View view, @Nullable Rect bounds, int color) {
mHandler.removeCallbacks(mHighlightViewOnUiThreadRunnable);
mViewToHighlight.set(view);
mBoundsToHighlight.set(bounds);
mContentColor.set(color);
mHandler.postDelayed(mHighlightViewOnUiThreadRunnable, 100);
}
代码示例来源:origin: facebook/stetho
public void startScreencast(JsonRpcPeer peer, Page.StartScreencastRequest request) {
LogUtil.d("Starting screencast");
mRequest = request;
mHandlerThread = new HandlerThread("Screencast Thread");
mHandlerThread.start();
mPeer = peer;
mIsRunning = true;
mStream = new ByteArrayOutputStream();
mBackgroundHandler = new Handler(mHandlerThread.getLooper());
mMainHandler.postDelayed(mBitmapFetchRunnable, FRAME_DELAY);
}
代码示例来源:origin: CarGuo/GSYVideoPlayer
/**
* 启动十秒的定时器进行 缓存操作
*/
protected void startTimeOutBuffer() {
// 启动定时
Debuger.printfError("startTimeOutBuffer");
mainThreadHandler.postDelayed(mTimeOutRunnable, timeOut);
}
代码示例来源:origin: robolectric/robolectric
@Implementation
protected void postCallbackDelayed(
int callbackType, Runnable action, Object token, long delayMillis) {
handler.postDelayed(action, delayMillis);
}
代码示例来源:origin: ReactiveX/RxAndroid
@Override
public Disposable scheduleDirect(Runnable run, long delay, TimeUnit unit) {
if (run == null) throw new NullPointerException("run == null");
if (unit == null) throw new NullPointerException("unit == null");
run = RxJavaPlugins.onSchedule(run);
ScheduledRunnable scheduled = new ScheduledRunnable(handler, run);
handler.postDelayed(scheduled, unit.toMillis(delay));
return scheduled;
}
代码示例来源:origin: bumptech/glide
@Override
public void run() {
if (allocate()) {
handler.postDelayed(this, getNextDelay());
}
}
代码示例来源:origin: robolectric/robolectric
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Handler h = new Handler();
h.post(r1);
h.postDelayed(r2, 60000);
}
}
代码示例来源:origin: google/ExoPlayer
public void update() {
TaskState[] taskStates = downloadManager.getAllTaskStates();
startForeground(notificationId, getForegroundNotification(taskStates));
notificationDisplayed = true;
if (periodicUpdatesStarted) {
handler.removeCallbacks(this);
handler.postDelayed(this, updateInterval);
}
}
代码示例来源:origin: lipangit/JiaoZiVideoPlayer
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home:
Jzvd.releaseAllVideos();
handler.postDelayed(() -> Jzvd.setMediaInterface(new JZMediaSystem()), 1000);
finish();
break;
}
return super.onOptionsItemSelected(item);
}
代码示例来源:origin: google/ExoPlayer
@Override
public void run() {
Callback callback = getCallback();
callback.onCurrentPositionChanged(this);
callback.onBufferedPositionChanged(this);
handler.postDelayed(this, updatePeriodMs);
}
代码示例来源:origin: bumptech/glide
@Test
public void testPreFillHandlerDoesNotPostIfHasNoBitmapsToAllocate() {
BitmapPreFillRunner handler = getHandler(new HashMap<PreFillType, Integer>());
handler.run();
verify(mainHandler, never()).postDelayed(any(Runnable.class), anyLong());
}
代码示例来源:origin: bumptech/glide
@Test
public void testPreFillHandlerDoesNotPostIfHasBitmapsButIsCancelled() {
PreFillType size = new PreFillType.Builder(1).setConfig(Bitmap.Config.ARGB_8888).build();
Map<PreFillType, Integer> allocationOrder = new HashMap<>();
allocationOrder.put(size, 2);
BitmapPreFillRunner handler = getHandler(allocationOrder);
when(clock.now()).thenReturn(0L).thenReturn(0L).thenReturn(BitmapPreFillRunner.MAX_DURATION_MS);
handler.cancel();
handler.run();
verify(mainHandler, never()).postDelayed(any(Runnable.class), anyLong());
}
代码示例来源:origin: bumptech/glide
@Test
public void testPreFillHandlerPostsIfHasBitmapsToAllocateAfterRunning() {
PreFillType size = new PreFillType.Builder(1).setConfig(Bitmap.Config.ARGB_8888).build();
Map<PreFillType, Integer> allocationOrder = new HashMap<>();
allocationOrder.put(size, 2);
BitmapPreFillRunner handler = getHandler(allocationOrder);
when(clock.now()).thenReturn(0L).thenReturn(0L).thenReturn(BitmapPreFillRunner.MAX_DURATION_MS);
handler.run();
verify(mainHandler).postDelayed(eq(handler), anyLong());
}
代码示例来源:origin: robolectric/robolectric
@Test
public void idleConstantly_runsPostDelayedTasksImmediately() {
ShadowLooper.idleMainLooperConstantly(true);
final boolean[] wasRun = new boolean[]{false};
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
wasRun[0] = true;
}
}, 2000);
assertThat(wasRun[0]).isTrue();
}
代码示例来源:origin: robolectric/robolectric
@Test
public void testPostDelayedThenRunMainLooperOneTask() throws Exception {
new Handler().postDelayed(scratchRunnable, 1);
ShadowLooper.runMainLooperOneTask();
assertThat(scratchRunnable.wasRun).isTrue();
}
内容来源于网络,如有侵权,请联系作者删除!