Beispiel #1
0
 @Override
 protected void onPostExecute(Bitmap bitmap) {
   final T container = this.getTargetContainer();
   if (container != null) {
     if (bitmap != null) {
       callBack.onLoadCompleted(container, this.uri, bitmap, displayConfig, from);
     } else {
       callBack.onLoadFailed(container, this.uri, displayConfig.getLoadFailedDrawable());
     }
   }
 }
Beispiel #2
0
  public <T extends View> void display(
      T container, String uri, BitmapDisplayConfig displayConfig, BitmapLoadCallBack<T> callBack) {
    if (container == null) {
      return;
    }

    container.clearAnimation();

    if (callBack == null) {
      callBack = new SimpleBitmapLoadCallBack<T>();
    }

    if (displayConfig == null || displayConfig == defaultDisplayConfig) {
      displayConfig = defaultDisplayConfig.cloneNew();
    }

    // Optimize Max Size
    BitmapSize size = displayConfig.getBitmapMaxSize();
    displayConfig.setBitmapMaxSize(
        BitmapCommonUtils.optimizeMaxSizeByView(container, size.getWidth(), size.getHeight()));

    callBack.onPreLoad(container, uri, displayConfig);

    if (TextUtils.isEmpty(uri)) {
      callBack.onLoadFailed(container, uri, displayConfig.getLoadFailedDrawable());
      return;
    }

    Bitmap bitmap = globalConfig.getBitmapCache().getBitmapFromMemCache(uri, displayConfig);

    if (bitmap != null) {
      callBack.onLoadStarted(container, uri, displayConfig);
      callBack.onLoadCompleted(container, uri, bitmap, displayConfig, BitmapLoadFrom.MEMORY_CACHE);
    } else if (!bitmapLoadTaskExist(container, uri, callBack)) {

      final BitmapLoadTask<T> loadTask =
          new BitmapLoadTask<T>(container, uri, displayConfig, callBack);
      // set loading image
      final AsyncDrawable<T> asyncDrawable =
          new AsyncDrawable<T>(displayConfig.getLoadingDrawable(), loadTask);
      callBack.setDrawable(container, asyncDrawable);

      // load bitmap from uri or diskCache
      loadTask.executeOnExecutor(globalConfig.getBitmapLoadExecutor());
    }
  }
Beispiel #3
0
    @Override
    protected void onProgressUpdate(Object... values) {
      if (values == null || values.length < 1) return;

      final T container = this.getTargetContainer();
      if (container == null) return;

      switch ((Integer) values[0]) {
        case PROGRESS_LOAD_STARTED:
          callBack.onLoadStarted(container, uri, displayConfig);
          break;
        case PROGRESS_LOADING:
          if (values.length != 3) return;
          callBack.onLoading(container, uri, displayConfig, (Long) values[1], (Long) values[2]);
          break;
        default:
          break;
      }
    }
Beispiel #4
0
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.image);

    ViewUtils.inject(this);

    String imgUrl = getIntent().getStringExtra("url");

    bitmapUtils = BitmapFragment.bitmapUtils;
    if (bitmapUtils == null) {
      bitmapUtils = BitmapHelp.getBitmapUtils(this.getApplicationContext());
    }

    bigPicDisplayConfig = new BitmapDisplayConfig();
    // bigPicDisplayConfig.setShowOriginal(true); // 显示原始图片,不压缩, 尽量不要使用, 图片太大时容易OOM。
    bigPicDisplayConfig.setBitmapConfig(Bitmap.Config.RGB_565);
    bigPicDisplayConfig.setBitmapMaxSize(BitmapCommonUtils.getScreenSize(this));

    BitmapLoadCallBack<ImageView> callback =
        new SimpleBitmapLoadCallBack<ImageView>() {
          @Override
          public void onLoadStarted(ImageView container, String uri, BitmapDisplayConfig config) {
            super.onLoadStarted(container, uri, config);
            Toast.makeText(getApplicationContext(), uri, 300).show();
          }

          @Override
          public void onLoadCompleted(
              ImageView container,
              String url,
              Bitmap bitmap,
              BitmapDisplayConfig config,
              BitmapLoadFrom from) {
            super.onLoadCompleted(container, url, bitmap, config, from);
            Toast.makeText(
                    getApplicationContext(), bitmap.getWidth() + "*" + bitmap.getHeight(), 300)
                .show();
          }
        };
    callback.setBitmapSetter(BitmapCommonUtils.sDefaultImageViewSetter);

    bitmapUtils.display(bigImage, imgUrl, bigPicDisplayConfig, callback);
  }
Beispiel #5
0
 @SuppressWarnings("unchecked")
 private static <T extends View> BitmapLoadTask<T> getBitmapTaskFromContainer(
     T container, BitmapLoadCallBack<T> callBack) {
   if (container != null) {
     final Drawable drawable = callBack.getDrawable(container);
     if (drawable instanceof AsyncDrawable) {
       final AsyncDrawable<T> asyncDrawable = (AsyncDrawable<T>) drawable;
       return asyncDrawable.getBitmapWorkerTask();
     }
   }
   return null;
 }