public final class

ImageManager

extends Object
java.lang.Object
   ↳ com.google.android.gms.common.images.ImageManager

Class Overview

This class is used to load images from the network and handles local caching for you.

Summary

Nested Classes
interface ImageManager.OnImageLoadedListener Listener interface for handling when the image for a particular URI has been loaded. 
Public Methods
static ImageManager create(Context context)
Returns a new ImageManager for loading images from the network.
void loadImage(ImageView imageView, Uri uri)
Loads an image to display from a URI.
void loadImage(ImageView imageView, int resId)
Loads an image to display from the given resource ID.
void loadImage(ImageManager.OnImageLoadedListener listener, Uri uri, int defaultResId)
Load an image to display from a URI, using the given resource ID as the default if no image is found for the given URI.
void loadImage(ImageManager.OnImageLoadedListener listener, Uri uri)
Load an image to display from a URI.
void loadImage(ImageView imageView, Uri uri, int defaultResId)
Loads an image to display from a URI, using the given resource ID as the default if no image is found for the given URI.
[Expand]
Inherited Methods
From class java.lang.Object

Public Methods

public static ImageManager create (Context context)

Returns a new ImageManager for loading images from the network.

Parameters
context The context used by the ImageManager.
Returns
  • A new ImageManager.

public void loadImage (ImageView imageView, Uri uri)

Loads an image to display from a URI. Note that this does not support arbitrary URIs - the URI must be something that was retrieved from another call to Google Play services.

The image view will be cleared out (the drawable set to null) if the image needs to be loaded asynchronously.

The result (if non-null) is set on the given image view on the main thread.

Note that if the ImageView used for this call is hosted in a ListAdapter (or any other class that recycles ImageView instances), then ALL calls to set the contents of that ImageView must be done via one of the calls on this ImageManager.

Parameters
imageView The image view to populate with the image.
uri URI to load the image data from.

public void loadImage (ImageView imageView, int resId)

Loads an image to display from the given resource ID.

If you also use ImageManagers for Views hosted in a ListAdapter (or any other class that recycles Views instances), then this call should be used rather than setting the resource directly. This avoids clobbering images when views are recycled.

Parameters
imageView The image view to populate with the image.
resId Resource ID to use for the image.

public void loadImage (ImageManager.OnImageLoadedListener listener, Uri uri, int defaultResId)

Load an image to display from a URI, using the given resource ID as the default if no image is found for the given URI. Note that this does not support arbitrary URIs - the URI must be something that was retrieved from another call to Google Play services.

Note that you should hold a reference to the listener provided until the callback is complete. For this reason, the use of anonymous implementations is discouraged.

The result is delivered to the given listener on the main thread.

If a result is not found, the image view will be set to the given default resource if the image needs to be loaded asynchronously.

Parameters
listener The listener that is called when the load is complete.
uri URI to load the image data from.
defaultResId Resource ID to use by default for the image.

public void loadImage (ImageManager.OnImageLoadedListener listener, Uri uri)

Load an image to display from a URI. Note that this does not support arbitrary URIs - the URI must be something that was retrieved from another call to Google Play services.

Note that you should hold a reference to the listener provided until the callback is complete. For this reason, the use of anonymous implementations is discouraged.

The result is delivered to the given listener on the main thread.

Parameters
listener The listener that is called when the load is complete.
uri URI to load the image data from.

public void loadImage (ImageView imageView, Uri uri, int defaultResId)

Loads an image to display from a URI, using the given resource ID as the default if no image is found for the given URI. Note that this does not support arbitrary URIs - the URI must be something that was retrieved from another call to Google Play services.

The image view will be set to the given default resource if the image needs to be loaded asynchronously.

The result (if non-null) is set on the given image view on the main thread.

Note that if the ImageView used for this call is hosted in a ListAdapter (or any other class that recycles ImageView instances), then ALL calls to set the contents of that ImageView must be done via one of the calls on this ImageManager.

Parameters
imageView The image view to populate with the image.
uri URI to load the image data from.
defaultResId Resource ID to use by default for the image.