2011-01-10 12:47:28 -05:00
|
|
|
package com.fsck.k9.view;
|
|
|
|
|
|
|
|
import android.content.Context;
|
|
|
|
import android.graphics.Typeface;
|
2012-02-23 22:07:29 -05:00
|
|
|
import android.os.Parcel;
|
|
|
|
import android.os.Parcelable;
|
2011-01-10 12:47:28 -05:00
|
|
|
import android.text.SpannableString;
|
|
|
|
import android.text.SpannableStringBuilder;
|
2013-02-04 07:23:44 -05:00
|
|
|
import android.text.TextUtils;
|
2011-01-10 12:47:28 -05:00
|
|
|
import android.text.style.StyleSpan;
|
|
|
|
import android.util.Log;
|
|
|
|
import android.util.AttributeSet;
|
|
|
|
import android.view.Gravity;
|
|
|
|
import android.view.View;
|
2012-02-21 10:21:47 -05:00
|
|
|
import android.view.View.OnClickListener;
|
2011-01-10 12:47:28 -05:00
|
|
|
import android.widget.CheckBox;
|
2013-02-10 19:01:42 -05:00
|
|
|
|
|
|
|
import android.widget.QuickContactBadge;
|
2012-02-20 22:56:05 -05:00
|
|
|
import android.widget.ScrollView;
|
2011-01-10 12:47:28 -05:00
|
|
|
import android.widget.TextView;
|
|
|
|
import android.widget.Toast;
|
|
|
|
import com.fsck.k9.FontSizes;
|
|
|
|
import com.fsck.k9.K9;
|
|
|
|
import com.fsck.k9.R;
|
2013-02-08 21:24:36 -05:00
|
|
|
import com.fsck.k9.activity.misc.ContactPictureLoader;
|
2011-01-10 12:47:28 -05:00
|
|
|
import com.fsck.k9.helper.Contacts;
|
|
|
|
import com.fsck.k9.Account;
|
|
|
|
import com.fsck.k9.helper.DateFormatter;
|
2013-02-10 19:01:42 -05:00
|
|
|
import com.fsck.k9.helper.MessageHelper;
|
2012-09-07 23:33:53 -04:00
|
|
|
import com.fsck.k9.helper.StringUtils;
|
2011-01-10 12:47:28 -05:00
|
|
|
import com.fsck.k9.mail.Address;
|
|
|
|
import com.fsck.k9.mail.Flag;
|
|
|
|
import com.fsck.k9.mail.Message;
|
|
|
|
import com.fsck.k9.mail.MessagingException;
|
|
|
|
import com.fsck.k9.mail.internet.MimeUtility;
|
2012-02-23 22:07:29 -05:00
|
|
|
|
2011-11-14 23:32:46 -05:00
|
|
|
import java.util.LinkedHashSet;
|
2011-01-10 12:47:28 -05:00
|
|
|
import java.util.LinkedList;
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.Set;
|
|
|
|
import java.text.DateFormat;
|
2011-01-18 18:54:49 -05:00
|
|
|
|
2012-02-21 10:21:47 -05:00
|
|
|
public class MessageHeader extends ScrollView implements OnClickListener {
|
2011-01-10 12:47:28 -05:00
|
|
|
private Context mContext;
|
|
|
|
private TextView mFromView;
|
|
|
|
private TextView mDateView;
|
|
|
|
private TextView mToView;
|
2013-02-08 21:24:36 -05:00
|
|
|
private TextView mToLabel;
|
2011-01-10 12:47:28 -05:00
|
|
|
private TextView mCcView;
|
2013-02-08 21:24:36 -05:00
|
|
|
private TextView mCcLabel;
|
2012-09-07 23:33:53 -04:00
|
|
|
private TextView mSubjectView;
|
2011-01-10 12:47:28 -05:00
|
|
|
private DateFormat mDateFormat;
|
|
|
|
private DateFormat mTimeFormat;
|
|
|
|
|
2012-02-21 17:38:43 -05:00
|
|
|
private View mChip;
|
2011-01-10 12:47:28 -05:00
|
|
|
private CheckBox mFlagged;
|
2012-09-07 23:33:53 -04:00
|
|
|
private int defaultSubjectColor;
|
2011-01-10 12:47:28 -05:00
|
|
|
private TextView mAdditionalHeadersView;
|
2011-01-17 12:25:00 -05:00
|
|
|
private View mAnsweredIcon;
|
2012-08-20 22:09:34 -04:00
|
|
|
private View mForwardedIcon;
|
2011-01-10 12:47:28 -05:00
|
|
|
private Message mMessage;
|
|
|
|
private Account mAccount;
|
|
|
|
private FontSizes mFontSizes = K9.getFontSizes();
|
|
|
|
private Contacts mContacts;
|
2012-02-23 22:07:29 -05:00
|
|
|
private SavedState mSavedState;
|
2011-01-10 12:47:28 -05:00
|
|
|
|
2013-02-10 19:01:42 -05:00
|
|
|
private MessageHelper mMessageHelper;
|
2013-02-08 21:24:36 -05:00
|
|
|
private ContactPictureLoader mContactsPictureLoader;
|
|
|
|
private QuickContactBadge mContactBadge;
|
|
|
|
|
2012-03-01 23:16:58 -05:00
|
|
|
private OnLayoutChangedListener mOnLayoutChangedListener;
|
|
|
|
|
2011-01-10 12:47:28 -05:00
|
|
|
/**
|
|
|
|
* Pair class is only available since API Level 5, so we need
|
|
|
|
* this helper class unfortunately
|
|
|
|
*/
|
2011-02-06 17:09:48 -05:00
|
|
|
private static class HeaderEntry {
|
2011-01-10 12:47:28 -05:00
|
|
|
public String label;
|
|
|
|
public String value;
|
|
|
|
|
2011-02-06 17:09:48 -05:00
|
|
|
public HeaderEntry(String label, String value) {
|
2011-01-10 12:47:28 -05:00
|
|
|
this.label = label;
|
|
|
|
this.value = value;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-02-06 17:09:48 -05:00
|
|
|
public MessageHeader(Context context, AttributeSet attrs) {
|
2011-01-10 12:47:28 -05:00
|
|
|
super(context, attrs);
|
|
|
|
mContext = context;
|
|
|
|
mDateFormat = DateFormatter.getDateFormat(mContext);
|
|
|
|
mTimeFormat = android.text.format.DateFormat.getTimeFormat(mContext); // 12/24 date format
|
|
|
|
mContacts = Contacts.getInstance(mContext);
|
|
|
|
}
|
|
|
|
|
2013-02-05 17:55:21 -05:00
|
|
|
@Override
|
|
|
|
protected void onFinishInflate() {
|
2011-01-17 12:25:00 -05:00
|
|
|
mAnsweredIcon = findViewById(R.id.answered);
|
2013-02-05 17:55:21 -05:00
|
|
|
mForwardedIcon = findViewById(R.id.forwarded);
|
2011-01-10 12:47:28 -05:00
|
|
|
mFromView = (TextView) findViewById(R.id.from);
|
|
|
|
mToView = (TextView) findViewById(R.id.to);
|
2013-02-08 21:24:36 -05:00
|
|
|
mToLabel = (TextView) findViewById(R.id.to_label);
|
2011-01-10 12:47:28 -05:00
|
|
|
mCcView = (TextView) findViewById(R.id.cc);
|
2013-02-08 21:24:36 -05:00
|
|
|
mCcLabel = (TextView) findViewById(R.id.cc_label);
|
2013-02-10 19:01:42 -05:00
|
|
|
|
|
|
|
mContactBadge = (QuickContactBadge) findViewById(R.id.contact_badge);
|
|
|
|
|
|
|
|
|
2012-09-07 23:33:53 -04:00
|
|
|
mSubjectView = (TextView) findViewById(R.id.subject);
|
2011-01-10 12:47:28 -05:00
|
|
|
mAdditionalHeadersView = (TextView) findViewById(R.id.additional_headers_view);
|
2012-02-21 17:38:43 -05:00
|
|
|
mChip = findViewById(R.id.chip);
|
2011-01-10 12:47:28 -05:00
|
|
|
mDateView = (TextView) findViewById(R.id.date);
|
|
|
|
mFlagged = (CheckBox) findViewById(R.id.flagged);
|
|
|
|
|
2012-09-07 23:33:53 -04:00
|
|
|
defaultSubjectColor = mSubjectView.getCurrentTextColor();
|
2013-02-08 21:19:22 -05:00
|
|
|
mFontSizes.setViewTextSize(mSubjectView, mFontSizes.getMessageViewSubject());
|
|
|
|
mFontSizes.setViewTextSize(mDateView, mFontSizes.getMessageViewDate());
|
|
|
|
mFontSizes.setViewTextSize(mAdditionalHeadersView, mFontSizes.getMessageViewAdditionalHeaders());
|
2012-08-20 22:09:34 -04:00
|
|
|
|
2013-02-08 21:19:22 -05:00
|
|
|
mFontSizes.setViewTextSize(mFromView, mFontSizes.getMessageViewSender());
|
|
|
|
mFontSizes.setViewTextSize(mToView, mFontSizes.getMessageViewTo());
|
2013-02-08 21:24:36 -05:00
|
|
|
mFontSizes.setViewTextSize(mToLabel, mFontSizes.getMessageViewTo());
|
2013-02-08 21:19:22 -05:00
|
|
|
mFontSizes.setViewTextSize(mCcView, mFontSizes.getMessageViewCC());
|
2013-02-08 21:24:36 -05:00
|
|
|
mFontSizes.setViewTextSize(mCcLabel, mFontSizes.getMessageViewCC());
|
2011-01-10 12:47:28 -05:00
|
|
|
|
2012-02-21 10:21:47 -05:00
|
|
|
mFromView.setOnClickListener(this);
|
2012-03-17 23:51:29 -04:00
|
|
|
mToView.setOnClickListener(this);
|
|
|
|
mCcView.setOnClickListener(this);
|
2013-02-05 17:55:21 -05:00
|
|
|
|
2013-02-10 19:01:42 -05:00
|
|
|
mMessageHelper = MessageHelper.getInstance(mContext);
|
|
|
|
|
2013-02-05 17:55:21 -05:00
|
|
|
mSubjectView.setVisibility(VISIBLE);
|
|
|
|
hideAdditionalHeaders();
|
2012-02-21 10:21:47 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onClick(View view) {
|
|
|
|
switch (view.getId()) {
|
|
|
|
case R.id.from: {
|
|
|
|
onAddSenderToContacts();
|
|
|
|
break;
|
2011-01-10 12:47:28 -05:00
|
|
|
}
|
2012-03-01 23:41:01 -05:00
|
|
|
case R.id.to:
|
|
|
|
case R.id.cc: {
|
|
|
|
expand((TextView)view, ((TextView)view).getEllipsize() != null);
|
|
|
|
layoutChanged();
|
|
|
|
}
|
2012-02-21 10:21:47 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void onAddSenderToContacts() {
|
|
|
|
if (mMessage != null) {
|
|
|
|
try {
|
|
|
|
final Address senderEmail = mMessage.getFrom()[0];
|
|
|
|
mContacts.createContact(senderEmail);
|
|
|
|
} catch (Exception e) {
|
|
|
|
Log.e(K9.LOG_TAG, "Couldn't create contact", e);
|
|
|
|
}
|
|
|
|
}
|
2011-01-10 12:47:28 -05:00
|
|
|
}
|
|
|
|
|
2011-02-06 17:09:48 -05:00
|
|
|
public void setOnFlagListener(OnClickListener listener) {
|
2012-02-20 22:56:05 -05:00
|
|
|
if (mFlagged == null)
|
|
|
|
return;
|
2011-01-10 12:47:28 -05:00
|
|
|
mFlagged.setOnClickListener(listener);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-02-06 17:09:48 -05:00
|
|
|
public boolean additionalHeadersVisible() {
|
2012-02-23 22:07:29 -05:00
|
|
|
return (mAdditionalHeadersView != null &&
|
|
|
|
mAdditionalHeadersView.getVisibility() == View.VISIBLE);
|
2011-01-10 12:47:28 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Clear the text field for the additional headers display if they are
|
|
|
|
* not shown, to save UI resources.
|
|
|
|
*/
|
2011-02-06 17:09:48 -05:00
|
|
|
private void hideAdditionalHeaders() {
|
2011-01-10 12:47:28 -05:00
|
|
|
mAdditionalHeadersView.setVisibility(View.GONE);
|
|
|
|
mAdditionalHeadersView.setText("");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set up and then show the additional headers view. Called by
|
|
|
|
* {@link #onShowAdditionalHeaders()}
|
|
|
|
* (when switching between messages).
|
|
|
|
*/
|
2011-02-06 17:09:48 -05:00
|
|
|
private void showAdditionalHeaders() {
|
2011-01-10 12:47:28 -05:00
|
|
|
Integer messageToShow = null;
|
2011-02-06 17:09:48 -05:00
|
|
|
try {
|
2011-01-10 12:47:28 -05:00
|
|
|
// Retrieve additional headers
|
|
|
|
boolean allHeadersDownloaded = mMessage.isSet(Flag.X_GOT_ALL_HEADERS);
|
|
|
|
List<HeaderEntry> additionalHeaders = getAdditionalHeaders(mMessage);
|
2011-02-06 17:09:48 -05:00
|
|
|
if (!additionalHeaders.isEmpty()) {
|
2011-01-10 12:47:28 -05:00
|
|
|
// Show the additional headers that we have got.
|
|
|
|
populateAdditionalHeadersView(additionalHeaders);
|
|
|
|
mAdditionalHeadersView.setVisibility(View.VISIBLE);
|
|
|
|
}
|
2011-02-06 17:09:48 -05:00
|
|
|
if (!allHeadersDownloaded) {
|
2011-01-10 12:47:28 -05:00
|
|
|
/*
|
|
|
|
* Tell the user about the "save all headers" setting
|
|
|
|
*
|
|
|
|
* NOTE: This is only a temporary solution... in fact,
|
|
|
|
* the system should download headers on-demand when they
|
|
|
|
* have not been saved in their entirety initially.
|
|
|
|
*/
|
|
|
|
messageToShow = R.string.message_additional_headers_not_downloaded;
|
2011-02-06 17:09:48 -05:00
|
|
|
} else if (additionalHeaders.isEmpty()) {
|
2011-01-10 12:47:28 -05:00
|
|
|
// All headers have been downloaded, but there are no additional headers.
|
|
|
|
messageToShow = R.string.message_no_additional_headers_available;
|
|
|
|
}
|
2011-02-06 17:09:48 -05:00
|
|
|
} catch (MessagingException e) {
|
2011-01-10 12:47:28 -05:00
|
|
|
messageToShow = R.string.message_additional_headers_retrieval_failed;
|
|
|
|
}
|
|
|
|
// Show a message to the user, if any
|
2011-02-06 17:09:48 -05:00
|
|
|
if (messageToShow != null) {
|
2011-01-10 12:47:28 -05:00
|
|
|
Toast toast = Toast.makeText(mContext, messageToShow, Toast.LENGTH_LONG);
|
|
|
|
toast.setGravity(Gravity.CENTER_VERTICAL | Gravity.CENTER_HORIZONTAL, 0, 0);
|
|
|
|
toast.show();
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2011-02-06 17:09:48 -05:00
|
|
|
public void populate(final Message message, final Account account) throws MessagingException {
|
2011-01-10 12:47:28 -05:00
|
|
|
final Contacts contacts = K9.showContactName() ? mContacts : null;
|
|
|
|
final CharSequence from = Address.toFriendly(message.getFrom(), contacts);
|
|
|
|
final String date = mDateFormat.format(message.getSentDate());
|
|
|
|
final String time = mTimeFormat.format(message.getSentDate());
|
|
|
|
final CharSequence to = Address.toFriendly(message.getRecipients(Message.RecipientType.TO), contacts);
|
|
|
|
final CharSequence cc = Address.toFriendly(message.getRecipients(Message.RecipientType.CC), contacts);
|
|
|
|
|
2013-02-10 19:01:42 -05:00
|
|
|
Address[] fromAddrs = message.getFrom();
|
|
|
|
Address[] toAddrs = message.getRecipients(Message.RecipientType.TO);
|
|
|
|
Address[] ccAddrs = message.getRecipients(Message.RecipientType.CC);
|
|
|
|
boolean fromMe = mMessageHelper.toMe(account, fromAddrs);
|
|
|
|
|
|
|
|
String counterpartyAddress = null;
|
|
|
|
if (fromMe) {
|
|
|
|
if (toAddrs.length > 0) {
|
|
|
|
counterpartyAddress = toAddrs[0].getAddress();
|
|
|
|
} else if (ccAddrs.length > 0) {
|
|
|
|
counterpartyAddress = ccAddrs[0].getAddress();
|
|
|
|
}
|
|
|
|
} else if (fromAddrs.length > 0) {
|
|
|
|
counterpartyAddress = fromAddrs[0].getAddress();
|
|
|
|
}
|
|
|
|
|
2013-02-11 01:29:22 -05:00
|
|
|
/*
|
|
|
|
* Only reset visibility of the subject if populate() was called because a new
|
|
|
|
* message is shown. If it is the same, do not force the subject visible, because
|
|
|
|
* this breaks the MessageTitleView in the action bar, which may hide our subject
|
|
|
|
* if it fits in the action bar but is only called when a new message is shown
|
|
|
|
* or the device is rotated.
|
|
|
|
*/
|
|
|
|
if (mMessage == null || mMessage.getId() != message.getId()) {
|
|
|
|
mSubjectView.setVisibility(VISIBLE);
|
|
|
|
}
|
|
|
|
|
2011-01-10 12:47:28 -05:00
|
|
|
mMessage = message;
|
|
|
|
mAccount = account;
|
|
|
|
|
2013-02-10 19:01:42 -05:00
|
|
|
if (K9.showContactPicture()) {
|
|
|
|
mContactBadge.setVisibility(View.VISIBLE);
|
|
|
|
mContactsPictureLoader = new ContactPictureLoader(mContext, R.drawable.ic_contact_picture);
|
|
|
|
} else {
|
|
|
|
mContactBadge.setVisibility(View.GONE);
|
|
|
|
}
|
|
|
|
|
2012-09-07 23:33:53 -04:00
|
|
|
final String subject = message.getSubject();
|
|
|
|
if (StringUtils.isNullOrEmpty(subject)) {
|
|
|
|
mSubjectView.setText(mContext.getText(R.string.general_no_subject));
|
|
|
|
} else {
|
|
|
|
mSubjectView.setText(subject);
|
|
|
|
}
|
|
|
|
mSubjectView.setTextColor(0xff000000 | defaultSubjectColor);
|
2011-01-10 12:47:28 -05:00
|
|
|
|
2011-02-06 17:09:48 -05:00
|
|
|
if (date != null) {
|
2013-02-08 21:26:19 -05:00
|
|
|
mDateView.setText(time + " - " + date);
|
2011-02-06 17:09:48 -05:00
|
|
|
} else {
|
2013-02-08 21:26:19 -05:00
|
|
|
mDateView.setText(time);
|
|
|
|
}
|
2013-02-10 19:01:42 -05:00
|
|
|
|
2013-02-11 03:07:19 -05:00
|
|
|
if (K9.showContactPicture()) {
|
|
|
|
mContactBadge.assignContactFromEmail(counterpartyAddress, true);
|
|
|
|
if (counterpartyAddress != null) {
|
|
|
|
mContactsPictureLoader.loadContactPicture(counterpartyAddress, mContactBadge);
|
|
|
|
} else {
|
|
|
|
mContactBadge.setImageResource(R.drawable.ic_contact_picture);
|
|
|
|
}
|
2011-01-10 12:47:28 -05:00
|
|
|
}
|
2013-02-11 03:07:19 -05:00
|
|
|
|
2013-02-10 19:01:42 -05:00
|
|
|
mFromView.setText(from);
|
|
|
|
|
2013-02-08 21:24:36 -05:00
|
|
|
updateAddressField(mToView, to, mToLabel);
|
|
|
|
updateAddressField(mCcView, cc, mCcLabel);
|
2011-01-17 12:25:00 -05:00
|
|
|
mAnsweredIcon.setVisibility(message.isSet(Flag.ANSWERED) ? View.VISIBLE : View.GONE);
|
2012-08-20 22:09:34 -04:00
|
|
|
mForwardedIcon.setVisibility(message.isSet(Flag.FORWARDED) ? View.VISIBLE : View.GONE);
|
2011-01-10 12:47:28 -05:00
|
|
|
mFlagged.setChecked(message.isSet(Flag.FLAGGED));
|
2012-02-21 17:38:43 -05:00
|
|
|
|
|
|
|
int chipColor = mAccount.getChipColor();
|
|
|
|
int chipColorAlpha = (!message.isSet(Flag.SEEN)) ? 255 : 127;
|
|
|
|
mChip.setBackgroundColor(chipColor);
|
|
|
|
mChip.getBackground().setAlpha(chipColorAlpha);
|
|
|
|
|
2011-01-10 12:47:28 -05:00
|
|
|
setVisibility(View.VISIBLE);
|
2012-02-23 22:07:29 -05:00
|
|
|
|
|
|
|
if (mSavedState != null) {
|
|
|
|
if (mSavedState.additionalHeadersVisible) {
|
|
|
|
showAdditionalHeaders();
|
|
|
|
}
|
|
|
|
mSavedState = null;
|
|
|
|
} else {
|
|
|
|
hideAdditionalHeaders();
|
2011-01-10 12:47:28 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-02-06 17:09:48 -05:00
|
|
|
public void onShowAdditionalHeaders() {
|
2011-01-10 12:47:28 -05:00
|
|
|
int currentVisibility = mAdditionalHeadersView.getVisibility();
|
2011-02-06 17:09:48 -05:00
|
|
|
if (currentVisibility == View.VISIBLE) {
|
2011-01-10 12:47:28 -05:00
|
|
|
hideAdditionalHeaders();
|
2012-03-01 23:41:01 -05:00
|
|
|
expand(mToView, false);
|
|
|
|
expand(mCcView, false);
|
2011-02-06 17:09:48 -05:00
|
|
|
} else {
|
2011-01-10 12:47:28 -05:00
|
|
|
showAdditionalHeaders();
|
2012-03-01 23:41:01 -05:00
|
|
|
expand(mToView, true);
|
|
|
|
expand(mCcView, true);
|
2011-01-10 12:47:28 -05:00
|
|
|
}
|
2012-03-01 23:16:58 -05:00
|
|
|
layoutChanged();
|
2011-01-10 12:47:28 -05:00
|
|
|
}
|
|
|
|
|
2013-02-04 07:23:44 -05:00
|
|
|
|
2013-02-08 21:24:36 -05:00
|
|
|
private void updateAddressField(TextView v, CharSequence text, View label) {
|
2013-02-11 03:07:19 -05:00
|
|
|
boolean hasText = !TextUtils.isEmpty(text);
|
2013-02-04 07:23:44 -05:00
|
|
|
|
|
|
|
v.setText(text);
|
2013-02-11 03:07:19 -05:00
|
|
|
v.setVisibility(hasText ? View.VISIBLE : View.GONE);
|
|
|
|
label.setVisibility(hasText ? View.VISIBLE : View.GONE);
|
2013-02-04 07:23:44 -05:00
|
|
|
}
|
|
|
|
|
2012-03-01 23:41:01 -05:00
|
|
|
/**
|
|
|
|
* Expand or collapse a TextView by removing or adding the 2 lines limitation
|
|
|
|
*/
|
|
|
|
private void expand(TextView v, boolean expand) {
|
|
|
|
if (expand) {
|
|
|
|
v.setMaxLines(Integer.MAX_VALUE);
|
|
|
|
v.setEllipsize(null);
|
|
|
|
} else {
|
|
|
|
v.setMaxLines(2);
|
|
|
|
v.setEllipsize(android.text.TextUtils.TruncateAt.END);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-01-10 12:47:28 -05:00
|
|
|
private List<HeaderEntry> getAdditionalHeaders(final Message message)
|
2011-02-06 17:09:48 -05:00
|
|
|
throws MessagingException {
|
2011-01-10 12:47:28 -05:00
|
|
|
List<HeaderEntry> additionalHeaders = new LinkedList<HeaderEntry>();
|
2013-02-08 21:20:19 -05:00
|
|
|
|
2011-11-14 23:32:46 -05:00
|
|
|
Set<String> headerNames = new LinkedHashSet<String>(message.getHeaderNames());
|
2011-02-06 17:09:48 -05:00
|
|
|
for (String headerName : headerNames) {
|
2011-01-10 12:47:28 -05:00
|
|
|
String[] headerValues = message.getHeader(headerName);
|
2011-02-06 17:09:48 -05:00
|
|
|
for (String headerValue : headerValues) {
|
2011-01-10 12:47:28 -05:00
|
|
|
additionalHeaders.add(new HeaderEntry(headerName, headerValue));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return additionalHeaders;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set up the additional headers text view with the supplied header data.
|
|
|
|
*
|
|
|
|
* @param additionalHeaders List of header entries. Each entry consists of a header
|
|
|
|
* name and a header value. Header names may appear multiple
|
|
|
|
* times.
|
|
|
|
* <p/>
|
|
|
|
* This method is always called from within the UI thread by
|
|
|
|
* {@link #showAdditionalHeaders()}.
|
|
|
|
*/
|
2011-02-06 17:09:48 -05:00
|
|
|
private void populateAdditionalHeadersView(final List<HeaderEntry> additionalHeaders) {
|
2011-01-10 12:47:28 -05:00
|
|
|
SpannableStringBuilder sb = new SpannableStringBuilder();
|
|
|
|
boolean first = true;
|
2011-02-06 17:09:48 -05:00
|
|
|
for (HeaderEntry additionalHeader : additionalHeaders) {
|
|
|
|
if (!first) {
|
2011-01-10 12:47:28 -05:00
|
|
|
sb.append("\n");
|
2011-02-06 17:09:48 -05:00
|
|
|
} else {
|
2011-01-10 12:47:28 -05:00
|
|
|
first = false;
|
|
|
|
}
|
|
|
|
StyleSpan boldSpan = new StyleSpan(Typeface.BOLD);
|
|
|
|
SpannableString label = new SpannableString(additionalHeader.label + ": ");
|
|
|
|
label.setSpan(boldSpan, 0, label.length(), 0);
|
|
|
|
sb.append(label);
|
|
|
|
sb.append(MimeUtility.unfoldAndDecode(additionalHeader.value));
|
|
|
|
}
|
|
|
|
mAdditionalHeadersView.setText(sb);
|
|
|
|
}
|
|
|
|
|
2012-02-23 22:07:29 -05:00
|
|
|
@Override
|
|
|
|
public Parcelable onSaveInstanceState() {
|
|
|
|
Parcelable superState = super.onSaveInstanceState();
|
|
|
|
|
|
|
|
SavedState savedState = new SavedState(superState);
|
|
|
|
|
|
|
|
savedState.additionalHeadersVisible = additionalHeadersVisible();
|
|
|
|
|
|
|
|
return savedState;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onRestoreInstanceState(Parcelable state) {
|
|
|
|
if(!(state instanceof SavedState)) {
|
|
|
|
super.onRestoreInstanceState(state);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
SavedState savedState = (SavedState)state;
|
|
|
|
super.onRestoreInstanceState(savedState.getSuperState());
|
|
|
|
|
|
|
|
mSavedState = savedState;
|
|
|
|
}
|
|
|
|
|
|
|
|
static class SavedState extends BaseSavedState {
|
|
|
|
boolean additionalHeadersVisible;
|
|
|
|
|
|
|
|
public static final Parcelable.Creator<SavedState> CREATOR =
|
|
|
|
new Parcelable.Creator<SavedState>() {
|
|
|
|
@Override
|
|
|
|
public SavedState createFromParcel(Parcel in) {
|
|
|
|
return new SavedState(in);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public SavedState[] newArray(int size) {
|
|
|
|
return new SavedState[size];
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
SavedState(Parcelable superState) {
|
|
|
|
super(superState);
|
|
|
|
}
|
|
|
|
|
|
|
|
private SavedState(Parcel in) {
|
|
|
|
super(in);
|
|
|
|
this.additionalHeadersVisible = (in.readInt() != 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void writeToParcel(Parcel out, int flags) {
|
|
|
|
super.writeToParcel(out, flags);
|
|
|
|
out.writeInt((this.additionalHeadersVisible) ? 1 : 0);
|
|
|
|
}
|
|
|
|
}
|
2012-03-01 23:16:58 -05:00
|
|
|
|
|
|
|
public interface OnLayoutChangedListener {
|
|
|
|
void onLayoutChanged();
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setOnLayoutChangedListener(OnLayoutChangedListener listener) {
|
|
|
|
mOnLayoutChangedListener = listener;
|
|
|
|
}
|
|
|
|
|
|
|
|
private void layoutChanged() {
|
|
|
|
if (mOnLayoutChangedListener != null) {
|
|
|
|
mOnLayoutChangedListener.onLayoutChanged();
|
|
|
|
}
|
|
|
|
}
|
2012-09-07 23:33:53 -04:00
|
|
|
|
2013-01-31 20:50:00 -05:00
|
|
|
public void hideSubjectLine() {
|
|
|
|
mSubjectView.setVisibility(GONE);
|
2012-09-07 23:33:53 -04:00
|
|
|
}
|
2011-01-10 12:47:28 -05:00
|
|
|
}
|