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