Example #1
0
 /** Recover the from the work list */
 public void recoverWork() {
   if (DEBUG) {
     CLog.d(LOG_TAG, "work_status: recoverWork %s", this);
   }
   mExitTasksEarly = false;
   setPause(false);
   Iterator<Entry<String, LoadImageTask>> it =
       (Iterator<Entry<String, LoadImageTask>>) mLoadWorkList.entrySet().iterator();
   while (it.hasNext()) {
     Entry<String, LoadImageTask> item = it.next();
     LoadImageTask task = item.getValue();
     task.restart();
     mImageTaskExecutor.execute(task);
   }
 }
Example #2
0
  private LoadImageTask createLoadImageTask(ImageTask imageTask) {
    // pop top, make top.next as top
    synchronized (sPoolSync) {
      if (sTopLoadImageTask != null) {
        LoadImageTask m = sTopLoadImageTask;
        m.mNextImageTask = null;
        m.renew(this, imageTask);

        sTopLoadImageTask = m.mNextImageTask;
        sPoolSize--;
        return m;
      }
    }
    return new LoadImageTask().renew(this, imageTask);
  }
Example #3
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();
   }
 }
Example #4
0
  /** Drop all the work, clear the work list. */
  public void destroy() {
    if (DEBUG) {
      CLog.d(LOG_TAG, "work_status: destroy %s", this);
    }
    mExitTasksEarly = true;
    setPause(false);

    Iterator<Entry<String, LoadImageTask>> it =
        (Iterator<Entry<String, LoadImageTask>>) mLoadWorkList.entrySet().iterator();
    while (it.hasNext()) {
      Entry<String, LoadImageTask> item = it.next();
      final LoadImageTask task = item.getValue();
      it.remove();
      if (task != null) {
        task.cancel();
      }
    }
    mLoadWorkList.clear();
  }
Example #5
0
  /**
   * Add the ImageTask into loading list.
   *
   * @param imageTask
   * @param imageView
   */
  public void addImageTask(ImageTask imageTask, CubeImageView imageView) {
    if (!mHasBeenAddedToComponentManager) {
      CLog.w(LOG_TAG, "ImageLoader has not been add to a Component Manager.", this);
    }
    LoadImageTask runningTask = mLoadWorkList.get(imageTask.getIdentityKey());
    if (runningTask != null) {
      if (imageView != null) {
        if (DEBUG) {
          CLog.d(LOG_TAG, MSG_ATTACK_TO_RUNNING_TASK, imageTask, runningTask.getImageTask());
        }
        runningTask.getImageTask().addImageView(imageView);
        runningTask.getImageTask().notifyLoading(mImageLoadHandler, imageView);
      }
      return;
    } else {
      imageTask.addImageView(imageView);
    }

    imageTask.onLoading(mImageLoadHandler);

    LoadImageTask loadImageTask = createLoadImageTask(imageTask);
    mLoadWorkList.put(imageTask.getIdentityKey(), loadImageTask);
    mImageTaskExecutor.execute(loadImageTask);
  }