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