16
16
package com .nostra13 .universalimageloader .core ;
17
17
18
18
import android .graphics .Bitmap ;
19
- import android .widget .ImageView ;
20
19
import com .nostra13 .universalimageloader .core .assist .ImageLoadingListener ;
21
20
import com .nostra13 .universalimageloader .core .assist .LoadedFrom ;
22
21
import com .nostra13 .universalimageloader .core .display .BitmapDisplayer ;
22
+ import com .nostra13 .universalimageloader .core .imageaware .ImageAware ;
23
23
import com .nostra13 .universalimageloader .utils .L ;
24
24
25
- import java .lang .ref .Reference ;
26
-
27
25
/**
28
- * Displays bitmap in {@link ImageView }. Must be called on UI thread.
26
+ * Displays bitmap in {@link com.nostra13.universalimageloader.core.imageaware.ImageAware }. Must be called on UI thread.
29
27
*
30
28
* @author Sergey Tarasevich (nostra13[at]gmail[dot]com)
31
29
* @see ImageLoadingListener
34
32
*/
35
33
final class DisplayBitmapTask implements Runnable {
36
34
37
- private static final String LOG_DISPLAY_IMAGE_IN_IMAGEVIEW = "Display image in ImageView (loaded from %1$s) [%2$s]" ;
38
- private static final String LOG_TASK_CANCELLED_IMAGEVIEW_REUSED = "ImageView is reused for another image. Task is cancelled. [%s]" ;
39
- private static final String LOG_TASK_CANCELLED_IMAGEVIEW_LOST = "ImageView was collected by GC. Task is cancelled. [%s]" ;
35
+ private static final String LOG_DISPLAY_IMAGE_IN_IMAGEAWARE = "Display image in ImageAware (loaded from %1$s) [%2$s]" ;
36
+ private static final String LOG_TASK_CANCELLED_IMAGEAWARE_REUSED = "ImageAware is reused for another image. Task is cancelled. [%s]" ;
37
+ private static final String LOG_TASK_CANCELLED_IMAGEAWARE_COLLECTED = "ImageAware was collected by GC. Task is cancelled. [%s]" ;
40
38
41
39
private final Bitmap bitmap ;
42
40
private final String imageUri ;
43
- private final Reference < ImageView > imageViewRef ;
41
+ private final ImageAware imageAware ;
44
42
private final String memoryCacheKey ;
45
43
private final BitmapDisplayer displayer ;
46
44
private final ImageLoadingListener listener ;
@@ -49,10 +47,11 @@ final class DisplayBitmapTask implements Runnable {
49
47
50
48
private boolean loggingEnabled ;
51
49
52
- public DisplayBitmapTask (Bitmap bitmap , ImageLoadingInfo imageLoadingInfo , ImageLoaderEngine engine , LoadedFrom loadedFrom ) {
50
+ public DisplayBitmapTask (Bitmap bitmap , ImageLoadingInfo imageLoadingInfo , ImageLoaderEngine engine ,
51
+ LoadedFrom loadedFrom ) {
53
52
this .bitmap = bitmap ;
54
53
imageUri = imageLoadingInfo .uri ;
55
- imageViewRef = imageLoadingInfo .imageViewRef ;
54
+ imageAware = imageLoadingInfo .imageAware ;
56
55
memoryCacheKey = imageLoadingInfo .memoryCacheKey ;
57
56
displayer = imageLoadingInfo .options .getDisplayer ();
58
57
listener = imageLoadingInfo .listener ;
@@ -61,24 +60,23 @@ public DisplayBitmapTask(Bitmap bitmap, ImageLoadingInfo imageLoadingInfo, Image
61
60
}
62
61
63
62
public void run () {
64
- ImageView imageView = imageViewRef .get ();
65
- if (imageView == null ) {
66
- if (loggingEnabled ) L .d (LOG_TASK_CANCELLED_IMAGEVIEW_LOST , memoryCacheKey );
67
- listener .onLoadingCancelled (imageUri , imageView );
68
- } else if (isViewWasReused (imageView )) {
69
- if (loggingEnabled ) L .d (LOG_TASK_CANCELLED_IMAGEVIEW_REUSED , memoryCacheKey );
70
- listener .onLoadingCancelled (imageUri , imageView );
63
+ if (imageAware .isCollected ()) {
64
+ if (loggingEnabled ) L .d (LOG_TASK_CANCELLED_IMAGEAWARE_COLLECTED , memoryCacheKey );
65
+ listener .onLoadingCancelled (imageUri , imageAware .getWrappedView ());
66
+ } else if (isViewWasReused ()) {
67
+ if (loggingEnabled ) L .d (LOG_TASK_CANCELLED_IMAGEAWARE_REUSED , memoryCacheKey );
68
+ listener .onLoadingCancelled (imageUri , imageAware .getWrappedView ());
71
69
} else {
72
- if (loggingEnabled ) L .d (LOG_DISPLAY_IMAGE_IN_IMAGEVIEW , loadedFrom , memoryCacheKey );
73
- Bitmap displayedBitmap = displayer .display (bitmap , imageView , loadedFrom );
74
- listener .onLoadingComplete (imageUri , imageView , displayedBitmap );
75
- engine .cancelDisplayTaskFor (imageView );
70
+ if (loggingEnabled ) L .d (LOG_DISPLAY_IMAGE_IN_IMAGEAWARE , loadedFrom , memoryCacheKey );
71
+ displayer .display (bitmap , imageAware , loadedFrom );
72
+ listener .onLoadingComplete (imageUri , imageAware . getWrappedView (), bitmap );
73
+ engine .cancelDisplayTaskFor (imageAware );
76
74
}
77
75
}
78
76
79
- /** Checks whether memory cache key (image URI) for current ImageView is actual */
80
- private boolean isViewWasReused (ImageView imageView ) {
81
- String currentCacheKey = engine .getLoadingUriForView (imageView );
77
+ /** Checks whether memory cache key (image URI) for current ImageAware is actual */
78
+ private boolean isViewWasReused () {
79
+ String currentCacheKey = engine .getLoadingUriForView (imageAware );
82
80
return !memoryCacheKey .equals (currentCacheKey );
83
81
}
84
82
0 commit comments