com.nostra13.universalimageloader.core.imageaware
Class ImageViewAware

java.lang.Object
  extended by com.nostra13.universalimageloader.core.imageaware.ImageViewAware
All Implemented Interfaces:
ImageAware

public class ImageViewAware
extends java.lang.Object
implements ImageAware

Wrapper for Android ImageView. Keeps weak reference of ImageView to prevent memory leaks.

Since:
1.9.0
Author:
Sergey Tarasevich (nostra13[at]gmail[dot]com)

Field Summary
protected  boolean checkActualViewSize
           
protected  java.lang.ref.Reference<android.widget.ImageView> imageViewRef
           
 
Constructor Summary
ImageViewAware(android.widget.ImageView imageView)
          Constructor.
ImageViewAware(android.widget.ImageView imageView, boolean checkActualViewSize)
          Constructor
 
Method Summary
 int getHeight()
          Returns height of image aware view.
 int getId()
          Returns ID of image aware view.
 ViewScaleType getScaleType()
          Returns scale type which is used for scaling image for this image aware view.
 int getWidth()
          Returns width of image aware view.
 android.widget.ImageView getWrappedView()
          Returns wrapped Android View.
 boolean isCollected()
          Returns a flag whether image aware view is collected by GC or whatsoever.
 boolean setImageBitmap(android.graphics.Bitmap bitmap)
          Sets image bitmap into this image aware view.
 boolean setImageDrawable(android.graphics.drawable.Drawable drawable)
          Sets image drawable into this image aware view.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

imageViewRef

protected java.lang.ref.Reference<android.widget.ImageView> imageViewRef

checkActualViewSize

protected boolean checkActualViewSize
Constructor Detail

ImageViewAware

public ImageViewAware(android.widget.ImageView imageView)
Constructor. References ImageViewAware(imageView, true).

Parameters:
imageView - ImageView to work with

ImageViewAware

public ImageViewAware(android.widget.ImageView imageView,
                      boolean checkActualViewSize)
Constructor

Parameters:
imageView - ImageView to work with
checkActualViewSize - true - then getWidth() and getHeight() will check actual size of ImageView. It can cause known issues like this. But it helps to save memory because memory cache keeps bitmaps of actual (less in general) size.

false - then getWidth() and getHeight() will NOT consider actual size of ImageView, just layout parameters.

Method Detail

getWidth

public int getWidth()
Returns width of image aware view. This value is used to define scale size for original image. Can return 0 if width is undefined.
Called on UI thread.

Width is defined by target view parameters, configuration parameters or device display dimensions.
Size computing algorithm:
1) Get the actual drawn getWidth() of the View. If view haven't drawn yet then go to step #2.
2) Get layout_width. If it hasn't exact value then go to step #3.
3) Get maxWidth.

Specified by:
getWidth in interface ImageAware

getHeight

public int getHeight()
Returns height of image aware view. This value is used to define scale size for original image. Can return 0 if height is undefined.
Called on UI thread.

Height is defined by target view parameters, configuration parameters or device display dimensions.
Size computing algorithm:
1) Get the actual drawn getHeight() of the View. If view haven't drawn yet then go to step #2.
2) Get layout_height. If it hasn't exact value then go to step #3.
3) Get maxHeight.

Specified by:
getHeight in interface ImageAware

getScaleType

public ViewScaleType getScaleType()
Description copied from interface: ImageAware
Returns scale type which is used for scaling image for this image aware view.

Specified by:
getScaleType in interface ImageAware

getWrappedView

public android.widget.ImageView getWrappedView()
Description copied from interface: ImageAware
Returns wrapped Android View. Can return null if no view is wrapped.
Called on UI thread.

Specified by:
getWrappedView in interface ImageAware

isCollected

public boolean isCollected()
Description copied from interface: ImageAware
Returns a flag whether image aware view is collected by GC or whatsoever. If so then ImageLoader stop processing of task for this image aware view and fires ImageLoadingListener#onLoadingCancelled(String, View) callback.
May be called on UI thread.

Specified by:
isCollected in interface ImageAware
Returns:
true - if view is collected by GC and ImageLoader should stop processing this image aware view; false - otherwise

getId

public int getId()
Description copied from interface: ImageAware
Returns ID of image aware view. Point of ID is similar to Object's hashCode. This ID should be unique for every image view instance and should be the same for same instances. This ID identifies processing task in ImageLoader so ImageLoader won't process two image aware views with the same ID in one time. When ImageLoader get new task it cancels old task with this ID (if any) and starts new task.

It's reasonable to return hash code of wrapped view (if any) to prevent displaying non-actual images in view because of view re-using.

Specified by:
getId in interface ImageAware

setImageDrawable

public boolean setImageDrawable(android.graphics.drawable.Drawable drawable)
Description copied from interface: ImageAware
Sets image drawable into this image aware view.
Called on UI thread to display drawable in this image aware view for empty Uri, on loading or on loading fail. These drawables can be specified in display options.

Specified by:
setImageDrawable in interface ImageAware
Returns:
true if drawable was set successfully; false - otherwise

setImageBitmap

public boolean setImageBitmap(android.graphics.Bitmap bitmap)
Description copied from interface: ImageAware
Sets image bitmap into this image aware view.
Called on UI thread to display loaded and decoded image Bitmap in this image view aware. Actually it's used only in BitmapDisplayer.

Specified by:
setImageBitmap in interface ImageAware
Returns:
true if bitmap was set successfully; false - otherwise


Copyright © 2011-2013. All Rights Reserved.