Merge "Minor visual fixes in message list"

This commit is contained in:
Ben Komalo 2011-08-03 10:40:36 -07:00 committed by Android (Google) Code Review
commit 0a12a6636c
6 changed files with 58 additions and 35 deletions

View File

@ -19,5 +19,10 @@
android:drawable="@drawable/list_wide_read_pressed_holo" />
<item android:state_selected="true"
android:drawable="@drawable/list_wide_read_selected_holo" />
<item android:state_selected="true"
android:state_activated="true"
android:drawable="@drawable/list_wide_read_selected_holo" />
<item android:state_activated="true"
android:drawable="@drawable/list_activated_holo" />
<item android:drawable="@drawable/list_wide_read_normal_holo" />
</selector>

View File

@ -19,5 +19,10 @@
android:drawable="@drawable/list_wide_unread_pressed_holo" />
<item android:state_selected="true"
android:drawable="@drawable/list_wide_unread_selected_holo" />
<item android:state_selected="true"
android:state_activated="true"
android:drawable="@drawable/list_wide_unread_selected_holo" />
<item android:state_activated="true"
android:drawable="@drawable/list_activated_holo" />
<item android:drawable="@drawable/list_wide_unread_normal_holo" />
</selector>

View File

@ -109,7 +109,6 @@ public class MessageListItem extends View {
private String mSubjectAndDescription;
private StaticLayout mSubjectLayout;
public boolean mRead;
public long mTimestamp;
public boolean mHasAttachment = false;
public boolean mHasInvite = true;
public boolean mIsFavorite = false;
@ -132,7 +131,7 @@ public class MessageListItem extends View {
private Drawable mWideReadSelector;
private Drawable mWideUnreadSelector;
public int mSnippetLineCount = NEEDS_LAYOUT;
private int mSnippetLineCount = NEEDS_LAYOUT;
private CharSequence mFormattedSender;
private CharSequence mFormattedDate;
@ -179,13 +178,44 @@ public class MessageListItem extends View {
}
/**
* Sets message subject safely, ensuring the cache is invalidated.
* Sets message subject and snippet safely, ensuring the cache is invalidated.
*/
public void setSubject(String subject) {
public void setText(String subject, String snippet) {
boolean changed = false;
if (!Objects.equal(mSubject, subject)) {
mSubject = subject;
changed = true;
mSubjectAndDescription = null;
}
if (!Objects.equal(mSnippet, snippet)) {
mSnippet = snippet;
mSnippetLineCount = MessageListItem.NEEDS_LAYOUT;
changed = true;
}
if (changed) {
SpannableStringBuilder ssb = new SpannableStringBuilder();
boolean hasSubject = false;
if (!TextUtils.isEmpty(mSubject)) {
SpannableString ss = new SpannableString(mSubject);
ss.setSpan(new StyleSpan(mRead ? Typeface.NORMAL : Typeface.BOLD), 0, ss.length(),
Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
ssb.append(ss);
hasSubject = true;
}
if (!TextUtils.isEmpty(mSnippet)) {
if (hasSubject) {
ssb.append(sSubjectSnippetDivider);
}
ssb.append(mSnippet);
}
mText = ssb;
}
}
public void setTimestamp(long timestamp) {
mFormattedDate = DateUtils.getRelativeTimeSpanString(mContext, timestamp).toString();
}
/**
@ -239,24 +269,9 @@ public class MessageListItem extends View {
}
private void calculateDrawingData() {
SpannableStringBuilder ssb = new SpannableStringBuilder();
boolean hasSubject = false;
if (!TextUtils.isEmpty(mSubject)) {
SpannableString ss = new SpannableString(mSubject);
ss.setSpan(new StyleSpan(mRead ? Typeface.NORMAL : Typeface.BOLD), 0, ss.length(),
Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
ssb.append(ss);
hasSubject = true;
}
if (!TextUtils.isEmpty(mSnippet)) {
if (hasSubject) {
ssb.append(sSubjectSnippetDivider);
}
ssb.append(mSnippet);
}
mText = ssb;
sDefaultPaint.setTextSize(mCoordinates.subjectFontSize);
sDefaultPaint.setColor(mContext.getResources().getColor(
isActivated() ? android.R.color.white : android.R.color.black));
mSubjectLayout = new StaticLayout(mText, sDefaultPaint,
mCoordinates.subjectWidth, Alignment.ALIGN_NORMAL, 1, 0, false /* includePad */);
if (mCoordinates.subjectLineCount < mSubjectLayout.getLineCount()) {
@ -277,8 +292,6 @@ public class MessageListItem extends View {
mFormattedSender = TextUtils.ellipsize(mSender, senderPaint, senderWidth,
TruncateAt.END);
}
// Get a nicely formatted date string (relative to today)
mFormattedDate = DateUtils.getRelativeTimeSpanString(getContext(), mTimestamp).toString();
}
@Override
@ -357,14 +370,19 @@ public class MessageListItem extends View {
mColorChipPaint);
}
int fontColor = mContext.getResources().getColor(
(isActivated() || isPressed()) ? android.R.color.white : android.R.color.black);
// Draw the checkbox
canvas.drawBitmap(mAdapter.isSelected(this) ? sSelectedIconOn : sSelectedIconOff,
mCoordinates.checkmarkX, mCoordinates.checkmarkY, null);
// Draw the sender name
Paint senderPaint = mRead ? sDefaultPaint : sBoldPaint;
senderPaint.setColor(fontColor);
canvas.drawText(mFormattedSender, 0, mFormattedSender.length(),
mCoordinates.sendersX, mCoordinates.sendersY - mCoordinates.sendersAscent,
mRead ? sDefaultPaint : sBoldPaint);
senderPaint);
// Draw the reply state. Draw nothing if neither replied nor forwarded.
if (mHasBeenRepliedTo && mHasBeenForwarded) {
@ -381,6 +399,7 @@ public class MessageListItem extends View {
// Subject and snippet.
sDefaultPaint.setTextSize(mCoordinates.subjectFontSize);
sDefaultPaint.setTypeface(Typeface.DEFAULT);
sDefaultPaint.setColor(fontColor);
canvas.save();
canvas.translate(
mCoordinates.subjectX,
@ -390,6 +409,7 @@ public class MessageListItem extends View {
// Draw the date
sDatePaint.setTextSize(mCoordinates.dateFontSize);
sDatePaint.setColor(fontColor);
int dateX = mCoordinates.dateXEnd
- (int) sDatePaint.measureText(mFormattedDate, 0, mFormattedDate.length());

View File

@ -52,7 +52,6 @@ public class MessageListItemCoordinates {
int checkmarkX;
int checkmarkY;
int checkmarkWidthIncludingMargins;
int checkmarkHeightIncludingMargins;
// Reply and forward state.
int stateX;
@ -67,7 +66,6 @@ public class MessageListItemCoordinates {
int sendersY;
int sendersWidth;
int sendersLineCount;
int sendersLineHeight;
int sendersFontSize;
int sendersAscent;
@ -76,7 +74,6 @@ public class MessageListItemCoordinates {
int subjectY;
int subjectWidth;
int subjectLineCount;
int subjectLineHeight;
int subjectFontSize;
int subjectAscent;
@ -270,7 +267,6 @@ public class MessageListItemCoordinates {
coordinates.sendersY = getY(senders);
coordinates.sendersWidth = getWidth(senders, false);
coordinates.sendersLineCount = getLineCount(senders);
coordinates.sendersLineHeight = senders.getLineHeight();
coordinates.sendersFontSize = (int) senders.getTextSize();
coordinates.sendersAscent = Math.round(senders.getPaint().ascent());
@ -279,7 +275,6 @@ public class MessageListItemCoordinates {
coordinates.subjectY = getY(subject);
coordinates.subjectWidth = getWidth(subject, false);
coordinates.subjectLineCount = getLineCount(subject);
coordinates.subjectLineHeight = subject.getLineHeight();
coordinates.subjectFontSize = (int) subject.getTextSize();
coordinates.subjectAscent = Math.round(subject.getPaint().ascent());

View File

@ -196,11 +196,9 @@ import java.util.Set;
itemView.mHasBeenRepliedTo = (flags & Message.FLAG_REPLIED_TO) != 0;
itemView.mHasBeenForwarded = (flags & Message.FLAG_FORWARDED) != 0;
itemView.mHasAttachment = cursor.getInt(COLUMN_ATTACHMENTS) != 0;
itemView.mTimestamp = cursor.getLong(COLUMN_DATE);
itemView.setTimestamp(cursor.getLong(COLUMN_DATE));
itemView.mSender = cursor.getString(COLUMN_DISPLAY_NAME);
itemView.mSnippet = cursor.getString(COLUMN_SNIPPET);
itemView.setSubject(cursor.getString(COLUMN_SUBJECT));
itemView.mSnippetLineCount = MessageListItem.NEEDS_LAYOUT;
itemView.setText(cursor.getString(COLUMN_SUBJECT), cursor.getString(COLUMN_SNIPPET));
itemView.mColorChipPaint =
mShowColorChips ? mResourceHelper.getAccountColorPaint(accountId) : null;

View File

@ -47,8 +47,8 @@ import com.android.emailcommon.Logging;
public class ThreePaneLayout extends LinearLayout implements View.OnClickListener {
private static final boolean ANIMATION_DEBUG = false; // DON'T SUBMIT WITH true
private static final int ANIMATION_DURATION = ANIMATION_DEBUG ? 1000 : 80;
private static final TimeInterpolator INTERPOLATOR = new DecelerateInterpolator(1.5f);
private static final int ANIMATION_DURATION = ANIMATION_DEBUG ? 1000 : 150;
private static final TimeInterpolator INTERPOLATOR = new DecelerateInterpolator(1.75f);
/** Uninitialized state -- {@link #changePaneState} hasn't been called yet. */
private static final int STATE_UNINITIALIZED = -1;