AccountSetupCheckSettingspublic class AccountSetupCheckSettings extends android.app.Activity implements android.view.View.OnClickListenerChecks the given settings to make sure that they can be used to send and
receive mail.
XXX NOTE: The manifest for this app has it ignore config changes, because
it doesn't correctly deal with restarting while its thread is running. |
Fields Summary |
---|
private static final String | EXTRA_ACCOUNT | private static final String | EXTRA_CHECK_INCOMING | private static final String | EXTRA_CHECK_OUTGOING | private android.os.Handler | mHandler | private android.widget.ProgressBar | mProgressBar | private android.widget.TextView | mMessageView | private com.android.email.Account | mAccount | private boolean | mCheckIncoming | private boolean | mCheckOutgoing | private boolean | mCanceled | private boolean | mDestroyed |
Methods Summary |
---|
public static void | actionCheckSettings(android.app.Activity context, com.android.email.Account account, boolean checkIncoming, boolean checkOutgoing)
Intent i = new Intent(context, AccountSetupCheckSettings.class);
i.putExtra(EXTRA_ACCOUNT, account);
i.putExtra(EXTRA_CHECK_INCOMING, checkIncoming);
i.putExtra(EXTRA_CHECK_OUTGOING, checkOutgoing);
context.startActivityForResult(i, 1);
| private void | onCancel()
mCanceled = true;
setMessage(R.string.account_setup_check_settings_canceling_msg);
| public void | onClick(android.view.View v)
switch (v.getId()) {
case R.id.cancel:
onCancel();
break;
}
| public void | onCreate(android.os.Bundle savedInstanceState)
super.onCreate(savedInstanceState);
setContentView(R.layout.account_setup_check_settings);
mMessageView = (TextView)findViewById(R.id.message);
mProgressBar = (ProgressBar)findViewById(R.id.progress);
((Button)findViewById(R.id.cancel)).setOnClickListener(this);
setMessage(R.string.account_setup_check_settings_retr_info_msg);
mProgressBar.setIndeterminate(true);
mAccount = (Account)getIntent().getSerializableExtra(EXTRA_ACCOUNT);
mCheckIncoming = (boolean)getIntent().getBooleanExtra(EXTRA_CHECK_INCOMING, false);
mCheckOutgoing = (boolean)getIntent().getBooleanExtra(EXTRA_CHECK_OUTGOING, false);
new Thread() {
public void run() {
Process.setThreadPriority(Process.THREAD_PRIORITY_BACKGROUND);
try {
if (mDestroyed) {
return;
}
if (mCanceled) {
finish();
return;
}
if (mCheckIncoming) {
setMessage(R.string.account_setup_check_settings_check_incoming_msg);
Store store = Store.getInstance(mAccount.getStoreUri(), getApplication());
store.checkSettings();
}
if (mDestroyed) {
return;
}
if (mCanceled) {
finish();
return;
}
if (mCheckOutgoing) {
setMessage(R.string.account_setup_check_settings_check_outgoing_msg);
Sender sender = Sender.getInstance(mAccount.getSenderUri());
sender.close();
sender.open();
sender.close();
}
if (mDestroyed) {
return;
}
if (mCanceled) {
finish();
return;
}
setResult(RESULT_OK);
finish();
} catch (final AuthenticationFailedException afe) {
String message = afe.getMessage();
int id = (message == null)
? R.string.account_setup_failed_dlg_auth_message
: R.string.account_setup_failed_dlg_auth_message_fmt;
showErrorDialog(id, message);
} catch (final CertificateValidationException cve) {
String message = cve.getMessage();
int id = (message == null)
? R.string.account_setup_failed_dlg_certificate_message
: R.string.account_setup_failed_dlg_certificate_message_fmt;
showErrorDialog(id, message);
} catch (final MessagingException me) {
int id;
String message = me.getMessage();
switch (me.getExceptionType()) {
case MessagingException.IOERROR:
id = R.string.account_setup_failed_ioerror;
break;
case MessagingException.TLS_REQUIRED:
id = R.string.account_setup_failed_tls_required;
break;
case MessagingException.AUTH_REQUIRED:
id = R.string.account_setup_failed_auth_required;
break;
case MessagingException.GENERAL_SECURITY:
id = R.string.account_setup_failed_security;
break;
default:
id = (message == null)
? R.string.account_setup_failed_dlg_server_message
: R.string.account_setup_failed_dlg_server_message_fmt;
break;
}
showErrorDialog(id, message);
}
}
}.start();
| public void | onDestroy()
super.onDestroy();
mDestroyed = true;
mCanceled = true;
| private void | setMessage(int resId)
mHandler.post(new Runnable() {
public void run() {
if (mDestroyed) {
return;
}
mMessageView.setText(getString(resId));
}
});
| private void | showErrorDialog(int msgResId, java.lang.Object args)
mHandler.post(new Runnable() {
public void run() {
if (mDestroyed) {
return;
}
mProgressBar.setIndeterminate(false);
new AlertDialog.Builder(AccountSetupCheckSettings.this)
.setIcon(android.R.drawable.ic_dialog_alert)
.setTitle(getString(R.string.account_setup_failed_dlg_title))
.setMessage(getString(msgResId, args))
.setCancelable(true)
.setPositiveButton(
getString(R.string.account_setup_failed_dlg_edit_details_action),
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
finish();
}
})
.show();
}
});
|
|