mirror of
https://github.com/moparisthebest/k-9
synced 2024-11-27 11:42:16 -05:00
Replace handrolled linkifier with android.text.util.Linkify.
This commit is contained in:
parent
21f2d934b6
commit
ac14fe8d02
@ -25,7 +25,10 @@ import android.os.Bundle;
|
|||||||
import android.os.Environment;
|
import android.os.Environment;
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
import android.os.Process;
|
import android.os.Process;
|
||||||
|
import android.text.Spannable;
|
||||||
|
import android.text.SpannableString;
|
||||||
import android.text.util.Regex;
|
import android.text.util.Regex;
|
||||||
|
import android.text.util.Linkify;
|
||||||
import android.util.Config;
|
import android.util.Config;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.view.KeyEvent;
|
import android.view.KeyEvent;
|
||||||
@ -691,6 +694,7 @@ public class MessageView extends Activity
|
|||||||
}
|
}
|
||||||
|
|
||||||
class Listener extends MessagingListener {
|
class Listener extends MessagingListener {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void loadMessageForViewHeadersAvailable(Account account, String folder, String uid,
|
public void loadMessageForViewHeadersAvailable(Account account, String folder, String uid,
|
||||||
final Message message) {
|
final Message message) {
|
||||||
@ -719,6 +723,7 @@ public class MessageView extends Activity
|
|||||||
@Override
|
@Override
|
||||||
public void loadMessageForViewBodyAvailable(Account account, String folder, String uid,
|
public void loadMessageForViewBodyAvailable(Account account, String folder, String uid,
|
||||||
Message message) {
|
Message message) {
|
||||||
|
SpannableString markup;
|
||||||
MessageView.this.mMessage = message;
|
MessageView.this.mMessage = message;
|
||||||
try {
|
try {
|
||||||
Part part = MimeUtility.findFirstPartByMimeType(mMessage, "text/html");
|
Part part = MimeUtility.findFirstPartByMimeType(mMessage, "text/html");
|
||||||
@ -731,25 +736,15 @@ public class MessageView extends Activity
|
|||||||
text = text.replaceAll("cid:", "http://cid/");
|
text = text.replaceAll("cid:", "http://cid/");
|
||||||
} else {
|
} else {
|
||||||
/*
|
/*
|
||||||
* Linkify the plain text and convert it to HTML by replacing
|
* Convert plain text to HTML by replacing
|
||||||
* \r?\n with <br> and adding a html/body wrapper.
|
* \r?\n with <br> and adding a html/body wrapper.
|
||||||
*/
|
*/
|
||||||
Matcher m = Regex.WEB_URL_PATTERN.matcher(text);
|
text = text.replaceAll("\r?\n", "<br>");
|
||||||
StringBuffer sb = new StringBuffer();
|
|
||||||
while (m.find()) {
|
|
||||||
int start = m.start();
|
|
||||||
if (start != 0 && text.charAt(start - 1) != '@') {
|
|
||||||
m.appendReplacement(sb, "<a href=\"$0\">$0</a>");
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
m.appendReplacement(sb, "$0");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
m.appendTail(sb);
|
|
||||||
text = sb.toString().replaceAll("\r?\n", "<br>");
|
|
||||||
text = "<html><body>" + text + "</body></html>";
|
text = "<html><body>" + text + "</body></html>";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* TODO this should be smarter, change to regex for img, but consider how to
|
* 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.
|
* get backgroung images and a million other things that HTML allows.
|
||||||
@ -757,8 +752,10 @@ public class MessageView extends Activity
|
|||||||
if (text.contains("<img")) {
|
if (text.contains("<img")) {
|
||||||
mHandler.showShowPictures(true);
|
mHandler.showShowPictures(true);
|
||||||
}
|
}
|
||||||
|
markup = new SpannableString(text);
|
||||||
|
Linkify.addLinks(markup, Linkify.ALL);
|
||||||
|
|
||||||
mMessageContentView.loadDataWithBaseURL("email://", text, "text/html",
|
mMessageContentView.loadDataWithBaseURL("email://", markup.toString(), "text/html",
|
||||||
"utf-8", null);
|
"utf-8", null);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
Loading…
Reference in New Issue
Block a user