Skip to content

Commit 645effe

Browse files
committed
Added imageTargetSize to displayImage method
1 parent 3acca4a commit 645effe

File tree

1 file changed

+48
-1
lines changed

1 file changed

+48
-1
lines changed

library/src/main/java/com/nostra13/universalimageloader/core/ImageLoader.java

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,34 @@ public void displayImage(String uri, ImageAware imageAware, DisplayImageOptions
204204
* @throws IllegalArgumentException if passed <b>imageAware</b> is null
205205
*/
206206
public void displayImage(String uri, ImageAware imageAware, DisplayImageOptions options,
207+
ImageLoadingListener listener, ImageLoadingProgressListener progressListener) {
208+
displayImage(uri,imageAware,options,null,listener,progressListener);
209+
}
210+
211+
/**
212+
* Adds display image task to execution pool. Image will be set to ImageAware when it's turn.<br />
213+
* <b>NOTE:</b> {@link #init(ImageLoaderConfiguration)} method must be called before this method call
214+
*
215+
* @param uri Image URI (i.e. "http://site.com/image.png", "file:///mnt/sdcard/image.png")
216+
* @param imageAware {@linkplain com.nostra13.universalimageloader.core.imageaware.ImageAware Image aware view}
217+
* which should display image
218+
* @param options {@linkplain com.nostra13.universalimageloader.core.DisplayImageOptions Options} for image
219+
* decoding and displaying. If <b>null</b> - default display image options
220+
* {@linkplain ImageLoaderConfiguration.Builder#defaultDisplayImageOptions(DisplayImageOptions)
221+
* from configuration} will be used.
222+
* @param targetImageSize {@linkplain ImageSize} Image target size. If <b>null</b> - size will depend on the view
223+
* @param listener {@linkplain ImageLoadingListener Listener} for image loading process. Listener fires
224+
* events on UI thread if this method is called on UI thread.
225+
* @param progressListener {@linkplain com.nostra13.universalimageloader.core.listener.ImageLoadingProgressListener
226+
* Listener} for image loading progress. Listener fires events on UI thread if this method
227+
* is called on UI thread. Caching on disk should be enabled in
228+
* {@linkplain com.nostra13.universalimageloader.core.DisplayImageOptions options} to make
229+
* this listener work.
230+
* @throws IllegalStateException if {@link #init(ImageLoaderConfiguration)} method wasn't called before
231+
* @throws IllegalArgumentException if passed <b>imageAware</b> is null
232+
*/
233+
public void displayImage(String uri, ImageAware imageAware, DisplayImageOptions options,
234+
ImageSize targetImageSize,
207235
ImageLoadingListener listener, ImageLoadingProgressListener progressListener) {
208236
checkConfiguration();
209237
if (imageAware == null) {
@@ -228,7 +256,12 @@ public void displayImage(String uri, ImageAware imageAware, DisplayImageOptions
228256
return;
229257
}
230258

231-
ImageSize targetSize = ImageSizeUtils.defineTargetSizeForView(imageAware, configuration.getMaxImageSize());
259+
ImageSize targetSize;
260+
if (targetImageSize != null) {
261+
targetSize = targetImageSize;
262+
}else {
263+
targetSize = ImageSizeUtils.defineTargetSizeForView(imageAware, configuration.getMaxImageSize());
264+
}
232265
String memoryCacheKey = MemoryCacheUtils.generateKey(uri, targetSize);
233266
engine.prepareDisplayTaskFor(imageAware, memoryCacheKey);
234267

@@ -286,6 +319,20 @@ public void displayImage(String uri, ImageView imageView) {
286319
displayImage(uri, new ImageViewAware(imageView), null, null, null);
287320
}
288321

322+
/**
323+
* Adds display image task to execution pool. Image will be set to ImageView when it's turn. <br/>
324+
* Default {@linkplain DisplayImageOptions display image options} from {@linkplain ImageLoaderConfiguration
325+
* configuration} will be used.<br />
326+
* <b>NOTE:</b> {@link #init(ImageLoaderConfiguration)} method must be called before this method call
327+
*
328+
* @param uri Image URI (i.e. "http://site.com/image.png", "file:///mnt/sdcard/image.png")
329+
* @param imageView {@link ImageView} which should display image
330+
* @throws IllegalStateException if {@link #init(ImageLoaderConfiguration)} method wasn't called before
331+
* @throws IllegalArgumentException if passed <b>imageView</b> is null
332+
*/
333+
public void displayImage(String uri, ImageView imageView, ImageSize targetImageSize) {
334+
displayImage(uri, new ImageViewAware(imageView), null, targetImageSize, null, null);
335+
}
289336
/**
290337
* Adds display image task to execution pool. Image will be set to ImageView when it's turn.<br />
291338
* <b>NOTE:</b> {@link #init(ImageLoaderConfiguration)} method must be called before this method call

0 commit comments

Comments
 (0)