1
0
mirror of https://github.com/moparisthebest/k-9 synced 2024-11-27 19:52:17 -05:00

Fixes Issue 738

Fixes Issue 133

Really, just displays a Toast and allows K-9 to continue in some
situations that otherwise cause a crash.  Will hopefully allow users
of Android 2.0 to use K-9, but may just provide better info about what
is going wrong.
This commit is contained in:
Daniel Applebaum 2009-11-07 16:21:47 +00:00
parent 2f4b9a1178
commit b9642ee5f3
4 changed files with 76 additions and 44 deletions

View File

@ -323,7 +323,7 @@ Welcome to K-9 Mail setup. K-9 is an open source email client for Android based
<string name="account_setup_outgoing_authentication_imap_before_smtp_label">IMAP before SMTP</string> <string name="account_setup_outgoing_authentication_imap_before_smtp_label">IMAP before SMTP</string>
<string name="account_setup_outgoing_authentication_webdav_before_smtp_label">WebDav(Exchange) before SMTP</string> <string name="account_setup_outgoing_authentication_webdav_before_smtp_label">WebDav(Exchange) before SMTP</string>
<string name="account_setup_bad_uri">Invalid account: <xliff:g id="err_mess">%s</xliff:g></string> <string name="account_setup_bad_uri">Invalid setup: <xliff:g id="err_mess">%s</xliff:g></string>
<string name="account_setup_options_title">Account options</string> <string name="account_setup_options_title">Account options</string>

View File

@ -8,12 +8,14 @@ import com.android.email.K9Activity;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.os.Bundle; import android.os.Bundle;
import android.util.Log;
import android.view.View; import android.view.View;
import android.view.View.OnClickListener; import android.view.View.OnClickListener;
import android.widget.Button; import android.widget.Button;
import android.widget.Toast; import android.widget.Toast;
import com.android.email.Account; import com.android.email.Account;
import com.android.email.Email;
import com.android.email.R; import com.android.email.R;
import com.android.email.activity.SizeFormatter; import com.android.email.activity.SizeFormatter;
@ -104,6 +106,7 @@ public class AccountSetupAccountType extends K9Activity implements OnClickListen
} }
private void failure(Exception use) private void failure(Exception use)
{ {
Log.e(Email.LOG_TAG, "Failure", use);
String toastText = getString(R.string.account_setup_bad_uri, use.getMessage()); String toastText = getString(R.string.account_setup_bad_uri, use.getMessage());
Toast toast = Toast.makeText(getApplication(), toastText, Toast.LENGTH_LONG); Toast toast = Toast.makeText(getApplication(), toastText, Toast.LENGTH_LONG);

View File

@ -21,6 +21,7 @@ import android.widget.Button;
import android.widget.EditText; import android.widget.EditText;
import android.widget.Spinner; import android.widget.Spinner;
import android.widget.TextView; import android.widget.TextView;
import android.widget.Toast;
import com.android.email.Account; import com.android.email.Account;
import com.android.email.Email; import com.android.email.Email;
@ -257,7 +258,7 @@ public class AccountSetupIncoming extends K9Activity implements OnClickListener
} }
} }
} else { } else {
throw new Error("Unknown account type: " + mAccount.getStoreUri()); throw new Exception("Unknown account type: " + mAccount.getStoreUri());
} }
for (int i = 0; i < mAccountSchemes.length; i++) { for (int i = 0; i < mAccountSchemes.length; i++) {
@ -275,14 +276,12 @@ public class AccountSetupIncoming extends K9Activity implements OnClickListener
} else { } else {
updatePortFromSecurityType(); updatePortFromSecurityType();
} }
} catch (URISyntaxException use) {
/* validateFields();
* We should always be able to parse our own settings. } catch (Exception e) {
*/ failure(e);
throw new Error(use);
} }
validateFields();
} }
@Override @Override
@ -301,8 +300,11 @@ public class AccountSetupIncoming extends K9Activity implements OnClickListener
} }
private void updatePortFromSecurityType() { private void updatePortFromSecurityType() {
int securityType = (Integer)((SpinnerOption)mSecurityTypeView.getSelectedItem()).value; if (mAccountPorts != null)
mPortView.setText(Integer.toString(mAccountPorts[securityType])); {
int securityType = (Integer)((SpinnerOption)mSecurityTypeView.getSelectedItem()).value;
mPortView.setText(Integer.toString(mAccountPorts[securityType]));
}
} }
@Override @Override
@ -356,8 +358,8 @@ public class AccountSetupIncoming extends K9Activity implements OnClickListener
} }
private void onNext() { private void onNext() {
int securityType = (Integer)((SpinnerOption)mSecurityTypeView.getSelectedItem()).value;
try { try {
int securityType = (Integer)((SpinnerOption)mSecurityTypeView.getSelectedItem()).value;
String path = null; String path = null;
if (mAccountSchemes[securityType].startsWith("imap")) { if (mAccountSchemes[securityType].startsWith("imap")) {
path = "/" + mImapPathPrefixView.getText(); path = "/" + mImapPathPrefixView.getText();
@ -376,38 +378,43 @@ public class AccountSetupIncoming extends K9Activity implements OnClickListener
null, // query null, // query
null); null);
mAccount.setStoreUri(uri.toString()); mAccount.setStoreUri(uri.toString());
} catch (URISyntaxException use) {
/*
* It's unrecoverable if we cannot create a URI from components that mAccount.setDraftsFolderName(mImapFolderDrafts.getText().toString());
* we validated to be safe. mAccount.setSentFolderName(mImapFolderSent.getText().toString());
*/ mAccount.setTrashFolderName(mImapFolderTrash.getText().toString());
throw new Error(use); mAccount.setOutboxFolderName(mImapFolderOutbox.getText().toString());
AccountSetupCheckSettings.actionCheckSettings(this, mAccount, true, false);
} catch (Exception e) {
failure(e);
} }
mAccount.setDraftsFolderName(mImapFolderDrafts.getText().toString());
mAccount.setSentFolderName(mImapFolderSent.getText().toString());
mAccount.setTrashFolderName(mImapFolderTrash.getText().toString());
mAccount.setOutboxFolderName(mImapFolderOutbox.getText().toString());
AccountSetupCheckSettings.actionCheckSettings(this, mAccount, true, false);
} }
public void onClick(View v) { public void onClick(View v) {
switch (v.getId()) { try
case R.id.next: {
onNext(); switch (v.getId()) {
break; case R.id.next:
case R.id.account_imap_folder_drafts: onNext();
selectImapFolder(SELECT_DRAFT_FOLDER); break;
break; case R.id.account_imap_folder_drafts:
case R.id.account_imap_folder_sent: selectImapFolder(SELECT_DRAFT_FOLDER);
selectImapFolder(SELECT_SENT_FOLDER); break;
break; case R.id.account_imap_folder_sent:
case R.id.account_imap_folder_trash: selectImapFolder(SELECT_SENT_FOLDER);
selectImapFolder(SELECT_TRASH_FOLDER); break;
break; case R.id.account_imap_folder_trash:
case R.id.account_imap_folder_outbox: selectImapFolder(SELECT_TRASH_FOLDER);
selectImapFolder(SELECT_OUTBOX_FOLDER); break;
break; case R.id.account_imap_folder_outbox:
selectImapFolder(SELECT_OUTBOX_FOLDER);
break;
}
}
catch (Exception e)
{
failure(e);
} }
} }
@ -437,4 +444,13 @@ public class AccountSetupIncoming extends K9Activity implements OnClickListener
selectIntent.putExtra(ChooseFolder.EXTRA_SHOW_CURRENT, "yes"); selectIntent.putExtra(ChooseFolder.EXTRA_SHOW_CURRENT, "yes");
startActivityForResult(selectIntent, activityCode); startActivityForResult(selectIntent, activityCode);
} }
private void failure(Exception use)
{
Log.e(Email.LOG_TAG, "Failure", use);
String toastText = getString(R.string.account_setup_bad_uri, use.getMessage());
Toast toast = Toast.makeText(getApplication(), toastText, Toast.LENGTH_LONG);
toast.show();
}
} }

View File

@ -11,6 +11,7 @@ import android.os.Bundle;
import android.text.Editable; import android.text.Editable;
import android.text.TextWatcher; import android.text.TextWatcher;
import android.text.method.DigitsKeyListener; import android.text.method.DigitsKeyListener;
import android.util.Log;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.view.View.OnClickListener; import android.view.View.OnClickListener;
@ -21,9 +22,11 @@ import android.widget.CheckBox;
import android.widget.CompoundButton; import android.widget.CompoundButton;
import android.widget.EditText; import android.widget.EditText;
import android.widget.Spinner; import android.widget.Spinner;
import android.widget.Toast;
import android.widget.CompoundButton.OnCheckedChangeListener; import android.widget.CompoundButton.OnCheckedChangeListener;
import com.android.email.Account; import com.android.email.Account;
import com.android.email.Email;
import com.android.email.Preferences; import com.android.email.Preferences;
import com.android.email.R; import com.android.email.R;
import com.android.email.Utility; import com.android.email.Utility;
@ -203,14 +206,15 @@ public class AccountSetupOutgoing extends K9Activity implements OnClickListener,
} else { } else {
updatePortFromSecurityType(); updatePortFromSecurityType();
} }
} catch (URISyntaxException use) {
validateFields();
} catch (Exception e) {
/* /*
* We should always be able to parse our own settings. * We should always be able to parse our own settings.
*/ */
throw new Error(use); failure(e);
} }
validateFields();
} }
@Override @Override
@ -260,14 +264,15 @@ public class AccountSetupOutgoing extends K9Activity implements OnClickListener,
uri = new URI(smtpSchemes[securityType], userInfo, mServerView.getText().toString(), uri = new URI(smtpSchemes[securityType], userInfo, mServerView.getText().toString(),
Integer.parseInt(mPortView.getText().toString()), null, null, null); Integer.parseInt(mPortView.getText().toString()), null, null, null);
mAccount.setTransportUri(uri.toString()); mAccount.setTransportUri(uri.toString());
} catch (URISyntaxException use) { AccountSetupCheckSettings.actionCheckSettings(this, mAccount, false, true);
} catch (Exception e) {
/* /*
* It's unrecoverable if we cannot create a URI from components that * It's unrecoverable if we cannot create a URI from components that
* we validated to be safe. * we validated to be safe.
*/ */
throw new Error(use); failure(e);
} }
AccountSetupCheckSettings.actionCheckSettings(this, mAccount, false, true);
} }
public void onClick(View v) { public void onClick(View v) {
@ -282,4 +287,12 @@ public class AccountSetupOutgoing extends K9Activity implements OnClickListener,
mRequireLoginSettingsView.setVisibility(isChecked ? View.VISIBLE : View.GONE); mRequireLoginSettingsView.setVisibility(isChecked ? View.VISIBLE : View.GONE);
validateFields(); validateFields();
} }
private void failure(Exception use)
{
Log.e(Email.LOG_TAG, "Failure", use);
String toastText = getString(R.string.account_setup_bad_uri, use.getMessage());
Toast toast = Toast.makeText(getApplication(), toastText, Toast.LENGTH_LONG);
toast.show();
}
} }