Skip to content

Commit a823163

Browse files
committed
CHanged API: Removed ImageLoaderConfiguration.offOutOfMemoryHandling().
Not handle OOM by default (but still catch).
1 parent d90d8d3 commit a823163

File tree

2 files changed

+2
-58
lines changed

2 files changed

+2
-58
lines changed

library/src/com/nostra13/universalimageloader/core/ImageLoaderConfiguration.java

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,6 @@
2525
import com.nostra13.universalimageloader.cache.disc.impl.UnlimitedDiscCache;
2626
import com.nostra13.universalimageloader.cache.disc.naming.FileNameGenerator;
2727
import com.nostra13.universalimageloader.cache.memory.MemoryCacheAware;
28-
import com.nostra13.universalimageloader.core.assist.FailReason;
29-
import com.nostra13.universalimageloader.core.assist.ImageLoadingListener;
3028
import com.nostra13.universalimageloader.core.assist.QueueProcessingType;
3129
import com.nostra13.universalimageloader.core.download.ImageDownloader;
3230
import com.nostra13.universalimageloader.core.download.NetworkDeniedImageDownloader;
@@ -64,7 +62,6 @@ public final class ImageLoaderConfiguration {
6462
final int threadPoolSize;
6563
final int threadPriority;
6664
final QueueProcessingType tasksProcessingType;
67-
final boolean handleOutOfMemory;
6865

6966
final MemoryCacheAware<String, Bitmap> memoryCache;
7067
final DiscCacheAware discCache;
@@ -89,7 +86,6 @@ private ImageLoaderConfiguration(final Builder builder) {
8986
threadPoolSize = builder.threadPoolSize;
9087
threadPriority = builder.threadPriority;
9188
tasksProcessingType = builder.tasksProcessingType;
92-
handleOutOfMemory = builder.handleOutOfMemory;
9389
discCache = builder.discCache;
9490
memoryCache = builder.memoryCache;
9591
defaultDisplayImageOptions = builder.defaultDisplayImageOptions;
@@ -168,7 +164,6 @@ public static class Builder {
168164
private int threadPoolSize = DEFAULT_THREAD_POOL_SIZE;
169165
private int threadPriority = DEFAULT_THREAD_PRIORITY;
170166
private boolean denyCacheImageMultipleSizesInMemory = false;
171-
private boolean handleOutOfMemory = true;
172167
private QueueProcessingType tasksProcessingType = DEFAULT_TASK_PROCESSING_TYPE;
173168

174169
private int memoryCacheSize = DEFAULT_MEMORY_CACHE_SIZE;
@@ -317,17 +312,6 @@ public Builder denyCacheImageMultipleSizesInMemory() {
317312
return this;
318313
}
319314

320-
/**
321-
* ImageLoader try clean memory and re-display image it self when {@link OutOfMemoryError} occurs. You can
322-
* switch off this feature by this method and process error by your way (you can know that
323-
* {@link OutOfMemoryError} occurred if you got {@link FailReason#OUT_OF_MEMORY} in
324-
* {@link ImageLoadingListener#onLoadingFailed(FailReason)}).
325-
*/
326-
public Builder offOutOfMemoryHandling() {
327-
this.handleOutOfMemory = false;
328-
return this;
329-
}
330-
331315
/**
332316
* Sets type of queue processing for tasks for loading and displaying images.<br />
333317
* Default value - {@link QueueProcessingType#FIFO}

library/src/com/nostra13/universalimageloader/core/LoadAndDisplayImageTask.java

Lines changed: 2 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@
4444
import android.graphics.Bitmap;
4545
import android.net.Uri;
4646
import android.os.Handler;
47-
import android.os.SystemClock;
4847
import android.widget.ImageView;
4948

5049
import com.nostra13.universalimageloader.cache.disc.DiscCacheAware;
@@ -69,7 +68,6 @@
6968
*/
7069
final class LoadAndDisplayImageTask implements Runnable {
7170

72-
private static final int ATTEMPT_COUNT_TO_DECODE_BITMAP = 3;
7371
private static final int BUFFER_SIZE = 8 * 1024; // 8 Kb
7472

7573
private static final String ALLOWED_URI_CHARS = "@#&=*+-_.,:!?()/~'%";
@@ -271,48 +269,10 @@ private Bitmap tryLoadBitmap() {
271269
}
272270

273271
private Bitmap decodeImage(URI imageUri) throws IOException {
274-
Bitmap bmp = null;
275-
276-
if (configuration.handleOutOfMemory) {
277-
bmp = decodeWithOOMHandling(imageUri);
278-
} else {
279-
ImageDecoder decoder = new ImageDecoder(imageUri, getDownloader(), options);
280-
decoder.setLoggingEnabled(loggingEnabled);
281-
ViewScaleType viewScaleType = ViewScaleType.fromImageView(imageView);
282-
bmp = decoder.decode(targetSize, options.getImageScaleType(), viewScaleType);
283-
}
284-
return bmp;
285-
}
286-
287-
private Bitmap decodeWithOOMHandling(URI imageUri) throws IOException {
288-
Bitmap result = null;
289272
ImageDecoder decoder = new ImageDecoder(imageUri, getDownloader(), options);
290273
decoder.setLoggingEnabled(loggingEnabled);
291-
for (int attempt = 1; attempt <= ATTEMPT_COUNT_TO_DECODE_BITMAP; attempt++) {
292-
try {
293-
ViewScaleType viewScaleType = ViewScaleType.fromImageView(imageView);
294-
result = decoder.decode(targetSize, options.getImageScaleType(), viewScaleType);
295-
} catch (OutOfMemoryError e) {
296-
L.e(e);
297-
298-
switch (attempt) {
299-
case 1:
300-
System.gc();
301-
break;
302-
case 2:
303-
configuration.memoryCache.clear();
304-
System.gc();
305-
break;
306-
case 3:
307-
throw e;
308-
}
309-
// Wait some time while GC is working
310-
SystemClock.sleep(attempt * 1000);
311-
continue;
312-
}
313-
break;
314-
}
315-
return result;
274+
ViewScaleType viewScaleType = ViewScaleType.fromImageView(imageView);
275+
return decoder.decode(targetSize, options.getImageScaleType(), viewScaleType);
316276
}
317277

318278
private void saveImageOnDisc(File targetFile) throws IOException, URISyntaxException {

0 commit comments

Comments
 (0)