android.text.style.BulletSpan Java Examples
The following examples show how to use
android.text.style.BulletSpan.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ListTagHandler.java From zulip-android with Apache License 2.0 | 6 votes |
@Override protected Object[] getReplaces(final Editable text, final int indentation) { // Nested BulletSpans increases distance between BULLET_SPAN and text, so we must prevent it. int bulletMargin = INDENT_PX; if (indentation > 1) { bulletMargin = INDENT_PX - BULLET_SPAN.getLeadingMargin(true); if (indentation > 2) { // This get's more complicated when we add a LeadingMarginSpan into the same line: // we have also counter it's effect to BulletSpan bulletMargin -= (indentation - 2) * LIST_ITEM_INDENT_PX; } } return new Object[]{ new LeadingMarginSpan.Standard(LIST_ITEM_INDENT_PX * (indentation - 1)), new BulletSpan(bulletMargin) }; }
Example #2
Source File: UtilitiesTest.java From google-authenticator-android with Apache License 2.0 | 6 votes |
@Test public void testGetStyledTextFromHtmlWithInputWithBulletList() { assertThat( Utilities.getStyledTextFromHtml( "<ul><li>First<li><li>Second</li><li>Third<li></ul>End").toString()) .isEqualTo("\n\nFirst\nSecond\nThird\n\nEnd"); Spanned result = Utilities.getStyledTextFromHtml( "Some items:<ul>\n<li>First<li><li>Second</li>\n<li>Third<li>\n\n</ul>End"); assertThat(result.toString()).isEqualTo("Some items:\n\nFirst\nSecond\nThird\n\nEnd"); BulletSpan[] bulletSpans = result.getSpans(0, result.length(), BulletSpan.class); assertThat(bulletSpans).hasLength(3); assertSpanLocation(bulletSpans[0], result, 13, 19); assertSpanLocation(bulletSpans[1], result, 19, 26); assertSpanLocation(bulletSpans[2], result, 26, 32); LeadingMarginSpan.Standard[] leadingMarginSpans = result.getSpans(0, result.length(), LeadingMarginSpan.Standard.class); assertThat(bulletSpans).hasLength(3); assertSpanLocation(leadingMarginSpans[0], result, 13, 19); assertSpanLocation(leadingMarginSpans[1], result, 19, 26); assertSpanLocation(leadingMarginSpans[2], result, 26, 32); }
Example #3
Source File: KnifeTagHandler.java From Knife with Apache License 2.0 | 6 votes |
@Override public void handleTag(boolean opening, String tag, Editable output, XMLReader xmlReader) { if (opening) { if (tag.equalsIgnoreCase(BULLET_LI)) { if (output.length() > 0 && output.charAt(output.length() - 1) != '\n') { output.append("\n"); } start(output, new Li()); } else if (tag.equalsIgnoreCase(STRIKETHROUGH_S) || tag.equalsIgnoreCase(STRIKETHROUGH_STRIKE) || tag.equalsIgnoreCase(STRIKETHROUGH_DEL)) { start(output, new Strike()); } } else { if (tag.equalsIgnoreCase(BULLET_LI)) { if (output.length() > 0 && output.charAt(output.length() - 1) != '\n') { output.append("\n"); } end(output, Li.class, new BulletSpan()); } else if (tag.equalsIgnoreCase(STRIKETHROUGH_S) || tag.equalsIgnoreCase(STRIKETHROUGH_STRIKE) || tag.equalsIgnoreCase(STRIKETHROUGH_DEL)) { end(output, Strike.class, new StrikethroughSpan()); } } }
Example #4
Source File: KnifeText.java From Knife with Apache License 2.0 | 6 votes |
protected boolean containBullet(int index) { String[] lines = TextUtils.split(getEditableText().toString(), "\n"); if (index < 0 || index >= lines.length) { return false; } int start = 0; for (int i = 0; i < index; i++) { start = start + lines[i].length() + 1; } int end = start + lines[index].length(); if (start >= end) { return false; } BulletSpan[] spans = getEditableText().getSpans(start, end, BulletSpan.class); return spans.length > 0; }
Example #5
Source File: GlobalGUIRoutines.java From PhoneProfilesPlus with Apache License 2.0 | 6 votes |
private static SpannableStringBuilder addNumbers(Spanned htmlSpanned, int numberFrom, int sp) { int listItemCount = numberFrom-1; SpannableStringBuilder spannableBuilder = new SpannableStringBuilder(htmlSpanned); BulletSpan[] spans = spannableBuilder.getSpans(0, spannableBuilder.length(), BulletSpan.class); if (spans != null) { for (BulletSpan span : spans) { int start = spannableBuilder.getSpanStart(span); int end = spannableBuilder.getSpanEnd(span); spannableBuilder.removeSpan(span); ++listItemCount; spannableBuilder.insert(start, listItemCount + ". "); spannableBuilder.setSpan(new LeadingMarginSpan.Standard(0, sip(sp)), start, end, Spanned.SPAN_INCLUSIVE_EXCLUSIVE); } } return spannableBuilder; }
Example #6
Source File: GlobalGUIRoutines.java From PhoneProfilesPlus with Apache License 2.0 | 6 votes |
@Override public void handleTag(boolean opening, String tag, Editable output, XMLReader xmlReader) { class Bullet {} if (tag.equals("li") && opening) { output.setSpan(new Bullet(), output.length(), output.length(), Spannable.SPAN_INCLUSIVE_EXCLUSIVE); } if (tag.equals("li") && !opening) { //output.append("\n\n"); output.append("\n"); Bullet[] spans = output.getSpans(0, output.length(), Bullet.class); if (spans != null) { Bullet lastMark = spans[spans.length-1]; int start = output.getSpanStart(lastMark); output.removeSpan(lastMark); if (start != output.length()) { output.setSpan(new BulletSpan(), start, output.length(), Spanned.SPAN_INCLUSIVE_EXCLUSIVE); } } } }
Example #7
Source File: SharedData.java From Simple-Search with GNU General Public License v3.0 | 5 votes |
/** * Uses the given string array to create a text paragraph. The strings are separated by bullet * characters. * * @param strings The string array to use for the text paragraph * @return a charSequence, which can directly be applied to a textView */ static public CharSequence createBulletParagraph(CharSequence[] strings){ SpannableString spanns[] = new SpannableString[strings.length]; //apply the bullet characters for (int i=0;i<strings.length;i++){ spanns[i] = new SpannableString(strings[i] + (i<strings.length-1 ? "\n" : "")); spanns[i].setSpan(new BulletSpan(15), 0, strings[i].length(), 0); } //set up the textView return TextUtils.concat(spanns); }
Example #8
Source File: IncognitoNewTabPageViewMD.java From 365browser with Apache License 2.0 | 5 votes |
/** * @param element Resource ID of the element to be populated with the bulletpoints. * @param content String ID to serve as the text of |element|. Must contain an <em></em> span, * which will be emphasized, and three <li> items, which will be converted to * bulletpoints. * Populates |element| with |content|. */ private void populateBulletpoints(@IdRes int element, @StringRes int content) { TextView view = (TextView) findViewById(element); String text = mContext.getResources().getString(content); // TODO(msramek): Unfortunately, our strings are missing the closing "</li>" tag, which // is not a problem when they're used in the Desktop WebUI (omitting the tag is valid in // HTML5), but it is a problem for SpanApplier. Update the strings and remove this regex. // Note that modifying the strings is a non-trivial operation as they went through a special // translation process. text = text.replaceAll("<li>([^<]+)\n", "<li>$1</li>\n"); // Disambiguate the <li><li> spans for SpanApplier. text = text.replaceFirst("<li>(.*)</li>", "<li1>$1</li1>"); text = text.replaceFirst("<li>(.*)</li>", "<li2>$1</li2>"); text = text.replaceFirst("<li>(.*)</li>", "<li3>$1</li3>"); // Remove the <ul></ul> tags which serve no purpose here. text = text.replaceAll("</?ul>", ""); view.setText(SpanApplier.applySpans(text, new SpanApplier.SpanInfo("<em>", "</em>", new ForegroundColorSpan(ApiCompatibilityUtils.getColor( mContext.getResources(), R.color.incognito_emphasis))), new SpanApplier.SpanInfo("<li1>", "</li1>", new BulletSpan()), new SpanApplier.SpanInfo("<li2>", "</li2>", new BulletSpan()), new SpanApplier.SpanInfo("<li3>", "</li3>", new BulletSpan()))); }
Example #9
Source File: StyleBuilderImpl.java From Markdown with MIT License | 5 votes |
@Override public SpannableStringBuilder ol(CharSequence charSequence, int level, int index) { SpannableStringBuilder spannableStringBuilder = SpannableStringBuilder.valueOf(charSequence); BulletSpan bulletSpan = new MarkDownBulletSpan(level, h1_text_color, index); spannableStringBuilder.setSpan(bulletSpan, 0, spannableStringBuilder.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); return spannableStringBuilder; }
Example #10
Source File: StyleBuilderImpl.java From Markdown with MIT License | 5 votes |
@Override public SpannableStringBuilder ul(CharSequence charSequence, int level) { SpannableStringBuilder spannableStringBuilder = SpannableStringBuilder.valueOf(charSequence); BulletSpan bulletSpan = new MarkDownBulletSpan(level, h1_text_color, 0); spannableStringBuilder.setSpan(bulletSpan, 0, spannableStringBuilder.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); return spannableStringBuilder; }
Example #11
Source File: SharedData.java From Simple-Solitaire with GNU General Public License v3.0 | 5 votes |
/** * Uses the given string array to create a text paragraph. The strings are separated by bullet * characters. * * @param strings The string array to use for the text paragraph * @return a charSequence, which can directly be applied to a textView */ static public CharSequence createBulletParagraph(CharSequence[] strings) { SpannableString spanns[] = new SpannableString[strings.length]; //apply the bullet characters for (int i = 0; i < strings.length; i++) { spanns[i] = new SpannableString(strings[i] + (i < strings.length - 1 ? "\n" : "")); spanns[i].setSpan(new BulletSpan(15), 0, strings[i].length(), 0); } //set up the textView return TextUtils.concat(spanns); }
Example #12
Source File: DialogUtils.java From aptoide-client-v8 with GNU General Public License v3.0 | 5 votes |
public void setBulletText(TextView textView, String text) { SpannableString spannable = new SpannableString(text); spannable.setSpan( new BulletSpan(16, themeManager.getAttributeForTheme(R.attr.colorPrimaryDark).data), 0, text.length(), 0); textView.setText(spannable); }
Example #13
Source File: TextDecorator.java From text-decorator with Apache License 2.0 | 5 votes |
public TextDecorator insertBullet(final int gapWidth, @ColorRes final int colorResId, final int start, final int end) { checkIndexOutOfBoundsException(start, end); decoratedContent.setSpan(new BulletSpan(gapWidth, ContextCompat.getColor(textView.getContext(), colorResId)), start, end, flags); return this; }
Example #14
Source File: GlobalGUIRoutines.java From PhoneProfilesPlus with Apache License 2.0 | 5 votes |
private static SpannableStringBuilder addBullets(Spanned htmlSpanned) { SpannableStringBuilder spannableBuilder = new SpannableStringBuilder(htmlSpanned); BulletSpan[] spans = spannableBuilder.getSpans(0, spannableBuilder.length(), BulletSpan.class); if (spans != null) { for (BulletSpan span : spans) { int start = spannableBuilder.getSpanStart(span); int end = spannableBuilder.getSpanEnd(span); spannableBuilder.removeSpan(span); spannableBuilder.setSpan(new ImprovedBulletSpan(dip(2), dip(8), 0), start, end, Spanned.SPAN_INCLUSIVE_EXCLUSIVE); } } return spannableBuilder; }
Example #15
Source File: KnifeText.java From Knife with Apache License 2.0 | 5 votes |
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); } } } }
Example #16
Source File: KnifeParser.java From Knife with Apache License 2.0 | 5 votes |
private static void withinHtml(StringBuilder out, Spanned text) { int next; for (int i = 0; i < text.length(); i = next) { next = text.nextSpanTransition(i, text.length(), ParagraphStyle.class); ParagraphStyle[] styles = text.getSpans(i, next, ParagraphStyle.class); if (styles.length == 2) { if (styles[0] instanceof BulletSpan && styles[1] instanceof QuoteSpan) { // Let a <br> follow the BulletSpan or QuoteSpan end, so next++ withinBulletThenQuote(out, text, i, next++); } else if (styles[0] instanceof QuoteSpan && styles[1] instanceof BulletSpan) { withinQuoteThenBullet(out, text, i, next++); } else { withinContent(out, text, i, next); } } else if (styles.length == 1) { if (styles[0] instanceof BulletSpan) { withinBullet(out, text, i, next++); } else if (styles[0] instanceof QuoteSpan) { withinQuote(out, text, i, next++); } else { withinContent(out, text, i, next); } } else { withinContent(out, text, i, next); } } }
Example #17
Source File: Utilities.java From google-authenticator-android with Apache License 2.0 | 5 votes |
@Override public void handleTag(boolean opening, String tag, Editable output, XMLReader xmlReader) { if ("ul".equalsIgnoreCase(tag)) { // Ensure there are at least two newlines both before and after the list. ensureAtLeastTwoTrailingNewlines(output); } else if ("li".equalsIgnoreCase(tag)) { appendNewlineIfNoTrailingNewline(output); int outputLength = output.length(); if (opening) { // Attach a BulletSpan to the beginning of the list entry. The span will be removed // when processing the closing of this tag/entry. output.setSpan(new BulletSpan(), outputLength, outputLength, Spannable.SPAN_MARK_MARK); } else { // Attach a BulletSpan, spanning the whole list entry. This removes the span // attached to the start of this list entry when processing the opening of this tag/entry. // We also attach a LeadingMarginSpan to the same location to indent the list entries // and their bullets. BulletSpan[] bulletSpans = output.getSpans(0, outputLength, BulletSpan.class); if (bulletSpans.length > 0) { BulletSpan startMarkSpan = bulletSpans[bulletSpans.length - 1]; int startIndex = output.getSpanStart(startMarkSpan); output.removeSpan(startMarkSpan); if (startIndex != outputLength) { output.setSpan( new LeadingMarginSpan.Standard(10), startIndex, outputLength, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); output.setSpan( new BulletSpan(10), startIndex, outputLength, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); } } } } }
Example #18
Source File: AKHtml.java From Mupdf with Apache License 2.0 | 4 votes |
private static void endLi(Editable text) { endCssStyle(text); endBlockElement(text); end(text, Bullet.class, new BulletSpan()); }
Example #19
Source File: HtmlTagHandler.java From android-discourse with Apache License 2.0 | 4 votes |
@Override public void handleTag(boolean opening, String tag, Editable output, XMLReader xmlReader) { if (tag.equalsIgnoreCase("ul")) { if (opening) { lists.push(tag); } else { lists.pop(); } } else if (tag.equalsIgnoreCase("ol")) { if (opening) { lists.push(tag); olNextIndex.push(Integer.valueOf(1)).toString();// TODO: add support for lists starting other index than 1 } else { lists.pop(); olNextIndex.pop().toString(); } } 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(olNextIndex.peek().toString() + ". "); olNextIndex.push(Integer.valueOf(olNextIndex.pop().intValue() + 1)); } else if (parentList.equalsIgnoreCase("ul")) { start(output, new Ul()); } } else { if (lists.peek().equalsIgnoreCase("ul")) { if (output.charAt(output.length() - 1) != '\n') { output.append("\n"); } // Nested BulletSpans increases distance between bullet and text, so we must prevent it. int bulletMargin = indent; if (lists.size() > 1) { bulletMargin = indent - bullet.getLeadingMargin(true); if (lists.size() > 2) { // This get's more complicated when we add a LeadingMarginSpan into the same line: // we have also counter it's effect to BulletSpan 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.charAt(output.length() - 1) != '\n') { output.append("\n"); } int numberMargin = listItemIndent * (lists.size() - 1); if (lists.size() > 2) { // Same as in ordered lists: counter the effect of nested Spans numberMargin -= (lists.size() - 2) * listItemIndent; } end(output, Ol.class, new LeadingMarginSpan.Standard(numberMargin)); } } } else if (tag.equalsIgnoreCase("code")) { if (opening) { output.setSpan(new TypefaceSpan("monospace"), output.length(), output.length(), Spannable.SPAN_MARK_MARK); } else { L.d("Code tag encountered"); Object obj = getLast(output, TypefaceSpan.class); int where = output.getSpanStart(obj); output.setSpan(new TypefaceSpan("monospace"), where, output.length(), 0); output.setSpan(new BackgroundColorSpan(Color.parseColor("#f1f1ff")), where, output.length(), 0); } } else { if (opening) L.d("Found an unsupported tag " + tag); } }
Example #20
Source File: SpanOptions.java From AndroidSpan with Apache License 2.0 | 4 votes |
public SpanOptions addBulletSpan(int gapWidth, int color) { BulletSpan span = new BulletSpan(gapWidth, color); listSpan.add(span); return this; }
Example #21
Source File: CustomHtmlTagHandler.java From SteamGifts with MIT License | 4 votes |
/** * Processes a single list item. * * @param opening is this the opening tag? * @see <a href="https://bitbucket.org/Kuitsi/android-textview-html-list">Kuitsi/android-textview-html-list</a> */ private void processListItem(boolean opening, Editable output) { 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(olNextIndex.peek().toString()).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"); } // Nested BulletSpans increases distance between bullet and text, so we must prevent it. int bulletMargin = indent; if (lists.size() > 1) { bulletMargin = indent - bullet.getLeadingMargin(true); if (lists.size() > 2) { // This get's more complicated when we add a LeadingMarginSpan into the same line: // we have also counter it's effect to BulletSpan 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) { // Same as in ordered lists: counter the effect of nested Spans numberMargin -= (lists.size() - 2) * listItemIndent; } end(output, Ol.class, new LeadingMarginSpan.Standard(numberMargin)); } } }
Example #22
Source File: AKHtml.java From Mupdf with Apache License 2.0 | 4 votes |
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++; } }
Example #23
Source File: Html.java From android_9.0.0_r45 with Apache License 2.0 | 4 votes |
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++; } }
Example #24
Source File: TextDecorator.java From text-decorator with Apache License 2.0 | 4 votes |
public TextDecorator insertBullet(final int gapWidth, final int start, final int end) { checkIndexOutOfBoundsException(start, end); decoratedContent.setSpan(new BulletSpan(gapWidth), start, end, flags); return this; }
Example #25
Source File: TextDecorator.java From text-decorator with Apache License 2.0 | 4 votes |
public TextDecorator insertBullet(final int start, final int end) { checkIndexOutOfBoundsException(start, end); decoratedContent.setSpan(new BulletSpan(), start, end, flags); return this; }
Example #26
Source File: Html.java From ForPDA with GNU General Public License v3.0 | 4 votes |
private static void endLi(Editable text) { endCssStyle(text); endBlockElement(text); end(text, Bullet.class, new BulletSpan()); }
Example #27
Source File: Html.java From ForPDA with GNU General Public License v3.0 | 4 votes |
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++; } }
Example #28
Source File: HtmlToSpannedConverter.java From HtmlCompat with Apache License 2.0 | 4 votes |
private void endLi(String tag, Editable text) { endCssStyle(tag, text); endBlockElement(tag, text); end(tag, text, Bullet.class, new BulletSpan()); }
Example #29
Source File: HtmlCompat.java From HtmlCompat with Apache License 2.0 | 4 votes |
private static void withinBlockquoteIndividual(Context context, 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(context, out, text, i, next); out.append("</"); out.append(tagType); out.append(">\n"); if (next == end && isInList) { isInList = false; out.append("</ul>\n"); } } next++; } }
Example #30
Source File: Span.java From Android-Spans with Apache License 2.0 | 4 votes |
public static Node bullet(Integer gapWidth, @ColorInt Integer color, Object... nodes) { return new SpanNode(new BulletSpan(gapWidth, color), nodes); }