Esempio n. 1
0
  private void doDisplay(
      ImageView imageView,
      String uri,
      BitmapDisplayConfig displayConfig,
      CompressFormat compressFormat) {
    if (TextUtils.isEmpty(uri) || imageView == null) {
      return;
    }

    if (displayConfig == null) {
      displayConfig = globalConfig.getDefaultDisplayConfig();
    }

    Bitmap bitmap = null;

    bitmap = globalConfig.getBitmapCache().getBitmapFromMemCache(uri);

    if (bitmap != null) {
      imageView.setImageBitmap(bitmap);

    } else if (!bitmapLoadTaskExist(imageView, uri)) {

      final BitmapLoadTask loadTask = new BitmapLoadTask(imageView, displayConfig);
      // set loading image
      final AsyncBitmapDrawable asyncBitmapDrawable =
          new AsyncBitmapDrawable(
              context.getResources(), displayConfig.getLoadingBitmap(), loadTask);
      imageView.setImageDrawable(asyncBitmapDrawable);

      // load bitmap from uri or diskCache
      loadTask.executeOnExecutor(globalConfig.getBitmapLoadExecutor(), uri, compressFormat);
    }
  }
Esempio n. 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());
    }
  }