Example usage for android.text TextUtils indexOf

List of usage examples for android.text TextUtils indexOf

Introduction

In this page you can find the example usage for android.text TextUtils indexOf.

Prototype

public static int indexOf(CharSequence s, CharSequence needle, int start, int end) 

Source Link

Usage

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

private static void withinBlockquoteIndividual(StringBuilder out, Spanned text, int start, int end,
        Context context) {//  w w  w .ja v a2  s.  c o  m
    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++;
    }
}

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

private static void withinBlockquoteConsecutive(StringBuilder out, Spanned text, int start, int end,
        Context context) {/*from   w w  w  .  j  av  a 2s.c  o  m*/
    out.append("<p").append(getTextDirection(text, start, end)).append(">");

    int next;
    for (int i = start; i < end; i = next) {
        next = TextUtils.indexOf(text, '\n', i, end);
        if (next < 0) {
            next = end;
        }

        int nl = 0;

        while (next < end && text.charAt(next) == '\n') {
            nl++;
            next++;
        }

        withinParagraph(out, text, i, next - nl, context);

        if (nl == 1) {
            out.append("<br>\n");
        } else {
            for (int j = 2; j < nl; j++) {
                out.append("<br>");
            }
            if (next != end) {
                /* Paragraph should be closed and reopened */
                out.append("</p>\n");
                out.append("<p").append(getTextDirection(text, start, end)).append(">");
            }
        }
    }

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