Exemplo n.º 1
0
  /** Check weather this imageTask has cache Drawable data. */
  public boolean queryCache(ImageTask imageTask, CubeImageView imageView) {
    if (null == mImageProvider) {
      return false;
    }
    BitmapDrawable drawable = mImageProvider.getBitmapFromMemCache(imageTask);

    if (imageTask.getStatistics() != null) {
      imageTask.getStatistics().s0_afterCheckMemoryCache(drawable != null);
    }
    if (drawable == null) {
      return false;
    }

    if (DEBUG) {
      CLog.d(
          LOG_TAG,
          MSG_HIT_CACHE,
          imageTask,
          drawable.getIntrinsicWidth(),
          drawable.getIntrinsicHeight());
    }
    imageTask.addImageView(imageView);
    imageTask.onLoadTaskFinish(drawable, mImageLoadHandler);
    return true;
  }
Exemplo n.º 2
0
    @Override
    public void doInBackground() {
      if (DEBUG) {
        CLog.d(LOG_TAG, MSG_TASK_DO_IN_BACKGROUND, this, mImageTask);
      }

      if (mImageTask.getStatistics() != null) {
        mImageTask.getStatistics().s1_beginLoad();
      }
      Bitmap bitmap = null;
      // Wait here if work is paused and the task is not cancelled
      synchronized (mImageLoader.mPauseWorkLock) {
        while (mImageLoader.mPauseWork && !isCancelled()) {
          try {
            if (DEBUG) {
              CLog.d(LOG_TAG, MSG_TASK_WAITING, this, mImageTask);
            }
            mImageLoader.mPauseWorkLock.wait();
          } catch (InterruptedException e) {
          }
        }
      }

      // If this task has not been cancelled by another
      // thread and the ImageView that was originally bound to this task is still bound back
      // to this task and our "exit early" flag is not set then try and fetch the bitmap from
      // the cache
      if (!isCancelled()
          && !mImageLoader.mExitTasksEarly
          && (mImageTask.isPreLoad() || mImageTask.stillHasRelatedImageView())) {
        try {
          bitmap =
              mImageLoader.mImageProvider.fetchBitmapData(
                  mImageLoader, mImageTask, mImageLoader.mImageReSizer);
          if (DEBUG) {
            CLog.d(LOG_TAG, MSG_TASK_AFTER_fetchBitmapData, this, mImageTask, isCancelled());
          }
          mDrawable =
              mImageLoader.mImageProvider.createBitmapDrawable(mImageLoader.mResources, bitmap);
          mImageLoader.mImageProvider.addBitmapToMemCache(mImageTask.getIdentityKey(), mDrawable);
        } catch (Exception e) {
          e.printStackTrace();
        } catch (OutOfMemoryError e) {
          e.printStackTrace();
        }
      }
    }