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_RESULT = 8; // terminal
private int mState = STATE_START;
private SetupData mSetupData;
private SetupDataFragment mSetupData;
// Support for UI
private boolean mAttached;
@ -106,13 +106,13 @@ public class AccountCheckSettingsFragment extends Fragment {
* Called when CheckSettings completed
* @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.
* @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
@ -153,8 +153,8 @@ public class AccountCheckSettingsFragment extends Fragment {
// If this is the first time, start the AsyncTask
if (mAccountCheckTask == null) {
final int checkMode = getTargetRequestCode();
final SetupData.SetupDataContainer container =
(SetupData.SetupDataContainer) getActivity();
final SetupDataFragment.SetupDataContainer container =
(SetupDataFragment.SetupDataContainer) getActivity();
mSetupData = container.getSetupData();
final Account checkAccount = mSetupData.getAccount();
mAccountCheckTask = (AccountCheckTask)
@ -440,7 +440,7 @@ public class AccountCheckSettingsFragment extends Fragment {
@Override
protected MessagingException doInBackground(Void... params) {
try {
if ((mMode & SetupData.CHECK_AUTODISCOVER) != 0) {
if ((mMode & SetupDataFragment.CHECK_AUTODISCOVER) != 0) {
if (isCancelled()) return null;
publishProgress(STATE_CHECK_AUTODISCOVER);
LogUtils.d(Logging.LOG_TAG, "Begin auto-discover for " + mCheckEmail);
@ -468,7 +468,7 @@ public class AccountCheckSettingsFragment extends Fragment {
}
// Check Incoming Settings
if ((mMode & SetupData.CHECK_INCOMING) != 0) {
if ((mMode & SetupDataFragment.CHECK_INCOMING) != 0) {
if (isCancelled()) return null;
LogUtils.d(Logging.LOG_TAG, "Begin check of incoming email settings");
publishProgress(STATE_CHECK_INCOMING);
@ -513,7 +513,7 @@ public class AccountCheckSettingsFragment extends Fragment {
final EmailServiceInfo info = EmailServiceUtils.getServiceInfo(mContext, protocol);
// Check Outgoing Settings
if (info.usesSmtp && (mMode & SetupData.CHECK_OUTGOING) != 0) {
if (info.usesSmtp && (mMode & SetupDataFragment.CHECK_OUTGOING) != 0) {
if (isCancelled()) return null;
LogUtils.d(Logging.LOG_TAG, "Begin check of outgoing email settings");
publishProgress(STATE_CHECK_OUTGOING);

View File

@ -62,7 +62,7 @@ public abstract class AccountServerBaseFragment extends Fragment
/*package*/ HostAuth mLoadedSendAuth;
/*package*/ HostAuth mLoadedRecvAuth;
protected SetupData mSetupData;
protected SetupDataFragment mSetupData;
// This is null in the setup wizard screens, and non-null in AccountSettings mode
private Button mProceedButton;
@ -82,7 +82,7 @@ public abstract class AccountServerBaseFragment extends Fragment
/**
* 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
*/
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 setupData possibly modified SetupData
*/
public void onCheckSettingsComplete(int result, SetupData setupData);
public void onCheckSettingsComplete(int result, SetupDataFragment setupData);
}
private static class EmptyCallback implements Callback {
public static final Callback INSTANCE = new EmptyCallback();
@Override public void onEnableProceedButtons(boolean enable) { }
@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) {
mContext.setTitle(savedInstanceState.getString(BUNDLE_KEY_ACTIVITY_TITLE));
}
SetupData.SetupDataContainer container = (SetupData.SetupDataContainer) mContext;
SetupDataFragment.SetupDataContainer container =
(SetupDataFragment.SetupDataContainer) mContext;
mSetupData = container.getSetupData();
super.onActivityCreated(savedInstanceState);
@ -302,13 +303,13 @@ public abstract class AccountServerBaseFragment extends Fragment
* exit to previous fragment.
*/
@Override
public void onCheckSettingsComplete(final int settingsResult, SetupData setupData) {
public void onCheckSettingsComplete(final int settingsResult, SetupDataFragment setupData) {
mSetupData = setupData;
new AsyncTask<Void, Void, Void>() {
@Override
protected Void doInBackground(Void... params) {
if (settingsResult == AccountCheckSettingsFragment.CHECK_SETTINGS_OK) {
if (mSetupData.getFlowMode() == SetupData.FLOW_MODE_EDIT) {
if (mSetupData.getFlowMode() == SetupDataFragment.FLOW_MODE_EDIT) {
saveSettingsAfterEdit();
} else {
saveSettingsAfterSetup();
@ -330,7 +331,7 @@ public abstract class AccountServerBaseFragment extends Fragment
* This is overridden only by AccountSetupExchange
*/
@Override
public void onAutoDiscoverComplete(int result, SetupData setupData) {
public void onAutoDiscoverComplete(int result, SetupDataFragment setupData) {
throw new IllegalStateException();
}

View File

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

View File

@ -17,6 +17,7 @@
package com.android.email.activity.setup;
import android.app.Activity;
import android.app.FragmentTransaction;
import android.os.Bundle;
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
* 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
protected SetupData mSetupData;
protected SetupDataFragment mSetupData;
private static final String SETUP_DATA_FRAGMENT_TAG = "setupData";
@Override
public void onCreate(Bundle savedInstanceState) {
if (savedInstanceState != null) {
mSetupData = savedInstanceState.getParcelable(SetupData.EXTRA_SETUP_DATA);
} else {
super.onCreate(savedInstanceState);
if (savedInstanceState == null) {
final Bundle b = getIntent().getExtras();
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();
}
}
if (mSetupData == null) {
mSetupData = new SetupData();
} else {
mSetupData = (SetupDataFragment)getFragmentManager()
.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) {
LogUtils.d(Logging.LOG_TAG, "%s onCreate %s", getClass().getName(),
mSetupData.debugString());
@ -52,18 +65,12 @@ public class AccountSetupActivity extends Activity implements SetupData.SetupDat
}
@Override
public void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
outState.putParcelable(SetupData.EXTRA_SETUP_DATA, mSetupData);
}
@Override
public SetupData getSetupData() {
public SetupDataFragment getSetupData() {
return mSetupData;
}
@Override
public void setSetupData(SetupData setupData) {
public void setSetupData(SetupDataFragment setupData) {
mSetupData = setupData;
}
}

View File

@ -126,13 +126,13 @@ public class AccountSetupBasics extends AccountSetupActivity
public static void actionNewAccount(Activity fromActivity) {
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);
}
public static void actionNewAccountWithResult(Activity fromActivity) {
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);
}
@ -142,7 +142,7 @@ public class AccountSetupBasics extends AccountSetupActivity
*/
public static Intent actionGetCreateAccountIntent(Context context, String accountManagerType) {
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);
return i;
}
@ -155,7 +155,8 @@ public class AccountSetupBasics extends AccountSetupActivity
final Intent i= new ForwardingIntent(fromActivity, AccountSetupBasics.class);
// If we're in the "account flow" (from AccountManager), we want to return to the caller
// (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);
fromActivity.startActivity(i);
}
@ -167,8 +168,8 @@ public class AccountSetupBasics extends AccountSetupActivity
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
i.putExtra(SetupData.EXTRA_SETUP_DATA,
new SetupData(SetupData.FLOW_MODE_RETURN_NO_ACCOUNTS_RESULT));
i.putExtra(SetupDataFragment.EXTRA_SETUP_DATA,
new SetupDataFragment(SetupDataFragment.FLOW_MODE_RETURN_NO_ACCOUNTS_RESULT));
i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
fromActivity.startActivity(i);
}
@ -177,8 +178,8 @@ public class AccountSetupBasics extends AccountSetupActivity
final Intent i = new Intent(fromActivity, AccountSetupBasics.class);
// If we're not in the "account flow" (from AccountManager), we want to show the
// message list for the new inbox
i.putExtra(SetupData.EXTRA_SETUP_DATA,
new SetupData(SetupData.FLOW_MODE_RETURN_TO_MESSAGE_LIST, account));
i.putExtra(SetupDataFragment.EXTRA_SETUP_DATA,
new SetupDataFragment(SetupDataFragment.FLOW_MODE_RETURN_TO_MESSAGE_LIST, account));
i.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
fromActivity.startActivity(i);
}
@ -197,22 +198,22 @@ public class AccountSetupBasics extends AccountSetupActivity
INTENT_CREATE_ACCOUNT = getString(R.string.intent_create_account);
}
if (INTENT_CREATE_ACCOUNT.equals(action)) {
mSetupData = new SetupData(SetupData.FLOW_MODE_FORCE_CREATE);
mSetupData = new SetupDataFragment(SetupDataFragment.FLOW_MODE_FORCE_CREATE);
} else {
final int intentFlowMode =
intent.getIntExtra(EXTRA_FLOW_MODE, SetupData.FLOW_MODE_UNSPECIFIED);
if (intentFlowMode != SetupData.FLOW_MODE_UNSPECIFIED) {
mSetupData = new SetupData(intentFlowMode,
intent.getIntExtra(EXTRA_FLOW_MODE, SetupDataFragment.FLOW_MODE_UNSPECIFIED);
if (intentFlowMode != SetupDataFragment.FLOW_MODE_UNSPECIFIED) {
mSetupData = new SetupDataFragment(intentFlowMode,
intent.getStringExtra(EXTRA_FLOW_ACCOUNT_TYPE));
}
}
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
finish();
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) {
setResult(RESULT_OK);
} else {
@ -220,7 +221,7 @@ public class AccountSetupBasics extends AccountSetupActivity
}
finish();
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();
if (account != null && account.mId >= 0) {
// 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)
// 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 &&
!ActivityManager.isRunningInTestHarness()) {
LogUtils.e(Logging.LOG_TAG,
@ -540,7 +541,8 @@ public class AccountSetupBasics extends AccountSetupActivity
if (mAutoSetup) {
final AccountCheckSettingsFragment checkerFragment =
AccountCheckSettingsFragment.newInstance(
SetupData.CHECK_INCOMING | SetupData.CHECK_OUTGOING, null);
SetupDataFragment.CHECK_INCOMING | SetupDataFragment.CHECK_OUTGOING,
null);
final FragmentTransaction transaction = getFragmentManager().beginTransaction();
transaction.add(checkerFragment, AccountCheckSettingsFragment.TAG);
transaction.addToBackStack("back");
@ -681,7 +683,7 @@ public class AccountSetupBasics extends AccountSetupActivity
* so we inhibit reporting any error back to the Account manager.
*/
@Override
public void onCheckSettingsComplete(int result, SetupData setupData) {
public void onCheckSettingsComplete(int result, SetupDataFragment setupData) {
mSetupData = setupData;
if (result == AccountCheckSettingsFragment.CHECK_SETTINGS_OK) {
AccountSetupOptions.actionOptions(this, mSetupData);
@ -695,7 +697,7 @@ public class AccountSetupBasics extends AccountSetupActivity
* This is overridden only by AccountSetupIncoming
*/
@Override
public void onAutoDiscoverComplete(int result, SetupData setupData) {
public void onAutoDiscoverComplete(int result, SetupDataFragment setupData) {
throw new IllegalStateException();
}

View File

@ -53,10 +53,10 @@ public class AccountSetupIncoming extends AccountSetupActivity
// 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);
// 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);
}
@ -141,11 +141,11 @@ public class AccountSetupIncoming extends AccountSetupActivity
final String username = account.mHostAuthRecv.mLogin;
final String password = account.mHostAuthRecv.mPassword;
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)
mSetupData = setupData;
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
*/
@Override
public void onCheckSettingsComplete(int result, SetupData setupData) {
public void onCheckSettingsComplete(int result, SetupDataFragment setupData) {
mSetupData = setupData;
if (result == AccountCheckSettingsFragment.CHECK_SETTINGS_OK) {
if (mServiceInfo.usesSmtp) {

View File

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

View File

@ -59,9 +59,9 @@ public class AccountSetupNames extends AccountSetupActivity {
private boolean mRequiresName = true;
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);
intent.putExtra(SetupData.EXTRA_SETUP_DATA, setupData);
intent.putExtra(SetupDataFragment.EXTRA_SETUP_DATA, setupData);
fromActivity.startActivity(intent);
}
@ -108,8 +108,8 @@ public class AccountSetupNames extends AccountSetupActivity {
final int flowMode = mSetupData.getFlowMode();
if (flowMode != SetupData.FLOW_MODE_FORCE_CREATE
&& flowMode != SetupData.FLOW_MODE_EDIT) {
if (flowMode != SetupDataFragment.FLOW_MODE_FORCE_CREATE
&& flowMode != SetupDataFragment.FLOW_MODE_EDIT) {
final String accountEmail = account.mEmailAddress;
mDescription.setText(accountEmail);
@ -127,8 +127,8 @@ public class AccountSetupNames extends AccountSetupActivity {
} else {
if (account.getSenderName() != null) {
mName.setText(account.getSenderName());
} else if (flowMode != SetupData.FLOW_MODE_FORCE_CREATE
&& flowMode != SetupData.FLOW_MODE_EDIT) {
} else if (flowMode != SetupDataFragment.FLOW_MODE_FORCE_CREATE
&& flowMode != SetupDataFragment.FLOW_MODE_EDIT) {
// Attempt to prefill the name field from the profile if we don't have it,
prefillNameFromProfile();
}
@ -138,7 +138,7 @@ public class AccountSetupNames extends AccountSetupActivity {
validateFields();
// Proceed immediately if in account creation mode
if (flowMode == SetupData.FLOW_MODE_FORCE_CREATE) {
if (flowMode == SetupDataFragment.FLOW_MODE_FORCE_CREATE) {
onNext();
}
}
@ -189,9 +189,9 @@ public class AccountSetupNames extends AccountSetupActivity {
}
private void finishActivity() {
if (mSetupData.getFlowMode() == SetupData.FLOW_MODE_NO_ACCOUNTS) {
if (mSetupData.getFlowMode() == SetupDataFragment.FLOW_MODE_NO_ACCOUNTS) {
AccountSetupBasics.actionAccountCreateFinishedWithResult(this);
} else if (mSetupData.getFlowMode() != SetupData.FLOW_MODE_NORMAL) {
} else if (mSetupData.getFlowMode() != SetupDataFragment.FLOW_MODE_NORMAL) {
AccountSetupBasics.actionAccountCreateFinishedAccountFlow(this);
} else {
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 */
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);
intent.putExtra(SetupData.EXTRA_SETUP_DATA, setupData);
intent.putExtra(SetupDataFragment.EXTRA_SETUP_DATA, setupData);
fromActivity.startActivity(intent);
}
@ -149,7 +149,7 @@ public class AccountSetupOptions extends AccountSetupActivity implements OnClick
if (mIsProcessing) {
// We are already processing, so just show the dialog until we finish
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
onDone();
}

View File

@ -42,9 +42,9 @@ public class AccountSetupOutgoing extends AccountSetupActivity
private Button mNextButton;
/* 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.putExtra(SetupData.EXTRA_SETUP_DATA, setupData);
intent.putExtra(SetupDataFragment.EXTRA_SETUP_DATA, setupData);
fromActivity.startActivity(intent);
}
@ -110,7 +110,7 @@ public class AccountSetupOutgoing extends AccountSetupActivity
* If the checked settings are OK, proceed to options screen
*/
@Override
public void onCheckSettingsComplete(int result, SetupData setupData) {
public void onCheckSettingsComplete(int result, SetupDataFragment setupData) {
mSetupData = setupData;
if (result == AccountCheckSettingsFragment.CHECK_SETTINGS_OK) {
AccountSetupOptions.actionOptions(this, mSetupData);

View File

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

View File

@ -47,9 +47,9 @@ public class AccountSetupType extends AccountSetupActivity implements OnClickLis
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);
i.putExtra(SetupData.EXTRA_SETUP_DATA, setupData);
i.putExtra(SetupDataFragment.EXTRA_SETUP_DATA, setupData);
fromActivity.startActivity(i);
}
@ -60,7 +60,7 @@ public class AccountSetupType extends AccountSetupActivity implements OnClickLis
final String accountType = mSetupData.getFlowAccountType();
// 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;
String protocol = null;
for (EmailServiceInfo info: EmailServiceUtils.getServiceInfoList(this)) {
@ -126,10 +126,11 @@ public class AccountSetupType extends AccountSetupActivity implements OnClickLis
final HostAuth recvAuth = account.getOrCreateHostAuthRecv(this);
final EmailServiceInfo info = EmailServiceUtils.getServiceInfo(this, recvAuth.mProtocol);
if (info.usesAutodiscover) {
mSetupData.setCheckSettingsMode(SetupData.CHECK_AUTODISCOVER);
mSetupData.setCheckSettingsMode(SetupDataFragment.CHECK_AUTODISCOVER);
} else {
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;
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;
import android.accounts.AccountAuthenticatorResponse;
import android.app.Fragment;
import android.os.Bundle;
import android.os.Parcel;
import android.os.Parcelable;
@ -24,7 +9,10 @@ import android.os.Parcelable;
import com.android.emailcommon.provider.Account;
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
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_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
private int mFlowMode = FLOW_MODE_NORMAL;
private String mFlowAccountType;
@ -59,11 +58,11 @@ public class SetupData implements Parcelable {
private AccountAuthenticatorResponse mAccountAuthenticatorResponse = null;
public interface SetupDataContainer {
public SetupData getSetupData();
public void setSetupData(SetupData setupData);
public SetupDataFragment getSetupData();
public void setSetupData(SetupDataFragment setupData);
}
public SetupData() {
public SetupDataFragment() {
mPolicy = null;
mAllowAutodiscover = true;
mCheckSettingsMode = 0;
@ -73,31 +72,69 @@ public class SetupData implements Parcelable {
mAccountAuthenticatorResponse = null;
}
public SetupData(int flowMode) {
public SetupDataFragment(int flowMode) {
this();
mFlowMode = flowMode;
}
public SetupData(int flowMode, String accountType) {
public SetupDataFragment(int flowMode, String accountType) {
this(flowMode);
mFlowAccountType = accountType;
}
public SetupData(int flowMode, Account account) {
public SetupDataFragment(int flowMode, Account account) {
this(flowMode);
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() {
return mFlowMode;
}
public void setFlowMode(int flowMode) {
mFlowMode = flowMode;
}
public String getFlowAccountType() {
return mFlowAccountType;
}
public void setFlowMode(int flowMode) {
mFlowMode = flowMode;
public void setFlowAccountType(String flowAccountType) {
mFlowAccountType = flowAccountType;
}
public Account getAccount() {
@ -124,26 +161,20 @@ public class SetupData implements Parcelable {
mPassword = password;
}
public int getCheckSettingsMode() {
return mCheckSettingsMode;
}
public void setCheckSettingsMode(int 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() {
return mAllowAutodiscover;
}
public void setAllowAutodiscover(boolean mAllowAutodiscover) {
mAllowAutodiscover = mAllowAutodiscover;
public void setAllowAutodiscover(boolean allowAutodiscover) {
mAllowAutodiscover = allowAutodiscover;
}
public Policy getPolicy() {
@ -152,15 +183,15 @@ public class SetupData implements Parcelable {
public void setPolicy(Policy policy) {
mPolicy = policy;
mAccount.mPolicy = policy;
}
public AccountAuthenticatorResponse getAccountAuthenticatorResponse() {
return mAccountAuthenticatorResponse;
}
public void setAccountAuthenticatorResponse(AccountAuthenticatorResponse response) {
mAccountAuthenticatorResponse = response;
public void setAccountAuthenticatorResponse(
AccountAuthenticatorResponse accountAuthenticatorResponse) {
mAccountAuthenticatorResponse = accountAuthenticatorResponse;
}
// Parcelable methods
@ -169,22 +200,23 @@ public class SetupData implements Parcelable {
return 0;
}
public static final Parcelable.Creator<SetupData> CREATOR =
new Parcelable.Creator<SetupData>() {
public static final Parcelable.Creator<SetupDataFragment> CREATOR =
new Parcelable.Creator<SetupDataFragment>() {
@Override
public SetupData createFromParcel(Parcel in) {
return new SetupData(in);
public SetupDataFragment createFromParcel(Parcel in) {
return new SetupDataFragment(in);
}
@Override
public SetupData[] newArray(int size) {
return new SetupData[size];
public SetupDataFragment[] newArray(int size) {
return new SetupDataFragment[size];
}
};
@Override
public void writeToParcel(Parcel dest, int flags) {
dest.writeInt(mFlowMode);
dest.writeString(mFlowAccountType);
dest.writeParcelable(mAccount, 0);
dest.writeString(mUsername);
dest.writeString(mPassword);
@ -194,9 +226,10 @@ public class SetupData implements Parcelable {
dest.writeParcelable(mAccountAuthenticatorResponse, 0);
}
public SetupData(Parcel in) {
public SetupDataFragment(Parcel in) {
final ClassLoader loader = getClass().getClassLoader();
mFlowMode = in.readInt();
mFlowAccountType = in.readString();
mAccount = in.readParcelable(loader);
mUsername = in.readString();
mPassword = in.readString();
@ -221,11 +254,12 @@ public class SetupData implements Parcelable {
sb.append(":a/d=");
sb.append(mAllowAutodiscover);
sb.append(":check=");
if (isCheckIncoming()) sb.append("in+");
if (isCheckOutgoing()) sb.append("out+");
if (isCheckAutodiscover()) sb.append("a/d");
if ((mCheckSettingsMode & CHECK_INCOMING) != 0) sb.append("in+");
if ((mCheckSettingsMode & CHECK_OUTGOING) != 0) sb.append("out+");
if ((mCheckSettingsMode & CHECK_AUTODISCOVER) != 0) sb.append("a/d");
sb.append(":policy=");
sb.append(mPolicy == null ? "none" : "exists");
return sb.toString();
}
}

View File

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

@ -164,13 +164,16 @@ public class AccountSetupOptionsTests
*/
private Intent getTestIntent(String name, String storeUri)
throws URISyntaxException {
Account account = new Account();
final Account account = new Account();
account.setSenderName(name);
Context context = getInstrumentation().getTargetContext();
HostAuth auth = account.getOrCreateHostAuthRecv(context);
final Context context = getInstrumentation().getTargetContext();
final HostAuth auth = account.getOrCreateHostAuthRecv(context);
HostAuth.setHostAuthFromString(auth, storeUri);
SetupData setupData = new SetupData(SetupData.FLOW_MODE_NORMAL, account);
return new Intent(Intent.ACTION_MAIN);
final SetupDataFragment setupDataFragment =
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.activity.setup.AccountSetupOutgoing;
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.HostAuth;
@ -185,13 +185,15 @@ public class AccountSetupOutgoingTests extends
*/
private Intent getTestIntent(String senderUriString)
throws URISyntaxException {
Account account = new Account();
Context context = getInstrumentation().getTargetContext();
HostAuth auth = account.getOrCreateHostAuthSend(context);
final Account account = new Account();
final Context context = getInstrumentation().getTargetContext();
final HostAuth auth = account.getOrCreateHostAuthSend(context);
HostAuth.setHostAuthFromString(auth, senderUriString);
// TODO: we need to do something with this SetupData, add it as an extra in the intent?
SetupData setupData = new SetupData(SetupData.FLOW_MODE_NORMAL, account);
return new Intent(Intent.ACTION_MAIN);
final SetupDataFragment setupDataFragment =
new SetupDataFragment(SetupDataFragment.FLOW_MODE_NORMAL, account);
final Intent i = new Intent(Intent.ACTION_MAIN);
i.putExtra(SetupDataFragment.EXTRA_SETUP_DATA, setupDataFragment);
return i;
}
}