22
22
import com .nostra13 .universalimageloader .cache .disc .DiscCacheAware ;
23
23
import com .nostra13 .universalimageloader .cache .memory .MemoryCacheAware ;
24
24
import com .nostra13 .universalimageloader .core .assist .*;
25
- import com .nostra13 .universalimageloader .core .imageaware .ImageNonViewAware ;
26
25
import com .nostra13 .universalimageloader .core .imageaware .ImageAware ;
26
+ import com .nostra13 .universalimageloader .core .imageaware .ImageNonViewAware ;
27
27
import com .nostra13 .universalimageloader .core .imageaware .ImageViewAware ;
28
28
import com .nostra13 .universalimageloader .utils .ImageSizeUtils ;
29
29
import com .nostra13 .universalimageloader .utils .L ;
@@ -140,8 +140,8 @@ public void displayImage(String uri, ImageAware imageAware, ImageLoadingListener
140
140
* @param uri Image URI (i.e. "http://site.com/image.png", "file:///mnt/sdcard/image.png")
141
141
* @param imageAware {@linkplain com.nostra13.universalimageloader.core.imageaware.ImageAware Image aware view}
142
142
* which should display image
143
- * @param options {@linkplain DisplayImageOptions Display image options } for image displaying. If <b>null</b> -
144
- * default display image options
143
+ * @param options {@linkplain com.nostra13.universalimageloader.core. DisplayImageOptions Options } for image
144
+ * decoding and displaying. If <b>null</b> - default display image options
145
145
* {@linkplain ImageLoaderConfiguration.Builder#defaultDisplayImageOptions(DisplayImageOptions) from
146
146
* configuration} will be used.
147
147
* @throws IllegalStateException if {@link #init(ImageLoaderConfiguration)} method wasn't called before
@@ -158,8 +158,8 @@ public void displayImage(String uri, ImageAware imageAware, DisplayImageOptions
158
158
* @param uri Image URI (i.e. "http://site.com/image.png", "file:///mnt/sdcard/image.png")
159
159
* @param imageAware {@linkplain com.nostra13.universalimageloader.core.imageaware.ImageAware Image aware view}
160
160
* which should display image
161
- * @param options {@linkplain DisplayImageOptions Display image options } for image displaying. If <b>null</b> -
162
- * default display image options
161
+ * @param options {@linkplain com.nostra13.universalimageloader.core. DisplayImageOptions Options } for image
162
+ * decoding and displaying. If <b>null</b> - default display image options
163
163
* {@linkplain ImageLoaderConfiguration.Builder#defaultDisplayImageOptions(DisplayImageOptions) from
164
164
* configuration} will be used.
165
165
* @param listener {@linkplain ImageLoadingListener Listener} for image loading process. Listener fires events on UI
@@ -206,7 +206,11 @@ public void displayImage(String uri, ImageAware imageAware, DisplayImageOptions
206
206
.getLockForUri (uri ));
207
207
ProcessAndDisplayImageTask displayTask = new ProcessAndDisplayImageTask (engine , bmp , imageLoadingInfo , options
208
208
.getHandler ());
209
- engine .submit (displayTask );
209
+ if (options .isSyncLoading ()) {
210
+ displayTask .run ();
211
+ } else {
212
+ engine .submit (displayTask );
213
+ }
210
214
} else {
211
215
bmp = options .getDisplayer ().display (bmp , imageAware , LoadedFrom .MEMORY_CACHE );
212
216
listener .onLoadingComplete (uri , imageAware .getWrappedView (), bmp );
@@ -222,7 +226,11 @@ public void displayImage(String uri, ImageAware imageAware, DisplayImageOptions
222
226
.getLockForUri (uri ));
223
227
LoadAndDisplayImageTask displayTask = new LoadAndDisplayImageTask (engine , imageLoadingInfo , options
224
228
.getHandler ());
225
- engine .submit (displayTask );
229
+ if (options .isSyncLoading ()) {
230
+ displayTask .run ();
231
+ } else {
232
+ engine .submit (displayTask );
233
+ }
226
234
}
227
235
}
228
236
@@ -247,8 +255,8 @@ public void displayImage(String uri, ImageView imageView) {
247
255
*
248
256
* @param uri Image URI (i.e. "http://site.com/image.png", "file:///mnt/sdcard/image.png")
249
257
* @param imageView {@link ImageView} which should display image
250
- * @param options {@linkplain DisplayImageOptions Display image options } for image displaying. If <b>null</b> -
251
- * default display image options
258
+ * @param options {@linkplain com.nostra13.universalimageloader.core. DisplayImageOptions Options } for image
259
+ * decoding and displaying. If <b>null</b> - default display image options
252
260
* {@linkplain ImageLoaderConfiguration.Builder#defaultDisplayImageOptions(DisplayImageOptions) from
253
261
* configuration} will be used.
254
262
* @throws IllegalStateException if {@link #init(ImageLoaderConfiguration)} method wasn't called before
@@ -281,8 +289,8 @@ public void displayImage(String uri, ImageView imageView, ImageLoadingListener l
281
289
*
282
290
* @param uri Image URI (i.e. "http://site.com/image.png", "file:///mnt/sdcard/image.png")
283
291
* @param imageView {@link ImageView} which should display image
284
- * @param options {@linkplain DisplayImageOptions Display image options } for image displaying. If <b>null</b> -
285
- * default display image options
292
+ * @param options {@linkplain com.nostra13.universalimageloader.core. DisplayImageOptions Options } for image
293
+ * decoding and displaying. If <b>null</b> - default display image options
286
294
* {@linkplain ImageLoaderConfiguration.Builder#defaultDisplayImageOptions(DisplayImageOptions) from
287
295
* configuration} will be used.
288
296
* @param listener {@linkplain ImageLoadingListener Listener} for image loading process. Listener fires events on UI
@@ -314,17 +322,17 @@ public void loadImage(String uri, ImageLoadingListener listener) {
314
322
* {@link ImageLoadingListener#onLoadingComplete(String, android.view.View, android.graphics.Bitmap)} callback}.<br />
315
323
* <b>NOTE:</b> {@link #init(ImageLoaderConfiguration)} method must be called before this method call
316
324
*
317
- * @param uri Image URI (i.e. "http://site.com/image.png", "file:///mnt/sdcard/image.png")
318
- * @param minImageSize Minimal size for {@link Bitmap} which will be returned in
319
- * {@linkplain ImageLoadingListener#onLoadingComplete(String, android.view.View, android.graphics.Bitmap)} callback}. Downloaded image will be decoded
320
- * and scaled to {@link Bitmap} of the size which is <b>equal or larger</b> (usually a bit larger) than
321
- * incoming minImageSize .
322
- * @param listener {@linkplain ImageLoadingListener Listener} for image loading process. Listener fires events on UI
323
- * thread.
325
+ * @param uri Image URI (i.e. "http://site.com/image.png", "file:///mnt/sdcard/image.png")
326
+ * @param targetImageSize Minimal size for {@link Bitmap} which will be returned in
327
+ * {@linkplain ImageLoadingListener#onLoadingComplete(String, android.view.View, android.graphics.Bitmap)} callback}. Downloaded image will be decoded
328
+ * and scaled to {@link Bitmap} of the size which is <b>equal or larger</b> (usually a bit larger) than
329
+ * incoming targetImageSize .
330
+ * @param listener {@linkplain ImageLoadingListener Listener} for image loading process. Listener fires events on UI
331
+ * thread.
324
332
* @throws IllegalStateException if {@link #init(ImageLoaderConfiguration)} method wasn't called before
325
333
*/
326
- public void loadImage (String uri , ImageSize minImageSize , ImageLoadingListener listener ) {
327
- loadImage (uri , minImageSize , null , listener );
334
+ public void loadImage (String uri , ImageSize targetImageSize , ImageLoadingListener listener ) {
335
+ loadImage (uri , targetImageSize , null , listener );
328
336
}
329
337
330
338
/**
@@ -333,8 +341,8 @@ public void loadImage(String uri, ImageSize minImageSize, ImageLoadingListener l
333
341
* <b>NOTE:</b> {@link #init(ImageLoaderConfiguration)} method must be called before this method call
334
342
*
335
343
* @param uri Image URI (i.e. "http://site.com/image.png", "file:///mnt/sdcard/image.png")
336
- * @param options {@linkplain DisplayImageOptions Display image options } for image displaying. If <b>null</b> -
337
- * default display image options
344
+ * @param options {@linkplain com.nostra13.universalimageloader.core. DisplayImageOptions Options } for image
345
+ * decoding and displaying. If <b>null</b> - default display image options
338
346
* {@linkplain ImageLoaderConfiguration.Builder#defaultDisplayImageOptions(DisplayImageOptions) from
339
347
* configuration} will be used.<br />
340
348
* @param listener {@linkplain ImageLoadingListener Listener} for image loading process. Listener fires events on UI
@@ -354,9 +362,9 @@ public void loadImage(String uri, DisplayImageOptions options, ImageLoadingListe
354
362
* @param targetImageSize Minimal size for {@link Bitmap} which will be returned in
355
363
* {@linkplain ImageLoadingListener#onLoadingComplete(String, android.view.View, android.graphics.Bitmap)} callback}. Downloaded image will be decoded
356
364
* and scaled to {@link Bitmap} of the size which is <b>equal or larger</b> (usually a bit larger) than
357
- * incoming minImageSize .
358
- * @param options {@linkplain DisplayImageOptions Display image options } for image displaying. If <b>null</b> -
359
- * default display image options
365
+ * incoming targetImageSize .
366
+ * @param options {@linkplain com.nostra13.universalimageloader.core. DisplayImageOptions Options } for image
367
+ * decoding and displaying. If <b>null</b> - default display image options
360
368
* {@linkplain ImageLoaderConfiguration.Builder#defaultDisplayImageOptions(DisplayImageOptions) from
361
369
* configuration} will be used.<br />
362
370
* @param listener {@linkplain ImageLoadingListener Listener} for image loading process. Listener fires events on UI
@@ -377,6 +385,81 @@ public void loadImage(String uri, ImageSize targetImageSize, DisplayImageOptions
377
385
displayImage (uri , imageAware , options , listener );
378
386
}
379
387
388
+ /**
389
+ * Loads and decodes image synchronously.<br />
390
+ * Default display image options
391
+ * {@linkplain ImageLoaderConfiguration.Builder#defaultDisplayImageOptions(DisplayImageOptions) from
392
+ * configuration} will be used.<br />
393
+ * <b>NOTE:</b> {@link #init(ImageLoaderConfiguration)} method must be called before this method call
394
+ *
395
+ * @param uri Image URI (i.e. "http://site.com/image.png", "file:///mnt/sdcard/image.png")
396
+ * @return Result image Bitmap. Can be <b>null</b> if image loading/decoding was failed or cancelled.
397
+ * @throws IllegalStateException if {@link #init(ImageLoaderConfiguration)} method wasn't called before
398
+ */
399
+ public Bitmap loadImageSync (String uri ) {
400
+ return loadImageSync (uri , null , null );
401
+ }
402
+
403
+ /**
404
+ * Loads and decodes image synchronously.<br />
405
+ * <b>NOTE:</b> {@link #init(ImageLoaderConfiguration)} method must be called before this method call
406
+ *
407
+ * @param uri Image URI (i.e. "http://site.com/image.png", "file:///mnt/sdcard/image.png")
408
+ * @param options {@linkplain com.nostra13.universalimageloader.core.DisplayImageOptions Options} for image
409
+ * decoding and scaling. If <b>null</b> - default display image options
410
+ * {@linkplain ImageLoaderConfiguration.Builder#defaultDisplayImageOptions(DisplayImageOptions) from
411
+ * configuration} will be used.
412
+ * @return Result image Bitmap. Can be <b>null</b> if image loading/decoding was failed or cancelled.
413
+ * @throws IllegalStateException if {@link #init(ImageLoaderConfiguration)} method wasn't called before
414
+ */
415
+ public Bitmap loadImageSync (String uri , DisplayImageOptions options ) {
416
+ return loadImageSync (uri , null , options );
417
+ }
418
+
419
+ /**
420
+ * Loads and decodes image synchronously.<br />
421
+ * Default display image options
422
+ * {@linkplain ImageLoaderConfiguration.Builder#defaultDisplayImageOptions(DisplayImageOptions) from
423
+ * configuration} will be used.<br />
424
+ * <b>NOTE:</b> {@link #init(ImageLoaderConfiguration)} method must be called before this method call
425
+ *
426
+ * @param uri Image URI (i.e. "http://site.com/image.png", "file:///mnt/sdcard/image.png")
427
+ * @param targetImageSize Minimal size for {@link Bitmap} which will be returned. Downloaded image will be decoded
428
+ * and scaled to {@link Bitmap} of the size which is <b>equal or larger</b> (usually a bit
429
+ * larger) than incoming targetImageSize.
430
+ * @return Result image Bitmap. Can be <b>null</b> if image loading/decoding was failed or cancelled.
431
+ * @throws IllegalStateException if {@link #init(ImageLoaderConfiguration)} method wasn't called before
432
+ */
433
+ public Bitmap loadImageSync (String uri , ImageSize targetImageSize ) {
434
+ return loadImageSync (uri , targetImageSize , null );
435
+ }
436
+
437
+ /**
438
+ * Loads and decodes image synchronously.<br />
439
+ * <b>NOTE:</b> {@link #init(ImageLoaderConfiguration)} method must be called before this method call
440
+ *
441
+ * @param uri Image URI (i.e. "http://site.com/image.png", "file:///mnt/sdcard/image.png")
442
+ * @param targetImageSize Minimal size for {@link Bitmap} which will be returned. Downloaded image will be decoded
443
+ * and scaled to {@link Bitmap} of the size which is <b>equal or larger</b> (usually a bit
444
+ * larger) than incoming targetImageSize.
445
+ * @param options {@linkplain com.nostra13.universalimageloader.core.DisplayImageOptions Options} for image
446
+ * decoding and scaling. If <b>null</b> - default display image options
447
+ * {@linkplain ImageLoaderConfiguration.Builder#defaultDisplayImageOptions(DisplayImageOptions) from
448
+ * configuration} will be used.
449
+ * @return Result image Bitmap. Can be <b>null</b> if image loading/decoding was failed or cancelled.
450
+ * @throws IllegalStateException if {@link #init(ImageLoaderConfiguration)} method wasn't called before
451
+ */
452
+ public Bitmap loadImageSync (String uri , ImageSize targetImageSize , DisplayImageOptions options ) {
453
+ if (options == null ) {
454
+ options = configuration .defaultDisplayImageOptions ;
455
+ }
456
+ options = new DisplayImageOptions .Builder ().cloneFrom (options ).syncLoading (true ).build ();
457
+
458
+ SyncImageLoadingListener listener = new SyncImageLoadingListener ();
459
+ loadImage (uri , targetImageSize , options , listener );
460
+ return listener .getLoadedBitmap ();
461
+ }
462
+
380
463
/**
381
464
* Checks if ImageLoader's configuration was initialized
382
465
*
0 commit comments