@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)); }
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; } }); } }); }
private void queueUpdatePreference () { if (!queuedUpdate) { Looper.myQueue ().addIdleHandler (new IdleHandler () { public boolean queueIdle () { updatePreference (); queuedUpdate = false; /* Remove the handler */ return false; } }); queuedUpdate = true; } }
private void executeDelayedAfterIdleUnsafe(final Runnable runnable) { Looper.myQueue().addIdleHandler(new IdleHandler() { public boolean queueIdle() { AndroidWatchExecutor.this.backgroundHandler.postDelayed(runnable, 5000); return false; } }); }
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; } }); }
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(); } }); }
@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."); }
Initializer(IdleHandler myIdleHandler) { this.myIdleHandler = checkNotNull(myIdleHandler); }