diff options
author | Andrew Dolgov <[email protected]> | 2012-12-03 12:20:05 +0300 |
---|---|---|
committer | Andrew Dolgov <[email protected]> | 2012-12-03 12:20:05 +0300 |
commit | bba178394e160c514430b7170d2b46e6b6f72879 (patch) | |
tree | 81b3635cef40beb4c86c20b4a9f57c35a9778550 /src | |
parent | df1fc6033a7997e49f4cf284b122641352c1e5ae (diff) |
try several downsampling sizes if OOM detected
Diffstat (limited to 'src')
-rw-r--r-- | src/org/fox/ttcomics/ComicFragment.java | 38 |
1 files changed, 25 insertions, 13 deletions
diff --git a/src/org/fox/ttcomics/ComicFragment.java b/src/org/fox/ttcomics/ComicFragment.java index 4c5ce9c..7b324dc 100644 --- a/src/org/fox/ttcomics/ComicFragment.java +++ b/src/org/fox/ttcomics/ComicFragment.java @@ -44,21 +44,33 @@ public class ComicFragment extends Fragment implements GestureDetector.OnDoubleT final BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = true;
BitmapFactory.decodeStream(archive.getItem(page), null, options);
-
- if (CommonActivity.isCompatMode()) {
- options.inSampleSize = CommonActivity.calculateInSampleSize(options, 512, 512);
- } else {
- options.inSampleSize = CommonActivity.calculateInSampleSize(options, 1024, 1024);
- }
-
options.inJustDecodeBounds = false;
+
+ Bitmap bitmap = null;
- return BitmapFactory.decodeStream(archive.getItem(page), null, options);
- } catch (OutOfMemoryError e) {
- if (activity != null) {
- activity.toast(R.string.error_out_of_memory);
- }
- e.printStackTrace();
+ try {
+ options.inSampleSize = CommonActivity.calculateInSampleSize(options, 1024, 1024);
+ bitmap = BitmapFactory.decodeStream(archive.getItem(page), null, options);
+ return bitmap;
+ } catch (OutOfMemoryError e) {
+ try {
+ options.inSampleSize = CommonActivity.calculateInSampleSize(options, 768, 768);
+ bitmap = BitmapFactory.decodeStream(archive.getItem(page), null, options);
+ return bitmap;
+ } catch (OutOfMemoryError e1) {
+ try {
+ options.inSampleSize = CommonActivity.calculateInSampleSize(options, 512, 512);
+ bitmap = BitmapFactory.decodeStream(archive.getItem(page), null, options);
+ return bitmap;
+ } catch (OutOfMemoryError e3) {
+ e3.printStackTrace();
+
+ if (activity != null) {
+ activity.toast(R.string.error_out_of_memory);
+ }
+ }
+ }
+ }
} catch (IOException e) {
e.printStackTrace();
}
|