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;
|
|
|
|
import android.text.style.StyleSpan;
|
|
|
|
import android.util.Log;
|
|
|
|
import android.util.AttributeSet;
|
|
|
|
import android.util.TypedValue;
|
|
|
|
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;
|
2012-02-20 22:56:05 -05:00
|
|
|
import android.widget.ImageView;
|
|
|
|
import android.widget.ScrollView;
|
2011-01-10 12:47:28 -05:00
|
|
|
import android.widget.LinearLayout;
|
|
|
|
import android.widget.TextView;
|
|
|
|
import android.widget.Toast;
|
|
|
|
import com.fsck.k9.FontSizes;
|
|
|
|
import com.fsck.k9.K9;
|
|
|
|
import com.fsck.k9.R;
|
|
|
|
import com.fsck.k9.helper.Contacts;
|
|
|
|
import com.fsck.k9.Account;
|
|
|
|
import com.fsck.k9.helper.DateFormatter;
|
|
|
|
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 mTimeView;
|
|
|
|
private TextView mToView;
|
|
|
|
private TextView mCcView;
|
|
|
|
private TextView mSubjectView;
|
|
|
|
private DateFormat mDateFormat;
|
|
|
|
private DateFormat mTimeFormat;
|
|
|
|
|
2012-02-21 17:38:43 -05:00
|
|
|
private View mChip;
|
2012-03-17 23:51:29 -04:00
|
|
|
private View mChip2;
|
|
|
|
private View mChip3;
|
2011-01-10 12:47:28 -05:00
|
|
|
private CheckBox mFlagged;
|
|
|
|
private int defaultSubjectColor;
|
|
|
|
private LinearLayout mToContainerView;
|
|
|
|
private LinearLayout mCcContainerView;
|
|
|
|
private TextView mAdditionalHeadersView;
|
2011-01-17 12:25:00 -05:00
|
|
|
private View mAnsweredIcon;
|
2011-01-10 12:47:28 -05:00
|
|
|
private Message mMessage;
|
|
|
|
private Account mAccount;
|
|
|
|
private FontSizes mFontSizes = K9.getFontSizes();
|
|
|
|
private Contacts mContacts;
|
2012-03-05 22:26:18 -05:00
|
|
|
private ImageView mShowAdditionalHeadersIcon;
|
2012-02-23 22:07:29 -05:00
|
|
|
private SavedState mSavedState;
|
2011-01-10 12:47:28 -05:00
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2011-02-06 17:09:48 -05:00
|
|
|
private void initializeLayout() {
|
2011-01-17 12:25:00 -05:00
|
|
|
mAnsweredIcon = findViewById(R.id.answered);
|
2011-01-10 12:47:28 -05:00
|
|
|
mFromView = (TextView) findViewById(R.id.from);
|
|
|
|
mToView = (TextView) findViewById(R.id.to);
|
|
|
|
mCcView = (TextView) findViewById(R.id.cc);
|
|
|
|
mToContainerView = (LinearLayout) findViewById(R.id.to_container);
|
|
|
|
mCcContainerView = (LinearLayout) findViewById(R.id.cc_container);
|
|
|
|
mSubjectView = (TextView) findViewById(R.id.subject);
|
|
|
|
mAdditionalHeadersView = (TextView) findViewById(R.id.additional_headers_view);
|
2012-02-21 17:38:43 -05:00
|
|
|
mChip = findViewById(R.id.chip);
|
2012-03-17 23:51:29 -04:00
|
|
|
mChip2 = findViewById(R.id.chip2);
|
|
|
|
mChip3 = findViewById(R.id.chip3);
|
2011-01-10 12:47:28 -05:00
|
|
|
mDateView = (TextView) findViewById(R.id.date);
|
|
|
|
mTimeView = (TextView) findViewById(R.id.time);
|
|
|
|
mFlagged = (CheckBox) findViewById(R.id.flagged);
|
2012-03-05 22:26:18 -05:00
|
|
|
mShowAdditionalHeadersIcon = (ImageView) findViewById(R.id.show_additional_headers_icon);
|
2011-01-10 12:47:28 -05:00
|
|
|
|
|
|
|
defaultSubjectColor = mSubjectView.getCurrentTextColor();
|
2012-01-11 20:18:41 -05:00
|
|
|
mSubjectView.setTextSize(TypedValue.COMPLEX_UNIT_SP, mFontSizes.getMessageViewSubject());
|
|
|
|
mTimeView.setTextSize(TypedValue.COMPLEX_UNIT_SP, mFontSizes.getMessageViewTime());
|
|
|
|
mDateView.setTextSize(TypedValue.COMPLEX_UNIT_SP, mFontSizes.getMessageViewDate());
|
|
|
|
mAdditionalHeadersView.setTextSize(TypedValue.COMPLEX_UNIT_SP, mFontSizes.getMessageViewAdditionalHeaders());
|
2012-02-20 22:56:05 -05:00
|
|
|
hideAdditionalHeaders();
|
|
|
|
|
2011-01-17 12:25:00 -05:00
|
|
|
mAnsweredIcon.setVisibility(View.GONE);
|
2012-01-11 20:18:41 -05:00
|
|
|
mFromView.setTextSize(TypedValue.COMPLEX_UNIT_SP, mFontSizes.getMessageViewSender());
|
|
|
|
mToView.setTextSize(TypedValue.COMPLEX_UNIT_SP, mFontSizes.getMessageViewTo());
|
|
|
|
mCcView.setTextSize(TypedValue.COMPLEX_UNIT_SP, mFontSizes.getMessageViewCC());
|
|
|
|
((TextView) findViewById(R.id.to_label)).setTextSize(TypedValue.COMPLEX_UNIT_SP, mFontSizes.getMessageViewTo());
|
|
|
|
((TextView) findViewById(R.id.cc_label)).setTextSize(TypedValue.COMPLEX_UNIT_SP, mFontSizes.getMessageViewCC());
|
2011-01-10 12:47:28 -05:00
|
|
|
|
2012-03-17 23:51:29 -04:00
|
|
|
findViewById(R.id.show_additional_headers_area).setOnClickListener(this);
|
|
|
|
findViewById(R.id.additional_headers_row).setOnClickListener(this);
|
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);
|
2012-02-21 10:21:47 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onClick(View view) {
|
|
|
|
switch (view.getId()) {
|
2012-03-17 23:51:29 -04:00
|
|
|
case R.id.additional_headers_row:
|
|
|
|
case R.id.show_additional_headers_area: {
|
2011-01-10 12:47:28 -05:00
|
|
|
onShowAdditionalHeaders();
|
2012-02-21 10:21:47 -05:00
|
|
|
break;
|
2011-01-10 12:47:28 -05:00
|
|
|
}
|
2012-02-21 10:21:47 -05:00
|
|
|
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("");
|
2012-03-05 22:26:18 -05:00
|
|
|
mShowAdditionalHeadersIcon.setImageResource(R.drawable.show_more);
|
2011-01-10 12:47:28 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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);
|
2012-03-05 22:26:18 -05:00
|
|
|
mShowAdditionalHeadersIcon.setImageResource(R.drawable.show_less);
|
2011-01-10 12:47:28 -05:00
|
|
|
}
|
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);
|
|
|
|
|
|
|
|
mMessage = message;
|
|
|
|
mAccount = account;
|
|
|
|
|
|
|
|
initializeLayout();
|
|
|
|
String subject = message.getSubject();
|
2011-02-06 17:09:48 -05:00
|
|
|
if (subject == null || subject.equals("")) {
|
2011-01-10 12:47:28 -05:00
|
|
|
mSubjectView.setText(mContext.getText(R.string.general_no_subject));
|
2011-02-06 17:09:48 -05:00
|
|
|
} else {
|
2011-01-10 12:47:28 -05:00
|
|
|
mSubjectView.setText(subject);
|
|
|
|
}
|
|
|
|
mSubjectView.setTextColor(0xff000000 | defaultSubjectColor);
|
|
|
|
|
|
|
|
mFromView.setText(from);
|
|
|
|
|
2011-02-06 17:09:48 -05:00
|
|
|
if (date != null) {
|
2011-01-10 12:47:28 -05:00
|
|
|
mDateView.setText(date);
|
|
|
|
mDateView.setVisibility(View.VISIBLE);
|
2011-02-06 17:09:48 -05:00
|
|
|
} else {
|
2011-01-10 12:47:28 -05:00
|
|
|
mDateView.setVisibility(View.GONE);
|
|
|
|
}
|
|
|
|
mTimeView.setText(time);
|
|
|
|
mToContainerView.setVisibility((to != null && to.length() > 0) ? View.VISIBLE : View.GONE);
|
|
|
|
mToView.setText(to);
|
|
|
|
mCcContainerView.setVisibility((cc != null && cc.length() > 0) ? View.VISIBLE : View.GONE);
|
|
|
|
mCcView.setText(cc);
|
2011-01-17 12:25:00 -05:00
|
|
|
mAnsweredIcon.setVisibility(message.isSet(Flag.ANSWERED) ? 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);
|
2012-03-17 23:51:29 -04:00
|
|
|
mChip2.setBackgroundColor(chipColor);
|
|
|
|
mChip2.getBackground().setAlpha(chipColorAlpha);
|
|
|
|
mChip3.setBackgroundColor(chipColor);
|
|
|
|
mChip3.getBackground().setAlpha(chipColorAlpha);
|
2012-02-21 17:38:43 -05:00
|
|
|
|
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
|
|
|
}
|
|
|
|
|
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>();
|
|
|
|
/*
|
|
|
|
* Remove "Subject" header as it is already shown in the standard
|
|
|
|
* message view header. But do show "From", "To", and "Cc" again.
|
|
|
|
* This time including the email addresses. See issue 1805.
|
|
|
|
*/
|
2011-11-14 23:32:46 -05:00
|
|
|
Set<String> headerNames = new LinkedHashSet<String>(message.getHeaderNames());
|
2011-01-10 12:47:28 -05:00
|
|
|
headerNames.remove("Subject");
|
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;
|
|
|
|
|
|
|
|
@SuppressWarnings("hiding")
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
}
|
2011-01-10 12:47:28 -05:00
|
|
|
}
|