com.android.volley.toolbox
Class ImageRequest

java.lang.Object
  extended by com.android.volley.Request<Bitmap>
      extended by com.android.volley.toolbox.ImageRequest
All Implemented Interfaces:
Comparable<Request<Bitmap>>

public class ImageRequest
extends Request<Bitmap>

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


Nested Class Summary
 
Nested classes/interfaces inherited from class com.android.volley.Request
Request.Method, Request.Priority
 
Constructor Summary
ImageRequest(String url, Response.Listener<Bitmap> listener, int maxWidth, int maxHeight, Config decodeConfig, Response.ErrorListener errorListener)
          Creates a new image request, decoding to a maximum specified width and height.
 
Method Summary
protected  void deliverResponse(Bitmap response)
          Subclasses must implement this to perform delivery of the parsed response to their listeners.
(package private) static int findBestSampleSize(int actualWidth, int actualHeight, int desiredWidth, int desiredHeight)
          Returns the largest power-of-two divisor for use in downscaling a bitmap that will not result in the scaling past the desired dimensions.
 Request.Priority getPriority()
          Returns the Request.Priority of this request; Request.Priority.NORMAL by default.
protected  Response<Bitmap> parseNetworkResponse(NetworkResponse response)
          Subclasses must implement this to parse the raw network response and return an appropriate response type.
 
Methods inherited from class com.android.volley.Request
addMarker, cancel, compareTo, deliverError, getBody, getBodyContentType, getCacheEntry, getCacheKey, getHeaders, getMethod, getParams, getParamsEncoding, getPostBody, getPostBodyContentType, getPostParams, getPostParamsEncoding, getRetryPolicy, getSequence, getTag, getTimeoutMs, getTrafficStatsTag, getUrl, hasHadResponseDelivered, isCanceled, markDelivered, parseNetworkError, setCacheEntry, setRequestQueue, setRetryPolicy, setSequence, setShouldCache, setTag, shouldCache, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ImageRequest

public ImageRequest(String url,
                    Response.Listener<Bitmap> listener,
                    int maxWidth,
                    int maxHeight,
                    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
decodeConfig - Format to decode the bitmap to
errorListener - Error listener, or null to ignore errors
Method Detail

getPriority

public Request.Priority getPriority()
Description copied from class: Request
Returns the Request.Priority of this request; Request.Priority.NORMAL by default.

Overrides:
getPriority in class Request<Bitmap>

parseNetworkResponse

protected Response<Bitmap> parseNetworkResponse(NetworkResponse response)
Description copied from class: Request
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.

Specified by:
parseNetworkResponse in class Request<Bitmap>
Parameters:
response - Response from the network
Returns:
The parsed response, or null in the case of an error

deliverResponse

protected void deliverResponse(Bitmap response)
Description copied from class: Request
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.

Specified by:
deliverResponse in class Request<Bitmap>
Parameters:
response - The parsed response returned by Request.parseNetworkResponse(NetworkResponse)

findBestSampleSize

static int findBestSampleSize(int actualWidth,
                              int actualHeight,
                              int desiredWidth,
                              int desiredHeight)
Returns the largest power-of-two divisor for use in downscaling a bitmap that will not result in the scaling past the desired dimensions.

Parameters:
actualWidth - Actual width of the bitmap
actualHeight - Actual height of the bitmap
desiredWidth - Desired width of the bitmap
desiredHeight - Desired height of the bitmap