// main thread public boolean addTarget(final ImageConsumer imageHolder) { if (future.isCancelled()) { return false; } // we should start a new task imageHolder.onStart(this, request.url); synchronized (targets) { if (result != null) { imagesManager.setResultImage(imageHolder, result, false); imageHolder.onFinish(request.url, result); } else if (error != null) { imageHolder.onError(request.url, error); } else { imageHolder.currentLoader = this; targets.add(imageHolder); } } return true; }
// main thread public void removeTarget(final ImageConsumer consumer) { if (imagesManager.debug) { Log.d(TAG, "Cancel request: " + request.getKey() + "\nLoader: " + this); } consumer.onCancel(request.url); synchronized (targets) { targets.remove(consumer); if (targets.isEmpty()) { if (!future.cancel(true)) { if (imagesManager.debug) { Log.d(TAG, "Can't cancel task so let's try to remove loader manually"); } imagesManager.currentLoads.remove(request.getKey(), this); } } } }
private void post(final Runnable action) { ImageConsumer consumer = findMainTarget(); if (consumer != null) { consumer.post(action); } }