diff --git a/src/com/android/email/activity/MessageListXL.java b/src/com/android/email/activity/MessageListXL.java index 180f7bb42..26d9e0fbb 100644 --- a/src/com/android/email/activity/MessageListXL.java +++ b/src/com/android/email/activity/MessageListXL.java @@ -174,6 +174,7 @@ public class MessageListXL extends Activity implements protected void onResume() { if (Email.DEBUG_LIFECYCLE && Email.DEBUG) Log.d(Email.LOG_TAG, "MessageListXL onResume"); super.onResume(); + mFragmentManager.onResume(); // On MessageList.onResume, we go back to Welcome if an account has been added/removed. // We don't need to do that here, because when the activity resumes, the account list loader @@ -212,11 +213,25 @@ public class MessageListXL extends Activity implements if (Email.DEBUG_LIFECYCLE && Email.DEBUG) { Log.d(Email.LOG_TAG, "MessageListXL onBackPressed"); } + onBackPressed(true); + } + + /** + * Performs the back action. + * + * @param mayCloseActivity if true, the activity will close if it's already on top of the + * internal back state stack. + */ + private boolean onBackPressed(boolean mayCloseActivity) { if (mFragmentManager.onBackPressed()) { - return; + return true; } - // Perform the default behavior. - super.onBackPressed(); + if (mayCloseActivity) { + // Perform the default behavior. + super.onBackPressed(); + return true; + } + return false; } private void onCurrentMessageGone() { @@ -601,7 +616,8 @@ public class MessageListXL extends Activity implements switch (item.getItemId()) { case android.R.id.home: // Comes from the action bar when the app icon on the left is pressed. - return mFragmentManager.onBackPressed(); + // It works like a back press, but it won't close the activity. + return onBackPressed(false); case R.id.compose: return onCompose(); case R.id.refresh: diff --git a/src/com/android/email/activity/MessageListXLFragmentManager.java b/src/com/android/email/activity/MessageListXLFragmentManager.java index 77630c5d0..2708da56a 100644 --- a/src/com/android/email/activity/MessageListXLFragmentManager.java +++ b/src/com/android/email/activity/MessageListXLFragmentManager.java @@ -124,8 +124,6 @@ class MessageListXLFragmentManager { mThreePane.getMiddlePaneId()); mMessageViewFragment = (MessageViewFragment) fm.findFragmentById( mThreePane.getRightPaneId()); - - updateActionBar(); } /** Set callback for fragment. */ @@ -197,6 +195,8 @@ class MessageListXLFragmentManager { return; } mIsActivityResumed = true; + + updateActionBar(); } /** @@ -303,7 +303,7 @@ class MessageListXLFragmentManager { // Open mailbox list, clear message list / message view mMailboxListFragment.openMailboxes(mAccountId); mMessageListFragment.clearContent(); - hideMessageView(); + mThreePane.showLeftPane(); // Show mailbox list if ((accountId == Account.ACCOUNT_ID_COMBINED_VIEW) && (mailboxId == -1)) { // When opening the Combined view, the right pane will be "combined inbox". @@ -321,12 +321,7 @@ class MessageListXLFragmentManager { * @return true "back" is handled. */ public boolean onBackPressed() { - if (isMessageSelected()) { - // Go back to the message list. - goBackToMailbox(); - return true; - } - return false; // Not handled. + return mThreePane.onBackPressed(); } /** @@ -334,7 +329,6 @@ class MessageListXLFragmentManager { */ public void goBackToMailbox() { if (isMessageSelected()) { - hideMessageView(); selectMailbox(getMailboxId(), false); } } @@ -374,7 +368,7 @@ class MessageListXLFragmentManager { mMailboxListFragment.setSelectedMailbox(mMailboxId); mTargetActivity.onMailboxChanged(mAccountId, mMailboxId); - hideMessageView(); + mThreePane.showLeftPane(); // Show mailbox list } /** @@ -402,16 +396,17 @@ class MessageListXLFragmentManager { // Open message mMessageListFragment.setSelectedMessage(mMessageId); mMessageViewFragment.openMessage(mMessageId); - hideMessageBoxList(); + mThreePane.showRightPane(); // Show message view } - private void hideMessageBoxList() { - mThreePane.showRightPane(true); - } - - private void hideMessageView() { + /** + * Unselect the currently viewed message, if any, and release the resoruce grabbed by the + * message view. + * + * This must be called when the three pane reports that the message view pane gets hidden. + */ + private void onMessageViewClosed() { mMessageId = -1; - mThreePane.showRightPane(false); mMessageListFragment.setSelectedMessage(-1); mMessageViewFragment.clearContent(); } @@ -469,8 +464,14 @@ class MessageListXLFragmentManager { private class ThreePaneLayoutCallback implements ThreePaneLayout.Callback { @Override - public void onVisiblePanesChanged() { + public void onVisiblePanesChanged(int previousVisiblePanes) { updateActionBar(); + final int visiblePanes = mThreePane.getVisiblePanes(); + if (((visiblePanes & ThreePaneLayout.PANE_RIGHT) == 0) && + ((previousVisiblePanes & ThreePaneLayout.PANE_RIGHT) != 0)) { + // Message view just got hidden + onMessageViewClosed(); + } } } } diff --git a/src/com/android/email/activity/ThreePaneLayout.java b/src/com/android/email/activity/ThreePaneLayout.java index b2f7f88e7..ae88e0aed 100644 --- a/src/com/android/email/activity/ThreePaneLayout.java +++ b/src/com/android/email/activity/ThreePaneLayout.java @@ -50,9 +50,10 @@ public class ThreePaneLayout extends LinearLayout implements View.OnClickListene /** Portrait mode only: message view + expanded message list */ private static final int STATE_PORTRAIT_MIDDLE_EXPANDED = 3; - public static final int PANE_LEFT = 1 << 0; + // Flags for getVisiblePanes() + public static final int PANE_LEFT = 1 << 2; public static final int PANE_MIDDLE = 1 << 1; - public static final int PANE_RIGHT = 1 << 2; + public static final int PANE_RIGHT = 1 << 0; private int mPaneState = STATE_LEFT_UNINITIALIZED; @@ -69,13 +70,13 @@ public class ThreePaneLayout extends LinearLayout implements View.OnClickListene public interface Callback { /** Called when {@link ThreePaneLayout#getVisiblePanes()} has changed. */ - public void onVisiblePanesChanged(); + public void onVisiblePanesChanged(int previousVisiblePanes); } private static final class EmptyCallback implements Callback { public static final Callback INSTANCE = new EmptyCallback(); - @Override public void onVisiblePanesChanged() {} + @Override public void onVisiblePanesChanged(int previousVisiblePanes) {} } public ThreePaneLayout(Context context, AttributeSet attrs, int defStyle) { @@ -162,11 +163,38 @@ public class ThreePaneLayout extends LinearLayout implements View.OnClickListene return ret; } + public boolean onBackPressed() { + if (isLandscape()) { + switch (mPaneState) { + case STATE_RIGHT_VISIBLE: + changePaneState(STATE_LEFT_VISIBLE, true); // Close the right pane + return true; + } + } else { + switch (mPaneState) { + case STATE_RIGHT_VISIBLE: + changePaneState(STATE_PORTRAIT_MIDDLE_EXPANDED, true); + return true; + case STATE_PORTRAIT_MIDDLE_EXPANDED: + changePaneState(STATE_LEFT_VISIBLE, true); + return true; + } + } + return false; + } + /** - * Show/hide the right most pane. (i.e. message view) + * Show the left most pane. (i.e. mailbox list) */ - public void showRightPane(boolean show) { - changePaneState(show ? STATE_RIGHT_VISIBLE : STATE_LEFT_VISIBLE, true); + public void showLeftPane() { + changePaneState(STATE_LEFT_VISIBLE, true); + } + + /** + * Show the right most pane. (i.e. message view) + */ + public void showRightPane() { + changePaneState(STATE_RIGHT_VISIBLE, true); } private void changePaneState(int newState, boolean animate) { @@ -176,6 +204,7 @@ public class ThreePaneLayout extends LinearLayout implements View.OnClickListene if (newState == mPaneState) { return; } + final int previousVisiblePanes = getVisiblePanes(); mPaneState = newState; switch (mPaneState) { case STATE_LEFT_VISIBLE: @@ -217,7 +246,7 @@ public class ThreePaneLayout extends LinearLayout implements View.OnClickListene mFoggedGlass.setVisibility(View.VISIBLE); break; } - mCallback.onVisiblePanesChanged(); + mCallback.onVisiblePanesChanged(previousVisiblePanes); } /**