com.github.ignition.support.images.remote
Class RemoteImageLoader

java.lang.Object
  extended by com.github.ignition.support.images.remote.RemoteImageLoader

public class RemoteImageLoader
extends Object

Realizes a background image loader that downloads an image from a URL, optionally backed by a two-level FIFO cache. If the image to be loaded is present in the cache, it is set immediately on the given view. Otherwise, a thread from a thread pool will be used to download the image in the background and set the image on the view as soon as it completes.

Author:
Matthias Kaeppler

Constructor Summary
RemoteImageLoader(android.content.Context context)
           
RemoteImageLoader(android.content.Context context, boolean createCache)
          Creates a new ImageLoader that is backed by an ImageCache.
 
Method Summary
 void clearImageCache()
          Clears the image cache, if it's used.
 ImageCache getImageCache()
          Returns the image cache backing this image loader.
 void loadImage(String imageUrl, android.widget.ImageView imageView)
          Triggers the image loader for the given image and view.
 void loadImage(String imageUrl, android.widget.ImageView imageView, android.graphics.drawable.Drawable dummyDrawable)
          Triggers the image loader for the given image and view.
 void loadImage(String imageUrl, android.widget.ImageView imageView, android.graphics.drawable.Drawable dummyDrawable, RemoteImageLoaderHandler handler)
          Triggers the image loader for the given image and view.
 void loadImage(String imageUrl, android.widget.ImageView imageView, RemoteImageLoaderHandler handler)
          Triggers the image loader for the given image and view.
 void setDefaultBufferSize(int defaultBufferSize)
          If the server you're loading images from does not report file sizes via the Content-Length header, then you can use this method to tell the downloader how much space it should allocate by default when downloading an image into memory.
 void setDownloadFailedDrawable(android.graphics.drawable.Drawable drawable)
           
 void setDownloadInProgressDrawable(android.graphics.drawable.Drawable drawable)
           
 void setImageCache(ImageCache imageCache)
           
 void setMaxDownloadAttempts(int numAttempts)
           
 void setThreadPoolSize(int numThreads)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

RemoteImageLoader

public RemoteImageLoader(android.content.Context context)

RemoteImageLoader

public RemoteImageLoader(android.content.Context context,
                         boolean createCache)
Creates a new ImageLoader that is backed by an ImageCache. The cache will by default cache to the device's external storage, and expire images after 1 day. You can set useCache to false and then supply your own image cache instance via setImageCache(ImageCache) , or fine-tune the default one through getImageCache().

Parameters:
context - the current context
createCache - whether to create a default ImageCache used for caching
Method Detail

setThreadPoolSize

public void setThreadPoolSize(int numThreads)
Parameters:
numThreads - the maximum number of threads that will be started to download images in parallel

setMaxDownloadAttempts

public void setMaxDownloadAttempts(int numAttempts)
Parameters:
numAttempts - how often the image loader should retry the image download if network connection fails

setDefaultBufferSize

public void setDefaultBufferSize(int defaultBufferSize)
If the server you're loading images from does not report file sizes via the Content-Length header, then you can use this method to tell the downloader how much space it should allocate by default when downloading an image into memory.

Parameters:
defaultBufferSize - how big the buffer should be into which the image file is read. This should be big enough to hold the largest image you expect to download

setDownloadInProgressDrawable

public void setDownloadInProgressDrawable(android.graphics.drawable.Drawable drawable)

setDownloadFailedDrawable

public void setDownloadFailedDrawable(android.graphics.drawable.Drawable drawable)

setImageCache

public void setImageCache(ImageCache imageCache)

clearImageCache

public void clearImageCache()
Clears the image cache, if it's used. A good candidate for calling in Application.onLowMemory().


getImageCache

public ImageCache getImageCache()
Returns the image cache backing this image loader.

Returns:
the ImageCache

loadImage

public void loadImage(String imageUrl,
                      android.widget.ImageView imageView)
Triggers the image loader for the given image and view. The image loading will be performed concurrently to the UI main thread, using a fixed size thread pool. The loaded image will be posted back to the given ImageView upon completion. This method will the default RemoteImageLoaderHandler to process the bitmap after downloading it.

Parameters:
imageUrl - the URL of the image to download
imageView - the ImageView which should be updated with the new image

loadImage

public void loadImage(String imageUrl,
                      android.widget.ImageView imageView,
                      android.graphics.drawable.Drawable dummyDrawable)
Triggers the image loader for the given image and view. The image loading will be performed concurrently to the UI main thread, using a fixed size thread pool. The loaded image will be posted back to the given ImageView upon completion. This method will the default RemoteImageLoaderHandler to process the bitmap after downloading it.

Parameters:
imageUrl - the URL of the image to download
imageView - the ImageView which should be updated with the new image
dummyDrawable - the Drawable to be shown while the image is being downloaded.

loadImage

public void loadImage(String imageUrl,
                      android.widget.ImageView imageView,
                      RemoteImageLoaderHandler handler)
Triggers the image loader for the given image and view. The image loading will be performed concurrently to the UI main thread, using a fixed size thread pool. The loaded image will be posted back to the given ImageView upon completion.

Parameters:
imageUrl - the URL of the image to download
imageView - the ImageView which should be updated with the new image
handler - the handler that will process the bitmap after completion

loadImage

public void loadImage(String imageUrl,
                      android.widget.ImageView imageView,
                      android.graphics.drawable.Drawable dummyDrawable,
                      RemoteImageLoaderHandler handler)
Triggers the image loader for the given image and view. The image loading will be performed concurrently to the UI main thread, using a fixed size thread pool. The loaded image will be posted back to the given ImageView upon completion. While waiting, the dummyDrawable is shown.

Parameters:
imageUrl - the URL of the image to download
imageView - the ImageView which should be updated with the new image
dummyDrawable - the Drawable to be shown while the image is being downloaded.
handler - the handler that will process the bitmap after completion


Copyright © 2012. All Rights Reserved.