Example usage for android.text Spanned SPAN_PARAGRAPH

List of usage examples for android.text Spanned SPAN_PARAGRAPH

Introduction

In this page you can find the example usage for android.text Spanned SPAN_PARAGRAPH.

Prototype

int SPAN_PARAGRAPH

To view the source code for android.text Spanned SPAN_PARAGRAPH.

Click Source Link

Document

SPAN_PARAGRAPH behaves like SPAN_INCLUSIVE_EXCLUSIVE (SPAN_MARK_MARK), except that if either end of the span is at the end of the buffer, that end behaves like _POINT instead (so SPAN_INCLUSIVE_INCLUSIVE if it starts in the middle and ends at the end, or SPAN_EXCLUSIVE_INCLUSIVE if it both starts and ends at the end).

Usage

From source file:org.miaowo.miaowo.util.Html.java

private static void withinBlockquoteIndividual(StringBuilder out, Spanned text, int start, int end,
        Context context) {/*from  w w w  .  j  a v  a2s.  c om*/
    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;
        }

        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>\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, start, next))
                .append(getTextStyles(text, start, next)).append(">");

        if (next - i == 0) {
            out.append("<br>");
        } else {
            withinParagraph(out, text, i, next, context);
        }

        out.append("</");
        out.append(tagType);
        out.append(">\n");

        if (next == end && isInList) {
            isInList = false;
            out.append("</ul>\n");
        }

        next++;
    }
}