1
0
mirror of https://github.com/moparisthebest/k-9 synced 2025-01-31 07:10:14 -05:00

Update issue 2144

Use setSpan() instead of Html.fromHtml()
Should clear cached name of contacts at MessageView#onClickSender().
This commit is contained in:
Koji Arai 2010-09-01 01:35:20 +00:00
parent a83fd2d548
commit 842a5ee123
2 changed files with 27 additions and 2 deletions

View File

@ -1405,6 +1405,8 @@ public class MessageView extends K9Activity implements OnClickListener
{ {
final Address senderEmail = mMessage.getFrom()[0]; final Address senderEmail = mMessage.getFrom()[0];
mContacts.createContact(this, senderEmail); mContacts.createContact(this, senderEmail);
Address.clearContactsNameCache();
} }
catch (Exception e) catch (Exception e)
{ {

View File

@ -2,8 +2,12 @@
package com.fsck.k9.mail; package com.fsck.k9.mail;
import android.database.Cursor; import android.database.Cursor;
import android.graphics.Color;
import android.text.Html; import android.text.Html;
import android.text.Spannable;
import android.text.SpannableString;
import android.text.SpannableStringBuilder; import android.text.SpannableStringBuilder;
import android.text.style.ForegroundColorSpan;
import android.text.util.Rfc822Token; import android.text.util.Rfc822Token;
import android.text.util.Rfc822Tokenizer; import android.text.util.Rfc822Tokenizer;
import android.util.Log; import android.util.Log;
@ -33,6 +37,11 @@ public class Address
*/ */
private static final Address[] EMPTY_ADDRESS_ARRAY = new Address[0]; private static final Address[] EMPTY_ADDRESS_ARRAY = new Address[0];
private static Map<String,String> sContactsName = new ConcurrentHashMap<String, String>(); private static Map<String,String> sContactsName = new ConcurrentHashMap<String, String>();
public static void clearContactsNameCache() {
sContactsName.clear();
}
private static final String NO_ENTRY = ""; private static final String NO_ENTRY = "";
String mAddress; String mAddress;
@ -251,9 +260,16 @@ public class Address
if (contacts != null) if (contacts != null)
{ {
String name = sContactsName.get(mAddress); String name = sContactsName.get(mAddress);
if (name != null && name != NO_ENTRY) if (name != null && name != NO_ENTRY)
{ {
return Html.fromHtml("<font color=\"Blue\">" + name + "</font>"); // 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) if (name == null)
{ {
@ -267,7 +283,14 @@ public class Address
cursor.moveToFirst(); cursor.moveToFirst();
name = contacts.getName(cursor); name = contacts.getName(cursor);
sContactsName.put(mAddress, name); sContactsName.put(mAddress, name);
return Html.fromHtml("<font color=\"Blue\">" + name + "</font>"); // TODO: use setSpan
SpannableString sname = new SpannableString(name);
sname.setSpan(new ForegroundColorSpan(Color.BLUE),
0,
sname.length(),
Spannable.SPAN_EXCLUSIVE_EXCLUSIVE
);
return sname;
} }
else else
{ {