Example #1
0
  /**
   * Same as download but the image is always downloaded and the cache is not used. Kept private at
   * the moment as its interest is not clear.
   */
  private void forceDownload(String url, ImageView imageView) {
    // State sanity: url is guaranteed to never be null in DownloadedDrawable and cache keys.
    if (url == null) {
      imageView.setImageDrawable(null);
      return;
    }

    if (cancelPotentialDownload(url, imageView)) {
      //            switch (mode) {
      //                case NO_ASYNC_TASK:
      //                    Bitmap bitmap = downloadBitmap(url);
      //                    addBitmapToCache(url, bitmap);
      //                    imageView.setImageBitmap(bitmap);
      //                    break;
      //
      //                case NO_DOWNLOADED_DRAWABLE:
      //                    imageView.setMinimumHeight(156);
      BitmapDownloaderTask task = new BitmapDownloaderTask(imageView);
      //                    task.execute(url);
      //                    break;
      //
      //                case CORRECT:
      //                    task = new BitmapDownloaderTask(imageView);
      DownloadedDrawable downloadedDrawable = new DownloadedDrawable(task);
      imageView.setImageDrawable(downloadedDrawable);
      //                    imageView.setMinimumHeight(156);
      task.execute(url);
      //                    break;
      //            }
    }
  }
  public void scheduleForLoad(ImageView imageView, ImageSource src) {

    boolean imageSet = setImageIfDownloadNotNeeded(imageView, src);
    if (imageSet) return;

    // download needed
    BitmapDownloaderTask<ImageSource> downloadTask =
        new BitmapDownloaderTask<ImageSource>(this, imageDownloader, src, null, null);
    downloadTask.execute();
    downloaderTasksMap.put(src, downloadTask);
    setImageIfDownloadNotNeeded(imageView, src); // set imageLoadingDrawable
  }
Example #3
0
 /**
  * Same as download but the image is always downloaded and the cache is not used. Kept private at
  * the moment as its interest is not clear.
  */
 private void forceDownload(String url, ImageView imageView) {
   if (url == null) {
     imageView.setImageDrawable(null); // TODO 更改为默认图�?            return;
   }
   if (cancelPotentialDownload(url, imageView)) {
     BitmapDownloaderTask task = new BitmapDownloaderTask(imageView);
     task = new BitmapDownloaderTask(imageView);
     DownloadedDrawable downloadedDrawable = new DownloadedDrawable(task);
     imageView.setImageDrawable(downloadedDrawable);
     task.execute(url);
   }
 }
Example #4
0
  /**
   * Returns true if the current download has been canceled or if there was no download in progress
   * on this image view. Returns false if the download in progress deals with the same url. The
   * download is not stopped in that case.
   */
  private static boolean cancelPotentialDownload(String url, ImageView imageView) {
    BitmapDownloaderTask bitmapDownloaderTask = getBitmapDownloaderTask(imageView);

    if (bitmapDownloaderTask != null) {
      String bitmapUrl = bitmapDownloaderTask.url;
      if ((bitmapUrl == null) || (!bitmapUrl.equals(url))) {
        bitmapDownloaderTask.cancel(true);
      } else {
        // The same URL is already being downloaded.
        return false;
      }
    }
    return true;
  }
 private boolean wasLoadingError(ImageSource src) {
   BitmapDownloaderTask<ImageSource> downloaderTask = downloaderTasksMap.get(src);
   return (downloaderTask != null && downloaderTask.getStatus() == AsyncTask.Status.FINISHED);
 }