public class

MediaVariations

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

Class Overview

An optional part of image requests which describes the piece of media being requested.

This allows for the provision of a number of image variants which are identical in content but at different resolutions. This way if the image at the source URI isn't already cached an appropriate fallback may be used instead.

Even without explicitly including the variants, by using the same media ID across multiple image requests, the pipeline may build up a knowledge of these and fulfil requests accordingly.

This extra functionality is currently only enabled if getMediaVariationsIndexEnabled() is true in the image pipeline config.

Summary

Nested Classes
class MediaVariations.Builder  
@interface MediaVariations.Source Defines the range of valid source values to be held by an instance. 
class MediaVariations.Variant  
Constants
String SOURCE_ID_EXTRACTOR
String SOURCE_IMAGE_REQUEST
String SOURCE_INDEX_DB
Public Methods
boolean equals(Object o)
static MediaVariations forMediaId(String mediaId)
Creates an instance with a media ID and without specific variants.
String getMediaId()
Get the unique ID for this piece of media.
List<MediaVariations.Variant> getSortedVariants(Comparator<MediaVariations.Variant> comparator)
Gets a list of the variants in an order determined by the provided comparator.
String getSource()
Get the source of these variations, for the purposes of logging.
MediaVariations.Variant getVariant(int index)
Gets the variant at the specified index.
int getVariantsCount()
Get the number of contained variants.
int hashCode()
static MediaVariations.Builder newBuilderForMediaId(String mediaId)
Creates a builder for a new MediaVariations to which you can add specific variants.
boolean shouldForceRequestForSpecifiedUri()
Gets whether the URI in the original request should be downloaded even if another cached image appears to be big enough for the request.
String toString()
[Expand]
Inherited Methods
From class java.lang.Object

Constants

public static final String SOURCE_ID_EXTRACTOR

Constant Value: "id_extractor"

public static final String SOURCE_IMAGE_REQUEST

Constant Value: "request"

public static final String SOURCE_INDEX_DB

Constant Value: "index_db"

Public Methods

public boolean equals (Object o)

public static MediaVariations forMediaId (String mediaId)

Creates an instance with a media ID and without specific variants. If a null or empty ID is given, null is returned.

Parameters
mediaId the unique ID for this piece of media. If this is neither null or empty, it must be 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).

public String getMediaId ()

Get the unique ID for this piece of media. This must be non-null, not empty 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).

public List<MediaVariations.Variant> getSortedVariants (Comparator<MediaVariations.Variant> comparator)

Gets a list of the variants in an order determined by the provided comparator.

public String getSource ()

Get the source of these variations, for the purposes of logging.

public MediaVariations.Variant getVariant (int index)

Gets the variant at the specified index.

Parameters
index index of the element to return
Returns
  • the element at the specified position in this list
Throws
IndexOutOfBoundsException if the index is out of range (index < 0 || index >= getVariantsCount())
NullPointerException if there are no variants

public int getVariantsCount ()

Get the number of contained variants. This may not be an exhaustive set of variants and these sets may be combined over time to allow the possibilities of fallbacks being offered even when not specified in a later request.

Returns
  • the number of variants

public int hashCode ()

public static MediaVariations.Builder newBuilderForMediaId (String mediaId)

Creates a builder for a new MediaVariations to which you can add specific variants.

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).

public boolean shouldForceRequestForSpecifiedUri ()

Gets whether the URI in the original request should be downloaded even if another cached image appears to be big enough for the request.

Returns
  • true if any found image should only be used as a placeholder, whatever the size

public String toString ()