ImageManager
public final class ImageManager
This class is used to load images from the network and handles local caching for you.
Summary
Nested types |
|---|
public interface ImageManager.OnImageLoadedListenerListener interface for handling when the image for a particular URI has been loaded. |
Public methods |
|
|---|---|
static ImageManager |
Returns a new ImageManager for loading images from the network. |
void |
Loads an image to display from the given resource ID. |
void |
Loads an image to display from a URI. |
void |
loadImage(ImageManager.OnImageLoadedListener listener, Uri uri)Load an image to display from a URI. |
void |
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. |
void |
loadImage(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. |
Public methods
create
public static ImageManager create(Context context)
Returns a new ImageManager for loading images from the network.
| Parameters | |
|---|---|
Context context |
The context used by the ImageManager. |
| Returns | |
|---|---|
ImageManager |
A new ImageManager. |
loadImage
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 imageView |
The image view to populate with the image. |
int resId |
Resource ID to use for the image. |
loadImage
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.
loadImage
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 | |
|---|---|
ImageManager.OnImageLoadedListener listener |
The listener that is called when the load is complete. |
Uri uri |
URI to load the image data from. |
loadImage
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.
loadImage
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 | |
|---|---|
ImageManager.OnImageLoadedListener listener |
The listener that is called when the load is complete. |
Uri uri |
URI to load the image data from. |
int defaultResId |
Resource ID to use by default for the image. |