| AndBase开发框架 1.6

- 首页
- 相关页面
- 命名空间
- 类
- 文件

- 类列表
- 类索引
- 类继承关系
- 类成员

全部 类 命名空间 文件 函数 变量 枚举值 页
类 | Public 成员函数 | Private 成员函数 | 静态 Private 成员函数 | Private 属性 | 所有成员列表
com.ab.image.toolbox.ImageLoader类 参考

## 类
class | BatchedImageRequest
interface | ImageCache
class | ImageContainer
interface | ImageListener

## Public 成员函数
| ImageLoader (RequestQueue queue, ImageCache imageCache)
boolean | isCached (String requestUrl, int maxWidth, int maxHeight)
ImageContainer | get (String requestUrl, final ImageListener listener)
ImageContainer | get (String requestUrl, ImageListener imageListener, int maxWidth, int maxHeight)
void | setBatchedResponseDelay (int newBatchedResponseDelayMs)

## Private 成员函数
void | onGetImageSuccess (String cacheKey, Bitmap response)
void | onGetImageError (String cacheKey, VolleyError error)
void | batchResponse (String cacheKey, BatchedImageRequest request)
void | throwIfNotOnMainThread ()

## 静态 Private 成员函数
static String | getCacheKey (String url, int maxWidth, int maxHeight)

## Private 属性
final RequestQueue | mRequestQueue
int | mBatchResponseDelayMs = 100
final ImageCache | mCache
final HashMap< String, BatchedImageRequest > | mInFlightRequests
final HashMap< String, BatchedImageRequest > | mBatchedResponses
final Handler | mHandler = new Handler(Looper.getMainLooper())
Runnable | mRunnable

## 详细描述

Helper that handles loading and caching images from remote URLs.

The simple way to use this class is to call ImageLoader#get(String, ImageListener) and to pass in the default image listener provided by ImageLoader#getImageListener(ImageView, int, int). Note that all function calls to this class must be made from the main thead, and all responses will be delivered to the main thread as well.

## 构造及析构函数说明

com.ab.image.toolbox.ImageLoader.ImageLoader | ( | RequestQueue | queue,
|  | ImageCache | imageCache
| ) |  |
| inline

Constructs a new ImageLoader.

参数

  queue | The RequestQueue to use for making image requests.
  imageCache | The cache to use as an L1 cache.

## 成员函数说明

void com.ab.image.toolbox.ImageLoader.batchResponse | ( | String | cacheKey,
|  | BatchedImageRequest | request
| ) |  |
| inline private

Starts the runnable for batched delivery of responses if it is not already started.

参数

  cacheKey | The cacheKey of the response being delivered.
  request | The BatchedImageRequest to be delivered.
  error | The volley error associated with the request (if applicable).

ImageContainer com.ab.image.toolbox.ImageLoader.get | ( | String | requestUrl,
|  | final ImageListener | listener
| ) |  |
| inline

Returns an ImageContainer for the requested URL.

The ImageContainer will contain either the specified default bitmap or the loaded bitmap. If the default was returned, the ImageLoader will be invoked when the request is fulfilled.

参数

  requestUrl | The URL of the image to be loaded.
  defaultImage | Optional default image to return until the actual image is loaded.

ImageContainer com.ab.image.toolbox.ImageLoader.get | ( | String | requestUrl,
|  | ImageListener | imageListener,
|  | int | maxWidth,
|  | int | maxHeight
| ) |  |
| inline

Issues a bitmap request with the given URL if that image is not available in the cache, and returns a bitmap container that contains all of the data relating to the request (as well as the default image if the requested image is not available).

参数

  requestUrl | The url of the remote image
  imageListener | The listener to call when the remote image is loaded
  maxWidth | The maximum width of the returned image.
  maxHeight | The maximum height of the returned image.

返回
  A container object that contains all of the properties of the request, as well as the currently available image (default if remote is not loaded).

static String com.ab.image.toolbox.ImageLoader.getCacheKey | ( | String | url,
|  | int | maxWidth,
|  | int | maxHeight
| ) |  |
| inline static private

Creates a cache key for use with the L1 cache.

参数

  url | The URL of the request.
  maxWidth | The max-width of the output.
  maxHeight | The max-height of the output.

boolean com.ab.image.toolbox.ImageLoader.isCached | ( | String | requestUrl,
|  | int | maxWidth,
|  | int | maxHeight
| ) |  |
| inline

Checks if the item is available in the cache.

参数

  requestUrl | The url of the remote image
  maxWidth | The maximum width of the returned image.
  maxHeight | The maximum height of the returned image.

返回
  True if the item exists in cache, false otherwise.

void com.ab.image.toolbox.ImageLoader.onGetImageError | ( | String | cacheKey,
|  | VolleyError | error
| ) |  |
| inline private

Handler for when an image failed to load.

参数

  cacheKey | The cache key that is associated with the image request.

void com.ab.image.toolbox.ImageLoader.onGetImageSuccess | ( | String | cacheKey,
|  | Bitmap | response
| ) |  |
| inline private

Handler for when an image was successfully loaded.

参数

  cacheKey | The cache key that is associated with the image request.
  response | The bitmap that was returned from the network.

void com.ab.image.toolbox.ImageLoader.setBatchedResponseDelay | ( | int | newBatchedResponseDelayMs | ) |
| inline

Sets the amount of time to wait after the first response arrives before delivering all responses. Batching can be disabled entirely by passing in 0.

参数

  newBatchedResponseDelayMs | The time in milliseconds to wait.

void com.ab.image.toolbox.ImageLoader.throwIfNotOnMainThread | ( |  | ) |
| inline private

## 类成员变量说明

final HashMap<String, BatchedImageRequest> com.ab.image.toolbox.ImageLoader.mBatchedResponses
| private

初始值:
=
new HashMap<String, BatchedImageRequest>()

HashMap of the currently pending responses (waiting to be delivered).

int com.ab.image.toolbox.ImageLoader.mBatchResponseDelayMs = 100
| private

Amount of time to wait after first response arrives before delivering all responses.

final ImageCache com.ab.image.toolbox.ImageLoader.mCache
| private

The cache implementation to be used as an L1 cache before calling into volley.

final Handler com.ab.image.toolbox.ImageLoader.mHandler = new Handler(Looper.getMainLooper())
| private

Handler to the main thread.

final HashMap<String, BatchedImageRequest> com.ab.image.toolbox.ImageLoader.mInFlightRequests
| private

初始值:
=
new HashMap<String, BatchedImageRequest>()

HashMap of Cache keys -> BatchedImageRequest used to track in-flight requests so that we can coalesce multiple requests to the same URL into a single network request.

final RequestQueue com.ab.image.toolbox.ImageLoader.mRequestQueue
| private

RequestQueue for dispatching ImageRequests onto.

Runnable com.ab.image.toolbox.ImageLoader.mRunnable
| private

Runnable for in-flight response delivery.

该类的文档由以下文件生成:

- src/com/ab/image/toolbox/ImageLoader.java