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 Project: zulip-android   Author: zulip   File: ListTagHandler.java    License: Apache License 2.0 6 votes vote down vote up
@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 Project: PhoneProfilesPlus   Author: henrichg   File: GlobalGUIRoutines.java    License: Apache License 2.0 6 votes vote down vote up
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 #3
Source Project: PhoneProfilesPlus   Author: henrichg   File: GlobalGUIRoutines.java    License: Apache License 2.0 6 votes vote down vote up
@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 #4
Source Project: Knife   Author: mthli   File: KnifeText.java    License: Apache License 2.0 6 votes vote down vote up
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 Project: Knife   Author: mthli   File: KnifeTagHandler.java    License: Apache License 2.0 6 votes vote down vote up
@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 #6
Source Project: google-authenticator-android   Author: google   File: UtilitiesTest.java    License: Apache License 2.0 6 votes vote down vote up
@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 #7
Source Project: Simple-Search   Author: TobiasBielefeld   File: SharedData.java    License: GNU General Public License v3.0 5 votes vote down vote up
/**
 * 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 Project: text-decorator   Author: nntuyen   File: TextDecorator.java    License: Apache License 2.0 5 votes vote down vote up
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 #9
Source Project: aptoide-client-v8   Author: Aptoide   File: DialogUtils.java    License: GNU General Public License v3.0 5 votes vote down vote up
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 #10
Source Project: Simple-Solitaire   Author: TobiasBielefeld   File: SharedData.java    License: GNU General Public License v3.0 5 votes vote down vote up
/**
 * 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 #11
Source Project: Markdown   Author: zzhoujay   File: StyleBuilderImpl.java    License: MIT License 5 votes vote down vote up
@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 #12
Source Project: Markdown   Author: zzhoujay   File: StyleBuilderImpl.java    License: MIT License 5 votes vote down vote up
@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 #13
Source Project: 365browser   Author: mogoweb   File: IncognitoNewTabPageViewMD.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * @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 #14
Source Project: PhoneProfilesPlus   Author: henrichg   File: GlobalGUIRoutines.java    License: Apache License 2.0 5 votes vote down vote up
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 Project: Knife   Author: mthli   File: KnifeText.java    License: Apache License 2.0 5 votes vote down vote up
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 Project: Knife   Author: mthli   File: KnifeParser.java    License: Apache License 2.0 5 votes vote down vote up
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 Project: google-authenticator-android   Author: google   File: Utilities.java    License: Apache License 2.0 5 votes vote down vote up
@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 Project: android_9.0.0_r45   Author: lulululbj   File: Html.java    License: Apache License 2.0 4 votes vote down vote up
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 #19
Source Project: android_9.0.0_r45   Author: lulululbj   File: Html.java    License: Apache License 2.0 4 votes vote down vote up
private static void endLi(Editable text) {
    endCssStyle(text);
    endBlockElement(text);
    end(text, Bullet.class, new BulletSpan());
}
 
Example #20
Source Project: tysq-android   Author: tysqapp   File: Html.java    License: GNU General Public License v3.0 4 votes vote down vote up
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;
                    // xxx
//                    out.append("</ul>\n");
                    out.append("</ul>");
                }
                // xxx
//                out.append("<br>\n");
                out.append("<br>");
            } else {
                boolean isListItem = false;
                IBlockStyle[] blockStyles = text.getSpans(i, next, IBlockStyle.class);
                for (IBlockStyle blockStyle : blockStyles) {
                    final int spanFlags = text.getSpanFlags(blockStyle);
                    if ((spanFlags & Spanned.SPAN_PARAGRAPH) == Spanned.SPAN_PARAGRAPH
                            && blockStyle instanceof BulletSpan) {
                        isListItem = true;
                        break;
                    }
                }

                if (isListItem && !isInList) {
                    // Current paragraph is the first item in a list
                    isInList = true;
                    // xxx
//                    out.append("<ul")
//                            .append(getTextStyles(text, i, next, true, false))
//                            .append(">\n");
                    out.append("<ul")
                            .append(getTextStyles(text, i, next, true, false))
                            .append(">");
                }

                if (isInList && !isListItem) {
                    // Current paragraph is no longer a list item; close the previously opened list
                    isInList = false;
                    // xxx
//                    out.append("</ul>\n");
                    out.append("</ul>");

                }

                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);
                // xxx
//                out.append(">\n");
                out.append(">");

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

            next++;
        }
    }
 
Example #21
Source Project: tysq-android   Author: tysqapp   File: Html.java    License: GNU General Public License v3.0 4 votes vote down vote up
private static void endLi(Editable text) {
    endCssStyle(text);
    endBlockElement(text);
    end(text, Bullet.class, new BulletSpan());
}
 
Example #22
Source Project: FairEmail   Author: M66B   File: HtmlEx.java    License: GNU General Public License v3.0 4 votes vote down vote up
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 Project: dante   Author: fourlastor   File: BulletSpanListener.java    License: MIT License 4 votes vote down vote up
@Override
protected Object getStyleSpan() {
    return new BulletSpan(margin);
}
 
Example #24
Source Project: Android-Spans   Author: SimonMarquis   File: Span.java    License: Apache License 2.0 4 votes vote down vote up
public static Node bullet(Object... nodes) {
    return new SpanNode(new BulletSpan(), nodes);
}
 
Example #25
Source Project: Android-Spans   Author: SimonMarquis   File: Span.java    License: Apache License 2.0 4 votes vote down vote up
public static Node bullet(@Px Integer gapWidth, Object... nodes) {
    return new SpanNode(new BulletSpan(gapWidth), nodes);
}
 
Example #26
Source Project: Android-Spans   Author: SimonMarquis   File: Span.java    License: Apache License 2.0 4 votes vote down vote up
public static Node bullet(Integer gapWidth, @ColorInt Integer color, Object... nodes) {
    return new SpanNode(new BulletSpan(gapWidth, color), nodes);
}
 
Example #27
Source Project: HtmlCompat   Author: Pixplicity   File: HtmlCompat.java    License: Apache License 2.0 4 votes vote down vote up
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 #28
Source Project: HtmlCompat   Author: Pixplicity   File: HtmlToSpannedConverter.java    License: Apache License 2.0 4 votes vote down vote up
private void endLi(String tag, Editable text) {
    endCssStyle(tag, text);
    endBlockElement(tag, text);
    end(tag, text, Bullet.class, new BulletSpan());
}
 
Example #29
Source Project: ForPDA   Author: RadiationX   File: Html.java    License: GNU General Public License v3.0 4 votes vote down vote up
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 #30
Source Project: ForPDA   Author: RadiationX   File: Html.java    License: GNU General Public License v3.0 4 votes vote down vote up
private static void endLi(Editable text) {
    endCssStyle(text);
    endBlockElement(text);
    end(text, Bullet.class, new BulletSpan());
}