Adding more ActivityController dependencies
ui.ControllableActivity added from Gmail.
One pane layout files brought in.
Minor changes to make everything work with the test activity.
Change-Id: I8cacd5f36394fe4a786590e2e381369a3afb5494
diff --git a/src/com/android/mail/ui/AbstractActivityController.java b/src/com/android/mail/ui/AbstractActivityController.java
index c411a6f..ebccce2 100644
--- a/src/com/android/mail/ui/AbstractActivityController.java
+++ b/src/com/android/mail/ui/AbstractActivityController.java
@@ -17,18 +17,26 @@
package com.android.mail.ui;
+
+import android.app.ActionBar;
import android.app.Activity;
import android.app.Dialog;
+import android.app.ActionBar.LayoutParams;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
+import android.os.Parcelable;
import android.view.ActionMode;
import android.view.KeyEvent;
+import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.MotionEvent;
+import android.widget.LinearLayout;
-import com.android.mail.ViewMode;
+import com.android.mail.ConversationListContext;
+import com.android.mail.R;
+import com.android.mail.providers.Account;
import com.android.mail.providers.Folder;
/**
@@ -45,9 +53,18 @@
* In the Gmail codebase, this was called BaseActivityController</p>
*/
public abstract class AbstractActivityController implements ActivityController {
- protected final MailActivity mActivity;
- protected final ViewMode mViewMode;
+ private static final String SAVED_CONVERSATION = "saved-conversation";
+ private static final String SAVED_CONVERSATION_POSITION = "saved-conv-pos";
+ private static final String SAVED_CONVERSATIONS = "saved-conversations";
+ // Keys for serialization of various information in Bundles.
+ private static final String SAVED_LIST_CONTEXT = "saved-list-context";
+ private Account mAccount;
+ private ActionBarView mActionBarView;
+
+ protected final RestrictedActivity mActivity;
+ private ConversationSelectionSet mBatchConversations = new ConversationSelectionSet();
protected final Context mContext;
+ protected final ViewMode mViewMode;
public AbstractActivityController(MailActivity activity, ViewMode viewMode) {
mActivity = activity;
@@ -56,10 +73,147 @@
}
@Override
+ public void clearSubject() {
+ // TODO(viki): Auto-generated method stub
+
+ }
+
+ @Override
+ public void dispatchTouchEvent(MotionEvent ev) {
+ // TODO(viki): Auto-generated method stub
+
+ }
+
+ @Override
+ public void doneChangingFolders(FolderOperations folderOperations) {
+ // TODO(viki): Auto-generated method stub
+
+ }
+
+ @Override
+ public void enterSearchMode() {
+ // TODO(viki): Auto-generated method stub
+
+ }
+
+ @Override
+ public void exitSearchMode() {
+ // TODO(viki): Auto-generated method stub
+
+ }
+
+ @Override
+ public ConversationSelectionSet getBatchConversations() {
+ // TODO(viki): Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public String getCurrentAccount() {
+ // TODO(viki): Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public ConversationListContext getCurrentListContext() {
+ // TODO(viki): Auto-generated method stub
+ return null;
+ }
+
+ @Override
public String getHelpContext() {
return "Mail";
}
+ @Override
+ public String getUnshownSubject(String subject) {
+ // Calculate how much of the subject is shown, and return the remaining.
+ return null;
+ }
+
+ @Override
+ public void handleConversationLoadError() {
+ // TODO(viki): Auto-generated method stub
+
+ }
+
+ @Override
+ public void handleSearchRequested() {
+ // TODO(viki): Auto-generated method stub
+
+ }
+
+ /**
+ * Initialize the action bar. This is not visible to OnePaneController and TwoPaneController so
+ * they cannot override this behavior.
+ */
+ private void initCustomActionBarView() {
+ ActionBar actionBar = mActivity.getActionBar();
+ mActionBarView = (MailActionBar) LayoutInflater.from(mContext).inflate(
+ R.layout.actionbar_view, null);
+
+ if (actionBar != null && mActionBarView != null) {
+ // Why have a different variable for the same thing? We should apply the same actions
+ // on mActionBarView instead.
+ // mSubjectDisplayer = (ConversationSubjectDisplayer) mActionBarView;
+ mActionBarView.initialize(mActivity, this, mViewMode, actionBar);
+ actionBar.setCustomView((LinearLayout) mActionBarView, new ActionBar.LayoutParams(
+ LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
+ actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM,
+ ActionBar.DISPLAY_SHOW_CUSTOM
+ | ActionBar.DISPLAY_SHOW_TITLE);
+ }
+ }
+
+ /**
+ * Returns whether the conversation list fragment is visible or not. Different layouts will have
+ * their own notion on the visibility of fragments, so this method needs to be overriden.
+ * @return
+ */
+ protected abstract boolean isConversationListVisible();
+
+ @Override
+ public boolean navigateToAccount(String account) {
+ // TODO(viki): Auto-generated method stub
+ return false;
+ }
+
+ @Override
+ public void navigateToFolder(String folderCanonicalName) {
+ // TODO(viki): Auto-generated method stub
+
+ }
+
+ @Override
+ public void onActionModeFinished(ActionMode mode) {
+ // TODO(viki): Auto-generated method stub
+
+ }
+
+ @Override
+ public void onActionModeStarted(ActionMode mode) {
+ // TODO(viki): Auto-generated method stub
+
+ }
+
+ @Override
+ public void onActivityResult(int requestCode, int resultCode, Intent data) {
+ // TODO(viki): Auto-generated method stub
+
+ }
+
+ @Override
+ public boolean onBackPressed() {
+ // TODO(viki): Auto-generated method stub
+ return false;
+ }
+
+ @Override
+ public void onConversationListVisibilityChanged(boolean visible) {
+ // TODO(viki): Auto-generated method stub
+
+ }
+
/**
* By default, doing nothing is right. A two-pane controller will need to
* override this.
@@ -71,71 +225,13 @@
}
@Override
- public void onLabelChanged(Folder label, long conversationId, boolean added) {
- // TODO(viki): Auto-generated method stub
-
- }
-
- @Override
- public void doneChangingLabels(FolderOperations labelOperations) {
- // TODO(viki): Auto-generated method stub
-
- }
-
- @Override
- public void handleSearchRequested() {
- // TODO(viki): Auto-generated method stub
-
- }
-
- @Override
- public void onStartBulkOperation() {
- // TODO(viki): Auto-generated method stub
-
- }
-
- @Override
- public void onEndBulkOperation() {
- // TODO(viki): Auto-generated method stub
-
- }
-
- @Override
- public void onStartDragMode() {
- // TODO(viki): Auto-generated method stub
-
- }
-
- @Override
- public void onStopDragMode() {
- // TODO(viki): Auto-generated method stub
-
- }
-
- @Override
- public void setSubject(String subject) {
- // Do something useful with the subject. This requires changing the
- // conversation view's
- // subject text.
- }
-
- @Override
- public String getUnshownSubject(String subject) {
- // Calculate how much of the subject is shown, and return the remaining.
- return null;
- }
-
- @Override
- public void onConversationListVisibilityChanged(boolean visible) {
- // TODO(viki): Auto-generated method stub
-
- }
-
- @Override
public void onCreate(Bundle savedState) {
// Initialize the action bar view.
+ initCustomActionBarView();
final Intent intent = mActivity.getIntent();
+ // TODO(viki) Choose an account here.
+
// Allow shortcut keys to function for the ActionBar and menus.
mActivity.setDefaultKeyMode(Activity.DEFAULT_KEYS_SHORTCUT);
final Context context = mActivity.getApplicationContext();
@@ -144,48 +240,10 @@
restoreState(savedState);
}
- /**
- * Restore the state from the previous bundle.
- * @param savedState
- */
- protected void restoreState(Bundle savedState) {
- // Do nothing here.
- }
-
@Override
- public void onSetEmpty(ConversationSelectionSet set) {
+ public Dialog onCreateDialog(int id, Bundle bundle) {
// TODO(viki): Auto-generated method stub
-
- }
-
- @Override
- public void onSetPopulated(ConversationSelectionSet set) {
- // TODO(viki): Auto-generated method stub
-
- }
-
- @Override
- public void onSetChanged(ConversationSelectionSet set) {
- // TODO(viki): Auto-generated method stub
-
- }
-
- @Override
- public void onResume() {
- // TODO(viki): Auto-generated method stub
-
- }
-
- @Override
- public void onPause() {
- // TODO(viki): Auto-generated method stub
-
- }
-
- @Override
- public void onStop() {
- // TODO(viki): Auto-generated method stub
-
+ return null;
}
@Override
@@ -195,31 +253,31 @@
}
@Override
- public boolean onPrepareOptionsMenu(Menu menu) {
+ public void onEndBulkOperation() {
+ // TODO(viki): Auto-generated method stub
+
+ }
+
+ @Override
+ public boolean onKeyDown(int keyCode, KeyEvent event) {
// TODO(viki): Auto-generated method stub
return false;
}
@Override
+ public void onFolderChanged(Folder folder, long conversationId, boolean added) {
+ // TODO(viki): Auto-generated method stub
+
+ }
+
+ @Override
public boolean onOptionsItemSelected(MenuItem item) {
// TODO(viki): Auto-generated method stub
return false;
}
@Override
- public void onWindowFocusChanged(boolean hasFocus) {
- // TODO(viki): Auto-generated method stub
-
- }
-
- @Override
- public boolean onBackPressed() {
- // TODO(viki): Auto-generated method stub
- return false;
- }
-
- @Override
- public void onSaveInstanceState(Bundle outState) {
+ public void onPause() {
// TODO(viki): Auto-generated method stub
}
@@ -231,67 +289,159 @@
}
@Override
- public void onActionModeStarted(ActionMode mode) {
- // TODO(viki): Auto-generated method stub
-
- }
-
- @Override
- public void onActionModeFinished(ActionMode mode) {
- // TODO(viki): Auto-generated method stub
-
- }
-
- @Override
- public void onActivityResult(int requestCode, int resultCode, Intent data) {
- // TODO(viki): Auto-generated method stub
-
- }
-
- @Override
- public ConversationSelectionSet getBatchConversations() {
- // TODO(viki): Auto-generated method stub
- return null;
- }
-
- @Override
- public void handleConversationLoadError() {
- // TODO(viki): Auto-generated method stub
-
- }
-
- @Override
- public void dispatchTouchEvent(MotionEvent ev) {
- // TODO(viki): Auto-generated method stub
-
- }
-
- @Override
- public Dialog onCreateDialog(int id, Bundle bundle) {
- // TODO(viki): Auto-generated method stub
- return null;
- }
-
- @Override
- public boolean onKeyDown(int keyCode, KeyEvent event) {
+ public boolean onPrepareOptionsMenu(Menu menu) {
// TODO(viki): Auto-generated method stub
return false;
}
@Override
+ public void onResume() {
+ // TODO(viki): Auto-generated method stub
+ mBatchConversations.addObserver(this);
+ if (mActionBarView != null) {
+ mActionBarView.onResume();
+ }
+ }
+
+ @Override
+ public void onSaveInstanceState(Bundle outState) {
+ // TODO(viki): Auto-generated method stub
+
+ }
+
+ @Override
public void onSearchRequested() {
// TODO(viki): Auto-generated method stub
}
@Override
+ public void onSetChanged(ConversationSelectionSet set) {
+ // We don't care about changes to the set. Ignore.
+ }
+
+ @Override
+ public void onSetEmpty() {
+ }
+
+ @Override
+ public void onSetPopulated(ConversationSelectionSet set) {
+ // TODO(viki): Auto-generated method stub
+
+ }
+
+ @Override
+ public void onStartBulkOperation() {
+ // TODO(viki): Auto-generated method stub
+
+ }
+
+ @Override
+ public void onStartDragMode() {
+ // TODO(viki): Auto-generated method stub
+
+ }
+
+ @Override
+ public void onStop() {
+ // TODO(viki): Auto-generated method stub
+
+ }
+
+ @Override
+ public void onStopDragMode() {
+ // TODO(viki): Auto-generated method stub
+
+ }
+
+ @Override
public void onViewModeChanged(ViewMode mode) {
// TODO(viki): Auto-generated method stub
}
@Override
- public void clearSubject() {
+ public void onWindowFocusChanged(boolean hasFocus) {
+ // TODO(viki): Auto-generated method stub
+
+ }
+
+ @Override
+ public void reloadSearch(String string) {
+ // TODO(viki): Auto-generated method stub
+
+ }
+
+ /**
+ * @param savedState
+ */
+ protected void restoreListContext(Bundle savedState) {
+ // TODO(viki): Auto-generated method stub
+
+ }
+
+ /**
+ * Restore the state of selected conversations. This needs to be done after the correct mode
+ * is set and the action bar is fully initialized. If not, several key pieces of state
+ * information will be missing, and the split views may not be initialized correctly.
+ * @param savedState
+ */
+ private void restoreSelectedConversations(Bundle savedState) {
+ if (savedState != null){
+ // Restore the view mode? This looks wrong.
+ mBatchConversations = savedState.getParcelable(SAVED_CONVERSATIONS);
+ if (mBatchConversations.isEmpty()) {
+ onSetPopulated(mBatchConversations);
+ onConversationVisibilityChanged(isConversationListVisible());
+ } else {
+ onSetEmpty();
+ }
+ } else {
+ onSetEmpty();
+ }
+ }
+
+ /**
+ * Restore the state from the previous bundle. Subclasses should call this method from the
+ * parent class, since it performs important UI initialization.
+ * @param savedState
+ */
+ protected void restoreState(Bundle savedState) {
+ if (savedState != null) {
+ restoreListContext(savedState);
+ // Attach the menu handler here.
+ } else {
+ final Intent intent = mActivity.getIntent();
+ // TODO(viki): Show the list context from Intent
+ // showConversationList(ConversationListContext.forIntent(mContext, mAccount, intent));
+ }
+
+ // Set the correct mode based on the current context
+
+ // And restore the state of selected conversations
+ restoreSelectedConversations(savedState);
+ }
+
+ @Override
+ public void setSubject(String subject) {
+ // Do something useful with the subject. This requires changing the
+ // conversation view's subject text.
+ }
+
+ @Override
+ public void showFolderList() {
+ // TODO(viki): Auto-generated method stub
+
+ }
+
+ @Override
+ public void startActionBarStatusCursorLoader(String account) {
+ // TODO(viki): Auto-generated method stub
+
+ }
+
+ @Override
+ public void stopActionBarStatusCursorLoader(String account) {
// TODO(viki): Auto-generated method stub
}