1 /*
2  * Copyright (C) 2015 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 package com.android.messaging.ui;
17 
18 import android.app.Activity;
19 import android.app.Fragment;
20 import android.app.PendingIntent;
21 import android.content.ContentValues;
22 import android.content.Context;
23 import android.content.Intent;
24 import android.graphics.Point;
25 import android.graphics.Rect;
26 import android.net.Uri;
27 import android.os.Bundle;
28 
29 import com.android.messaging.Factory;
30 import com.android.messaging.datamodel.data.MessageData;
31 import com.android.messaging.util.ConversationIdSet;
32 
33 /**
34  * A central repository of Intents used to start activities.
35  */
36 public abstract class UIIntents {
get()37     public static UIIntents get() {
38         return Factory.get().getUIIntents();
39     }
40 
41     // Intent extras
42     public static final String UI_INTENT_EXTRA_CONVERSATION_ID = "conversation_id";
43 
44     // Sending draft data (from share intent / message forwarding) to the ConversationActivity.
45     public static final String UI_INTENT_EXTRA_DRAFT_DATA = "draft_data";
46 
47     // The request code for picking a media from the Document picker.
48     public static final int REQUEST_PICK_MEDIA_FROM_DOCUMENT_PICKER = 1400;
49 
50     // The request code for picking a contact card from existing Contacts apps.
51     public static final int REQUEST_PICK_CONTACT_CARD = 1500;
52 
53     // Indicates what type of notification this applies to (See BugleNotifications:
54     // UPDATE_NONE, UPDATE_MESSAGES, UPDATE_ERRORS, UPDATE_ALL)
55     public static final String UI_INTENT_EXTRA_NOTIFICATIONS_UPDATE = "notifications_update";
56 
57     // Pass a set of conversation id's.
58     public static final String UI_INTENT_EXTRA_CONVERSATION_ID_SET = "conversation_id_set";
59 
60     // Sending class zero message to its activity
61     public static final String UI_INTENT_EXTRA_MESSAGE_VALUES = "message_values";
62 
63     // For the widget to go to the ConversationList from the Conversation.
64     public static final String UI_INTENT_EXTRA_GOTO_CONVERSATION_LIST = "goto_conv_list";
65 
66     // Indicates whether a conversation is launched with custom transition.
67     public static final String UI_INTENT_EXTRA_WITH_CUSTOM_TRANSITION = "with_custom_transition";
68 
69     public static final String ACTION_RESET_NOTIFICATIONS =
70             "com.android.messaging.reset_notifications";
71 
72     // Sending VCard uri to VCard detail activity
73     public static final String UI_INTENT_EXTRA_VCARD_URI = "vcard_uri";
74 
75     public static final String CMAS_COMPONENT = "com.android.cellbroadcastreceiver";
76 
77     // Intent action for local broadcast receiver for conversation self id change.
78     public static final String CONVERSATION_SELF_ID_CHANGE_BROADCAST_ACTION =
79             "conversation_self_id_change";
80 
81     // Conversation self id
82     public static final String UI_INTENT_EXTRA_CONVERSATION_SELF_ID = "conversation_self_id";
83 
84     // For opening an APN editor on a particular row in the apn database.
85     public static final String UI_INTENT_EXTRA_APN_ROW_ID = "apn_row_id";
86 
87     // Subscription id
88     public static final String UI_INTENT_EXTRA_SUB_ID = "sub_id";
89 
90     // Per-Subscription setting activity title
91     public static final String UI_INTENT_EXTRA_PER_SUBSCRIPTION_SETTING_TITLE =
92             "per_sub_setting_title";
93 
94     // Is application settings launched as the top level settings activity?
95     public static final String UI_INTENT_EXTRA_TOP_LEVEL_SETTINGS = "top_level_settings";
96 
97     // Sending attachment uri from widget
98     public static final String UI_INTENT_EXTRA_ATTACHMENT_URI = "attachment_uri";
99 
100     // Sending attachment content type from widget
101     public static final String UI_INTENT_EXTRA_ATTACHMENT_TYPE = "attachment_type";
102 
103     public static final String ACTION_WIDGET_CONVERSATION =
104             "com.android.messaging.widget_conversation:";
105 
106     public static final String UI_INTENT_EXTRA_REQUIRES_MMS = "requires_mms";
107 
108     public static final String UI_INTENT_EXTRA_SELF_ID = "self_id";
109 
110     // Message position to scroll to.
111     public static final String UI_INTENT_EXTRA_MESSAGE_POSITION = "message_position";
112 
113     /**
114      * Launch the permission check activity
115      */
launchPermissionCheckActivity(final Context context)116     public abstract void launchPermissionCheckActivity(final Context context);
117 
launchConversationListActivity(final Context context)118     public abstract void launchConversationListActivity(final Context context);
119 
120     /**
121      * Launch an activity to show a conversation. This method by default provides no additional
122      * activity options.
123      */
launchConversationActivity(final Context context, final String conversationId, final MessageData draft)124     public void launchConversationActivity(final Context context,
125             final String conversationId, final MessageData draft) {
126         launchConversationActivity(context, conversationId, draft, null,
127                 false /* withCustomTransition */);
128     }
129 
130     /**
131      * Launch an activity to show a conversation.
132      */
launchConversationActivity(final Context context, final String conversationId, final MessageData draft, final Bundle activityOptions, final boolean withCustomTransition)133     public abstract void launchConversationActivity(final Context context,
134             final String conversationId, final MessageData draft, final Bundle activityOptions,
135             final boolean withCustomTransition);
136 
137 
138     /**
139      * Launch an activity to show conversation with conversation list in back stack.
140      */
launchConversationActivityWithParentStack(Context context, String conversationId, String smsBody)141     public abstract void launchConversationActivityWithParentStack(Context context,
142             String conversationId, String smsBody);
143 
144     /**
145      * Launch an activity to show a conversation as a new task.
146      */
launchConversationActivityNewTask(final Context context, final String conversationId)147     public abstract void launchConversationActivityNewTask(final Context context,
148             final String conversationId);
149 
150     /**
151      * Launch an activity to start a new conversation
152      */
launchCreateNewConversationActivity(final Context context, final MessageData draft)153     public abstract void launchCreateNewConversationActivity(final Context context,
154             final MessageData draft);
155 
156     /**
157      * Launch debug activity to set MMS config options.
158      */
launchDebugMmsConfigActivity(final Context context)159     public abstract void launchDebugMmsConfigActivity(final Context context);
160 
161     /**
162      * Launch an activity to change settings.
163      */
launchSettingsActivity(final Context context)164     public abstract void launchSettingsActivity(final Context context);
165 
166     /**
167      * Launch an activity to add a contact with a given destination.
168      */
launchAddContactActivity(final Context context, final String destination)169     public abstract void launchAddContactActivity(final Context context, final String destination);
170 
171     /**
172      * Launch an activity to show the document picker to pick an image/video/audio.
173      *
174      * @param fragment the requesting fragment
175      */
launchDocumentImagePicker(final Fragment fragment)176     public abstract void launchDocumentImagePicker(final Fragment fragment);
177 
178     /**
179      * Launch an activity to show the contacts list to pick one.
180      *
181      * @param fragment the requesting fragment
182      */
launchContactCardPicker(final Fragment fragment)183     public abstract void launchContactCardPicker(final Fragment fragment);
184 
185     /**
186      * Launch an activity to show people & options for a given conversation.
187      */
launchPeopleAndOptionsActivity(final Activity context, final String conversationId)188     public abstract void launchPeopleAndOptionsActivity(final Activity context,
189             final String conversationId);
190 
191     /**
192      * Launch an external activity to handle a phone call
193      * @param phoneNumber the phone number to call
194      * @param clickPosition is the location tapped to start this launch for transition use
195      */
launchPhoneCallActivity(final Context context, final String phoneNumber, final Point clickPosition)196     public abstract void launchPhoneCallActivity(final Context context, final String phoneNumber,
197                                                  final Point clickPosition);
198 
199     /**
200      * Launch an activity to show archived conversations.
201      */
launchArchivedConversationsActivity(final Context context)202     public abstract void launchArchivedConversationsActivity(final Context context);
203 
204     /**
205      * Launch an activity to show blocked participants.
206      */
launchBlockedParticipantsActivity(final Context context)207     public abstract void launchBlockedParticipantsActivity(final Context context);
208 
209     /**
210      * Launch an activity to show a class zero message
211      */
launchClassZeroActivity(Context context, ContentValues messageValues)212     public abstract void launchClassZeroActivity(Context context, ContentValues messageValues);
213 
214     /**
215      * Launch an activity to let the user forward a message
216      */
launchForwardMessageActivity(Context context, MessageData message)217     public abstract void launchForwardMessageActivity(Context context, MessageData message);
218 
219     /**
220      * Launch an activity to show details for a VCard
221      */
launchVCardDetailActivity(Context context, Uri vcardUri)222     public abstract void launchVCardDetailActivity(Context context, Uri vcardUri);
223 
224     /**
225      * Launch an external activity that handles the intent to add VCard to contacts
226      */
launchSaveVCardToContactsActivity(Context context, Uri vcardUri)227     public abstract void launchSaveVCardToContactsActivity(Context context, Uri vcardUri);
228 
229     /**
230      * Launch an activity to let the user select & unselect the list of attachments to send.
231      */
launchAttachmentChooserActivity(final Activity activity, final String conversationId, final int requestCode)232     public abstract void launchAttachmentChooserActivity(final Activity activity,
233             final String conversationId, final int requestCode);
234 
235     /**
236      * Launch full screen video viewer.
237      */
launchFullScreenVideoViewer(Context context, Uri videoUri)238     public abstract void launchFullScreenVideoViewer(Context context, Uri videoUri);
239 
240     /**
241      * Launch full screen photo viewer.
242      */
launchFullScreenPhotoViewer(Activity activity, Uri initialPhoto, Rect initialPhotoBounds, Uri photosUri)243     public abstract void launchFullScreenPhotoViewer(Activity activity, Uri initialPhoto,
244             Rect initialPhotoBounds, Uri photosUri);
245 
246     /**
247      * Launch an activity to show general app settings
248      * @param topLevel indicates whether the app settings is launched as the top-level settings
249      *        activity (instead of SettingsActivity which shows a collapsed view of the app
250      *        settings + one settings item per subscription). This is true when there's only one
251      *        active SIM in the system so we can show this activity directly.
252      */
launchApplicationSettingsActivity(Context context, boolean topLevel)253     public abstract void launchApplicationSettingsActivity(Context context, boolean topLevel);
254 
255     /**
256      * Launch an activity to show per-subscription settings
257      */
launchPerSubscriptionSettingsActivity(Context context, int subId, String settingTitle)258     public abstract void launchPerSubscriptionSettingsActivity(Context context, int subId,
259             String settingTitle);
260 
261     /**
262      * Get a ACTION_VIEW intent
263      * @param url display the data in the url to users
264      */
getViewUrlIntent(final String url)265     public abstract Intent getViewUrlIntent(final String url);
266 
267     /**
268      * Get an intent to launch the ringtone picker
269      * @param title the title to show in the ringtone picker
270      * @param existingUri the currently set uri
271      * @param defaultUri the default uri if none is currently set
272      * @param toneType type of ringtone to pick, maybe any of RingtoneManager.TYPE_*
273      */
getRingtonePickerIntent(final String title, final Uri existingUri, final Uri defaultUri, final int toneType)274     public abstract Intent getRingtonePickerIntent(final String title, final Uri existingUri,
275             final Uri defaultUri, final int toneType);
276 
277     /**
278      * Get an intent to launch the wireless alert viewer.
279      */
getWirelessAlertsIntent()280     public abstract Intent getWirelessAlertsIntent();
281 
282     /**
283      * Get an intent to launch the dialog for changing the default SMS App.
284      */
getChangeDefaultSmsAppIntent(final Activity activity)285     public abstract Intent getChangeDefaultSmsAppIntent(final Activity activity);
286 
287     /**
288      * Broadcast conversation self id change so it may be reflected in the message compose UI.
289      */
broadcastConversationSelfIdChange(final Context context, final String conversationId, final String conversationSelfId)290     public abstract void broadcastConversationSelfIdChange(final Context context,
291             final String conversationId, final String conversationSelfId);
292 
293     /**
294      * Get a PendingIntent for starting conversation list from notifications.
295      */
getPendingIntentForConversationListActivity( final Context context)296     public abstract PendingIntent getPendingIntentForConversationListActivity(
297             final Context context);
298 
299     /**
300      * Get a PendingIntent for starting conversation list from widget.
301      */
getWidgetPendingIntentForConversationListActivity( final Context context)302     public abstract PendingIntent getWidgetPendingIntentForConversationListActivity(
303             final Context context);
304 
305     /**
306      * Get a PendingIntent for showing a conversation from notifications.
307      */
getPendingIntentForConversationActivity(final Context context, final String conversationId, final MessageData draft)308     public abstract PendingIntent getPendingIntentForConversationActivity(final Context context,
309             final String conversationId, final MessageData draft);
310 
311     /**
312      * Get an Intent for showing a conversation from the widget.
313      */
getIntentForConversationActivity(final Context context, final String conversationId, final MessageData draft)314     public abstract Intent getIntentForConversationActivity(final Context context,
315             final String conversationId, final MessageData draft);
316 
317     /**
318      * Get a PendingIntent for sending a message to a conversation, without opening the Bugle UI.
319      *
320      * <p>This is intended to be used by the Android Wear companion app when sending transcribed
321      * voice replies.
322      */
getPendingIntentForSendingMessageToConversation( final Context context, final String conversationId, final String selfId, final boolean requiresMms, final int requestCode)323     public abstract PendingIntent getPendingIntentForSendingMessageToConversation(
324             final Context context, final String conversationId, final String selfId,
325             final boolean requiresMms, final int requestCode);
326 
327     /**
328      * Get a PendingIntent for clearing notifications.
329      *
330      * <p>This is intended to be used by notifications.
331      */
getPendingIntentForClearingNotifications(final Context context, final int updateTargets, final ConversationIdSet conversationIdSet, final int requestCode)332     public abstract PendingIntent getPendingIntentForClearingNotifications(final Context context,
333             final int updateTargets, final ConversationIdSet conversationIdSet,
334             final int requestCode);
335 
336     /**
337      * Get a PendingIntent for showing low storage notifications.
338      */
getPendingIntentForLowStorageNotifications(final Context context)339     public abstract PendingIntent getPendingIntentForLowStorageNotifications(final Context context);
340 
341     /**
342      * Get a PendingIntent for showing a new message to a secondary user.
343      */
getPendingIntentForSecondaryUserNewMessageNotification( final Context context)344     public abstract PendingIntent getPendingIntentForSecondaryUserNewMessageNotification(
345             final Context context);
346 
347     /**
348      * Get an intent for showing the APN editor.
349      */
getApnEditorIntent(final Context context, final String rowId, int subId)350     public abstract Intent getApnEditorIntent(final Context context, final String rowId, int subId);
351 
352     /**
353      * Get an intent for showing the APN settings.
354      */
getApnSettingsIntent(final Context context, final int subId)355     public abstract Intent getApnSettingsIntent(final Context context, final int subId);
356 
357     /**
358      * Get an intent for showing advanced settings.
359      */
getAdvancedSettingsIntent(final Context context)360     public abstract Intent getAdvancedSettingsIntent(final Context context);
361 
362     /**
363      * Get an intent for the LaunchConversationActivity.
364      */
getLaunchConversationActivityIntent(final Context context)365     public abstract Intent getLaunchConversationActivityIntent(final Context context);
366 
367     /**
368      *  Tell MediaScanner to re-scan the specified volume.
369      */
kickMediaScanner(final Context context, final String volume)370     public abstract void kickMediaScanner(final Context context, final String volume);
371 
372     /**
373      * Launch to browser for a url.
374      */
launchBrowserForUrl(final Context context, final String url)375     public abstract void launchBrowserForUrl(final Context context, final String url);
376 
377     /**
378      * Get a PendingIntent for the widget conversation template.
379      */
getWidgetPendingIntentForConversationActivity( final Context context, final String conversationId, final int requestCode)380     public abstract PendingIntent getWidgetPendingIntentForConversationActivity(
381             final Context context, final String conversationId, final int requestCode);
382 
383     /**
384      * Get a PendingIntent for the conversation widget configuration activity template.
385      */
getWidgetPendingIntentForConfigurationActivity( final Context context, final int appWidgetId)386     public abstract PendingIntent getWidgetPendingIntentForConfigurationActivity(
387             final Context context, final int appWidgetId);
388 
389 }
390