com.nostra13.universalimageloader.core.imageaware
Class ViewAware

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

public abstract class ViewAware
extends Object
implements ImageAware

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

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

Field Summary
protected  boolean checkActualViewSize
           
protected  Reference<android.view.View> viewRef
           
static String WARN_CANT_SET_BITMAP
           
static String WARN_CANT_SET_DRAWABLE
           
 
Constructor Summary
ViewAware(android.view.View view)
          Constructor.
ViewAware(android.view.View view, 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.view.View 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.
protected abstract  void setImageBitmapInto(android.graphics.Bitmap bitmap, android.view.View view)
          Should set Bitmap into incoming view.
 boolean setImageDrawable(android.graphics.drawable.Drawable drawable)
          Sets image drawable into this image aware view.
protected abstract  void setImageDrawableInto(android.graphics.drawable.Drawable drawable, android.view.View view)
          Should set drawable into incoming view.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

WARN_CANT_SET_DRAWABLE

public static final String WARN_CANT_SET_DRAWABLE
See Also:
Constant Field Values

WARN_CANT_SET_BITMAP

public static final String WARN_CANT_SET_BITMAP
See Also:
Constant Field Values

viewRef

protected Reference<android.view.View> viewRef

checkActualViewSize

protected boolean checkActualViewSize
Constructor Detail

ViewAware

public ViewAware(android.view.View view)
Constructor.
References ImageViewAware(imageView, true).

Parameters:
view - View to work with

ViewAware

public ViewAware(android.view.View view,
                 boolean checkActualViewSize)
Constructor

Parameters:
view - View to work with
checkActualViewSize - true - then getWidth() and getHeight() will check actual size of View. 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 View, just layout parameters.
If you set 'false' it's recommended 'android:layout_width' and 'android:layout_height' (or 'android:maxWidth' and 'android:maxHeight') are set with concrete values. It helps to save memory.

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.
Is called on UI thread if ImageLoader was called on UI thread. Otherwise - on background thread.

Width is defined by target view parameters, configuration parameters or device display dimensions.
Size computing algorithm (go by steps until get non-zero value):
1) Get the actual drawn getWidth() of the View
2) Get layout_width

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.
Is called on UI thread if ImageLoader was called on UI thread. Otherwise - on background thread.

Height is defined by target view parameters, configuration parameters or device display dimensions.
Size computing algorithm (go by steps until get non-zero value):
1) Get the actual drawn getHeight() of the View
2) Get layout_height

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. Must NOT return null.

Specified by:
getScaleType in interface ImageAware

getWrappedView

public android.view.View getWrappedView()
Description copied from interface: ImageAware
Returns wrapped Android View. Can return null if no view is wrapped or view was collected by GC.
Is called on UI thread if ImageLoader was called on UI thread. Otherwise - on background 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.
Mey be called on UI thread if ImageLoader was called on UI thread. Otherwise - on background 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.
Displays drawable in this image aware view for empty Uri, on loading or on loading fail. These drawables can be specified in display options.
Also can be called in BitmapDisplayer.< br /> Is called on UI thread if ImageLoader was called on UI thread. Otherwise - on background thread.

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.
Displays loaded and decoded image Bitmap in this image view aware. Actually it's used only in BitmapDisplayer.< br /> Is called on UI thread if ImageLoader was called on UI thread. Otherwise - on background thread.

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

setImageDrawableInto

protected abstract void setImageDrawableInto(android.graphics.drawable.Drawable drawable,
                                             android.view.View view)
Should set drawable into incoming view. Incoming view is guaranteed not null.
This method is called on UI thread.


setImageBitmapInto

protected abstract void setImageBitmapInto(android.graphics.Bitmap bitmap,
                                           android.view.View view)
Should set Bitmap into incoming view. Incoming view is guaranteed not null.< br /> This method is called on UI thread.



Copyright © 2011-2014. All Rights Reserved.