ActivityController.java revision 23aadfd1c83e08b6723d4cb9357b2908cc464a86
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. If the conversation is null, this is a request to pop 223 * <em>out</em> of conversation view mode and head back to conversation list mode, or whatever 224 * should best show in its place. 225 * @param conversation conversation to display, possibly null. 226 */ 227 void showConversation(Conversation conversation); 228 229 /** 230 * Show the wait for account initialization mode. 231 */ 232 public void showWaitForInitialization(); 233 234 /** 235 * Dismiss the wait for account initialization mode. 236 */ 237 public void hideWaitForInitialization(); 238 239 /** 240 * Update the wait for account initialization mode. 241 */ 242 public void updateWaitMode(); 243 244 public boolean inWaitMode(); 245 246 /** 247 * Show the folder list associated with the currently selected account. 248 */ 249 void showFolderList(); 250 251 /** 252 * Handle a touch event. 253 */ 254 void onTouchEvent(MotionEvent event); 255 256 /** 257 * Return the settings currently being used by this activity. 258 * @return 259 */ 260 Settings getSettings(); 261 262 /** 263 * Returns whether the first conversation in the conversation list should be 264 * automatically selected and shown. 265 */ 266 boolean shouldShowFirstConversation(); 267 268 public ConversationSelectionSet getSelectedSet(); 269 270 /** 271 * Start search mode if the account being view supports the search capability. 272 */ 273 void startSearch(); 274 275 /** 276 * Exit the search mode, popping off one activity so that the back stack is fine. 277 */ 278 void exitSearchMode(); 279 280 /** 281 * Supports dragging conversations to a folder. 282 */ 283 boolean supportsDrag(DragEvent event, Folder folder); 284 285 /** 286 * Handles dropping conversations to a folder. 287 */ 288 void handleDrop(DragEvent event, Folder folder); 289 290 void onUndoCancel(); 291 292 /** 293 * Coordinates actions that might occur in response to a conversation that has finished loading 294 * and is now user-visible. 295 */ 296 void onConversationSeen(Conversation conv); 297 298 /** 299 * Load the default inbox associated with the current account. 300 */ 301 public abstract void loadAccountInbox(); 302 303 /** 304 * Return the folder currently being viewed by the activity. 305 */ 306 public abstract Folder getFolder(); 307} 308