mirror of
https://github.com/moparisthebest/Yaaic
synced 2024-11-29 04:12:18 -05:00
Render colors correctly in topics and other foreground colored places.
This commit is contained in:
parent
59c70a750d
commit
7c4abe0c9c
@ -231,7 +231,9 @@ public class Message
|
|||||||
String nick = hasSender() ? "<" + sender + "> " : "";
|
String nick = hasSender() ? "<" + sender + "> " : "";
|
||||||
String timestamp = settings.showTimestamp() ? renderTimeStamp(settings.use24hFormat()) : "";
|
String timestamp = settings.showTimestamp() ? renderTimeStamp(settings.use24hFormat()) : "";
|
||||||
if (settings.showMircColors()) {
|
if (settings.showMircColors()) {
|
||||||
String htmltext = Colors.mircColorParser(TextUtils.htmlEncode(text));
|
// Tagsoup doesn't like when a html string begins with a <font> tag so we'll surround the html with <pre> tags.
|
||||||
|
String entext = "<pre>"+TextUtils.htmlEncode(text).replaceAll(" ", " ")+"</pre>";
|
||||||
|
String htmltext = Colors.mircColorParser(entext);
|
||||||
Spanned colortext = Html2.fromHtml(htmltext);
|
Spanned colortext = Html2.fromHtml(htmltext);
|
||||||
|
|
||||||
canvas = new SpannableString(prefix + timestamp + nick);
|
canvas = new SpannableString(prefix + timestamp + nick);
|
||||||
@ -257,7 +259,15 @@ public class Message
|
|||||||
canvas.setSpan(new ImageSpan(drawable, ImageSpan.ALIGN_BOTTOM), 0, 1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
|
canvas.setSpan(new ImageSpan(drawable, ImageSpan.ALIGN_BOTTOM), 0, 1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
|
||||||
}
|
}
|
||||||
if (hasColor() && settings.showColors()) {
|
if (hasColor() && settings.showColors()) {
|
||||||
canvas.setSpan(new ForegroundColorSpan(color), 0, canvas.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
|
// Only apply the foreground color on areas that don't already have a foreground color.
|
||||||
|
ForegroundColorSpan[] spans = canvas.getSpans(0, canvas.length(), ForegroundColorSpan.class);
|
||||||
|
int start = 0;
|
||||||
|
for (int i = 0; i < spans.length; i++) {
|
||||||
|
canvas.getSpanStart(spans[i]);
|
||||||
|
canvas.setSpan(new ForegroundColorSpan(color), start, canvas.getSpanStart(spans[i]), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
|
||||||
|
start = canvas.getSpanEnd(spans[i]);
|
||||||
|
}
|
||||||
|
canvas.setSpan(new ForegroundColorSpan(color), start, canvas.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3,6 +3,8 @@ package org.yaaic.utils;
|
|||||||
import java.util.regex.Matcher;
|
import java.util.regex.Matcher;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
|
import android.util.Log;
|
||||||
|
|
||||||
|
|
||||||
public class Colors {
|
public class Colors {
|
||||||
/*
|
/*
|
||||||
@ -80,6 +82,7 @@ public class Colors {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Remove left over codes
|
// Remove left over codes
|
||||||
|
Log.d("html", removeStyleAndColors(sb.toString()));
|
||||||
return removeStyleAndColors(sb.toString());
|
return removeStyleAndColors(sb.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -59,6 +59,7 @@ import android.text.style.TextAppearanceSpan;
|
|||||||
import android.text.style.TypefaceSpan;
|
import android.text.style.TypefaceSpan;
|
||||||
import android.text.style.URLSpan;
|
import android.text.style.URLSpan;
|
||||||
import android.text.style.UnderlineSpan;
|
import android.text.style.UnderlineSpan;
|
||||||
|
import android.util.Log;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This class processes HTML strings into displayable styled text.
|
* This class processes HTML strings into displayable styled text.
|
||||||
@ -90,7 +91,7 @@ public class Html2 {
|
|||||||
*/
|
*/
|
||||||
public static interface TagHandler {
|
public static interface TagHandler {
|
||||||
/**
|
/**
|
||||||
* This method will be called whenn the HTML parser encounters
|
* This method will be called when the HTML parser encounters
|
||||||
* a tag that it does not know how to interpret.
|
* a tag that it does not know how to interpret.
|
||||||
*/
|
*/
|
||||||
public void handleTag(boolean opening, String tag,
|
public void handleTag(boolean opening, String tag,
|
||||||
@ -467,6 +468,7 @@ class HtmlToSpannedConverter implements ContentHandler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void handleStartTag(String tag, Attributes attributes) {
|
private void handleStartTag(String tag, Attributes attributes) {
|
||||||
|
Log.d("colors", "handleStartTag: "+tag);
|
||||||
if (tag.equalsIgnoreCase("br")) {
|
if (tag.equalsIgnoreCase("br")) {
|
||||||
// We don't need to handle this. TagSoup will ensure that there's a </br> for each <br>
|
// We don't need to handle this. TagSoup will ensure that there's a </br> for each <br>
|
||||||
// so we can safely emite the linebreaks when we handle the close tag.
|
// so we can safely emite the linebreaks when we handle the close tag.
|
||||||
@ -518,6 +520,7 @@ class HtmlToSpannedConverter implements ContentHandler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void handleEndTag(String tag) {
|
private void handleEndTag(String tag) {
|
||||||
|
Log.d("colors", "handleEndTag: "+tag);
|
||||||
if (tag.equalsIgnoreCase("br")) {
|
if (tag.equalsIgnoreCase("br")) {
|
||||||
handleBr(mSpannableStringBuilder);
|
handleBr(mSpannableStringBuilder);
|
||||||
} else if (tag.equalsIgnoreCase("p")) {
|
} else if (tag.equalsIgnoreCase("p")) {
|
||||||
|
Loading…
Reference in New Issue
Block a user