1 /* 2 * Copyright (C) 2012 Google Inc. 3 * Licensed to The Android Open Source Project. 4 * 5 * Licensed under the Apache License, Version 2.0 (the "License"); 6 * you may not use this file except in compliance with the License. 7 * You may obtain a copy of the License at 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the License for the specific language governing permissions and 15 * limitations under the License. 16 */ 17 18 package com.android.mail.photo; 19 20 import android.content.Context; 21 import android.content.Intent; 22 23 import com.android.ex.photo.Intents; 24 import com.android.ex.photo.PhotoViewActivity; 25 import com.android.ex.photo.PhotoViewController; 26 import com.android.mail.R; 27 import com.android.mail.browse.ConversationMessage; 28 import com.android.mail.providers.UIProvider; 29 30 /** 31 * Derives from {@link PhotoViewActivity} to allow customization. 32 * Delegates all work to {@link MailPhotoViewController}. 33 */ 34 public class MailPhotoViewActivity extends PhotoViewActivity implements 35 MailPhotoViewController.ActivityInterface { 36 37 static final String EXTRA_ACCOUNT = MailPhotoViewActivity.class.getName() + "-acct"; 38 static final String EXTRA_ACCOUNT_TYPE = MailPhotoViewActivity.class.getName() + "-accttype"; 39 static final String EXTRA_MESSAGE = MailPhotoViewActivity.class.getName() + "-msg"; 40 static final String EXTRA_HIDE_EXTRA_OPTION_ONE = 41 MailPhotoViewActivity.class.getName() + "-hide-extra-option-one"; 42 43 /** 44 * Start a new MailPhotoViewActivity to view the given images. 45 * 46 * @param context The context. 47 * @param account The email address of the account. 48 * @param accountType The type of the account. 49 * @param msg The text of the message for this photo. 50 * @param photoIndex The index of the photo within the album. 51 */ 52 public static void startMailPhotoViewActivity(final Context context, final String account, 53 final String accountType, final ConversationMessage msg, final int photoIndex) { 54 final Intents.PhotoViewIntentBuilder builder = 55 Intents.newPhotoViewIntentBuilder(context, 56 context.getString(R.string.photo_view_activity)); 57 builder 58 .setPhotosUri(msg.attachmentListUri.toString()) 59 .setProjection(UIProvider.ATTACHMENT_PROJECTION) 60 .setPhotoIndex(photoIndex); 61 62 context.startActivity(wrapIntent(builder.build(), account, accountType, msg)); 63 } 64 65 /** 66 * Start a new MailPhotoViewActivity to view the given images. 67 * 68 * @param initialPhotoUri The uri of the photo to show first. 69 */ 70 public static void startMailPhotoViewActivity(final Context context, final String account, 71 final String accountType, final ConversationMessage msg, final String initialPhotoUri) { 72 context.startActivity( 73 buildMailPhotoViewActivityIntent(context, account, accountType, msg, 74 initialPhotoUri)); 75 } 76 77 public static Intent buildMailPhotoViewActivityIntent( 78 final Context context, final String account, final String accountType, 79 final ConversationMessage msg, final String initialPhotoUri) { 80 final Intents.PhotoViewIntentBuilder builder = Intents.newPhotoViewIntentBuilder( 81 context, context.getString(R.string.photo_view_activity)); 82 83 builder.setPhotosUri(msg.attachmentListUri.toString()) 84 .setProjection(UIProvider.ATTACHMENT_PROJECTION) 85 .setInitialPhotoUri(initialPhotoUri); 86 87 return wrapIntent(builder.build(), account, accountType, msg); 88 } 89 90 private static Intent wrapIntent( 91 final Intent intent, final String account, final String accountType, 92 final ConversationMessage msg) { 93 intent.putExtra(EXTRA_MESSAGE, msg); 94 intent.putExtra(EXTRA_ACCOUNT, account); 95 intent.putExtra(EXTRA_ACCOUNT_TYPE, accountType); 96 intent.putExtra(EXTRA_HIDE_EXTRA_OPTION_ONE, msg.getConversation() == null); 97 return intent; 98 } 99 100 @Override 101 public PhotoViewController createController() { 102 return new MailPhotoViewController(this); 103 } 104 } 105