Clean up warnings, finals, dead and useless code

Change-Id: I8225a78c3b1712479bb5752161e3585a2bc2be2e
This commit is contained in:
Tony Mantler 2013-08-23 12:06:19 -07:00
parent 21b95c1071
commit ed4accb24f
6 changed files with 132 additions and 219 deletions

View File

@ -146,24 +146,6 @@ public class Utility {
}
return sb.toString();
}
public static String base64Decode(String encoded) {
if (encoded == null) {
return null;
}
byte[] decoded = Base64.decode(encoded, Base64.DEFAULT);
return new String(decoded);
}
public static String base64Encode(String s) {
if (s == null) {
return s;
}
return Base64.encodeToString(s.getBytes(), Base64.NO_WRAP);
}
public static boolean isTextViewNotEmpty(TextView view) {
return !TextUtils.isEmpty(view.getText());
}
public static boolean isPortFieldValid(TextView view) {
CharSequence chars = view.getText();

View File

@ -58,14 +58,6 @@ public class AccountCheckSettingsFragment extends Fragment {
public final static String TAG = "AccountCheckSettingsFragment";
// Debugging flags - for debugging the UI
// If true, use a "fake" account check cycle
private static final boolean DEBUG_FAKE_CHECK_CYCLE = false; // DO NOT CHECK IN TRUE
// If true, use fake check cycle, return failure
private static final boolean DEBUG_FAKE_CHECK_ERR = false; // DO NOT CHECK IN TRUE
// If true, use fake check cycle, return "security required"
private static final boolean DEBUG_FORCE_SECURITY_REQUIRED = false; // DO NOT CHECK IN TRUE
// State
private final static int STATE_START = 0;
private final static int STATE_CHECK_AUTODISCOVER = 1;
@ -131,7 +123,7 @@ public class AccountCheckSettingsFragment extends Fragment {
* @param mode incoming or outgoing
*/
public static AccountCheckSettingsFragment newInstance(int mode, Fragment parentFragment) {
AccountCheckSettingsFragment f = new AccountCheckSettingsFragment();
final AccountCheckSettingsFragment f = new AccountCheckSettingsFragment();
f.setTargetFragment(parentFragment, mode);
return f;
}
@ -159,8 +151,8 @@ public class AccountCheckSettingsFragment extends Fragment {
// If this is the first time, start the AsyncTask
if (mAccountCheckTask == null) {
int checkMode = getTargetRequestCode();
Account checkAccount = SetupData.getAccount();
final int checkMode = getTargetRequestCode();
final Account checkAccount = SetupData.getAccount();
mAccountCheckTask = (AccountCheckTask)
new AccountCheckTask(checkMode, checkAccount)
.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
@ -221,7 +213,7 @@ public class AccountCheckSettingsFragment extends Fragment {
// If we are attached, create, recover, and/or update the dialog
if (mAttached && !mPaused) {
FragmentManager fm = getFragmentManager();
final FragmentManager fm = getFragmentManager();
switch (newState) {
case STATE_CHECK_OK:
@ -263,7 +255,7 @@ public class AccountCheckSettingsFragment extends Fragment {
}
break;
case STATE_AUTODISCOVER_RESULT:
HostAuth autoDiscoverResult = ((AutoDiscoverResults) ex).mHostAuth;
final HostAuth autoDiscoverResult = ((AutoDiscoverResults) ex).mHostAuth;
// 1. get rid of progress dialog (if any)
recoverAndDismissCheckingDialog();
// 2. exit self
@ -293,7 +285,7 @@ public class AccountCheckSettingsFragment extends Fragment {
* Find the callback target, either a target fragment or the activity
*/
private Callbacks getCallbackTarget() {
Fragment target = getTargetFragment();
final Fragment target = getTargetFragment();
if (target instanceof Callbacks) {
return (Callbacks) target;
}
@ -344,7 +336,7 @@ public class AccountCheckSettingsFragment extends Fragment {
*/
private void onErrorDialogEditButton() {
// 1. handle "edit" - notify callback that we had a problem with the test
Callbacks callbackTarget = getCallbackTarget();
final Callbacks callbackTarget = getCallbackTarget();
if (mState == STATE_AUTODISCOVER_AUTH_DIALOG) {
// report auth error to target fragment or activity
callbackTarget.onAutoDiscoverComplete(AUTODISCOVER_AUTHENTICATION);
@ -357,7 +349,7 @@ public class AccountCheckSettingsFragment extends Fragment {
/** Kill self if not already killed. */
private void finish() {
FragmentManager fm = getFragmentManager();
final FragmentManager fm = getFragmentManager();
if (fm != null) {
fm.popBackStack();
}
@ -369,12 +361,12 @@ public class AccountCheckSettingsFragment extends Fragment {
*/
private void onSecurityRequiredDialogResultOk(boolean okPressed) {
// 1. handle OK/cancel - notify that security is OK and we can proceed
Callbacks callbackTarget = getCallbackTarget();
final Callbacks callbackTarget = getCallbackTarget();
callbackTarget.onCheckSettingsComplete(
okPressed ? CHECK_SETTINGS_OK : CHECK_SETTINGS_SECURITY_USER_DENY);
// 2. kill self if not already killed by callback
FragmentManager fm = getFragmentManager();
final FragmentManager fm = getFragmentManager();
if (fm != null) {
fm.popBackStack();
}
@ -432,17 +424,13 @@ public class AccountCheckSettingsFragment extends Fragment {
@Override
protected MessagingException doInBackground(Void... params) {
if (DEBUG_FAKE_CHECK_CYCLE) {
return fakeChecker();
}
try {
if ((mMode & SetupData.CHECK_AUTODISCOVER) != 0) {
if (isCancelled()) return null;
publishProgress(STATE_CHECK_AUTODISCOVER);
LogUtils.d(Logging.LOG_TAG, "Begin auto-discover for " + mCheckEmail);
Store store = Store.getInstance(mAccount, mContext);
Bundle result = store.autoDiscover(mContext, mCheckEmail, mCheckPassword);
final Store store = Store.getInstance(mAccount, mContext);
final Bundle result = store.autoDiscover(mContext, mCheckEmail, mCheckPassword);
// Result will be one of:
// null: remote exception - proceed to manual setup
// MessagingException.AUTHENTICATION_FAILED: username/password rejected
@ -458,7 +446,7 @@ public class AccountCheckSettingsFragment extends Fragment {
} else if (errorCode != MessagingException.NO_ERROR) {
return new AutoDiscoverResults(false, null);
} else {
HostAuth serverInfo = (HostAuth)
HostAuth serverInfo =
result.getParcelable(EmailServiceProxy.AUTO_DISCOVER_BUNDLE_HOST_AUTH);
return new AutoDiscoverResults(false, serverInfo);
}
@ -469,51 +457,52 @@ public class AccountCheckSettingsFragment extends Fragment {
if (isCancelled()) return null;
LogUtils.d(Logging.LOG_TAG, "Begin check of incoming email settings");
publishProgress(STATE_CHECK_INCOMING);
Store store = Store.getInstance(mAccount, mContext);
Bundle bundle = store.checkSettings();
int resultCode = MessagingException.UNSPECIFIED_EXCEPTION;
if (bundle != null) {
mAccount.mProtocolVersion = bundle.getString(
EmailServiceProxy.VALIDATE_BUNDLE_PROTOCOL_VERSION);
resultCode = bundle.getInt(
EmailServiceProxy.VALIDATE_BUNDLE_RESULT_CODE);
final String redirectAddress = bundle.getString(
EmailServiceProxy.VALIDATE_BUNDLE_REDIRECT_ADDRESS, null);
if (redirectAddress != null) {
mAccount.mHostAuthRecv.mAddress = redirectAddress;
}
// Only show "policies required" if this is a new account setup
if (resultCode == MessagingException.SECURITY_POLICIES_REQUIRED &&
mAccount.isSaved()) {
resultCode = MessagingException.NO_ERROR;
}
final Store store = Store.getInstance(mAccount, mContext);
final Bundle bundle = store.checkSettings();
if (bundle == null) {
return new MessagingException(MessagingException.UNSPECIFIED_EXCEPTION);
}
mAccount.mProtocolVersion = bundle.getString(
EmailServiceProxy.VALIDATE_BUNDLE_PROTOCOL_VERSION);
int resultCode = bundle.getInt(EmailServiceProxy.VALIDATE_BUNDLE_RESULT_CODE);
final String redirectAddress = bundle.getString(
EmailServiceProxy.VALIDATE_BUNDLE_REDIRECT_ADDRESS, null);
if (redirectAddress != null) {
mAccount.mHostAuthRecv.mAddress = redirectAddress;
}
// Only show "policies required" if this is a new account setup
if (resultCode == MessagingException.SECURITY_POLICIES_REQUIRED &&
mAccount.isSaved()) {
resultCode = MessagingException.NO_ERROR;
}
if (resultCode == MessagingException.SECURITY_POLICIES_REQUIRED) {
SetupData.setPolicy((Policy)bundle.getParcelable(
EmailServiceProxy.VALIDATE_BUNDLE_POLICY_SET));
return new MessagingException(resultCode, mStoreHost);
} else if (resultCode == MessagingException.SECURITY_POLICIES_UNSUPPORTED) {
Policy policy = (Policy)bundle.getParcelable(
final Policy policy = bundle.getParcelable(
EmailServiceProxy.VALIDATE_BUNDLE_POLICY_SET);
String unsupported = policy.mProtocolPoliciesUnsupported;
String[] data = unsupported.split("" + Policy.POLICY_STRING_DELIMITER);
final String unsupported = policy.mProtocolPoliciesUnsupported;
final String[] data =
unsupported.split("" + Policy.POLICY_STRING_DELIMITER);
return new MessagingException(resultCode, mStoreHost, data);
} else if (resultCode != MessagingException.NO_ERROR) {
String errorMessage =
bundle.getString(EmailServiceProxy.VALIDATE_BUNDLE_ERROR_MESSAGE);
final String errorMessage;
errorMessage = bundle.getString(
EmailServiceProxy.VALIDATE_BUNDLE_ERROR_MESSAGE);
return new MessagingException(resultCode, errorMessage);
}
}
String protocol = mAccount.mHostAuthRecv.mProtocol;
EmailServiceInfo info = EmailServiceUtils.getServiceInfo(mContext, protocol);
final String protocol = mAccount.mHostAuthRecv.mProtocol;
final EmailServiceInfo info = EmailServiceUtils.getServiceInfo(mContext, protocol);
// Check Outgoing Settings
if (info.usesSmtp && (mMode & SetupData.CHECK_OUTGOING) != 0) {
if (isCancelled()) return null;
LogUtils.d(Logging.LOG_TAG, "Begin check of outgoing email settings");
publishProgress(STATE_CHECK_OUTGOING);
Sender sender = Sender.getInstance(mContext, mAccount);
final Sender sender = Sender.getInstance(mContext, mAccount);
sender.close();
sender.open();
sender.close();
@ -528,53 +517,6 @@ public class AccountCheckSettingsFragment extends Fragment {
}
}
/**
* Dummy background worker, for testing UI only.
*/
private MessagingException fakeChecker() {
// Dummy: Publish a series of progress setups, 2 sec delays between them;
// then return "ok" (null)
final int DELAY = 2*1000;
if (isCancelled()) return null;
if ((mMode & SetupData.CHECK_AUTODISCOVER) != 0) {
publishProgress(STATE_CHECK_AUTODISCOVER);
try {
Thread.sleep(DELAY);
} catch (InterruptedException e) { }
if (DEBUG_FAKE_CHECK_ERR) {
return new MessagingException(MessagingException.AUTHENTICATION_FAILED);
}
// Return "real" AD results
HostAuth auth = new HostAuth();
auth.setLogin("user", "password");
auth.setConnection("eas", "testserver.com", 0);
return new AutoDiscoverResults(false, auth);
}
if (isCancelled()) return null;
if ((mMode & SetupData.CHECK_INCOMING) != 0) {
publishProgress(STATE_CHECK_INCOMING);
try {
Thread.sleep(DELAY);
} catch (InterruptedException e) { }
if (DEBUG_FAKE_CHECK_ERR) {
return new MessagingException(MessagingException.IOERROR);
} else if (DEBUG_FORCE_SECURITY_REQUIRED) {
return new MessagingException(MessagingException.SECURITY_POLICIES_REQUIRED);
}
}
if (isCancelled()) return null;
if ((mMode & SetupData.CHECK_OUTGOING) != 0) {
publishProgress(STATE_CHECK_OUTGOING);
try {
Thread.sleep(DELAY);
} catch (InterruptedException e) { }
if (DEBUG_FAKE_CHECK_ERR) {
return new MessagingException(MessagingException.TLS_REQUIRED);
}
}
return null;
}
/**
* Progress reports (runs in UI thread). This should be used for real progress only
* (not for errors).
@ -601,7 +543,7 @@ public class AccountCheckSettingsFragment extends Fragment {
reportProgress(STATE_CHECK_OK, null);
} else {
int progressState = STATE_CHECK_ERROR;
int exceptionType = result.getExceptionType();
final int exceptionType = result.getExceptionType();
switch (exceptionType) {
// NOTE: AutoDiscover reports have their own reporting state, handle differently
@ -664,7 +606,7 @@ public class AccountCheckSettingsFragment extends Fragment {
break;
}
// Build a string, concatenating policies we don't support
StringBuilder sb = new StringBuilder();
final StringBuilder sb = new StringBuilder();
boolean first = true;
for (String policyName: unsupportedPolicies) {
if (first) {
@ -726,7 +668,7 @@ public class AccountCheckSettingsFragment extends Fragment {
*/
public static CheckingDialog newInstance(AccountCheckSettingsFragment parentFragment,
int progress) {
CheckingDialog f = new CheckingDialog();
final CheckingDialog f = new CheckingDialog();
f.setTargetFragment(parentFragment, progress);
return f;
}
@ -737,7 +679,7 @@ public class AccountCheckSettingsFragment extends Fragment {
*/
public void updateProgress(int progress) {
mProgressString = getProgressString(progress);
AlertDialog dialog = (AlertDialog) getDialog();
final AlertDialog dialog = (AlertDialog) getDialog();
if (dialog != null && mProgressString != null) {
dialog.setMessage(mProgressString);
}
@ -745,7 +687,7 @@ public class AccountCheckSettingsFragment extends Fragment {
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
Context context = getActivity();
final Context context = getActivity();
if (savedInstanceState != null) {
mProgressString = savedInstanceState.getString(EXTRA_PROGRESS_STRING);
}
@ -755,7 +697,7 @@ public class AccountCheckSettingsFragment extends Fragment {
final AccountCheckSettingsFragment target =
(AccountCheckSettingsFragment) getTargetFragment();
ProgressDialog dialog = new ProgressDialog(context);
final ProgressDialog dialog = new ProgressDialog(context);
dialog.setIndeterminate(true);
dialog.setMessage(mProgressString);
dialog.setButton(DialogInterface.BUTTON_NEGATIVE,
@ -776,7 +718,7 @@ public class AccountCheckSettingsFragment extends Fragment {
*/
@Override
public void onCancel(DialogInterface dialog) {
AccountCheckSettingsFragment target =
final AccountCheckSettingsFragment target =
(AccountCheckSettingsFragment) getTargetFragment();
target.onCheckingDialogCancel();
super.onCancel(dialog);
@ -829,8 +771,8 @@ public class AccountCheckSettingsFragment extends Fragment {
public static ErrorDialog newInstance(Context context, AccountCheckSettingsFragment target,
MessagingException ex) {
ErrorDialog fragment = new ErrorDialog();
Bundle arguments = new Bundle();
final ErrorDialog fragment = new ErrorDialog();
final Bundle arguments = new Bundle(2);
arguments.putString(ARGS_MESSAGE, getErrorString(context, ex));
arguments.putInt(ARGS_EXCEPTION_ID, ex.getExceptionType());
fragment.setArguments(arguments);
@ -847,7 +789,7 @@ public class AccountCheckSettingsFragment extends Fragment {
final AccountCheckSettingsFragment target =
(AccountCheckSettingsFragment) getTargetFragment();
AlertDialog.Builder builder = new AlertDialog.Builder(context)
final AlertDialog.Builder builder = new AlertDialog.Builder(context)
.setIconAttribute(android.R.attr.alertDialogIcon)
.setTitle(context.getString(R.string.account_setup_failed_dlg_title))
.setMessage(message)
@ -915,8 +857,8 @@ public class AccountCheckSettingsFragment extends Fragment {
public static SecurityRequiredDialog newInstance(AccountCheckSettingsFragment target,
String hostName) {
SecurityRequiredDialog fragment = new SecurityRequiredDialog();
Bundle arguments = new Bundle();
final SecurityRequiredDialog fragment = new SecurityRequiredDialog();
final Bundle arguments = new Bundle(1);
arguments.putString(ARGS_HOST_NAME, hostName);
fragment.setArguments(arguments);
fragment.setTargetFragment(target, 0);

View File

@ -51,6 +51,7 @@ import com.android.emailcommon.provider.Account;
import com.android.emailcommon.provider.EmailContent;
import com.android.emailcommon.provider.HostAuth;
import com.android.emailcommon.service.ServiceProxy;
import com.android.emailcommon.utility.EmailAsyncTask;
import com.android.emailcommon.utility.Utility;
import com.android.mail.utils.LogUtils;
@ -123,13 +124,13 @@ public class AccountSetupBasics extends AccountSetupActivity
FutureTask<String> mOwnerLookupTask;
public static void actionNewAccount(Activity fromActivity) {
Intent i = new Intent(fromActivity, AccountSetupBasics.class);
final Intent i = new Intent(fromActivity, AccountSetupBasics.class);
i.putExtra(EXTRA_FLOW_MODE, SetupData.FLOW_MODE_NORMAL);
fromActivity.startActivity(i);
}
public static void actionNewAccountWithResult(Activity fromActivity) {
Intent i = new ForwardingIntent(fromActivity, AccountSetupBasics.class);
final Intent i = new ForwardingIntent(fromActivity, AccountSetupBasics.class);
i.putExtra(EXTRA_FLOW_MODE, SetupData.FLOW_MODE_NO_ACCOUNTS);
fromActivity.startActivity(i);
}
@ -139,7 +140,7 @@ public class AccountSetupBasics extends AccountSetupActivity
* for exchange accounts.
*/
public static Intent actionGetCreateAccountIntent(Context context, String accountManagerType) {
Intent i = new Intent(context, AccountSetupBasics.class);
final Intent i = new Intent(context, AccountSetupBasics.class);
i.putExtra(EXTRA_FLOW_MODE, SetupData.FLOW_MODE_ACCOUNT_MANAGER);
i.putExtra(EXTRA_FLOW_ACCOUNT_TYPE, accountManagerType);
return i;
@ -150,7 +151,7 @@ public class AccountSetupBasics extends AccountSetupActivity
// is not safe, since it's not guaranteed that an Activity will run with the Intent, and
// information can get lost.
Intent i= new ForwardingIntent(fromActivity, AccountSetupBasics.class);
final Intent i= new ForwardingIntent(fromActivity, AccountSetupBasics.class);
// If we're in the "account flow" (from AccountManager), we want to return to the caller
// (in the settings app)
SetupData.init(SetupData.FLOW_MODE_RETURN_TO_CALLER);
@ -163,27 +164,20 @@ public class AccountSetupBasics extends AccountSetupActivity
// is not safe, since it's not guaranteed that an Activity will run with the Intent, and
// information can get lost.
Intent i= new ForwardingIntent(fromActivity, AccountSetupBasics.class);
final Intent i= new ForwardingIntent(fromActivity, AccountSetupBasics.class);
// If we're in the "no accounts" flow, we want to return to the caller with a result
SetupData.init(SetupData.FLOW_MODE_RETURN_NO_ACCOUNTS_RESULT);
i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
fromActivity.startActivity(i);
}
@SuppressWarnings("deprecation")
public static void actionAccountCreateFinished(final Activity fromActivity,
final long accountId) {
Utility.runAsync(new Runnable() {
@Override
public void run() {
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
Account account = Account.restoreAccountWithId(fromActivity, accountId);
SetupData.init(SetupData.FLOW_MODE_RETURN_TO_MESSAGE_LIST, account);
i.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
fromActivity.startActivity(i);
}});
public static void actionAccountCreateFinished(final Activity fromActivity, Account account) {
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.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
fromActivity.startActivity(i);
}
@Override
@ -193,28 +187,27 @@ public class AccountSetupBasics extends AccountSetupActivity
// Check for forced account creation first, as it comes from an externally-generated
// intent and won't have any SetupData prepared.
Intent intent = getIntent();
String action = intent.getAction();
final Intent intent = getIntent();
final String action = intent.getAction();
SetupData intentData = null;
// See if we have SetupData to restore; if so, use it
if (savedInstanceState != null) {
intentData = savedInstanceState.getParcelable(STATE_KEY_SETUP_DATA);
}
final SetupData intentData = (SetupData) ((savedInstanceState != null)
? savedInstanceState.getParcelable(STATE_KEY_SETUP_DATA)
: null);
if (intentData != null) {
SetupData.init(intentData);
} else if (ServiceProxy.getIntentStringForEmailPackage(
this, ACTION_CREATE_ACCOUNT).equals(action)) {
SetupData.init(SetupData.FLOW_MODE_FORCE_CREATE);
} else {
int intentFlowMode =
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));
}
}
int flowMode = SetupData.getFlowMode();
final int flowMode = SetupData.getFlowMode();
if (flowMode == SetupData.FLOW_MODE_RETURN_TO_CALLER) {
// Return to the caller who initiated account creation
finish();
@ -228,7 +221,7 @@ public class AccountSetupBasics extends AccountSetupActivity
finish();
return;
} else if (flowMode == SetupData.FLOW_MODE_RETURN_TO_MESSAGE_LIST) {
Account account = SetupData.getAccount();
final Account account = SetupData.getAccount();
if (account != null && account.mId >= 0) {
// Show the message list for the new account
//***
@ -240,18 +233,16 @@ public class AccountSetupBasics extends AccountSetupActivity
setContentView(R.layout.account_setup_basics);
mEmailView = (EditText) UiUtilities.getView(this, R.id.account_email);
mPasswordView = (EditText) UiUtilities.getView(this, R.id.account_password);
mEmailView = UiUtilities.getView(this, R.id.account_email);
mPasswordView = UiUtilities.getView(this, R.id.account_password);
mEmailView.addTextChangedListener(this);
mPasswordView.addTextChangedListener(this);
boolean manualButtonDisplayed = true;
// Configure buttons
mManualButton = (Button) UiUtilities.getView(this, R.id.manual_setup);
mNextButton = (Button) UiUtilities.getView(this, R.id.next);
mManualButton.setVisibility(manualButtonDisplayed ? View.VISIBLE : View.INVISIBLE);
mManualButton = UiUtilities.getView(this, R.id.manual_setup);
mNextButton = UiUtilities.getView(this, R.id.next);
mManualButton.setVisibility(View.VISIBLE);
mManualButton.setOnClickListener(this);
mNextButton.setOnClickListener(this);
// Force disabled until validator notifies otherwise
@ -260,7 +251,7 @@ public class AccountSetupBasics extends AccountSetupActivity
mNextButtonInhibit = false;
// Set aside incoming AccountAuthenticatorResponse, if there was any
AccountAuthenticatorResponse authenticatorResponse =
final AccountAuthenticatorResponse authenticatorResponse =
getIntent().getParcelableExtra(AccountManager.KEY_ACCOUNT_AUTHENTICATOR_RESPONSE);
SetupData.setAccountAuthenticatorResponse(authenticatorResponse);
if (authenticatorResponse != null) {
@ -273,12 +264,12 @@ public class AccountSetupBasics extends AccountSetupActivity
}
// Load fields, but only once
String userName = SetupData.getUsername();
final String userName = SetupData.getUsername();
if (userName != null) {
mEmailView.setText(userName);
SetupData.setUsername(null);
}
String password = SetupData.getPassword();
final String password = SetupData.getPassword();
if (userName != null) {
mPasswordView.setText(password);
SetupData.setPassword(null);
@ -294,10 +285,10 @@ public class AccountSetupBasics extends AccountSetupActivity
finish();
return;
}
String email = intent.getStringExtra(EXTRA_CREATE_ACCOUNT_EMAIL);
String user = intent.getStringExtra(EXTRA_CREATE_ACCOUNT_USER);
String incoming = intent.getStringExtra(EXTRA_CREATE_ACCOUNT_INCOMING);
String outgoing = intent.getStringExtra(EXTRA_CREATE_ACCOUNT_OUTGOING);
final String email = intent.getStringExtra(EXTRA_CREATE_ACCOUNT_EMAIL);
final String user = intent.getStringExtra(EXTRA_CREATE_ACCOUNT_USER);
final String incoming = intent.getStringExtra(EXTRA_CREATE_ACCOUNT_INCOMING);
final String outgoing = intent.getStringExtra(EXTRA_CREATE_ACCOUNT_OUTGOING);
if (TextUtils.isEmpty(email) || TextUtils.isEmpty(user) ||
TextUtils.isEmpty(incoming) || TextUtils.isEmpty(outgoing)) {
LogUtils.e(Logging.LOG_TAG, "ERROR: Force account create requires extras EMAIL, " +
@ -317,7 +308,7 @@ public class AccountSetupBasics extends AccountSetupActivity
// Launch a worker to look up the owner name. It should be ready well in advance of
// the time the user clicks next or manual.
mOwnerLookupTask = new FutureTask<String>(mOwnerLookupCallable);
Utility.runAsync(mOwnerLookupTask);
EmailAsyncTask.runAsyncParallel(mOwnerLookupTask);
}
@Override
@ -337,7 +328,7 @@ public class AccountSetupBasics extends AccountSetupActivity
// 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.
if (mReportAccountAuthenticatorError) {
AccountAuthenticatorResponse authenticatorResponse =
final AccountAuthenticatorResponse authenticatorResponse =
SetupData.getAccountAuthenticatorResponse();
if (authenticatorResponse != null) {
authenticatorResponse.onError(AccountManager.ERROR_CODE_CANCELED, "canceled");
@ -399,8 +390,8 @@ public class AccountSetupBasics extends AccountSetupActivity
}
private void validateFields() {
boolean valid = Utility.isTextViewNotEmpty(mEmailView)
&& Utility.isTextViewNotEmpty(mPasswordView)
final boolean valid = !TextUtils.isEmpty(mEmailView.getText())
&& !TextUtils.isEmpty(mPasswordView.getText())
&& mEmailValidator.isValid(mEmailView.getText().toString().trim());
onEnableProceedButtons(valid);
@ -412,13 +403,13 @@ public class AccountSetupBasics extends AccountSetupActivity
* Return an existing username if found, or null. This is the result of the Callable (below).
*/
private String getOwnerName() {
String result = null;
try {
result = mOwnerLookupTask.get();
return mOwnerLookupTask.get();
} catch (InterruptedException e) {
return null;
} catch (ExecutionException e) {
return null;
}
return result;
}
/**
@ -448,22 +439,22 @@ public class AccountSetupBasics extends AccountSetupActivity
* Finish the auto setup process, in some cases after showing a warning dialog.
*/
private void finishAutoSetup() {
String email = mEmailView.getText().toString().trim();
String password = mPasswordView.getText().toString();
final String email = mEmailView.getText().toString().trim();
final String password = mPasswordView.getText().toString();
try {
mProvider.expandTemplates(email);
Account account = SetupData.getAccount();
HostAuth recvAuth = account.getOrCreateHostAuthRecv(this);
final Account account = SetupData.getAccount();
final HostAuth recvAuth = account.getOrCreateHostAuthRecv(this);
HostAuth.setHostAuthFromString(recvAuth, mProvider.incomingUri);
recvAuth.setLogin(mProvider.incomingUsername, password);
EmailServiceInfo info = EmailServiceUtils.getServiceInfo(this, recvAuth.mProtocol);
final EmailServiceInfo info = EmailServiceUtils.getServiceInfo(this, recvAuth.mProtocol);
recvAuth.mPort =
((recvAuth.mFlags & HostAuth.FLAG_SSL) != 0) ? info.portSsl : info.port;
HostAuth sendAuth = account.getOrCreateHostAuthSend(this);
final HostAuth sendAuth = account.getOrCreateHostAuthSend(this);
HostAuth.setHostAuthFromString(sendAuth, mProvider.outgoingUri);
sendAuth.setLogin(mProvider.outgoingUsername, password);
@ -504,9 +495,7 @@ public class AccountSetupBasics extends AccountSetupActivity
@Override
protected Account doInBackground(Void... params) {
Account account = Utility.findExistingAccount(mContext, -1,
mCheckHost, mCheckLogin);
return account;
return Utility.findExistingAccount(mContext, -1, mCheckHost, mCheckLogin);
}
@Override
@ -516,15 +505,14 @@ public class AccountSetupBasics extends AccountSetupActivity
if (mPaused) return;
// Show duplicate account warning, or proceed
if (duplicateAccount != null) {
DuplicateAccountDialogFragment dialogFragment =
final DuplicateAccountDialogFragment dialogFragment =
DuplicateAccountDialogFragment.newInstance(duplicateAccount.mDisplayName);
dialogFragment.show(getFragmentManager(), DuplicateAccountDialogFragment.TAG);
return;
} else {
AccountCheckSettingsFragment checkerFragment =
final AccountCheckSettingsFragment checkerFragment =
AccountCheckSettingsFragment.newInstance(
SetupData.CHECK_INCOMING | SetupData.CHECK_OUTGOING, null);
FragmentTransaction transaction = getFragmentManager().beginTransaction();
final FragmentTransaction transaction = getFragmentManager().beginTransaction();
transaction.add(checkerFragment, AccountCheckSettingsFragment.TAG);
transaction.addToBackStack("back");
transaction.commit();
@ -537,14 +525,14 @@ public class AccountSetupBasics extends AccountSetupActivity
*/
private void onNext() {
// Try auto-configuration from XML providers (unless in EAS mode, we can skip it)
String email = mEmailView.getText().toString().trim();
String[] emailParts = email.split("@");
String domain = emailParts[1].trim();
final String email = mEmailView.getText().toString().trim();
final String[] emailParts = email.split("@");
final String domain = emailParts[1].trim();
mProvider = AccountSettingsUtils.findProviderForDomain(this, domain);
if (mProvider != null) {
mProvider.expandTemplates(email);
if (mProvider.note != null) {
NoteDialogFragment dialogFragment =
final NoteDialogFragment dialogFragment =
NoteDialogFragment.newInstance(mProvider.note);
dialogFragment.show(getFragmentManager(), NoteDialogFragment.TAG);
} else {
@ -564,11 +552,11 @@ public class AccountSetupBasics extends AccountSetupActivity
* Ignored for IMAP & POP accounts.
*/
private void onManualSetup(boolean allowAutoDiscover) {
String email = mEmailView.getText().toString().trim();
String password = mPasswordView.getText().toString();
String[] emailParts = email.split("@");
String user = emailParts[0].trim();
String domain = emailParts[1].trim();
final String email = mEmailView.getText().toString().trim();
final String password = mPasswordView.getText().toString();
final String[] emailParts = email.split("@");
final String user = emailParts[0].trim();
final String domain = emailParts[1].trim();
// Alternate entry to the debug options screen (for devices without a physical keyboard:
// Username: d@d.d
@ -580,12 +568,12 @@ public class AccountSetupBasics extends AccountSetupActivity
return;
}
Account account = SetupData.getAccount();
HostAuth recvAuth = account.getOrCreateHostAuthRecv(this);
final Account account = SetupData.getAccount();
final HostAuth recvAuth = account.getOrCreateHostAuthRecv(this);
recvAuth.setLogin(user, password);
recvAuth.setConnection(null, domain, HostAuth.PORT_UNKNOWN, HostAuth.FLAG_NONE);
HostAuth sendAuth = account.getOrCreateHostAuthSend(this);
final HostAuth sendAuth = account.getOrCreateHostAuthSend(this);
sendAuth.setLogin(user, password);
sendAuth.setConnection(null, domain, HostAuth.PORT_UNKNOWN, HostAuth.FLAG_NONE);
@ -609,10 +597,10 @@ public class AccountSetupBasics extends AccountSetupActivity
private void forceCreateAccount(String email, String user, String incoming, String outgoing) {
Account account = SetupData.getAccount();
try {
HostAuth recvAuth = account.getOrCreateHostAuthRecv(this);
final HostAuth recvAuth = account.getOrCreateHostAuthRecv(this);
HostAuth.setHostAuthFromString(recvAuth, incoming);
HostAuth sendAuth = account.getOrCreateHostAuthSend(this);
final HostAuth sendAuth = account.getOrCreateHostAuthSend(this);
HostAuth.setHostAuthFromString(sendAuth, outgoing);
populateSetupData(user, email);
@ -624,9 +612,9 @@ public class AccountSetupBasics extends AccountSetupActivity
}
public static void setDefaultsForProtocol(Context context, Account account) {
String protocol = account.mHostAuthRecv.mProtocol;
final String protocol = account.mHostAuthRecv.mProtocol;
if (protocol == null) return;
EmailServiceInfo info = EmailServiceUtils.getServiceInfo(context, protocol);
final EmailServiceInfo info = EmailServiceUtils.getServiceInfo(context, protocol);
account.mSyncInterval = info.defaultSyncInterval;
account.mSyncLookback = info.defaultLookback;
if (info.offerLocalDeletes) {
@ -638,7 +626,7 @@ public class AccountSetupBasics extends AccountSetupActivity
* Populate SetupData's account with complete setup info.
*/
private void populateSetupData(String senderName, String senderEmail) {
Account account = SetupData.getAccount();
final Account account = SetupData.getAccount();
account.setSenderName(senderName);
account.setEmailAddress(senderEmail);
account.setDisplayName(senderEmail);
@ -692,8 +680,8 @@ public class AccountSetupBasics extends AccountSetupActivity
* Create the dialog with parameters
*/
public static NoteDialogFragment newInstance(String note) {
NoteDialogFragment f = new NoteDialogFragment();
Bundle b = new Bundle();
final NoteDialogFragment f = new NoteDialogFragment();
final Bundle b = new Bundle(1);
b.putString(BUNDLE_KEY_NOTE, note);
f.setArguments(b);
return f;
@ -701,7 +689,7 @@ public class AccountSetupBasics extends AccountSetupActivity
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
Context context = getActivity();
final Context context = getActivity();
final String note = getArguments().getString(BUNDLE_KEY_NOTE);
return new AlertDialog.Builder(context)
@ -713,7 +701,7 @@ public class AccountSetupBasics extends AccountSetupActivity
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Activity a = getActivity();
final Activity a = getActivity();
if (a instanceof AccountSetupBasics) {
((AccountSetupBasics)a).finishAutoSetup();
}

View File

@ -409,8 +409,8 @@ public class AccountSetupIncomingFragment extends AccountServerBaseFragment
*/
private void validateFields() {
if (!mLoaded) return;
boolean enabled = Utility.isTextViewNotEmpty(mUsernameView)
&& Utility.isTextViewNotEmpty(mPasswordView)
final boolean enabled = !TextUtils.isEmpty(mUsernameView.getText())
&& !TextUtils.isEmpty(mPasswordView.getText())
&& Utility.isServerNameValid(mServerView)
&& Utility.isPortFieldValid(mPortView);
enableNextButton(enabled);

View File

@ -67,10 +67,10 @@ public class AccountSetupNames extends AccountSetupActivity implements OnClickLi
super.onCreate(savedInstanceState);
ActivityHelper.debugSetWindowFlags(this);
setContentView(R.layout.account_setup_names);
mDescription = (EditText) UiUtilities.getView(this, R.id.account_description);
mName = (EditText) UiUtilities.getView(this, R.id.account_name);
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);
mNextButton = (Button) UiUtilities.getView(this, R.id.next);
mNextButton = UiUtilities.getView(this, R.id.next);
mNextButton.setOnClickListener(this);
TextWatcher validationTextWatcher = new TextWatcher() {
@ -199,7 +199,7 @@ public class AccountSetupNames extends AccountSetupActivity implements OnClickLi
} else {
Account account = SetupData.getAccount();
if (account != null) {
AccountSetupBasics.actionAccountCreateFinished(this, account.mId);
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

View File

@ -20,6 +20,7 @@ import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextUtils;
import android.text.TextWatcher;
import android.text.method.DigitsKeyListener;
import android.view.LayoutInflater;
@ -307,8 +308,8 @@ public class AccountSetupOutgoingFragment extends AccountServerBaseFragment
Utility.isServerNameValid(mServerView) && Utility.isPortFieldValid(mPortView);
if (enabled && mRequireLoginView.isChecked()) {
enabled = (Utility.isTextViewNotEmpty(mUsernameView)
&& Utility.isTextViewNotEmpty(mPasswordView));
enabled = !TextUtils.isEmpty(mUsernameView.getText())
&& !TextUtils.isEmpty(mPasswordView.getText());
}
enableNextButton(enabled);
// Warn (but don't prevent) if password has leading/trailing spaces