Search in sources :

Example 11 with BulletSpan

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

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

use of android.text.style.BulletSpan in project Reader by TheKeeperOfPie.

the class TagHandlerReddit method handleTag.

@Override
public void handleTag(boolean opening, String tag, Editable output, XMLReader xmlReader) {
    if (tag.equalsIgnoreCase("del") || tag.equalsIgnoreCase("strike") || tag.equals("s")) {
        if (opening) {
            start(output, new Strike());
        } else {
            end(output, Strike.class, new StrikethroughSpan());
        }
    } else if (tag.equalsIgnoreCase("ul")) {
        if (opening) {
            lists.push(tag);
        } else {
            lists.pop();
        }
    } else if (tag.equalsIgnoreCase("ol")) {
        if (opening) {
            lists.push(tag);
            olNextIndex.push(1);
        } else {
            lists.pop();
            olNextIndex.pop();
        }
    } else if (tag.equalsIgnoreCase("li")) {
        if (opening) {
            if (output.length() > 0 && output.charAt(output.length() - 1) != '\n') {
                output.append("\n");
            }
            String parentList = lists.peek();
            if (parentList.equalsIgnoreCase("ol")) {
                start(output, new Ol());
                output.append(String.valueOf(olNextIndex.peek())).append(". ");
                olNextIndex.push(olNextIndex.pop() + 1);
            } else if (parentList.equalsIgnoreCase("ul")) {
                start(output, new Ul());
            }
        } else {
            if (lists.peek().equalsIgnoreCase("ul")) {
                if (output.length() > 0 && output.charAt(output.length() - 1) != '\n') {
                    output.append("\n");
                }
                int bulletMargin = indent;
                if (lists.size() > 1) {
                    bulletMargin = indent - bullet.getLeadingMargin(true);
                    if (lists.size() > 2) {
                        bulletMargin -= (lists.size() - 2) * listItemIndent;
                    }
                }
                BulletSpan newBullet = new BulletSpan(bulletMargin);
                end(output, Ul.class, new LeadingMarginSpan.Standard(listItemIndent * (lists.size() - 1)), newBullet);
            } else if (lists.peek().equalsIgnoreCase("ol")) {
                if (output.length() > 0 && output.charAt(output.length() - 1) != '\n') {
                    output.append("\n");
                }
                int numberMargin = listItemIndent * (lists.size() - 1);
                if (lists.size() > 2) {
                    numberMargin -= (lists.size() - 2) * listItemIndent;
                }
                end(output, Ol.class, new LeadingMarginSpan.Standard(numberMargin));
            }
        }
    }
}
Also used : BulletSpan(android.text.style.BulletSpan) LeadingMarginSpan(android.text.style.LeadingMarginSpan) StrikethroughSpan(android.text.style.StrikethroughSpan)

Example 13 with BulletSpan

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

the class KnifeText method bulletInvalid.

protected void bulletInvalid() {
    String[] lines = TextUtils.split(getEditableText().toString(), "\n");
    for (int i = 0; i < lines.length; i++) {
        if (!containBullet(i)) {
            continue;
        }
        int lineStart = 0;
        for (int j = 0; j < i; j++) {
            lineStart = lineStart + lines[j].length() + 1;
        }
        int lineEnd = lineStart + lines[i].length();
        if (lineStart >= lineEnd) {
            continue;
        }
        int bulletStart = 0;
        int bulletEnd = 0;
        if (lineStart <= getSelectionStart() && getSelectionEnd() <= lineEnd) {
            bulletStart = lineStart;
            bulletEnd = lineEnd;
        } else if (getSelectionStart() <= lineStart && lineEnd <= getSelectionEnd()) {
            bulletStart = lineStart;
            bulletEnd = lineEnd;
        }
        if (bulletStart < bulletEnd) {
            BulletSpan[] spans = getEditableText().getSpans(bulletStart, bulletEnd, BulletSpan.class);
            for (BulletSpan span : spans) {
                getEditableText().removeSpan(span);
            }
        }
    }
}
Also used : BulletSpan(android.text.style.BulletSpan)

Example 14 with BulletSpan

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

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

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

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