ActivityController.java revision 8c887ef97607ad5c2c94d1d3b902afe6d5ef95a0
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.content.Intent;
22import android.content.res.Configuration;
23import android.os.Bundle;
24import android.view.DragEvent;
25import android.view.KeyEvent;
26import android.view.Menu;
27import android.view.MenuItem;
28import android.view.MotionEvent;
29
30import com.android.mail.ConversationListContext;
31import com.android.mail.browse.ConversationCursor.ConversationListener;
32import com.android.mail.browse.ConversationListFooterView;
33import com.android.mail.providers.Account;
34import com.android.mail.providers.Folder;
35import com.android.mail.ui.ViewMode.ModeChangeListener;
36
37/**
38 * An Activity controller knows how to combine views and listeners into a functioning activity.
39 * ActivityControllers are delegates that implement methods by calling underlying views to modify,
40 * or respond to user action.
41 */
42public interface ActivityController extends LayoutListener,
43        ModeChangeListener, ConversationListCallbacks,
44        FolderChangeListener, ConversationSetObserver, ConversationListener,
45        FolderListFragment.FolderListSelectionListener, HelpCallback, UndoListener,
46        ConversationUpdater, ErrorListener, FolderController, AccountController,
47        ConversationPositionTracker.Callbacks, ConversationListFooterView.FooterViewClickListener,
48        RecentFolderController, UpOrBackController {
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     * @see android.app.Activity#onActivityResult
65     * @param requestCode
66     * @param resultCode
67     * @param data
68     */
69    void onActivityResult(int requestCode, int resultCode, Intent data);
70
71    /**
72     * Called by the Mail activity when the back button is pressed. Returning true consumes the
73     * event and disallows the calling method from trying to handle the back button any other way.
74     *
75     * @see android.app.Activity#onBackPressed()
76     * @return true if the back press was handled and the event was consumed. Return false if the
77     * event was not consumed.
78     */
79    boolean onBackPressed();
80
81    /**
82     * Called by the Mail activity when the up button is pressed.
83     * @return
84     */
85    boolean onUpPressed();
86
87    /**
88     * Called when the root activity calls onCreate. Any initialization needs to
89     * be done here. Subclasses need to call their parents' onCreate method, since it performs
90     * valuable initialization common to all subclasses.
91     *
92     * This was called initialize in Gmail.
93     *
94     * @see android.app.Activity#onCreate
95     * @param savedState
96     * @return true if the controller was able to initialize successfully, false otherwise.
97     */
98    boolean onCreate(Bundle savedState);
99
100    /**
101     * @see android.app.Activity#onPostCreate
102     */
103    void onPostCreate(Bundle savedState);
104
105    /**
106     * @see android.app.Activity#onConfigurationChanged
107     */
108    void onConfigurationChanged(Configuration newConfig);
109
110    /**
111     * @see android.app.Activity#onStart
112     */
113    void onStart();
114
115    /**
116     * Called when the the root activity calls onRestart
117     * @see android.app.Activity#onRestart
118     */
119    void onRestart();
120
121    /**
122     * @see android.app.Activity#onCreateDialog(int, Bundle)
123     * @param id
124     * @param bundle
125     * @return
126     */
127    Dialog onCreateDialog(int id, Bundle bundle);
128
129    /**
130     * @see android.app.Activity#onCreateOptionsMenu(Menu)
131     * @param menu
132     * @return
133     */
134    boolean onCreateOptionsMenu(Menu menu);
135
136    /**
137     * @see android.app.Activity#onKeyDown(int, KeyEvent)
138     * @param keyCode
139     * @param event
140     * @return
141     */
142    boolean onKeyDown(int keyCode, KeyEvent event);
143
144    /**
145     * Called by Mail activity when menu items are selected
146     * @see android.app.Activity#onOptionsItemSelected(MenuItem)
147     * @param item
148     * @return
149     */
150    boolean onOptionsItemSelected(MenuItem item);
151
152    /**
153     * Called by the Mail activity on Activity pause.
154     * @see android.app.Activity#onPause
155     */
156    void onPause();
157
158    /**
159     * @see android.app.Activity#onDestroy
160     */
161    void onDestroy();
162
163    /**
164     * @see android.app.Activity#onPrepareDialog
165     * @param id
166     * @param dialog
167     * @param bundle
168     */
169    void onPrepareDialog(int id, Dialog dialog, Bundle bundle);
170
171    /**
172     * Called by the Mail activity when menu items need to be prepared.
173     * @see android.app.Activity#onPrepareOptionsMenu(Menu)
174     * @param menu
175     * @return
176     */
177    boolean onPrepareOptionsMenu(Menu menu);
178
179    /**
180     * Called by the Mail activity on Activity resume.
181     * @see android.app.Activity#onResume
182     */
183    void onResume();
184
185    /**
186     * @see android.app.Activity#onRestoreInstanceState
187     */
188    void onRestoreInstanceState(Bundle savedInstanceState);
189
190    /**
191     * @see android.app.Activity#onSaveInstanceState
192     * @param outState
193     */
194    void onSaveInstanceState(Bundle outState);
195
196    /**
197     * Begin a search with the given query string.
198     */
199    void executeSearch(String query);
200
201    /**
202     * Called by the Mail activity on Activity stop.
203     * @see android.app.Activity#onStop
204     */
205    void onStop();
206
207    /**
208     * Called by the Mail activity when window focus changes.
209     * @see android.app.Activity#onWindowFocusChanged(boolean)
210     * @param hasFocus
211     */
212    void onWindowFocusChanged(boolean hasFocus);
213
214    /**
215     * Show the conversation List with the list context provided here. On certain layouts, this
216     * might show more than just the conversation list. For instance, on tablets this might show
217     * the conversations along with the conversation list.
218     * @param listContext context providing information on what conversation list to display.
219     */
220    void showConversationList(ConversationListContext listContext);
221
222    /**
223     * Show the wait for account initialization mode.
224     */
225    public void showWaitForInitialization();
226
227    /**
228     * Handle a touch event.
229     */
230    void onTouchEvent(MotionEvent event);
231
232    /**
233     * Returns whether the first conversation in the conversation list should be
234     * automatically selected and shown.
235     */
236    boolean shouldShowFirstConversation();
237
238    /**
239     * Get the selected set of conversations. Guaranteed to return non-null, this should return
240     * an empty set if no conversation is currently selected.
241     * @return
242     */
243    public ConversationSelectionSet getSelectedSet();
244
245    /**
246     * Start search mode if the account being view supports the search capability.
247     */
248    void startSearch();
249
250    /**
251     * Exit the search mode, popping off one activity so that the back stack is fine.
252     */
253    void exitSearchMode();
254
255    /**
256     * Supports dragging conversations to a folder.
257     */
258    boolean supportsDrag(DragEvent event, Folder folder);
259
260    /**
261     * Handles dropping conversations to a folder.
262     */
263    void handleDrop(DragEvent event, Folder folder);
264
265    /**
266     * Load the default inbox associated with the current account.
267     */
268    public void loadAccountInbox();
269
270    /**
271     * Return the folder currently being viewed by the activity.
272     */
273    public Folder getHierarchyFolder();
274
275    /**
276     * Set the folder currently selected in the folder selection hierarchy fragments.
277     */
278    void setHierarchyFolder(Folder folder);
279
280    /**
281     * Handles the animation end of the animated adapter.
282     */
283    void onAnimationEnd(AnimatedAdapter animatedAdapter);
284
285    /**
286     * Called when the user has started a drag/ drop gesture.
287     */
288    void startDragMode();
289
290    /**
291     * Called when the user has ended drag/drop.
292     */
293    void stopDragMode();
294
295    /**
296     * Called when Accessibility is enabled or disabled.
297     */
298    void onAccessibilityStateChanged();
299
300    /**
301     * Called to determine if the drawer is enabled for this controller/activity instance.
302     * Note: the value returned should not change for this controller instance.
303     */
304    boolean isDrawerEnabled();
305}
306