private void updateBackground() { int backgroundId; if (mConversation.isChecked()) { backgroundId = R.drawable.list_selected_holo_light; } else if (mConversation.hasUnreadMessages()) { backgroundId = R.drawable.conversation_item_background_unread; } else { backgroundId = R.drawable.conversation_item_background_read; } Drawable background = mContext.getResources().getDrawable(backgroundId); setBackground(background); }
private CharSequence formatMessage() { final int color = android.R.styleable.Theme_textColorSecondary; String from = mConversation.getRecipients().formatNames(", "); Log.v("formatMessage", "formatMessage: " + from); SpannableStringBuilder buf = new SpannableStringBuilder(from); try { if (mConversation.hasUnreadMessages() && mConversation.getUnReadMessageCount(mConversation.getThreadId()) != 0) { if (mConversation.getUnReadMessageCount(mConversation.getThreadId()) != 0) { buf.setSpan(STYLE_BOLD, 0, buf.length(), Spannable.SPAN_INCLUSIVE_EXCLUSIVE); buf.append(" "); // 010 make it on buf.append( mContext .getResources() .getString( R.string.message_count_format, mConversation.getUnReadMessageCount(mConversation.getThreadId()))); buf.append(" /"); // 010未读"/"已读之间的分隔 } else { mConversation.setHasUnreadMessages(false); } } } catch (Exception e) { e.printStackTrace(); } if (mConversation.getMessageCount() >= 1) { int before = buf.length(); buf.append( mContext .getResources() .getString(R.string.message_count_format, mConversation.getMessageCount())); buf.setSpan( new ForegroundColorSpan(mContext.getResources().getColor(R.color.message_count_color)), before, buf.length(), Spannable.SPAN_INCLUSIVE_EXCLUSIVE); } if (mConversation.hasDraft()) { buf.append(mContext.getResources().getString(R.string.draft_separator)); int before = buf.length(); int size; buf.append(mContext.getResources().getString(R.string.has_draft)); size = android.R.style.TextAppearance_Small; buf.setSpan( new TextAppearanceSpan(mContext, size, color), before, buf.length(), Spannable.SPAN_INCLUSIVE_EXCLUSIVE); buf.setSpan( new ForegroundColorSpan(mContext.getResources().getColor(R.drawable.text_color_red)), before, buf.length(), Spannable.SPAN_INCLUSIVE_EXCLUSIVE); } // Unread messages are shown in bold return buf; }