Convert SetupData into a retained fragment

This will keep it from being recreated quite as much while off-thread tasks are possibly mutating it.

Change-Id: Ic9873489906339c33a76b8a600c0fc28016debc4
This commit is contained in:
Tony Mantler 2013-12-05 16:25:01 -08:00
parent 471e792ab4
commit 9c8c471f97
16 changed files with 219 additions and 170 deletions

View File

@ -69,7 +69,7 @@ public class AccountCheckSettingsFragment extends Fragment {
private final static int STATE_AUTODISCOVER_AUTH_DIALOG = 7; // terminal private final static int STATE_AUTODISCOVER_AUTH_DIALOG = 7; // terminal
private final static int STATE_AUTODISCOVER_RESULT = 8; // terminal private final static int STATE_AUTODISCOVER_RESULT = 8; // terminal
private int mState = STATE_START; private int mState = STATE_START;
private SetupData mSetupData; private SetupDataFragment mSetupData;
// Support for UI // Support for UI
private boolean mAttached; private boolean mAttached;
@ -106,13 +106,13 @@ public class AccountCheckSettingsFragment extends Fragment {
* Called when CheckSettings completed * Called when CheckSettings completed
* @param result check settings result code - success is CHECK_SETTINGS_OK * @param result check settings result code - success is CHECK_SETTINGS_OK
*/ */
public void onCheckSettingsComplete(int result, SetupData setupData); public void onCheckSettingsComplete(int result, SetupDataFragment setupData);
/** /**
* Called when autodiscovery completes. * Called when autodiscovery completes.
* @param result autodiscovery result code - success is AUTODISCOVER_OK * @param result autodiscovery result code - success is AUTODISCOVER_OK
*/ */
public void onAutoDiscoverComplete(int result, SetupData setupData); public void onAutoDiscoverComplete(int result, SetupDataFragment setupData);
} }
// Public no-args constructor needed for fragment re-instantiation // Public no-args constructor needed for fragment re-instantiation
@ -153,8 +153,8 @@ public class AccountCheckSettingsFragment extends Fragment {
// If this is the first time, start the AsyncTask // If this is the first time, start the AsyncTask
if (mAccountCheckTask == null) { if (mAccountCheckTask == null) {
final int checkMode = getTargetRequestCode(); final int checkMode = getTargetRequestCode();
final SetupData.SetupDataContainer container = final SetupDataFragment.SetupDataContainer container =
(SetupData.SetupDataContainer) getActivity(); (SetupDataFragment.SetupDataContainer) getActivity();
mSetupData = container.getSetupData(); mSetupData = container.getSetupData();
final Account checkAccount = mSetupData.getAccount(); final Account checkAccount = mSetupData.getAccount();
mAccountCheckTask = (AccountCheckTask) mAccountCheckTask = (AccountCheckTask)
@ -440,7 +440,7 @@ public class AccountCheckSettingsFragment extends Fragment {
@Override @Override
protected MessagingException doInBackground(Void... params) { protected MessagingException doInBackground(Void... params) {
try { try {
if ((mMode & SetupData.CHECK_AUTODISCOVER) != 0) { if ((mMode & SetupDataFragment.CHECK_AUTODISCOVER) != 0) {
if (isCancelled()) return null; if (isCancelled()) return null;
publishProgress(STATE_CHECK_AUTODISCOVER); publishProgress(STATE_CHECK_AUTODISCOVER);
LogUtils.d(Logging.LOG_TAG, "Begin auto-discover for " + mCheckEmail); LogUtils.d(Logging.LOG_TAG, "Begin auto-discover for " + mCheckEmail);
@ -468,7 +468,7 @@ public class AccountCheckSettingsFragment extends Fragment {
} }
// Check Incoming Settings // Check Incoming Settings
if ((mMode & SetupData.CHECK_INCOMING) != 0) { if ((mMode & SetupDataFragment.CHECK_INCOMING) != 0) {
if (isCancelled()) return null; if (isCancelled()) return null;
LogUtils.d(Logging.LOG_TAG, "Begin check of incoming email settings"); LogUtils.d(Logging.LOG_TAG, "Begin check of incoming email settings");
publishProgress(STATE_CHECK_INCOMING); publishProgress(STATE_CHECK_INCOMING);
@ -513,7 +513,7 @@ public class AccountCheckSettingsFragment extends Fragment {
final EmailServiceInfo info = EmailServiceUtils.getServiceInfo(mContext, protocol); final EmailServiceInfo info = EmailServiceUtils.getServiceInfo(mContext, protocol);
// Check Outgoing Settings // Check Outgoing Settings
if (info.usesSmtp && (mMode & SetupData.CHECK_OUTGOING) != 0) { if (info.usesSmtp && (mMode & SetupDataFragment.CHECK_OUTGOING) != 0) {
if (isCancelled()) return null; if (isCancelled()) return null;
LogUtils.d(Logging.LOG_TAG, "Begin check of outgoing email settings"); LogUtils.d(Logging.LOG_TAG, "Begin check of outgoing email settings");
publishProgress(STATE_CHECK_OUTGOING); publishProgress(STATE_CHECK_OUTGOING);

View File

@ -62,7 +62,7 @@ public abstract class AccountServerBaseFragment extends Fragment
/*package*/ HostAuth mLoadedSendAuth; /*package*/ HostAuth mLoadedSendAuth;
/*package*/ HostAuth mLoadedRecvAuth; /*package*/ HostAuth mLoadedRecvAuth;
protected SetupData mSetupData; protected SetupDataFragment mSetupData;
// This is null in the setup wizard screens, and non-null in AccountSettings mode // This is null in the setup wizard screens, and non-null in AccountSettings mode
private Button mProceedButton; private Button mProceedButton;
@ -82,7 +82,7 @@ public abstract class AccountServerBaseFragment extends Fragment
/** /**
* Called when user clicks "next". Starts account checker. * Called when user clicks "next". Starts account checker.
* @param checkMode values from {@link SetupData} * @param checkMode values from {@link SetupDataFragment}
* @param target the fragment that requested the check * @param target the fragment that requested the check
*/ */
public void onProceedNext(int checkMode, AccountServerBaseFragment target); public void onProceedNext(int checkMode, AccountServerBaseFragment target);
@ -93,14 +93,14 @@ public abstract class AccountServerBaseFragment extends Fragment
* @param result check settings result code - success is CHECK_SETTINGS_OK * @param result check settings result code - success is CHECK_SETTINGS_OK
* @param setupData possibly modified SetupData * @param setupData possibly modified SetupData
*/ */
public void onCheckSettingsComplete(int result, SetupData setupData); public void onCheckSettingsComplete(int result, SetupDataFragment setupData);
} }
private static class EmptyCallback implements Callback { private static class EmptyCallback implements Callback {
public static final Callback INSTANCE = new EmptyCallback(); public static final Callback INSTANCE = new EmptyCallback();
@Override public void onEnableProceedButtons(boolean enable) { } @Override public void onEnableProceedButtons(boolean enable) { }
@Override public void onProceedNext(int checkMode, AccountServerBaseFragment target) { } @Override public void onProceedNext(int checkMode, AccountServerBaseFragment target) { }
@Override public void onCheckSettingsComplete(int result, SetupData setupData) { } @Override public void onCheckSettingsComplete(int result, SetupDataFragment setupData) { }
} }
/** /**
@ -154,7 +154,8 @@ public abstract class AccountServerBaseFragment extends Fragment
if (mSettingsMode && savedInstanceState != null) { if (mSettingsMode && savedInstanceState != null) {
mContext.setTitle(savedInstanceState.getString(BUNDLE_KEY_ACTIVITY_TITLE)); mContext.setTitle(savedInstanceState.getString(BUNDLE_KEY_ACTIVITY_TITLE));
} }
SetupData.SetupDataContainer container = (SetupData.SetupDataContainer) mContext; SetupDataFragment.SetupDataContainer container =
(SetupDataFragment.SetupDataContainer) mContext;
mSetupData = container.getSetupData(); mSetupData = container.getSetupData();
super.onActivityCreated(savedInstanceState); super.onActivityCreated(savedInstanceState);
@ -302,13 +303,13 @@ public abstract class AccountServerBaseFragment extends Fragment
* exit to previous fragment. * exit to previous fragment.
*/ */
@Override @Override
public void onCheckSettingsComplete(final int settingsResult, SetupData setupData) { public void onCheckSettingsComplete(final int settingsResult, SetupDataFragment setupData) {
mSetupData = setupData; mSetupData = setupData;
new AsyncTask<Void, Void, Void>() { new AsyncTask<Void, Void, Void>() {
@Override @Override
protected Void doInBackground(Void... params) { protected Void doInBackground(Void... params) {
if (settingsResult == AccountCheckSettingsFragment.CHECK_SETTINGS_OK) { if (settingsResult == AccountCheckSettingsFragment.CHECK_SETTINGS_OK) {
if (mSetupData.getFlowMode() == SetupData.FLOW_MODE_EDIT) { if (mSetupData.getFlowMode() == SetupDataFragment.FLOW_MODE_EDIT) {
saveSettingsAfterEdit(); saveSettingsAfterEdit();
} else { } else {
saveSettingsAfterSetup(); saveSettingsAfterSetup();
@ -330,7 +331,7 @@ public abstract class AccountServerBaseFragment extends Fragment
* This is overridden only by AccountSetupExchange * This is overridden only by AccountSetupExchange
*/ */
@Override @Override
public void onAutoDiscoverComplete(int result, SetupData setupData) { public void onAutoDiscoverComplete(int result, SetupDataFragment setupData) {
throw new IllegalStateException(); throw new IllegalStateException();
} }

View File

@ -72,7 +72,7 @@ import java.util.List;
* dealing with accounts being added/deleted and triggering the header reload. * dealing with accounts being added/deleted and triggering the header reload.
*/ */
public class AccountSettings extends PreferenceActivity implements FeedbackEnabledActivity, public class AccountSettings extends PreferenceActivity implements FeedbackEnabledActivity,
SetupData.SetupDataContainer { SetupDataFragment.SetupDataContainer {
/* /*
* Intent to open account settings for account=1 * Intent to open account settings for account=1
adb shell am start -a android.intent.action.EDIT \ adb shell am start -a android.intent.action.EDIT \
@ -120,7 +120,7 @@ public class AccountSettings extends PreferenceActivity implements FeedbackEnabl
private Uri mFeedbackUri; private Uri mFeedbackUri;
private MenuItem mFeedbackMenuItem; private MenuItem mFeedbackMenuItem;
private SetupData mSetupData; private SetupDataFragment mSetupData;
// Async Tasks // Async Tasks
private LoadAccountListTask mLoadAccountListTask; private LoadAccountListTask mLoadAccountListTask;
@ -227,7 +227,7 @@ public class AccountSettings extends PreferenceActivity implements FeedbackEnabl
} }
} }
} else { } else {
mSetupData = savedInstanceState.getParcelable(SetupData.EXTRA_SETUP_DATA); mSetupData = savedInstanceState.getParcelable(SetupDataFragment.EXTRA_SETUP_DATA);
} }
mShowDebugMenu = i.getBooleanExtra(EXTRA_ENABLE_DEBUG, false); mShowDebugMenu = i.getBooleanExtra(EXTRA_ENABLE_DEBUG, false);
@ -253,7 +253,8 @@ public class AccountSettings extends PreferenceActivity implements FeedbackEnabl
protected void onSaveInstanceState(Bundle outState) { protected void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState( super.onSaveInstanceState(
outState); outState);
outState.putParcelable(SetupData.EXTRA_SETUP_DATA, mSetupData); // TODO: use the fragment manager to persist this
outState.putParcelable(SetupDataFragment.EXTRA_SETUP_DATA, mSetupData);
} }
@Override @Override
@ -660,7 +661,7 @@ public class AccountSettings extends PreferenceActivity implements FeedbackEnabl
* simply does a "back" to exit the settings screen. * simply does a "back" to exit the settings screen.
*/ */
@Override @Override
public void onCheckSettingsComplete(int result, SetupData setupData) { public void onCheckSettingsComplete(int result, SetupDataFragment setupData) {
if (result == AccountCheckSettingsFragment.CHECK_SETTINGS_OK) { if (result == AccountCheckSettingsFragment.CHECK_SETTINGS_OK) {
// Settings checked & saved; clear current fragment // Settings checked & saved; clear current fragment
mCurrentFragment = null; mCurrentFragment = null;
@ -705,7 +706,7 @@ public class AccountSettings extends PreferenceActivity implements FeedbackEnabl
*/ */
public void onIncomingSettings(Account account) { public void onIncomingSettings(Account account) {
try { try {
mSetupData = new SetupData(SetupData.FLOW_MODE_EDIT, account); mSetupData = new SetupDataFragment(SetupDataFragment.FLOW_MODE_EDIT, account);
final Fragment f = new AccountSetupIncomingFragment(); final Fragment f = new AccountSetupIncomingFragment();
f.setArguments(AccountSetupIncomingFragment.getArgs(true)); f.setArguments(AccountSetupIncomingFragment.getArgs(true));
// Use startPreferenceFragment here because we need to keep this activity instance // Use startPreferenceFragment here because we need to keep this activity instance
@ -722,7 +723,7 @@ public class AccountSettings extends PreferenceActivity implements FeedbackEnabl
*/ */
public void onOutgoingSettings(Account account) { public void onOutgoingSettings(Account account) {
try { try {
mSetupData = new SetupData(SetupData.FLOW_MODE_EDIT, account); mSetupData = new SetupDataFragment(SetupDataFragment.FLOW_MODE_EDIT, account);
final Fragment f = new AccountSetupOutgoingFragment(); final Fragment f = new AccountSetupOutgoingFragment();
f.setArguments(AccountSetupOutgoingFragment.getArgs(true)); f.setArguments(AccountSetupOutgoingFragment.getArgs(true));
// Use startPreferenceFragment here because we need to keep this activity instance // Use startPreferenceFragment here because we need to keep this activity instance
@ -926,12 +927,12 @@ public class AccountSettings extends PreferenceActivity implements FeedbackEnabl
} }
@Override @Override
public SetupData getSetupData() { public SetupDataFragment getSetupData() {
return mSetupData; return mSetupData;
} }
@Override @Override
public void setSetupData(SetupData setupData) { public void setSetupData(SetupDataFragment setupData) {
mSetupData = setupData; mSetupData = setupData;
} }
} }

View File

@ -17,6 +17,7 @@
package com.android.email.activity.setup; package com.android.email.activity.setup;
import android.app.Activity; import android.app.Activity;
import android.app.FragmentTransaction;
import android.os.Bundle; import android.os.Bundle;
import com.android.emailcommon.Logging; import com.android.emailcommon.Logging;
@ -26,25 +27,37 @@ import com.android.mail.utils.LogUtils;
* Superclass of all of the account setup activities; ensures that SetupData state is saved/restored * Superclass of all of the account setup activities; ensures that SetupData state is saved/restored
* automatically as required * automatically as required
*/ */
public class AccountSetupActivity extends Activity implements SetupData.SetupDataContainer { public class AccountSetupActivity extends Activity implements SetupDataFragment.SetupDataContainer {
private static final boolean DEBUG_SETUP_FLOWS = false; // Don't check in set to true private static final boolean DEBUG_SETUP_FLOWS = false; // Don't check in set to true
protected SetupData mSetupData; protected SetupDataFragment mSetupData;
private static final String SETUP_DATA_FRAGMENT_TAG = "setupData";
@Override @Override
public void onCreate(Bundle savedInstanceState) { public void onCreate(Bundle savedInstanceState) {
if (savedInstanceState != null) { super.onCreate(savedInstanceState);
mSetupData = savedInstanceState.getParcelable(SetupData.EXTRA_SETUP_DATA);
} else { if (savedInstanceState == null) {
final Bundle b = getIntent().getExtras(); final Bundle b = getIntent().getExtras();
if (b != null) { if (b != null) {
mSetupData = b.getParcelable(SetupData.EXTRA_SETUP_DATA); mSetupData = b.getParcelable(SetupDataFragment.EXTRA_SETUP_DATA);
if (mSetupData != null) {
final FragmentTransaction ft = getFragmentManager().beginTransaction();
ft.add(mSetupData, SETUP_DATA_FRAGMENT_TAG);
ft.commit();
}
} }
} } else {
if (mSetupData == null) { mSetupData = (SetupDataFragment)getFragmentManager()
mSetupData = new SetupData(); .findFragmentByTag(SETUP_DATA_FRAGMENT_TAG);
}
if (mSetupData == null) {
mSetupData = new SetupDataFragment();
final FragmentTransaction ft = getFragmentManager().beginTransaction();
ft.add(mSetupData, SETUP_DATA_FRAGMENT_TAG);
ft.commit();
} }
super.onCreate(savedInstanceState);
if (DEBUG_SETUP_FLOWS) { if (DEBUG_SETUP_FLOWS) {
LogUtils.d(Logging.LOG_TAG, "%s onCreate %s", getClass().getName(), LogUtils.d(Logging.LOG_TAG, "%s onCreate %s", getClass().getName(),
mSetupData.debugString()); mSetupData.debugString());
@ -52,18 +65,12 @@ public class AccountSetupActivity extends Activity implements SetupData.SetupDat
} }
@Override @Override
public void onSaveInstanceState(Bundle outState) { public SetupDataFragment getSetupData() {
super.onSaveInstanceState(outState);
outState.putParcelable(SetupData.EXTRA_SETUP_DATA, mSetupData);
}
@Override
public SetupData getSetupData() {
return mSetupData; return mSetupData;
} }
@Override @Override
public void setSetupData(SetupData setupData) { public void setSetupData(SetupDataFragment setupData) {
mSetupData = setupData; mSetupData = setupData;
} }
} }

View File

@ -126,13 +126,13 @@ public class AccountSetupBasics extends AccountSetupActivity
public static void actionNewAccount(Activity fromActivity) { public static void actionNewAccount(Activity fromActivity) {
final Intent i = new Intent(fromActivity, AccountSetupBasics.class); final Intent i = new Intent(fromActivity, AccountSetupBasics.class);
i.putExtra(EXTRA_FLOW_MODE, SetupData.FLOW_MODE_NORMAL); i.putExtra(EXTRA_FLOW_MODE, SetupDataFragment.FLOW_MODE_NORMAL);
fromActivity.startActivity(i); fromActivity.startActivity(i);
} }
public static void actionNewAccountWithResult(Activity fromActivity) { public static void actionNewAccountWithResult(Activity fromActivity) {
final Intent i = new ForwardingIntent(fromActivity, AccountSetupBasics.class); final Intent i = new ForwardingIntent(fromActivity, AccountSetupBasics.class);
i.putExtra(EXTRA_FLOW_MODE, SetupData.FLOW_MODE_NO_ACCOUNTS); i.putExtra(EXTRA_FLOW_MODE, SetupDataFragment.FLOW_MODE_NO_ACCOUNTS);
fromActivity.startActivity(i); fromActivity.startActivity(i);
} }
@ -142,7 +142,7 @@ public class AccountSetupBasics extends AccountSetupActivity
*/ */
public static Intent actionGetCreateAccountIntent(Context context, String accountManagerType) { public static Intent actionGetCreateAccountIntent(Context context, String accountManagerType) {
final Intent i = new Intent(context, AccountSetupBasics.class); final Intent i = new Intent(context, AccountSetupBasics.class);
i.putExtra(EXTRA_FLOW_MODE, SetupData.FLOW_MODE_ACCOUNT_MANAGER); i.putExtra(EXTRA_FLOW_MODE, SetupDataFragment.FLOW_MODE_ACCOUNT_MANAGER);
i.putExtra(EXTRA_FLOW_ACCOUNT_TYPE, accountManagerType); i.putExtra(EXTRA_FLOW_ACCOUNT_TYPE, accountManagerType);
return i; return i;
} }
@ -155,7 +155,8 @@ public class AccountSetupBasics extends AccountSetupActivity
final Intent i= new ForwardingIntent(fromActivity, AccountSetupBasics.class); final Intent i= new ForwardingIntent(fromActivity, AccountSetupBasics.class);
// If we're in the "account flow" (from AccountManager), we want to return to the caller // If we're in the "account flow" (from AccountManager), we want to return to the caller
// (in the settings app) // (in the settings app)
i.putExtra(SetupData.EXTRA_SETUP_DATA, new SetupData(SetupData.FLOW_MODE_RETURN_TO_CALLER)); i.putExtra(SetupDataFragment.EXTRA_SETUP_DATA,
new SetupDataFragment(SetupDataFragment.FLOW_MODE_RETURN_TO_CALLER));
i.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); i.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
fromActivity.startActivity(i); fromActivity.startActivity(i);
} }
@ -167,8 +168,8 @@ public class AccountSetupBasics extends AccountSetupActivity
final Intent i= new ForwardingIntent(fromActivity, AccountSetupBasics.class); final Intent i= new ForwardingIntent(fromActivity, AccountSetupBasics.class);
// If we're in the "no accounts" flow, we want to return to the caller with a result // If we're in the "no accounts" flow, we want to return to the caller with a result
i.putExtra(SetupData.EXTRA_SETUP_DATA, i.putExtra(SetupDataFragment.EXTRA_SETUP_DATA,
new SetupData(SetupData.FLOW_MODE_RETURN_NO_ACCOUNTS_RESULT)); new SetupDataFragment(SetupDataFragment.FLOW_MODE_RETURN_NO_ACCOUNTS_RESULT));
i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
fromActivity.startActivity(i); fromActivity.startActivity(i);
} }
@ -177,8 +178,8 @@ public class AccountSetupBasics extends AccountSetupActivity
final Intent i = new Intent(fromActivity, AccountSetupBasics.class); final Intent i = new Intent(fromActivity, AccountSetupBasics.class);
// If we're not in the "account flow" (from AccountManager), we want to show the // If we're not in the "account flow" (from AccountManager), we want to show the
// message list for the new inbox // message list for the new inbox
i.putExtra(SetupData.EXTRA_SETUP_DATA, i.putExtra(SetupDataFragment.EXTRA_SETUP_DATA,
new SetupData(SetupData.FLOW_MODE_RETURN_TO_MESSAGE_LIST, account)); new SetupDataFragment(SetupDataFragment.FLOW_MODE_RETURN_TO_MESSAGE_LIST, account));
i.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); i.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
fromActivity.startActivity(i); fromActivity.startActivity(i);
} }
@ -197,22 +198,22 @@ public class AccountSetupBasics extends AccountSetupActivity
INTENT_CREATE_ACCOUNT = getString(R.string.intent_create_account); INTENT_CREATE_ACCOUNT = getString(R.string.intent_create_account);
} }
if (INTENT_CREATE_ACCOUNT.equals(action)) { if (INTENT_CREATE_ACCOUNT.equals(action)) {
mSetupData = new SetupData(SetupData.FLOW_MODE_FORCE_CREATE); mSetupData = new SetupDataFragment(SetupDataFragment.FLOW_MODE_FORCE_CREATE);
} else { } else {
final int intentFlowMode = final int intentFlowMode =
intent.getIntExtra(EXTRA_FLOW_MODE, SetupData.FLOW_MODE_UNSPECIFIED); intent.getIntExtra(EXTRA_FLOW_MODE, SetupDataFragment.FLOW_MODE_UNSPECIFIED);
if (intentFlowMode != SetupData.FLOW_MODE_UNSPECIFIED) { if (intentFlowMode != SetupDataFragment.FLOW_MODE_UNSPECIFIED) {
mSetupData = new SetupData(intentFlowMode, mSetupData = new SetupDataFragment(intentFlowMode,
intent.getStringExtra(EXTRA_FLOW_ACCOUNT_TYPE)); intent.getStringExtra(EXTRA_FLOW_ACCOUNT_TYPE));
} }
} }
final int flowMode = mSetupData.getFlowMode(); final int flowMode = mSetupData.getFlowMode();
if (flowMode == SetupData.FLOW_MODE_RETURN_TO_CALLER) { if (flowMode == SetupDataFragment.FLOW_MODE_RETURN_TO_CALLER) {
// Return to the caller who initiated account creation // Return to the caller who initiated account creation
finish(); finish();
return; return;
} else if (flowMode == SetupData.FLOW_MODE_RETURN_NO_ACCOUNTS_RESULT) { } else if (flowMode == SetupDataFragment.FLOW_MODE_RETURN_NO_ACCOUNTS_RESULT) {
if (EmailContent.count(this, Account.CONTENT_URI) > 0) { if (EmailContent.count(this, Account.CONTENT_URI) > 0) {
setResult(RESULT_OK); setResult(RESULT_OK);
} else { } else {
@ -220,7 +221,7 @@ public class AccountSetupBasics extends AccountSetupActivity
} }
finish(); finish();
return; return;
} else if (flowMode == SetupData.FLOW_MODE_RETURN_TO_MESSAGE_LIST) { } else if (flowMode == SetupDataFragment.FLOW_MODE_RETURN_TO_MESSAGE_LIST) {
final Account account = mSetupData.getAccount(); final Account account = mSetupData.getAccount();
if (account != null && account.mId >= 0) { if (account != null && account.mId >= 0) {
// Show the message list for the new account // Show the message list for the new account
@ -280,7 +281,7 @@ public class AccountSetupBasics extends AccountSetupActivity
// Handle force account creation immediately (now that fragment is set up) // Handle force account creation immediately (now that fragment is set up)
// This is never allowed in a normal user build and will exit immediately. // This is never allowed in a normal user build and will exit immediately.
if (mSetupData.getFlowMode() == SetupData.FLOW_MODE_FORCE_CREATE) { if (mSetupData.getFlowMode() == SetupDataFragment.FLOW_MODE_FORCE_CREATE) {
if (!DEBUG_ALLOW_NON_TEST_HARNESS_CREATION && if (!DEBUG_ALLOW_NON_TEST_HARNESS_CREATION &&
!ActivityManager.isRunningInTestHarness()) { !ActivityManager.isRunningInTestHarness()) {
LogUtils.e(Logging.LOG_TAG, LogUtils.e(Logging.LOG_TAG,
@ -540,7 +541,8 @@ public class AccountSetupBasics extends AccountSetupActivity
if (mAutoSetup) { if (mAutoSetup) {
final AccountCheckSettingsFragment checkerFragment = final AccountCheckSettingsFragment checkerFragment =
AccountCheckSettingsFragment.newInstance( AccountCheckSettingsFragment.newInstance(
SetupData.CHECK_INCOMING | SetupData.CHECK_OUTGOING, null); SetupDataFragment.CHECK_INCOMING | SetupDataFragment.CHECK_OUTGOING,
null);
final FragmentTransaction transaction = getFragmentManager().beginTransaction(); final FragmentTransaction transaction = getFragmentManager().beginTransaction();
transaction.add(checkerFragment, AccountCheckSettingsFragment.TAG); transaction.add(checkerFragment, AccountCheckSettingsFragment.TAG);
transaction.addToBackStack("back"); transaction.addToBackStack("back");
@ -681,7 +683,7 @@ public class AccountSetupBasics extends AccountSetupActivity
* so we inhibit reporting any error back to the Account manager. * so we inhibit reporting any error back to the Account manager.
*/ */
@Override @Override
public void onCheckSettingsComplete(int result, SetupData setupData) { public void onCheckSettingsComplete(int result, SetupDataFragment setupData) {
mSetupData = setupData; mSetupData = setupData;
if (result == AccountCheckSettingsFragment.CHECK_SETTINGS_OK) { if (result == AccountCheckSettingsFragment.CHECK_SETTINGS_OK) {
AccountSetupOptions.actionOptions(this, mSetupData); AccountSetupOptions.actionOptions(this, mSetupData);
@ -695,7 +697,7 @@ public class AccountSetupBasics extends AccountSetupActivity
* This is overridden only by AccountSetupIncoming * This is overridden only by AccountSetupIncoming
*/ */
@Override @Override
public void onAutoDiscoverComplete(int result, SetupData setupData) { public void onAutoDiscoverComplete(int result, SetupDataFragment setupData) {
throw new IllegalStateException(); throw new IllegalStateException();
} }

View File

@ -53,10 +53,10 @@ public class AccountSetupIncoming extends AccountSetupActivity
// Extras for AccountSetupIncoming intent // Extras for AccountSetupIncoming intent
public static void actionIncomingSettings(Activity fromActivity, SetupData setupData) { public static void actionIncomingSettings(Activity fromActivity, SetupDataFragment setupData) {
final Intent intent = new Intent(fromActivity, AccountSetupIncoming.class); final Intent intent = new Intent(fromActivity, AccountSetupIncoming.class);
// Add the additional information to the intent, in case the Email process is killed. // Add the additional information to the intent, in case the Email process is killed.
intent.putExtra(SetupData.EXTRA_SETUP_DATA, setupData); intent.putExtra(SetupDataFragment.EXTRA_SETUP_DATA, setupData);
fromActivity.startActivity(intent); fromActivity.startActivity(intent);
} }
@ -141,11 +141,11 @@ public class AccountSetupIncoming extends AccountSetupActivity
final String username = account.mHostAuthRecv.mLogin; final String username = account.mHostAuthRecv.mLogin;
final String password = account.mHostAuthRecv.mPassword; final String password = account.mHostAuthRecv.mPassword;
if (username != null && password != null) { if (username != null && password != null) {
onProceedNext(SetupData.CHECK_AUTODISCOVER, mFragment); onProceedNext(SetupDataFragment.CHECK_AUTODISCOVER, mFragment);
} }
} }
public void onAutoDiscoverComplete(int result, SetupData setupData) { public void onAutoDiscoverComplete(int result, SetupDataFragment setupData) {
// If authentication failed, exit immediately (to re-enter credentials) // If authentication failed, exit immediately (to re-enter credentials)
mSetupData = setupData; mSetupData = setupData;
if (result == AccountCheckSettingsFragment.AUTODISCOVER_AUTHENTICATION) { if (result == AccountCheckSettingsFragment.AUTODISCOVER_AUTHENTICATION) {
@ -190,7 +190,7 @@ public class AccountSetupIncoming extends AccountSetupActivity
* If the checked settings are OK, proceed to outgoing settings screen * If the checked settings are OK, proceed to outgoing settings screen
*/ */
@Override @Override
public void onCheckSettingsComplete(int result, SetupData setupData) { public void onCheckSettingsComplete(int result, SetupDataFragment setupData) {
mSetupData = setupData; mSetupData = setupData;
if (result == AccountCheckSettingsFragment.CHECK_SETTINGS_OK) { if (result == AccountCheckSettingsFragment.CHECK_SETTINGS_OK) {
if (mServiceInfo.usesSmtp) { if (mServiceInfo.usesSmtp) {

View File

@ -187,7 +187,8 @@ public class AccountSetupIncomingFragment extends AccountServerBaseFragment
mClientCertificateSelector.setHostActivity(this); mClientCertificateSelector.setHostActivity(this);
final Context context = getActivity(); final Context context = getActivity();
final SetupData.SetupDataContainer container = (SetupData.SetupDataContainer) context; final SetupDataFragment.SetupDataContainer container =
(SetupDataFragment.SetupDataContainer) context;
mSetupData = container.getSetupData(); mSetupData = container.getSetupData();
final HostAuth recvAuth = mSetupData.getAccount().mHostAuthRecv; final HostAuth recvAuth = mSetupData.getAccount().mHostAuthRecv;
@ -566,7 +567,7 @@ public class AccountSetupIncomingFragment extends AccountServerBaseFragment
} }
recvAuth.mClientCertAlias = mClientCertificateSelector.getCertificate(); recvAuth.mClientCertAlias = mClientCertificateSelector.getCertificate();
mCallback.onProceedNext(SetupData.CHECK_INCOMING, this); mCallback.onProceedNext(SetupDataFragment.CHECK_INCOMING, this);
clearButtonBounce(); clearButtonBounce();
} }
@ -590,7 +591,7 @@ public class AccountSetupIncomingFragment extends AccountServerBaseFragment
* Implements AccountCheckSettingsFragment.Callbacks * Implements AccountCheckSettingsFragment.Callbacks
*/ */
@Override @Override
public void onAutoDiscoverComplete(int result, SetupData setupData) { public void onAutoDiscoverComplete(int result, SetupDataFragment setupData) {
mSetupData = setupData; mSetupData = setupData;
final AccountSetupIncoming activity = (AccountSetupIncoming) getActivity(); final AccountSetupIncoming activity = (AccountSetupIncoming) getActivity();
activity.onAutoDiscoverComplete(result, setupData); activity.onAutoDiscoverComplete(result, setupData);

View File

@ -59,9 +59,9 @@ public class AccountSetupNames extends AccountSetupActivity {
private boolean mRequiresName = true; private boolean mRequiresName = true;
private boolean mIsCompleting = false; private boolean mIsCompleting = false;
public static void actionSetNames(Activity fromActivity, SetupData setupData) { public static void actionSetNames(Activity fromActivity, SetupDataFragment setupData) {
ForwardingIntent intent = new ForwardingIntent(fromActivity, AccountSetupNames.class); ForwardingIntent intent = new ForwardingIntent(fromActivity, AccountSetupNames.class);
intent.putExtra(SetupData.EXTRA_SETUP_DATA, setupData); intent.putExtra(SetupDataFragment.EXTRA_SETUP_DATA, setupData);
fromActivity.startActivity(intent); fromActivity.startActivity(intent);
} }
@ -108,8 +108,8 @@ public class AccountSetupNames extends AccountSetupActivity {
final int flowMode = mSetupData.getFlowMode(); final int flowMode = mSetupData.getFlowMode();
if (flowMode != SetupData.FLOW_MODE_FORCE_CREATE if (flowMode != SetupDataFragment.FLOW_MODE_FORCE_CREATE
&& flowMode != SetupData.FLOW_MODE_EDIT) { && flowMode != SetupDataFragment.FLOW_MODE_EDIT) {
final String accountEmail = account.mEmailAddress; final String accountEmail = account.mEmailAddress;
mDescription.setText(accountEmail); mDescription.setText(accountEmail);
@ -127,8 +127,8 @@ public class AccountSetupNames extends AccountSetupActivity {
} else { } else {
if (account.getSenderName() != null) { if (account.getSenderName() != null) {
mName.setText(account.getSenderName()); mName.setText(account.getSenderName());
} else if (flowMode != SetupData.FLOW_MODE_FORCE_CREATE } else if (flowMode != SetupDataFragment.FLOW_MODE_FORCE_CREATE
&& flowMode != SetupData.FLOW_MODE_EDIT) { && flowMode != SetupDataFragment.FLOW_MODE_EDIT) {
// Attempt to prefill the name field from the profile if we don't have it, // Attempt to prefill the name field from the profile if we don't have it,
prefillNameFromProfile(); prefillNameFromProfile();
} }
@ -138,7 +138,7 @@ public class AccountSetupNames extends AccountSetupActivity {
validateFields(); validateFields();
// Proceed immediately if in account creation mode // Proceed immediately if in account creation mode
if (flowMode == SetupData.FLOW_MODE_FORCE_CREATE) { if (flowMode == SetupDataFragment.FLOW_MODE_FORCE_CREATE) {
onNext(); onNext();
} }
} }
@ -189,9 +189,9 @@ public class AccountSetupNames extends AccountSetupActivity {
} }
private void finishActivity() { private void finishActivity() {
if (mSetupData.getFlowMode() == SetupData.FLOW_MODE_NO_ACCOUNTS) { if (mSetupData.getFlowMode() == SetupDataFragment.FLOW_MODE_NO_ACCOUNTS) {
AccountSetupBasics.actionAccountCreateFinishedWithResult(this); AccountSetupBasics.actionAccountCreateFinishedWithResult(this);
} else if (mSetupData.getFlowMode() != SetupData.FLOW_MODE_NORMAL) { } else if (mSetupData.getFlowMode() != SetupDataFragment.FLOW_MODE_NORMAL) {
AccountSetupBasics.actionAccountCreateFinishedAccountFlow(this); AccountSetupBasics.actionAccountCreateFinishedAccountFlow(this);
} else { } else {
final Account account = mSetupData.getAccount(); final Account account = mSetupData.getAccount();

View File

@ -76,9 +76,9 @@ public class AccountSetupOptions extends AccountSetupActivity implements OnClick
/** Default sync window for new EAS accounts */ /** Default sync window for new EAS accounts */
private static final int SYNC_WINDOW_EAS_DEFAULT = SyncWindow.SYNC_WINDOW_1_WEEK; private static final int SYNC_WINDOW_EAS_DEFAULT = SyncWindow.SYNC_WINDOW_1_WEEK;
public static void actionOptions(Activity fromActivity, SetupData setupData) { public static void actionOptions(Activity fromActivity, SetupDataFragment setupData) {
final Intent intent = new ForwardingIntent(fromActivity, AccountSetupOptions.class); final Intent intent = new ForwardingIntent(fromActivity, AccountSetupOptions.class);
intent.putExtra(SetupData.EXTRA_SETUP_DATA, setupData); intent.putExtra(SetupDataFragment.EXTRA_SETUP_DATA, setupData);
fromActivity.startActivity(intent); fromActivity.startActivity(intent);
} }
@ -149,7 +149,7 @@ public class AccountSetupOptions extends AccountSetupActivity implements OnClick
if (mIsProcessing) { if (mIsProcessing) {
// We are already processing, so just show the dialog until we finish // We are already processing, so just show the dialog until we finish
showCreateAccountDialog(); showCreateAccountDialog();
} else if (mSetupData.getFlowMode() == SetupData.FLOW_MODE_FORCE_CREATE) { } else if (mSetupData.getFlowMode() == SetupDataFragment.FLOW_MODE_FORCE_CREATE) {
// If we are just visiting here to fill in details, exit immediately // If we are just visiting here to fill in details, exit immediately
onDone(); onDone();
} }

View File

@ -42,9 +42,9 @@ public class AccountSetupOutgoing extends AccountSetupActivity
private Button mNextButton; private Button mNextButton;
/* package */ boolean mNextButtonEnabled; /* package */ boolean mNextButtonEnabled;
public static void actionOutgoingSettings(Activity fromActivity, SetupData setupData) { public static void actionOutgoingSettings(Activity fromActivity, SetupDataFragment setupData) {
Intent intent = new Intent(fromActivity, AccountSetupOutgoing.class); Intent intent = new Intent(fromActivity, AccountSetupOutgoing.class);
intent.putExtra(SetupData.EXTRA_SETUP_DATA, setupData); intent.putExtra(SetupDataFragment.EXTRA_SETUP_DATA, setupData);
fromActivity.startActivity(intent); fromActivity.startActivity(intent);
} }
@ -110,7 +110,7 @@ public class AccountSetupOutgoing extends AccountSetupActivity
* If the checked settings are OK, proceed to options screen * If the checked settings are OK, proceed to options screen
*/ */
@Override @Override
public void onCheckSettingsComplete(int result, SetupData setupData) { public void onCheckSettingsComplete(int result, SetupDataFragment setupData) {
mSetupData = setupData; mSetupData = setupData;
if (result == AccountCheckSettingsFragment.CHECK_SETTINGS_OK) { if (result == AccountCheckSettingsFragment.CHECK_SETTINGS_OK) {
AccountSetupOptions.actionOptions(this, mSetupData); AccountSetupOptions.actionOptions(this, mSetupData);

View File

@ -387,7 +387,7 @@ public class AccountSetupOutgoingFragment extends AccountServerBaseFragment
sendAuth.setConnection(mBaseScheme, serverAddress, serverPort, securityType); sendAuth.setConnection(mBaseScheme, serverAddress, serverPort, securityType);
sendAuth.mDomain = null; sendAuth.mDomain = null;
mCallback.onProceedNext(SetupData.CHECK_OUTGOING, this); mCallback.onProceedNext(SetupDataFragment.CHECK_OUTGOING, this);
clearButtonBounce(); clearButtonBounce();
} }
} }

View File

@ -47,9 +47,9 @@ public class AccountSetupType extends AccountSetupActivity implements OnClickLis
private boolean mButtonPressed; private boolean mButtonPressed;
public static void actionSelectAccountType(Activity fromActivity, SetupData setupData) { public static void actionSelectAccountType(Activity fromActivity, SetupDataFragment setupData) {
final Intent i = new ForwardingIntent(fromActivity, AccountSetupType.class); final Intent i = new ForwardingIntent(fromActivity, AccountSetupType.class);
i.putExtra(SetupData.EXTRA_SETUP_DATA, setupData); i.putExtra(SetupDataFragment.EXTRA_SETUP_DATA, setupData);
fromActivity.startActivity(i); fromActivity.startActivity(i);
} }
@ -60,7 +60,7 @@ public class AccountSetupType extends AccountSetupActivity implements OnClickLis
final String accountType = mSetupData.getFlowAccountType(); final String accountType = mSetupData.getFlowAccountType();
// If we're in account setup flow mode, see if there's just one protocol that matches // If we're in account setup flow mode, see if there's just one protocol that matches
if (mSetupData.getFlowMode() == SetupData.FLOW_MODE_ACCOUNT_MANAGER) { if (mSetupData.getFlowMode() == SetupDataFragment.FLOW_MODE_ACCOUNT_MANAGER) {
int matches = 0; int matches = 0;
String protocol = null; String protocol = null;
for (EmailServiceInfo info: EmailServiceUtils.getServiceInfoList(this)) { for (EmailServiceInfo info: EmailServiceUtils.getServiceInfoList(this)) {
@ -126,10 +126,11 @@ public class AccountSetupType extends AccountSetupActivity implements OnClickLis
final HostAuth recvAuth = account.getOrCreateHostAuthRecv(this); final HostAuth recvAuth = account.getOrCreateHostAuthRecv(this);
final EmailServiceInfo info = EmailServiceUtils.getServiceInfo(this, recvAuth.mProtocol); final EmailServiceInfo info = EmailServiceUtils.getServiceInfo(this, recvAuth.mProtocol);
if (info.usesAutodiscover) { if (info.usesAutodiscover) {
mSetupData.setCheckSettingsMode(SetupData.CHECK_AUTODISCOVER); mSetupData.setCheckSettingsMode(SetupDataFragment.CHECK_AUTODISCOVER);
} else { } else {
mSetupData.setCheckSettingsMode( mSetupData.setCheckSettingsMode(
SetupData.CHECK_INCOMING | (info.usesSmtp ? SetupData.CHECK_OUTGOING : 0)); SetupDataFragment.CHECK_INCOMING |
(info.usesSmtp ? SetupDataFragment.CHECK_OUTGOING : 0));
} }
recvAuth.mLogin = recvAuth.mLogin + "@" + recvAuth.mAddress; recvAuth.mLogin = recvAuth.mLogin + "@" + recvAuth.mAddress;
AccountSetupBasics.setDefaultsForProtocol(this, account); AccountSetupBasics.setDefaultsForProtocol(this, account);

View File

@ -1,22 +1,7 @@
/*
* Copyright (C) 2010 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.android.email.activity.setup; package com.android.email.activity.setup;
import android.accounts.AccountAuthenticatorResponse; import android.accounts.AccountAuthenticatorResponse;
import android.app.Fragment;
import android.os.Bundle; import android.os.Bundle;
import android.os.Parcel; import android.os.Parcel;
import android.os.Parcelable; import android.os.Parcelable;
@ -24,7 +9,10 @@ import android.os.Parcelable;
import com.android.emailcommon.provider.Account; import com.android.emailcommon.provider.Account;
import com.android.emailcommon.provider.Policy; import com.android.emailcommon.provider.Policy;
public class SetupData implements Parcelable { /**
* Headless fragment to hold setup data for the account setup or settings flows
*/
public class SetupDataFragment extends Fragment implements Parcelable {
// The "extra" name for the Bundle saved with SetupData // The "extra" name for the Bundle saved with SetupData
public static final String EXTRA_SETUP_DATA = "com.android.email.setupdata"; public static final String EXTRA_SETUP_DATA = "com.android.email.setupdata";
@ -47,6 +35,17 @@ public class SetupData implements Parcelable {
public static final int CHECK_OUTGOING = 2; public static final int CHECK_OUTGOING = 2;
public static final int CHECK_AUTODISCOVER = 4; public static final int CHECK_AUTODISCOVER = 4;
private static final String SAVESTATE_FLOWMODE = "flowMode";
private static final String SAVESTATE_FLOWACCOUNTTYPE = "flowAccountType";
private static final String SAVESTATE_ACCOUNT = "account";
private static final String SAVESTATE_USERNAME = "username";
private static final String SAVESTATE_PASSWORD = "password";
private static final String SAVESTATE_CHECKSETTINGSMODE = "checkSettingsMode";
private static final String SAVESTATE_ALLOWAUTODISCOVER = "allowAutoDiscover";
private static final String SAVESTATE_POLICY = "policy";
private static final String SAVESTATE_ACCOUNTAUTHENTICATORRESPONSE =
"accountAuthenticatorResponse";
// All access will be through getters/setters // All access will be through getters/setters
private int mFlowMode = FLOW_MODE_NORMAL; private int mFlowMode = FLOW_MODE_NORMAL;
private String mFlowAccountType; private String mFlowAccountType;
@ -59,11 +58,11 @@ public class SetupData implements Parcelable {
private AccountAuthenticatorResponse mAccountAuthenticatorResponse = null; private AccountAuthenticatorResponse mAccountAuthenticatorResponse = null;
public interface SetupDataContainer { public interface SetupDataContainer {
public SetupData getSetupData(); public SetupDataFragment getSetupData();
public void setSetupData(SetupData setupData); public void setSetupData(SetupDataFragment setupData);
} }
public SetupData() { public SetupDataFragment() {
mPolicy = null; mPolicy = null;
mAllowAutodiscover = true; mAllowAutodiscover = true;
mCheckSettingsMode = 0; mCheckSettingsMode = 0;
@ -73,31 +72,69 @@ public class SetupData implements Parcelable {
mAccountAuthenticatorResponse = null; mAccountAuthenticatorResponse = null;
} }
public SetupData(int flowMode) { public SetupDataFragment(int flowMode) {
this(); this();
mFlowMode = flowMode; mFlowMode = flowMode;
} }
public SetupData(int flowMode, String accountType) { public SetupDataFragment(int flowMode, String accountType) {
this(flowMode); this(flowMode);
mFlowAccountType = accountType; mFlowAccountType = accountType;
} }
public SetupData(int flowMode, Account account) { public SetupDataFragment(int flowMode, Account account) {
this(flowMode); this(flowMode);
mAccount = account; mAccount = account;
} }
@Override
public void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
outState.putInt(SAVESTATE_FLOWMODE, mFlowMode);
outState.putString(SAVESTATE_FLOWACCOUNTTYPE, mFlowAccountType);
outState.putParcelable(SAVESTATE_ACCOUNT, mAccount);
outState.putString(SAVESTATE_USERNAME, mUsername);
outState.putString(SAVESTATE_PASSWORD, mPassword);
outState.putInt(SAVESTATE_CHECKSETTINGSMODE, mCheckSettingsMode);
outState.putBoolean(SAVESTATE_ALLOWAUTODISCOVER, mAllowAutodiscover);
outState.putParcelable(SAVESTATE_POLICY, mPolicy);
outState.putParcelable(SAVESTATE_ACCOUNTAUTHENTICATORRESPONSE,
mAccountAuthenticatorResponse);
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (savedInstanceState != null) {
mFlowMode = savedInstanceState.getInt(SAVESTATE_FLOWMODE);
mFlowAccountType = savedInstanceState.getString(SAVESTATE_FLOWACCOUNTTYPE);
mAccount = savedInstanceState.getParcelable(SAVESTATE_ACCOUNT);
mUsername = savedInstanceState.getString(SAVESTATE_USERNAME);
mPassword = savedInstanceState.getString(SAVESTATE_PASSWORD);
mCheckSettingsMode = savedInstanceState.getInt(SAVESTATE_CHECKSETTINGSMODE);
mAllowAutodiscover = savedInstanceState.getBoolean(SAVESTATE_ALLOWAUTODISCOVER);
mPolicy = savedInstanceState.getParcelable(SAVESTATE_POLICY);
mAccountAuthenticatorResponse =
savedInstanceState.getParcelable(SAVESTATE_ACCOUNTAUTHENTICATORRESPONSE);
}
setRetainInstance(true);
}
// Getters and setters
public int getFlowMode() { public int getFlowMode() {
return mFlowMode; return mFlowMode;
} }
public void setFlowMode(int flowMode) {
mFlowMode = flowMode;
}
public String getFlowAccountType() { public String getFlowAccountType() {
return mFlowAccountType; return mFlowAccountType;
} }
public void setFlowMode(int flowMode) { public void setFlowAccountType(String flowAccountType) {
mFlowMode = flowMode; mFlowAccountType = flowAccountType;
} }
public Account getAccount() { public Account getAccount() {
@ -124,26 +161,20 @@ public class SetupData implements Parcelable {
mPassword = password; mPassword = password;
} }
public int getCheckSettingsMode() {
return mCheckSettingsMode;
}
public void setCheckSettingsMode(int checkSettingsMode) { public void setCheckSettingsMode(int checkSettingsMode) {
mCheckSettingsMode = checkSettingsMode; mCheckSettingsMode = checkSettingsMode;
} }
public boolean isCheckIncoming() {
return (mCheckSettingsMode & CHECK_INCOMING) != 0;
}
public boolean isCheckOutgoing() {
return (mCheckSettingsMode & CHECK_OUTGOING) != 0;
}
public boolean isCheckAutodiscover() {
return (mCheckSettingsMode & CHECK_AUTODISCOVER) != 0;
}
public boolean isAllowAutodiscover() { public boolean isAllowAutodiscover() {
return mAllowAutodiscover; return mAllowAutodiscover;
} }
public void setAllowAutodiscover(boolean mAllowAutodiscover) { public void setAllowAutodiscover(boolean allowAutodiscover) {
mAllowAutodiscover = mAllowAutodiscover; mAllowAutodiscover = allowAutodiscover;
} }
public Policy getPolicy() { public Policy getPolicy() {
@ -152,15 +183,15 @@ public class SetupData implements Parcelable {
public void setPolicy(Policy policy) { public void setPolicy(Policy policy) {
mPolicy = policy; mPolicy = policy;
mAccount.mPolicy = policy;
} }
public AccountAuthenticatorResponse getAccountAuthenticatorResponse() { public AccountAuthenticatorResponse getAccountAuthenticatorResponse() {
return mAccountAuthenticatorResponse; return mAccountAuthenticatorResponse;
} }
public void setAccountAuthenticatorResponse(AccountAuthenticatorResponse response) { public void setAccountAuthenticatorResponse(
mAccountAuthenticatorResponse = response; AccountAuthenticatorResponse accountAuthenticatorResponse) {
mAccountAuthenticatorResponse = accountAuthenticatorResponse;
} }
// Parcelable methods // Parcelable methods
@ -169,22 +200,23 @@ public class SetupData implements Parcelable {
return 0; return 0;
} }
public static final Parcelable.Creator<SetupData> CREATOR = public static final Parcelable.Creator<SetupDataFragment> CREATOR =
new Parcelable.Creator<SetupData>() { new Parcelable.Creator<SetupDataFragment>() {
@Override @Override
public SetupData createFromParcel(Parcel in) { public SetupDataFragment createFromParcel(Parcel in) {
return new SetupData(in); return new SetupDataFragment(in);
} }
@Override @Override
public SetupData[] newArray(int size) { public SetupDataFragment[] newArray(int size) {
return new SetupData[size]; return new SetupDataFragment[size];
} }
}; };
@Override @Override
public void writeToParcel(Parcel dest, int flags) { public void writeToParcel(Parcel dest, int flags) {
dest.writeInt(mFlowMode); dest.writeInt(mFlowMode);
dest.writeString(mFlowAccountType);
dest.writeParcelable(mAccount, 0); dest.writeParcelable(mAccount, 0);
dest.writeString(mUsername); dest.writeString(mUsername);
dest.writeString(mPassword); dest.writeString(mPassword);
@ -194,9 +226,10 @@ public class SetupData implements Parcelable {
dest.writeParcelable(mAccountAuthenticatorResponse, 0); dest.writeParcelable(mAccountAuthenticatorResponse, 0);
} }
public SetupData(Parcel in) { public SetupDataFragment(Parcel in) {
final ClassLoader loader = getClass().getClassLoader(); final ClassLoader loader = getClass().getClassLoader();
mFlowMode = in.readInt(); mFlowMode = in.readInt();
mFlowAccountType = in.readString();
mAccount = in.readParcelable(loader); mAccount = in.readParcelable(loader);
mUsername = in.readString(); mUsername = in.readString();
mPassword = in.readString(); mPassword = in.readString();
@ -221,11 +254,12 @@ public class SetupData implements Parcelable {
sb.append(":a/d="); sb.append(":a/d=");
sb.append(mAllowAutodiscover); sb.append(mAllowAutodiscover);
sb.append(":check="); sb.append(":check=");
if (isCheckIncoming()) sb.append("in+"); if ((mCheckSettingsMode & CHECK_INCOMING) != 0) sb.append("in+");
if (isCheckOutgoing()) sb.append("out+"); if ((mCheckSettingsMode & CHECK_OUTGOING) != 0) sb.append("out+");
if (isCheckAutodiscover()) sb.append("a/d"); if ((mCheckSettingsMode & CHECK_AUTODISCOVER) != 0) sb.append("a/d");
sb.append(":policy="); sb.append(":policy=");
sb.append(mPolicy == null ? "none" : "exists"); sb.append(mPolicy == null ? "none" : "exists");
return sb.toString(); return sb.toString();
} }
} }

View File

@ -27,7 +27,7 @@ import android.widget.EditText;
import com.android.email.R; import com.android.email.R;
import com.android.email.activity.setup.AccountSetupIncoming; import com.android.email.activity.setup.AccountSetupIncoming;
import com.android.email.activity.setup.AccountSetupIncomingFragment; import com.android.email.activity.setup.AccountSetupIncomingFragment;
import com.android.email.activity.setup.SetupData; import com.android.email.activity.setup.SetupDataFragment;
import com.android.emailcommon.provider.Account; import com.android.emailcommon.provider.Account;
import com.android.emailcommon.provider.HostAuth; import com.android.emailcommon.provider.HostAuth;
@ -190,18 +190,15 @@ public class AccountSetupIncomingTests extends
*/ */
private Intent getTestIntent(String storeUriString) private Intent getTestIntent(String storeUriString)
throws URISyntaxException { throws URISyntaxException {
Account account = new Account(); final Account account = new Account();
Context context = getInstrumentation().getTargetContext(); final Context context = getInstrumentation().getTargetContext();
HostAuth auth = account.getOrCreateHostAuthRecv(context); final HostAuth auth = account.getOrCreateHostAuthRecv(context);
HostAuth.setHostAuthFromString(auth, storeUriString); HostAuth.setHostAuthFromString(auth, storeUriString);
final SetupDataFragment setupDataFragment =
Bundle extras = new Bundle(); new SetupDataFragment(SetupDataFragment.FLOW_MODE_NORMAL, account);
extras.putParcelable(SetupData.EXTRA_SETUP_DATA, new SetupData(SetupData.FLOW_MODE_NORMAL, account)); final Intent i = new Intent(Intent.ACTION_MAIN);
i.putExtra(SetupDataFragment.EXTRA_SETUP_DATA, setupDataFragment);
Intent intent = new Intent(Intent.ACTION_MAIN); return i;
intent.putExtras(extras);
return intent;
} }
} }

View File

@ -164,13 +164,16 @@ public class AccountSetupOptionsTests
*/ */
private Intent getTestIntent(String name, String storeUri) private Intent getTestIntent(String name, String storeUri)
throws URISyntaxException { throws URISyntaxException {
Account account = new Account(); final Account account = new Account();
account.setSenderName(name); account.setSenderName(name);
Context context = getInstrumentation().getTargetContext(); final Context context = getInstrumentation().getTargetContext();
HostAuth auth = account.getOrCreateHostAuthRecv(context); final HostAuth auth = account.getOrCreateHostAuthRecv(context);
HostAuth.setHostAuthFromString(auth, storeUri); HostAuth.setHostAuthFromString(auth, storeUri);
SetupData setupData = new SetupData(SetupData.FLOW_MODE_NORMAL, account); final SetupDataFragment setupDataFragment =
return new Intent(Intent.ACTION_MAIN); new SetupDataFragment(SetupDataFragment.FLOW_MODE_NORMAL, account);
final Intent i = new Intent(Intent.ACTION_MAIN);
i.putExtra(SetupDataFragment.EXTRA_SETUP_DATA, setupDataFragment);
return i;
} }
} }

View File

@ -26,7 +26,7 @@ import android.widget.EditText;
import com.android.email.R; import com.android.email.R;
import com.android.email.activity.setup.AccountSetupOutgoing; import com.android.email.activity.setup.AccountSetupOutgoing;
import com.android.email.activity.setup.AccountSetupOutgoingFragment; import com.android.email.activity.setup.AccountSetupOutgoingFragment;
import com.android.email.activity.setup.SetupData; import com.android.email.activity.setup.SetupDataFragment;
import com.android.emailcommon.provider.Account; import com.android.emailcommon.provider.Account;
import com.android.emailcommon.provider.HostAuth; import com.android.emailcommon.provider.HostAuth;
@ -185,13 +185,15 @@ public class AccountSetupOutgoingTests extends
*/ */
private Intent getTestIntent(String senderUriString) private Intent getTestIntent(String senderUriString)
throws URISyntaxException { throws URISyntaxException {
Account account = new Account(); final Account account = new Account();
Context context = getInstrumentation().getTargetContext(); final Context context = getInstrumentation().getTargetContext();
HostAuth auth = account.getOrCreateHostAuthSend(context); final HostAuth auth = account.getOrCreateHostAuthSend(context);
HostAuth.setHostAuthFromString(auth, senderUriString); HostAuth.setHostAuthFromString(auth, senderUriString);
// TODO: we need to do something with this SetupData, add it as an extra in the intent? final SetupDataFragment setupDataFragment =
SetupData setupData = new SetupData(SetupData.FLOW_MODE_NORMAL, account); new SetupDataFragment(SetupDataFragment.FLOW_MODE_NORMAL, account);
return new Intent(Intent.ACTION_MAIN); final Intent i = new Intent(Intent.ACTION_MAIN);
i.putExtra(SetupDataFragment.EXTRA_SETUP_DATA, setupDataFragment);
return i;
} }
} }