コード例 #1
0
  BitmapFetcher executeCache() {
    final String downloadKey = computeDownloadKey();
    assert Thread.currentThread() == Looper.getMainLooper().getThread() || imageViewPostRef == null;
    assert downloadKey != null;

    if (resizeHeight > 0 || resizeWidth > 0) {
      if (transforms == null) transforms = new ArrayList<Transform>();
      transforms.add(0, new DefaultTransform(resizeWidth, resizeHeight, scaleMode));
    }

    // determine the key for this bitmap after all transformations
    String bitmapKey = downloadKey;
    boolean hasTransforms = transforms != null && transforms.size() > 0;
    if (hasTransforms) {
      for (Transform transform : transforms) {
        bitmapKey += transform.key();
      }
      bitmapKey = ResponseCacheMiddleware.toKeyString(bitmapKey);
    }

    // TODO: eliminate this allocation?
    BitmapFetcher ret = new BitmapFetcher();
    ret.downloadKey = downloadKey;
    ret.bitmapKey = bitmapKey;
    ret.hasTransforms = hasTransforms;
    ret.resizeWidth = resizeWidth;
    ret.resizeHeight = resizeHeight;
    ret.builder = builder;
    ret.transforms = transforms;
    ret.animateGif = animateGif;
    ret.deepZoom = deepZoom;

    // see if this request can be fulfilled from the cache
    if (!builder.noCache) {
      BitmapInfo bitmap = builder.ion.bitmapCache.get(bitmapKey);
      if (bitmap != null) {
        ret.info = bitmap;
        return ret;
      }
    }

    return ret;
  }
コード例 #2
0
  @Override
  public BitmapInfo asCachedBitmap() {
    final String downloadKey = computeDownloadKey();
    assert Thread.currentThread() == Looper.getMainLooper().getThread() || imageViewPostRef == null;
    assert downloadKey != null;

    if (resizeHeight > 0 || resizeWidth > 0) {
      if (transforms == null) transforms = new ArrayList<Transform>();
      transforms.add(0, new DefaultTransform(resizeWidth, resizeHeight, scaleMode));
    }

    // determine the key for this bitmap after all transformations
    String bitmapKey = downloadKey;
    boolean hasTransforms = transforms != null && transforms.size() > 0;
    if (hasTransforms) {
      for (Transform transform : transforms) {
        bitmapKey += transform.key();
      }
      bitmapKey = ResponseCacheMiddleware.toKeyString(bitmapKey);
    }

    return builder.ion.bitmapCache.get(bitmapKey);
  }