Java 类android.os.MessageQueue.IdleHandler 实例源码
项目:GitHub
文件:EngineTest.java
@Test
public void load_afterResourceIsGcedFromActive_returnsFromMemoryCache() {
when(harness.resource.getResource()).thenReturn(mock(Resource.class));
when(harness.resource.isCacheable()).thenReturn(true);
harness.cache = new LruResourceCache(100);
doAnswer(new Answer<Object>() {
@Override
public Object answer(InvocationOnMock invocationOnMock) throws Throwable {
harness.getEngine().onEngineJobComplete(harness.cacheKey, harness.resource);
return null;
}
}).when(harness.job).start(any(DecodeJob.class));
harness.doLoad();
ArgumentCaptor<IdleHandler> captor = ArgumentCaptor.forClass(IdleHandler.class);
verify(GlideShadowLooper.queue).addIdleHandler(captor.capture());
captor.getValue().queueIdle();
harness.doLoad();
verify(harness.cb).onResourceReady(any(Resource.class), eq(DataSource.MEMORY_CACHE));
}
项目:boohee_v5.6
文件:AndroidHeapDumper.java
private void showToast(final FutureResult<Toast> waitingForToast) {
this.mainHandler.post(new Runnable() {
public void run() {
final Toast toast = new Toast(AndroidHeapDumper.this.context);
toast.setGravity(16, 0, 0);
toast.setDuration(1);
toast.setView(LayoutInflater.from(AndroidHeapDumper.this.context).inflate(R
.layout.__leak_canary_heap_dump_toast, null));
toast.show();
Looper.myQueue().addIdleHandler(new IdleHandler() {
public boolean queueIdle() {
waitingForToast.set(toast);
return false;
}
});
}
});
}
项目:prevo
文件:PreferenceActivity.java
private void queueUpdatePreference ()
{
if (!queuedUpdate)
{
Looper.myQueue ().addIdleHandler (new IdleHandler ()
{
public boolean queueIdle ()
{
updatePreference ();
queuedUpdate = false;
/* Remove the handler */
return false;
}
});
queuedUpdate = true;
}
}
项目:boohee_v5.6
文件:AndroidWatchExecutor.java
private void executeDelayedAfterIdleUnsafe(final Runnable runnable) {
Looper.myQueue().addIdleHandler(new IdleHandler() {
public boolean queueIdle() {
AndroidWatchExecutor.this.backgroundHandler.postDelayed(runnable, 5000);
return false;
}
});
}
项目:boohee_v5.6
文件:SampleLoadReporter.java
public void onLoadResult(File patchDirectory, int loadCode, long cost) {
super.onLoadResult(patchDirectory, loadCode, cost);
switch (loadCode) {
case 0:
SampleTinkerReport.onLoaded(cost);
break;
}
Looper.getMainLooper();
Looper.myQueue().addIdleHandler(new IdleHandler() {
public boolean queueIdle() {
UpgradePatchRetry.getInstance(SampleLoadReporter.this.context).onPatchRetryLoad();
return false;
}
});
}
项目:ACDD
文件:Coordinator.java
public static void scheduleIdleTasks() {
Looper.myQueue().addIdleHandler(new IdleHandler() {
@Override
public boolean queueIdle() {
TaggedRunnable taggedRunnable = Coordinator.mIdleTasks
.poll();
if (taggedRunnable == null) {
return false;
}
Coordinator.postTask(taggedRunnable);
return !Coordinator.mIdleTasks.isEmpty();
}
});
}
项目:android-test-kit
文件:LooperIdlingResource.java
@Override
public void registerIdleTransitionCallback(ResourceCallback resourceCallback) {
this.resourceCallback = resourceCallback;
// on main thread here.
queueInterrogator = new QueueInterrogator(monitoredLooper);
// must load idle handlers from monitored looper thread.
IdleHandler idleHandler = new ResourceCallbackIdleHandler(resourceCallback, queueInterrogator,
monitoredHandler);
checkState(monitoredHandler.postAtFrontOfQueue(new Initializer(idleHandler)),
"Monitored looper exiting.");
}
项目:android-test-kit
文件:LooperIdlingResource.java
Initializer(IdleHandler myIdleHandler) {
this.myIdleHandler = checkNotNull(myIdleHandler);
}