コード例 #1
0
  public void loadImage(
      Context context,
      final ViewHolder holder,
      final String url,
      BitmapLruCache mCache,
      final long tweetId) {
    // First check whether there's already a task running, if so cancel it
    /*if (null != mCurrentTask) {
        mCurrentTask.cancel(true);
    }*/

    if (url == null) {
      return;
    }

    BitmapDrawable wrapper = mCache.getFromMemoryCache(url);

    if (null != wrapper && holder.picture.getVisibility() != View.GONE) {
      // The cache has it, so just display it
      holder.picture.setImageDrawable(wrapper);
      Animation fadeInAnimation = AnimationUtils.loadAnimation(context, R.anim.fade_in);

      holder.picture.startAnimation(fadeInAnimation);
    } else {
      // Memory Cache doesn't have the URL, do threaded request...
      holder.picture.setImageDrawable(null);

      mCurrentTask = new ImageUrlAsyncTask(context, holder, mCache, tweetId);

      try {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
          SDK11.executeOnThreadPool(mCurrentTask, url);
        } else {
          mCurrentTask.execute(url);
        }
      } catch (RejectedExecutionException e) {
        // This shouldn't happen, but might.
      }
    }
  }