@@ -66,11 +66,13 @@ final class LoadAndDisplayImageTask implements Runnable {
66
66
private static final String LOG_POSTPROCESS_IMAGE = "PostProcess image before displaying [%s]" ;
67
67
private static final String LOG_CACHE_IMAGE_IN_MEMORY = "Cache image in memory [%s]" ;
68
68
private static final String LOG_CACHE_IMAGE_ON_DISC = "Cache image on disc [%s]" ;
69
+ private static final String LOG_PROCESS_IMAGE_BEFORE_CACHE_ON_DISC = "Process image before cache on disc [%s]" ;
69
70
private static final String LOG_TASK_CANCELLED = "ImageView is reused for another image. Task is cancelled. [%s]" ;
70
71
private static final String LOG_TASK_INTERRUPTED = "Task was interrupted [%s]" ;
71
72
72
- private static final String WARNING_PRE_PROCESSOR_NULL = "Pre-processor returned null [%s]" ;
73
- private static final String WARNING_POST_PROCESSOR_NULL = "Pre-processor returned null [%s]" ;
73
+ private static final String ERROR_PRE_PROCESSOR_NULL = "Pre-processor returned null [%s]" ;
74
+ private static final String ERROR_POST_PROCESSOR_NULL = "Pre-processor returned null [%s]" ;
75
+ private static final String ERROR_PROCESSOR_FOR_DISC_CACHE_NULL = "Bitmap processor for disc cache returned null [%s]" ;
74
76
75
77
private static final int BUFFER_SIZE = 8 * 1024 ; // 8 Kb
76
78
@@ -132,15 +134,15 @@ public void run() {
132
134
bmp = configuration .memoryCache .get (memoryCacheKey );
133
135
if (bmp == null ) {
134
136
bmp = tryLoadBitmap ();
135
- if (bmp == null ) return ;
137
+ if (bmp == null ) return ; // listener callback already was fired
136
138
137
139
if (checkTaskIsNotActual () || checkTaskIsInterrupted ()) return ;
138
140
139
141
if (options .shouldPreProcess ()) {
140
142
log (LOG_PREPROCESS_IMAGE );
141
143
bmp = options .getPreProcessor ().process (bmp );
142
144
if (bmp == null ) {
143
- L .w ( WARNING_PRE_PROCESSOR_NULL );
145
+ L .e ( ERROR_PRE_PROCESSOR_NULL );
144
146
}
145
147
}
146
148
@@ -157,7 +159,7 @@ public void run() {
157
159
log (LOG_POSTPROCESS_IMAGE );
158
160
bmp = options .getPostProcessor ().process (bmp );
159
161
if (bmp == null ) {
160
- L .w ( WARNING_POST_PROCESSOR_NULL , memoryCacheKey );
162
+ L .e ( ERROR_POST_PROCESSOR_NULL , memoryCacheKey );
161
163
}
162
164
}
163
165
} finally {
@@ -210,7 +212,7 @@ private boolean delayIfNeed() {
210
212
211
213
/**
212
214
* Check whether the image URI of this task matches to image URI which is actual for current ImageView at this
213
- * moment and fire {@link ImageLoadingListener#onLoadingCancelled() } event if it doesn't.
215
+ * moment and fire {@link ImageLoadingListener#onLoadingCancelled(String, android.view.View)} } event if it doesn't.
214
216
*/
215
217
private boolean checkTaskIsNotActual () {
216
218
String currentCacheKey = engine .getLoadingUriForView (imageView );
@@ -328,18 +330,25 @@ private boolean downloadSizedImage(File targetFile, int maxWidth, int maxHeight)
328
330
DisplayImageOptions specialOptions = new DisplayImageOptions .Builder ().cloneFrom (options ).imageScaleType (ImageScaleType .IN_SAMPLE_INT ).build ();
329
331
ImageDecodingInfo decodingInfo = new ImageDecodingInfo (memoryCacheKey , uri , targetImageSize , ViewScaleType .FIT_INSIDE , getDownloader (), specialOptions );
330
332
Bitmap bmp = decoder .decode (decodingInfo );
331
- boolean savedSuccessfully = false ;
332
- if (bmp != null ) {
333
- OutputStream os = new BufferedOutputStream (new FileOutputStream (targetFile ), BUFFER_SIZE );
334
- try {
335
- savedSuccessfully = bmp .compress (configuration .imageCompressFormatForDiscCache , configuration .imageQualityForDiscCache , os );
336
- } finally {
337
- IoUtils .closeSilently (os );
338
- }
339
- if (savedSuccessfully ) {
340
- bmp .recycle ();
333
+ if (bmp == null ) return false ;
334
+
335
+ if (configuration .processorForDiscCache != null ) {
336
+ log (LOG_PROCESS_IMAGE_BEFORE_CACHE_ON_DISC );
337
+ bmp = configuration .processorForDiscCache .process (bmp );
338
+ if (bmp == null ) {
339
+ L .e (ERROR_PROCESSOR_FOR_DISC_CACHE_NULL , memoryCacheKey );
340
+ return false ;
341
341
}
342
342
}
343
+
344
+ OutputStream os = new BufferedOutputStream (new FileOutputStream (targetFile ), BUFFER_SIZE );
345
+ boolean savedSuccessfully ;
346
+ try {
347
+ savedSuccessfully = bmp .compress (configuration .imageCompressFormatForDiscCache , configuration .imageQualityForDiscCache , os );
348
+ } finally {
349
+ IoUtils .closeSilently (os );
350
+ }
351
+ bmp .recycle ();
343
352
return savedSuccessfully ;
344
353
}
345
354
0 commit comments