ImageManager

class ImageManager


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

Summary

Nested types

Listener interface for handling when the image for a particular URI has been loaded.

Public functions

java-static ImageManager!
create(context: Context!)

Returns a new ImageManager for loading images from the network.

Unit
loadImage(imageView: ImageView!, resId: Int)

Loads an image to display from the given resource ID.

Unit
loadImage(imageView: ImageView!, uri: Uri!)

Loads an image to display from a URI.

Unit

Load an image to display from a URI.

Unit
loadImage(imageView: ImageView!, uri: Uri!, defaultResId: Int)

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.

Unit
loadImage(
    listener: ImageManager.OnImageLoadedListener!,
    uri: Uri!,
    defaultResId: Int
)

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 functions

create

java-static fun create(context: Context!): ImageManager!

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

fun loadImage(imageView: ImageView!, resId: Int): Unit

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.

resId: Int

Resource ID to use for the image.

loadImage

fun loadImage(imageView: ImageView!, uri: Uri!): Unit

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: ImageView!

The image view to populate with the image.

uri: Uri!

URI to load the image data from.

loadImage

fun loadImage(listener: ImageManager.OnImageLoadedListener!, uri: Uri!): Unit

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: ImageManager.OnImageLoadedListener!

The listener that is called when the load is complete.

uri: Uri!

URI to load the image data from.

loadImage

fun loadImage(imageView: ImageView!, uri: Uri!, defaultResId: Int): Unit

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: ImageView!

The image view to populate with the image.

uri: Uri!

URI to load the image data from.

defaultResId: Int

Resource ID to use by default for the image.

loadImage

fun loadImage(
    listener: ImageManager.OnImageLoadedListener!,
    uri: Uri!,
    defaultResId: Int
): Unit

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: ImageManager.OnImageLoadedListener!

The listener that is called when the load is complete.

uri: Uri!

URI to load the image data from.

defaultResId: Int

Resource ID to use by default for the image.