Search in sources :

Example 16 with BulletSpan

use of android.text.style.BulletSpan in project android_frameworks_base by DirtyUnicorns.

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 17 with BulletSpan

use of android.text.style.BulletSpan in project android_frameworks_base by crdroidandroid.

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)

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