Esempio n. 1
0
  public void setImageUrl(String url) {
    if ((mUrl != null && mUrl.equals(url))) return;

    Bitmap oldOne = mBitmap;

    if (mDownloadTask != null) {
      mDownloadTask.cancelDownload();
    }

    mUrl = url;

    if (mUrl != null) {
      mBitmap = mCache.get(mUrl);
      if (mBitmap == null) {
        mDownloadPercent = 0;
        Log.d("zdw", "submiting task");
        mDownloadTask = new ImageDownloadTask(mUrl);
        mDownloadTask.setDownloadStatusListener(this);
        DownloadManager.submitTask(mDownloadTask);
        mBitmap = mDefaultBitmap;
      }
    } else {
      mBitmap = mDefaultBitmap;
    }
    if (mBitmap != oldOne) updateView();
  }
Esempio n. 2
0
  @Override
  public void onDownloadFinished(DownloadTask task, boolean success) {
    mDownloadTask = null;
    Bitmap image = ((ImageDownloadTask) task).getDownloadedBitmap();
    if (image != null) {
      mDownloadPercent = 100;
      mBitmap = createThumb(image);
      mCache.put(mUrl, mBitmap);
      image = null;
    } else { // download failed, use default Bitmap
      mDownloadPercent = 100;
      mBitmap = mDefaultBitmap;
      mCache.put(mUrl, mBitmap);
    }

    updateView();
  }