コード例 #1
0
  @Override
  public void load(ImageView imageView) {
    ImageWrapper w = new ImageWrapper(imageView);

    if (w.getUrl() == null) {
      Log.w("ImageLoader", "You should never call load if you don't set a ImageTag on the view");
      return;
    }

    if (checkConcurrentTasks(w.getUrl(), w.getLoaderTask())) {
      // only continue if a concurrent task has not yet been started

      try {

        // get bitmap from cache
        Bitmap b = loaderContext.getCache().get(w.getUrl(), w.getHeight(), w.getWidth());
        if (b != null && !b.isRecycled()) {
          w.setBitmap(b);
          return;
        }

        // get preview or loading image
        String thumbUrl = w.getPreviewUrl();
        if (thumbUrl != null) {
          b = loaderContext.getCache().get(thumbUrl, w.getPreviewHeight(), w.getPreviewWidth());
          if (b != null && !b.isRecycled()) {
            w.setBitmap(b);
          } else {
            setResource(w, w.getLoadingResourceId());
          }
        } else {
          setResource(w, w.getLoadingResourceId());
        }

        if (w.isUseCacheOnly()) {
          return;
        }

        // spin off a new task for this url
        LoaderTask task = new LoaderTask(imageView, loaderContext);
        w.setLoaderTask(task);
        task.execute();

      } catch (ImageNotFoundException inf) {
        setResource(w, w.getNotFoundResourceId());
      } catch (Throwable t) {
        setResource(w, w.getNotFoundResourceId());
      }
    }
  }
コード例 #2
0
 private void setResource(ImageWrapper w, int resId) {
   Bitmap b = loaderContext.getResBitmapCache().get("" + resId, w.getWidth(), w.getHeight());
   if (b != null) {
     w.setBitmap(b);
     return;
   }
   b =
       loaderContext
           .getBitmapUtil()
           .decodeResourceBitmapAndScale(
               w, resId, loaderContext.getSettings().isAllowUpsampling());
   loaderContext.getResBitmapCache().put(String.valueOf(resId), b);
   w.setBitmap(b);
 }