Beispiel #1
0
  private void tryLoadImage() {

    if (mRequest == null || TextUtils.isEmpty(mRequest.getUrl())) {
      return;
    }

    int width = getWidth();
    int height = getHeight();
    final String mUrl = mRequest.getUrl();

    LayoutParams lyp = getLayoutParams();
    boolean isFullyWrapContent =
        lyp != null
            && lyp.height == LayoutParams.WRAP_CONTENT
            && lyp.width == LayoutParams.WRAP_CONTENT;
    // if the view's bounds aren't known yet, and this is not a wrap-content/wrap-content
    // view, hold off on loading the image.
    if (width == 0 && height == 0 && !isFullyWrapContent) {
      return;
    }

    mRequest.setLayoutSize(width, height);

    // 1. Check the previous ImageTask related to this ImageView
    if (null != mImageTask) {

      // duplicated ImageTask, return directly.
      if (mImageTask.isLoadingThisUrl(mRequest)) {
        return;
      }
      // ImageView is reused, detach it from the related ImageViews of the previous ImageTask.
      else {
        mImageLoader.detachImageViewFromImageTask(mImageTask, this);
      }
    }

    // 2. Let the ImageView hold this ImageTask. When ImageView is reused next time, check it in
    // step 1.
    ImageTask imageTask = mImageLoader.createImageTask(mRequest);
    // .createImageTask(mUrl, width, height, mImageReuseInfo);
    mImageTask = imageTask;

    // 3. Query cache, if hit, return at once.
    boolean hitCache = mImageLoader.queryCache(imageTask, this);
    if (hitCache) {
      return;
    } else {
      mImageLoader.addImageTask(mImageTask, this);
    }
  }
Beispiel #2
0
  public void loadImage(ImageLoader imageLoader, ImageLoadRequest request) {
    mImageLoader = imageLoader;
    if (request == null || TextUtils.isEmpty(request.getUrl())) {
      setImageDrawable(null);
      mImageTask = null;
      return;
    }
    mRequest = request;

    tryLoadImage();
  }