Exemplo n.º 1
0
  public static boolean isNewWork(Uri uri, SquareImageView imageView) {
    final BitmapWorkerTask bitmapWorkerTask = (BitmapWorkerTask) imageView.getAsyncTask();

    if (bitmapWorkerTask != null && bitmapWorkerTask.getAttachment() != null) {
      final Uri bitmapData = bitmapWorkerTask.getAttachment().getUri();
      // If bitmapData is not yet set or it differs from the new data
      if (bitmapData == null || bitmapData != uri) {
        // Cancel previous task
        bitmapWorkerTask.cancel(true);
      } else {
        // The same work is already in progress
        return false;
      }
    }
    // No task associated with the ImageView, or an existing task was
    // cancelled
    return true;
  }
Exemplo n.º 2
0
 @SuppressLint("NewApi")
 private void loadThumbnail(NoteAdapterViewHolder holder, Attachment mAttachment) {
   //		if (isNewWork(mAttachment.getUri(), holder.attachmentThumbnail)) {
   BitmapWorkerTask task =
       new BitmapWorkerTask(
           mActivity,
           holder.attachmentThumbnail,
           Constants.THUMBNAIL_SIZE,
           Constants.THUMBNAIL_SIZE);
   holder.attachmentThumbnail.setAsyncTask(task);
   try {
     if (Build.VERSION.SDK_INT >= 11) {
       task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, mAttachment);
     } else {
       task.execute(mAttachment);
     }
   } catch (RejectedExecutionException e) {
     Log.w(Constants.TAG, "Oversized tasks pool to load thumbnails!");
   }
   holder.attachmentThumbnail.setVisibility(View.VISIBLE);
   //		}
 }