17
17
18
18
import android .graphics .Bitmap ;
19
19
import android .os .Handler ;
20
-
21
20
import com .nostra13 .universalimageloader .core .assist .FailReason ;
22
21
import com .nostra13 .universalimageloader .core .assist .FailReason .FailType ;
23
- import com .nostra13 .universalimageloader .core .listener .ImageLoadingListener ;
24
- import com .nostra13 .universalimageloader .core .listener .ImageLoadingProgressListener ;
25
22
import com .nostra13 .universalimageloader .core .assist .ImageScaleType ;
26
23
import com .nostra13 .universalimageloader .core .assist .ImageSize ;
27
24
import com .nostra13 .universalimageloader .core .assist .LoadedFrom ;
31
28
import com .nostra13 .universalimageloader .core .download .ImageDownloader ;
32
29
import com .nostra13 .universalimageloader .core .download .ImageDownloader .Scheme ;
33
30
import com .nostra13 .universalimageloader .core .imageaware .ImageAware ;
31
+ import com .nostra13 .universalimageloader .core .listener .ImageLoadingListener ;
32
+ import com .nostra13 .universalimageloader .core .listener .ImageLoadingProgressListener ;
34
33
import com .nostra13 .universalimageloader .utils .IoUtils ;
35
34
import com .nostra13 .universalimageloader .utils .L ;
36
35
@@ -83,7 +82,6 @@ final class LoadAndDisplayImageTask implements Runnable, IoUtils.CopyListener {
83
82
private final ImageDownloader networkDeniedDownloader ;
84
83
private final ImageDownloader slowNetworkDownloader ;
85
84
private final ImageDecoder decoder ;
86
- private final boolean writeLogs ;
87
85
final String uri ;
88
86
private final String memoryCacheKey ;
89
87
final ImageAware imageAware ;
@@ -106,7 +104,6 @@ public LoadAndDisplayImageTask(ImageLoaderEngine engine, ImageLoadingInfo imageL
106
104
networkDeniedDownloader = configuration .networkDeniedDownloader ;
107
105
slowNetworkDownloader = configuration .slowNetworkDownloader ;
108
106
decoder = configuration .decoder ;
109
- writeLogs = configuration .writeLogs ;
110
107
uri = imageLoadingInfo .uri ;
111
108
memoryCacheKey = imageLoadingInfo .memoryCacheKey ;
112
109
imageAware = imageLoadingInfo .imageAware ;
@@ -123,9 +120,9 @@ public void run() {
123
120
if (delayIfNeed ()) return ;
124
121
125
122
ReentrantLock loadFromUriLock = imageLoadingInfo .loadFromUriLock ;
126
- log (LOG_START_DISPLAY_IMAGE_TASK );
123
+ L . d (LOG_START_DISPLAY_IMAGE_TASK , memoryCacheKey );
127
124
if (loadFromUriLock .isLocked ()) {
128
- log (LOG_WAITING_FOR_IMAGE_LOADED );
125
+ L . d (LOG_WAITING_FOR_IMAGE_LOADED , memoryCacheKey );
129
126
}
130
127
131
128
loadFromUriLock .lock ();
@@ -142,24 +139,24 @@ public void run() {
142
139
checkTaskInterrupted ();
143
140
144
141
if (options .shouldPreProcess ()) {
145
- log (LOG_PREPROCESS_IMAGE );
142
+ L . d (LOG_PREPROCESS_IMAGE , memoryCacheKey );
146
143
bmp = options .getPreProcessor ().process (bmp );
147
144
if (bmp == null ) {
148
145
L .e (ERROR_PRE_PROCESSOR_NULL , memoryCacheKey );
149
146
}
150
147
}
151
148
152
149
if (bmp != null && options .isCacheInMemory ()) {
153
- log (LOG_CACHE_IMAGE_IN_MEMORY );
150
+ L . d (LOG_CACHE_IMAGE_IN_MEMORY , memoryCacheKey );
154
151
configuration .memoryCache .put (memoryCacheKey , bmp );
155
152
}
156
153
} else {
157
154
loadedFrom = LoadedFrom .MEMORY_CACHE ;
158
- log (LOG_GET_IMAGE_FROM_MEMORY_CACHE_AFTER_WAITING );
155
+ L . d (LOG_GET_IMAGE_FROM_MEMORY_CACHE_AFTER_WAITING , memoryCacheKey );
159
156
}
160
157
161
158
if (bmp != null && options .shouldPostProcess ()) {
162
- log (LOG_POSTPROCESS_IMAGE );
159
+ L . d (LOG_POSTPROCESS_IMAGE , memoryCacheKey );
163
160
bmp = options .getPostProcessor ().process (bmp );
164
161
if (bmp == null ) {
165
162
L .e (ERROR_POST_PROCESSOR_NULL , memoryCacheKey );
@@ -175,7 +172,6 @@ public void run() {
175
172
}
176
173
177
174
DisplayBitmapTask displayBitmapTask = new DisplayBitmapTask (bmp , imageLoadingInfo , engine , loadedFrom );
178
- displayBitmapTask .setLoggingEnabled (writeLogs );
179
175
runTask (displayBitmapTask , syncLoading , handler , engine );
180
176
}
181
177
@@ -185,14 +181,14 @@ private boolean waitIfPaused() {
185
181
if (pause .get ()) {
186
182
synchronized (engine .getPauseLock ()) {
187
183
if (pause .get ()) {
188
- log (LOG_WAITING_FOR_RESUME );
184
+ L . d (LOG_WAITING_FOR_RESUME , memoryCacheKey );
189
185
try {
190
186
engine .getPauseLock ().wait ();
191
187
} catch (InterruptedException e ) {
192
188
L .e (LOG_TASK_INTERRUPTED , memoryCacheKey );
193
189
return true ;
194
190
}
195
- log (LOG_RESUME_AFTER_PAUSE );
191
+ L . d (LOG_RESUME_AFTER_PAUSE , memoryCacheKey );
196
192
}
197
193
}
198
194
}
@@ -202,7 +198,7 @@ private boolean waitIfPaused() {
202
198
/** @return <b>true</b> - if task should be interrupted; <b>false</b> - otherwise */
203
199
private boolean delayIfNeed () {
204
200
if (options .shouldDelayBeforeLoading ()) {
205
- log (LOG_DELAY_BEFORE_LOADING , options .getDelayBeforeLoading (), memoryCacheKey );
201
+ L . d (LOG_DELAY_BEFORE_LOADING , options .getDelayBeforeLoading (), memoryCacheKey );
206
202
try {
207
203
Thread .sleep (options .getDelayBeforeLoading ());
208
204
} catch (InterruptedException e ) {
@@ -219,14 +215,14 @@ private Bitmap tryLoadBitmap() throws TaskCancelledException {
219
215
try {
220
216
File imageFile = configuration .diskCache .get (uri );
221
217
if (imageFile != null && imageFile .exists ()) {
222
- log (LOG_LOAD_IMAGE_FROM_DISK_CACHE );
218
+ L . d (LOG_LOAD_IMAGE_FROM_DISK_CACHE , memoryCacheKey );
223
219
loadedFrom = LoadedFrom .DISC_CACHE ;
224
220
225
221
checkTaskNotActual ();
226
222
bitmap = decodeImage (Scheme .FILE .wrap (imageFile .getAbsolutePath ()));
227
223
}
228
224
if (bitmap == null || bitmap .getWidth () <= 0 || bitmap .getHeight () <= 0 ) {
229
- log (LOG_LOAD_IMAGE_FROM_NETWORK );
225
+ L . d (LOG_LOAD_IMAGE_FROM_NETWORK , memoryCacheKey );
230
226
loadedFrom = LoadedFrom .NETWORK ;
231
227
232
228
String imageUriForDecoding = uri ;
@@ -270,7 +266,7 @@ private Bitmap decodeImage(String imageUri) throws IOException {
270
266
271
267
/** @return <b>true</b> - if image was downloaded successfully; <b>false</b> - otherwise */
272
268
private boolean tryCacheImageOnDisk () throws TaskCancelledException {
273
- log (LOG_CACHE_IMAGE_ON_DISK );
269
+ L . d (LOG_CACHE_IMAGE_ON_DISK , memoryCacheKey );
274
270
275
271
boolean loaded ;
276
272
try {
@@ -279,7 +275,7 @@ private boolean tryCacheImageOnDisk() throws TaskCancelledException {
279
275
int width = configuration .maxImageWidthForDiskCache ;
280
276
int height = configuration .maxImageHeightForDiskCache ;
281
277
if (width > 0 || height > 0 ) {
282
- log (LOG_RESIZE_CACHED_IMAGE_FILE );
278
+ L . d (LOG_RESIZE_CACHED_IMAGE_FILE , memoryCacheKey );
283
279
resizeAndSaveImage (width , height ); // TODO : process boolean result
284
280
}
285
281
}
@@ -309,7 +305,7 @@ private boolean resizeAndSaveImage(int maxWidth, int maxHeight) throws IOExcepti
309
305
getDownloader (), specialOptions );
310
306
Bitmap bmp = decoder .decode (decodingInfo );
311
307
if (bmp != null && configuration .processorForDiskCache != null ) {
312
- log (LOG_PROCESS_IMAGE_BEFORE_CACHE_ON_DISK );
308
+ L . d (LOG_PROCESS_IMAGE_BEFORE_CACHE_ON_DISK , memoryCacheKey );
313
309
bmp = configuration .processorForDiskCache .process (bmp );
314
310
if (bmp == null ) {
315
311
L .e (ERROR_PROCESSOR_FOR_DISK_CACHE_NULL , memoryCacheKey );
@@ -408,7 +404,7 @@ private void checkViewCollected() throws TaskCancelledException {
408
404
/** @return <b>true</b> - if target ImageAware is collected by GC; <b>false</b> - otherwise */
409
405
private boolean isViewCollected () {
410
406
if (imageAware .isCollected ()) {
411
- log (LOG_TASK_CANCELLED_IMAGEAWARE_COLLECTED );
407
+ L . d (LOG_TASK_CANCELLED_IMAGEAWARE_COLLECTED , memoryCacheKey );
412
408
return true ;
413
409
}
414
410
return false ;
@@ -428,7 +424,7 @@ private boolean isViewReused() {
428
424
// If ImageAware is reused for another task then current task should be cancelled.
429
425
boolean imageAwareWasReused = !memoryCacheKey .equals (currentCacheKey );
430
426
if (imageAwareWasReused ) {
431
- log (LOG_TASK_CANCELLED_IMAGEAWARE_REUSED );
427
+ L . d (LOG_TASK_CANCELLED_IMAGEAWARE_REUSED , memoryCacheKey );
432
428
return true ;
433
429
}
434
430
return false ;
@@ -444,7 +440,7 @@ private void checkTaskInterrupted() throws TaskCancelledException {
444
440
/** @return <b>true</b> - if current task was interrupted; <b>false</b> - otherwise */
445
441
private boolean isTaskInterrupted () {
446
442
if (Thread .interrupted ()) {
447
- log (LOG_TASK_INTERRUPTED );
443
+ L . d (LOG_TASK_INTERRUPTED , memoryCacheKey );
448
444
return true ;
449
445
}
450
446
return false ;
@@ -454,14 +450,6 @@ String getLoadingUri() {
454
450
return uri ;
455
451
}
456
452
457
- private void log (String message ) {
458
- if (writeLogs ) L .d (message , memoryCacheKey );
459
- }
460
-
461
- private void log (String message , Object ... args ) {
462
- if (writeLogs ) L .d (message , args );
463
- }
464
-
465
453
static void runTask (Runnable r , boolean sync , Handler handler , ImageLoaderEngine engine ) {
466
454
if (sync ) {
467
455
r .run ();
0 commit comments