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