Merge "New method to see whether 1-pane or 2-pane UI..."

This commit is contained in:
Makoto Onuki 2011-06-07 14:06:57 -07:00 committed by Android (Google) Code Review
commit ed14960af5
4 changed files with 34 additions and 31 deletions

View File

@ -323,7 +323,7 @@ public class AccountSelectorAdapter extends CursorAdapter {
emailAddress =
matrixCursor.getString(matrixCursor.getColumnIndex(Account.EMAIL_ADDRESS));
}
boolean useTwoPane = mContext.getResources().getBoolean(R.bool.use_two_pane);
boolean useTwoPane = UiUtilities.useTwoPane(mContext);
// Filter system mailboxes if we're using a two-pane view
RecentMailboxManager mailboxManager = RecentMailboxManager.getInstance(mContext);
ArrayList<Long> recentMailboxes = mailboxManager.getMostRecent(mAccountId, useTwoPane);

View File

@ -62,7 +62,6 @@ public class EmailActivity extends Activity implements View.OnClickListener, Fra
private static final String EXTRA_ACCOUNT_ID = "ACCOUNT_ID";
private static final String EXTRA_MAILBOX_ID = "MAILBOX_ID";
private static final String EXTRA_MESSAGE_ID = "MESSAGE_ID";
private static final String EXTRA_FORCE_PANE_MODE = "FORCE_PANE_MODE";
/** Loader IDs starting with this is safe to use from UIControllers. */
static final int UI_CONTROLLER_LOADER_ID_BASE = 100;
@ -140,32 +139,12 @@ public class EmailActivity extends Activity implements View.OnClickListener, Fra
return i;
}
/**
* Set a debug flag to an intent to force open in 1-pane or 2-pane.
*
* @param useTwoPane true to open in 2-pane. false to open in 1-pane.
*/
public static void forcePaneMode(Intent i, boolean useTwoPane) {
i.putExtra(EXTRA_FORCE_PANE_MODE, useTwoPane ? 2 : 1);
}
/**
* Initialize {@link #mUIController}.
*/
private void initUIController() {
final boolean twoPane;
switch (getIntent().getIntExtra(EXTRA_FORCE_PANE_MODE, -1)) {
case 1:
twoPane = false;
break;
case 2:
twoPane = true;
break;
default:
twoPane = getResources().getBoolean(R.bool.use_two_pane);
break;
}
mUIController = twoPane ? new UIControllerTwoPane(this) : new UIControllerOnePane(this);
mUIController = UiUtilities.useTwoPane(this)
? new UIControllerTwoPane(this) : new UIControllerOnePane(this);
}
@Override

View File

@ -148,4 +148,29 @@ public class UiUtilities {
((FragmentInstallable) a).onUninstallFragment(fragment);
}
}
private static int sDebugForcedPaneMode = 0;
/**
* Force 1-pane UI or 2-pane UI.
*
* @param paneMode Set 1 if 1-pane UI should be used. Set 2 if 2-pane UI should be used.
* Set 0 to use the default UI.
*/
static void setDebugPaneMode(int paneMode) {
sDebugForcedPaneMode = paneMode;
}
/**
* @return {@code true} if 2-pane UI should be used. {@code false} otherwise.
*/
public static boolean useTwoPane(Context context) {
if (sDebugForcedPaneMode == 1) {
return false;
}
if (sDebugForcedPaneMode == 2) {
return true;
}
return context.getResources().getBoolean(R.bool.use_two_pane);
}
}

View File

@ -135,8 +135,11 @@ public class Welcome extends Activity {
}
/**
* Parse the {@link #EXTRA_DEBUG_PANE_MODE} extra and return 1 or 2, if it's set to "1" or "2".
* Return 0 otherwise.
* If the {@link #EXTRA_DEBUG_PANE_MODE} extra is "1" or "2", return 1 or 2 respectively.
* Otherwise return 0.
*
* @see UiUtilities#setDebugPaneMode(int)
* @see UiUtilities#useTwoPane(Context)
*/
private static int getDebugPaneMode(Intent i) {
Bundle extras = i.getExtras();
@ -191,7 +194,6 @@ public class Welcome extends Activity {
@VisibleForTesting
static class MainActivityLauncher extends EmailAsyncTask<Void, Void, Void> {
private final Welcome mFromActivity;
private final int mDebugPaneMode;
private final long mAccountId;
private final long mMailboxId;
private final long mMessageId;
@ -205,7 +207,7 @@ public class Welcome extends Activity {
mMailboxId = IntentUtilities.getMailboxIdFromIntent(intent);
mMessageId = IntentUtilities.getMessageIdFromIntent(intent);
mAccountUuid = IntentUtilities.getAccountUuidFromIntent(intent);
mDebugPaneMode = getDebugPaneMode(intent);
UiUtilities.setDebugPaneMode(getDebugPaneMode(intent));
}
private boolean isMailboxSelected() {
@ -268,9 +270,6 @@ public class Welcome extends Activity {
} else {
i = EmailActivity.createOpenAccountIntent(mFromActivity, accountId);
}
if (mDebugPaneMode != 0) {
EmailActivity.forcePaneMode(i, mDebugPaneMode == 2);
}
mFromActivity.startActivity(i);
}
return null;