use of android.text.style.QuoteSpan in project WordPress-Utils-Android by wordpress-mobile.
the class HtmlUtils method fromHtml.
/**
* An alternative to Html.fromHtml() supporting {@code <ul>}, {@code <ol>}, {@code <blockquote>}
* tags and replacing EmoticonsUtils with Emojis
* @param source
* @param wpImageGetter
*/
public static SpannableStringBuilder fromHtml(String source, WPImageGetter wpImageGetter) {
source = replaceListTagsWithCustomTags(source);
SpannableStringBuilder html;
try {
html = (SpannableStringBuilder) Html.fromHtml(source, wpImageGetter, new WPHtmlTagHandler());
} catch (RuntimeException runtimeException) {
// In case our tag handler fails
html = (SpannableStringBuilder) Html.fromHtml(source, wpImageGetter, null);
}
EmoticonsUtils.replaceEmoticonsWithEmoji(html);
QuoteSpan[] spans = html.getSpans(0, html.length(), QuoteSpan.class);
for (QuoteSpan span : spans) {
html.setSpan(new WPQuoteSpan(), html.getSpanStart(span), html.getSpanEnd(span), html.getSpanFlags(span));
html.setSpan(new ForegroundColorSpan(0xFF666666), html.getSpanStart(span), html.getSpanEnd(span), html.getSpanFlags(span));
html.removeSpan(span);
}
return html;
}
use of android.text.style.QuoteSpan in project BBS-Android by bdpqchen.
the class QuoteReplaceUtil method replaceQuoteSpans.
public static void replaceQuoteSpans(Spannable spannable) {
QuoteSpan[] quoteSpans = spannable.getSpans(0, spannable.length(), QuoteSpan.class);
for (QuoteSpan quoteSpan : quoteSpans) {
int start = spannable.getSpanStart(quoteSpan);
int end = spannable.getSpanEnd(quoteSpan);
int flags = spannable.getSpanFlags(quoteSpan);
spannable.removeSpan(quoteSpan);
spannable.setSpan(new CustomQuoteSpan(8, 20), start, end, flags);
}
}
use of android.text.style.QuoteSpan in project WordPress-Utils-Android by wordpress-mobile.
the class HtmlUtils method fromHtml.
/**
* An alternative to Html.fromHtml() supporting {@code <ul>}, {@code <ol>}, {@code <blockquote>}
* tags and replacing EmoticonsUtils with Emojis
* @param source
* @param imageGetter
*/
public static SpannableStringBuilder fromHtml(String source, ImageGetter imageGetter) {
source = replaceListTagsWithCustomTags(source);
SpannableStringBuilder html;
try {
html = (SpannableStringBuilder) Html.fromHtml(source, imageGetter, new WPHtmlTagHandler());
} catch (RuntimeException runtimeException) {
// In case our tag handler fails
try {
html = (SpannableStringBuilder) Html.fromHtml(source, imageGetter, null);
} catch (IllegalArgumentException illegalArgumentException) {
// In case the html is missing a required parameter (for example: "src" missing from img)
html = new SpannableStringBuilder("");
AppLog.w(UTILS, "Could not parse html");
}
}
EmoticonsUtils.replaceEmoticonsWithEmoji(html);
QuoteSpan[] spans = html.getSpans(0, html.length(), QuoteSpan.class);
for (QuoteSpan span : spans) {
html.setSpan(new WPQuoteSpan(), html.getSpanStart(span), html.getSpanEnd(span), html.getSpanFlags(span));
html.setSpan(new ForegroundColorSpan(0xFF666666), html.getSpanStart(span), html.getSpanEnd(span), html.getSpanFlags(span));
html.removeSpan(span);
}
return html;
}
use of android.text.style.QuoteSpan in project Slide by ccrama.
the class SpoilerRobotoTextView method replaceQuoteSpans.
/**
* Replaces the blue line produced by <blockquote>s with something more visible
*
* @param spannable parsed comment text #fromHtml
*/
private void replaceQuoteSpans(Spannable spannable) {
QuoteSpan[] quoteSpans = spannable.getSpans(0, spannable.length(), QuoteSpan.class);
for (QuoteSpan quoteSpan : quoteSpans) {
final int start = spannable.getSpanStart(quoteSpan);
final int end = spannable.getSpanEnd(quoteSpan);
final int flags = spannable.getSpanFlags(quoteSpan);
spannable.removeSpan(quoteSpan);
// If the theme is Light or Sepia, use a darker blue; otherwise, use a lighter blue
final int barColor = ContextCompat.getColor(getContext(), SettingValues.currentTheme == 1 || SettingValues.currentTheme == 5 ? R.color.md_blue_600 : R.color.md_blue_400);
final int BAR_WIDTH = 4;
final int GAP = 5;
spannable.setSpan(new CustomQuoteSpan(// bar color
barColor, // bar width
BAR_WIDTH, // bar + text gap
GAP), start, end, flags);
}
}
Aggregations