From d5059731780b81c91eff85be8830cafad41f3ed1 Mon Sep 17 00:00:00 2001 From: Andy Stadler <> Date: Fri, 3 Apr 2009 15:42:31 -0700 Subject: [PATCH] AI 144522: am: CL 144520 General cleanup after the integrations in CL 143018. Some spelling errors, inconsistencies in passing Application/Activity/Context, and some error handling cleanups. These are all changes that would have probably been made before the original submits, but I didn't want to fix them in the integration step. Original author: stadler Automated import of CL 144522 --- .../email/activity/setup/AccountSettings.java | 13 +++---- .../setup/AccountSetupAccountType.java | 16 ++++----- .../activity/setup/AccountSetupBasics.java | 27 +++++++------- .../setup/AccountSetupCheckSettings.java | 6 ++-- .../activity/setup/AccountSetupIncoming.java | 24 ++++++------- .../activity/setup/AccountSetupNames.java | 21 ++++++----- .../activity/setup/AccountSetupOptions.java | 17 +++++---- .../activity/setup/AccountSetupOutgoing.java | 26 +++++++------- src/com/android/email/mail/Sender.java | 15 ++++---- src/com/android/email/mail/Store.java | 36 +++++++++++-------- 10 files changed, 103 insertions(+), 98 deletions(-) diff --git a/src/com/android/email/activity/setup/AccountSettings.java b/src/com/android/email/activity/setup/AccountSettings.java index 459aa8fa4..c9bd1a032 100644 --- a/src/com/android/email/activity/setup/AccountSettings.java +++ b/src/com/android/email/activity/setup/AccountSettings.java @@ -23,7 +23,7 @@ import com.android.email.R; import com.android.email.mail.Sender; import com.android.email.mail.Store; -import android.content.Context; +import android.app.Activity; import android.content.Intent; import android.content.SharedPreferences; import android.os.Bundle; @@ -33,6 +33,7 @@ import android.preference.ListPreference; import android.preference.Preference; import android.preference.PreferenceActivity; import android.preference.RingtonePreference; +import android.util.Log; import android.view.KeyEvent; public class AccountSettings extends PreferenceActivity { @@ -60,10 +61,10 @@ public class AccountSettings extends PreferenceActivity { private CheckBoxPreference mAccountVibrate; private RingtonePreference mAccountRingtone; - public static void actionSettings(Context context, Account account) { - Intent i = new Intent(context, AccountSettings.class); + public static void actionSettings(Activity fromActivity, Account account) { + Intent i = new Intent(fromActivity, AccountSettings.class); i.putExtra(EXTRA_ACCOUNT, account); - context.startActivity(i); + fromActivity.startActivity(i); } @Override @@ -196,7 +197,7 @@ public class AccountSettings extends PreferenceActivity { } } } catch (Exception e) { - android.util.Log.d(Email.LOG_TAG, "Error while trying to invoke store settings.", e); + Log.d(Email.LOG_TAG, "Error while trying to invoke store settings.", e); } } @@ -212,7 +213,7 @@ public class AccountSettings extends PreferenceActivity { } } } catch (Exception e) { - android.util.Log.d(Email.LOG_TAG, "Error while trying to invoke sender settings.", e); + Log.d(Email.LOG_TAG, "Error while trying to invoke sender settings.", e); } } diff --git a/src/com/android/email/activity/setup/AccountSetupAccountType.java b/src/com/android/email/activity/setup/AccountSetupAccountType.java index cf5341a72..f62e42061 100644 --- a/src/com/android/email/activity/setup/AccountSetupAccountType.java +++ b/src/com/android/email/activity/setup/AccountSetupAccountType.java @@ -16,19 +16,18 @@ package com.android.email.activity.setup; -import java.net.URI; -import java.net.URISyntaxException; +import com.android.email.Account; +import com.android.email.R; import android.app.Activity; -import android.content.Context; import android.content.Intent; import android.os.Bundle; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; -import com.android.email.Account; -import com.android.email.R; +import java.net.URI; +import java.net.URISyntaxException; /** * Prompts the user to select an account type. The account type, along with the @@ -44,11 +43,12 @@ public class AccountSetupAccountType extends Activity implements OnClickListener private boolean mMakeDefault; - public static void actionSelectAccountType(Context context, Account account, boolean makeDefault) { - Intent i = new Intent(context, AccountSetupAccountType.class); + public static void actionSelectAccountType(Activity fromActivity, Account account, + boolean makeDefault) { + Intent i = new Intent(fromActivity, AccountSetupAccountType.class); i.putExtra(EXTRA_ACCOUNT, account); i.putExtra(EXTRA_MAKE_DEFAULT, makeDefault); - context.startActivity(i); + fromActivity.startActivity(i); } @Override diff --git a/src/com/android/email/activity/setup/AccountSetupBasics.java b/src/com/android/email/activity/setup/AccountSetupBasics.java index 997ac3e68..f405e67ec 100644 --- a/src/com/android/email/activity/setup/AccountSetupBasics.java +++ b/src/com/android/email/activity/setup/AccountSetupBasics.java @@ -16,14 +16,17 @@ package com.android.email.activity.setup; -import java.io.Serializable; -import java.net.URI; -import java.net.URISyntaxException; +import com.android.email.Account; +import com.android.email.Email; +import com.android.email.EmailAddressValidator; +import com.android.email.Preferences; +import com.android.email.R; +import com.android.email.Utility; +import com.android.email.activity.Debug; import android.app.Activity; import android.app.AlertDialog; import android.app.Dialog; -import android.content.Context; import android.content.DialogInterface; import android.content.Intent; import android.content.res.XmlResourceParser; @@ -42,13 +45,9 @@ import android.widget.CheckBox; import android.widget.EditText; import android.widget.Toast; -import com.android.email.Account; -import com.android.email.Email; -import com.android.email.EmailAddressValidator; -import com.android.email.Preferences; -import com.android.email.R; -import com.android.email.Utility; -import com.android.email.activity.Debug; +import java.io.Serializable; +import java.net.URI; +import java.net.URISyntaxException; /** * Prompts the user for the email address and password. Also prompts for @@ -80,9 +79,9 @@ public class AccountSetupBasics extends Activity private EmailAddressValidator mEmailValidator = new EmailAddressValidator(); - public static void actionNewAccount(Context context) { - Intent i = new Intent(context, AccountSetupBasics.class); - context.startActivity(i); + public static void actionNewAccount(Activity fromActivity) { + Intent i = new Intent(fromActivity, AccountSetupBasics.class); + fromActivity.startActivity(i); } @Override diff --git a/src/com/android/email/activity/setup/AccountSetupCheckSettings.java b/src/com/android/email/activity/setup/AccountSetupCheckSettings.java index 6fe0ab4b1..a86ed8f32 100644 --- a/src/com/android/email/activity/setup/AccountSetupCheckSettings.java +++ b/src/com/android/email/activity/setup/AccountSetupCheckSettings.java @@ -67,13 +67,13 @@ public class AccountSetupCheckSettings extends Activity implements OnClickListen private boolean mDestroyed; - public static void actionCheckSettings(Activity context, Account account, + public static void actionCheckSettings(Activity fromActivity, Account account, boolean checkIncoming, boolean checkOutgoing) { - Intent i = new Intent(context, AccountSetupCheckSettings.class); + Intent i = new Intent(fromActivity, AccountSetupCheckSettings.class); i.putExtra(EXTRA_ACCOUNT, account); i.putExtra(EXTRA_CHECK_INCOMING, checkIncoming); i.putExtra(EXTRA_CHECK_OUTGOING, checkOutgoing); - context.startActivityForResult(i, 1); + fromActivity.startActivityForResult(i, 1); } @Override diff --git a/src/com/android/email/activity/setup/AccountSetupIncoming.java b/src/com/android/email/activity/setup/AccountSetupIncoming.java index 95ddf11c4..b18811b7c 100644 --- a/src/com/android/email/activity/setup/AccountSetupIncoming.java +++ b/src/com/android/email/activity/setup/AccountSetupIncoming.java @@ -16,8 +16,10 @@ package com.android.email.activity.setup; -import java.net.URI; -import java.net.URISyntaxException; +import com.android.email.Account; +import com.android.email.Preferences; +import com.android.email.R; +import com.android.email.Utility; import android.app.Activity; import android.content.Intent; @@ -34,10 +36,8 @@ import android.widget.EditText; import android.widget.Spinner; import android.widget.TextView; -import com.android.email.Account; -import com.android.email.Preferences; -import com.android.email.R; -import com.android.email.Utility; +import java.net.URI; +import java.net.URISyntaxException; public class AccountSetupIncoming extends Activity implements OnClickListener { private static final String EXTRA_ACCOUNT = "account"; @@ -69,18 +69,18 @@ public class AccountSetupIncoming extends Activity implements OnClickListener { private Account mAccount; private boolean mMakeDefault; - public static void actionIncomingSettings(Activity context, Account account, boolean makeDefault) { - Intent i = new Intent(context, AccountSetupIncoming.class); + public static void actionIncomingSettings(Activity fromActivity, Account account, boolean makeDefault) { + Intent i = new Intent(fromActivity, AccountSetupIncoming.class); i.putExtra(EXTRA_ACCOUNT, account); i.putExtra(EXTRA_MAKE_DEFAULT, makeDefault); - context.startActivity(i); + fromActivity.startActivity(i); } - public static void actionEditIncomingSettings(Activity context, Account account) { - Intent i = new Intent(context, AccountSetupIncoming.class); + public static void actionEditIncomingSettings(Activity fromActivity, Account account) { + Intent i = new Intent(fromActivity, AccountSetupIncoming.class); i.setAction(Intent.ACTION_EDIT); i.putExtra(EXTRA_ACCOUNT, account); - context.startActivity(i); + fromActivity.startActivity(i); } @Override diff --git a/src/com/android/email/activity/setup/AccountSetupNames.java b/src/com/android/email/activity/setup/AccountSetupNames.java index ff1bd0e62..4af55c9ac 100644 --- a/src/com/android/email/activity/setup/AccountSetupNames.java +++ b/src/com/android/email/activity/setup/AccountSetupNames.java @@ -16,8 +16,14 @@ package com.android.email.activity.setup; +import com.android.email.Account; +import com.android.email.Email; +import com.android.email.Preferences; +import com.android.email.R; +import com.android.email.Utility; +import com.android.email.activity.FolderMessageList; + import android.app.Activity; -import android.content.Context; import android.content.Intent; import android.os.Bundle; import android.text.Editable; @@ -29,13 +35,6 @@ import android.view.View.OnClickListener; import android.widget.Button; import android.widget.EditText; -import com.android.email.Account; -import com.android.email.Email; -import com.android.email.Preferences; -import com.android.email.R; -import com.android.email.Utility; -import com.android.email.activity.FolderMessageList; - public class AccountSetupNames extends Activity implements OnClickListener { private static final String EXTRA_ACCOUNT = "account"; @@ -47,10 +46,10 @@ public class AccountSetupNames extends Activity implements OnClickListener { private Button mDoneButton; - public static void actionSetNames(Context context, Account account) { - Intent i = new Intent(context, AccountSetupNames.class); + public static void actionSetNames(Activity fromActivity, Account account) { + Intent i = new Intent(fromActivity, AccountSetupNames.class); i.putExtra(EXTRA_ACCOUNT, account); - context.startActivity(i); + fromActivity.startActivity(i); } @Override diff --git a/src/com/android/email/activity/setup/AccountSetupOptions.java b/src/com/android/email/activity/setup/AccountSetupOptions.java index 04fddd521..9facf5353 100644 --- a/src/com/android/email/activity/setup/AccountSetupOptions.java +++ b/src/com/android/email/activity/setup/AccountSetupOptions.java @@ -16,8 +16,12 @@ package com.android.email.activity.setup; +import com.android.email.Account; +import com.android.email.Email; +import com.android.email.Preferences; +import com.android.email.R; + import android.app.Activity; -import android.content.Context; import android.content.Intent; import android.os.Bundle; import android.view.View; @@ -26,11 +30,6 @@ import android.widget.ArrayAdapter; import android.widget.CheckBox; import android.widget.Spinner; -import com.android.email.Account; -import com.android.email.Email; -import com.android.email.Preferences; -import com.android.email.R; - public class AccountSetupOptions extends Activity implements OnClickListener { private static final String EXTRA_ACCOUNT = "account"; @@ -44,11 +43,11 @@ public class AccountSetupOptions extends Activity implements OnClickListener { private Account mAccount; - public static void actionOptions(Context context, Account account, boolean makeDefault) { - Intent i = new Intent(context, AccountSetupOptions.class); + public static void actionOptions(Activity fromActivity, Account account, boolean makeDefault) { + Intent i = new Intent(fromActivity, AccountSetupOptions.class); i.putExtra(EXTRA_ACCOUNT, account); i.putExtra(EXTRA_MAKE_DEFAULT, makeDefault); - context.startActivity(i); + fromActivity.startActivity(i); } @Override diff --git a/src/com/android/email/activity/setup/AccountSetupOutgoing.java b/src/com/android/email/activity/setup/AccountSetupOutgoing.java index f08835c9c..df1173791 100644 --- a/src/com/android/email/activity/setup/AccountSetupOutgoing.java +++ b/src/com/android/email/activity/setup/AccountSetupOutgoing.java @@ -16,11 +16,12 @@ package com.android.email.activity.setup; -import java.net.URI; -import java.net.URISyntaxException; +import com.android.email.Account; +import com.android.email.Preferences; +import com.android.email.R; +import com.android.email.Utility; import android.app.Activity; -import android.content.Context; import android.content.Intent; import android.os.Bundle; import android.text.Editable; @@ -38,10 +39,8 @@ import android.widget.EditText; import android.widget.Spinner; import android.widget.CompoundButton.OnCheckedChangeListener; -import com.android.email.Account; -import com.android.email.Preferences; -import com.android.email.R; -import com.android.email.Utility; +import java.net.URI; +import java.net.URISyntaxException; public class AccountSetupOutgoing extends Activity implements OnClickListener, OnCheckedChangeListener { @@ -68,18 +67,19 @@ public class AccountSetupOutgoing extends Activity implements OnClickListener, private Account mAccount; private boolean mMakeDefault; - public static void actionOutgoingSettings(Context context, Account account, boolean makeDefault) { - Intent i = new Intent(context, AccountSetupOutgoing.class); + public static void actionOutgoingSettings(Activity fromActivity, Account account, + boolean makeDefault) { + Intent i = new Intent(fromActivity, AccountSetupOutgoing.class); i.putExtra(EXTRA_ACCOUNT, account); i.putExtra(EXTRA_MAKE_DEFAULT, makeDefault); - context.startActivity(i); + fromActivity.startActivity(i); } - public static void actionEditOutgoingSettings(Context context, Account account) { - Intent i = new Intent(context, AccountSetupOutgoing.class); + public static void actionEditOutgoingSettings(Activity fromActivity, Account account) { + Intent i = new Intent(fromActivity, AccountSetupOutgoing.class); i.setAction(Intent.ACTION_EDIT); i.putExtra(EXTRA_ACCOUNT, account); - context.startActivity(i); + fromActivity.startActivity(i); } @Override diff --git a/src/com/android/email/mail/Sender.java b/src/com/android/email/mail/Sender.java index 1ee241ccd..22821dfe9 100644 --- a/src/com/android/email/mail/Sender.java +++ b/src/com/android/email/mail/Sender.java @@ -23,6 +23,7 @@ import org.xmlpull.v1.XmlPullParserException; import android.content.Context; import android.content.res.XmlResourceParser; +import android.util.Log; import java.io.IOException; @@ -38,10 +39,10 @@ public abstract class Sender { */ public static Sender newInstance(String uri, Context context) throws MessagingException { - throw new MessagingException("Sender.newInscance: Unknown scheme in " + uri); + throw new MessagingException("Sender.newInstance: Unknown scheme in " + uri); } - private static Sender instanciateSender(String className, String uri, Context context) + private static Sender instantiateSender(String className, String uri, Context context) throws MessagingException { Object o = null; try { @@ -51,10 +52,10 @@ public abstract class Sender { c.getMethod("newInstance", String.class, Context.class); o = m.invoke(null, uri, context); } catch (Exception e) { - android.util.Log.e(Email.LOG_TAG, - String.format("can not invoke %s.newInstance.(String, Context) method for %s", - className, uri)); - throw new MessagingException("can not instanciate Sender object for " + uri); + Log.d(Email.LOG_TAG, String.format( + "exception %s invoking %s.newInstance.(String, Context) method for %s", + e.toString(), className, uri)); + throw new MessagingException("can not instantiate Sender object for " + uri); } if (!(o instanceof Sender)) { throw new MessagingException( @@ -81,7 +82,7 @@ public abstract class Sender { // found sender entry whose scheme is matched with uri. // then load sender class. String className = xml.getAttributeValue(null, "class"); - sender = instanciateSender(className, uri, context); + sender = instantiateSender(className, uri, context); } } } diff --git a/src/com/android/email/mail/Store.java b/src/com/android/email/mail/Store.java index 8ec0ec2ce..f76639934 100644 --- a/src/com/android/email/mail/Store.java +++ b/src/com/android/email/mail/Store.java @@ -23,6 +23,7 @@ import org.xmlpull.v1.XmlPullParserException; import android.content.Context; import android.content.res.XmlResourceParser; +import android.util.Log; import java.io.IOException; @@ -61,7 +62,7 @@ public abstract class Store { throw new MessagingException("Store.newInstance: Unknown scheme in " + uri); } - private static Store instanciateStore(String className, String uri, Context context) + private static Store instantiateStore(String className, String uri, Context context) throws MessagingException { Object o = null; try { @@ -71,10 +72,10 @@ public abstract class Store { c.getMethod("newInstance", String.class, Context.class); o = m.invoke(null, uri, context); } catch (Exception e) { - android.util.Log.e(Email.LOG_TAG, - String.format("can not invoke %s.newInstance(String, Context) method for %s", - className, uri)); - throw new MessagingException("can not instanciate Store object for " + uri); + Log.d(Email.LOG_TAG, String.format( + "exception %s invoking %s.newInstance.(String, Context) method for %s", + e.toString(), className, uri)); + throw new MessagingException("can not instantiate Store object for " + uri); } if (!(o instanceof Store)) { throw new MessagingException( @@ -101,7 +102,7 @@ public abstract class Store { // found store entry whose scheme is matched with uri. // then load store class. String className = xml.getAttributeValue(null, "class"); - store = instanciateStore(className, uri, context); + store = instantiateStore(className, uri, context); } } } @@ -115,15 +116,20 @@ public abstract class Store { /** * Get an instance of a mail store. The URI is parsed as a standard URI and - * the scheme is used to determine which protocol will be used. The - * following schemes are currently recognized: imap - IMAP with no - * connection security. Ex: imap://username:password@host/ imap+tls - IMAP - * with TLS connection security, if the server supports it. Ex: - * imap+tls://username:password@host imap+tls+ - IMAP with required TLS - * connection security. Connection fails if TLS is not available. Ex: - * imap+tls+://username:password@host imap+ssl+ - IMAP with required SSL - * connection security. Connection fails if SSL is not available. Ex: - * imap+ssl+://username:password@host + * the scheme is used to determine which protocol will be used. + * + * Although the URI format is somewhat protocol-specific, we use the following + * guidelines wherever possible: + * + * scheme [+ security [+]] :// username : password @ host [ / resource ] + * + * Typical schemes include imap, pop3, local, eas. + * Typical security models include SSL or TLS. + * A + after the security identifier indicates "required". + * + * Username, password, and host are as expected. + * Resource is protocol specific. For example, IMAP uses it as the path prefix. EAS uses it + * as the domain. * * @param uri The URI of the store. * @return an initialized store of the appropriate class