com.herroworld.imagegrabber
Class ImageWorker

java.lang.Object
  extended by com.herroworld.imagegrabber.ImageWorker
Direct Known Subclasses:
ImageResizer

public abstract class ImageWorker
extends java.lang.Object

This class wraps up completing some arbitrary long running work when loading a bitmap to an ImageView. It handles things like using a memory and disk cache, running the work in a background thread and setting a placeholder image. It also allows forcing a network response to refresh the disk cache.


Method Summary
static void cancelWork(ImageView imageView)
           
 ImageCache getImageCache()
          Get the ImageCache object for reuse.
 void loadImage(java.lang.Object data, ImageView imageView)
          Load an image specified by the data parameter into an ImageView (override ImageWorker#processBitmap(Object) to define the processing logic).
 void setAlwaysFetchFromServer(boolean fetch)
          If set to true, image will be returned from cache if available and simultaneously re-fetch the image from network if it has changed since the last time.
 void setExitTasksEarly(boolean exitTasksEarly)
          If set to true, all intermediate tasks will be cancelled.
 void setFadeInTime(int fadeInTime)
          Set the fade in time when bitmap is loaded into the image view.
 void setImageCache(ImageCache cacheCallback)
          Set the ImageCache object to use with this ImageWorker.
 void setImageFadeIn(boolean fadeIn)
          If set to true, the image will fade-in once it has been loaded by the background thread.
 void setLoadingImage(Bitmap bitmap)
          Set placeholder bitmap that shows when the the background thread is running.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

setFadeInTime

public void setFadeInTime(int fadeInTime)
Set the fade in time when bitmap is loaded into the image view.

Parameters:
fadeInTime - Fade in time in milliseconds

loadImage

public void loadImage(java.lang.Object data,
                      ImageView imageView)
Load an image specified by the data parameter into an ImageView (override ImageWorker#processBitmap(Object) to define the processing logic). A memory and disk cache will be used if an ImageCache has been set using setImageCache(ImageCache). If the image is found in the memory cache, it is set immediately, otherwise an AsyncTask will be created to asynchronously load the bitmap.

Parameters:
data - The URL of the image to download.
imageView - The ImageView to bind the downloaded image to.

setLoadingImage

public void setLoadingImage(Bitmap bitmap)
Set placeholder bitmap that shows when the the background thread is running.

Parameters:
bitmap -

setImageCache

public void setImageCache(ImageCache cacheCallback)
Set the ImageCache object to use with this ImageWorker.

Parameters:
cacheCallback -

getImageCache

public ImageCache getImageCache()
Get the ImageCache object for reuse.

Returns:
The ImageCache object

setImageFadeIn

public void setImageFadeIn(boolean fadeIn)
If set to true, the image will fade-in once it has been loaded by the background thread.

Parameters:
fadeIn -

setAlwaysFetchFromServer

public void setAlwaysFetchFromServer(boolean fetch)
If set to true, image will be returned from cache if available and simultaneously re-fetch the image from network if it has changed since the last time.

Parameters:
fetch -

setExitTasksEarly

public void setExitTasksEarly(boolean exitTasksEarly)
If set to true, all intermediate tasks will be cancelled.

Parameters:
exitTasksEarly -

cancelWork

public static void cancelWork(ImageView imageView)