public class

ImageRequestBuilder

extends Object
java.lang.Object
   ↳ com.facebook.imagepipeline.request.ImageRequestBuilder

Class Overview

Builder class for ImageRequests.

Summary

Nested Classes
class ImageRequestBuilder.BuilderException An exception class for builder methods. 
Public Methods
ImageRequest build()
Builds the Request.
ImageRequestBuilder disableDiskCache()
Disables disk cache for this request, regardless where the image will come from.
static ImageRequestBuilder fromRequest(ImageRequest imageRequest)
Creates a new request builder instance with the same parameters as the imageRequest passed in.
BytesRange getBytesRange()
Gets the range of bytes if set, null otherwise.
ImageRequest.CacheChoice getCacheChoice()
Gets the cache choice (profile image or default).
ImageDecodeOptions getImageDecodeOptions()
ImageRequest.RequestLevel getLowestPermittedRequestLevel()
Gets the lowest permitted request level.
MediaVariations getMediaVariations()
Postprocessor getPostprocessor()
Gets postprocessor if set, null otherwise.
RequestListener getRequestListener()
Priority getRequestPriority()
Returns the request priority.
ResizeOptions getResizeOptions()
Gets the resize options if set, null otherwise.
RotationOptions getRotationOptions()
Gets the rotation options if set, null otherwise.
Uri getSourceUri()
Gets the source Uri.
boolean isDiskCacheEnabled()
Returns whether the use of the disk cache is enabled, which is partly dependent on the URI.
boolean isLocalThumbnailPreviewsEnabled()
Returns whether the use of local thumbnails for previews is enabled.
boolean isProgressiveRenderingEnabled()
Returns whether progressive loading is enabled.
static ImageRequestBuilder newBuilderWithResourceId(int resId)
Creates a new request builder instance for a local resource image.
static ImageRequestBuilder newBuilderWithSource(Uri uri)
Creates a new request builder instance.
ImageRequestBuilder setAutoRotateEnabled(boolean enabled)
This method is deprecated. Use #setRotationOptions(RotationOptions)
ImageRequestBuilder setBytesRange(BytesRange bytesRange)
Set the range of bytes to request from the network (in the case of an HTTP request).
ImageRequestBuilder setCacheChoice(ImageRequest.CacheChoice cacheChoice)
Sets the cache option.
ImageRequestBuilder setImageDecodeOptions(ImageDecodeOptions imageDecodeOptions)
ImageRequestBuilder setLocalThumbnailPreviewsEnabled(boolean enabled)
Enables or disables the use of local thumbnails as previews.
ImageRequestBuilder setLowestPermittedRequestLevel(ImageRequest.RequestLevel requestLevel)
Sets the lowest level that is permitted to request the image from.
ImageRequestBuilder setMediaVariations(MediaVariations mediaVariations)
Sets details of variations of the piece of media which might allow the request to be satisfied (either as a placeholder or ultimate result) by a cached image at another size.
ImageRequestBuilder setMediaVariationsForMediaId(String mediaId)
Sets a media ID for variations of the piece of media which might allow the request to be satisfied (either as a placeholder or ultimate result) by a cached image at another size.
ImageRequestBuilder setPostprocessor(Postprocessor postprocessor)
Sets the postprocessor.
ImageRequestBuilder setProgressiveRenderingEnabled(boolean enabled)
Enables or disables progressive rendering.
ImageRequestBuilder setRequestListener(RequestListener requestListener)
Sets a request listener to use for just this image request
ImageRequestBuilder setRequestPriority(Priority requestPriority)
Set priority for the request.
ImageRequestBuilder setResizeOptions(ResizeOptions resizeOptions)
Sets resize options in case resize should be performed.
ImageRequestBuilder setRotationOptions(RotationOptions rotationOptions)
Sets rotation options for the image, whether to rotate by a multiple of 90 degrees, use the EXIF metadata (relevant to JPEGs only) or to not rotate.
ImageRequestBuilder setSource(Uri uri)
Sets the source uri (both network and local uris are supported).
Protected Methods
void validate()
Performs validation.
[Expand]
Inherited Methods
From class java.lang.Object

Public Methods

public ImageRequest build ()

Builds the Request.

Returns
  • a valid image request

public ImageRequestBuilder disableDiskCache ()

Disables disk cache for this request, regardless where the image will come from.

public static ImageRequestBuilder fromRequest (ImageRequest imageRequest)

Creates a new request builder instance with the same parameters as the imageRequest passed in.

Parameters
imageRequest the ImageRequest from where to copy the parameters to the builder.
Returns
  • a new request builder instance

public BytesRange getBytesRange ()

Gets the range of bytes if set, null otherwise.

public ImageRequest.CacheChoice getCacheChoice ()

Gets the cache choice (profile image or default).

public ImageDecodeOptions getImageDecodeOptions ()

public ImageRequest.RequestLevel getLowestPermittedRequestLevel ()

Gets the lowest permitted request level.

public MediaVariations getMediaVariations ()

public Postprocessor getPostprocessor ()

Gets postprocessor if set, null otherwise.

public RequestListener getRequestListener ()

Returns
  • the additional request listener to use for this image request

public Priority getRequestPriority ()

Returns the request priority.

public ResizeOptions getResizeOptions ()

Gets the resize options if set, null otherwise.

public RotationOptions getRotationOptions ()

Gets the rotation options if set, null otherwise.

public Uri getSourceUri ()

Gets the source Uri.

public boolean isDiskCacheEnabled ()

Returns whether the use of the disk cache is enabled, which is partly dependent on the URI.

public boolean isLocalThumbnailPreviewsEnabled ()

Returns whether the use of local thumbnails for previews is enabled.

public boolean isProgressiveRenderingEnabled ()

Returns whether progressive loading is enabled.

public static ImageRequestBuilder newBuilderWithResourceId (int resId)

Creates a new request builder instance for a local resource image.

Only image resources can be used with the image pipeline (PNG, JPG, GIF). Other resource types such as Strings or XML Drawables make no sense in the context of the image pipeline and so cannot be supported. Attempts to do so will throw an java.lang.IllegalArgumentException when the pipeline tries to decode the resource.

One potentially confusing case is drawable declared in XML (e.g. ShapeDrawable). This is not an image. If you want to display an XML drawable as the main image, then set it as a placeholder and do not set a URI.

Parameters
resId local image resource id.
Returns
  • a new request builder instance.

public static ImageRequestBuilder newBuilderWithSource (Uri uri)

Creates a new request builder instance. The setting will be done according to the source type.

Parameters
uri the uri to fetch
Returns
  • a new request builder instance

public ImageRequestBuilder setAutoRotateEnabled (boolean enabled)

This method is deprecated.
Use #setRotationOptions(RotationOptions)

Enables or disables auto-rotate for the image in case image has orientation.

Returns
  • the updated builder instance

public ImageRequestBuilder setBytesRange (BytesRange bytesRange)

Set the range of bytes to request from the network (in the case of an HTTP request). This is only used if isPartialImageCachingEnabled() is true and your NetworkFetcher makes use of it.

Even where this is supported, there is no contract that this must be followed. The response may contain the full image data, more than is requested or less, depending on what's already in cache and external factors.

Parameters
bytesRange the range of bytes
Returns
  • the modified builder instance

public ImageRequestBuilder setCacheChoice (ImageRequest.CacheChoice cacheChoice)

Sets the cache option. Pipeline might use different caches and eviction policies for each image type.

Parameters
cacheChoice the cache choice to set
Returns
  • the modified builder instance

public ImageRequestBuilder setImageDecodeOptions (ImageDecodeOptions imageDecodeOptions)

public ImageRequestBuilder setLocalThumbnailPreviewsEnabled (boolean enabled)

Enables or disables the use of local thumbnails as previews.

Returns
  • the modified builder instance

public ImageRequestBuilder setLowestPermittedRequestLevel (ImageRequest.RequestLevel requestLevel)

Sets the lowest level that is permitted to request the image from.

Parameters
requestLevel the lowest request level that is allowed
Returns
  • the updated builder instance

public ImageRequestBuilder setMediaVariations (MediaVariations mediaVariations)

Sets details of variations of the piece of media which might allow the request to be satisfied (either as a placeholder or ultimate result) by a cached image at another size.

Experimental. This is now functional but the behaviour is still being tested.

Parameters
mediaVariations the variations of image which relate to the same original media
Returns
  • the updated builder instance

public ImageRequestBuilder setMediaVariationsForMediaId (String mediaId)

Sets a media ID for variations of the piece of media which might allow the request to be satisfied (either as a placeholder or ultimate result) by a cached image at another size.

Experimental. This is now functional but the behaviour is still being tested.

Parameters
mediaId the unique ID for this piece of media. This must be non-null and unique for this piece of media (i.e. another request for the same picture at a different size should share the ID but not an unrelated image and not the same media at a different orientation).
Returns
  • the updated builder instance

public ImageRequestBuilder setPostprocessor (Postprocessor postprocessor)

Sets the postprocessor.

Parameters
postprocessor postprocessor to postprocess the output bitmap with.
Returns
  • the modified builder instance

public ImageRequestBuilder setProgressiveRenderingEnabled (boolean enabled)

Enables or disables progressive rendering.

Returns
  • the modified builder instance

public ImageRequestBuilder setRequestListener (RequestListener requestListener)

Sets a request listener to use for just this image request

Parameters
requestListener a request listener to use in addition to the global ones set in the ImagePipelineConfig
Returns
  • the modified builder instance

public ImageRequestBuilder setRequestPriority (Priority requestPriority)

Set priority for the request.

Returns
  • the modified builder instance

public ImageRequestBuilder setResizeOptions (ResizeOptions resizeOptions)

Sets resize options in case resize should be performed.

Parameters
resizeOptions resize options
Returns
  • the modified builder instance

public ImageRequestBuilder setRotationOptions (RotationOptions rotationOptions)

Sets rotation options for the image, whether to rotate by a multiple of 90 degrees, use the EXIF metadata (relevant to JPEGs only) or to not rotate. This also specifies whether the rotation should be left until the bitmap is rendered (as the GPU can do this more efficiently than the effort to change the bitmap object).

Parameters
rotationOptions rotation options
Returns
  • the modified builder instance

public ImageRequestBuilder setSource (Uri uri)

Sets the source uri (both network and local uris are supported). Note: this will enable disk caching for network sources, and disable it for local sources.

Parameters
uri the uri to fetch the image from
Returns
  • the updated builder instance

Protected Methods

protected void validate ()

Performs validation.