Merge "Hide spinners if airplane mode enabled whilst browsing images" into jb-mr2-dev
diff --git a/src/com/android/ex/photo/loaders/PhotoBitmapLoader.java b/src/com/android/ex/photo/loaders/PhotoBitmapLoader.java
index c29b14f..ca92050 100644
--- a/src/com/android/ex/photo/loaders/PhotoBitmapLoader.java
+++ b/src/com/android/ex/photo/loaders/PhotoBitmapLoader.java
@@ -51,13 +51,11 @@
if (context != null && mPhotoUri != null) {
final ContentResolver resolver = context.getContentResolver();
try {
- Bitmap bitmap = ImageUtils.createLocalBitmap(resolver, Uri.parse(mPhotoUri),
+ result = ImageUtils.createLocalBitmap(resolver, Uri.parse(mPhotoUri),
PhotoViewFragment.sPhotoSize);
- if (bitmap != null) {
- bitmap.setDensity(DisplayMetrics.DENSITY_MEDIUM);
+ if (result.bitmap != null) {
+ result.bitmap.setDensity(DisplayMetrics.DENSITY_MEDIUM);
}
- result.status = BitmapResult.STATUS_SUCCESS;
- result.bitmap = bitmap;
} catch (UnsupportedOperationException ex) {
// We got image bytes, but unable to decode to a Bitmap
result.status = BitmapResult.STATUS_EXCEPTION;
@@ -170,7 +168,7 @@
}
}
- public class BitmapResult {
+ public static class BitmapResult {
public static final int STATUS_SUCCESS = 0;
public static final int STATUS_EXCEPTION = 1;
diff --git a/src/com/android/ex/photo/util/ImageUtils.java b/src/com/android/ex/photo/util/ImageUtils.java
index 9c7189c..0db064e 100644
--- a/src/com/android/ex/photo/util/ImageUtils.java
+++ b/src/com/android/ex/photo/util/ImageUtils.java
@@ -29,7 +29,7 @@
import android.util.Log;
import com.android.ex.photo.PhotoViewActivity;
-import com.android.ex.photo.util.Exif;
+import com.android.ex.photo.loaders.PhotoBitmapLoader.BitmapResult;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
@@ -97,15 +97,17 @@
*
* @return The new bitmap or null
*/
- public static Bitmap createLocalBitmap(ContentResolver resolver, Uri uri, int maxSize) {
+ public static BitmapResult createLocalBitmap(ContentResolver resolver, Uri uri, int maxSize) {
// TODO: make this method not download the image for both getImageBounds and decodeStream
+ BitmapResult result = new BitmapResult();
InputStream inputStream = null;
try {
final BitmapFactory.Options opts = new BitmapFactory.Options();
final Point bounds = getImageBounds(resolver, uri);
inputStream = openInputStream(resolver, uri);
if (bounds == null || inputStream == null) {
- return null;
+ result.status = BitmapResult.STATUS_EXCEPTION;
+ return result;
}
opts.inSampleSize = Math.max(bounds.x / maxSize, bounds.y / maxSize);
@@ -114,16 +116,18 @@
// Correct thumbnail orientation as necessary
// TODO: Fix rotation if it's actually a problem
//return rotateBitmap(resolver, uri, decodedBitmap);
- return decodedBitmap;
+ result.bitmap = decodedBitmap;
+ result.status = BitmapResult.STATUS_SUCCESS;
+ return result;
} catch (FileNotFoundException exception) {
// Do nothing - the photo will appear to be missing
} catch (IOException exception) {
- // Do nothing - the photo will appear to be missing
+ result.status = BitmapResult.STATUS_EXCEPTION;
} catch (IllegalArgumentException exception) {
// Do nothing - the photo will appear to be missing
} catch (SecurityException exception) {
- // Do nothing - the photo will appear to be missing
+ result.status = BitmapResult.STATUS_EXCEPTION;
} finally {
try {
if (inputStream != null) {
@@ -132,7 +136,7 @@
} catch (IOException ignore) {
}
}
- return null;
+ return result;
}
/**