/** Check whether the current task was interrupted */ private boolean checkTaskIsInterrupted() { boolean interrupted = Thread.interrupted(); if (interrupted) log(LOG_TASK_INTERRUPTED); return interrupted; }
/** * Check whether the image URI of this task matches to image URI which is actual for current ImageView at this * moment and fire {@link ImageLoadingListener onLoadingCancelled()} event if it doesn't. */ private boolean checkTaskIsNotActual() { String currentCacheKey = engine.getLoadingUriForView(imageView); // Check whether memory cache key (image URI) for current ImageView is actual. // If ImageView is reused for another task then current task should be cancelled. boolean imageViewWasReused = !memoryCacheKey.equals(currentCacheKey); if (imageViewWasReused) { handler.post(new Runnable() { @Override public void run() { listener.onLoadingCancelled(uri, imageView); } }); log(LOG_TASK_CANCELLED); } return imageViewWasReused; }
/** * @return true - if task should be interrupted; false - otherwise */ private boolean waitIfPaused() { AtomicBoolean pause = engine.getPause(); if (pause.get()) { synchronized (pause) { log(LOG_WAITING_FOR_RESUME); try { pause.wait(); } catch (InterruptedException e) { L.e(LOG_TASK_INTERRUPTED, memoryCacheKey); return true; } log(LOG_RESUME_AFTER_PAUSE); } } return checkTaskIsNotActual(); }
/** * @return true - if task should be interrupted; false - otherwise */ private boolean delayIfNeed() { if (options.shouldDelayBeforeLoading()) { log(LOG_DELAY_BEFORE_LOADING, options.getDelayBeforeLoading(), memoryCacheKey); try { Thread.sleep(options.getDelayBeforeLoading()); } catch (InterruptedException e) { L.e(LOG_TASK_INTERRUPTED, memoryCacheKey); return true; } return checkTaskIsNotActual(); } return false; }
log(LOG_START_DISPLAY_IMAGE_TASK); if (loadFromUriLock.isLocked()) { log(LOG_WAITING_FOR_IMAGE_LOADED); log(LOG_PREPROCESS_IMAGE); bmp = options.getPreProcessor().process(bmp); if (bmp == null) { log(LOG_CACHE_IMAGE_IN_MEMORY); configuration.memoryCache.put(memoryCacheKey, bmp); log(LOG_GET_IMAGE_FROM_MEMORY_CACHE_AFTER_WAITING); log(LOG_POSTPROCESS_IMAGE); bmp = options.getPostProcessor().process(bmp); if (bmp == null) {
/** * @return Cached image URI; or original image URI if caching failed */ private String tryCacheImageOnDisc(File targetFile) { log(LOG_CACHE_IMAGE_ON_DISC); try { int width = configuration.maxImageWidthForDiscCache; int height = configuration.maxImageHeightForDiscCache; if (imageLoadingInfo != null && imageLoadingInfo.targetSize != null) { width = imageLoadingInfo.targetSize.getWidth(); height = imageLoadingInfo.targetSize.getHeight(); } boolean saved = false; if (width > 0 || height > 0) { saved = downloadSizedImage(targetFile, width, height); } if (!saved) { downloadImage(targetFile); } configuration.discCache.put(uri, targetFile); return Scheme.FILE.wrap(targetFile.getAbsolutePath()); } catch (IOException e) { L.e(e); return uri; } }