Merge "Add signature when starting from external intents."

This commit is contained in:
Ben Komalo 2011-04-13 10:22:51 -07:00 committed by Android (Google) Code Review
commit 1d1b7a070a
2 changed files with 35 additions and 18 deletions

View File

@ -88,6 +88,7 @@ import java.util.List;
*/
public class MessageCompose extends Activity implements OnClickListener, OnFocusChangeListener,
DeleteMessageConfirmationDialog.Callback {
private static final String ACTION_REPLY = "com.android.email.intent.action.REPLY";
private static final String ACTION_REPLY_ALL = "com.android.email.intent.action.REPLY_ALL";
private static final String ACTION_FORWARD = "com.android.email.intent.action.FORWARD";
@ -324,7 +325,6 @@ public class MessageCompose extends Activity implements OnClickListener, OnFocus
|| Intent.ACTION_SENDTO.equals(mAction)
|| Intent.ACTION_SEND.equals(mAction)
|| Intent.ACTION_SEND_MULTIPLE.equals(mAction)) {
setAccount(intent);
// Use the fields found in the Intent to prefill as much of the message as possible
initFromIntent(intent);
setDraftNeedsSaving(true);
@ -342,7 +342,7 @@ public class MessageCompose extends Activity implements OnClickListener, OnFocus
mMessageLoaded = true;
mSourceMessageProcessed = true;
}
setInitialComposeText(null, (mAccount != null) ? mAccount.mSignature : null);
setInitialComposeText(null, getAccountSignature(mAccount));
}
if (ACTION_REPLY.equals(mAction) || ACTION_REPLY_ALL.equals(mAction) ||
@ -743,7 +743,7 @@ public class MessageCompose extends Activity implements OnClickListener, OnFocus
// There is no way to determine if the focus change was programmatic or due
// to keyboard event, or if it was due to a tap/restore. Use a best-guess
// by using the fact that auto-focus/keyboard tabs set the selection to 0.
setMessageContentSelection((mAccount != null) ? mAccount.mSignature : null);
setMessageContentSelection(getAccountSignature(mAccount));
}
}
}
@ -1337,6 +1337,7 @@ public class MessageCompose extends Activity implements OnClickListener, OnFocus
* @param text the message body
*/
/* package */ void setInitialComposeText(CharSequence text, String signature) {
mMessageContentView.setText("");
int textLength = 0;
if (text != null) {
mMessageContentView.append(text);
@ -1366,6 +1367,8 @@ public class MessageCompose extends Activity implements OnClickListener, OnFocus
*/
/* package */ void initFromIntent(Intent intent) {
setAccount(intent);
// First, add values stored in top-level extras
String[] extraStrings = intent.getStringArrayExtra(Intent.EXTRA_EMAIL);
if (extraStrings != null) {
@ -1402,9 +1405,7 @@ public class MessageCompose extends Activity implements OnClickListener, OnFocus
// Next, fill in the plaintext (note, this will override mailto:?body=)
CharSequence text = intent.getCharSequenceExtra(Intent.EXTRA_TEXT);
if (text != null) {
setInitialComposeText(text, null);
}
setInitialComposeText(text, getAccountSignature(mAccount));
// Next, convert EXTRA_STREAM into an attachment
if (Intent.ACTION_SEND.equals(mAction) && intent.hasExtra(Intent.EXTRA_STREAM)) {
@ -1478,7 +1479,7 @@ public class MessageCompose extends Activity implements OnClickListener, OnFocus
List<String> body = uri.getQueryParameters("body");
if (body.size() > 0) {
setInitialComposeText(body.get(0), (mAccount != null) ? mAccount.mSignature : null);
setInitialComposeText(body.get(0), getAccountSignature(mAccount));
}
}
@ -1599,13 +1600,13 @@ public class MessageCompose extends Activity implements OnClickListener, OnFocus
}
displayQuotedText(message.mText, message.mHtml);
setIncludeQuotedText(true, false);
setInitialComposeText(null, (account != null) ? account.mSignature : null);
setInitialComposeText(null, getAccountSignature(account));
} else if (ACTION_FORWARD.equals(mAction)) {
mSubjectView.setText(subject != null && !subject.toLowerCase().startsWith("fwd:") ?
"Fwd: " + subject : subject);
displayQuotedText(message.mText, message.mHtml);
setIncludeQuotedText(true, false);
setInitialComposeText(null, (account != null) ? account.mSignature : null);
setInitialComposeText(null, getAccountSignature(account));
} else if (ACTION_EDIT_DRAFT.equals(mAction)) {
mSubjectView.setText(subject);
addAddresses(mToView, Address.unpack(message.mTo));
@ -1670,4 +1671,12 @@ public class MessageCompose extends Activity implements OnClickListener, OnFocus
mMessageContentView.requestFocus();
}
}
/**
* @return the signature for the specified account, if non-null. If the account specified is
* null or has no signature, {@code null} is returned.
*/
private static String getAccountSignature(Account account) {
return (account == null) ? null : account.mSignature;
}
}

View File

@ -68,8 +68,6 @@ public class MessageComposeTests
private static final String RECIPIENT_BCC = "recipient-bcc@android.com";
private static final String SUBJECT = "This is the subject";
private static final String BODY = "This is the body. This is also the body.";
private static final String REPLY_BODY_SHORT = "\n\n" + SENDER + " wrote:\n\n";
private static final String REPLY_BODY = REPLY_BODY_SHORT + ">" + BODY;
private static final String SIGNATURE = "signature";
private static final String FROM = "Fred From <from@google.com>";
@ -107,7 +105,12 @@ public class MessageComposeTests
private static final String UTF32_SUBJECT = "\uD834\uDF01\uD834\uDF46";
private static final String UTF32_BODY = "\uD834\uDF01\uD834\uDF46";
/** Note - these are copied from private strings in MessageCompose. Make them package? */
/*
* The following action definitions are purposefully copied from MessageCompose, so that
* any changes to the action strings will break these tests. Changes to the actions should
* be done consciously to think about existing shortcuts and clients.
*/
private static final String ACTION_REPLY = "com.android.email.intent.action.REPLY";
private static final String ACTION_REPLY_ALL = "com.android.email.intent.action.REPLY_ALL";
private static final String ACTION_FORWARD = "com.android.email.intent.action.FORWARD";
@ -133,6 +136,7 @@ public class MessageComposeTests
Account account = new Account();
account.mSenderName = "Bob Sender";
account.mEmailAddress = "bob@sender.com";
account.mSignature = SIGNATURE;
account.save(mContext);
accountId = account.mId;
mCreatedAccountId = accountId;
@ -174,7 +178,10 @@ public class MessageComposeTests
assertNotNull(mSubjectView);
assertEquals(0, mSubjectView.length());
assertNotNull(mMessageView);
assertEquals(0, mMessageView.length());
// Note that the signature is always preceeded with a newline.
int sigLength = (mSignature == null) ? 0 : (1 + mSignature.length());
assertEquals(sigLength, mMessageView.length());
}
/**
@ -618,7 +625,7 @@ public class MessageComposeTests
public void run() {
a.initFromIntent(i2);
checkFields(RECIPIENT_TO + ", ", RECIPIENT_CC + ", ", RECIPIENT_BCC + ", ", SUBJECT,
null, null);
null, mSignature);
checkFocused(mMessageView);
}
});
@ -642,7 +649,7 @@ public class MessageComposeTests
public void run() {
a.initFromIntent(i2);
checkFields(UTF16_RECIPIENT_TO + ", ", UTF16_RECIPIENT_CC + ", ",
UTF16_RECIPIENT_BCC + ", ", UTF16_SUBJECT, null, null);
UTF16_RECIPIENT_BCC + ", ", UTF16_SUBJECT, null, mSignature);
checkFocused(mMessageView);
}
});
@ -666,7 +673,7 @@ public class MessageComposeTests
public void run() {
a.initFromIntent(i2);
checkFields(UTF32_RECIPIENT_TO + ", ", UTF32_RECIPIENT_CC + ", ",
UTF32_RECIPIENT_BCC + ", ", UTF32_SUBJECT, null, null);
UTF32_RECIPIENT_BCC + ", ", UTF32_SUBJECT, null, mSignature);
checkFocused(mMessageView);
}
});
@ -688,7 +695,7 @@ public class MessageComposeTests
runTestOnUiThread(new Runnable() {
public void run() {
a.initFromIntent(i2);
checkFields(null, null, null, null, BODY, null);
checkFields(null, null, null, null, BODY, mSignature);
checkFocused(mToView);
}
});
@ -712,7 +719,8 @@ public class MessageComposeTests
runTestOnUiThread(new Runnable() {
public void run() {
a.initFromIntent(i2);
checkFields(RECIPIENT_TO + ", ", null, null, "This is the subject", null, null);
checkFields(
RECIPIENT_TO + ", ", null, null, "This is the subject", null, mSignature);
checkFocused(mMessageView);
}
});