public class

AsyncImageView

extends ImageView
implements ImageRequest.ImageRequestCallback
java.lang.Object
   ↳ android.view.View
     ↳ android.widget.ImageView
       ↳ greendroid.widget.AsyncImageView

Class Overview

A AsyncImageView is a network-aware ImageView. It may display images from the web according to a URL. AsyncImageView takes care of loading asynchronously images on the Internet. It also caches images in an application-wide cache to prevent loading images several times.

Clients may listen the AsyncImageView.OnImageViewLoadListener to be notified of the current image loading state.

AsyncImageView may be extremely useful in ListView's row. To prevent your AsyncImageView from downloading while scrolling or flinging it is a good idea to pause it using setPaused(boolean) method. Once the scrolling/flinging is over, un-pause your AsyncImageViews using setPaused(false)

Summary

Nested Classes
interface AsyncImageView.OnImageViewLoadListener Clients may listen to AsyncImageView changes using a AsyncImageView.OnImageViewLoadListener
[Expand]
Inherited Constants
From class android.view.View
Public Constructors
AsyncImageView(Context context)
AsyncImageView(Context context, AttributeSet attrs)
AsyncImageView(Context context, AttributeSet attrs, int defStyle)
Public Methods
boolean isLoaded()
Return true if the displayed image has been correctly loaded.
boolean isLoading()
Return true if this AsyncImageView is currently loading an image.
void onImageRequestCancelled(ImageRequest request)
Callback to be invoked when the request processing has been cancelled.
void onImageRequestEnded(ImageRequest request, Bitmap image)
Callback to be invoked when the request processing ended.
void onImageRequestFailed(ImageRequest request, Throwable throwable)
Callback to be invoked when the request processing failed.
void onImageRequestStarted(ImageRequest request)
Callback to be invoked when the request processing started.
void onRestoreInstanceState(Parcelable state)
Parcelable onSaveInstanceState()
void reload()
Reload the image pointed by the given URL
void reload(boolean force)
Reload the image pointed by the given URL.
void setDefaultImageBitmap(Bitmap bitmap)
Set the default bitmap as the content of this AsyncImageView
void setDefaultImageDrawable(Drawable drawable)
Set the default drawable as the content of this AsyncImageView
void setDefaultImageResource(int resId)
Set the default resource as the content of this AsyncImageView
void setImageProcessor(ImageProcessor imageProcessor)
Set an image processor to this AsyncImageView.
void setInDensity(int inDensity)
Helper to setOptions(Options) that simply sets the inDensity for loaded image.
void setOnImageViewLoadListener(AsyncImageView.OnImageViewLoadListener listener)
Register a callback to be invoked when an event occured for this AsyncImageView.
void setOptions(BitmapFactory.Options options)
Assign an Options object to this AsyncImageView.
void setPaused(boolean paused)
Pause this AsyncImageView preventing it from downloading the image.
void setUrl(String url)
Set the url of the image that will be used as the content of this AsyncImageView.
void stopLoading()
Force the loading to be stopped.
[Expand]
Inherited Methods
From class android.widget.ImageView
From class android.view.View
From class java.lang.Object
From interface android.graphics.drawable.Drawable.Callback
From interface android.view.KeyEvent.Callback
From interface android.view.accessibility.AccessibilityEventSource
From interface greendroid.image.ImageRequest.ImageRequestCallback

Public Constructors

public AsyncImageView (Context context)

public AsyncImageView (Context context, AttributeSet attrs)

public AsyncImageView (Context context, AttributeSet attrs, int defStyle)

Public Methods

public boolean isLoaded ()

Return true if the displayed image has been correctly loaded.

Returns
  • true if this AsyncImageView succeed to load the image at the given url.

public boolean isLoading ()

Return true if this AsyncImageView is currently loading an image.

Returns
  • true if this AsyncImageView is currently loading an image. Otherwise it returns false.

public void onImageRequestCancelled (ImageRequest request)

Callback to be invoked when the request processing has been cancelled.

Parameters
request ImageRequest that has been cancelled

public void onImageRequestEnded (ImageRequest request, Bitmap image)

Callback to be invoked when the request processing ended.

Parameters
request ImageRequest that ended
image The resulting Bitmap

public void onImageRequestFailed (ImageRequest request, Throwable throwable)

Callback to be invoked when the request processing failed.

Parameters
request ImageRequest that failed
throwable The Throwable that occurs

public void onImageRequestStarted (ImageRequest request)

Callback to be invoked when the request processing started.

Parameters
request The ImageRequest that started

public void onRestoreInstanceState (Parcelable state)

public Parcelable onSaveInstanceState ()

public void reload ()

Reload the image pointed by the given URL

public void reload (boolean force)

Reload the image pointed by the given URL. You may want to force reloading by setting the force parameter to true.

Parameters
force if true the AsyncImageView won't look into the application-wide cache.

public void setDefaultImageBitmap (Bitmap bitmap)

Set the default bitmap as the content of this AsyncImageView

Parameters
bitmap The bitmap to set

public void setDefaultImageDrawable (Drawable drawable)

Set the default drawable as the content of this AsyncImageView

Parameters
drawable The drawable to set

public void setDefaultImageResource (int resId)

Set the default resource as the content of this AsyncImageView

Parameters
resId The resource identifier to set

public void setImageProcessor (ImageProcessor imageProcessor)

Set an image processor to this AsyncImageView. An ImageProcessor may be used in order to work on the retrieved Bitmap prior displaying it on screen.

Parameters
imageProcessor The ImageProcessor to set
See Also

public void setInDensity (int inDensity)

Helper to setOptions(Options) that simply sets the inDensity for loaded image.

public void setOnImageViewLoadListener (AsyncImageView.OnImageViewLoadListener listener)

Register a callback to be invoked when an event occured for this AsyncImageView.

Parameters
listener The listener that will be notified

public void setOptions (BitmapFactory.Options options)

Assign an Options object to this AsyncImageView. Those options are used internally by the AsyncImageView when decoding the image. This may be used to prevent the default behavior that loads all images as mdpi density.

public void setPaused (boolean paused)

Pause this AsyncImageView preventing it from downloading the image. The download process will start back once setPaused(false) is called.

public void setUrl (String url)

Set the url of the image that will be used as the content of this AsyncImageView. The given may be null in order to display the default image. Please note the url may be a local url. For instance, you can asynchronously load images from the disk memory is the url scheme is file://

Parameters
url The url of the image to set. Pass null to force the AsyncImageView to display the default image

public void stopLoading ()

Force the loading to be stopped.