/**
   * Adds load image task to execution pool. Image will be returned with {@link
   * ImageLoadingListener#onLoadingComplete(String, android.view.View, android.graphics.Bitmap)}
   * callback}. <br>
   * <b>NOTE:</b> {@link #init(ImageLoaderConfiguration)} method must be called before this method
   * call
   *
   * @param uri Image URI (i.e. "http://site.com/image.png", "file:///mnt/sdcard/image.png")
   * @param targetImageSize Minimal size for {@link Bitmap} which will be returned in {@linkplain
   *     ImageLoadingListener#onLoadingComplete(String, android.view.View, android.graphics.Bitmap)}
   *     callback}. Downloaded image will be decoded and scaled to {@link Bitmap} of the size which
   *     is <b>equal or larger</b> (usually a bit larger) than incoming targetImageSize.
   * @param options {@linkplain com.nostra13.universalimageloader.core.DisplayImageOptions Options}
   *     for image decoding and displaying. If <b>null</b> - default display image options
   *     {@linkplain
   *     ImageLoaderConfiguration.Builder#defaultDisplayImageOptions(DisplayImageOptions) from
   *     configuration} will be used.<br>
   * @param listener {@linkplain ImageLoadingListener Listener} for image loading process. Listener
   *     fires events on UI thread if this method is called on UI thread.
   * @param progressListener {@linkplain
   *     com.nostra13.universalimageloader.core.listener.ImageLoadingProgressListener Listener} for
   *     image loading progress. Listener fires events on UI thread if this method is called on UI
   *     thread. Caching on disk should be enabled in {@linkplain
   *     com.nostra13.universalimageloader.core.DisplayImageOptions options} to make this listener
   *     work.
   * @throws IllegalStateException if {@link #init(ImageLoaderConfiguration)} method wasn't called
   *     before
   */
  public void loadImage(
      String uri,
      ImageSize targetImageSize,
      DisplayImageOptions options,
      ImageLoadingListener listener,
      ImageLoadingProgressListener progressListener) {
    checkConfiguration();
    if (targetImageSize == null) {
      targetImageSize = configuration.getMaxImageSize();
    }
    if (options == null) {
      options = configuration.defaultDisplayImageOptions;
    }

    NonViewAware imageAware = new NonViewAware(uri, targetImageSize, ViewScaleType.CROP);
    displayImage(uri, imageAware, options, listener, progressListener);
  }
Пример #2
0
  /**
   * Adds load image task to execution pool. Image will be returned with {@link
   * ImageLoadingListener#onLoadingComplete(String, android.view.View, android.graphics.Bitmap)}
   * callback}.<br>
   * <b>NOTE:</b> {@link #init(ImageLoaderConfiguration)} method must be called before this method
   * call
   *
   * @param uri Image URI (i.e. "http://site.com/image.png", "file:///mnt/sdcard/image.png")
   * @param targetImageSize Minimal size for {@link Bitmap} which will be returned in {@linkplain
   *     ImageLoadingListener#onLoadingComplete(String, android.view.View, android.graphics.Bitmap)}
   *     callback}. Downloaded image will be decoded and scaled to {@link Bitmap} of the size which
   *     is <b>equal or larger</b> (usually a bit larger) than incoming minImageSize .
   * @param options {@linkplain DisplayImageOptions Display image options} for image displaying. If
   *     <b>null</b> - default display image options {@linkplain
   *     ImageLoaderConfiguration.Builder#defaultDisplayImageOptions(DisplayImageOptions) from
   *     configuration} will be used.<br>
   *     Incoming options should contain {@link FakeBitmapDisplayer} as displayer.
   * @param listener {@linkplain ImageLoadingListener Listener} for image loading process. Listener
   *     fires events on UI thread.
   * @throws IllegalStateException if {@link #init(ImageLoaderConfiguration)} method wasn't called
   *     before
   */
  public void loadImage(
      String uri,
      ImageSize targetImageSize,
      DisplayImageOptions options,
      ImageLoadingListener listener) {
    checkConfiguration();

    if (targetImageSize == null) {
      targetImageSize =
          new ImageSize(
              configuration.maxImageWidthForMemoryCache,
              configuration.maxImageHeightForMemoryCache);
    }

    if (options == null) {
      options = configuration.defaultDisplayImageOptions;
    }

    DisplayImageOptions optionsWithFakeDisplayer;

    if (options.getDisplayer() instanceof FakeBitmapDisplayer) {
      optionsWithFakeDisplayer = options;

    } else {
      optionsWithFakeDisplayer =
          new DisplayImageOptions.Builder()
              .cloneFrom(options)
              .displayer(fakeBitmapDisplayer)
              .build();
    }

    ImageView fakeImage = new ImageView(configuration.context);
    fakeImage.setLayoutParams(
        new LayoutParams(targetImageSize.getWidth(), targetImageSize.getHeight()));
    fakeImage.setScaleType(ScaleType.CENTER_CROP);

    displayImage(uri, fakeImage, optionsWithFakeDisplayer, listener);
  }
Пример #3
0
 /**
  * Clears disc cache.
  *
  * @throws IllegalStateException if {@link #init(ImageLoaderConfiguration)} method wasn't called
  *     before
  */
 public void clearDiscCache() {
   checkConfiguration();
   configuration.discCache.clear();
 }
Пример #4
0
 /**
  * Returns disc cache
  *
  * @throws IllegalStateException if {@link #init(ImageLoaderConfiguration)} method wasn't called
  *     before
  */
 public DiscCacheAware getDiscCache() {
   checkConfiguration();
   return configuration.discCache;
 }
Пример #5
0
 /**
  * Clears memory cache
  *
  * @throws IllegalStateException if {@link #init(ImageLoaderConfiguration)} method wasn't called
  *     before
  */
 public void clearMemoryCache() {
   checkConfiguration();
   configuration.memoryCache.clear();
 }
Пример #6
0
 /**
  * Returns memory cache
  *
  * @throws IllegalStateException if {@link #init(ImageLoaderConfiguration)} method wasn't called
  *     before
  */
 public MemoryCacheAware<String, Bitmap> getMemoryCache() {
   checkConfiguration();
   return configuration.memoryCache;
 }
Пример #7
0
  /**
   * Adds display image task to execution pool. Image will be set to ImageView when it's turn.<br>
   * <b>NOTE:</b> {@link #init(ImageLoaderConfiguration)} method must be called before this method
   * call
   *
   * @param uri Image URI (i.e. "http://site.com/image.png", "file:///mnt/sdcard/image.png")
   * @param imageView {@link ImageView} which should display image
   * @param options {@linkplain DisplayImageOptions Display image options} for image displaying. If
   *     <b>null</b> - default display image options {@linkplain
   *     ImageLoaderConfiguration.Builder#defaultDisplayImageOptions(DisplayImageOptions) from
   *     configuration} will be used.
   * @param listener {@linkplain ImageLoadingListener Listener} for image loading process. Listener
   *     fires events on UI thread.
   * @throws IllegalStateException if {@link #init(ImageLoaderConfiguration)} method wasn't called
   *     before
   * @throws IllegalArgumentException if passed <b>imageView</b> is null
   */
  public void displayImage(
      String uri, ImageView imageView, DisplayImageOptions options, ImageLoadingListener listener) {
    checkConfiguration();

    if (imageView == null) {
      throw new IllegalArgumentException(ERROR_WRONG_ARGUMENTS);
    }

    if (listener == null) {
      listener = emptyListener;
    }

    if (options == null) {
      options = configuration.defaultDisplayImageOptions;
    }

    if (TextUtils.isEmpty(uri)) {
      engine.cancelDisplayTaskFor(imageView);
      listener.onLoadingStarted(uri, imageView);

      if (options.shouldShowImageResForEmptyUri()) {
        imageView.setImageResource(options.getImageResForEmptyUri());

      } else if (options.shouldShowImageForEmptyUri()) {
        imageView.setImageDrawable(options.getImageForEmptyUri());

      } else {
        imageView.setImageDrawable(null);
      }

      listener.onLoadingComplete(uri, imageView, null);
      return;
    }

    ImageSize targetSize =
        ImageSizeUtils.defineTargetSizeForView(
            imageView,
            configuration.maxImageWidthForMemoryCache,
            configuration.maxImageHeightForMemoryCache);
    String memoryCacheKey = MemoryCacheUtil.generateKey(uri, targetSize);
    engine.prepareDisplayTaskFor(imageView, memoryCacheKey);

    listener.onLoadingStarted(uri, imageView);
    Bitmap bmp = configuration.memoryCache.get(memoryCacheKey);

    if (bmp != null && !bmp.isRecycled()) {
      if (configuration.writeLogs) {
        L.d(LOG_LOAD_IMAGE_FROM_MEMORY_CACHE, memoryCacheKey);
      }

      if (options.shouldPostProcess()) {
        ImageLoadingInfo imageLoadingInfo =
            new ImageLoadingInfo(
                uri,
                imageView,
                targetSize,
                memoryCacheKey,
                options,
                listener,
                engine.getLockForUri(uri));
        ProcessAndDisplayImageTask displayTask =
            new ProcessAndDisplayImageTask(engine, bmp, imageLoadingInfo, options.getHandler());
        engine.submit(displayTask);

      } else {
        options.getDisplayer().display(bmp, imageView, LoadedFrom.MEMORY_CACHE);
        listener.onLoadingComplete(uri, imageView, bmp);
      }

    } else {
      if (options.shouldShowImageResOnLoading()) {
        imageView.setImageResource(options.getImageResOnLoading());

      } else if (options.shouldShowImageOnLoading()) {
        imageView.setImageDrawable(options.getImageOnLoading());

      } else {
        if (options.isResetViewBeforeLoading()) {
          imageView.setImageDrawable(null);
        }
      }

      ImageLoadingInfo imageLoadingInfo =
          new ImageLoadingInfo(
              uri,
              imageView,
              targetSize,
              memoryCacheKey,
              options,
              listener,
              engine.getLockForUri(uri));
      LoadAndDisplayImageTask displayTask =
          new LoadAndDisplayImageTask(engine, imageLoadingInfo, options.getHandler());
      engine.submit(displayTask);
    }
  }
 /**
  * Returns memory cache
  *
  * @throws IllegalStateException if {@link #init(ImageLoaderConfiguration)} method wasn't called
  *     before
  */
 public MemoryCache getMemoryCache() {
   checkConfiguration();
   return configuration.memoryCache;
 }