diff options
author | Andrew Dolgov <[email protected]> | 2012-12-03 12:25:35 +0300 |
---|---|---|
committer | Andrew Dolgov <[email protected]> | 2012-12-03 12:25:35 +0300 |
commit | 21cd47247b074f2f6d031caeff7f46560c5f8685 (patch) | |
tree | bb9d66894f582fb8a189247a6271a96c34021d20 /src | |
parent | bba178394e160c514430b7170d2b46e6b6f72879 (diff) |
make downsampling selection less ugly
Diffstat (limited to 'src')
-rw-r--r-- | src/org/fox/ttcomics/ComicFragment.java | 35 |
1 files changed, 16 insertions, 19 deletions
diff --git a/src/org/fox/ttcomics/ComicFragment.java b/src/org/fox/ttcomics/ComicFragment.java index 7b324dc..7de319e 100644 --- a/src/org/fox/ttcomics/ComicFragment.java +++ b/src/org/fox/ttcomics/ComicFragment.java @@ -13,6 +13,7 @@ import android.os.AsyncTask; import android.os.Bundle;
import android.preference.PreferenceManager;
import android.support.v4.app.Fragment;
+import android.util.Log;
import android.view.GestureDetector;
import android.view.LayoutInflater;
import android.view.MotionEvent;
@@ -47,30 +48,26 @@ public class ComicFragment extends Fragment implements GestureDetector.OnDoubleT options.inJustDecodeBounds = false;
Bitmap bitmap = null;
+
+ int sampleSizes[] = new int[] { 1024, 768, 512, 256 };
- try {
- options.inSampleSize = CommonActivity.calculateInSampleSize(options, 1024, 1024);
- bitmap = BitmapFactory.decodeStream(archive.getItem(page), null, options);
- return bitmap;
- } catch (OutOfMemoryError e) {
+ for (int sampleSize : sampleSizes) {
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) {
+ options.inSampleSize = CommonActivity.calculateInSampleSize(options, sampleSize, sampleSize);
+ bitmap = BitmapFactory.decodeStream(archive.getItem(page), null, options);
+
+ return bitmap;
+ } catch (OutOfMemoryError e) {
+ if (sampleSize == sampleSizes[sampleSizes.length-1]) {
+ e.printStackTrace();
+
+ if (activity != null && isAdded()) {
activity.toast(R.string.error_out_of_memory);
- }
- }
+ }
+ }
}
}
+
} catch (IOException e) {
e.printStackTrace();
}
|