First version of photo viewer in Gmail.
Shows only one photo at the moment.
Change-Id: I128c40f693fd9cfeddb6bf2df3ac96e5257a7e62
diff --git a/res/values/constants.xml b/res/values/constants.xml
index 06bdc50..ccf4f44 100644
--- a/res/values/constants.xml
+++ b/res/values/constants.xml
@@ -61,7 +61,7 @@
<!-- Whether to show conversation subject in conversation view -->
<bool name="show_conversation_subject">true</bool>
- <!-- Amount of memory in bytes allocated for image cache -->
+ <!-- Amount of memory in bytes allocated for image cache -->
<integer name="config_image_cache_max_bytes">1500000</integer>
<!-- Number of decoded contact photo bitmaps retained in an LRU cache -->
diff --git a/src/com/android/mail/browse/MessageHeaderAttachment.java b/src/com/android/mail/browse/MessageHeaderAttachment.java
index 453508b..e1597e1 100644
--- a/src/com/android/mail/browse/MessageHeaderAttachment.java
+++ b/src/com/android/mail/browse/MessageHeaderAttachment.java
@@ -45,6 +45,9 @@
import android.widget.TextView;
import com.android.mail.R;
+import com.android.mail.photo.Intents;
+import com.android.mail.photo.Intents.PhotoViewIntentBuilder;
+import com.android.mail.photo.util.MediaStoreUtils;
import com.android.mail.providers.Attachment;
import com.android.mail.providers.UIProvider.AttachmentColumns;
import com.android.mail.providers.UIProvider.AttachmentDestination;
@@ -452,6 +455,16 @@
* View an attachment by an application on device.
*/
private void sendViewIntent() {
+ if (MediaStoreUtils.isImageMimeType(Utils.normalizeMimeType(mAttachment.contentType))) {
+ final PhotoViewIntentBuilder builder =
+ Intents.newPhotoViewActivityIntentBuilder(getContext());
+ builder.setAlbumName(mAttachment.name)
+ .setPhotosUri(mAttachment.contentUri.toString());
+
+ getContext().startActivity(builder.build());
+ return;
+ }
+
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION
| Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
diff --git a/src/com/android/mail/photo/fragments/PhotoViewFragment.java b/src/com/android/mail/photo/fragments/PhotoViewFragment.java
index f904851..6d3a7ef 100644
--- a/src/com/android/mail/photo/fragments/PhotoViewFragment.java
+++ b/src/com/android/mail/photo/fragments/PhotoViewFragment.java
@@ -173,7 +173,7 @@
private final static int LOADER_ID_PHOTO = R.id.photo_view_photo_loader_id;
/** The size of the photo */
- private static Integer sPhotoSize;
+ public static Integer sPhotoSize;
/** The ID of this photo */
private long mPhotoId;
diff --git a/src/com/android/mail/photo/loaders/PhotoBitmapLoader.java b/src/com/android/mail/photo/loaders/PhotoBitmapLoader.java
index a126d8f..49965a5 100644
--- a/src/com/android/mail/photo/loaders/PhotoBitmapLoader.java
+++ b/src/com/android/mail/photo/loaders/PhotoBitmapLoader.java
@@ -17,14 +17,14 @@
package com.android.mail.photo.loaders;
+import android.content.ContentResolver;
import android.content.Context;
import android.graphics.Bitmap;
-import android.graphics.BitmapFactory;
+import android.net.Uri;
import android.support.v4.content.AsyncTaskLoader;
-import android.util.Log;
-import java.io.IOException;
-import java.io.InputStream;
+import com.android.mail.photo.fragments.PhotoViewFragment;
+import com.android.mail.photo.util.ImageUtils;
/**
* Loader for the bitmap of a photo.
@@ -43,28 +43,13 @@
public Bitmap loadInBackground() {
Context context = getContext();
- Bitmap bitmap = null;
- InputStream stream = null;
-
- try {
- if (context != null) {
- stream = context.getAssets().open(mPhotoUrl);
-
- bitmap = BitmapFactory.decodeStream(stream);
- }
- } catch (final IOException e) {
- Log.d("PhotoBitmapLoader", "Caught IOException", e);
- } finally {
- if (stream != null) {
- try {
- stream.close();
- } catch (IOException e) {
- // ignore
- }
- }
+ if (context != null && mPhotoUrl != null) {
+ final ContentResolver resolver = context.getContentResolver();
+ return ImageUtils.createLocalBitmap(resolver, Uri.parse(mPhotoUrl),
+ PhotoViewFragment.sPhotoSize);
}
- return bitmap;
+ return null;
}
/**
diff --git a/src/com/android/mail/photo/loaders/PhotoPagerLoader.java b/src/com/android/mail/photo/loaders/PhotoPagerLoader.java
index 5e3f7c3..12ba712 100644
--- a/src/com/android/mail/photo/loaders/PhotoPagerLoader.java
+++ b/src/com/android/mail/photo/loaders/PhotoPagerLoader.java
@@ -19,6 +19,7 @@
import android.content.Context;
import android.database.Cursor;
+import android.database.MatrixCursor;
import android.net.Uri;
import com.android.mail.photo.provider.PhotoContract.PhotoQuery;
@@ -39,10 +40,26 @@
final Uri loaderUri = getLoaderUri();
+ if (true) {
+ returnCursor = new MatrixCursor(PhotoQuery.PROJECTION);
+ ((MatrixCursor) returnCursor).newRow()
+ .add(0) // _id
+ .add(loaderUri.toString());
+ return returnCursor;
+ }
+
setUri(loaderUri);
setProjection(PhotoQuery.PROJECTION);
returnCursor = super.esLoadInBackground();
+ if (returnCursor == null || returnCursor.getCount() == 0) {
+ returnCursor.close();
+ returnCursor = new MatrixCursor(PhotoQuery.PROJECTION);
+ ((MatrixCursor) returnCursor).newRow()
+ .add(0) // _id
+ .add(loaderUri.toString()); // url
+ }
+
return returnCursor;
}
}
diff --git a/src/com/android/mail/photo/util/ImageUtils.java b/src/com/android/mail/photo/util/ImageUtils.java
index 03837af..4143d2d 100644
--- a/src/com/android/mail/photo/util/ImageUtils.java
+++ b/src/com/android/mail/photo/util/ImageUtils.java
@@ -294,7 +294,9 @@
final Bitmap decodedBitmap = decodeStream(inputStream, null, opts);
// Correct thumbnail orientation as necessary
- return rotateBitmap(resolver, uri, decodedBitmap);
+ // TODO: Fix rotation if it's actually a problem
+ //return rotateBitmap(resolver, uri, decodedBitmap);
+ return decodedBitmap;
} catch (FileNotFoundException exception) {
// Do nothing - the photo will appear to be missing