diff options
author | Andy Huang <ath@google.com> | 2014-02-25 17:32:28 -0800 |
---|---|---|
committer | Andy Huang <ath@google.com> | 2014-03-25 17:10:28 -0700 |
commit | 4f347e811052f446c3958c76db278bcd7b39a44f (patch) | |
tree | f765e9dc1793c975964f8d23e8590479ce594ebf /src/com/android/mail | |
parent | f6b26fbdaa8c8a8989d49f23858b5c1a15efb766 (diff) | |
download | android_packages_apps_UnifiedEmail-4f347e811052f446c3958c76db278bcd7b39a44f.tar.gz android_packages_apps_UnifiedEmail-4f347e811052f446c3958c76db278bcd7b39a44f.tar.bz2 android_packages_apps_UnifiedEmail-4f347e811052f446c3958c76db278bcd7b39a44f.zip |
allow an extra option on attachments (in bar and tile UI)
Bug: 7659807
Change-Id: I4c1294d2ba772a70139e0b37429b17bc6096cafd
Diffstat (limited to 'src/com/android/mail')
11 files changed, 172 insertions, 56 deletions
diff --git a/src/com/android/mail/browse/AttachmentActionHandler.java b/src/com/android/mail/browse/AttachmentActionHandler.java index 9c1fa0064..8a72533f5 100644 --- a/src/com/android/mail/browse/AttachmentActionHandler.java +++ b/src/com/android/mail/browse/AttachmentActionHandler.java @@ -31,6 +31,7 @@ import android.os.Handler; import android.os.Parcelable; import com.android.mail.providers.Attachment; +import com.android.mail.providers.Message; import com.android.mail.providers.UIProvider; import com.android.mail.providers.UIProvider.AttachmentColumns; import com.android.mail.providers.UIProvider.AttachmentContentValueKeys; @@ -45,6 +46,8 @@ import java.util.ArrayList; public class AttachmentActionHandler { private static final String PROGRESS_FRAGMENT_TAG = "attachment-progress"; + private String mAccount; + private Message mMessage; private Attachment mAttachment; private final AttachmentCommandHandler mCommandHandler; @@ -56,6 +59,8 @@ public class AttachmentActionHandler { private static final String LOG_TAG = LogTag.getLogTag(); + private static OptionHandler sOptionHandler = new OptionHandler(); + public AttachmentActionHandler(Context context, AttachmentViewInterface view) { mCommandHandler = new AttachmentCommandHandler(context); mView = view; @@ -68,6 +73,14 @@ public class AttachmentActionHandler { mFragmentManager = fragmentManager; } + public void setAccount(String account) { + mAccount = account; + } + + public void setMessage(Message message) { + mMessage = message; + } + public void setAttachment(Attachment attachment) { mAttachment = attachment; } @@ -236,4 +249,41 @@ public class AttachmentActionHandler { LogUtils.e(LOG_TAG, "Couldn't find Activity for intent", e); } } + + public static void setOptionHandler(OptionHandler handler) { + sOptionHandler = handler; + } + + public boolean shouldShowExtraOption1() { + return (sOptionHandler != null) && sOptionHandler.shouldShowExtraOption1(); + } + + public void handleOption1() { + if (sOptionHandler == null) { + return; + } + sOptionHandler.handleOption1(mContext, mAccount, mMessage, mAttachment, mFragmentManager); + } + + /** + * A default, no-op option class. Override this and set it globally with + * {@link AttachmentActionHandler#setOptionHandler(OptionHandler)}.<br> + * <br> + * Subclasses of this type will live pretty much forever, so really, really try to avoid + * keeping any state as member variables in them. + */ + public static class OptionHandler { + + public boolean shouldShowExtraOption1() { + return false; + } + + @SuppressWarnings("unused") + public void handleOption1(Context context, String account, Message message, + Attachment attachment, FragmentManager fm) { + // no-op + } + + } + } diff --git a/src/com/android/mail/browse/ConversationMessage.java b/src/com/android/mail/browse/ConversationMessage.java index e9aa875a1..2ac40ee66 100644 --- a/src/com/android/mail/browse/ConversationMessage.java +++ b/src/com/android/mail/browse/ConversationMessage.java @@ -25,6 +25,7 @@ import com.android.emailcommon.internet.MimeMessage; import com.android.emailcommon.mail.MessagingException; import com.android.mail.browse.MessageCursor.ConversationController; import com.android.mail.content.CursorCreator; +import com.android.mail.providers.Account; import com.android.mail.providers.Attachment; import com.android.mail.providers.Conversation; import com.android.mail.providers.Message; @@ -65,6 +66,10 @@ public final class ConversationMessage extends Message { return mController != null ? mController.getConversation() : null; } + public Account getAccount() { + return mController != null ? mController.getAccount() : null; + } + /** * Returns a hash code based on this message's identity, contents and current state. * This is a separate method from hashCode() to allow for an instance of this class to be diff --git a/src/com/android/mail/browse/MessageAttachmentBar.java b/src/com/android/mail/browse/MessageAttachmentBar.java index 378db87f8..93e7ca33f 100644 --- a/src/com/android/mail/browse/MessageAttachmentBar.java +++ b/src/com/android/mail/browse/MessageAttachmentBar.java @@ -109,13 +109,14 @@ public class MessageAttachmentBar extends FrameLayout implements OnClickListener * repeatedly as status updates stream in, so only properties with new or changed values will * cause sub-views to update. */ - public void render(Attachment attachment, Account account, + public void render(Attachment attachment, Account account, ConversationMessage message, boolean loaderResult, BidiFormatter bidiFormatter) { // get account uri for potential eml viewer usage mAccount = account; final Attachment prevAttachment = mAttachment; mAttachment = attachment; + mActionHandler.setMessage(message); mActionHandler.setAttachment(mAttachment); // reset mSaveClicked if we are not currently downloading @@ -202,6 +203,8 @@ public class MessageAttachmentBar extends FrameLayout implements OnClickListener Analytics.getInstance().sendEvent( "cancel_attachment", Utils.normalizeMimeType(mAttachment.getContentType()), "attachment_bar", mAttachment.size); + } else if (res == R.id.attachment_extra_option1) { + mActionHandler.handleOption1(); } else if (res == R.id.overflow) { // If no overflow items are visible, just bail out. // We shouldn't be able to get here anyhow since the overflow @@ -218,6 +221,7 @@ public class MessageAttachmentBar extends FrameLayout implements OnClickListener menu.findItem(R.id.preview_attachment).setVisible(shouldShowPreview()); menu.findItem(R.id.save_attachment).setVisible(shouldShowSave()); menu.findItem(R.id.download_again).setVisible(shouldShowDownloadAgain()); + menu.findItem(R.id.attachment_extra_option1).setVisible(shouldShowExtraOption1()); mPopup.show(); } @@ -296,9 +300,13 @@ public class MessageAttachmentBar extends FrameLayout implements OnClickListener return mAttachment.supportsDownloadAgain() && mAttachment.isDownloadFinishedOrFailed(); } + private boolean shouldShowExtraOption1() { + return mActionHandler.shouldShowExtraOption1(); + } + private boolean shouldShowOverflow() { - return (shouldShowPreview() || shouldShowSave() || shouldShowDownloadAgain()) - && !shouldShowCancel(); + return (shouldShowPreview() || shouldShowSave() || shouldShowDownloadAgain() + || shouldShowExtraOption1()) && !shouldShowCancel(); } private boolean shouldShowCancel() { diff --git a/src/com/android/mail/browse/MessageAttachmentTile.java b/src/com/android/mail/browse/MessageAttachmentTile.java index 90a87ccfb..46a89939f 100644 --- a/src/com/android/mail/browse/MessageAttachmentTile.java +++ b/src/com/android/mail/browse/MessageAttachmentTile.java @@ -22,7 +22,6 @@ import android.content.ActivityNotFoundException; import android.content.Context; import android.content.Intent; import android.graphics.Bitmap; -import android.net.Uri; import android.util.AttributeSet; import android.view.LayoutInflater; import android.view.View; @@ -33,7 +32,6 @@ import android.view.ViewParent; import com.android.ex.photo.util.ImageUtils; import com.android.mail.R; import com.android.mail.analytics.Analytics; -import com.android.mail.photo.MailPhotoViewActivity; import com.android.mail.providers.Attachment; import com.android.mail.providers.UIProvider; import com.android.mail.providers.UIProvider.AttachmentDestination; @@ -57,13 +55,22 @@ public class MessageAttachmentTile extends AttachmentTile implements OnClickList AttachmentViewInterface { private int mPhotoIndex; - private Uri mAttachmentsListUri; private View mTextContainer; private final AttachmentActionHandler mActionHandler; + private PhotoViewHandler mPhotoViewHandler; + private static final String LOG_TAG = LogTag.getLogTag(); + /** + * Let someone else do this work, since it typically requires broader visibility of context, + * like what other photos to also show alongside this one. + */ + public interface PhotoViewHandler { + void viewPhoto(MessageAttachmentTile source); + } + public MessageAttachmentTile(Context context) { this(context, null); } @@ -78,17 +85,19 @@ public class MessageAttachmentTile extends AttachmentTile implements OnClickList mActionHandler.initialize(fragmentManager); } + public void setPhotoViewHandler(PhotoViewHandler pvh) { + mPhotoViewHandler = pvh; + } + /** * Render or update an attachment's view. This happens immediately upon instantiation, and * repeatedly as status updates stream in, so only properties with new or changed values will * cause sub-views to update. */ - @Override - public void render(Attachment attachment, Uri attachmentsListUri, int index, + public void render(Attachment attachment, int index, AttachmentPreviewCache attachmentPreviewCache, boolean loaderResult) { - super.render(attachment, attachmentsListUri, index, attachmentPreviewCache, loaderResult); + render(attachment, attachmentPreviewCache); - mAttachmentsListUri = attachmentsListUri; mPhotoIndex = index; mActionHandler.setAttachment(mAttachment); @@ -122,6 +131,8 @@ public class MessageAttachmentTile extends AttachmentTile implements OnClickList } private void showAndDownloadAttachments() { + // TODO: clean this up, it seems like it should live in AttachmentTileGrid since it keeps + // inappropriately touching this view's peers AttachmentTileGrid tileGrid = ((AttachmentTileGrid) getParent()); int childCount = tileGrid.getChildCount(); @@ -158,8 +169,11 @@ public class MessageAttachmentTile extends AttachmentTile implements OnClickList .sendEvent("view_attachment", mime, "attachment_tile", mAttachment.size); if (ImageUtils.isImageMimeType(mime)) { - MailPhotoViewActivity - .startMailPhotoViewActivity(getContext(), mAttachmentsListUri, mPhotoIndex); + if (mPhotoViewHandler != null) { + mPhotoViewHandler.viewPhoto(this); + } else { + LogUtils.e(LOG_TAG, "unable to view image attachment b/c handler is null"); + } return; } diff --git a/src/com/android/mail/browse/MessageFooterView.java b/src/com/android/mail/browse/MessageFooterView.java index 55c139df6..9c081d06f 100644 --- a/src/com/android/mail/browse/MessageFooterView.java +++ b/src/com/android/mail/browse/MessageFooterView.java @@ -205,8 +205,8 @@ public class MessageFooterView extends LinearLayout implements DetachListener, mAttachmentGrid.setVisibility(View.VISIBLE); // Setup the tiles. - mAttachmentGrid.configureGrid(mFragmentManager, - mMessageHeaderItem.getMessage().attachmentListUri, tiledAttachments, loaderResult); + mAttachmentGrid.configureGrid(mFragmentManager, getAccount(), + mMessageHeaderItem.getMessage(), tiledAttachments, loaderResult); } private void renderBarAttachments(List<Attachment> barAttachments, boolean loaderResult) { @@ -225,7 +225,8 @@ public class MessageFooterView extends LinearLayout implements DetachListener, mAttachmentBarList.addView(barAttachmentView); } - barAttachmentView.render(attachment, account, loaderResult, getBidiFormatter()); + barAttachmentView.render(attachment, account, mMessageHeaderItem.getMessage(), + loaderResult, getBidiFormatter()); } } diff --git a/src/com/android/mail/compose/ComposeAttachmentTile.java b/src/com/android/mail/compose/ComposeAttachmentTile.java index 022fbe115..844a7a3a0 100644 --- a/src/com/android/mail/compose/ComposeAttachmentTile.java +++ b/src/com/android/mail/compose/ComposeAttachmentTile.java @@ -7,6 +7,7 @@ import android.view.ViewGroup; import android.widget.ImageButton; import com.android.mail.R; +import com.android.mail.providers.Attachment; import com.android.mail.ui.AttachmentTile; public class ComposeAttachmentTile extends AttachmentTile implements AttachmentDeletionInterface { @@ -29,6 +30,12 @@ public class ComposeAttachmentTile extends AttachmentTile implements AttachmentD } @Override + public void render(Attachment attachment, AttachmentPreviewCache attachmentPreviewCache) { + // the super implementation is good enough. just broaden its access. + super.render(attachment, attachmentPreviewCache); + } + + @Override protected void onFinishInflate() { super.onFinishInflate(); diff --git a/src/com/android/mail/photo/MailPhotoViewActivity.java b/src/com/android/mail/photo/MailPhotoViewActivity.java index a0618ba4f..3113bdf72 100644 --- a/src/com/android/mail/photo/MailPhotoViewActivity.java +++ b/src/com/android/mail/photo/MailPhotoViewActivity.java @@ -21,7 +21,6 @@ import android.app.ActionBar; import android.content.Context; import android.content.Intent; import android.database.Cursor; -import android.net.Uri; import android.os.Bundle; import android.os.Parcelable; import android.support.v4.print.PrintHelper; @@ -42,6 +41,7 @@ import com.android.mail.analytics.Analytics; import com.android.mail.browse.AttachmentActionHandler; import com.android.mail.print.PrintUtils; import com.android.mail.providers.Attachment; +import com.android.mail.providers.Message; import com.android.mail.providers.UIProvider; import com.android.mail.providers.UIProvider.AttachmentDestination; import com.android.mail.providers.UIProvider.AttachmentState; @@ -73,54 +73,59 @@ public class MailPhotoViewActivity extends PhotoViewActivity { * retry button. */ private MenuItem mDownloadAgainItem; - private AttachmentActionHandler mActionHandler; + private MenuItem mExtraOption1Item; + protected AttachmentActionHandler mActionHandler; private Menu mMenu; + private static final String EXTRA_ACCOUNT = MailPhotoViewActivity.class.getName() + "-acct"; + private static final String EXTRA_MESSAGE = MailPhotoViewActivity.class.getName() + "-msg"; + /** * Start a new MailPhotoViewActivity to view the given images. * - * @param imageListUri The uri to query for the images that you want to view. The resulting - * cursor must have the columns as defined in - * {@link com.android.ex.photo.provider.PhotoContract.PhotoViewColumns}. * @param photoIndex The index of the photo to show first. */ - public static void startMailPhotoViewActivity(final Context context, final Uri imageListUri, - final int photoIndex) { + public static void startMailPhotoViewActivity(final Context context, final String account, + final Message msg, final int photoIndex) { final Intents.PhotoViewIntentBuilder builder = Intents.newPhotoViewIntentBuilder(context, "com.android.mail.photo.MailPhotoViewActivity"); builder - .setPhotosUri(imageListUri.toString()) + .setPhotosUri(msg.attachmentListUri.toString()) .setProjection(UIProvider.ATTACHMENT_PROJECTION) .setPhotoIndex(photoIndex); - context.startActivity(builder.build()); + context.startActivity(wrapIntent(builder.build(), account, msg)); } /** * Start a new MailPhotoViewActivity to view the given images. * - * @param imageListUri The uri to query for the images that you want to view. The resulting - * cursor must have the columns as defined in - * {@link com.android.ex.photo.provider.PhotoContract.PhotoViewColumns}. * @param initialPhotoUri The uri of the photo to show first. */ - public static void startMailPhotoViewActivity(final Context context, final Uri imageListUri, - final String initialPhotoUri) { + public static void startMailPhotoViewActivity(final Context context, final String account, + final Message msg, final String initialPhotoUri) { context.startActivity( - buildMailPhotoViewActivityIntent(context, imageListUri, initialPhotoUri)); + buildMailPhotoViewActivityIntent(context, account, msg, initialPhotoUri)); } public static Intent buildMailPhotoViewActivityIntent( - final Context context, final Uri imageListUri, final String initialPhotoUri) { + final Context context, final String account, final Message msg, + final String initialPhotoUri) { final Intents.PhotoViewIntentBuilder builder = Intents.newPhotoViewIntentBuilder( context, "com.android.mail.photo.MailPhotoViewActivity"); - builder.setPhotosUri(imageListUri.toString()) + builder.setPhotosUri(msg.attachmentListUri.toString()) .setProjection(UIProvider.ATTACHMENT_PROJECTION) .setInitialPhotoUri(initialPhotoUri); - return builder.build(); + return wrapIntent(builder.build(), account, msg); + } + + private static Intent wrapIntent(final Intent intent, final String account, final Message msg) { + intent.putExtra(EXTRA_MESSAGE, msg); + intent.putExtra(EXTRA_ACCOUNT, account); + return intent; } @Override @@ -130,6 +135,12 @@ public class MailPhotoViewActivity extends PhotoViewActivity { mActionHandler = new AttachmentActionHandler(this, null); mActionHandler.initialize(getFragmentManager()); + + final Intent intent = getIntent(); + final String account = intent.getStringExtra(EXTRA_ACCOUNT); + final Message msg = intent.getParcelableExtra(EXTRA_MESSAGE); + mActionHandler.setAccount(account); + mActionHandler.setMessage(msg); } @Override @@ -145,6 +156,7 @@ public class MailPhotoViewActivity extends PhotoViewActivity { mShareAllItem = mMenu.findItem(R.id.menu_share_all); mPrintItem = mMenu.findItem(R.id.menu_print); mDownloadAgainItem = mMenu.findItem(R.id.menu_download_again); + mExtraOption1Item = mMenu.findItem(R.id.attachment_extra_option1); return true; } @@ -171,6 +183,7 @@ public class MailPhotoViewActivity extends PhotoViewActivity { mShareItem.setEnabled(canShare); mPrintItem.setEnabled(canShare); mDownloadAgainItem.setEnabled(attachment.canSave() && attachment.isDownloading()); + mExtraOption1Item.setEnabled(mActionHandler.shouldShowExtraOption1()); } else { if (mMenu != null) { mMenu.setGroupEnabled(R.id.photo_view_menu_group, false); @@ -223,28 +236,25 @@ public class MailPhotoViewActivity extends PhotoViewActivity { if (itemId == android.R.id.home) { // app icon in action bar clicked; go back to conversation finish(); - return true; } else if (itemId == R.id.menu_save) { // save the current photo saveAttachment(); - return true; } else if (itemId == R.id.menu_save_all) { // save all of the photos saveAllAttachments(); - return true; } else if (itemId == R.id.menu_share) { // share the current photo shareAttachment(); - return true; } else if (itemId == R.id.menu_share_all) { // share all of the photos shareAllAttachments(); - return true; } else if (itemId == R.id.menu_print) { // print the current photo printAttachment(); - return true; } else if (itemId == R.id.menu_download_again) { // redownload the current photo redownloadAttachment(); - return true; + } else if (itemId == R.id.attachment_extra_option1) { + mActionHandler.setAttachment(getCurrentAttachment()); + mActionHandler.handleOption1(); } else { return super.onOptionsItemSelected(item); } + return true; } /** diff --git a/src/com/android/mail/providers/UIProvider.java b/src/com/android/mail/providers/UIProvider.java index d4ff81989..d37a083e1 100644 --- a/src/com/android/mail/providers/UIProvider.java +++ b/src/com/android/mail/providers/UIProvider.java @@ -1742,7 +1742,10 @@ public class UIProvider { public static final String HAS_ATTACHMENTS = "hasAttachments"; /** * This string column contains the content provider URI for the list of - * attachments associated with this message. + * attachments associated with this message.<br> + * <br> + * The resulting cursor MUST have the columns as defined in + * {@link com.android.ex.photo.provider.PhotoContract.PhotoViewColumns}. */ public static final String ATTACHMENT_LIST_URI = "attachmentListUri"; /** diff --git a/src/com/android/mail/ui/AbstractConversationViewFragment.java b/src/com/android/mail/ui/AbstractConversationViewFragment.java index 84ec9439c..5d665d7f0 100644 --- a/src/com/android/mail/ui/AbstractConversationViewFragment.java +++ b/src/com/android/mail/ui/AbstractConversationViewFragment.java @@ -67,6 +67,7 @@ public abstract class AbstractConversationViewFragment extends Fragment implemen private static final String LOG_TAG = LogTag.getLogTag(); protected static final int MESSAGE_LOADER = 0; protected static final int CONTACT_LOADER = 1; + public static final int ATTACHMENT_OPTION1_LOADER = 2; protected ControllableActivity mActivity; private final MessageLoaderCallbacks mMessageLoaderCallbacks = new MessageLoaderCallbacks(); private ContactLoaderCallbacks mContactLoaderCallbacks; diff --git a/src/com/android/mail/ui/AttachmentTile.java b/src/com/android/mail/ui/AttachmentTile.java index 63542fa05..3fc8dc57a 100644 --- a/src/com/android/mail/ui/AttachmentTile.java +++ b/src/com/android/mail/ui/AttachmentTile.java @@ -20,7 +20,6 @@ package com.android.mail.ui; import android.content.ContentResolver; import android.content.Context; import android.graphics.Bitmap; -import android.net.Uri; import android.os.Parcel; import android.os.Parcelable; import android.text.TextUtils; @@ -28,22 +27,22 @@ import android.util.AttributeSet; import android.util.DisplayMetrics; import android.view.View; import android.widget.ImageView; +import android.widget.ImageView.ScaleType; import android.widget.RelativeLayout; import android.widget.TextView; -import android.widget.ImageView.ScaleType; import com.android.ex.photo.util.ImageUtils; import com.android.mail.R; import com.android.mail.providers.Attachment; -import com.android.mail.utils.LogTag; import com.android.mail.utils.AttachmentUtils; +import com.android.mail.utils.LogTag; import com.android.mail.utils.LogUtils; /** * Base class for attachment tiles that handles the work of fetching and displaying the bitmaps for * the tiles. */ -public class AttachmentTile extends RelativeLayout implements AttachmentBitmapHolder { +public abstract class AttachmentTile extends RelativeLayout implements AttachmentBitmapHolder { protected Attachment mAttachment; private ImageView mIcon; private ImageView mDefaultIcon; @@ -98,13 +97,16 @@ public class AttachmentTile extends RelativeLayout implements AttachmentBitmapHo ThumbnailLoadTask.setupThumbnailPreview(this, mAttachment, null); } + public Attachment getAttachment() { + return mAttachment; + } + /** * Render or update an attachment's view. This happens immediately upon instantiation, and * repeatedly as status updates stream in, so only properties with new or changed values will * cause sub-views to update. */ - public void render(Attachment attachment, Uri attachmentsListUri, int index, - AttachmentPreviewCache attachmentPreviewCache, boolean loaderResult) { + protected void render(Attachment attachment, AttachmentPreviewCache attachmentPreviewCache) { if (attachment == null) { setVisibility(View.INVISIBLE); return; diff --git a/src/com/android/mail/ui/AttachmentTileGrid.java b/src/com/android/mail/ui/AttachmentTileGrid.java index 2bb2acdbc..59ff7049b 100644 --- a/src/com/android/mail/ui/AttachmentTileGrid.java +++ b/src/com/android/mail/ui/AttachmentTileGrid.java @@ -19,19 +19,21 @@ package com.android.mail.ui; import android.app.FragmentManager; import android.content.Context; import android.graphics.Bitmap; -import android.net.Uri; import android.util.AttributeSet; import android.view.LayoutInflater; import android.view.View; import android.widget.FrameLayout; import com.android.mail.R; +import com.android.mail.browse.ConversationMessage; import com.android.mail.browse.MessageAttachmentTile; import com.android.mail.compose.ComposeAttachmentTile; +import com.android.mail.photo.MailPhotoViewActivity; +import com.android.mail.providers.Account; import com.android.mail.providers.Attachment; +import com.android.mail.providers.Message; import com.android.mail.ui.AttachmentTile.AttachmentPreview; import com.android.mail.ui.AttachmentTile.AttachmentPreviewCache; - import com.android.mail.utils.ViewUtils; import com.google.common.collect.Lists; import com.google.common.collect.Maps; @@ -43,14 +45,16 @@ import java.util.List; /** * Acts as a grid composed of {@link AttachmentTile}s. */ -public class AttachmentTileGrid extends FrameLayout implements AttachmentPreviewCache { +public class AttachmentTileGrid extends FrameLayout implements AttachmentPreviewCache, + MessageAttachmentTile.PhotoViewHandler { private final LayoutInflater mInflater; - private Uri mAttachmentsListUri; private final int mTileMinSize; private int mColumnCount; private List<Attachment> mAttachments; private final HashMap<String, AttachmentPreview> mAttachmentPreviews; private FragmentManager mFragmentManager; + private Account mAccount; + private Message mMessage; public AttachmentTileGrid(Context context, AttributeSet attrs) { super(context, attrs); @@ -63,10 +67,12 @@ public class AttachmentTileGrid extends FrameLayout implements AttachmentPreview /** * Configures the grid to add {@link Attachment}s information to the views. */ - public void configureGrid(FragmentManager fragmentManager, Uri attachmentsListUri, - List<Attachment> list, boolean loaderResult) { + public void configureGrid(FragmentManager fragmentManager, Account account, + ConversationMessage message, List<Attachment> list, boolean loaderResult) { + mFragmentManager = fragmentManager; - mAttachmentsListUri = attachmentsListUri; + mAccount = account; + mMessage = message; mAttachments = list; // Adding tiles to grid and filling in attachment information int index = 0; @@ -82,12 +88,13 @@ public class AttachmentTileGrid extends FrameLayout implements AttachmentPreview if (getChildCount() <= index) { attachmentTile = MessageAttachmentTile.inflate(mInflater, this); attachmentTile.initialize(mFragmentManager); + attachmentTile.setPhotoViewHandler(this); addView(attachmentTile); } else { attachmentTile = (MessageAttachmentTile) getChildAt(index); } - attachmentTile.render(attachment, mAttachmentsListUri, index, this, loaderResult); + attachmentTile.render(attachment, index, this, loaderResult); } public ComposeAttachmentTile addComposeTileFromAttachment(Attachment attachment) { @@ -95,12 +102,20 @@ public class AttachmentTileGrid extends FrameLayout implements AttachmentPreview ComposeAttachmentTile.inflate(mInflater, this); addView(attachmentTile); - attachmentTile.render(attachment, null, -1, this, false); + attachmentTile.render(attachment, this); return attachmentTile; } @Override + public void viewPhoto(MessageAttachmentTile source) { + final int photoIndex = indexOfChild(source); + + MailPhotoViewActivity.startMailPhotoViewActivity(getContext(), mAccount.getEmailAddress(), + mMessage, photoIndex); + } + + @Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { onMeasureForTiles(widthMeasureSpec); } |