Include guava in Email.

- adds a compile time dependency to the guava library
- changes to use @VisibleForTesting in places to ensure it works

Change-Id: I2c5c4f9861234fec3613da011185e5c11f228466
This commit is contained in:
Ben Komalo 2011-04-14 13:32:41 -07:00
parent 8faa4e9cfa
commit 28b3fec5c1
4 changed files with 18 additions and 11 deletions

View File

@ -23,7 +23,7 @@ LOCAL_MODULE_TAGS := optional
LOCAL_SRC_FILES := $(call all-java-files-under, src/com/android/email) LOCAL_SRC_FILES := $(call all-java-files-under, src/com/android/email)
LOCAL_SRC_FILES += $(call all-java-files-under, src/com/beetstra) LOCAL_SRC_FILES += $(call all-java-files-under, src/com/beetstra)
LOCAL_STATIC_JAVA_LIBRARIES := android-common com.android.emailcommon LOCAL_STATIC_JAVA_LIBRARIES := android-common com.android.emailcommon guava
LOCAL_PACKAGE_NAME := Email LOCAL_PACKAGE_NAME := Email

View File

@ -21,6 +21,7 @@ LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS) include $(CLEAR_VARS)
LOCAL_MODULE := com.android.emailcommon LOCAL_MODULE := com.android.emailcommon
LOCAL_STATIC_JAVA_LIBRARIES := guava
LOCAL_SRC_FILES := $(call all-java-files-under, src/com/android/emailcommon) LOCAL_SRC_FILES := $(call all-java-files-under, src/com/android/emailcommon)
LOCAL_SRC_FILES += $(call all-java-files-under, src/org) LOCAL_SRC_FILES += $(call all-java-files-under, src/org)
LOCAL_SRC_FILES += \ LOCAL_SRC_FILES += \

View File

@ -17,6 +17,7 @@
package com.android.emailcommon.mail; package com.android.emailcommon.mail;
import com.android.emailcommon.utility.Utility; import com.android.emailcommon.utility.Utility;
import com.google.common.annotations.VisibleForTesting;
import org.apache.james.mime4j.codec.EncoderUtil; import org.apache.james.mime4j.codec.EncoderUtil;
import org.apache.james.mime4j.decoder.DecoderUtil; import org.apache.james.mime4j.decoder.DecoderUtil;
@ -25,8 +26,6 @@ import android.text.TextUtils;
import android.text.util.Rfc822Token; import android.text.util.Rfc822Token;
import android.text.util.Rfc822Tokenizer; import android.text.util.Rfc822Tokenizer;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.regex.Pattern; import java.util.regex.Pattern;
@ -80,7 +79,7 @@ public class Address {
} }
public void setAddress(String address) { public void setAddress(String address) {
mAddress = REMOVE_OPTIONAL_BRACKET.matcher(address).replaceAll("$1");; mAddress = REMOVE_OPTIONAL_BRACKET.matcher(address).replaceAll("$1");
} }
/** /**
@ -96,7 +95,7 @@ public class Address {
* Set name part from UTF-16 string. Optional surrounding double quote will be removed. * Set name part from UTF-16 string. Optional surrounding double quote will be removed.
* It will be also unquoted and MIME/base64 decoded. * It will be also unquoted and MIME/base64 decoded.
* *
* @param Personal name part of email address as UTF-16 string. Null is acceptable. * @param personal name part of email address as UTF-16 string. Null is acceptable.
*/ */
public void setPersonal(String personal) { public void setPersonal(String personal) {
if (personal != null) { if (personal != null) {
@ -163,7 +162,8 @@ public class Address {
* Checks whether a string email address is valid. * Checks whether a string email address is valid.
* E.g. name@domain.com is valid. * E.g. name@domain.com is valid.
*/ */
/* package */ static boolean isValidAddress(String address) { @VisibleForTesting
static boolean isValidAddress(String address) {
// Note: Some email provider may violate the standard, so here we only check that // Note: Some email provider may violate the standard, so here we only check that
// address consists of two part that are separated by '@', and domain part contains // address consists of two part that are separated by '@', and domain part contains
// at least one '.'. // at least one '.'.

View File

@ -35,6 +35,7 @@ import com.android.emailcommon.provider.EmailContent.MessageColumns;
import com.android.emailcommon.utility.AttachmentUtilities; import com.android.emailcommon.utility.AttachmentUtilities;
import com.android.emailcommon.utility.EmailAsyncTask; import com.android.emailcommon.utility.EmailAsyncTask;
import com.android.emailcommon.utility.Utility; import com.android.emailcommon.utility.Utility;
import com.google.common.annotations.VisibleForTesting;
import android.app.ActionBar; import android.app.ActionBar;
import android.app.Activity; import android.app.Activity;
@ -1043,7 +1044,8 @@ public class MessageCompose extends Activity implements OnClickListener, OnFocus
/** /**
* Checks whether all the email addresses listed in TO, CC, BCC are valid. * Checks whether all the email addresses listed in TO, CC, BCC are valid.
*/ */
/* package */ boolean isAddressAllValid() { @VisibleForTesting
boolean isAddressAllValid() {
for (TextView view : new TextView[]{mToView, mCcView, mBccView}) { for (TextView view : new TextView[]{mToView, mCcView, mBccView}) {
String addresses = view.getText().toString().trim(); String addresses = view.getText().toString().trim();
if (!Address.isAllValid(addresses)) { if (!Address.isAllValid(addresses)) {
@ -1336,7 +1338,8 @@ public class MessageCompose extends Activity implements OnClickListener, OnFocus
* *
* @param text the message body * @param text the message body
*/ */
/* package */ void setInitialComposeText(CharSequence text, String signature) { @VisibleForTesting
void setInitialComposeText(CharSequence text, String signature) {
mMessageContentView.setText(""); mMessageContentView.setText("");
int textLength = 0; int textLength = 0;
if (text != null) { if (text != null) {
@ -1365,7 +1368,8 @@ public class MessageCompose extends Activity implements OnClickListener, OnFocus
* *
* @param intent the launch intent * @param intent the launch intent
*/ */
/* package */ void initFromIntent(Intent intent) { @VisibleForTesting
void initFromIntent(Intent intent) {
setAccount(intent); setAccount(intent);
@ -1534,7 +1538,8 @@ public class MessageCompose extends Activity implements OnClickListener, OnFocus
* @param ccView the "Cc" view * @param ccView the "Cc" view
* @param replyAll whether this is a replyAll (vs a reply) * @param replyAll whether this is a replyAll (vs a reply)
*/ */
/*package*/ void setupAddressViews(Message message, Account account, @VisibleForTesting
void setupAddressViews(Message message, Account account,
MultiAutoCompleteTextView toView, MultiAutoCompleteTextView ccView, boolean replyAll) { MultiAutoCompleteTextView toView, MultiAutoCompleteTextView ccView, boolean replyAll) {
/* /*
* If a reply-to was included with the message use that, otherwise use the from * If a reply-to was included with the message use that, otherwise use the from
@ -1631,7 +1636,8 @@ public class MessageCompose extends Activity implements OnClickListener, OnFocus
/** /**
* Set a cursor to the end of a body except a signature. * Set a cursor to the end of a body except a signature.
*/ */
/* package */ void setMessageContentSelection(String signature) { @VisibleForTesting
void setMessageContentSelection(String signature) {
int selection = mMessageContentView.length(); int selection = mMessageContentView.length();
if (!TextUtils.isEmpty(signature)) { if (!TextUtils.isEmpty(signature)) {
int signatureLength = signature.length(); int signatureLength = signature.length();