2010-07-08 17:08:47 +00:00
|
|
|
package com.android.email.activity.setup;
|
|
|
|
|
2013-12-06 00:25:01 +00:00
|
|
|
import android.app.Fragment;
|
2010-07-08 17:08:47 +00:00
|
|
|
import android.os.Bundle;
|
|
|
|
import android.os.Parcel;
|
|
|
|
import android.os.Parcelable;
|
|
|
|
|
2012-06-28 17:40:46 +00:00
|
|
|
import com.android.emailcommon.provider.Account;
|
|
|
|
import com.android.emailcommon.provider.Policy;
|
|
|
|
|
2013-12-06 00:25:01 +00:00
|
|
|
/**
|
|
|
|
* Headless fragment to hold setup data for the account setup or settings flows
|
|
|
|
*/
|
|
|
|
public class SetupDataFragment extends Fragment implements Parcelable {
|
2010-07-08 17:08:47 +00:00
|
|
|
// The "extra" name for the Bundle saved with SetupData
|
|
|
|
public static final String EXTRA_SETUP_DATA = "com.android.email.setupdata";
|
|
|
|
|
|
|
|
// NORMAL is the standard entry from the Email app; EAS and POP_IMAP are used when entering via
|
|
|
|
// Settings -> Accounts
|
2011-10-20 21:08:20 +00:00
|
|
|
public static final int FLOW_MODE_UNSPECIFIED = -1;
|
2010-07-08 17:08:47 +00:00
|
|
|
public static final int FLOW_MODE_NORMAL = 0;
|
2012-06-28 17:40:46 +00:00
|
|
|
public static final int FLOW_MODE_ACCOUNT_MANAGER = 1;
|
2010-07-08 17:08:47 +00:00
|
|
|
public static final int FLOW_MODE_EDIT = 3;
|
2010-12-05 06:53:59 +00:00
|
|
|
public static final int FLOW_MODE_FORCE_CREATE = 4;
|
2010-07-08 17:08:47 +00:00
|
|
|
// The following two modes are used to "pop the stack" and return from the setup flow. We
|
|
|
|
// either return to the caller (if we're in an account type flow) or go to the message list
|
2014-02-13 21:12:06 +00:00
|
|
|
// TODO: figure out if we still care about these
|
2010-12-05 06:53:59 +00:00
|
|
|
public static final int FLOW_MODE_RETURN_TO_CALLER = 5;
|
|
|
|
public static final int FLOW_MODE_RETURN_TO_MESSAGE_LIST = 6;
|
2012-06-28 17:40:46 +00:00
|
|
|
public static final int FLOW_MODE_RETURN_NO_ACCOUNTS_RESULT = 7;
|
|
|
|
public static final int FLOW_MODE_NO_ACCOUNTS = 8;
|
2010-07-08 17:08:47 +00:00
|
|
|
|
|
|
|
// Mode bits for AccountSetupCheckSettings, indicating the type of check requested
|
|
|
|
public static final int CHECK_INCOMING = 1;
|
|
|
|
public static final int CHECK_OUTGOING = 2;
|
|
|
|
public static final int CHECK_AUTODISCOVER = 4;
|
|
|
|
|
2014-02-13 21:12:06 +00:00
|
|
|
private static final String SAVESTATE_FLOWMODE = "SetupDataFragment.flowMode";
|
|
|
|
private static final String SAVESTATE_ACCOUNT = "SetupDataFragment.account";
|
|
|
|
private static final String SAVESTATE_EMAIL = "SetupDataFragment.email";
|
|
|
|
private static final String SAVESTATE_CREDENTIAL = "SetupDataFragment.credential";
|
|
|
|
private static final String SAVESTATE_INCOMING_LOADED = "SetupDataFragment.incomingLoaded";
|
|
|
|
private static final String SAVESTATE_OUTGOING_LOADED = "SetupDataFragment.outgoingLoaded";
|
|
|
|
private static final String SAVESTATE_POLICY = "SetupDataFragment.policy";
|
2013-12-06 00:25:01 +00:00
|
|
|
|
2010-07-08 17:08:47 +00:00
|
|
|
// All access will be through getters/setters
|
|
|
|
private int mFlowMode = FLOW_MODE_NORMAL;
|
|
|
|
private Account mAccount;
|
2014-02-13 21:12:06 +00:00
|
|
|
private String mEmail;
|
|
|
|
private Bundle mCredentialResults;
|
|
|
|
// These are used to track whether we've preloaded the login credentials into incoming/outgoing
|
|
|
|
// settings. Set them to 'true' by default, and false when we change the credentials or email
|
|
|
|
private boolean mIncomingCredLoaded = true;
|
|
|
|
private boolean mOutgoingCredLoaded = true;
|
|
|
|
// This is accessed off-thread in AccountCheckSettingsFragment
|
|
|
|
private volatile Policy mPolicy;
|
2010-07-08 17:08:47 +00:00
|
|
|
|
2013-08-30 22:48:35 +00:00
|
|
|
public interface SetupDataContainer {
|
2013-12-06 00:25:01 +00:00
|
|
|
public SetupDataFragment getSetupData();
|
2010-07-08 17:08:47 +00:00
|
|
|
}
|
|
|
|
|
2013-12-06 00:25:01 +00:00
|
|
|
public SetupDataFragment() {
|
2013-08-30 22:48:35 +00:00
|
|
|
mPolicy = null;
|
|
|
|
mAccount = new Account();
|
2014-02-13 21:12:06 +00:00
|
|
|
mEmail = null;
|
|
|
|
mCredentialResults = null;
|
2010-07-08 17:08:47 +00:00
|
|
|
}
|
|
|
|
|
2013-12-06 00:25:01 +00:00
|
|
|
public SetupDataFragment(int flowMode) {
|
2013-08-30 22:48:35 +00:00
|
|
|
this();
|
|
|
|
mFlowMode = flowMode;
|
2012-06-28 17:40:46 +00:00
|
|
|
}
|
|
|
|
|
2013-12-06 00:25:01 +00:00
|
|
|
public SetupDataFragment(int flowMode, Account account) {
|
2013-08-30 22:48:35 +00:00
|
|
|
this(flowMode);
|
|
|
|
mAccount = account;
|
2010-07-08 17:08:47 +00:00
|
|
|
}
|
|
|
|
|
2013-12-06 00:25:01 +00:00
|
|
|
@Override
|
|
|
|
public void onSaveInstanceState(Bundle outState) {
|
|
|
|
super.onSaveInstanceState(outState);
|
|
|
|
outState.putInt(SAVESTATE_FLOWMODE, mFlowMode);
|
|
|
|
outState.putParcelable(SAVESTATE_ACCOUNT, mAccount);
|
2014-02-13 21:12:06 +00:00
|
|
|
outState.putString(SAVESTATE_EMAIL, mEmail);
|
|
|
|
outState.putParcelable(SAVESTATE_CREDENTIAL, mCredentialResults);
|
|
|
|
outState.putBoolean(SAVESTATE_INCOMING_LOADED, mIncomingCredLoaded);
|
|
|
|
outState.putBoolean(SAVESTATE_OUTGOING_LOADED, mOutgoingCredLoaded);
|
2013-12-06 00:25:01 +00:00
|
|
|
outState.putParcelable(SAVESTATE_POLICY, mPolicy);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onCreate(Bundle savedInstanceState) {
|
|
|
|
super.onCreate(savedInstanceState);
|
|
|
|
if (savedInstanceState != null) {
|
|
|
|
mFlowMode = savedInstanceState.getInt(SAVESTATE_FLOWMODE);
|
|
|
|
mAccount = savedInstanceState.getParcelable(SAVESTATE_ACCOUNT);
|
2014-02-13 21:12:06 +00:00
|
|
|
mEmail = savedInstanceState.getString(SAVESTATE_EMAIL);
|
|
|
|
mCredentialResults = savedInstanceState.getParcelable(SAVESTATE_CREDENTIAL);
|
|
|
|
mIncomingCredLoaded = savedInstanceState.getBoolean(SAVESTATE_INCOMING_LOADED);
|
|
|
|
mOutgoingCredLoaded = savedInstanceState.getBoolean(SAVESTATE_OUTGOING_LOADED);
|
2013-12-06 00:25:01 +00:00
|
|
|
mPolicy = savedInstanceState.getParcelable(SAVESTATE_POLICY);
|
|
|
|
}
|
|
|
|
setRetainInstance(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Getters and setters
|
2013-08-30 22:48:35 +00:00
|
|
|
public int getFlowMode() {
|
|
|
|
return mFlowMode;
|
2010-07-08 17:08:47 +00:00
|
|
|
}
|
|
|
|
|
2013-12-06 00:25:01 +00:00
|
|
|
public void setFlowMode(int flowMode) {
|
|
|
|
mFlowMode = flowMode;
|
|
|
|
}
|
|
|
|
|
2013-08-30 22:48:35 +00:00
|
|
|
public Account getAccount() {
|
|
|
|
return mAccount;
|
2010-07-08 17:08:47 +00:00
|
|
|
}
|
|
|
|
|
2013-08-30 22:48:35 +00:00
|
|
|
public void setAccount(Account account) {
|
|
|
|
mAccount = account;
|
2010-07-08 17:08:47 +00:00
|
|
|
}
|
|
|
|
|
2014-02-13 21:12:06 +00:00
|
|
|
public String getEmail() {
|
|
|
|
return mEmail;
|
2010-07-08 17:08:47 +00:00
|
|
|
}
|
|
|
|
|
2014-02-13 21:12:06 +00:00
|
|
|
public void setEmail(String email) {
|
|
|
|
mEmail = email;
|
|
|
|
mAccount.mEmailAddress = email;
|
|
|
|
mIncomingCredLoaded = false;
|
|
|
|
mOutgoingCredLoaded = false;
|
2010-07-08 17:08:47 +00:00
|
|
|
}
|
|
|
|
|
2014-02-13 21:12:06 +00:00
|
|
|
public Bundle getCredentialResults() {
|
|
|
|
return mCredentialResults;
|
2010-07-08 17:08:47 +00:00
|
|
|
}
|
|
|
|
|
2014-02-13 21:12:06 +00:00
|
|
|
public void setCredentialResults(Bundle credentialResults) {
|
|
|
|
mCredentialResults = credentialResults;
|
|
|
|
mIncomingCredLoaded = false;
|
|
|
|
mOutgoingCredLoaded = false;
|
2010-07-08 17:08:47 +00:00
|
|
|
}
|
|
|
|
|
2014-02-13 21:12:06 +00:00
|
|
|
public boolean isIncomingCredLoaded() {
|
|
|
|
return mIncomingCredLoaded;
|
2010-07-08 17:08:47 +00:00
|
|
|
}
|
|
|
|
|
2014-02-13 21:12:06 +00:00
|
|
|
public void setIncomingCredLoaded(boolean incomingCredLoaded) {
|
|
|
|
mIncomingCredLoaded = incomingCredLoaded;
|
2010-07-08 17:08:47 +00:00
|
|
|
}
|
|
|
|
|
2014-02-13 21:12:06 +00:00
|
|
|
public boolean isOutgoingCredLoaded() {
|
|
|
|
return mOutgoingCredLoaded;
|
2011-01-26 19:16:56 +00:00
|
|
|
}
|
|
|
|
|
2014-02-13 21:12:06 +00:00
|
|
|
public void setOutgoingCredLoaded(boolean outgoingCredLoaded) {
|
|
|
|
mOutgoingCredLoaded = outgoingCredLoaded;
|
2011-01-26 19:16:56 +00:00
|
|
|
}
|
|
|
|
|
2014-02-13 21:12:06 +00:00
|
|
|
public synchronized Policy getPolicy() {
|
2013-08-30 22:48:35 +00:00
|
|
|
return mPolicy;
|
2012-08-17 23:04:05 +00:00
|
|
|
}
|
|
|
|
|
2014-02-13 21:12:06 +00:00
|
|
|
public synchronized void setPolicy(Policy policy) {
|
2013-08-30 22:48:35 +00:00
|
|
|
mPolicy = policy;
|
2010-07-08 17:08:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Parcelable methods
|
2012-06-28 17:40:46 +00:00
|
|
|
@Override
|
2010-07-08 17:08:47 +00:00
|
|
|
public int describeContents() {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-12-06 00:25:01 +00:00
|
|
|
public static final Parcelable.Creator<SetupDataFragment> CREATOR =
|
|
|
|
new Parcelable.Creator<SetupDataFragment>() {
|
|
|
|
@Override
|
|
|
|
public SetupDataFragment createFromParcel(Parcel in) {
|
|
|
|
return new SetupDataFragment(in);
|
|
|
|
}
|
2010-07-08 17:08:47 +00:00
|
|
|
|
2013-12-06 00:25:01 +00:00
|
|
|
@Override
|
|
|
|
public SetupDataFragment[] newArray(int size) {
|
|
|
|
return new SetupDataFragment[size];
|
|
|
|
}
|
|
|
|
};
|
2010-07-08 17:08:47 +00:00
|
|
|
|
2012-06-28 17:40:46 +00:00
|
|
|
@Override
|
2010-07-08 17:08:47 +00:00
|
|
|
public void writeToParcel(Parcel dest, int flags) {
|
|
|
|
dest.writeInt(mFlowMode);
|
|
|
|
dest.writeParcelable(mAccount, 0);
|
2014-02-13 21:12:06 +00:00
|
|
|
dest.writeString(mEmail);
|
|
|
|
dest.writeParcelable(mCredentialResults, 0);
|
|
|
|
dest.writeBooleanArray(new boolean[] {mIncomingCredLoaded, mOutgoingCredLoaded});
|
2011-04-28 00:12:06 +00:00
|
|
|
dest.writeParcelable(mPolicy, 0);
|
2010-07-08 17:08:47 +00:00
|
|
|
}
|
|
|
|
|
2013-12-06 00:25:01 +00:00
|
|
|
public SetupDataFragment(Parcel in) {
|
2013-08-30 22:48:35 +00:00
|
|
|
final ClassLoader loader = getClass().getClassLoader();
|
2010-07-08 17:08:47 +00:00
|
|
|
mFlowMode = in.readInt();
|
2010-11-01 20:36:42 +00:00
|
|
|
mAccount = in.readParcelable(loader);
|
2014-02-13 21:12:06 +00:00
|
|
|
mEmail = in.readString();
|
|
|
|
mCredentialResults = in.readParcelable(loader);
|
|
|
|
final boolean[] credsLoaded = in.createBooleanArray();
|
|
|
|
mIncomingCredLoaded = credsLoaded[0];
|
|
|
|
mOutgoingCredLoaded = credsLoaded[1];
|
2011-04-28 00:12:06 +00:00
|
|
|
mPolicy = in.readParcelable(loader);
|
2010-07-08 17:08:47 +00:00
|
|
|
}
|
|
|
|
|
2014-02-13 21:12:06 +00:00
|
|
|
@Override
|
|
|
|
public String toString() {
|
2013-08-30 22:48:35 +00:00
|
|
|
final StringBuilder sb = new StringBuilder("SetupData");
|
|
|
|
sb.append(":acct=");
|
|
|
|
sb.append(mAccount == null ? "none" :mAccount.mId);
|
2014-02-13 21:12:06 +00:00
|
|
|
if (mEmail != null) {
|
2013-08-30 22:48:35 +00:00
|
|
|
sb.append(":user=");
|
2014-02-13 21:12:06 +00:00
|
|
|
sb.append(mEmail);
|
2010-07-08 17:08:47 +00:00
|
|
|
}
|
2014-02-13 21:12:06 +00:00
|
|
|
if (mCredentialResults != null) {
|
|
|
|
sb.append(":cred=");
|
|
|
|
sb.append(mCredentialResults.toString());
|
2010-07-08 17:08:47 +00:00
|
|
|
}
|
2013-08-30 22:48:35 +00:00
|
|
|
sb.append(":policy=");
|
|
|
|
sb.append(mPolicy == null ? "none" : "exists");
|
2010-07-08 17:08:47 +00:00
|
|
|
return sb.toString();
|
|
|
|
}
|
2013-12-06 00:25:01 +00:00
|
|
|
|
2010-07-08 17:08:47 +00:00
|
|
|
}
|