com.nostra13.universalimageloader.core
Class ImageLoader

java.lang.Object
  extended by com.nostra13.universalimageloader.core.ImageLoader

public class ImageLoader
extends Object

Singletone for image loading and displaying at ImageViews
NOTE: init(ImageLoaderConfiguration) method must be called before any other method.

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

Field Summary
static String TAG
           
 
Constructor Summary
protected ImageLoader()
           
 
Method Summary
 void cancelDisplayTask(ImageAware imageAware)
          Cancel the task of loading and displaying image for passed ImageAware.
 void cancelDisplayTask(android.widget.ImageView imageView)
          Cancel the task of loading and displaying image for passed ImageView.
 void clearDiscCache()
          Deprecated. Use clearDiskCache() instead
 void clearDiskCache()
          Clears disk cache.
 void clearMemoryCache()
          Clears memory cache
 void denyNetworkDownloads(boolean denyNetworkDownloads)
          Denies or allows ImageLoader to download images from the network.
 void destroy()
          Stops ImageLoader and clears current configuration.
 void displayImage(String uri, ImageAware imageAware)
          Adds display image task to execution pool.
 void displayImage(String uri, ImageAware imageAware, DisplayImageOptions options)
          Adds display image task to execution pool.
 void displayImage(String uri, ImageAware imageAware, DisplayImageOptions options, ImageLoadingListener listener)
          Adds display image task to execution pool.
 void displayImage(String uri, ImageAware imageAware, DisplayImageOptions options, ImageLoadingListener listener, ImageLoadingProgressListener progressListener)
          Adds display image task to execution pool.
 void displayImage(String uri, ImageAware imageAware, ImageLoadingListener listener)
          Adds display image task to execution pool.
 void displayImage(String uri, android.widget.ImageView imageView)
          Adds display image task to execution pool.
 void displayImage(String uri, android.widget.ImageView imageView, DisplayImageOptions options)
          Adds display image task to execution pool.
 void displayImage(String uri, android.widget.ImageView imageView, DisplayImageOptions options, ImageLoadingListener listener)
          Adds display image task to execution pool.
 void displayImage(String uri, android.widget.ImageView imageView, DisplayImageOptions options, ImageLoadingListener listener, ImageLoadingProgressListener progressListener)
          Adds display image task to execution pool.
 void displayImage(String uri, android.widget.ImageView imageView, ImageLoadingListener listener)
          Adds display image task to execution pool.
 DiskCache getDiscCache()
          Deprecated. Use getDiskCache() instead
 DiskCache getDiskCache()
          Returns disk cache
static ImageLoader getInstance()
          Returns singleton class instance
 String getLoadingUriForView(ImageAware imageAware)
          Returns URI of image which is loading at this moment into passed ImageAware
 String getLoadingUriForView(android.widget.ImageView imageView)
          Returns URI of image which is loading at this moment into passed ImageView
 MemoryCache getMemoryCache()
          Returns memory cache
 void handleSlowNetwork(boolean handleSlowNetwork)
          Sets option whether ImageLoader will use FlushedInputStream for network downloads to handle
 void init(ImageLoaderConfiguration configuration)
          Initializes ImageLoader instance with configuration.
 boolean isInited()
          Returns true - if ImageLoader is initialized with configuration; false - otherwise
 void loadImage(String uri, DisplayImageOptions options, ImageLoadingListener listener)
          Adds load image task to execution pool.
 void loadImage(String uri, ImageLoadingListener listener)
          Adds load image task to execution pool.
 void loadImage(String uri, ImageSize targetImageSize, DisplayImageOptions options, ImageLoadingListener listener)
          Adds load image task to execution pool.
 void loadImage(String uri, ImageSize targetImageSize, DisplayImageOptions options, ImageLoadingListener listener, ImageLoadingProgressListener progressListener)
          Adds load image task to execution pool.
 void loadImage(String uri, ImageSize targetImageSize, ImageLoadingListener listener)
          Adds load image task to execution pool.
 android.graphics.Bitmap loadImageSync(String uri)
          Loads and decodes image synchronously.
 android.graphics.Bitmap loadImageSync(String uri, DisplayImageOptions options)
          Loads and decodes image synchronously.
 android.graphics.Bitmap loadImageSync(String uri, ImageSize targetImageSize)
          Loads and decodes image synchronously.
 android.graphics.Bitmap loadImageSync(String uri, ImageSize targetImageSize, DisplayImageOptions options)
          Loads and decodes image synchronously.
 void pause()
          Pause ImageLoader.
 void resume()
          Resumes waiting "load&display" tasks
 void stop()
          Cancels all running and scheduled display image tasks.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

TAG

public static final String TAG
Constructor Detail

ImageLoader

protected ImageLoader()
Method Detail

getInstance

public static ImageLoader getInstance()
Returns singleton class instance


init

public void init(ImageLoaderConfiguration configuration)
Initializes ImageLoader instance with configuration.
If configurations was set before ( isInited() == true) then this method does nothing.
To force initialization with new configuration you should destroy ImageLoader at first.

Parameters:
configuration - ImageLoader configuration
Throws:
IllegalArgumentException - if configuration parameter is null

isInited

public boolean isInited()
Returns true - if ImageLoader is initialized with configuration; false - otherwise


displayImage

public void displayImage(String uri,
                         ImageAware imageAware)
Adds display image task to execution pool. Image will be set to ImageAware when it's turn.
Default display image options from configuration will be used.
NOTE: init(ImageLoaderConfiguration) method must be called before this method call

Parameters:
uri - Image URI (i.e. "http://site.com/image.png", "file:///mnt/sdcard/image.png")
imageAware - Image aware view which should display image
Throws:
IllegalStateException - if init(ImageLoaderConfiguration) method wasn't called before
IllegalArgumentException - if passed imageAware is null

displayImage

public void displayImage(String uri,
                         ImageAware imageAware,
                         ImageLoadingListener listener)
Adds display image task to execution pool. Image will be set to ImageAware when it's turn.
Default display image options from configuration will be used.
NOTE: init(ImageLoaderConfiguration) method must be called before this method call

Parameters:
uri - Image URI (i.e. "http://site.com/image.png", "file:///mnt/sdcard/image.png")
imageAware - Image aware view which should display image
listener - Listener for image loading process. Listener fires events on UI thread if this method is called on UI thread.
Throws:
IllegalStateException - if init(ImageLoaderConfiguration) method wasn't called before
IllegalArgumentException - if passed imageAware is null

displayImage

public void displayImage(String uri,
                         ImageAware imageAware,
                         DisplayImageOptions options)
Adds display image task to execution pool. Image will be set to ImageAware when it's turn.
NOTE: init(ImageLoaderConfiguration) method must be called before this method call

Parameters:
uri - Image URI (i.e. "http://site.com/image.png", "file:///mnt/sdcard/image.png")
imageAware - Image aware view which should display image
options - Options for image decoding and displaying. If null - default display image options from configuration will be used.
Throws:
IllegalStateException - if init(ImageLoaderConfiguration) method wasn't called before
IllegalArgumentException - if passed imageAware is null

displayImage

public void displayImage(String uri,
                         ImageAware imageAware,
                         DisplayImageOptions options,
                         ImageLoadingListener listener)
Adds display image task to execution pool. Image will be set to ImageAware when it's turn.
NOTE: init(ImageLoaderConfiguration) method must be called before this method call

Parameters:
uri - Image URI (i.e. "http://site.com/image.png", "file:///mnt/sdcard/image.png")
imageAware - Image aware view which should display image
options - Options for image decoding and displaying. If null - default display image options from configuration will be used.
listener - Listener for image loading process. Listener fires events on UI thread if this method is called on UI thread.
Throws:
IllegalStateException - if init(ImageLoaderConfiguration) method wasn't called before
IllegalArgumentException - if passed imageAware is null

displayImage

public void displayImage(String uri,
                         ImageAware imageAware,
                         DisplayImageOptions options,
                         ImageLoadingListener listener,
                         ImageLoadingProgressListener progressListener)
Adds display image task to execution pool. Image will be set to ImageAware when it's turn.
NOTE: init(ImageLoaderConfiguration) method must be called before this method call

Parameters:
uri - Image URI (i.e. "http://site.com/image.png", "file:///mnt/sdcard/image.png")
imageAware - Image aware view which should display image
options - Options for image decoding and displaying. If null - default display image options from configuration will be used.
listener - Listener for image loading process. Listener fires events on UI thread if this method is called on UI thread.
progressListener - Listener for image loading progress. Listener fires events on UI thread if this method is called on UI thread. Caching on disk should be enabled in options to make this listener work.
Throws:
IllegalStateException - if init(ImageLoaderConfiguration) method wasn't called before
IllegalArgumentException - if passed imageAware is null

displayImage

public void displayImage(String uri,
                         android.widget.ImageView imageView)
Adds display image task to execution pool. Image will be set to ImageView when it's turn.
Default display image options from configuration will be used.
NOTE: init(ImageLoaderConfiguration) method must be called before this method call

Parameters:
uri - Image URI (i.e. "http://site.com/image.png", "file:///mnt/sdcard/image.png")
imageView - ImageView which should display image
Throws:
IllegalStateException - if init(ImageLoaderConfiguration) method wasn't called before
IllegalArgumentException - if passed imageView is null

displayImage

public void displayImage(String uri,
                         android.widget.ImageView imageView,
                         DisplayImageOptions options)
Adds display image task to execution pool. Image will be set to ImageView when it's turn.
NOTE: init(ImageLoaderConfiguration) method must be called before this method call

Parameters:
uri - Image URI (i.e. "http://site.com/image.png", "file:///mnt/sdcard/image.png")
imageView - ImageView which should display image
options - Options for image decoding and displaying. If null - default display image options from configuration will be used.
Throws:
IllegalStateException - if init(ImageLoaderConfiguration) method wasn't called before
IllegalArgumentException - if passed imageView is null

displayImage

public void displayImage(String uri,
                         android.widget.ImageView imageView,
                         ImageLoadingListener listener)
Adds display image task to execution pool. Image will be set to ImageView when it's turn.
Default display image options from configuration will be used.
NOTE: init(ImageLoaderConfiguration) method must be called before this method call

Parameters:
uri - Image URI (i.e. "http://site.com/image.png", "file:///mnt/sdcard/image.png")
imageView - ImageView which should display image
listener - Listener for image loading process. Listener fires events on UI thread if this method is called on UI thread.
Throws:
IllegalStateException - if init(ImageLoaderConfiguration) method wasn't called before
IllegalArgumentException - if passed imageView is null

displayImage

public void displayImage(String uri,
                         android.widget.ImageView imageView,
                         DisplayImageOptions options,
                         ImageLoadingListener listener)
Adds display image task to execution pool. Image will be set to ImageView when it's turn.
NOTE: init(ImageLoaderConfiguration) method must be called before this method call

Parameters:
uri - Image URI (i.e. "http://site.com/image.png", "file:///mnt/sdcard/image.png")
imageView - ImageView which should display image
options - Options for image decoding and displaying. If null - default display image options from configuration will be used.
listener - Listener for image loading process. Listener fires events on UI thread if this method is called on UI thread.
Throws:
IllegalStateException - if init(ImageLoaderConfiguration) method wasn't called before
IllegalArgumentException - if passed imageView is null

displayImage

public void displayImage(String uri,
                         android.widget.ImageView imageView,
                         DisplayImageOptions options,
                         ImageLoadingListener listener,
                         ImageLoadingProgressListener progressListener)
Adds display image task to execution pool. Image will be set to ImageView when it's turn.
NOTE: init(ImageLoaderConfiguration) method must be called before this method call

Parameters:
uri - Image URI (i.e. "http://site.com/image.png", "file:///mnt/sdcard/image.png")
imageView - ImageView which should display image
options - Options for image decoding and displaying. If null - default display image options from configuration will be used.
listener - Listener for image loading process. Listener fires events on UI thread if this method is called on UI thread.
progressListener - Listener for image loading progress. Listener fires events on UI thread if this method is called on UI thread. Caching on disk should be enabled in options to make this listener work.
Throws:
IllegalStateException - if init(ImageLoaderConfiguration) method wasn't called before
IllegalArgumentException - if passed imageView is null

loadImage

public void loadImage(String uri,
                      ImageLoadingListener listener)
Adds load image task to execution pool. Image will be returned with ImageLoadingListener.onLoadingComplete(String, android.view.View, android.graphics.Bitmap) callback}.
NOTE: init(ImageLoaderConfiguration) method must be called before this method call

Parameters:
uri - Image URI (i.e. "http://site.com/image.png", "file:///mnt/sdcard/image.png")
listener - Listener for image loading process. Listener fires events on UI thread if this method is called on UI thread.
Throws:
IllegalStateException - if init(ImageLoaderConfiguration) method wasn't called before

loadImage

public void loadImage(String uri,
                      ImageSize targetImageSize,
                      ImageLoadingListener listener)
Adds load image task to execution pool. Image will be returned with ImageLoadingListener.onLoadingComplete(String, android.view.View, android.graphics.Bitmap) callback}.
NOTE: init(ImageLoaderConfiguration) method must be called before this method call

Parameters:
uri - Image URI (i.e. "http://site.com/image.png", "file:///mnt/sdcard/image.png")
targetImageSize - Minimal size for Bitmap which will be returned in ImageLoadingListener.onLoadingComplete(String, android.view.View, android.graphics.Bitmap) callback}. Downloaded image will be decoded and scaled to Bitmap of the size which is equal or larger (usually a bit larger) than incoming targetImageSize.
listener - Listener for image loading process. Listener fires events on UI thread if this method is called on UI thread.
Throws:
IllegalStateException - if init(ImageLoaderConfiguration) method wasn't called before

loadImage

public void loadImage(String uri,
                      DisplayImageOptions options,
                      ImageLoadingListener listener)
Adds load image task to execution pool. Image will be returned with ImageLoadingListener.onLoadingComplete(String, android.view.View, android.graphics.Bitmap) callback}.
NOTE: init(ImageLoaderConfiguration) method must be called before this method call

Parameters:
uri - Image URI (i.e. "http://site.com/image.png", "file:///mnt/sdcard/image.png")
options - Options for image decoding and displaying. If null - default display image options from configuration will be used.
listener - Listener for image loading process. Listener fires events on UI thread if this method is called on UI thread.
Throws:
IllegalStateException - if init(ImageLoaderConfiguration) method wasn't called before

loadImage

public void loadImage(String uri,
                      ImageSize targetImageSize,
                      DisplayImageOptions options,
                      ImageLoadingListener listener)
Adds load image task to execution pool. Image will be returned with ImageLoadingListener.onLoadingComplete(String, android.view.View, android.graphics.Bitmap) callback}.
NOTE: init(ImageLoaderConfiguration) method must be called before this method call

Parameters:
uri - Image URI (i.e. "http://site.com/image.png", "file:///mnt/sdcard/image.png")
targetImageSize - Minimal size for Bitmap which will be returned in ImageLoadingListener.onLoadingComplete(String, android.view.View, android.graphics.Bitmap) callback}. Downloaded image will be decoded and scaled to Bitmap of the size which is equal or larger (usually a bit larger) than incoming targetImageSize.
options - Options for image decoding and displaying. If null - default display image options from configuration will be used.
listener - Listener for image loading process. Listener fires events on UI thread if this method is called on UI thread.
Throws:
IllegalStateException - if init(ImageLoaderConfiguration) method wasn't called before

loadImage

public void loadImage(String uri,
                      ImageSize targetImageSize,
                      DisplayImageOptions options,
                      ImageLoadingListener listener,
                      ImageLoadingProgressListener progressListener)
Adds load image task to execution pool. Image will be returned with ImageLoadingListener.onLoadingComplete(String, android.view.View, android.graphics.Bitmap) callback}.
NOTE: init(ImageLoaderConfiguration) method must be called before this method call

Parameters:
uri - Image URI (i.e. "http://site.com/image.png", "file:///mnt/sdcard/image.png")
targetImageSize - Minimal size for Bitmap which will be returned in ImageLoadingListener.onLoadingComplete(String, android.view.View, android.graphics.Bitmap) callback}. Downloaded image will be decoded and scaled to Bitmap of the size which is equal or larger (usually a bit larger) than incoming targetImageSize.
options - Options for image decoding and displaying. If null - default display image options from configuration will be used.
listener - Listener for image loading process. Listener fires events on UI thread if this method is called on UI thread.
progressListener - Listener for image loading progress. Listener fires events on UI thread if this method is called on UI thread. Caching on disk should be enabled in options to make this listener work.
Throws:
IllegalStateException - if init(ImageLoaderConfiguration) method wasn't called before

loadImageSync

public android.graphics.Bitmap loadImageSync(String uri)
Loads and decodes image synchronously.
Default display image options from configuration will be used.
NOTE: init(ImageLoaderConfiguration) method must be called before this method call

Parameters:
uri - Image URI (i.e. "http://site.com/image.png", "file:///mnt/sdcard/image.png")
Returns:
Result image Bitmap. Can be null if image loading/decoding was failed or cancelled.
Throws:
IllegalStateException - if init(ImageLoaderConfiguration) method wasn't called before

loadImageSync

public android.graphics.Bitmap loadImageSync(String uri,
                                             DisplayImageOptions options)
Loads and decodes image synchronously.
NOTE: init(ImageLoaderConfiguration) method must be called before this method call

Parameters:
uri - Image URI (i.e. "http://site.com/image.png", "file:///mnt/sdcard/image.png")
options - Options for image decoding and scaling. If null - default display image options from configuration will be used.
Returns:
Result image Bitmap. Can be null if image loading/decoding was failed or cancelled.
Throws:
IllegalStateException - if init(ImageLoaderConfiguration) method wasn't called before

loadImageSync

public android.graphics.Bitmap loadImageSync(String uri,
                                             ImageSize targetImageSize)
Loads and decodes image synchronously.
Default display image options from configuration will be used.
NOTE: init(ImageLoaderConfiguration) method must be called before this method call

Parameters:
uri - Image URI (i.e. "http://site.com/image.png", "file:///mnt/sdcard/image.png")
targetImageSize - Minimal size for Bitmap which will be returned. Downloaded image will be decoded and scaled to Bitmap of the size which is equal or larger (usually a bit larger) than incoming targetImageSize.
Returns:
Result image Bitmap. Can be null if image loading/decoding was failed or cancelled.
Throws:
IllegalStateException - if init(ImageLoaderConfiguration) method wasn't called before

loadImageSync

public android.graphics.Bitmap loadImageSync(String uri,
                                             ImageSize targetImageSize,
                                             DisplayImageOptions options)
Loads and decodes image synchronously.
NOTE: init(ImageLoaderConfiguration) method must be called before this method call

Parameters:
uri - Image URI (i.e. "http://site.com/image.png", "file:///mnt/sdcard/image.png")
targetImageSize - Minimal size for Bitmap which will be returned. Downloaded image will be decoded and scaled to Bitmap of the size which is equal or larger (usually a bit larger) than incoming targetImageSize.
options - Options for image decoding and scaling. If null - default display image options from configuration will be used.
Returns:
Result image Bitmap. Can be null if image loading/decoding was failed or cancelled.
Throws:
IllegalStateException - if init(ImageLoaderConfiguration) method wasn't called before

getMemoryCache

public MemoryCache getMemoryCache()
Returns memory cache

Throws:
IllegalStateException - if init(ImageLoaderConfiguration) method wasn't called before

clearMemoryCache

public void clearMemoryCache()
Clears memory cache

Throws:
IllegalStateException - if init(ImageLoaderConfiguration) method wasn't called before

getDiscCache

@Deprecated
public DiskCache getDiscCache()
Deprecated. Use getDiskCache() instead

Returns disk cache

Throws:
IllegalStateException - if init(ImageLoaderConfiguration) method wasn't called before

getDiskCache

public DiskCache getDiskCache()
Returns disk cache

Throws:
IllegalStateException - if init(ImageLoaderConfiguration) method wasn't called before

clearDiscCache

@Deprecated
public void clearDiscCache()
Deprecated. Use clearDiskCache() instead

Clears disk cache.

Throws:
IllegalStateException - if init(ImageLoaderConfiguration) method wasn't called before

clearDiskCache

public void clearDiskCache()
Clears disk cache.

Throws:
IllegalStateException - if init(ImageLoaderConfiguration) method wasn't called before

getLoadingUriForView

public String getLoadingUriForView(ImageAware imageAware)
Returns URI of image which is loading at this moment into passed ImageAware


getLoadingUriForView

public String getLoadingUriForView(android.widget.ImageView imageView)
Returns URI of image which is loading at this moment into passed ImageView


cancelDisplayTask

public void cancelDisplayTask(ImageAware imageAware)
Cancel the task of loading and displaying image for passed ImageAware.

Parameters:
imageAware - ImageAware for which display task will be cancelled

cancelDisplayTask

public void cancelDisplayTask(android.widget.ImageView imageView)
Cancel the task of loading and displaying image for passed ImageView.

Parameters:
imageView - ImageView for which display task will be cancelled

denyNetworkDownloads

public void denyNetworkDownloads(boolean denyNetworkDownloads)
Denies or allows ImageLoader to download images from the network.

If downloads are denied and if image isn't cached then ImageLoadingListener.onLoadingFailed(String, View, FailReason) callback will be fired with FailReason.FailType#NETWORK_DENIED

Parameters:
denyNetworkDownloads - pass true - to deny engine to download images from the network; false - to allow engine to download images from network.

handleSlowNetwork

public void handleSlowNetwork(boolean handleSlowNetwork)
Sets option whether ImageLoader will use FlushedInputStream for network downloads to handle this known problem or not.

Parameters:
handleSlowNetwork - pass true - to use FlushedInputStream for network downloads; false - otherwise.

pause

public void pause()
Pause ImageLoader. All new "load&display" tasks won't be executed until ImageLoader is resumed.
Already running tasks are not paused.


resume

public void resume()
Resumes waiting "load&display" tasks


stop

public void stop()
Cancels all running and scheduled display image tasks.
NOTE: This method doesn't shutdown custom task executors if you set them.
ImageLoader still can be used after calling this method.


destroy

public void destroy()
Stops ImageLoader and clears current configuration.
You can init ImageLoader with new configuration after calling this method.



Copyright © 2011-2014. All Rights Reserved.