From 842a5ee1234fbb1b487cb84a0b81af07829c322a Mon Sep 17 00:00:00 2001 From: Koji Arai Date: Wed, 1 Sep 2010 01:35:20 +0000 Subject: [PATCH] Update issue 2144 Use setSpan() instead of Html.fromHtml() Should clear cached name of contacts at MessageView#onClickSender(). --- src/com/fsck/k9/activity/MessageView.java | 2 ++ src/com/fsck/k9/mail/Address.java | 27 +++++++++++++++++++++-- 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/src/com/fsck/k9/activity/MessageView.java b/src/com/fsck/k9/activity/MessageView.java index f1c3c98f9..b65f38c6d 100644 --- a/src/com/fsck/k9/activity/MessageView.java +++ b/src/com/fsck/k9/activity/MessageView.java @@ -1405,6 +1405,8 @@ public class MessageView extends K9Activity implements OnClickListener { final Address senderEmail = mMessage.getFrom()[0]; mContacts.createContact(this, senderEmail); + + Address.clearContactsNameCache(); } catch (Exception e) { diff --git a/src/com/fsck/k9/mail/Address.java b/src/com/fsck/k9/mail/Address.java index 65daca9b9..32fa6ed38 100644 --- a/src/com/fsck/k9/mail/Address.java +++ b/src/com/fsck/k9/mail/Address.java @@ -2,8 +2,12 @@ package com.fsck.k9.mail; import android.database.Cursor; +import android.graphics.Color; import android.text.Html; +import android.text.Spannable; +import android.text.SpannableString; import android.text.SpannableStringBuilder; +import android.text.style.ForegroundColorSpan; import android.text.util.Rfc822Token; import android.text.util.Rfc822Tokenizer; import android.util.Log; @@ -33,6 +37,11 @@ public class Address */ private static final Address[] EMPTY_ADDRESS_ARRAY = new Address[0]; private static Map sContactsName = new ConcurrentHashMap(); + + public static void clearContactsNameCache() { + sContactsName.clear(); + } + private static final String NO_ENTRY = ""; String mAddress; @@ -251,9 +260,16 @@ public class Address if (contacts != null) { String name = sContactsName.get(mAddress); + if (name != null && name != NO_ENTRY) { - return Html.fromHtml("" + name + ""); // TODO: use setSpan + SpannableString sname = new SpannableString(name); + sname.setSpan(new ForegroundColorSpan(Color.BLUE), + 0, + sname.length(), + Spannable.SPAN_EXCLUSIVE_EXCLUSIVE + ); + return sname; } if (name == null) { @@ -267,7 +283,14 @@ public class Address cursor.moveToFirst(); name = contacts.getName(cursor); sContactsName.put(mAddress, name); - return Html.fromHtml("" + name + ""); // TODO: use setSpan + + SpannableString sname = new SpannableString(name); + sname.setSpan(new ForegroundColorSpan(Color.BLUE), + 0, + sname.length(), + Spannable.SPAN_EXCLUSIVE_EXCLUSIVE + ); + return sname; } else {