@Override
 public void downloadFinished(URI uri) {
   if (!TiResponseCache.peek(uri)) {
     // The requested image did not make it into our TiResponseCache,
     // possibly because it had a header forbidding that. Now get it
     // via the "old way" (not relying on cache).
     synchronized (imageTokenGenerator) {
       token = imageTokenGenerator.incrementAndGet();
       if (uri.toString().equals(currentUrl)) {
         makeImageSource(uri.toString())
             .getBitmapAsync(new BgImageLoader(requestedWidth, requestedHeight, token));
       }
     }
   } else {
     firedLoad = false;
     if (uri.toString().equals(currentUrl)) {
       ImageArgs imageArgs =
           new ImageArgs(
               makeImageSource(uri.toString()),
               getParentView(),
               requestedWidth,
               requestedHeight,
               true,
               false);
       BackgroundImageTask task = new BackgroundImageTask();
       try {
         task.execute(imageArgs);
       } catch (RejectedExecutionException e) {
         Log.e(TAG, "Cannot load the image. Loading too many images at the same time.");
       }
     }
   }
 }
  private void setImage(boolean recycle) {

    if (imageSources == null
        || imageSources.size() == 0
        || imageSources.get(0) == null
        || imageSources.get(0).isTypeNull()) {
      if (defaultImageSource != null) {
        setDefaultImage();
      } else {
        setImage(null);
      }
      return;
    }

    if (imageSources.size() == 1) {
      if (imageViewProxy.inTableView()) {
        Bitmap currentBitmap = imageViewProxy.getBitmap();
        if (currentBitmap != null) {
          // If the image proxy has the default image currently cached, we need to
          // load the downloaded URL instead. TIMOB-4814
          ArrayList<TiDrawableReference> proxySources = imageViewProxy.getImageSources();
          if (proxySources != null && !proxySources.contains(defaultImageSource)) {
            setImage(currentBitmap);
            return;
          }
        }
      }
      TiDrawableReference imageref = imageSources.get(0);
      if (imageref.isNetworkUrl()) {
        if (defaultImageSource != null) {
          setDefaultImage();
        } else {
          setImage(null);
        }
        currentUrl = imageref.getUrl();

        ImageArgs imageArgs =
            new ImageArgs(
                imageref, getParentView(), requestedWidth, requestedHeight, recycle, true);

        BackgroundImageTask task = new BackgroundImageTask();
        try {
          task.execute(imageArgs);
        } catch (RejectedExecutionException e) {
          Log.e(TAG, "Cannot load the image. Loading too many images at the same time.");
        }

      } else {
        currentUrl = imageref.getUrl();

        ImageArgs imageArgs =
            new ImageArgs(
                imageref, getParentView(), requestedWidth, requestedHeight, recycle, false);

        BackgroundImageTask task = new BackgroundImageTask();
        try {
          task.execute(imageArgs);
        } catch (RejectedExecutionException e) {
          Log.e(TAG, "Cannot load the image. Loading too many images at the same time.");
        }
      }
    } else {
      setImages();
    }
  }