• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.browse.ConversationMessage;
27 import com.android.mail.providers.UIProvider;
28 
29 /**
30  * Derives from {@link PhotoViewActivity} to allow customization.
31  * Delegates all work to {@link MailPhotoViewController}.
32  */
33 public class MailPhotoViewActivity extends PhotoViewActivity implements
34         MailPhotoViewController.ActivityInterface {
35 
36     static final String EXTRA_ACCOUNT = MailPhotoViewActivity.class.getName() + "-acct";
37     static final String EXTRA_MESSAGE = MailPhotoViewActivity.class.getName() + "-msg";
38     static final String EXTRA_HIDE_EXTRA_OPTION_ONE =
39             MailPhotoViewActivity.class.getName() + "-hide-extra-option-one";
40 
41     /**
42      * Start a new MailPhotoViewActivity to view the given images.
43      *
44      * @param photoIndex The index of the photo to show first.
45      */
startMailPhotoViewActivity(final Context context, final String account, final ConversationMessage msg, final int photoIndex)46     public static void startMailPhotoViewActivity(final Context context, final String account,
47             final ConversationMessage msg, final int photoIndex) {
48         final Intents.PhotoViewIntentBuilder builder =
49                 Intents.newPhotoViewIntentBuilder(context,
50                         "com.android.mail.photo.MailPhotoViewActivity");
51         builder
52                 .setPhotosUri(msg.attachmentListUri.toString())
53                 .setProjection(UIProvider.ATTACHMENT_PROJECTION)
54                 .setPhotoIndex(photoIndex);
55 
56         context.startActivity(wrapIntent(builder.build(), account, msg));
57     }
58 
59     /**
60      * Start a new MailPhotoViewActivity to view the given images.
61      *
62      * @param initialPhotoUri The uri of the photo to show first.
63      */
startMailPhotoViewActivity(final Context context, final String account, final ConversationMessage msg, final String initialPhotoUri)64     public static void startMailPhotoViewActivity(final Context context, final String account,
65             final ConversationMessage msg, final String initialPhotoUri) {
66         context.startActivity(
67                 buildMailPhotoViewActivityIntent(context, account, msg, initialPhotoUri));
68     }
69 
buildMailPhotoViewActivityIntent( final Context context, final String account, final ConversationMessage msg, final String initialPhotoUri)70     public static Intent buildMailPhotoViewActivityIntent(
71             final Context context, final String account, final ConversationMessage msg,
72             final String initialPhotoUri) {
73         final Intents.PhotoViewIntentBuilder builder = Intents.newPhotoViewIntentBuilder(
74                 context, "com.android.mail.photo.MailPhotoViewActivity");
75 
76         builder.setPhotosUri(msg.attachmentListUri.toString())
77                 .setProjection(UIProvider.ATTACHMENT_PROJECTION)
78                 .setInitialPhotoUri(initialPhotoUri);
79 
80         return wrapIntent(builder.build(), account, msg);
81     }
82 
wrapIntent( final Intent intent, final String account, final ConversationMessage msg)83     private static Intent wrapIntent(
84             final Intent intent, final String account, final ConversationMessage msg) {
85         intent.putExtra(EXTRA_MESSAGE, msg);
86         intent.putExtra(EXTRA_ACCOUNT, account);
87         intent.putExtra(EXTRA_HIDE_EXTRA_OPTION_ONE, msg.getConversation() == null);
88         return intent;
89     }
90 
91     @Override
createController()92     public PhotoViewController createController() {
93         return new MailPhotoViewController(this);
94     }
95 }
96