Search in sources :

Example 1 with WPQuoteSpan

use of org.wordpress.android.util.helpers.WPQuoteSpan in project WordPress-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) {
    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;
}
Also used : WPHtmlTagHandler(org.wordpress.android.util.helpers.WPHtmlTagHandler) WPQuoteSpan(org.wordpress.android.util.helpers.WPQuoteSpan) ForegroundColorSpan(android.text.style.ForegroundColorSpan) QuoteSpan(android.text.style.QuoteSpan) WPQuoteSpan(org.wordpress.android.util.helpers.WPQuoteSpan) SpannableStringBuilder(android.text.SpannableStringBuilder)

Aggregations

SpannableStringBuilder (android.text.SpannableStringBuilder)1 ForegroundColorSpan (android.text.style.ForegroundColorSpan)1 QuoteSpan (android.text.style.QuoteSpan)1 WPHtmlTagHandler (org.wordpress.android.util.helpers.WPHtmlTagHandler)1 WPQuoteSpan (org.wordpress.android.util.helpers.WPQuoteSpan)1