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() {
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:

View File

@ -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();
}
}
}
}

View File

@ -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);
}
/**