Three pane behavior changes

- Now pressing back on the message view on portrait expands the message
  list.  Pressing back again closes the message view and navigates
  to the mailbox list + message list view.
- Fixed the bug where the app icon on the action bar will lose the back arrow
  on screen rotation.
- Code clean up.

Bug 3137919
Bug 3198987

Change-Id: Ia452f90ebe5599a2a8de905f4dabec6bd3ceb4a2
This commit is contained in:
Makoto Onuki 2010-11-16 11:11:22 -08:00
parent 7fd78d8d61
commit d2289c2f19
3 changed files with 77 additions and 31 deletions

View File

@ -174,6 +174,7 @@ public class MessageListXL extends Activity implements
protected void onResume() { protected void onResume() {
if (Email.DEBUG_LIFECYCLE && Email.DEBUG) Log.d(Email.LOG_TAG, "MessageListXL onResume"); if (Email.DEBUG_LIFECYCLE && Email.DEBUG) Log.d(Email.LOG_TAG, "MessageListXL onResume");
super.onResume(); super.onResume();
mFragmentManager.onResume();
// On MessageList.onResume, we go back to Welcome if an account has been added/removed. // 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 // 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) { if (Email.DEBUG_LIFECYCLE && Email.DEBUG) {
Log.d(Email.LOG_TAG, "MessageListXL onBackPressed"); 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()) { if (mFragmentManager.onBackPressed()) {
return; return true;
} }
// Perform the default behavior. if (mayCloseActivity) {
super.onBackPressed(); // Perform the default behavior.
super.onBackPressed();
return true;
}
return false;
} }
private void onCurrentMessageGone() { private void onCurrentMessageGone() {
@ -601,7 +616,8 @@ public class MessageListXL extends Activity implements
switch (item.getItemId()) { switch (item.getItemId()) {
case android.R.id.home: case android.R.id.home:
// Comes from the action bar when the app icon on the left is pressed. // 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: case R.id.compose:
return onCompose(); return onCompose();
case R.id.refresh: case R.id.refresh:

View File

@ -124,8 +124,6 @@ class MessageListXLFragmentManager {
mThreePane.getMiddlePaneId()); mThreePane.getMiddlePaneId());
mMessageViewFragment = (MessageViewFragment) fm.findFragmentById( mMessageViewFragment = (MessageViewFragment) fm.findFragmentById(
mThreePane.getRightPaneId()); mThreePane.getRightPaneId());
updateActionBar();
} }
/** Set callback for fragment. */ /** Set callback for fragment. */
@ -197,6 +195,8 @@ class MessageListXLFragmentManager {
return; return;
} }
mIsActivityResumed = true; mIsActivityResumed = true;
updateActionBar();
} }
/** /**
@ -303,7 +303,7 @@ class MessageListXLFragmentManager {
// Open mailbox list, clear message list / message view // Open mailbox list, clear message list / message view
mMailboxListFragment.openMailboxes(mAccountId); mMailboxListFragment.openMailboxes(mAccountId);
mMessageListFragment.clearContent(); mMessageListFragment.clearContent();
hideMessageView(); mThreePane.showLeftPane(); // Show mailbox list
if ((accountId == Account.ACCOUNT_ID_COMBINED_VIEW) && (mailboxId == -1)) { if ((accountId == Account.ACCOUNT_ID_COMBINED_VIEW) && (mailboxId == -1)) {
// When opening the Combined view, the right pane will be "combined inbox". // When opening the Combined view, the right pane will be "combined inbox".
@ -321,12 +321,7 @@ class MessageListXLFragmentManager {
* @return true "back" is handled. * @return true "back" is handled.
*/ */
public boolean onBackPressed() { public boolean onBackPressed() {
if (isMessageSelected()) { return mThreePane.onBackPressed();
// Go back to the message list.
goBackToMailbox();
return true;
}
return false; // Not handled.
} }
/** /**
@ -334,7 +329,6 @@ class MessageListXLFragmentManager {
*/ */
public void goBackToMailbox() { public void goBackToMailbox() {
if (isMessageSelected()) { if (isMessageSelected()) {
hideMessageView();
selectMailbox(getMailboxId(), false); selectMailbox(getMailboxId(), false);
} }
} }
@ -374,7 +368,7 @@ class MessageListXLFragmentManager {
mMailboxListFragment.setSelectedMailbox(mMailboxId); mMailboxListFragment.setSelectedMailbox(mMailboxId);
mTargetActivity.onMailboxChanged(mAccountId, mMailboxId); mTargetActivity.onMailboxChanged(mAccountId, mMailboxId);
hideMessageView(); mThreePane.showLeftPane(); // Show mailbox list
} }
/** /**
@ -402,16 +396,17 @@ class MessageListXLFragmentManager {
// Open message // Open message
mMessageListFragment.setSelectedMessage(mMessageId); mMessageListFragment.setSelectedMessage(mMessageId);
mMessageViewFragment.openMessage(mMessageId); mMessageViewFragment.openMessage(mMessageId);
hideMessageBoxList(); mThreePane.showRightPane(); // Show message view
} }
private void hideMessageBoxList() { /**
mThreePane.showRightPane(true); * Unselect the currently viewed message, if any, and release the resoruce grabbed by the
} * message view.
*
private void hideMessageView() { * This must be called when the three pane reports that the message view pane gets hidden.
*/
private void onMessageViewClosed() {
mMessageId = -1; mMessageId = -1;
mThreePane.showRightPane(false);
mMessageListFragment.setSelectedMessage(-1); mMessageListFragment.setSelectedMessage(-1);
mMessageViewFragment.clearContent(); mMessageViewFragment.clearContent();
} }
@ -469,8 +464,14 @@ class MessageListXLFragmentManager {
private class ThreePaneLayoutCallback implements ThreePaneLayout.Callback { private class ThreePaneLayoutCallback implements ThreePaneLayout.Callback {
@Override @Override
public void onVisiblePanesChanged() { public void onVisiblePanesChanged(int previousVisiblePanes) {
updateActionBar(); updateActionBar();
final int visiblePanes = mThreePane.getVisiblePanes();
if (((visiblePanes & ThreePaneLayout.PANE_RIGHT) == 0) &&
((previousVisiblePanes & ThreePaneLayout.PANE_RIGHT) != 0)) {
// Message view just got hidden
onMessageViewClosed();
}
} }
} }
} }

View File

@ -50,9 +50,10 @@ public class ThreePaneLayout extends LinearLayout implements View.OnClickListene
/** Portrait mode only: message view + expanded message list */ /** Portrait mode only: message view + expanded message list */
private static final int STATE_PORTRAIT_MIDDLE_EXPANDED = 3; 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_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; private int mPaneState = STATE_LEFT_UNINITIALIZED;
@ -69,13 +70,13 @@ public class ThreePaneLayout extends LinearLayout implements View.OnClickListene
public interface Callback { public interface Callback {
/** Called when {@link ThreePaneLayout#getVisiblePanes()} has changed. */ /** Called when {@link ThreePaneLayout#getVisiblePanes()} has changed. */
public void onVisiblePanesChanged(); public void onVisiblePanesChanged(int previousVisiblePanes);
} }
private static final class EmptyCallback implements Callback { private static final class EmptyCallback implements Callback {
public static final Callback INSTANCE = new EmptyCallback(); 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) { public ThreePaneLayout(Context context, AttributeSet attrs, int defStyle) {
@ -162,11 +163,38 @@ public class ThreePaneLayout extends LinearLayout implements View.OnClickListene
return ret; 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) { public void showLeftPane() {
changePaneState(show ? STATE_RIGHT_VISIBLE : STATE_LEFT_VISIBLE, true); 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) { private void changePaneState(int newState, boolean animate) {
@ -176,6 +204,7 @@ public class ThreePaneLayout extends LinearLayout implements View.OnClickListene
if (newState == mPaneState) { if (newState == mPaneState) {
return; return;
} }
final int previousVisiblePanes = getVisiblePanes();
mPaneState = newState; mPaneState = newState;
switch (mPaneState) { switch (mPaneState) {
case STATE_LEFT_VISIBLE: case STATE_LEFT_VISIBLE:
@ -217,7 +246,7 @@ public class ThreePaneLayout extends LinearLayout implements View.OnClickListene
mFoggedGlass.setVisibility(View.VISIBLE); mFoggedGlass.setVisibility(View.VISIBLE);
break; break;
} }
mCallback.onVisiblePanesChanged(); mCallback.onVisiblePanesChanged(previousVisiblePanes);
} }
/** /**