Search in sources :

Example 1 with BulletSpan

use of android.text.style.BulletSpan in project Knife by mthli.

the class KnifeParser method withinBullet.

private static void withinBullet(StringBuilder out, Spanned text, int start, int end) {
    out.append("<ul>");
    int next;
    for (int i = start; i < end; i = next) {
        next = text.nextSpanTransition(i, end, BulletSpan.class);
        BulletSpan[] spans = text.getSpans(i, next, BulletSpan.class);
        for (BulletSpan span : spans) {
            out.append("<li>");
        }
        withinContent(out, text, i, next);
        for (BulletSpan span : spans) {
            out.append("</li>");
        }
    }
    out.append("</ul>");
}
Also used : BulletSpan(android.text.style.BulletSpan)

Example 2 with BulletSpan

use of android.text.style.BulletSpan in project Knife by mthli.

the class KnifeText method switchToKnifeStyle.

protected void switchToKnifeStyle(Editable editable, int start, int end) {
    BulletSpan[] bulletSpans = editable.getSpans(start, end, BulletSpan.class);
    for (BulletSpan span : bulletSpans) {
        int spanStart = editable.getSpanStart(span);
        int spanEnd = editable.getSpanEnd(span);
        spanEnd = 0 < spanEnd && spanEnd < editable.length() && editable.charAt(spanEnd) == '\n' ? spanEnd - 1 : spanEnd;
        editable.removeSpan(span);
        editable.setSpan(new KnifeBulletSpan(bulletColor, bulletRadius, bulletGapWidth), spanStart, spanEnd, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
    }
    QuoteSpan[] quoteSpans = editable.getSpans(start, end, QuoteSpan.class);
    for (QuoteSpan span : quoteSpans) {
        int spanStart = editable.getSpanStart(span);
        int spanEnd = editable.getSpanEnd(span);
        spanEnd = 0 < spanEnd && spanEnd < editable.length() && editable.charAt(spanEnd) == '\n' ? spanEnd - 1 : spanEnd;
        editable.removeSpan(span);
        editable.setSpan(new KnifeQuoteSpan(quoteColor, quoteStripeWidth, quoteGapWidth), spanStart, spanEnd, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
    }
    URLSpan[] urlSpans = editable.getSpans(start, end, URLSpan.class);
    for (URLSpan span : urlSpans) {
        int spanStart = editable.getSpanStart(span);
        int spanEnd = editable.getSpanEnd(span);
        editable.removeSpan(span);
        editable.setSpan(new KnifeURLSpan(span.getURL(), linkColor, linkUnderline), spanStart, spanEnd, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
    }
}
Also used : BulletSpan(android.text.style.BulletSpan) QuoteSpan(android.text.style.QuoteSpan) URLSpan(android.text.style.URLSpan)

Example 3 with BulletSpan

use of android.text.style.BulletSpan in project platform_frameworks_base by android.

the class HtmlToSpannedConverter method withinBlockquoteIndividual.

private static void withinBlockquoteIndividual(StringBuilder out, Spanned text, int start, int end) {
    boolean isInList = false;
    int next;
    for (int i = start; i <= end; i = next) {
        next = TextUtils.indexOf(text, '\n', i, end);
        if (next < 0) {
            next = end;
        }
        if (next == i) {
            if (isInList) {
                // Current paragraph is no longer a list item; close the previously opened list
                isInList = false;
                out.append("</ul>\n");
            }
            out.append("<br>\n");
        } else {
            boolean isListItem = false;
            ParagraphStyle[] paragraphStyles = text.getSpans(i, next, ParagraphStyle.class);
            for (ParagraphStyle paragraphStyle : paragraphStyles) {
                final int spanFlags = text.getSpanFlags(paragraphStyle);
                if ((spanFlags & Spanned.SPAN_PARAGRAPH) == Spanned.SPAN_PARAGRAPH && paragraphStyle instanceof BulletSpan) {
                    isListItem = true;
                    break;
                }
            }
            if (isListItem && !isInList) {
                // Current paragraph is the first item in a list
                isInList = true;
                out.append("<ul").append(getTextStyles(text, i, next, true, false)).append(">\n");
            }
            if (isInList && !isListItem) {
                // Current paragraph is no longer a list item; close the previously opened list
                isInList = false;
                out.append("</ul>\n");
            }
            String tagType = isListItem ? "li" : "p";
            out.append("<").append(tagType).append(getTextDirection(text, i, next)).append(getTextStyles(text, i, next, !isListItem, true)).append(">");
            withinParagraph(out, text, i, next);
            out.append("</");
            out.append(tagType);
            out.append(">\n");
            if (next == end && isInList) {
                isInList = false;
                out.append("</ul>\n");
            }
        }
        next++;
    }
}
Also used : BulletSpan(android.text.style.BulletSpan) ParagraphStyle(android.text.style.ParagraphStyle)

Example 4 with BulletSpan

use of android.text.style.BulletSpan in project platform_frameworks_base by android.

the class HtmlToSpannedConverter method endLi.

private static void endLi(Editable text) {
    endCssStyle(text);
    endBlockElement(text);
    end(text, Bullet.class, new BulletSpan());
}
Also used : BulletSpan(android.text.style.BulletSpan)

Example 5 with BulletSpan

use of android.text.style.BulletSpan in project WordPress-Android by wordpress-mobile.

the class WPHtmlTagHandler method handleListTag.

private void handleListTag(Editable output) {
    int size = mListParents.size();
    if (size > 0 && output != null) {
        if ("ul".equals(mListParents.get(size - 1))) {
            output.append("\n");
            String[] split = output.toString().split("\n");
            int start = 0;
            if (split.length != 1) {
                int lastIndex = split.length - 1;
                start = output.length() - split[lastIndex].length() - 1;
            }
            output.setSpan(new BulletSpan(SPAN_INDENT_WIDTH * mListParents.size()), start, output.length(), 0);
        } else if ("ol".equals(mListParents.get(size - 1))) {
            mListItemCount++;
            output.append("\n");
            String[] split = output.toString().split("\n");
            int start = 0;
            if (split.length != 1) {
                int lastIndex = split.length - 1;
                start = output.length() - split[lastIndex].length() - 1;
            }
            output.insert(start, mListItemCount + ". ");
            output.setSpan(new LeadingMarginSpan.Standard(SPAN_INDENT_WIDTH * mListParents.size()), start, output.length(), 0);
        }
    }
}
Also used : BulletSpan(android.text.style.BulletSpan)

Aggregations

BulletSpan (android.text.style.BulletSpan)17 ParagraphStyle (android.text.style.ParagraphStyle)5 LeadingMarginSpan (android.text.style.LeadingMarginSpan)2 StrikethroughSpan (android.text.style.StrikethroughSpan)2 Context (android.content.Context)1 SpannableString (android.text.SpannableString)1 TextPaint (android.text.TextPaint)1 AlignmentSpan (android.text.style.AlignmentSpan)1 QuoteSpan (android.text.style.QuoteSpan)1 TypefaceSpan (android.text.style.TypefaceSpan)1 URLSpan (android.text.style.URLSpan)1 TextView (android.widget.TextView)1