Esempio n. 1
0
  private void setImageUrlLocal(final String localUrl, final boolean forceOriginLoad) {
    if (!TextUtils.isEmpty(localUrl)) {
      mUrl = localUrl;
      Bitmap bt = mImageCache.getResourceFromMem(mCategory, localUrl);
      if (bt == null) {
        CustomThreadPool.asyncWork(
            new Runnable() {
              @Override
              public void run() {
                File file = new File(localUrl);
                if (file.exists()) {
                  Bitmap bt = null;
                  if (!forceOriginLoad) {
                    bt =
                        mImageCache.getResource(
                            CustomImageCategory.THUMBNAIL_CATEGORY.toString(), localUrl);
                  }
                  if (bt == null) {
                    bt = mImageCache.getResource(mCategory, localUrl);
                  }

                  if (bt == null) {
                    mImageCache.putResource(mCategory, localUrl, localUrl);
                    bt = mImageCache.getResource(mCategory, localUrl);
                  }

                  Message msg = Message.obtain();
                  msg.what = LOCAL_FILE_IMAGE_LOAD;
                  msg.obj = bt;
                  mHandler.sendMessageDelayed(msg, 30);
                }

                Message msg = Message.obtain();
                msg.what = LOCAL_FILE_IMAGE_LOAD;
                msg.obj = null;
                mHandler.sendMessageDelayed(msg, 30);
              }
            });
      } else {
        mCurrentBtLoadSuccess = true;
        setImageBitmap(bt, false);
      }
    }
  }
Esempio n. 2
0
  /**
   * @param url
   * @param forceOriginLoad 标示支持同步加载,如果不支持同步加载的,就是fastload模式
   */
  private void setImageUrl(final String url, final boolean forceOriginLoad) {
    if (!TextUtils.isEmpty(url)) {
      mUrl = url;
      Bitmap bt = mImageCache.getResourceFromMem(mCategory, url);
      if (bt == null) {
        CustomThreadPool.asyncWork(
            new Runnable() {
              @Override
              public void run() {
                Bitmap bt = null;
                if (!forceOriginLoad) {
                  bt =
                      mImageCache.getResource(
                          CustomImageCategory.THUMBNAIL_CATEGORY.toString(), url);
                }
                if (bt == null) {
                  bt = mImageCache.getResource(mCategory, url);
                }

                // the f**k logic for category != UtilsConfig.IMAGE_CACHE_CATEGORY_RAW
                if (bt == null
                    && !TextUtils.isEmpty(mCategory)
                    && !mCategory.equals(UtilsConfig.IMAGE_CACHE_CATEGORY_RAW)) {
                  Bitmap rawBt = mImageCache.getResource(UtilsConfig.IMAGE_CACHE_CATEGORY_RAW, url);
                  if (rawBt != null && mBitmapOperationListener != null) {
                    bt = mBitmapOperationListener.onAfterBitmapDownload(rawBt);
                    if (bt != null) {
                      mImageCache.putResource(mCategory, url, bt);
                    }
                  }
                  mImageCache.releaseResource(UtilsConfig.IMAGE_CACHE_CATEGORY_RAW, url);
                }

                if (bt == null) {
                  registeHandler();
                  if (mCurrentDownloadRequest != null
                      && !url.equals(mCurrentDownloadRequest.getmDownloadUrl())) {
                    mCurrentDownloadRequest.cancelDownload();
                  }

                  if (mWebImageViewStatusListener != null) {
                    mHandler.post(
                        new Runnable() {
                          @Override
                          public void run() {
                            mWebImageViewStatusListener.onPreLoadImage(WebImageView.this, mUrl);
                          }
                        });
                  }

                  mCurrentDownloadRequest =
                      new ImageFetchRequest(
                          DownloadRequest.DOWNLOAD_TYPE.IMAGE,
                          url,
                          mCategory,
                          mBitmapOperationListener);
                  mImageDownloaer.postRequest(mCurrentDownloadRequest);
                } else {
                  Message msg = Message.obtain();
                  msg.what = LOCAL_LOAD_IMAGE_SUCCESS;
                  msg.obj = bt;
                  Bundle data = new Bundle();
                  data.putString(DATA_KEY_URL, url);
                  msg.setData(data);
                  mHandler.sendMessageDelayed(msg, 30);
                }
              }
            });

        if (mHasAnimation) {
          this.clearAnimation();
        }
        this.setImageDrawable(mDefaultSrc);
      } else {
        mCurrentBtLoadSuccess = true;
        setImageBitmap(bt, false);
      }
    }
  }