예제 #1
0
  @Override
  protected void onPostExecute(Bitmap bitmap) {

    // Checks if has been canceled due to imageView recycling
    if (isCancelled()) {
      // bitmap = null;
      return;
    }

    // The bitmap will now be attached to view
    if (imageViewReference != null && bitmap != null) {
      final SquareImageView imageView = imageViewReference.get();

      // Checks if is still the task in charge to load image on that imageView
      if (imageView != null && this == (BitmapWorkerTask) imageView.getAsyncTask()) {

        // If the bitmap was already cached it will be directly attached to view
        if (wasCached) {
          imageView.setImageBitmap(bitmap);
        }

        // Otherwise a fading transaction will be used to shot it
        else {
          // Transition with transparent drawabale and the final bitmap
          final TransitionDrawable td =
              new TransitionDrawable(
                  new Drawable[] {
                    new ColorDrawable(Color.TRANSPARENT),
                    new BitmapDrawable(mActivity.getResources(), bitmap)
                  });
          if (td != null) {
            imageView.setImageDrawable(td);
            td.startTransition(FADE_IN_TIME);
          }
        }
      }
    } else {
      if (this.mOnAttachingFileErrorListener != null) {
        mOnAttachingFileErrorListener.onAttachingFileErrorOccurred(mAttachment);
      }
    }
  }
예제 #2
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;
  }