示例#1
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);
  }
 @Override
 public int getWidth() {
   return imageSize.getWidth();
 }