Search in sources :

Example 36 with QuoteSpan

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;
}
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)

Example 37 with QuoteSpan

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);
    }
}
Also used : QuoteSpan(android.text.style.QuoteSpan)

Example 38 with QuoteSpan

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

Example 39 with QuoteSpan

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);
    }
}
Also used : CustomQuoteSpan(me.ccrama.redditslide.Views.CustomQuoteSpan) QuoteSpan(android.text.style.QuoteSpan) CustomQuoteSpan(me.ccrama.redditslide.Views.CustomQuoteSpan) TextPaint(android.text.TextPaint)

Aggregations

QuoteSpan (android.text.style.QuoteSpan)39 StyleSpan (android.text.style.StyleSpan)9 StrikethroughSpan (android.text.style.StrikethroughSpan)7 RelativeSizeSpan (android.text.style.RelativeSizeSpan)6 TypefaceSpan (android.text.style.TypefaceSpan)6 SpannableStringBuilder (android.text.SpannableStringBuilder)5 SubscriptSpan (android.text.style.SubscriptSpan)5 SuperscriptSpan (android.text.style.SuperscriptSpan)5 ForegroundColorSpan (android.text.style.ForegroundColorSpan)4 URLSpan (android.text.style.URLSpan)4 UnderlineSpan (android.text.style.UnderlineSpan)4 TextView (android.widget.TextView)3 WPHtmlTagHandler (org.wordpress.android.util.helpers.WPHtmlTagHandler)3 WPQuoteSpan (org.wordpress.android.util.helpers.WPQuoteSpan)3 WPUnderlineSpan (org.wordpress.android.util.helpers.WPUnderlineSpan)3 Spannable (android.text.Spannable)2 SpannableString (android.text.SpannableString)2 TextPaint (android.text.TextPaint)2 BackgroundColorSpan (android.text.style.BackgroundColorSpan)2 BulletSpan (android.text.style.BulletSpan)2