Ejemplo n.º 1
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();
        }
      }
    }
Ejemplo n.º 2
0
 /**
  * Detach the ImageView from the ImageTask.
  *
  * @param imageTask
  * @param imageView
  */
 public void detachImageViewFromImageTask(ImageTask imageTask, CubeImageView imageView) {
   imageTask.removeImageView(imageView);
   if (imageTask.isLoading()) {
     if (!imageTask.isPreLoad() && !imageTask.stillHasRelatedImageView()) {
       LoadImageTask task = mLoadWorkList.get(imageTask.getIdentityKey());
       if (task != null) {
         task.cancel();
       }
       if (DEBUG) {
         CLog.d(LOG_TAG, "%s previous work is cancelled.", imageTask);
       }
     }
   }
   if (!imageTask.stillHasRelatedImageView()) {
     imageTask.tryToRecycle();
   }
 }