Don't store the account creation/modificaiton state in a singleton
b/10460757 Change-Id: I7f0bea69f843f9061d1cfa9277c99d36705aceaf
This commit is contained in:
parent
dad44e53b2
commit
26cd5e024c
|
@ -69,6 +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;
|
||||
|
||||
// Support for UI
|
||||
private boolean mAttached;
|
||||
|
@ -105,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);
|
||||
public void onCheckSettingsComplete(int result, SetupData setupData);
|
||||
|
||||
/**
|
||||
* Called when autodiscovery completes.
|
||||
* @param result autodiscovery result code - success is AUTODISCOVER_OK
|
||||
*/
|
||||
public void onAutoDiscoverComplete(int result);
|
||||
public void onAutoDiscoverComplete(int result, SetupData setupData);
|
||||
}
|
||||
|
||||
// Public no-args constructor needed for fragment re-instantiation
|
||||
|
@ -152,7 +153,10 @@ public class AccountCheckSettingsFragment extends Fragment {
|
|||
// If this is the first time, start the AsyncTask
|
||||
if (mAccountCheckTask == null) {
|
||||
final int checkMode = getTargetRequestCode();
|
||||
final Account checkAccount = SetupData.getAccount();
|
||||
final SetupData.SetupDataContainer container =
|
||||
(SetupData.SetupDataContainer) getActivity();
|
||||
mSetupData = container.getSetupData();
|
||||
final Account checkAccount = mSetupData.getAccount();
|
||||
mAccountCheckTask = (AccountCheckTask)
|
||||
new AccountCheckTask(checkMode, checkAccount)
|
||||
.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||
|
@ -223,7 +227,7 @@ public class AccountCheckSettingsFragment extends Fragment {
|
|||
// 2. exit self
|
||||
fm.popBackStack();
|
||||
// 3. report OK back to target fragment or activity
|
||||
getCallbackTarget().onCheckSettingsComplete(CHECK_SETTINGS_OK);
|
||||
getCallbackTarget().onCheckSettingsComplete(CHECK_SETTINGS_OK, mSetupData);
|
||||
break;
|
||||
case STATE_CHECK_SHOW_SECURITY:
|
||||
// 1. get rid of progress dialog (if any)
|
||||
|
@ -262,7 +266,8 @@ public class AccountCheckSettingsFragment extends Fragment {
|
|||
fm.popBackStack();
|
||||
// 3. report back to target fragment or activity
|
||||
getCallbackTarget().onAutoDiscoverComplete(
|
||||
(autoDiscoverResult != null) ? AUTODISCOVER_OK : AUTODISCOVER_NO_DATA);
|
||||
(autoDiscoverResult != null) ? AUTODISCOVER_OK : AUTODISCOVER_NO_DATA,
|
||||
mSetupData);
|
||||
break;
|
||||
default:
|
||||
// Display a normal progress message
|
||||
|
@ -324,7 +329,8 @@ public class AccountCheckSettingsFragment extends Fragment {
|
|||
}
|
||||
|
||||
private void onEditCertificateOk() {
|
||||
getCallbackTarget().onCheckSettingsComplete(CHECK_SETTINGS_CLIENT_CERTIFICATE_NEEDED);
|
||||
getCallbackTarget().onCheckSettingsComplete(CHECK_SETTINGS_CLIENT_CERTIFICATE_NEEDED,
|
||||
mSetupData);
|
||||
finish();
|
||||
}
|
||||
|
||||
|
@ -339,10 +345,10 @@ public class AccountCheckSettingsFragment extends Fragment {
|
|||
final Callbacks callbackTarget = getCallbackTarget();
|
||||
if (mState == STATE_AUTODISCOVER_AUTH_DIALOG) {
|
||||
// report auth error to target fragment or activity
|
||||
callbackTarget.onAutoDiscoverComplete(AUTODISCOVER_AUTHENTICATION);
|
||||
callbackTarget.onAutoDiscoverComplete(AUTODISCOVER_AUTHENTICATION, mSetupData);
|
||||
} else {
|
||||
// report check settings failure to target fragment or activity
|
||||
callbackTarget.onCheckSettingsComplete(CHECK_SETTINGS_SERVER_ERROR);
|
||||
callbackTarget.onCheckSettingsComplete(CHECK_SETTINGS_SERVER_ERROR, mSetupData);
|
||||
}
|
||||
finish();
|
||||
}
|
||||
|
@ -363,7 +369,7 @@ public class AccountCheckSettingsFragment extends Fragment {
|
|||
// 1. handle OK/cancel - notify that security is OK and we can proceed
|
||||
final Callbacks callbackTarget = getCallbackTarget();
|
||||
callbackTarget.onCheckSettingsComplete(
|
||||
okPressed ? CHECK_SETTINGS_OK : CHECK_SETTINGS_SECURITY_USER_DENY);
|
||||
okPressed ? CHECK_SETTINGS_OK : CHECK_SETTINGS_SECURITY_USER_DENY, mSetupData);
|
||||
|
||||
// 2. kill self if not already killed by callback
|
||||
final FragmentManager fm = getFragmentManager();
|
||||
|
@ -476,7 +482,7 @@ public class AccountCheckSettingsFragment extends Fragment {
|
|||
resultCode = MessagingException.NO_ERROR;
|
||||
}
|
||||
if (resultCode == MessagingException.SECURITY_POLICIES_REQUIRED) {
|
||||
SetupData.setPolicy((Policy)bundle.getParcelable(
|
||||
mSetupData.setPolicy((Policy)bundle.getParcelable(
|
||||
EmailServiceProxy.VALIDATE_BUNDLE_POLICY_SET));
|
||||
return new MessagingException(resultCode, mStoreHost);
|
||||
} else if (resultCode == MessagingException.SECURITY_POLICIES_UNSUPPORTED) {
|
||||
|
|
|
@ -37,9 +37,6 @@ import com.android.emailcommon.provider.Account;
|
|||
import com.android.emailcommon.provider.HostAuth;
|
||||
import com.android.emailcommon.utility.Utility;
|
||||
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
|
||||
/**
|
||||
* Common base class for server settings fragments, so they can be more easily manipulated by
|
||||
* AccountSettingsXL. Provides the following common functionality:
|
||||
|
@ -51,13 +48,10 @@ import java.net.URISyntaxException;
|
|||
public abstract class AccountServerBaseFragment extends Fragment
|
||||
implements AccountCheckSettingsFragment.Callbacks, OnClickListener {
|
||||
|
||||
public static Bundle sSetupModeArgs = null;
|
||||
protected static URI sDefaultUri;
|
||||
|
||||
private static final String BUNDLE_KEY_SETTINGS = "AccountServerBaseFragment.settings";
|
||||
private static final String BUNDLE_KEY_ACTIVITY_TITLE = "AccountServerBaseFragment.title";
|
||||
|
||||
protected Context mContext;
|
||||
protected Activity mContext;
|
||||
protected Callback mCallback = EmptyCallback.INSTANCE;
|
||||
/**
|
||||
* Whether or not we are in "settings mode". We re-use the same screens for both the initial
|
||||
|
@ -69,6 +63,8 @@ public abstract class AccountServerBaseFragment extends Fragment
|
|||
/*package*/ HostAuth mLoadedSendAuth;
|
||||
/*package*/ HostAuth mLoadedRecvAuth;
|
||||
|
||||
protected SetupData mSetupData;
|
||||
|
||||
// This is null in the setup wizard screens, and non-null in AccountSettings mode
|
||||
private Button mProceedButton;
|
||||
// This is used to debounce multiple clicks on the proceed button (which does async work)
|
||||
|
@ -96,39 +92,31 @@ public abstract class AccountServerBaseFragment extends Fragment
|
|||
* Called when account checker completes. Fragments are responsible for saving
|
||||
* own edited data; This is primarily for the activity to do post-check navigation.
|
||||
* @param result check settings result code - success is CHECK_SETTINGS_OK
|
||||
* @param setupMode signals if we were editing or creating
|
||||
* @param setupData possibly modified SetupData
|
||||
*/
|
||||
public void onCheckSettingsComplete(int result, int setupMode);
|
||||
public void onCheckSettingsComplete(int result, SetupData 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, int setupMode) { }
|
||||
@Override public void onCheckSettingsComplete(int result, SetupData setupData) { }
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the static arguments bundle that forces a server settings fragment into "settings" mode
|
||||
* (If not included, you'll be in "setup" mode which behaves slightly differently.)
|
||||
* Creates and returns a bundle of arguments in the format we expect
|
||||
*
|
||||
* @param settingsMode True if we're in settings, false if we're in account creation
|
||||
* @return Arg bundle
|
||||
*/
|
||||
public static synchronized Bundle getSettingsModeArgs() {
|
||||
if (sSetupModeArgs == null) {
|
||||
sSetupModeArgs = new Bundle();
|
||||
sSetupModeArgs.putBoolean(BUNDLE_KEY_SETTINGS, true);
|
||||
}
|
||||
return sSetupModeArgs;
|
||||
public static Bundle getArgs(Boolean settingsMode) {
|
||||
final Bundle setupModeArgs = new Bundle(1);
|
||||
setupModeArgs.putBoolean(BUNDLE_KEY_SETTINGS, settingsMode);
|
||||
return setupModeArgs;
|
||||
}
|
||||
|
||||
public AccountServerBaseFragment() {
|
||||
if (sDefaultUri == null) {
|
||||
try {
|
||||
sDefaultUri = new URI("");
|
||||
} catch (URISyntaxException ignore) {
|
||||
// ignore; will never happen
|
||||
}
|
||||
}
|
||||
}
|
||||
public AccountServerBaseFragment() {}
|
||||
|
||||
/**
|
||||
* At onCreate time, read the fragment arguments
|
||||
|
@ -139,7 +127,9 @@ public abstract class AccountServerBaseFragment extends Fragment
|
|||
|
||||
// Get arguments, which modally switch us into "settings" mode (different appearance)
|
||||
mSettingsMode = false;
|
||||
if (getArguments() != null) {
|
||||
if (savedInstanceState != null) {
|
||||
mSettingsMode = savedInstanceState.getBoolean(BUNDLE_KEY_SETTINGS);
|
||||
} else if (getArguments() != null) {
|
||||
mSettingsMode = getArguments().getBoolean(BUNDLE_KEY_SETTINGS);
|
||||
}
|
||||
setHasOptionsMenu(true);
|
||||
|
@ -161,21 +151,20 @@ public abstract class AccountServerBaseFragment extends Fragment
|
|||
public void onActivityCreated(Bundle savedInstanceState) {
|
||||
// startPreferencePanel launches this fragment with the right title initially, but
|
||||
// if the device is rotate we must set the title ourselves
|
||||
mContext = getActivity();
|
||||
if (mSettingsMode && savedInstanceState != null) {
|
||||
getActivity().setTitle(savedInstanceState.getString(BUNDLE_KEY_ACTIVITY_TITLE));
|
||||
mContext.setTitle(savedInstanceState.getString(BUNDLE_KEY_ACTIVITY_TITLE));
|
||||
}
|
||||
SetupData.SetupDataContainer container = (SetupData.SetupDataContainer) mContext;
|
||||
mSetupData = container.getSetupData();
|
||||
|
||||
super.onActivityCreated(savedInstanceState);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSaveInstanceState(Bundle outState) {
|
||||
outState.putString(BUNDLE_KEY_ACTIVITY_TITLE, (String) getActivity().getTitle());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAttach(Activity activity) {
|
||||
super.onAttach(activity);
|
||||
mContext = activity;
|
||||
outState.putBoolean(BUNDLE_KEY_SETTINGS, mSettingsMode);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -189,7 +178,7 @@ public abstract class AccountServerBaseFragment extends Fragment
|
|||
@Override
|
||||
public void onPause() {
|
||||
// Hide the soft keyboard if we lose focus
|
||||
InputMethodManager imm =
|
||||
final InputMethodManager imm =
|
||||
(InputMethodManager)mContext.getSystemService(Context.INPUT_METHOD_SERVICE);
|
||||
imm.hideSoftInputFromWindow(getView().getWindowToken(), 0);
|
||||
super.onPause();
|
||||
|
@ -301,7 +290,7 @@ public abstract class AccountServerBaseFragment extends Fragment
|
|||
if (context == null) {
|
||||
return false;
|
||||
}
|
||||
InputMethodManager imm = (InputMethodManager) context.getSystemService(
|
||||
final InputMethodManager imm = (InputMethodManager) context.getSystemService(
|
||||
Context.INPUT_METHOD_SERVICE);
|
||||
if (imm != null && imm.isActive()) {
|
||||
imm.hideSoftInputFromWindow(getView().getWindowToken(), 0);
|
||||
|
@ -344,7 +333,7 @@ public abstract class AccountServerBaseFragment extends Fragment
|
|||
AccountServerBaseFragment fragment = AccountServerBaseFragment.this;
|
||||
if (duplicateAccount != null) {
|
||||
// Show duplicate account warning
|
||||
DuplicateAccountDialogFragment dialogFragment =
|
||||
final DuplicateAccountDialogFragment dialogFragment =
|
||||
DuplicateAccountDialogFragment.newInstance(duplicateAccount.mDisplayName);
|
||||
dialogFragment.show(fragment.getFragmentManager(),
|
||||
DuplicateAccountDialogFragment.TAG);
|
||||
|
@ -363,12 +352,13 @@ public abstract class AccountServerBaseFragment extends Fragment
|
|||
* exit to previous fragment.
|
||||
*/
|
||||
@Override
|
||||
public void onCheckSettingsComplete(final int settingsResult) {
|
||||
public void onCheckSettingsComplete(final int settingsResult, SetupData setupData) {
|
||||
mSetupData = setupData;
|
||||
new AsyncTask<Void, Void, Void>() {
|
||||
@Override
|
||||
protected Void doInBackground(Void... params) {
|
||||
if (settingsResult == AccountCheckSettingsFragment.CHECK_SETTINGS_OK) {
|
||||
if (SetupData.getFlowMode() == SetupData.FLOW_MODE_EDIT) {
|
||||
if (mSetupData.getFlowMode() == SetupData.FLOW_MODE_EDIT) {
|
||||
saveSettingsAfterEdit();
|
||||
} else {
|
||||
saveSettingsAfterSetup();
|
||||
|
@ -380,7 +370,7 @@ public abstract class AccountServerBaseFragment extends Fragment
|
|||
@Override
|
||||
protected void onPostExecute(Void result) {
|
||||
// Signal to owning activity that a settings check completed
|
||||
mCallback.onCheckSettingsComplete(settingsResult, SetupData.getFlowMode());
|
||||
mCallback.onCheckSettingsComplete(settingsResult, mSetupData);
|
||||
}
|
||||
}.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||
}
|
||||
|
@ -390,7 +380,7 @@ public abstract class AccountServerBaseFragment extends Fragment
|
|||
* This is overridden only by AccountSetupExchange
|
||||
*/
|
||||
@Override
|
||||
public void onAutoDiscoverComplete(int result) {
|
||||
public void onAutoDiscoverComplete(int result, SetupData setupData) {
|
||||
throw new IllegalStateException();
|
||||
}
|
||||
|
||||
|
@ -398,13 +388,13 @@ public abstract class AccountServerBaseFragment extends Fragment
|
|||
* Returns whether or not any settings have changed.
|
||||
*/
|
||||
public boolean haveSettingsChanged() {
|
||||
Account account = SetupData.getAccount();
|
||||
final Account account = mSetupData.getAccount();
|
||||
|
||||
HostAuth sendAuth = account.getOrCreateHostAuthSend(mContext);
|
||||
boolean sendChanged = (mLoadedSendAuth != null && !mLoadedSendAuth.equals(sendAuth));
|
||||
final HostAuth sendAuth = account.getOrCreateHostAuthSend(mContext);
|
||||
final boolean sendChanged = (mLoadedSendAuth != null && !mLoadedSendAuth.equals(sendAuth));
|
||||
|
||||
HostAuth recvAuth = account.getOrCreateHostAuthRecv(mContext);
|
||||
boolean recvChanged = (mLoadedRecvAuth != null && !mLoadedRecvAuth.equals(recvAuth));
|
||||
final HostAuth recvAuth = account.getOrCreateHostAuthRecv(mContext);
|
||||
final boolean recvChanged = (mLoadedRecvAuth != null && !mLoadedRecvAuth.equals(recvAuth));
|
||||
|
||||
return sendChanged || recvChanged;
|
||||
}
|
||||
|
|
|
@ -73,7 +73,8 @@ import java.util.List;
|
|||
* sense to use a loader for the accounts list, because it would provide better support for
|
||||
* 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 {
|
||||
/*
|
||||
* Intent to open account settings for account=1
|
||||
adb shell am start -a android.intent.action.EDIT \
|
||||
|
@ -121,6 +122,8 @@ public class AccountSettings extends PreferenceActivity implements FeedbackEnabl
|
|||
private Uri mFeedbackUri;
|
||||
private MenuItem mFeedbackMenuItem;
|
||||
|
||||
private SetupData mSetupData;
|
||||
|
||||
// Async Tasks
|
||||
private LoadAccountListTask mLoadAccountListTask;
|
||||
private GetAccountIdFromAccountTask mGetAccountIdFromAccountTask;
|
||||
|
@ -148,7 +151,7 @@ public class AccountSettings extends PreferenceActivity implements FeedbackEnabl
|
|||
String loginWarningAccountName, String loginWarningReason) {
|
||||
final Uri.Builder b = IntentUtilities.createActivityIntentUrlBuilder("settings");
|
||||
IntentUtilities.setAccountId(b, accountId);
|
||||
Intent i = new Intent(Intent.ACTION_EDIT, b.build());
|
||||
final Intent i = new Intent(Intent.ACTION_EDIT, b.build());
|
||||
if (loginWarningAccountName != null) {
|
||||
i.putExtra(EXTRA_LOGIN_WARNING_FOR_ACCOUNT, loginWarningAccountName);
|
||||
}
|
||||
|
@ -162,7 +165,7 @@ public class AccountSettings extends PreferenceActivity implements FeedbackEnabl
|
|||
* Launch generic settings and pre-enable the debug preferences
|
||||
*/
|
||||
public static void actionSettingsWithDebug(Context fromContext) {
|
||||
Intent i = new Intent(fromContext, AccountSettings.class);
|
||||
final Intent i = new Intent(fromContext, AccountSettings.class);
|
||||
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
i.putExtra(EXTRA_ENABLE_DEBUG, true);
|
||||
fromContext.startActivity(i);
|
||||
|
@ -208,10 +211,12 @@ public class AccountSettings extends PreferenceActivity implements FeedbackEnabl
|
|||
dialog.show(getFragmentManager(), "loginwarning");
|
||||
}
|
||||
}
|
||||
} else {
|
||||
mSetupData = savedInstanceState.getParcelable(SetupData.EXTRA_SETUP_DATA);
|
||||
}
|
||||
mShowDebugMenu = i.getBooleanExtra(EXTRA_ENABLE_DEBUG, false);
|
||||
|
||||
String title = i.getStringExtra(EXTRA_TITLE);
|
||||
final String title = i.getStringExtra(EXTRA_TITLE);
|
||||
if (title != null) {
|
||||
setTitle(title);
|
||||
}
|
||||
|
@ -229,6 +234,13 @@ public class AccountSettings extends PreferenceActivity implements FeedbackEnabl
|
|||
mFeedbackUri = Utils.getValidUri(getString(R.string.email_feedback_uri));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onSaveInstanceState(Bundle outState) {
|
||||
super.onSaveInstanceState(
|
||||
outState);
|
||||
outState.putParcelable(SetupData.EXTRA_SETUP_DATA, mSetupData);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
|
@ -314,16 +326,16 @@ public class AccountSettings extends PreferenceActivity implements FeedbackEnabl
|
|||
@Override
|
||||
public Intent onBuildStartFragmentIntent(String fragmentName, Bundle args,
|
||||
int titleRes, int shortTitleRes) {
|
||||
Intent result = super.onBuildStartFragmentIntent(
|
||||
final Intent intent = super.onBuildStartFragmentIntent(
|
||||
fragmentName, args, titleRes, shortTitleRes);
|
||||
|
||||
// When opening a sub-settings page (e.g. account specific page), see if we want to modify
|
||||
// the activity title.
|
||||
String title = AccountSettingsFragment.getTitleFromArgs(args);
|
||||
if ((titleRes == 0) && (title != null)) {
|
||||
result.putExtra(EXTRA_TITLE, title);
|
||||
intent.putExtra(EXTRA_TITLE, title);
|
||||
}
|
||||
return result;
|
||||
return intent;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -339,8 +351,7 @@ public class AccountSettings extends PreferenceActivity implements FeedbackEnabl
|
|||
@Override
|
||||
public void onBackPressed() {
|
||||
if (mCurrentFragment instanceof AccountServerBaseFragment) {
|
||||
boolean changed = ((AccountServerBaseFragment) mCurrentFragment).haveSettingsChanged();
|
||||
if (changed) {
|
||||
if (((AccountServerBaseFragment) mCurrentFragment).haveSettingsChanged()) {
|
||||
UnsavedChangesDialogFragment dialogFragment =
|
||||
UnsavedChangesDialogFragment.newInstanceForBack();
|
||||
dialogFragment.show(getFragmentManager(), UnsavedChangesDialogFragment.TAG);
|
||||
|
@ -351,7 +362,7 @@ public class AccountSettings extends PreferenceActivity implements FeedbackEnabl
|
|||
}
|
||||
|
||||
private void launchMailboxSettings(Intent intent) {
|
||||
final Folder folder = (Folder)intent.getParcelableExtra(EditSettingsExtras.EXTRA_FOLDER);
|
||||
final Folder folder = intent.getParcelableExtra(EditSettingsExtras.EXTRA_FOLDER);
|
||||
|
||||
// TODO: determine from the account if we should navigate to the mailbox settings.
|
||||
// See bug 6242668
|
||||
|
@ -400,7 +411,7 @@ public class AccountSettings extends PreferenceActivity implements FeedbackEnabl
|
|||
|
||||
// Then add zero or more account headers as necessary
|
||||
if (mAccountListHeaders != null) {
|
||||
int headerCount = mAccountListHeaders.length;
|
||||
final int headerCount = mAccountListHeaders.length;
|
||||
for (int index = 0; index < headerCount; index++) {
|
||||
Header header = mAccountListHeaders[index];
|
||||
if (header != null && header.id != HEADER_ID_UNDEFINED) {
|
||||
|
@ -417,7 +428,7 @@ public class AccountSettings extends PreferenceActivity implements FeedbackEnabl
|
|||
// finally, if debug header is enabled, show it
|
||||
if (mShowDebugMenu) {
|
||||
// setup lightweight header for debugging
|
||||
Header debugHeader = new Header();
|
||||
final Header debugHeader = new Header();
|
||||
debugHeader.title = getText(R.string.debug_title);
|
||||
debugHeader.summary = null;
|
||||
debugHeader.iconRes = 0;
|
||||
|
@ -463,25 +474,24 @@ public class AccountSettings extends PreferenceActivity implements FeedbackEnabl
|
|||
protected Object[] doInBackground(Long... params) {
|
||||
Header[] result = null;
|
||||
Boolean deletingAccountFound = false;
|
||||
long deletingAccountId = params[0];
|
||||
final long deletingAccountId = params[0];
|
||||
|
||||
Cursor c = getContentResolver().query(
|
||||
Account.CONTENT_URI,
|
||||
Account.CONTENT_PROJECTION, null, null, null);
|
||||
try {
|
||||
int index = 0;
|
||||
int headerCount = c.getCount();
|
||||
result = new Header[headerCount];
|
||||
result = new Header[c.getCount()];
|
||||
|
||||
while (c.moveToNext()) {
|
||||
long accountId = c.getLong(Account.CONTENT_ID_COLUMN);
|
||||
final long accountId = c.getLong(Account.CONTENT_ID_COLUMN);
|
||||
if (accountId == deletingAccountId) {
|
||||
deletingAccountFound = true;
|
||||
continue;
|
||||
}
|
||||
String name = c.getString(Account.CONTENT_DISPLAY_NAME_COLUMN);
|
||||
String email = c.getString(Account.CONTENT_EMAIL_ADDRESS_COLUMN);
|
||||
Header newHeader = new Header();
|
||||
final String name = c.getString(Account.CONTENT_DISPLAY_NAME_COLUMN);
|
||||
final String email = c.getString(Account.CONTENT_EMAIL_ADDRESS_COLUMN);
|
||||
final Header newHeader = new Header();
|
||||
newHeader.id = accountId;
|
||||
newHeader.title = name;
|
||||
newHeader.summary = email;
|
||||
|
@ -503,8 +513,8 @@ public class AccountSettings extends PreferenceActivity implements FeedbackEnabl
|
|||
protected void onPostExecute(Object[] result) {
|
||||
if (isCancelled() || result == null) return;
|
||||
// Extract the results
|
||||
Header[] headers = (Header[]) result[0];
|
||||
boolean deletingAccountFound = (Boolean) result[1];
|
||||
final Header[] headers = (Header[]) result[0];
|
||||
final boolean deletingAccountFound = (Boolean) result[1];
|
||||
// report the settings
|
||||
mAccountListHeaders = headers;
|
||||
invalidateHeaders();
|
||||
|
@ -523,14 +533,12 @@ public class AccountSettings extends PreferenceActivity implements FeedbackEnabl
|
|||
@Override
|
||||
public void onHeaderClick(Header header, int position) {
|
||||
// special case when exiting the server settings fragments
|
||||
if (mCurrentFragment instanceof AccountServerBaseFragment) {
|
||||
boolean changed = ((AccountServerBaseFragment)mCurrentFragment).haveSettingsChanged();
|
||||
if (changed) {
|
||||
UnsavedChangesDialogFragment dialogFragment =
|
||||
UnsavedChangesDialogFragment.newInstanceForHeader(position);
|
||||
dialogFragment.show(getFragmentManager(), UnsavedChangesDialogFragment.TAG);
|
||||
return;
|
||||
}
|
||||
if ((mCurrentFragment instanceof AccountServerBaseFragment)
|
||||
&& (((AccountServerBaseFragment)mCurrentFragment).haveSettingsChanged())) {
|
||||
UnsavedChangesDialogFragment dialogFragment =
|
||||
UnsavedChangesDialogFragment.newInstanceForHeader(position);
|
||||
dialogFragment.show(getFragmentManager(), UnsavedChangesDialogFragment.TAG);
|
||||
return;
|
||||
}
|
||||
|
||||
// Secret keys: Click 10x to enable debug settings
|
||||
|
@ -557,8 +565,7 @@ public class AccountSettings extends PreferenceActivity implements FeedbackEnabl
|
|||
mCurrentFragment = null;
|
||||
// Ensure the UI visually shows the correct header selected
|
||||
setSelection(position);
|
||||
Header header = mGeneratedHeaders.get(position);
|
||||
switchToHeader(header);
|
||||
switchToHeader(mGeneratedHeaders.get(position));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -575,10 +582,10 @@ public class AccountSettings extends PreferenceActivity implements FeedbackEnabl
|
|||
super.onAttachFragment(f);
|
||||
|
||||
if (f instanceof AccountSettingsFragment) {
|
||||
AccountSettingsFragment asf = (AccountSettingsFragment) f;
|
||||
final AccountSettingsFragment asf = (AccountSettingsFragment) f;
|
||||
asf.setCallback(mAccountSettingsFragmentCallback);
|
||||
} else if (f instanceof AccountServerBaseFragment) {
|
||||
AccountServerBaseFragment asbf = (AccountServerBaseFragment) f;
|
||||
final AccountServerBaseFragment asbf = (AccountServerBaseFragment) f;
|
||||
asbf.setCallback(mAccountServerSettingsFragmentCallback);
|
||||
} else {
|
||||
// Possibly uninteresting fragment, such as a dialog.
|
||||
|
@ -638,7 +645,7 @@ public class AccountSettings extends PreferenceActivity implements FeedbackEnabl
|
|||
* simply does a "back" to exit the settings screen.
|
||||
*/
|
||||
@Override
|
||||
public void onCheckSettingsComplete(int result, int setupMode) {
|
||||
public void onCheckSettingsComplete(int result, SetupData setupData) {
|
||||
if (result == AccountCheckSettingsFragment.CHECK_SETTINGS_OK) {
|
||||
// Settings checked & saved; clear current fragment
|
||||
mCurrentFragment = null;
|
||||
|
@ -669,7 +676,7 @@ public class AccountSettings extends PreferenceActivity implements FeedbackEnabl
|
|||
*/
|
||||
public void onEditQuickResponses(com.android.mail.providers.Account account) {
|
||||
try {
|
||||
Bundle args = new Bundle();
|
||||
final Bundle args = new Bundle(1);
|
||||
args.putParcelable(QUICK_RESPONSE_ACCOUNT_KEY, account);
|
||||
startPreferencePanel(AccountSettingsEditQuickResponsesFragment.class.getName(), args,
|
||||
R.string.account_settings_edit_quick_responses_label, null, null, 0);
|
||||
|
@ -683,10 +690,11 @@ public class AccountSettings extends PreferenceActivity implements FeedbackEnabl
|
|||
*/
|
||||
public void onIncomingSettings(Account account) {
|
||||
try {
|
||||
SetupData.init(SetupData.FLOW_MODE_EDIT, account);
|
||||
startPreferencePanel(AccountSetupIncomingFragment.class.getName(),
|
||||
AccountSetupIncomingFragment.getSettingsModeArgs(),
|
||||
R.string.account_settings_incoming_label, null, null, 0);
|
||||
mSetupData = new SetupData(SetupData.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
|
||||
startPreferenceFragment(f, true);
|
||||
} catch (Exception e) {
|
||||
LogUtils.d(Logging.LOG_TAG, "Error while trying to invoke store settings.", e);
|
||||
}
|
||||
|
@ -699,18 +707,11 @@ public class AccountSettings extends PreferenceActivity implements FeedbackEnabl
|
|||
*/
|
||||
public void onOutgoingSettings(Account account) {
|
||||
try {
|
||||
Sender sender = Sender.getInstance(getApplication(), account);
|
||||
if (sender != null) {
|
||||
Class<? extends android.app.Activity> setting = sender.getSettingActivityClass();
|
||||
if (setting != null) {
|
||||
SetupData.init(SetupData.FLOW_MODE_EDIT, account);
|
||||
if (setting.equals(AccountSetupOutgoing.class)) {
|
||||
startPreferencePanel(AccountSetupOutgoingFragment.class.getName(),
|
||||
AccountSetupOutgoingFragment.getSettingsModeArgs(),
|
||||
R.string.account_settings_outgoing_label, null, null, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
mSetupData = new SetupData(SetupData.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
|
||||
startPreferenceFragment(f, true);
|
||||
} catch (Exception e) {
|
||||
LogUtils.d(Logging.LOG_TAG, "Error while trying to invoke sender settings.", e);
|
||||
}
|
||||
|
@ -724,7 +725,7 @@ public class AccountSettings extends PreferenceActivity implements FeedbackEnabl
|
|||
new Thread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
Uri uri = EmailProvider.uiUri("uiaccount", account.mId);
|
||||
final Uri uri = EmailProvider.uiUri("uiaccount", account.mId);
|
||||
getContentResolver().delete(uri, null, null);
|
||||
}}).start();
|
||||
|
||||
|
@ -732,7 +733,7 @@ public class AccountSettings extends PreferenceActivity implements FeedbackEnabl
|
|||
// Then update the UI as appropriate:
|
||||
// If single pane, return to the header list. If multi, rebuild header list
|
||||
if (onIsMultiPane()) {
|
||||
Header prefsHeader = getAppPreferencesHeader();
|
||||
final Header prefsHeader = getAppPreferencesHeader();
|
||||
this.switchToHeader(prefsHeader.fragment, prefsHeader.fragmentArguments);
|
||||
mDeletingAccountId = account.mId;
|
||||
updateAccounts();
|
||||
|
@ -752,9 +753,9 @@ public class AccountSettings extends PreferenceActivity implements FeedbackEnabl
|
|||
|
||||
@Override
|
||||
protected Long doInBackground(Intent... params) {
|
||||
Intent intent = params[0];
|
||||
final Intent intent = params[0];
|
||||
android.accounts.Account acct =
|
||||
(android.accounts.Account) intent.getParcelableExtra(EXTRA_ACCOUNT_MANAGER_ACCOUNT);
|
||||
intent.getParcelableExtra(EXTRA_ACCOUNT_MANAGER_ACCOUNT);
|
||||
return Utility.getFirstRowLong(AccountSettings.this, Account.CONTENT_URI,
|
||||
Account.ID_PROJECTION, SELECTION_ACCOUNT_EMAIL_ADDRESS,
|
||||
new String[] {acct.name}, null, Account.ID_PROJECTION_COLUMN, -1L);
|
||||
|
@ -785,8 +786,8 @@ public class AccountSettings extends PreferenceActivity implements FeedbackEnabl
|
|||
* must be a valid header index although there is no error checking.
|
||||
*/
|
||||
public static UnsavedChangesDialogFragment newInstanceForHeader(int position) {
|
||||
UnsavedChangesDialogFragment f = new UnsavedChangesDialogFragment();
|
||||
Bundle b = new Bundle();
|
||||
final UnsavedChangesDialogFragment f = new UnsavedChangesDialogFragment();
|
||||
final Bundle b = new Bundle(1);
|
||||
b.putInt(BUNDLE_KEY_HEADER, position);
|
||||
f.setArguments(b);
|
||||
return f;
|
||||
|
@ -797,8 +798,8 @@ public class AccountSettings extends PreferenceActivity implements FeedbackEnabl
|
|||
* {@link #onBackPressed()} defines in which case this may be triggered.
|
||||
*/
|
||||
public static UnsavedChangesDialogFragment newInstanceForBack() {
|
||||
UnsavedChangesDialogFragment f = new UnsavedChangesDialogFragment();
|
||||
Bundle b = new Bundle();
|
||||
final UnsavedChangesDialogFragment f = new UnsavedChangesDialogFragment();
|
||||
final Bundle b = new Bundle(1);
|
||||
b.putBoolean(BUNDLE_KEY_BACK, true);
|
||||
f.setArguments(b);
|
||||
return f;
|
||||
|
@ -854,7 +855,7 @@ public class AccountSettings extends PreferenceActivity implements FeedbackEnabl
|
|||
*/
|
||||
public static LoginWarningDialog newInstance(String accountName, String reason) {
|
||||
final LoginWarningDialog dialog = new LoginWarningDialog();
|
||||
Bundle b = new Bundle();
|
||||
final Bundle b = new Bundle(1);
|
||||
b.putString(BUNDLE_KEY_ACCOUNT_NAME, accountName);
|
||||
dialog.setArguments(b);
|
||||
dialog.mReason = reason;
|
||||
|
@ -872,17 +873,17 @@ public class AccountSettings extends PreferenceActivity implements FeedbackEnabl
|
|||
b.setIconAttribute(android.R.attr.alertDialogIcon);
|
||||
if (mReason != null) {
|
||||
final TextView message = new TextView(context);
|
||||
String alert = res.getString(
|
||||
final String alert = res.getString(
|
||||
R.string.account_settings_login_dialog_reason_fmt, accountName, mReason);
|
||||
SpannableString spannableAlertString = new SpannableString(alert);
|
||||
Linkify.addLinks(spannableAlertString, Linkify.WEB_URLS);
|
||||
message.setText(spannableAlertString);
|
||||
// There must be a better way than specifying size/padding this way
|
||||
// It does work and look right, though
|
||||
int textSize = res.getDimensionPixelSize(R.dimen.dialog_text_size);
|
||||
final int textSize = res.getDimensionPixelSize(R.dimen.dialog_text_size);
|
||||
message.setTextSize(textSize);
|
||||
int paddingLeft = res.getDimensionPixelSize(R.dimen.dialog_padding_left);
|
||||
int paddingOther = res.getDimensionPixelSize(R.dimen.dialog_padding_other);
|
||||
final int paddingLeft = res.getDimensionPixelSize(R.dimen.dialog_padding_left);
|
||||
final int paddingOther = res.getDimensionPixelSize(R.dimen.dialog_padding_other);
|
||||
message.setPadding(paddingLeft, paddingOther, paddingOther, paddingOther);
|
||||
message.setMovementMethod(LinkMovementMethod.getInstance());
|
||||
b.setView(message);
|
||||
|
@ -908,4 +909,14 @@ public class AccountSettings extends PreferenceActivity implements FeedbackEnabl
|
|||
public Context getActivityContext() {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SetupData getSetupData() {
|
||||
return mSetupData;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setSetupData(SetupData setupData) {
|
||||
mSetupData = setupData;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -25,21 +25,43 @@ 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 {
|
||||
public class AccountSetupActivity extends Activity implements SetupData.SetupDataContainer {
|
||||
private static final boolean DEBUG_SETUP_FLOWS = false; // Don't check in set to true
|
||||
protected SetupData mSetupData;
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
SetupData.restore(savedInstanceState);
|
||||
if (savedInstanceState != null) {
|
||||
mSetupData = savedInstanceState.getParcelable(SetupData.EXTRA_SETUP_DATA);
|
||||
} else {
|
||||
final Bundle b = getIntent().getExtras();
|
||||
if (b != null) {
|
||||
mSetupData = b.getParcelable(SetupData.EXTRA_SETUP_DATA);
|
||||
}
|
||||
}
|
||||
if (mSetupData == null) {
|
||||
mSetupData = new SetupData();
|
||||
}
|
||||
|
||||
super.onCreate(savedInstanceState);
|
||||
if (DEBUG_SETUP_FLOWS) {
|
||||
LogUtils.d(getClass().getName(), SetupData.debugString());
|
||||
LogUtils.d(getClass().getName(), mSetupData.debugString());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSaveInstanceState(Bundle outState) {
|
||||
super.onSaveInstanceState(outState);
|
||||
SetupData.save(outState);
|
||||
outState.putParcelable(SetupData.EXTRA_SETUP_DATA, mSetupData);
|
||||
}
|
||||
|
||||
@Override
|
||||
public SetupData getSetupData() {
|
||||
return mSetupData;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setSetupData(SetupData setupData) {
|
||||
mSetupData = setupData;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -107,7 +107,6 @@ public class AccountSetupBasics extends AccountSetupActivity
|
|||
private static final Boolean DEBUG_ALLOW_NON_TEST_HARNESS_CREATION = false;
|
||||
|
||||
private static final String STATE_KEY_PROVIDER = "AccountSetupBasics.provider";
|
||||
private static final String STATE_KEY_SETUP_DATA = "AccountSetupBasics.setupData";
|
||||
|
||||
// Support for UI
|
||||
private EditText mEmailView;
|
||||
|
@ -154,7 +153,7 @@ 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)
|
||||
SetupData.init(SetupData.FLOW_MODE_RETURN_TO_CALLER);
|
||||
i.putExtra(SetupData.EXTRA_SETUP_DATA, new SetupData(SetupData.FLOW_MODE_RETURN_TO_CALLER));
|
||||
i.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
|
||||
fromActivity.startActivity(i);
|
||||
}
|
||||
|
@ -166,7 +165,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
|
||||
SetupData.init(SetupData.FLOW_MODE_RETURN_NO_ACCOUNTS_RESULT);
|
||||
i.putExtra(SetupData.EXTRA_SETUP_DATA,
|
||||
new SetupData(SetupData.FLOW_MODE_RETURN_NO_ACCOUNTS_RESULT));
|
||||
i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
|
||||
fromActivity.startActivity(i);
|
||||
}
|
||||
|
@ -175,7 +175,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
|
||||
SetupData.init(SetupData.FLOW_MODE_RETURN_TO_MESSAGE_LIST, account);
|
||||
i.putExtra(SetupData.EXTRA_SETUP_DATA,
|
||||
new SetupData(SetupData.FLOW_MODE_RETURN_TO_MESSAGE_LIST, account));
|
||||
i.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
|
||||
fromActivity.startActivity(i);
|
||||
}
|
||||
|
@ -190,24 +191,19 @@ public class AccountSetupBasics extends AccountSetupActivity
|
|||
final Intent intent = getIntent();
|
||||
final String action = intent.getAction();
|
||||
|
||||
// See if we have SetupData to restore; if so, use it
|
||||
final SetupData intentData = (SetupData) ((savedInstanceState != null)
|
||||
? savedInstanceState.getParcelable(STATE_KEY_SETUP_DATA)
|
||||
: null);
|
||||
if (intentData != null) {
|
||||
SetupData.init(intentData);
|
||||
} else if (ServiceProxy.getIntentStringForEmailPackage(
|
||||
if (ServiceProxy.getIntentStringForEmailPackage(
|
||||
this, ACTION_CREATE_ACCOUNT).equals(action)) {
|
||||
SetupData.init(SetupData.FLOW_MODE_FORCE_CREATE);
|
||||
mSetupData = new SetupData(SetupData.FLOW_MODE_FORCE_CREATE);
|
||||
} else {
|
||||
final int intentFlowMode =
|
||||
intent.getIntExtra(EXTRA_FLOW_MODE, SetupData.FLOW_MODE_UNSPECIFIED);
|
||||
if (intentFlowMode != SetupData.FLOW_MODE_UNSPECIFIED) {
|
||||
SetupData.init(intentFlowMode, intent.getStringExtra(EXTRA_FLOW_ACCOUNT_TYPE));
|
||||
mSetupData = new SetupData(intentFlowMode,
|
||||
intent.getStringExtra(EXTRA_FLOW_ACCOUNT_TYPE));
|
||||
}
|
||||
}
|
||||
|
||||
final int flowMode = SetupData.getFlowMode();
|
||||
final int flowMode = mSetupData.getFlowMode();
|
||||
if (flowMode == SetupData.FLOW_MODE_RETURN_TO_CALLER) {
|
||||
// Return to the caller who initiated account creation
|
||||
finish();
|
||||
|
@ -221,7 +217,7 @@ public class AccountSetupBasics extends AccountSetupActivity
|
|||
finish();
|
||||
return;
|
||||
} else if (flowMode == SetupData.FLOW_MODE_RETURN_TO_MESSAGE_LIST) {
|
||||
final Account account = SetupData.getAccount();
|
||||
final Account account = mSetupData.getAccount();
|
||||
if (account != null && account.mId >= 0) {
|
||||
// Show the message list for the new account
|
||||
//***
|
||||
|
@ -253,7 +249,7 @@ public class AccountSetupBasics extends AccountSetupActivity
|
|||
// Set aside incoming AccountAuthenticatorResponse, if there was any
|
||||
final AccountAuthenticatorResponse authenticatorResponse =
|
||||
getIntent().getParcelableExtra(AccountManager.KEY_ACCOUNT_AUTHENTICATOR_RESPONSE);
|
||||
SetupData.setAccountAuthenticatorResponse(authenticatorResponse);
|
||||
mSetupData.setAccountAuthenticatorResponse(authenticatorResponse);
|
||||
if (authenticatorResponse != null) {
|
||||
// When this Activity is called as part of account authentification flow,
|
||||
// we are responsible for eventually reporting the result (success or failure) to
|
||||
|
@ -264,20 +260,20 @@ public class AccountSetupBasics extends AccountSetupActivity
|
|||
}
|
||||
|
||||
// Load fields, but only once
|
||||
final String userName = SetupData.getUsername();
|
||||
final String userName = mSetupData.getUsername();
|
||||
if (userName != null) {
|
||||
mEmailView.setText(userName);
|
||||
SetupData.setUsername(null);
|
||||
mSetupData.setUsername(null);
|
||||
}
|
||||
final String password = SetupData.getPassword();
|
||||
final String password = mSetupData.getPassword();
|
||||
if (userName != null) {
|
||||
mPasswordView.setText(password);
|
||||
SetupData.setPassword(null);
|
||||
mSetupData.setPassword(null);
|
||||
}
|
||||
|
||||
// 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 (SetupData.getFlowMode() == SetupData.FLOW_MODE_FORCE_CREATE) {
|
||||
if (mSetupData.getFlowMode() == SetupData.FLOW_MODE_FORCE_CREATE) {
|
||||
if (!DEBUG_ALLOW_NON_TEST_HARNESS_CREATION &&
|
||||
!ActivityManager.isRunningInTestHarness()) {
|
||||
LogUtils.e(Logging.LOG_TAG,
|
||||
|
@ -297,7 +293,8 @@ public class AccountSetupBasics extends AccountSetupActivity
|
|||
return;
|
||||
}
|
||||
forceCreateAccount(email, user, incoming, outgoing);
|
||||
onCheckSettingsComplete(AccountCheckSettingsFragment.CHECK_SETTINGS_OK); // calls finish
|
||||
// calls finish
|
||||
onCheckSettingsComplete(AccountCheckSettingsFragment.CHECK_SETTINGS_OK, mSetupData);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -329,10 +326,10 @@ public class AccountSetupBasics extends AccountSetupActivity
|
|||
// then we assume that we're giving up (for any reason) - report failure.
|
||||
if (mReportAccountAuthenticatorError) {
|
||||
final AccountAuthenticatorResponse authenticatorResponse =
|
||||
SetupData.getAccountAuthenticatorResponse();
|
||||
mSetupData.getAccountAuthenticatorResponse();
|
||||
if (authenticatorResponse != null) {
|
||||
authenticatorResponse.onError(AccountManager.ERROR_CODE_CANCELED, "canceled");
|
||||
SetupData.setAccountAuthenticatorResponse(null);
|
||||
mSetupData.setAccountAuthenticatorResponse(null);
|
||||
}
|
||||
}
|
||||
super.finish();
|
||||
|
@ -344,8 +341,6 @@ public class AccountSetupBasics extends AccountSetupActivity
|
|||
if (mProvider != null) {
|
||||
outState.putSerializable(STATE_KEY_PROVIDER, mProvider);
|
||||
}
|
||||
// Save the current state of our SetupData so we don't re-init it
|
||||
outState.putParcelable(STATE_KEY_SETUP_DATA, SetupData.getInstance());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -445,7 +440,7 @@ public class AccountSetupBasics extends AccountSetupActivity
|
|||
try {
|
||||
mProvider.expandTemplates(email);
|
||||
|
||||
final Account account = SetupData.getAccount();
|
||||
final Account account = mSetupData.getAccount();
|
||||
final HostAuth recvAuth = account.getOrCreateHostAuthRecv(this);
|
||||
HostAuth.setHostAuthFromString(recvAuth, mProvider.incomingUri);
|
||||
|
||||
|
@ -568,7 +563,7 @@ public class AccountSetupBasics extends AccountSetupActivity
|
|||
return;
|
||||
}
|
||||
|
||||
final Account account = SetupData.getAccount();
|
||||
final Account account = mSetupData.getAccount();
|
||||
final HostAuth recvAuth = account.getOrCreateHostAuthRecv(this);
|
||||
recvAuth.setLogin(user, password);
|
||||
recvAuth.setConnection(null, domain, HostAuth.PORT_UNKNOWN, HostAuth.FLAG_NONE);
|
||||
|
@ -579,8 +574,8 @@ public class AccountSetupBasics extends AccountSetupActivity
|
|||
|
||||
populateSetupData(getOwnerName(), email);
|
||||
|
||||
SetupData.setAllowAutodiscover(allowAutoDiscover);
|
||||
AccountSetupType.actionSelectAccountType(this);
|
||||
mSetupData.setAllowAutodiscover(allowAutoDiscover);
|
||||
AccountSetupType.actionSelectAccountType(this, mSetupData);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -595,7 +590,7 @@ public class AccountSetupBasics extends AccountSetupActivity
|
|||
* @param outgoing The URI-style string defining the outgoing account
|
||||
*/
|
||||
private void forceCreateAccount(String email, String user, String incoming, String outgoing) {
|
||||
Account account = SetupData.getAccount();
|
||||
Account account = mSetupData.getAccount();
|
||||
try {
|
||||
final HostAuth recvAuth = account.getOrCreateHostAuthRecv(this);
|
||||
HostAuth.setHostAuthFromString(recvAuth, incoming);
|
||||
|
@ -626,7 +621,7 @@ public class AccountSetupBasics extends AccountSetupActivity
|
|||
* Populate SetupData's account with complete setup info.
|
||||
*/
|
||||
private void populateSetupData(String senderName, String senderEmail) {
|
||||
final Account account = SetupData.getAccount();
|
||||
final Account account = mSetupData.getAccount();
|
||||
account.setSenderName(senderName);
|
||||
account.setEmailAddress(senderEmail);
|
||||
account.setDisplayName(senderEmail);
|
||||
|
@ -642,9 +637,10 @@ public class AccountSetupBasics extends AccountSetupActivity
|
|||
* so we inhibit reporting any error back to the Account manager.
|
||||
*/
|
||||
@Override
|
||||
public void onCheckSettingsComplete(int result) {
|
||||
public void onCheckSettingsComplete(int result, SetupData setupData) {
|
||||
mSetupData = setupData;
|
||||
if (result == AccountCheckSettingsFragment.CHECK_SETTINGS_OK) {
|
||||
AccountSetupOptions.actionOptions(this);
|
||||
AccountSetupOptions.actionOptions(this, mSetupData);
|
||||
mReportAccountAuthenticatorError = false;
|
||||
finish();
|
||||
}
|
||||
|
@ -652,10 +648,10 @@ public class AccountSetupBasics extends AccountSetupActivity
|
|||
|
||||
/**
|
||||
* Implements AccountCheckSettingsFragment.Callbacks
|
||||
* This is overridden only by AccountSetupExchange
|
||||
* This is overridden only by AccountSetupIncoming
|
||||
*/
|
||||
@Override
|
||||
public void onAutoDiscoverComplete(int result) {
|
||||
public void onAutoDiscoverComplete(int result, SetupData setupData) {
|
||||
throw new IllegalStateException();
|
||||
}
|
||||
|
||||
|
|
|
@ -52,18 +52,11 @@ public class AccountSetupIncoming extends AccountSetupActivity
|
|||
"AccountSetupExchange.StartedAutoDiscovery";
|
||||
|
||||
// Extras for AccountSetupIncoming intent
|
||||
private final static String FLOW_MODE_EXTRA = "flow-mode-extra";
|
||||
private final static String ACCOUNT_EXTRA = "account-extra";
|
||||
|
||||
public static void actionIncomingSettings(Activity fromActivity, int mode, Account account) {
|
||||
SetupData.setFlowMode(mode);
|
||||
SetupData.setAccount(account);
|
||||
|
||||
public static void actionIncomingSettings(Activity fromActivity, SetupData 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(FLOW_MODE_EXTRA, mode);
|
||||
intent.putExtra(ACCOUNT_EXTRA, account);
|
||||
|
||||
intent.putExtra(SetupData.EXTRA_SETUP_DATA, setupData);
|
||||
fromActivity.startActivity(intent);
|
||||
}
|
||||
|
||||
|
@ -72,16 +65,7 @@ public class AccountSetupIncoming extends AccountSetupActivity
|
|||
super.onCreate(savedInstanceState);
|
||||
ActivityHelper.debugSetWindowFlags(this);
|
||||
|
||||
final Account dataAccount = SetupData.getAccount();
|
||||
if (dataAccount == null) {
|
||||
// The account is not set in the SetupData. This probably means that the Email
|
||||
// process was killed, and we are in the process of restoring the activity
|
||||
final Bundle extras = getIntent().getExtras();
|
||||
SetupData.setFlowMode(extras.getInt(FLOW_MODE_EXTRA));
|
||||
SetupData.setAccount((Account)extras.getParcelable(ACCOUNT_EXTRA));
|
||||
}
|
||||
|
||||
HostAuth hostAuth = SetupData.getAccount().mHostAuthRecv;
|
||||
final HostAuth hostAuth = mSetupData.getAccount().mHostAuthRecv;
|
||||
mServiceInfo = EmailServiceUtils.getServiceInfo(this, hostAuth.mProtocol);
|
||||
|
||||
setContentView(R.layout.account_setup_incoming);
|
||||
|
@ -107,7 +91,7 @@ public class AccountSetupIncoming extends AccountSetupActivity
|
|||
}
|
||||
|
||||
// If we've got a default prefix for this protocol, use it
|
||||
String prefix = mServiceInfo.inferPrefix;
|
||||
final String prefix = mServiceInfo.inferPrefix;
|
||||
if (prefix != null && !hostAuth.mAddress.startsWith(prefix + ".")) {
|
||||
hostAuth.mAddress = prefix + "." + hostAuth.mAddress;
|
||||
}
|
||||
|
@ -148,26 +132,22 @@ public class AccountSetupIncoming extends AccountSetupActivity
|
|||
// this prevents repeating.
|
||||
mStartedAutoDiscovery = true;
|
||||
|
||||
if (!SetupData.isAllowAutodiscover()) {
|
||||
if (!mSetupData.isAllowAutodiscover()) {
|
||||
return;
|
||||
}
|
||||
|
||||
Account account = SetupData.getAccount();
|
||||
final Account account = mSetupData.getAccount();
|
||||
// If we've got a username and password and we're NOT editing, try autodiscover
|
||||
String username = account.mHostAuthRecv.mLogin;
|
||||
String password = account.mHostAuthRecv.mPassword;
|
||||
final String username = account.mHostAuthRecv.mLogin;
|
||||
final String password = account.mHostAuthRecv.mPassword;
|
||||
if (username != null && password != null) {
|
||||
onProceedNext(SetupData.CHECK_AUTODISCOVER, mFragment);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements AccountCheckSettingsFragment.Callbacks
|
||||
*
|
||||
* @param result Currently auth failed (bail), ok (move to next), or no data (stay here)
|
||||
*/
|
||||
public void onAutoDiscoverComplete(int result) {
|
||||
public void onAutoDiscoverComplete(int result, SetupData setupData) {
|
||||
// If authentication failed, exit immediately (to re-enter credentials)
|
||||
mSetupData = setupData;
|
||||
if (result == AccountCheckSettingsFragment.AUTODISCOVER_AUTHENTICATION) {
|
||||
finish();
|
||||
return;
|
||||
|
@ -210,13 +190,13 @@ public class AccountSetupIncoming extends AccountSetupActivity
|
|||
* If the checked settings are OK, proceed to outgoing settings screen
|
||||
*/
|
||||
@Override
|
||||
public void onCheckSettingsComplete(int result, int setupMode) {
|
||||
public void onCheckSettingsComplete(int result, SetupData setupData) {
|
||||
mSetupData = setupData;
|
||||
if (result == AccountCheckSettingsFragment.CHECK_SETTINGS_OK) {
|
||||
if (mServiceInfo.usesSmtp) {
|
||||
AccountSetupOutgoing.actionOutgoingSettings(this, SetupData.getFlowMode(),
|
||||
SetupData.getAccount());
|
||||
AccountSetupOutgoing.actionOutgoingSettings(this, mSetupData);
|
||||
} else {
|
||||
AccountSetupOptions.actionOptions(this);
|
||||
AccountSetupOptions.actionOptions(this, mSetupData);
|
||||
finish();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -114,15 +114,11 @@ public class AccountSetupIncomingFragment extends AccountServerBaseFragment
|
|||
if (Logging.DEBUG_LIFECYCLE && MailActivityEmail.DEBUG) {
|
||||
LogUtils.d(Logging.LOG_TAG, "AccountSetupIncomingFragment onCreateView");
|
||||
}
|
||||
int layoutId = mSettingsMode
|
||||
final int layoutId = mSettingsMode
|
||||
? R.layout.account_settings_incoming_fragment
|
||||
: R.layout.account_setup_incoming_fragment;
|
||||
|
||||
View view = inflater.inflate(layoutId, container, false);
|
||||
Context context = getActivity();
|
||||
|
||||
final HostAuth recvAuth = SetupData.getAccount().mHostAuthRecv;
|
||||
mServiceInfo = EmailServiceUtils.getServiceInfo(mContext, recvAuth.mProtocol);
|
||||
final View view = inflater.inflate(layoutId, container, false);
|
||||
|
||||
mUsernameView = UiUtilities.getView(view, R.id.account_username);
|
||||
mPasswordView = UiUtilities.getView(view, R.id.account_password);
|
||||
|
@ -137,48 +133,6 @@ public class AccountSetupIncomingFragment extends AccountServerBaseFragment
|
|||
mImapPathPrefixView = UiUtilities.getView(view, R.id.imap_path_prefix);
|
||||
mClientCertificateSelector = UiUtilities.getView(view, R.id.client_certificate_selector);
|
||||
|
||||
// Set up security type spinner
|
||||
ArrayList<SpinnerOption> securityTypes = new ArrayList<SpinnerOption>();
|
||||
securityTypes.add(
|
||||
new SpinnerOption(HostAuth.FLAG_NONE, context.getString(
|
||||
R.string.account_setup_incoming_security_none_label)));
|
||||
securityTypes.add(
|
||||
new SpinnerOption(HostAuth.FLAG_SSL, context.getString(
|
||||
R.string.account_setup_incoming_security_ssl_label)));
|
||||
securityTypes.add(
|
||||
new SpinnerOption(HostAuth.FLAG_SSL | HostAuth.FLAG_TRUST_ALL, context.getString(
|
||||
R.string.account_setup_incoming_security_ssl_trust_certificates_label)));
|
||||
if (mServiceInfo.offerTls) {
|
||||
securityTypes.add(
|
||||
new SpinnerOption(HostAuth.FLAG_TLS, context.getString(
|
||||
R.string.account_setup_incoming_security_tls_label)));
|
||||
securityTypes.add(
|
||||
new SpinnerOption(HostAuth.FLAG_TLS | HostAuth.FLAG_TRUST_ALL,
|
||||
context.getString(
|
||||
R.string.account_setup_incoming_security_tls_trust_certificates_label)));
|
||||
}
|
||||
ArrayAdapter<SpinnerOption> securityTypesAdapter = new ArrayAdapter<SpinnerOption>(
|
||||
context, android.R.layout.simple_spinner_item, securityTypes);
|
||||
securityTypesAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
|
||||
mSecurityTypeView.setAdapter(securityTypesAdapter);
|
||||
|
||||
if (mServiceInfo.offerLocalDeletes) {
|
||||
SpinnerOption deletePolicies[] = {
|
||||
new SpinnerOption(Account.DELETE_POLICY_NEVER,
|
||||
context.getString(
|
||||
R.string.account_setup_incoming_delete_policy_never_label)),
|
||||
new SpinnerOption(Account.DELETE_POLICY_ON_DELETE,
|
||||
context.getString(
|
||||
R.string.account_setup_incoming_delete_policy_delete_label)),
|
||||
};
|
||||
ArrayAdapter<SpinnerOption> deletePoliciesAdapter =
|
||||
new ArrayAdapter<SpinnerOption>(context,
|
||||
android.R.layout.simple_spinner_item, deletePolicies);
|
||||
deletePoliciesAdapter.setDropDownViewResource(
|
||||
android.R.layout.simple_spinner_dropdown_item);
|
||||
mDeletePolicyView.setAdapter(deletePoliciesAdapter);
|
||||
}
|
||||
|
||||
// Updates the port when the user changes the security type. This allows
|
||||
// us to show a reasonable default which the user can change.
|
||||
mSecurityTypeView.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
|
||||
|
@ -192,7 +146,7 @@ public class AccountSetupIncomingFragment extends AccountServerBaseFragment
|
|||
});
|
||||
|
||||
// After any text edits, call validateFields() which enables or disables the Next button
|
||||
TextWatcher validationTextWatcher = new TextWatcher() {
|
||||
final TextWatcher validationTextWatcher = new TextWatcher() {
|
||||
@Override
|
||||
public void afterTextChanged(Editable s) {
|
||||
validateFields();
|
||||
|
@ -229,6 +183,54 @@ public class AccountSetupIncomingFragment extends AccountServerBaseFragment
|
|||
}
|
||||
super.onActivityCreated(savedInstanceState);
|
||||
mClientCertificateSelector.setHostActivity(this);
|
||||
|
||||
final Context context = getActivity();
|
||||
final SetupData.SetupDataContainer container = (SetupData.SetupDataContainer) context;
|
||||
mSetupData = container.getSetupData();
|
||||
|
||||
final HostAuth recvAuth = mSetupData.getAccount().mHostAuthRecv;
|
||||
mServiceInfo = EmailServiceUtils.getServiceInfo(mContext, recvAuth.mProtocol);
|
||||
|
||||
if (mServiceInfo.offerLocalDeletes) {
|
||||
SpinnerOption deletePolicies[] = {
|
||||
new SpinnerOption(Account.DELETE_POLICY_NEVER,
|
||||
context.getString(
|
||||
R.string.account_setup_incoming_delete_policy_never_label)),
|
||||
new SpinnerOption(Account.DELETE_POLICY_ON_DELETE,
|
||||
context.getString(
|
||||
R.string.account_setup_incoming_delete_policy_delete_label)),
|
||||
};
|
||||
ArrayAdapter<SpinnerOption> deletePoliciesAdapter =
|
||||
new ArrayAdapter<SpinnerOption>(context,
|
||||
android.R.layout.simple_spinner_item, deletePolicies);
|
||||
deletePoliciesAdapter.setDropDownViewResource(
|
||||
android.R.layout.simple_spinner_dropdown_item);
|
||||
mDeletePolicyView.setAdapter(deletePoliciesAdapter);
|
||||
}
|
||||
|
||||
// Set up security type spinner
|
||||
ArrayList<SpinnerOption> securityTypes = new ArrayList<SpinnerOption>();
|
||||
securityTypes.add(
|
||||
new SpinnerOption(HostAuth.FLAG_NONE, context.getString(
|
||||
R.string.account_setup_incoming_security_none_label)));
|
||||
securityTypes.add(
|
||||
new SpinnerOption(HostAuth.FLAG_SSL, context.getString(
|
||||
R.string.account_setup_incoming_security_ssl_label)));
|
||||
securityTypes.add(
|
||||
new SpinnerOption(HostAuth.FLAG_SSL | HostAuth.FLAG_TRUST_ALL, context.getString(
|
||||
R.string.account_setup_incoming_security_ssl_trust_certificates_label)));
|
||||
if (mServiceInfo.offerTls) {
|
||||
securityTypes.add(
|
||||
new SpinnerOption(HostAuth.FLAG_TLS, context.getString(
|
||||
R.string.account_setup_incoming_security_tls_label)));
|
||||
securityTypes.add(new SpinnerOption(HostAuth.FLAG_TLS | HostAuth.FLAG_TRUST_ALL,
|
||||
context.getString(R.string
|
||||
.account_setup_incoming_security_tls_trust_certificates_label)));
|
||||
}
|
||||
ArrayAdapter<SpinnerOption> securityTypesAdapter = new ArrayAdapter<SpinnerOption>(
|
||||
context, android.R.layout.simple_spinner_item, securityTypes);
|
||||
securityTypesAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
|
||||
mSecurityTypeView.setAdapter(securityTypesAdapter);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -315,7 +317,7 @@ public class AccountSetupIncomingFragment extends AccountServerBaseFragment
|
|||
* Configure the editor for the account type
|
||||
*/
|
||||
private void configureEditor() {
|
||||
Account account = SetupData.getAccount();
|
||||
final Account account = mSetupData.getAccount();
|
||||
if (account == null || account.mHostAuthRecv == null) {
|
||||
LogUtils.e(Logging.LOG_TAG,
|
||||
"null account or host auth. account null: %b host auth null: %b",
|
||||
|
@ -345,10 +347,10 @@ public class AccountSetupIncomingFragment extends AccountServerBaseFragment
|
|||
private void loadSettings() {
|
||||
if (mLoaded) return;
|
||||
|
||||
Account account = SetupData.getAccount();
|
||||
HostAuth recvAuth = account.getOrCreateHostAuthRecv(mContext);
|
||||
final Account account = mSetupData.getAccount();
|
||||
final HostAuth recvAuth = account.getOrCreateHostAuthRecv(mContext);
|
||||
|
||||
String username = recvAuth.mLogin;
|
||||
final String username = recvAuth.mLogin;
|
||||
if (username != null) {
|
||||
//*** For eas?
|
||||
// Add a backslash to the start of the username, but only if the username has no
|
||||
|
@ -358,7 +360,7 @@ public class AccountSetupIncomingFragment extends AccountServerBaseFragment
|
|||
//}
|
||||
mUsernameView.setText(username);
|
||||
}
|
||||
String password = recvAuth.mPassword;
|
||||
final String password = recvAuth.mPassword;
|
||||
if (password != null) {
|
||||
mPasswordView.setText(password);
|
||||
// Since username is uneditable, focus on the next editable field
|
||||
|
@ -368,7 +370,7 @@ public class AccountSetupIncomingFragment extends AccountServerBaseFragment
|
|||
}
|
||||
|
||||
if (mServiceInfo.offerPrefix) {
|
||||
String prefix = recvAuth.mDomain;
|
||||
final String prefix = recvAuth.mDomain;
|
||||
if (prefix != null && prefix.length() > 0) {
|
||||
mImapPathPrefixView.setText(prefix.substring(1));
|
||||
}
|
||||
|
@ -387,12 +389,12 @@ public class AccountSetupIncomingFragment extends AccountServerBaseFragment
|
|||
}
|
||||
SpinnerOption.setSpinnerOptionValue(mSecurityTypeView, flags);
|
||||
|
||||
String hostname = recvAuth.mAddress;
|
||||
final String hostname = recvAuth.mAddress;
|
||||
if (hostname != null) {
|
||||
mServerView.setText(hostname);
|
||||
}
|
||||
|
||||
int port = recvAuth.mPort;
|
||||
final int port = recvAuth.mPort;
|
||||
if (port != HostAuth.PORT_UNKNOWN) {
|
||||
mPortView.setText(Integer.toString(port));
|
||||
} else {
|
||||
|
@ -409,11 +411,10 @@ public class AccountSetupIncomingFragment extends AccountServerBaseFragment
|
|||
*/
|
||||
private void validateFields() {
|
||||
if (!mLoaded) return;
|
||||
final boolean enabled = !TextUtils.isEmpty(mUsernameView.getText())
|
||||
enableNextButton(!TextUtils.isEmpty(mUsernameView.getText())
|
||||
&& !TextUtils.isEmpty(mPasswordView.getText())
|
||||
&& Utility.isServerNameValid(mServerView)
|
||||
&& Utility.isPortFieldValid(mPortView);
|
||||
enableNextButton(enabled);
|
||||
&& Utility.isPortFieldValid(mPortView));
|
||||
|
||||
mCacheLoginCredential = mUsernameView.getText().toString().trim();
|
||||
|
||||
|
@ -422,19 +423,20 @@ public class AccountSetupIncomingFragment extends AccountServerBaseFragment
|
|||
}
|
||||
|
||||
private int getPortFromSecurityType(boolean useSsl) {
|
||||
EmailServiceInfo info = EmailServiceUtils.getServiceInfo(mContext,
|
||||
SetupData.getAccount().mHostAuthRecv.mProtocol);
|
||||
final EmailServiceInfo info = EmailServiceUtils.getServiceInfo(mContext,
|
||||
mSetupData.getAccount().mHostAuthRecv.mProtocol);
|
||||
return useSsl ? info.portSsl : info.port;
|
||||
}
|
||||
|
||||
private boolean getSslSelected() {
|
||||
int securityType = (Integer)((SpinnerOption)mSecurityTypeView.getSelectedItem()).value;
|
||||
final int securityType =
|
||||
(Integer)((SpinnerOption)mSecurityTypeView.getSelectedItem()).value;
|
||||
return ((securityType & HostAuth.FLAG_SSL) != 0);
|
||||
}
|
||||
|
||||
public void onUseSslChanged(boolean useSsl) {
|
||||
if (mServiceInfo.offerCerts) {
|
||||
int mode = useSsl ? View.VISIBLE : View.GONE;
|
||||
final int mode = useSsl ? View.VISIBLE : View.GONE;
|
||||
mClientCertificateSelector.setVisibility(mode);
|
||||
String deviceId = "";
|
||||
try {
|
||||
|
@ -450,8 +452,8 @@ public class AccountSetupIncomingFragment extends AccountServerBaseFragment
|
|||
}
|
||||
|
||||
private void updatePortFromSecurityType() {
|
||||
boolean sslSelected = getSslSelected();
|
||||
int port = getPortFromSecurityType(sslSelected);
|
||||
final boolean sslSelected = getSslSelected();
|
||||
final int port = getPortFromSecurityType(sslSelected);
|
||||
mPortView.setText(Integer.toString(port));
|
||||
onUseSslChanged(sslSelected);
|
||||
}
|
||||
|
@ -464,7 +466,7 @@ public class AccountSetupIncomingFragment extends AccountServerBaseFragment
|
|||
*/
|
||||
@Override
|
||||
public void saveSettingsAfterEdit() {
|
||||
Account account = SetupData.getAccount();
|
||||
final Account account = mSetupData.getAccount();
|
||||
account.update(mContext, account.toContentValues());
|
||||
account.mHostAuthRecv.update(mContext, account.mHostAuthRecv.toContentValues());
|
||||
// Update the backup (side copy) of the accounts
|
||||
|
@ -476,14 +478,14 @@ public class AccountSetupIncomingFragment extends AccountServerBaseFragment
|
|||
*/
|
||||
@Override
|
||||
public void saveSettingsAfterSetup() {
|
||||
Account account = SetupData.getAccount();
|
||||
HostAuth recvAuth = account.getOrCreateHostAuthRecv(mContext);
|
||||
HostAuth sendAuth = account.getOrCreateHostAuthSend(mContext);
|
||||
final Account account = mSetupData.getAccount();
|
||||
final HostAuth recvAuth = account.getOrCreateHostAuthRecv(mContext);
|
||||
final HostAuth sendAuth = account.getOrCreateHostAuthSend(mContext);
|
||||
|
||||
// Set the username and password for the outgoing settings to the username and
|
||||
// password the user just set for incoming. Use the verified host address to try and
|
||||
// pick a smarter outgoing address.
|
||||
String hostName =
|
||||
final String hostName =
|
||||
AccountSettingsUtils.inferServerName(mContext, recvAuth.mAddress, null, "smtp");
|
||||
sendAuth.setLogin(recvAuth.mLogin, recvAuth.mPassword);
|
||||
sendAuth.setConnection(sendAuth.mProtocol, hostName, sendAuth.mPort, sendAuth.mFlags);
|
||||
|
@ -494,7 +496,7 @@ public class AccountSetupIncomingFragment extends AccountServerBaseFragment
|
|||
*/
|
||||
@Override
|
||||
public void onNext() {
|
||||
Account account = SetupData.getAccount();
|
||||
final Account account = mSetupData.getAccount();
|
||||
|
||||
// Make sure delete policy is an valid option before using it; otherwise, the results are
|
||||
// indeterminate, I suspect...
|
||||
|
@ -503,12 +505,12 @@ public class AccountSetupIncomingFragment extends AccountServerBaseFragment
|
|||
(Integer) ((SpinnerOption) mDeletePolicyView.getSelectedItem()).value);
|
||||
}
|
||||
|
||||
HostAuth recvAuth = account.getOrCreateHostAuthRecv(mContext);
|
||||
String userName = mUsernameView.getText().toString().trim();
|
||||
String userPassword = mPasswordView.getText().toString();
|
||||
final HostAuth recvAuth = account.getOrCreateHostAuthRecv(mContext);
|
||||
final String userName = mUsernameView.getText().toString().trim();
|
||||
final String userPassword = mPasswordView.getText().toString();
|
||||
recvAuth.setLogin(userName, userPassword);
|
||||
|
||||
String serverAddress = mServerView.getText().toString().trim();
|
||||
final String serverAddress = mServerView.getText().toString().trim();
|
||||
int serverPort;
|
||||
try {
|
||||
serverPort = Integer.parseInt(mPortView.getText().toString().trim());
|
||||
|
@ -516,10 +518,11 @@ public class AccountSetupIncomingFragment extends AccountServerBaseFragment
|
|||
serverPort = getPortFromSecurityType(getSslSelected());
|
||||
LogUtils.d(Logging.LOG_TAG, "Non-integer server port; using '" + serverPort + "'");
|
||||
}
|
||||
int securityType = (Integer) ((SpinnerOption) mSecurityTypeView.getSelectedItem()).value;
|
||||
final int securityType =
|
||||
(Integer) ((SpinnerOption) mSecurityTypeView.getSelectedItem()).value;
|
||||
recvAuth.setConnection(mBaseScheme, serverAddress, serverPort, securityType);
|
||||
if (mServiceInfo.offerPrefix) {
|
||||
String prefix = mImapPathPrefixView.getText().toString().trim();
|
||||
final String prefix = mImapPathPrefixView.getText().toString().trim();
|
||||
recvAuth.mDomain = TextUtils.isEmpty(prefix) ? null : ("/" + prefix);
|
||||
} else {
|
||||
recvAuth.mDomain = null;
|
||||
|
@ -533,13 +536,15 @@ public class AccountSetupIncomingFragment extends AccountServerBaseFragment
|
|||
|
||||
@Override
|
||||
public boolean haveSettingsChanged() {
|
||||
boolean deletePolicyChanged = false;
|
||||
final boolean deletePolicyChanged;
|
||||
|
||||
// Only verify the delete policy if the control is visible (i.e. is a pop3 account)
|
||||
if (mDeletePolicyView.getVisibility() == View.VISIBLE) {
|
||||
int newDeletePolicy =
|
||||
(Integer)((SpinnerOption)mDeletePolicyView.getSelectedItem()).value;
|
||||
deletePolicyChanged = mLoadedDeletePolicy != newDeletePolicy;
|
||||
} else {
|
||||
deletePolicyChanged = false;
|
||||
}
|
||||
|
||||
return deletePolicyChanged || super.haveSettingsChanged();
|
||||
|
@ -549,14 +554,15 @@ public class AccountSetupIncomingFragment extends AccountServerBaseFragment
|
|||
* Implements AccountCheckSettingsFragment.Callbacks
|
||||
*/
|
||||
@Override
|
||||
public void onAutoDiscoverComplete(int result) {
|
||||
AccountSetupIncoming activity = (AccountSetupIncoming) getActivity();
|
||||
activity.onAutoDiscoverComplete(result);
|
||||
public void onAutoDiscoverComplete(int result, SetupData setupData) {
|
||||
mSetupData = setupData;
|
||||
final AccountSetupIncoming activity = (AccountSetupIncoming) getActivity();
|
||||
activity.onAutoDiscoverComplete(result, setupData);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCertificateRequested() {
|
||||
Intent intent = new Intent(CertificateRequestor.ACTION_REQUEST_CERT);
|
||||
final Intent intent = new Intent(CertificateRequestor.ACTION_REQUEST_CERT);
|
||||
intent.setData(Uri.parse("eas://com.android.emailcommon/certrequest"));
|
||||
startActivityForResult(intent, CERTIFICATE_REQUEST);
|
||||
}
|
||||
|
@ -564,7 +570,7 @@ public class AccountSetupIncomingFragment extends AccountServerBaseFragment
|
|||
@Override
|
||||
public void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||
if (requestCode == CERTIFICATE_REQUEST && resultCode == Activity.RESULT_OK) {
|
||||
String certAlias = data.getStringExtra(CertificateRequestor.RESULT_ALIAS);
|
||||
final String certAlias = data.getStringExtra(CertificateRequestor.RESULT_ALIAS);
|
||||
if (certAlias != null) {
|
||||
mClientCertificateSelector.setCertificate(certAlias);
|
||||
}
|
||||
|
|
|
@ -48,7 +48,7 @@ import com.android.emailcommon.utility.Utility;
|
|||
/**
|
||||
* Final screen of setup process. Collect account nickname and/or username.
|
||||
*/
|
||||
public class AccountSetupNames extends AccountSetupActivity implements OnClickListener {
|
||||
public class AccountSetupNames extends AccountSetupActivity {
|
||||
private static final int REQUEST_SECURITY = 0;
|
||||
|
||||
private static final Uri PROFILE_URI = Profile.CONTENT_URI;
|
||||
|
@ -58,8 +58,10 @@ public class AccountSetupNames extends AccountSetupActivity implements OnClickLi
|
|||
private Button mNextButton;
|
||||
private boolean mRequiresName = true;
|
||||
|
||||
public static void actionSetNames(Activity fromActivity) {
|
||||
fromActivity.startActivity(new ForwardingIntent(fromActivity, AccountSetupNames.class));
|
||||
public static void actionSetNames(Activity fromActivity, SetupData setupData) {
|
||||
ForwardingIntent intent = new ForwardingIntent(fromActivity, AccountSetupNames.class);
|
||||
intent.putExtra(SetupData.EXTRA_SETUP_DATA, setupData);
|
||||
fromActivity.startActivity(intent);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -69,11 +71,16 @@ public class AccountSetupNames extends AccountSetupActivity implements OnClickLi
|
|||
setContentView(R.layout.account_setup_names);
|
||||
mDescription = UiUtilities.getView(this, R.id.account_description);
|
||||
mName = UiUtilities.getView(this, R.id.account_name);
|
||||
View accountNameLabel = UiUtilities.getView(this, R.id.account_name_label);
|
||||
final View accountNameLabel = UiUtilities.getView(this, R.id.account_name_label);
|
||||
mNextButton = UiUtilities.getView(this, R.id.next);
|
||||
mNextButton.setOnClickListener(this);
|
||||
mNextButton.setOnClickListener(new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
onNext();
|
||||
}
|
||||
});
|
||||
|
||||
TextWatcher validationTextWatcher = new TextWatcher() {
|
||||
final TextWatcher validationTextWatcher = new TextWatcher() {
|
||||
@Override
|
||||
public void afterTextChanged(Editable s) {
|
||||
validateFields();
|
||||
|
@ -90,18 +97,19 @@ public class AccountSetupNames extends AccountSetupActivity implements OnClickLi
|
|||
mName.addTextChangedListener(validationTextWatcher);
|
||||
mName.setKeyListener(TextKeyListener.getInstance(false, Capitalize.WORDS));
|
||||
|
||||
final Account account = SetupData.getAccount();
|
||||
final Account account = mSetupData.getAccount();
|
||||
if (account == null) {
|
||||
throw new IllegalStateException("unexpected null account");
|
||||
}
|
||||
if (account.mHostAuthRecv == null) {
|
||||
throw new IllegalStateException("unexpected null hostauth");
|
||||
}
|
||||
int flowMode = SetupData.getFlowMode();
|
||||
|
||||
final int flowMode = mSetupData.getFlowMode();
|
||||
|
||||
if (flowMode != SetupData.FLOW_MODE_FORCE_CREATE
|
||||
&& flowMode != SetupData.FLOW_MODE_EDIT) {
|
||||
String accountEmail = account.mEmailAddress;
|
||||
final String accountEmail = account.mEmailAddress;
|
||||
mDescription.setText(accountEmail);
|
||||
|
||||
// Move cursor to the end so it's easier to erase in case the user doesn't like it.
|
||||
|
@ -109,7 +117,7 @@ public class AccountSetupNames extends AccountSetupActivity implements OnClickLi
|
|||
}
|
||||
|
||||
// Remember whether we're an EAS account, since it doesn't require the user name field
|
||||
EmailServiceInfo info =
|
||||
final EmailServiceInfo info =
|
||||
EmailServiceUtils.getServiceInfo(this, account.mHostAuthRecv.mProtocol);
|
||||
if (!info.usesSmtp) {
|
||||
mRequiresName = false;
|
||||
|
@ -138,7 +146,7 @@ public class AccountSetupNames extends AccountSetupActivity implements OnClickLi
|
|||
new EmailAsyncTask<Void, Void, String>(null) {
|
||||
@Override
|
||||
protected String doInBackground(Void... params) {
|
||||
String[] projection = new String[] { Profile.DISPLAY_NAME };
|
||||
final String[] projection = new String[] { Profile.DISPLAY_NAME };
|
||||
return Utility.getFirstRowString(
|
||||
AccountSetupNames.this, PROFILE_URI, projection, null, null, null, 0);
|
||||
}
|
||||
|
@ -151,18 +159,6 @@ public class AccountSetupNames extends AccountSetupActivity implements OnClickLi
|
|||
}.executeParallel((Void[]) null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements OnClickListener
|
||||
*/
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
switch (v.getId()) {
|
||||
case R.id.next:
|
||||
onNext();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check input fields for legal values and enable/disable next button
|
||||
*/
|
||||
|
@ -170,7 +166,7 @@ public class AccountSetupNames extends AccountSetupActivity implements OnClickLi
|
|||
boolean enableNextButton = true;
|
||||
// Validation is based only on the "user name" field, not shown for EAS accounts
|
||||
if (mRequiresName) {
|
||||
String userName = mName.getText().toString().trim();
|
||||
final String userName = mName.getText().toString().trim();
|
||||
if (TextUtils.isEmpty(userName)) {
|
||||
enableNextButton = false;
|
||||
mName.setError(getString(R.string.account_setup_names_user_name_empty_error));
|
||||
|
@ -192,19 +188,14 @@ public class AccountSetupNames extends AccountSetupActivity implements OnClickLi
|
|||
}
|
||||
|
||||
private void finishActivity() {
|
||||
if (SetupData.getFlowMode() == SetupData.FLOW_MODE_NO_ACCOUNTS) {
|
||||
if (mSetupData.getFlowMode() == SetupData.FLOW_MODE_NO_ACCOUNTS) {
|
||||
AccountSetupBasics.actionAccountCreateFinishedWithResult(this);
|
||||
} else if (SetupData.getFlowMode() != SetupData.FLOW_MODE_NORMAL) {
|
||||
} else if (mSetupData.getFlowMode() != SetupData.FLOW_MODE_NORMAL) {
|
||||
AccountSetupBasics.actionAccountCreateFinishedAccountFlow(this);
|
||||
} else {
|
||||
Account account = SetupData.getAccount();
|
||||
final Account account = mSetupData.getAccount();
|
||||
if (account != null) {
|
||||
AccountSetupBasics.actionAccountCreateFinished(this, account);
|
||||
} else {
|
||||
// Safety check here; If mAccount is null (due to external issues or bugs)
|
||||
// just rewind back to Welcome, which can handle any configuration of accounts
|
||||
//***
|
||||
//Welcome.actionStart(this);
|
||||
}
|
||||
}
|
||||
finish();
|
||||
|
@ -218,8 +209,8 @@ public class AccountSetupNames extends AccountSetupActivity implements OnClickLi
|
|||
mNextButton.setEnabled(false); // Protect against double-tap.
|
||||
|
||||
// Update account object from UI
|
||||
Account account = SetupData.getAccount();
|
||||
String description = mDescription.getText().toString().trim();
|
||||
final Account account = mSetupData.getAccount();
|
||||
final String description = mDescription.getText().toString().trim();
|
||||
if (!TextUtils.isEmpty(description)) {
|
||||
account.setDisplayName(description);
|
||||
}
|
||||
|
@ -259,7 +250,7 @@ public class AccountSetupNames extends AccountSetupActivity implements OnClickLi
|
|||
@Override
|
||||
protected Boolean doInBackground(Void... params) {
|
||||
// Update the account in the database
|
||||
ContentValues cv = new ContentValues();
|
||||
final ContentValues cv = new ContentValues();
|
||||
cv.put(AccountColumns.DISPLAY_NAME, mAccount.getDisplayName());
|
||||
cv.put(AccountColumns.SENDER_NAME, mAccount.getSenderName());
|
||||
mAccount.update(mContext, cv);
|
||||
|
@ -274,7 +265,7 @@ public class AccountSetupNames extends AccountSetupActivity implements OnClickLi
|
|||
protected void onPostExecute(Boolean isSecurityHold) {
|
||||
if (!isCancelled()) {
|
||||
if (isSecurityHold) {
|
||||
Intent i = AccountSecurity.actionUpdateSecurityIntent(
|
||||
final Intent i = AccountSecurity.actionUpdateSecurityIntent(
|
||||
AccountSetupNames.this, mAccount.mId, false);
|
||||
startActivityForResult(i, REQUEST_SECURITY);
|
||||
} else {
|
||||
|
|
|
@ -28,6 +28,7 @@ import android.app.ProgressDialog;
|
|||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.os.AsyncTask;
|
||||
import android.os.Bundle;
|
||||
import android.os.RemoteException;
|
||||
import android.view.View;
|
||||
|
@ -72,8 +73,10 @@ 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) {
|
||||
fromActivity.startActivity(new ForwardingIntent(fromActivity, AccountSetupOptions.class));
|
||||
public static void actionOptions(Activity fromActivity, SetupData setupData) {
|
||||
final Intent intent = new ForwardingIntent(fromActivity, AccountSetupOptions.class);
|
||||
intent.putExtra(SetupData.EXTRA_SETUP_DATA, setupData);
|
||||
fromActivity.startActivity(intent);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -82,34 +85,34 @@ public class AccountSetupOptions extends AccountSetupActivity implements OnClick
|
|||
ActivityHelper.debugSetWindowFlags(this);
|
||||
setContentView(R.layout.account_setup_options);
|
||||
|
||||
mCheckFrequencyView = (Spinner) UiUtilities.getView(this, R.id.account_check_frequency);
|
||||
mSyncWindowView = (Spinner) UiUtilities.getView(this, R.id.account_sync_window);
|
||||
mNotifyView = (CheckBox) UiUtilities.getView(this, R.id.account_notify);
|
||||
mSyncContactsView = (CheckBox) UiUtilities.getView(this, R.id.account_sync_contacts);
|
||||
mSyncCalendarView = (CheckBox) UiUtilities.getView(this, R.id.account_sync_calendar);
|
||||
mSyncEmailView = (CheckBox) UiUtilities.getView(this, R.id.account_sync_email);
|
||||
mCheckFrequencyView = UiUtilities.getView(this, R.id.account_check_frequency);
|
||||
mSyncWindowView = UiUtilities.getView(this, R.id.account_sync_window);
|
||||
mNotifyView = UiUtilities.getView(this, R.id.account_notify);
|
||||
mSyncContactsView = UiUtilities.getView(this, R.id.account_sync_contacts);
|
||||
mSyncCalendarView = UiUtilities.getView(this, R.id.account_sync_calendar);
|
||||
mSyncEmailView = UiUtilities.getView(this, R.id.account_sync_email);
|
||||
mSyncEmailView.setChecked(true);
|
||||
mBackgroundAttachmentsView = (CheckBox) UiUtilities.getView(this,
|
||||
R.id.account_background_attachments);
|
||||
mBackgroundAttachmentsView = UiUtilities.getView(this, R.id.account_background_attachments);
|
||||
mBackgroundAttachmentsView.setChecked(true);
|
||||
UiUtilities.getView(this, R.id.previous).setOnClickListener(this);
|
||||
UiUtilities.getView(this, R.id.next).setOnClickListener(this);
|
||||
mAccountSyncWindowRow = UiUtilities.getView(this, R.id.account_sync_window_row);
|
||||
|
||||
Account account = SetupData.getAccount();
|
||||
final Account account = mSetupData.getAccount();
|
||||
mServiceInfo = EmailServiceUtils.getServiceInfo(getApplicationContext(),
|
||||
account.mHostAuthRecv.mProtocol);
|
||||
CharSequence[] frequencyValues = mServiceInfo.syncIntervals;
|
||||
CharSequence[] frequencyEntries = mServiceInfo.syncIntervalStrings;
|
||||
final CharSequence[] frequencyValues = mServiceInfo.syncIntervals;
|
||||
final CharSequence[] frequencyEntries = mServiceInfo.syncIntervalStrings;
|
||||
|
||||
// Now create the array used by the sync interval Spinner
|
||||
SpinnerOption[] checkFrequencies = new SpinnerOption[frequencyEntries.length];
|
||||
final SpinnerOption[] checkFrequencies = new SpinnerOption[frequencyEntries.length];
|
||||
for (int i = 0; i < frequencyEntries.length; i++) {
|
||||
checkFrequencies[i] = new SpinnerOption(
|
||||
Integer.valueOf(frequencyValues[i].toString()), frequencyEntries[i].toString());
|
||||
}
|
||||
ArrayAdapter<SpinnerOption> checkFrequenciesAdapter = new ArrayAdapter<SpinnerOption>(this,
|
||||
android.R.layout.simple_spinner_item, checkFrequencies);
|
||||
final ArrayAdapter<SpinnerOption> checkFrequenciesAdapter =
|
||||
new ArrayAdapter<SpinnerOption>(this, android.R.layout.simple_spinner_item,
|
||||
checkFrequencies);
|
||||
checkFrequenciesAdapter
|
||||
.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
|
||||
mCheckFrequencyView.setAdapter(checkFrequenciesAdapter);
|
||||
|
@ -139,8 +142,7 @@ public class AccountSetupOptions extends AccountSetupActivity implements OnClick
|
|||
}
|
||||
|
||||
// If we are just visiting here to fill in details, exit immediately
|
||||
if (SetupData.isAutoSetup() ||
|
||||
SetupData.getFlowMode() == SetupData.FLOW_MODE_FORCE_CREATE) {
|
||||
if (mSetupData.getFlowMode() == SetupData.FLOW_MODE_FORCE_CREATE) {
|
||||
onDone();
|
||||
}
|
||||
}
|
||||
|
@ -156,11 +158,11 @@ public class AccountSetupOptions extends AccountSetupActivity implements OnClick
|
|||
|
||||
// If the account manager initiated the creation, and success was not reported,
|
||||
// then we assume that we're giving up (for any reason) - report failure.
|
||||
AccountAuthenticatorResponse authenticatorResponse =
|
||||
SetupData.getAccountAuthenticatorResponse();
|
||||
final AccountAuthenticatorResponse authenticatorResponse =
|
||||
mSetupData.getAccountAuthenticatorResponse();
|
||||
if (authenticatorResponse != null) {
|
||||
authenticatorResponse.onError(AccountManager.ERROR_CODE_CANCELED, "canceled");
|
||||
SetupData.setAccountAuthenticatorResponse(null);
|
||||
mSetupData.setAccountAuthenticatorResponse(null);
|
||||
}
|
||||
super.finish();
|
||||
}
|
||||
|
@ -194,7 +196,7 @@ public class AccountSetupOptions extends AccountSetupActivity implements OnClick
|
|||
*/
|
||||
@SuppressWarnings("deprecation")
|
||||
private void onDone() {
|
||||
final Account account = SetupData.getAccount();
|
||||
final Account account = mSetupData.getAccount();
|
||||
if (account.isSaved()) {
|
||||
// Disrupting the normal flow could get us here, but if the account is already
|
||||
// saved, we've done this work
|
||||
|
@ -209,8 +211,8 @@ public class AccountSetupOptions extends AccountSetupActivity implements OnClick
|
|||
account.setSyncInterval((Integer)((SpinnerOption)mCheckFrequencyView
|
||||
.getSelectedItem()).value);
|
||||
if (mAccountSyncWindowRow.getVisibility() == View.VISIBLE) {
|
||||
int window = (Integer)((SpinnerOption)mSyncWindowView.getSelectedItem()).value;
|
||||
account.setSyncLookback(window);
|
||||
account.setSyncLookback(
|
||||
(Integer)((SpinnerOption)mSyncWindowView.getSelectedItem()).value);
|
||||
}
|
||||
|
||||
if (account.mHostAuthRecv == null) {
|
||||
|
@ -220,27 +222,18 @@ public class AccountSetupOptions extends AccountSetupActivity implements OnClick
|
|||
// Finish setting up the account, and commit it to the database
|
||||
// Set the incomplete flag here to avoid reconciliation issues in ExchangeService
|
||||
account.mFlags |= Account.FLAGS_INCOMPLETE;
|
||||
if (SetupData.getPolicy() != null) {
|
||||
if (mSetupData.getPolicy() != null) {
|
||||
account.mFlags |= Account.FLAGS_SECURITY_HOLD;
|
||||
account.mPolicy = SetupData.getPolicy();
|
||||
account.mPolicy = mSetupData.getPolicy();
|
||||
}
|
||||
boolean contacts = false;
|
||||
if (mServiceInfo.syncContacts) {
|
||||
contacts = mSyncContactsView.isChecked();
|
||||
}
|
||||
boolean calendar = false;
|
||||
if (mServiceInfo.syncCalendar) {
|
||||
calendar = mSyncCalendarView.isChecked();
|
||||
}
|
||||
boolean email = mSyncEmailView.isChecked();
|
||||
|
||||
// Finally, write the completed account (for the first time) and then
|
||||
// install it into the Account manager as well. These are done off-thread.
|
||||
// The account manager will report back via the callback, which will take us to
|
||||
// the next operations.
|
||||
final boolean email2 = email;
|
||||
final boolean calendar2 = calendar;
|
||||
final boolean contacts2 = contacts;
|
||||
final boolean email = mSyncEmailView.isChecked();
|
||||
final boolean calendar = mServiceInfo.syncCalendar && mSyncCalendarView.isChecked();
|
||||
final boolean contacts = mServiceInfo.syncContacts && mSyncContactsView.isChecked();
|
||||
|
||||
/// Show "Creating account..." dialog
|
||||
mCreateAccountDialog = new ProgressDialog(this);
|
||||
|
@ -251,10 +244,10 @@ public class AccountSetupOptions extends AccountSetupActivity implements OnClick
|
|||
Utility.runAsync(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
Context context = AccountSetupOptions.this;
|
||||
final Context context = AccountSetupOptions.this;
|
||||
AccountSettingsUtils.commitSettings(context, account);
|
||||
EmailServiceUtils.setupAccountManagerAccount(context, account,
|
||||
email2, calendar2, contacts2, mAccountManagerCallback);
|
||||
email, calendar, contacts, mAccountManagerCallback);
|
||||
|
||||
// We can move the notification setting to the inbox FolderPreferences later, once
|
||||
// we know what the inbox is
|
||||
|
@ -272,8 +265,8 @@ public class AccountSetupOptions extends AccountSetupActivity implements OnClick
|
|||
@Override
|
||||
public void run(AccountManagerFuture<Bundle> future) {
|
||||
try {
|
||||
Bundle bundle = future.getResult();
|
||||
bundle.keySet();
|
||||
// Block until the operation completes
|
||||
future.getResult();
|
||||
AccountSetupOptions.this.runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
|
@ -323,28 +316,29 @@ public class AccountSetupOptions extends AccountSetupActivity implements OnClick
|
|||
*/
|
||||
private void optionsComplete() {
|
||||
// If the account manager initiated the creation, report success at this point
|
||||
AccountAuthenticatorResponse authenticatorResponse =
|
||||
SetupData.getAccountAuthenticatorResponse();
|
||||
final AccountAuthenticatorResponse authenticatorResponse =
|
||||
mSetupData.getAccountAuthenticatorResponse();
|
||||
if (authenticatorResponse != null) {
|
||||
authenticatorResponse.onResult(null);
|
||||
SetupData.setAccountAuthenticatorResponse(null);
|
||||
mSetupData.setAccountAuthenticatorResponse(null);
|
||||
}
|
||||
|
||||
// Now that AccountManager account creation is complete, clear the INCOMPLETE flag
|
||||
Account account = SetupData.getAccount();
|
||||
final Account account = mSetupData.getAccount();
|
||||
account.mFlags &= ~Account.FLAGS_INCOMPLETE;
|
||||
AccountSettingsUtils.commitSettings(AccountSetupOptions.this, account);
|
||||
|
||||
// If we've got policies for this account, ask the user to accept.
|
||||
if ((account.mFlags & Account.FLAGS_SECURITY_HOLD) != 0) {
|
||||
Intent intent = AccountSecurity.actionUpdateSecurityIntent(this, account.mId, false);
|
||||
final Intent intent =
|
||||
AccountSecurity.actionUpdateSecurityIntent(this, account.mId, false);
|
||||
startActivityForResult(intent, AccountSetupOptions.REQUEST_CODE_ACCEPT_POLICIES);
|
||||
return;
|
||||
}
|
||||
saveAccountAndFinish();
|
||||
|
||||
// Update the folder list (to get our starting folders, e.g. Inbox)
|
||||
EmailServiceProxy proxy = EmailServiceUtils.getServiceForAccount(this, account.mId);
|
||||
final EmailServiceProxy proxy = EmailServiceUtils.getServiceForAccount(this, account.mId);
|
||||
try {
|
||||
proxy.updateFolderList(account.mId);
|
||||
} catch (RemoteException e) {
|
||||
|
@ -368,24 +362,25 @@ public class AccountSetupOptions extends AccountSetupActivity implements OnClick
|
|||
* Enable exchange services
|
||||
* Move to final setup screen
|
||||
*/
|
||||
@SuppressWarnings("deprecation")
|
||||
private void saveAccountAndFinish() {
|
||||
Utility.runAsync(new Runnable() {
|
||||
AsyncTask<Void, Void, Void> asyncTask = new AsyncTask<Void, Void, Void>() {
|
||||
@Override
|
||||
public void run() {
|
||||
AccountSetupOptions context = AccountSetupOptions.this;
|
||||
protected Void doInBackground(Void... params) {
|
||||
final AccountSetupOptions context = AccountSetupOptions.this;
|
||||
// Clear the security hold flag now
|
||||
Account account = SetupData.getAccount();
|
||||
final Account account = mSetupData.getAccount();
|
||||
account.mFlags &= ~Account.FLAGS_SECURITY_HOLD;
|
||||
AccountSettingsUtils.commitSettings(context, account);
|
||||
// Start up services based on new account(s)
|
||||
MailActivityEmail.setServicesEnabledSync(context);
|
||||
EmailServiceUtils.startService(context, account.mHostAuthRecv.mProtocol);
|
||||
// Move to final setup screen
|
||||
AccountSetupNames.actionSetNames(context);
|
||||
AccountSetupNames.actionSetNames(context, mSetupData);
|
||||
finish();
|
||||
return null;
|
||||
}
|
||||
});
|
||||
};
|
||||
asyncTask.execute();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -396,16 +391,16 @@ public class AccountSetupOptions extends AccountSetupActivity implements OnClick
|
|||
mAccountSyncWindowRow.setVisibility(View.VISIBLE);
|
||||
|
||||
// Generate spinner entries using XML arrays used by the preferences
|
||||
CharSequence[] windowValues = getResources().getTextArray(
|
||||
final CharSequence[] windowValues = getResources().getTextArray(
|
||||
R.array.account_settings_mail_window_values);
|
||||
CharSequence[] windowEntries = getResources().getTextArray(
|
||||
final CharSequence[] windowEntries = getResources().getTextArray(
|
||||
R.array.account_settings_mail_window_entries);
|
||||
|
||||
// Find a proper maximum for email lookback, based on policy (if we have one)
|
||||
int maxEntry = windowEntries.length;
|
||||
Policy policy = SetupData.getAccount().mPolicy;
|
||||
final Policy policy = mSetupData.getAccount().mPolicy;
|
||||
if (policy != null) {
|
||||
int maxLookback = policy.mMaxEmailLookback;
|
||||
final int maxLookback = policy.mMaxEmailLookback;
|
||||
if (maxLookback != 0) {
|
||||
// Offset/Code 0 1 2 3 4 5
|
||||
// Entries auto, 1 day, 3 day, 1 week, 2 week, 1 month
|
||||
|
@ -416,7 +411,7 @@ public class AccountSetupOptions extends AccountSetupActivity implements OnClick
|
|||
}
|
||||
|
||||
// Now create the array used by the Spinner
|
||||
SpinnerOption[] windowOptions = new SpinnerOption[maxEntry];
|
||||
final SpinnerOption[] windowOptions = new SpinnerOption[maxEntry];
|
||||
int defaultIndex = -1;
|
||||
for (int i = 0; i < maxEntry; i++) {
|
||||
final int value = Integer.valueOf(windowValues[i].toString());
|
||||
|
@ -426,14 +421,15 @@ public class AccountSetupOptions extends AccountSetupActivity implements OnClick
|
|||
}
|
||||
}
|
||||
|
||||
ArrayAdapter<SpinnerOption> windowOptionsAdapter = new ArrayAdapter<SpinnerOption>(this,
|
||||
android.R.layout.simple_spinner_item, windowOptions);
|
||||
final ArrayAdapter<SpinnerOption> windowOptionsAdapter =
|
||||
new ArrayAdapter<SpinnerOption>(this, android.R.layout.simple_spinner_item,
|
||||
windowOptions);
|
||||
windowOptionsAdapter
|
||||
.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
|
||||
mSyncWindowView.setAdapter(windowOptionsAdapter);
|
||||
|
||||
SpinnerOption.setSpinnerOptionValue(mSyncWindowView,
|
||||
SetupData.getAccount().getSyncLookback());
|
||||
mSetupData.getAccount().getSyncLookback());
|
||||
if (defaultIndex >= 0) {
|
||||
mSyncWindowView.setSelection(defaultIndex);
|
||||
}
|
||||
|
|
|
@ -35,17 +35,17 @@ import android.widget.Button;
|
|||
* Uses AccountSetupOutgoingFragment for primary UI. Uses AccountCheckSettingsFragment to validate
|
||||
* the settings as entered. If the account is OK, proceeds to AccountSetupOptions.
|
||||
*/
|
||||
public class AccountSetupOutgoing extends Activity
|
||||
public class AccountSetupOutgoing extends AccountSetupActivity
|
||||
implements AccountSetupOutgoingFragment.Callback, OnClickListener {
|
||||
|
||||
/* package */ AccountSetupOutgoingFragment mFragment;
|
||||
private Button mNextButton;
|
||||
/* package */ boolean mNextButtonEnabled;
|
||||
|
||||
public static void actionOutgoingSettings(Activity fromActivity, int mode, Account account) {
|
||||
SetupData.setFlowMode(mode);
|
||||
SetupData.setAccount(account);
|
||||
fromActivity.startActivity(new Intent(fromActivity, AccountSetupOutgoing.class));
|
||||
public static void actionOutgoingSettings(Activity fromActivity, SetupData setupData) {
|
||||
Intent intent = new Intent(fromActivity, AccountSetupOutgoing.class);
|
||||
intent.putExtra(SetupData.EXTRA_SETUP_DATA, setupData);
|
||||
fromActivity.startActivity(intent);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -81,22 +81,22 @@ public class AccountSetupOutgoing extends Activity
|
|||
}
|
||||
|
||||
/**
|
||||
* Implements AccountServerBaseFragment.Callback
|
||||
* Implements AccountSetupOugoingFragment.Callback
|
||||
*
|
||||
* Launches the account checker. Positive results are reported to onCheckSettingsOk().
|
||||
*/
|
||||
@Override
|
||||
public void onProceedNext(int checkMode, AccountServerBaseFragment target) {
|
||||
AccountCheckSettingsFragment checkerFragment =
|
||||
final AccountCheckSettingsFragment checkerFragment =
|
||||
AccountCheckSettingsFragment.newInstance(checkMode, target);
|
||||
FragmentTransaction transaction = getFragmentManager().beginTransaction();
|
||||
final FragmentTransaction transaction = getFragmentManager().beginTransaction();
|
||||
transaction.add(checkerFragment, AccountCheckSettingsFragment.TAG);
|
||||
transaction.addToBackStack("back");
|
||||
transaction.commit();
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements AccountServerBaseFragment.Callback
|
||||
* Implements AccountSetupOugoingFragment.Callback
|
||||
*/
|
||||
@Override
|
||||
public void onEnableProceedButtons(boolean enable) {
|
||||
|
@ -110,9 +110,10 @@ public class AccountSetupOutgoing extends Activity
|
|||
* If the checked settings are OK, proceed to options screen
|
||||
*/
|
||||
@Override
|
||||
public void onCheckSettingsComplete(int result, int setupMode) {
|
||||
public void onCheckSettingsComplete(int result, SetupData setupData) {
|
||||
mSetupData = setupData;
|
||||
if (result == AccountCheckSettingsFragment.CHECK_SETTINGS_OK) {
|
||||
AccountSetupOptions.actionOptions(this);
|
||||
AccountSetupOptions.actionOptions(this, mSetupData);
|
||||
finish();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -95,12 +95,12 @@ public class AccountSetupOutgoingFragment extends AccountServerBaseFragment
|
|||
if (Logging.DEBUG_LIFECYCLE && MailActivityEmail.DEBUG) {
|
||||
LogUtils.d(Logging.LOG_TAG, "AccountSetupOutgoingFragment onCreateView");
|
||||
}
|
||||
int layoutId = mSettingsMode
|
||||
final int layoutId = mSettingsMode
|
||||
? R.layout.account_settings_outgoing_fragment
|
||||
: R.layout.account_setup_outgoing_fragment;
|
||||
|
||||
View view = inflater.inflate(layoutId, container, false);
|
||||
Context context = getActivity();
|
||||
final View view = inflater.inflate(layoutId, container, false);
|
||||
final Context context = getActivity();
|
||||
|
||||
mUsernameView = UiUtilities.getView(view, R.id.account_username);
|
||||
mPasswordView = UiUtilities.getView(view, R.id.account_password);
|
||||
|
@ -111,7 +111,7 @@ public class AccountSetupOutgoingFragment extends AccountServerBaseFragment
|
|||
mRequireLoginView.setOnCheckedChangeListener(this);
|
||||
|
||||
// Note: Strings are shared with AccountSetupIncomingFragment
|
||||
SpinnerOption securityTypes[] = {
|
||||
final SpinnerOption securityTypes[] = {
|
||||
new SpinnerOption(HostAuth.FLAG_NONE, context.getString(
|
||||
R.string.account_setup_incoming_security_none_label)),
|
||||
new SpinnerOption(HostAuth.FLAG_SSL, context.getString(
|
||||
|
@ -124,8 +124,9 @@ public class AccountSetupOutgoingFragment extends AccountServerBaseFragment
|
|||
R.string.account_setup_incoming_security_tls_trust_certificates_label)),
|
||||
};
|
||||
|
||||
ArrayAdapter<SpinnerOption> securityTypesAdapter = new ArrayAdapter<SpinnerOption>(context,
|
||||
android.R.layout.simple_spinner_item, securityTypes);
|
||||
final ArrayAdapter<SpinnerOption> securityTypesAdapter =
|
||||
new ArrayAdapter<SpinnerOption>(context, android.R.layout.simple_spinner_item,
|
||||
securityTypes);
|
||||
securityTypesAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
|
||||
mSecurityTypeView.setAdapter(securityTypesAdapter);
|
||||
|
||||
|
@ -149,7 +150,7 @@ public class AccountSetupOutgoingFragment extends AccountServerBaseFragment
|
|||
}});
|
||||
|
||||
// Calls validateFields() which enables or disables the Next button
|
||||
TextWatcher validationTextWatcher = new TextWatcher() {
|
||||
final TextWatcher validationTextWatcher = new TextWatcher() {
|
||||
@Override
|
||||
public void afterTextChanged(Editable s) {
|
||||
validateFields();
|
||||
|
@ -265,29 +266,29 @@ public class AccountSetupOutgoingFragment extends AccountServerBaseFragment
|
|||
private void loadSettings() {
|
||||
if (mLoaded) return;
|
||||
|
||||
HostAuth sendAuth = SetupData.getAccount().getOrCreateHostAuthSend(mContext);
|
||||
final HostAuth sendAuth = mSetupData.getAccount().getOrCreateHostAuthSend(mContext);
|
||||
if ((sendAuth.mFlags & HostAuth.FLAG_AUTHENTICATE) != 0) {
|
||||
String username = sendAuth.mLogin;
|
||||
final String username = sendAuth.mLogin;
|
||||
if (username != null) {
|
||||
mUsernameView.setText(username);
|
||||
mRequireLoginView.setChecked(true);
|
||||
}
|
||||
|
||||
String password = sendAuth.mPassword;
|
||||
final String password = sendAuth.mPassword;
|
||||
if (password != null) {
|
||||
mPasswordView.setText(password);
|
||||
}
|
||||
}
|
||||
|
||||
int flags = sendAuth.mFlags & ~HostAuth.FLAG_AUTHENTICATE;
|
||||
final int flags = sendAuth.mFlags & ~HostAuth.FLAG_AUTHENTICATE;
|
||||
SpinnerOption.setSpinnerOptionValue(mSecurityTypeView, flags);
|
||||
|
||||
String hostname = sendAuth.mAddress;
|
||||
final String hostname = sendAuth.mAddress;
|
||||
if (hostname != null) {
|
||||
mServerView.setText(hostname);
|
||||
}
|
||||
|
||||
int port = sendAuth.mPort;
|
||||
final int port = sendAuth.mPort;
|
||||
if (port != -1) {
|
||||
mPortView.setText(Integer.toString(port));
|
||||
} else {
|
||||
|
@ -328,12 +329,13 @@ public class AccountSetupOutgoingFragment extends AccountServerBaseFragment
|
|||
}
|
||||
|
||||
private int getPortFromSecurityType() {
|
||||
int securityType = (Integer)((SpinnerOption)mSecurityTypeView.getSelectedItem()).value;
|
||||
final int securityType =
|
||||
(Integer)((SpinnerOption)mSecurityTypeView.getSelectedItem()).value;
|
||||
return (securityType & HostAuth.FLAG_SSL) != 0 ? SMTP_PORT_SSL : SMTP_PORT_NORMAL;
|
||||
}
|
||||
|
||||
private void updatePortFromSecurityType() {
|
||||
int port = getPortFromSecurityType();
|
||||
final int port = getPortFromSecurityType();
|
||||
mPortView.setText(Integer.toString(port));
|
||||
}
|
||||
|
||||
|
@ -343,7 +345,7 @@ public class AccountSetupOutgoingFragment extends AccountServerBaseFragment
|
|||
*/
|
||||
@Override
|
||||
public void saveSettingsAfterEdit() {
|
||||
Account account = SetupData.getAccount();
|
||||
final Account account = mSetupData.getAccount();
|
||||
account.mHostAuthSend.update(mContext, account.mHostAuthSend.toContentValues());
|
||||
// Update the backup (side copy) of the accounts
|
||||
AccountBackupRestore.backup(mContext);
|
||||
|
@ -361,18 +363,18 @@ public class AccountSetupOutgoingFragment extends AccountServerBaseFragment
|
|||
*/
|
||||
@Override
|
||||
public void onNext() {
|
||||
Account account = SetupData.getAccount();
|
||||
HostAuth sendAuth = account.getOrCreateHostAuthSend(mContext);
|
||||
final Account account = mSetupData.getAccount();
|
||||
final HostAuth sendAuth = account.getOrCreateHostAuthSend(mContext);
|
||||
|
||||
if (mRequireLoginView.isChecked()) {
|
||||
String userName = mUsernameView.getText().toString().trim();
|
||||
String userPassword = mPasswordView.getText().toString();
|
||||
final String userName = mUsernameView.getText().toString().trim();
|
||||
final String userPassword = mPasswordView.getText().toString();
|
||||
sendAuth.setLogin(userName, userPassword);
|
||||
} else {
|
||||
sendAuth.setLogin(null, null);
|
||||
}
|
||||
|
||||
String serverAddress = mServerView.getText().toString().trim();
|
||||
final String serverAddress = mServerView.getText().toString().trim();
|
||||
int serverPort;
|
||||
try {
|
||||
serverPort = Integer.parseInt(mPortView.getText().toString().trim());
|
||||
|
@ -380,7 +382,8 @@ public class AccountSetupOutgoingFragment extends AccountServerBaseFragment
|
|||
serverPort = getPortFromSecurityType();
|
||||
LogUtils.d(Logging.LOG_TAG, "Non-integer server port; using '" + serverPort + "'");
|
||||
}
|
||||
int securityType = (Integer)((SpinnerOption)mSecurityTypeView.getSelectedItem()).value;
|
||||
final int securityType =
|
||||
(Integer)((SpinnerOption)mSecurityTypeView.getSelectedItem()).value;
|
||||
sendAuth.setConnection(mBaseScheme, serverAddress, serverPort, securityType);
|
||||
sendAuth.mDomain = null;
|
||||
|
||||
|
|
|
@ -42,8 +42,9 @@ import com.android.emailcommon.provider.HostAuth;
|
|||
*/
|
||||
public class AccountSetupType extends AccountSetupActivity implements OnClickListener {
|
||||
|
||||
public static void actionSelectAccountType(Activity fromActivity) {
|
||||
Intent i = new ForwardingIntent(fromActivity, AccountSetupType.class);
|
||||
public static void actionSelectAccountType(Activity fromActivity, SetupData setupData) {
|
||||
final Intent i = new ForwardingIntent(fromActivity, AccountSetupType.class);
|
||||
i.putExtra(SetupData.EXTRA_SETUP_DATA, setupData);
|
||||
fromActivity.startActivity(i);
|
||||
}
|
||||
|
||||
|
@ -51,11 +52,10 @@ public class AccountSetupType extends AccountSetupActivity implements OnClickLis
|
|||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
ActivityHelper.debugSetWindowFlags(this);
|
||||
int flowMode = SetupData.getFlowMode();
|
||||
|
||||
String accountType = SetupData.getFlowAccountType();
|
||||
final String accountType = mSetupData.getFlowAccountType();
|
||||
// If we're in account setup flow mode, see if there's just one protocol that matches
|
||||
if (flowMode == SetupData.FLOW_MODE_ACCOUNT_MANAGER) {
|
||||
if (mSetupData.getFlowMode() == SetupData.FLOW_MODE_ACCOUNT_MANAGER) {
|
||||
int matches = 0;
|
||||
String protocol = null;
|
||||
for (EmailServiceInfo info: EmailServiceUtils.getServiceInfoList(this)) {
|
||||
|
@ -73,8 +73,7 @@ public class AccountSetupType extends AccountSetupActivity implements OnClickLis
|
|||
|
||||
// Otherwise proceed into this screen
|
||||
setContentView(R.layout.account_setup_account_type);
|
||||
ViewGroup parent = UiUtilities.getView(this, R.id.accountTypes);
|
||||
boolean parentRelative = parent instanceof RelativeLayout;
|
||||
final ViewGroup parent = UiUtilities.getView(this, R.id.accountTypes);
|
||||
View lastView = parent.getChildAt(0);
|
||||
int i = 1;
|
||||
for (EmailServiceInfo info: EmailServiceUtils.getServiceInfoList(this)) {
|
||||
|
@ -85,9 +84,9 @@ public class AccountSetupType extends AccountSetupActivity implements OnClickLis
|
|||
continue;
|
||||
}
|
||||
LayoutInflater.from(this).inflate(R.layout.account_type, parent);
|
||||
Button button = (Button)parent.getChildAt(i);
|
||||
if (parentRelative) {
|
||||
LayoutParams params = (LayoutParams)button.getLayoutParams();
|
||||
final Button button = (Button)parent.getChildAt(i);
|
||||
if (parent instanceof RelativeLayout) {
|
||||
final LayoutParams params = (LayoutParams)button.getLayoutParams();
|
||||
params.addRule(RelativeLayout.BELOW, lastView.getId());
|
||||
}
|
||||
button.setId(i);
|
||||
|
@ -108,19 +107,19 @@ public class AccountSetupType extends AccountSetupActivity implements OnClickLis
|
|||
* there is no UI (for exchange), and switch the default sync interval to "push".
|
||||
*/
|
||||
private void onSelect(String protocol) {
|
||||
Account account = SetupData.getAccount();
|
||||
HostAuth recvAuth = account.getOrCreateHostAuthRecv(this);
|
||||
final Account account = mSetupData.getAccount();
|
||||
final HostAuth recvAuth = account.getOrCreateHostAuthRecv(this);
|
||||
recvAuth.setConnection(protocol, recvAuth.mAddress, recvAuth.mPort, recvAuth.mFlags);
|
||||
EmailServiceInfo info = EmailServiceUtils.getServiceInfo(this, protocol);
|
||||
final EmailServiceInfo info = EmailServiceUtils.getServiceInfo(this, protocol);
|
||||
if (info.usesAutodiscover) {
|
||||
SetupData.setCheckSettingsMode(SetupData.CHECK_AUTODISCOVER);
|
||||
mSetupData.setCheckSettingsMode(SetupData.CHECK_AUTODISCOVER);
|
||||
} else {
|
||||
SetupData.setCheckSettingsMode(
|
||||
mSetupData.setCheckSettingsMode(
|
||||
SetupData.CHECK_INCOMING | (info.usesSmtp ? SetupData.CHECK_OUTGOING : 0));
|
||||
}
|
||||
recvAuth.mLogin = recvAuth.mLogin + "@" + recvAuth.mAddress;
|
||||
AccountSetupBasics.setDefaultsForProtocol(this, account);
|
||||
AccountSetupIncoming.actionIncomingSettings(this, SetupData.getFlowMode(), account);
|
||||
AccountSetupIncoming.actionIncomingSettings(this, mSetupData);
|
||||
// Back from the incoming screen returns to AccountSetupBasics
|
||||
finish();
|
||||
}
|
||||
|
|
|
@ -56,135 +56,15 @@ public class SetupData implements Parcelable {
|
|||
private int mCheckSettingsMode = 0;
|
||||
private boolean mAllowAutodiscover = true;
|
||||
private Policy mPolicy;
|
||||
private boolean mAutoSetup = false;
|
||||
private AccountAuthenticatorResponse mAccountAuthenticatorResponse = null;
|
||||
|
||||
// We only have one instance of SetupData; if/when the process is destroyed, this data will be
|
||||
// saved in the savedInstanceState Bundle
|
||||
private static SetupData INSTANCE = null;
|
||||
|
||||
public static synchronized SetupData getInstance() {
|
||||
if (INSTANCE == null) {
|
||||
INSTANCE = new SetupData();
|
||||
}
|
||||
return INSTANCE;
|
||||
public interface SetupDataContainer {
|
||||
public SetupData getSetupData();
|
||||
public void setSetupData(SetupData setupData);
|
||||
}
|
||||
|
||||
// Don't allow instantiation outside of this class
|
||||
private SetupData() {
|
||||
}
|
||||
|
||||
static public int getFlowMode() {
|
||||
return getInstance().mFlowMode;
|
||||
}
|
||||
|
||||
static public String getFlowAccountType() {
|
||||
return getInstance().mFlowAccountType;
|
||||
}
|
||||
|
||||
static public void setFlowMode(int mFlowMode) {
|
||||
getInstance().mFlowMode = mFlowMode;
|
||||
}
|
||||
|
||||
static public Account getAccount() {
|
||||
return getInstance().mAccount;
|
||||
}
|
||||
|
||||
static public void setAccount(Account mAccount) {
|
||||
getInstance().mAccount = mAccount;
|
||||
}
|
||||
|
||||
static public String getUsername() {
|
||||
return getInstance().mUsername;
|
||||
}
|
||||
|
||||
static public void setUsername(String mUsername) {
|
||||
getInstance().mUsername = mUsername;
|
||||
}
|
||||
|
||||
static public String getPassword() {
|
||||
return getInstance().mPassword;
|
||||
}
|
||||
|
||||
static public void setPassword(String mPassword) {
|
||||
getInstance().mPassword = mPassword;
|
||||
}
|
||||
|
||||
static public void setCheckSettingsMode(int mCheckSettingsMode) {
|
||||
getInstance().mCheckSettingsMode = mCheckSettingsMode;
|
||||
}
|
||||
|
||||
static public boolean isCheckIncoming() {
|
||||
return (getInstance().mCheckSettingsMode & CHECK_INCOMING) != 0;
|
||||
}
|
||||
|
||||
static public boolean isCheckOutgoing() {
|
||||
return (getInstance().mCheckSettingsMode & CHECK_OUTGOING) != 0;
|
||||
}
|
||||
static public boolean isCheckAutodiscover() {
|
||||
return (getInstance().mCheckSettingsMode & CHECK_AUTODISCOVER) != 0;
|
||||
}
|
||||
static public boolean isAllowAutodiscover() {
|
||||
return getInstance().mAllowAutodiscover;
|
||||
}
|
||||
|
||||
static public void setAllowAutodiscover(boolean mAllowAutodiscover) {
|
||||
getInstance().mAllowAutodiscover = mAllowAutodiscover;
|
||||
}
|
||||
|
||||
static public Policy getPolicy() {
|
||||
return getInstance().mPolicy;
|
||||
}
|
||||
|
||||
static public void setPolicy(Policy policy) {
|
||||
SetupData data = getInstance();
|
||||
data.mPolicy = policy;
|
||||
data.mAccount.mPolicy = policy;
|
||||
}
|
||||
|
||||
static public boolean isAutoSetup() {
|
||||
return getInstance().mAutoSetup;
|
||||
}
|
||||
|
||||
static public void setAutoSetup(boolean autoSetup) {
|
||||
getInstance().mAutoSetup = autoSetup;
|
||||
}
|
||||
|
||||
static public AccountAuthenticatorResponse getAccountAuthenticatorResponse() {
|
||||
return getInstance().mAccountAuthenticatorResponse;
|
||||
}
|
||||
|
||||
static public void setAccountAuthenticatorResponse(AccountAuthenticatorResponse response) {
|
||||
getInstance().mAccountAuthenticatorResponse = response;
|
||||
}
|
||||
|
||||
public static synchronized void init(SetupData setupData) {
|
||||
INSTANCE = setupData;
|
||||
}
|
||||
|
||||
public static void init(int flowMode) {
|
||||
SetupData data = getInstance();
|
||||
data.commonInit();
|
||||
data.mFlowMode = flowMode;
|
||||
}
|
||||
|
||||
public static void init(int flowMode, String accountType) {
|
||||
SetupData data = getInstance();
|
||||
data.commonInit();
|
||||
data.mFlowMode = flowMode;
|
||||
data.mFlowAccountType = accountType;
|
||||
}
|
||||
|
||||
public static void init(int flowMode, Account account) {
|
||||
SetupData data = getInstance();
|
||||
data.commonInit();
|
||||
data.mFlowMode = flowMode;
|
||||
data.mAccount = account;
|
||||
}
|
||||
|
||||
void commonInit() {
|
||||
public SetupData() {
|
||||
mPolicy = null;
|
||||
mAutoSetup = false;
|
||||
mAllowAutodiscover = true;
|
||||
mCheckSettingsMode = 0;
|
||||
mAccount = new Account();
|
||||
|
@ -193,6 +73,96 @@ public class SetupData implements Parcelable {
|
|||
mAccountAuthenticatorResponse = null;
|
||||
}
|
||||
|
||||
public SetupData(int flowMode) {
|
||||
this();
|
||||
mFlowMode = flowMode;
|
||||
}
|
||||
|
||||
public SetupData(int flowMode, String accountType) {
|
||||
this(flowMode);
|
||||
mFlowAccountType = accountType;
|
||||
}
|
||||
|
||||
public SetupData(int flowMode, Account account) {
|
||||
this(flowMode);
|
||||
mAccount = account;
|
||||
}
|
||||
|
||||
public int getFlowMode() {
|
||||
return mFlowMode;
|
||||
}
|
||||
|
||||
public String getFlowAccountType() {
|
||||
return mFlowAccountType;
|
||||
}
|
||||
|
||||
public void setFlowMode(int flowMode) {
|
||||
mFlowMode = flowMode;
|
||||
}
|
||||
|
||||
public Account getAccount() {
|
||||
return mAccount;
|
||||
}
|
||||
|
||||
public void setAccount(Account account) {
|
||||
mAccount = account;
|
||||
}
|
||||
|
||||
public String getUsername() {
|
||||
return mUsername;
|
||||
}
|
||||
|
||||
public void setUsername(String username) {
|
||||
mUsername = username;
|
||||
}
|
||||
|
||||
public String getPassword() {
|
||||
return mPassword;
|
||||
}
|
||||
|
||||
public void setPassword(String password) {
|
||||
mPassword = password;
|
||||
}
|
||||
|
||||
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 Policy getPolicy() {
|
||||
return mPolicy;
|
||||
}
|
||||
|
||||
public void setPolicy(Policy policy) {
|
||||
mPolicy = policy;
|
||||
mAccount.mPolicy = policy;
|
||||
}
|
||||
|
||||
public AccountAuthenticatorResponse getAccountAuthenticatorResponse() {
|
||||
return mAccountAuthenticatorResponse;
|
||||
}
|
||||
|
||||
public void setAccountAuthenticatorResponse(AccountAuthenticatorResponse response) {
|
||||
mAccountAuthenticatorResponse = response;
|
||||
}
|
||||
|
||||
// Parcelable methods
|
||||
@Override
|
||||
public int describeContents() {
|
||||
|
@ -221,12 +191,11 @@ public class SetupData implements Parcelable {
|
|||
dest.writeInt(mCheckSettingsMode);
|
||||
dest.writeInt(mAllowAutodiscover ? 1 : 0);
|
||||
dest.writeParcelable(mPolicy, 0);
|
||||
dest.writeInt(mAutoSetup ? 1 : 0);
|
||||
dest.writeParcelable(mAccountAuthenticatorResponse, 0);
|
||||
}
|
||||
|
||||
public SetupData(Parcel in) {
|
||||
ClassLoader loader = getClass().getClassLoader();
|
||||
final ClassLoader loader = getClass().getClassLoader();
|
||||
mFlowMode = in.readInt();
|
||||
mAccount = in.readParcelable(loader);
|
||||
mUsername = in.readString();
|
||||
|
@ -234,41 +203,29 @@ public class SetupData implements Parcelable {
|
|||
mCheckSettingsMode = in.readInt();
|
||||
mAllowAutodiscover = in.readInt() == 1;
|
||||
mPolicy = in.readParcelable(loader);
|
||||
mAutoSetup = in.readInt() == 1;
|
||||
mAccountAuthenticatorResponse = in.readParcelable(loader);
|
||||
}
|
||||
|
||||
// Save/restore our SetupData (used in AccountSetupActivity)
|
||||
static public void save(Bundle bundle) {
|
||||
bundle.putParcelable(EXTRA_SETUP_DATA, getInstance());
|
||||
}
|
||||
|
||||
static public synchronized SetupData restore(Bundle bundle) {
|
||||
if (bundle != null && bundle.containsKey(EXTRA_SETUP_DATA)) {
|
||||
INSTANCE = bundle.getParcelable(EXTRA_SETUP_DATA);
|
||||
return INSTANCE;
|
||||
} else {
|
||||
return getInstance();
|
||||
public String debugString() {
|
||||
final StringBuilder sb = new StringBuilder("SetupData");
|
||||
sb.append(":acct=");
|
||||
sb.append(mAccount == null ? "none" :mAccount.mId);
|
||||
if (mUsername != null) {
|
||||
sb.append(":user=");
|
||||
sb.append(mUsername);
|
||||
}
|
||||
}
|
||||
|
||||
public static String debugString() {
|
||||
StringBuilder sb = new StringBuilder("SetupData");
|
||||
SetupData data = getInstance();
|
||||
sb.append(":acct=" + (data.mAccount == null ? "none" : data.mAccount.mId));
|
||||
if (data.mUsername != null) {
|
||||
sb.append(":user=" + data.mUsername);
|
||||
if (mPassword != null) {
|
||||
sb.append(":pass=");
|
||||
sb.append(mPassword);
|
||||
}
|
||||
if (data.mPassword != null) {
|
||||
sb.append(":pass=" + data.mPassword);
|
||||
}
|
||||
sb.append(":a/d=" + data.mAllowAutodiscover);
|
||||
sb.append(":auto=" + data.mAutoSetup);
|
||||
sb.append(":a/d=");
|
||||
sb.append(mAllowAutodiscover);
|
||||
sb.append(":check=");
|
||||
if (SetupData.isCheckIncoming()) sb.append("in+");
|
||||
if (SetupData.isCheckOutgoing()) sb.append("out+");
|
||||
if (SetupData.isCheckAutodiscover()) sb.append("a/d");
|
||||
sb.append(":policy=" + (data.mPolicy == null ? "none" : "exists"));
|
||||
if (isCheckIncoming()) sb.append("in+");
|
||||
if (isCheckOutgoing()) sb.append("out+");
|
||||
if (isCheckAutodiscover()) sb.append("a/d");
|
||||
sb.append(":policy=");
|
||||
sb.append(mPolicy == null ? "none" : "exists");
|
||||
return sb.toString();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue