ActivityController.java revision d503df4f0c31bbf842c6a1d3cba18df8c074bf67
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
18package com.android.mail.ui;
19
20import android.app.Dialog;
21import android.app.LoaderManager;
22import android.content.Intent;
23import android.database.Cursor;
24import android.os.Bundle;
25import android.view.DragEvent;
26import android.view.KeyEvent;
27import android.view.Menu;
28import android.view.MenuItem;
29import android.view.MotionEvent;
30
31import com.android.mail.ConversationListContext;
32import com.android.mail.providers.Account;
33import com.android.mail.providers.Conversation;
34import com.android.mail.providers.Folder;
35import com.android.mail.providers.Settings;
36import com.android.mail.ui.FoldersSelectionDialog.FolderChangeCommitListener;
37import com.android.mail.ui.ViewMode.ModeChangeListener;
38
39import java.util.Collection;
40
41/**
42 * An Activity controller knows how to combine views and listeners into a functioning activity.
43 * ActivityControllers are delegates that implement methods by calling underlying views to modify,
44 * or respond to user action.
45 */
46public interface ActivityController extends DragListener, LayoutListener, SubjectDisplayChanger,
47        ModeChangeListener, ConversationListCallbacks, FolderChangeCommitListener,
48        FolderChangeListener, AccountChangeListener, LoaderManager.LoaderCallbacks<Cursor>,
49        ConversationSetObserver,
50        FolderListFragment.FolderListSelectionListener, HelpCallback, UndoBarView.UndoListener {
51
52    // As far as possible, the methods here that correspond to Activity lifecycle have the same name
53    // as their counterpart in the Activity lifecycle.
54
55    /**
56     * Returns the current account.
57     */
58    Account getCurrentAccount();
59
60    /**
61     * Returns the current conversation list context.
62     */
63    ConversationListContext getCurrentListContext();
64
65    /**
66     * Return the current mode the activity is in. Values need to be matched against constants in
67     * {@link ViewMode}.
68     * @return
69     */
70    int getMode();
71
72    /**
73     *
74     */
75    void handleConversationLoadError();
76
77    /**
78     * @see android.app.Activity#onActivityResult
79     * @param requestCode
80     * @param resultCode
81     * @param data
82     */
83    void onActivityResult(int requestCode, int resultCode, Intent data);
84
85    /**
86     * Called by the Mail activity when the back button is pressed. Returning true consumes the
87     * event and disallows the calling method from trying to handle the back button any other way.
88     *
89     * @see android.app.Activity#onBackPressed()
90     * @return true if the back press was handled and the event was consumed. Return false if the
91     * event was not consumed.
92     */
93    boolean onBackPressed();
94
95    /**
96     * Called by the Mail activity when the up button is pressed.
97     * @return
98     */
99    boolean onUpPressed();
100
101    /**
102     * Called when the root activity calls onCreate. Any initialization needs to
103     * be done here. Subclasses need to call their parents' onCreate method, since it performs
104     * valuable initialization common to all subclasses.
105     *
106     * This was called initialize in Gmail.
107     *
108     * @see android.app.Activity#onCreate
109     * @param savedState
110     * @return true if the controller was able to initialize successfully, false otherwise.
111     */
112    boolean onCreate(Bundle savedState);
113
114    /**
115     * @see android.app.Activity#onCreateDialog(int, Bundle)
116     * @param id
117     * @param bundle
118     * @return
119     */
120    Dialog onCreateDialog(int id, Bundle bundle);
121
122    /**
123     * @see android.app.Activity#onCreateOptionsMenu(Menu)
124     * @param menu
125     * @return
126     */
127    boolean onCreateOptionsMenu(Menu menu);
128
129    /**
130     * @see android.app.Activity#onKeyDown(int, KeyEvent)
131     * @param keyCode
132     * @param event
133     * @return
134     */
135    boolean onKeyDown(int keyCode, KeyEvent event);
136
137    /**
138     * Called by Mail activity when menu items are selected
139     * @see android.app.Activity#onOptionsItemSelected(MenuItem)
140     * @param item
141     * @return
142     */
143    boolean onOptionsItemSelected(MenuItem item);
144
145    /**
146     * Called by the Mail activity on Activity pause.
147     * @see android.app.Activity#onPause
148     */
149    void onPause();
150
151    /**
152     * @see android.app.Activity#onDestroy
153     */
154    void onDestroy();
155
156    /**
157     * @see android.app.Activity#onPrepareDialog
158     * @param id
159     * @param dialog
160     * @param bundle
161     */
162    void onPrepareDialog(int id, Dialog dialog, Bundle bundle);
163
164    /**
165     * Called by the Mail activity when menu items need to be prepared.
166     * @see android.app.Activity#onPrepareOptionsMenu(Menu)
167     * @param menu
168     * @return
169     */
170    boolean onPrepareOptionsMenu(Menu menu);
171
172    /**
173     * Called by the Mail activity on Activity resume.
174     * @see android.app.Activity#onResume
175     */
176    void onResume();
177
178    /**
179     * @see android.app.Activity#onRestoreInstanceState
180     */
181    void onRestoreInstanceState(Bundle savedInstanceState);
182
183    /**
184     * @see android.app.Activity#onSaveInstanceState
185     * @param outState
186     */
187    void onSaveInstanceState(Bundle outState);
188
189    /**
190     * @see android.app.Activity#onSearchRequested()
191     */
192    void onSearchRequested(String query);
193
194    /**
195     * Called by the Mail activity on Activity stop.
196     * @see android.app.Activity#onStop
197     */
198    void onStop();
199
200    /**
201     * Called by the Mail activity when window focus changes.
202     * @see android.app.Activity#onWindowFocusChanged(boolean)
203     * @param hasFocus
204     */
205    void onWindowFocusChanged(boolean hasFocus);
206
207    /**
208     * Set the Action Bar icon according to the mode. The Action Bar icon can contain a back button
209     * or not. The individual controller is responsible for changing the icon based on the mode.
210     */
211    void resetActionBarIcon();
212
213    /**
214     * Show the conversation List with the list context provided here. On certain layouts, this
215     * might show more than just the conversation list. For instance, on tablets this might show
216     * the conversations along with the conversation list.
217     * @param listContext context providing information on what conversation list to display.
218     */
219    void showConversationList(ConversationListContext listContext);
220
221    /**
222     * Show the conversation provided here.
223     * @param conversation conversation to display.
224     */
225    void showConversation(Conversation conversation);
226
227    /**
228     * Show the wait for account initilization mode.
229     */
230    public void showWaitForInitialization();
231
232    /**
233     * Dismiss the wait for account initization mode.
234     */
235    public void hideWaitForInitialization();
236
237    /**
238     * Update the wait for account intization mode.
239     */
240    public void updateWaitMode();
241
242    public boolean inWaitMode();
243
244    /**
245     * Show the folder list associated with the currently selected account.
246     */
247    void showFolderList();
248
249    /**
250     * Handle a touch event.
251     */
252    void onTouchEvent(MotionEvent event);
253
254    /**
255     * Return the settings currently being used by this activity.
256     * @return
257     */
258    Settings getSettings();
259
260    /**
261     * Returns whether the first conversation in the conversation list should be
262     * automatically selected and shown.
263     */
264    boolean shouldShowFirstConversation();
265
266    public ConversationSelectionSet getSelectedSet();
267
268    /**
269     * Start search mode if the account being view supports the search capability.
270     */
271    void startSearch();
272
273    /**
274     * Exit the search mode, popping off one activity so that the back stack is fine.
275     */
276    void exitSearchMode();
277
278    /**
279     * Supports dragging conversations to a folder.
280     */
281    boolean supportsDrag(DragEvent event, Folder folder);
282
283    /**
284     * Handles dropping conversations to a folder.
285     */
286    void handleDrop(DragEvent event, Folder folder);
287
288    void onUndoCancel();
289
290    /**
291     * Coordinates actions that might occur in response to a conversation that has finished loading
292     * and is now user-visible.
293     */
294    void onConversationSeen(Conversation conv);
295
296    /**
297     * Returns the destructive action that can change the folders for a specific conversation.
298     * @param target the conversations to act upon.
299     * @return
300     */
301    public abstract DestructiveAction getFolderDestructiveAction(Collection<Conversation> target);
302
303    /**
304     * Load the default inbox associated with the current account.
305     */
306    public abstract void loadAccountInbox();
307}
308