From ac14fe8d02b4e7d8009ec11a62b23e54b68696c4 Mon Sep 17 00:00:00 2001 From: Jesse Vincent Date: Fri, 31 Oct 2008 04:38:51 +0000 Subject: [PATCH] Replace handrolled linkifier with android.text.util.Linkify. --- src/com/fsck/k9/activity/MessageView.java | 27 ++++++++++------------- 1 file changed, 12 insertions(+), 15 deletions(-) diff --git a/src/com/fsck/k9/activity/MessageView.java b/src/com/fsck/k9/activity/MessageView.java index 3e0c3e7e6..532096648 100644 --- a/src/com/fsck/k9/activity/MessageView.java +++ b/src/com/fsck/k9/activity/MessageView.java @@ -25,7 +25,10 @@ import android.os.Bundle; import android.os.Environment; import android.os.Handler; import android.os.Process; +import android.text.Spannable; +import android.text.SpannableString; import android.text.util.Regex; +import android.text.util.Linkify; import android.util.Config; import android.util.Log; import android.view.KeyEvent; @@ -691,6 +694,7 @@ public class MessageView extends Activity } class Listener extends MessagingListener { + @Override public void loadMessageForViewHeadersAvailable(Account account, String folder, String uid, final Message message) { @@ -719,6 +723,7 @@ public class MessageView extends Activity @Override public void loadMessageForViewBodyAvailable(Account account, String folder, String uid, Message message) { + SpannableString markup; MessageView.this.mMessage = message; try { Part part = MimeUtility.findFirstPartByMimeType(mMessage, "text/html"); @@ -731,25 +736,15 @@ public class MessageView extends Activity text = text.replaceAll("cid:", "http://cid/"); } else { /* - * Linkify the plain text and convert it to HTML by replacing + * Convert plain text to HTML by replacing * \r?\n with
and adding a html/body wrapper. */ - Matcher m = Regex.WEB_URL_PATTERN.matcher(text); - StringBuffer sb = new StringBuffer(); - while (m.find()) { - int start = m.start(); - if (start != 0 && text.charAt(start - 1) != '@') { - m.appendReplacement(sb, "$0"); - } - else { - m.appendReplacement(sb, "$0"); - } - } - m.appendTail(sb); - text = sb.toString().replaceAll("\r?\n", "
"); + text = text.replaceAll("\r?\n", "
"); text = "" + text + ""; } + + /* * TODO this should be smarter, change to regex for img, but consider how to * get backgroung images and a million other things that HTML allows. @@ -757,8 +752,10 @@ public class MessageView extends Activity if (text.contains("