com.duowan.mobile.netroid.request
Class ImageRequest

java.lang.Object
  extended by com.duowan.mobile.netroid.Request<android.graphics.Bitmap>
      extended by com.duowan.mobile.netroid.request.ImageRequest
All Implemented Interfaces:
java.lang.Comparable<Request<android.graphics.Bitmap>>

public class ImageRequest
extends Request<android.graphics.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.duowan.mobile.netroid.Request
Request.Method, Request.Priority
 
Constructor Summary
ImageRequest(java.lang.String url, int maxWidth, int maxHeight)
           
ImageRequest(java.lang.String url, Listener<android.graphics.Bitmap> listener, int maxWidth, int maxHeight, android.graphics.Bitmap.Config decodeConfig)
          Creates a new image request, decoding to a maximum specified width and height.
 
Method Summary
(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<android.graphics.Bitmap> parseNetworkResponse(NetworkResponse response)
          Subclasses must implement this to parse the raw network response and return an appropriate response type.
 void setDecodeConfig(android.graphics.Bitmap.Config decodeConfig)
           
 void setMaxHeight(int maxHeight)
           
 void setMaxWidth(int maxWidth)
           
 
Methods inherited from class com.duowan.mobile.netroid.Request
addHeader, addMarker, cancel, compareTo, deliverCancel, deliverDownloadProgress, deliverError, deliverFinish, deliverNetworking, deliverPreExecute, deliverRetry, deliverSuccess, deliverUsedCache, finish, getBody, getBodyContentType, getCacheExpireTime, getCacheKey, getHeaders, getMethod, getParams, getParamsEncoding, getRetryPolicy, getSequence, getTag, getTimeoutMs, getUrl, handleResponse, hasHadResponseDelivered, isCanceled, isForceUpdate, markDelivered, parseNetworkError, perform, prepare, removeHeader, setCacheExpireTime, setForceUpdate, setListener, setRequestQueue, setRetryPolicy, setSequence, 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(java.lang.String url,
                    Listener<android.graphics.Bitmap> listener,
                    int maxWidth,
                    int maxHeight,
                    android.graphics.Bitmap.Config decodeConfig)
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 or error message
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

ImageRequest

public ImageRequest(java.lang.String url,
                    int maxWidth,
                    int maxHeight)
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<android.graphics.Bitmap>

parseNetworkResponse

protected Response<android.graphics.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<android.graphics.Bitmap>
Parameters:
response - Response from the network
Returns:
The parsed response, or null in the case of an error

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

setDecodeConfig

public void setDecodeConfig(android.graphics.Bitmap.Config decodeConfig)

setMaxWidth

public void setMaxWidth(int maxWidth)

setMaxHeight

public void setMaxHeight(int maxHeight)