public class

ImageRequest

extends Request<T>
java.lang.Object
   ↳ com.android.volley.Request<T>
     ↳ com.android.volley.toolbox.ImageRequest

Class Overview

A canned request for getting an image at a given URL and calling back with a decoded Bitmap.

Summary

Constants
float DEFAULT_IMAGE_BACKOFF_MULT Default backoff multiplier for image requests
int DEFAULT_IMAGE_MAX_RETRIES Default number of retries for image requests
int DEFAULT_IMAGE_TIMEOUT_MS Socket timeout in milliseconds for image requests
Public Constructors
ImageRequest(String url, Listener<Bitmap> listener, int maxWidth, int maxHeight, ImageView.ScaleType scaleType, Bitmap.Config decodeConfig, Response.ErrorListener errorListener)
Creates a new image request, decoding to a maximum specified width and height.
ImageRequest(String url, Listener<Bitmap> listener, int maxWidth, int maxHeight, Bitmap.Config decodeConfig, Response.ErrorListener errorListener)
For API compatibility with the pre-ScaleType variant of the constructor.
Public Methods
Request.Priority getPriority()
Returns the Request.Priority of this request; NORMAL by default.
Protected Methods
void deliverResponse(Bitmap response)
Subclasses must implement this to perform delivery of the parsed response to their listeners.
Response<Bitmap> parseNetworkResponse(NetworkResponse response)
Subclasses must implement this to parse the raw network response and return an appropriate response type.
[Expand]
Inherited Methods
From class com.android.volley.Request
From class java.lang.Object
From interface java.lang.Comparable

Constants

public static final float DEFAULT_IMAGE_BACKOFF_MULT

Default backoff multiplier for image requests

Constant Value: 2.0

public static final int DEFAULT_IMAGE_MAX_RETRIES

Default number of retries for image requests

Constant Value: 2 (0x00000002)

public static final int DEFAULT_IMAGE_TIMEOUT_MS

Socket timeout in milliseconds for image requests

Constant Value: 1000 (0x000003e8)

Public Constructors

public ImageRequest (String url, Listener<Bitmap> listener, int maxWidth, int maxHeight, ImageView.ScaleType scaleType, Bitmap.Config decodeConfig, Response.ErrorListener errorListener)

Creates a new image request, decoding to a maximum specified width and height. If both width and height are zero, the image will be decoded to its natural size. If one of the two is nonzero, that dimension will be clamped and the other one will be set to preserve the image's aspect ratio. If both width and height are nonzero, the image will be decoded to be fit in the rectangle of dimensions width x height while keeping its aspect ratio.

Parameters
url URL of the image
listener Listener to receive the decoded bitmap
maxWidth Maximum width to decode this bitmap to, or zero for none
maxHeight Maximum height to decode this bitmap to, or zero for none
scaleType The ImageViews ScaleType used to calculate the needed image size.
decodeConfig Format to decode the bitmap to
errorListener Error listener, or null to ignore errors

public ImageRequest (String url, Listener<Bitmap> listener, int maxWidth, int maxHeight, Bitmap.Config decodeConfig, Response.ErrorListener errorListener)

For API compatibility with the pre-ScaleType variant of the constructor. Equivalent to the normal constructor with ScaleType.CENTER_INSIDE.

Public Methods

public Request.Priority getPriority ()

Returns the Request.Priority of this request; NORMAL by default.

Protected Methods

protected void deliverResponse (Bitmap response)

Subclasses must implement this to perform delivery of the parsed response to their listeners. The given response is guaranteed to be non-null; responses that fail to parse are not delivered.

Parameters
response The parsed response returned by parseNetworkResponse(NetworkResponse)

protected Response<Bitmap> parseNetworkResponse (NetworkResponse response)

Subclasses must implement this to parse the raw network response and return an appropriate response type. This method will be called from a worker thread. The response will not be delivered if you return null.

Parameters
response Response from the network
Returns
  • The parsed response, or null in the case of an error