Java Code Examples for android.text.style.QuoteSpan

The following are top voted examples for showing how to use android.text.style.QuoteSpan. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: Slide-RSS   File: SpoilerRobotoTextView.java   Source Code and License 6 votes vote down vote up
/**
 * Replaces the blue line produced by <blockquote>s with something more visible
 *
 * @param spannable parsed comment text #fromHtml
 */
private void replaceQuoteSpans(Spannable spannable) {
    QuoteSpan[] quoteSpans = spannable.getSpans(0, spannable.length(), QuoteSpan.class);

    for (QuoteSpan quoteSpan : quoteSpans) {
        final int start = spannable.getSpanStart(quoteSpan);
        final int end = spannable.getSpanEnd(quoteSpan);
        final int flags = spannable.getSpanFlags(quoteSpan);

        spannable.removeSpan(quoteSpan);

        //If the theme is Light or Sepia, use a darker blue; otherwise, use a lighter blue
        final int barColor =
                (SettingValues.currentTheme == 1 || SettingValues.currentTheme == 5)
                        ? ContextCompat.getColor(getContext(), R.color.md_blue_600)
                        : ContextCompat.getColor(getContext(), R.color.md_blue_400);

        final int BAR_WIDTH = 4;
        final int GAP = 5;

        spannable.setSpan(new CustomQuoteSpan(Color.TRANSPARENT, //background color
                        barColor, //bar color
                        BAR_WIDTH, //bar width
                        GAP), //bar + text gap
                start, end, flags);
    }
}
 
Example 2
Project: ScribaNotesApp   File: Html.java   Source Code and License 6 votes vote down vote up
private void handleEndTag(String tag) {
    if (tag.equalsIgnoreCase("br")) {
        handleBr(mSpannableStringBuilder);
    } else if (tag.equalsIgnoreCase("p")) {
        handleP(mSpannableStringBuilder);
    } else if (tag.equalsIgnoreCase("b")) {
        end(mSpannableStringBuilder, Bold.class, new StyleSpan(Typeface.BOLD));
    } else if (tag.equalsIgnoreCase("i")) {
        end(mSpannableStringBuilder, Italic.class, new StyleSpan(Typeface.ITALIC));
    } else if (tag.equalsIgnoreCase("font")) {
        endFont(mSpannableStringBuilder);
    } else if (tag.equalsIgnoreCase("blockquote")) {
        handleP(mSpannableStringBuilder);
        end(mSpannableStringBuilder, Blockquote.class, new QuoteSpan());
    } else if (tag.equalsIgnoreCase("tt")) {
        end(mSpannableStringBuilder, Monospace.class,
                new TypefaceSpan("monospace"));
    } else if (tag.equalsIgnoreCase("u")) {
        end(mSpannableStringBuilder, Underline.class, new UnderlineSpan());
    } else if (mTagHandler != null) {
        mTagHandler.handleTag(false, tag, mSpannableStringBuilder, mReader);
    }
}
 
Example 3
Project: wordpress_app_android   File: HtmlUtils.java   Source Code and License 6 votes vote down vote up
/**
 * an alternative to Html.fromHtml() supporting <ul>, <ol>, <blockquote> tags and replacing EmoticonsUtils with Emojis
 */
public static SpannableStringBuilder fromHtml(String source, WPImageGetter wpImageGetter) {
    SpannableStringBuilder html;
    try {
        html = (SpannableStringBuilder) Html.fromHtml(source, wpImageGetter, new WPHtmlTagHandler());
    } catch (RuntimeException runtimeException) {
        // In case our tag handler fails
        html = (SpannableStringBuilder) Html.fromHtml(source, wpImageGetter, null);
    }
    EmoticonsUtils.replaceEmoticonsWithEmoji(html);
    QuoteSpan spans[] = html.getSpans(0, html.length(), QuoteSpan.class);
    for (QuoteSpan span : spans) {
        html.setSpan(new WPQuoteSpan(), html.getSpanStart(span), html.getSpanEnd(span), html.getSpanFlags(span));
        html.setSpan(new ForegroundColorSpan(0xFF666666), html.getSpanStart(span), html.getSpanEnd(span),
                html.getSpanFlags(span));
        html.removeSpan(span);
    }
    return html;
}
 
Example 4
Project: Overchan-Android   File: HtmlParser.java   Source Code and License 6 votes vote down vote up
private static void endBlockquote(SpannableStringBuilder text, ThemeColors colors) {
    int len = text.length();
    Object obj = getLast(text, Blockquote.class);
    int where = text.getSpanStart(obj);
    text.removeSpan(obj);
    
    if (where != len) {
        Blockquote b = (Blockquote) obj;
        if (b.mIsUnkfunc) {
            if (colors != null) {
                text.setSpan(new ForegroundColorSpan(colors.quoteForeground), where, len, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
            }
        } else {
            text.setSpan(new QuoteSpan(), where, len, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        }
    }
}
 
Example 5
Project: Knife   File: KnifeText.java   Source Code and License 6 votes vote down vote up
protected boolean containQuote(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;
    }

    QuoteSpan[] spans = getEditableText().getSpans(start, end, QuoteSpan.class);
    return spans.length > 0;
}
 
Example 6
Project: text-decorator   File: TextDecorator.java   Source Code and License 5 votes vote down vote up
public TextDecorator quote(final String... texts) {
  int index;

  for (String text : texts) {
    if (content.contains(text)) {
      index = content.indexOf(text);
      decoratedContent.setSpan(new QuoteSpan(), index, index + text.length(), flags);
    }
  }

  return this;
}
 
Example 7
Project: text-decorator   File: TextDecorator.java   Source Code and License 5 votes vote down vote up
public TextDecorator quote(@ColorRes final int colorResId, final int start, final int end) {
  checkIndexOutOfBoundsException(start, end);
  decoratedContent.setSpan(new QuoteSpan(ContextCompat.getColor(textView.getContext(), colorResId)), start, end,
      flags);

  return this;
}
 
Example 8
Project: text-decorator   File: TextDecorator.java   Source Code and License 5 votes vote down vote up
public TextDecorator quote(@ColorRes final int colorResId, final String... texts) {
  int index;

  for (String text : texts) {
    if (content.contains(text)) {
      index = content.indexOf(text);
      decoratedContent.setSpan(new QuoteSpan(ContextCompat.getColor(textView.getContext(), colorResId)), index, index + text.length(), flags);
    }
  }

  return this;
}
 
Example 9
Project: markdown-to-spanned   File: SpanTests.java   Source Code and License 5 votes vote down vote up
@Test
public void testBlockQuote() throws Exception {
    String content = "> blockquote\n" +
            "still blockquote";
    Spanned result = Markdown.fromMarkdown(content);
    printSpans(result);
    Object[] spans = result.getSpans(0, result.length(), Object.class);
    assertEquals(1, spans.length);
    assertEquals(QuoteSpan.class, spans[0].getClass());
}
 
Example 10
Project: Markdown   File: StyleBuilderImpl.java   Source Code and License 5 votes vote down vote up
@Override
public SpannableStringBuilder quota(CharSequence charSequence) {
    SpannableStringBuilder spannableStringBuilder = SpannableStringBuilder.valueOf(charSequence);
    QuoteSpan span = new MarkDownQuoteSpan(quota_color);
    spannableStringBuilder.setSpan(span, 0, spannableStringBuilder.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
    spannableStringBuilder.setSpan(new ForegroundColorSpan(quota_text_color), 0, spannableStringBuilder.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
    return spannableStringBuilder;
}
 
Example 11
Project: wATLlib   File: SpannedSerializator.java   Source Code and License 5 votes vote down vote up
private void writeSingleParagraphStyle(ParagraphStyle style, DataOutputStream dos) throws IOException {
    Class clazz = style.getClass();
    dos.writeInt(mString.getSpanStart(style));
    dos.writeInt(mString.getSpanEnd(style));
    dos.writeInt(mString.getSpanFlags(style));
    if (mCharacterStylesTags.containsKey(clazz.getSimpleName())) {
        int tag = mCharacterStylesTags.get(clazz.getSimpleName());
        if (mCharacterStylesTags.containsKey(clazz.getSimpleName())) {
            dos.writeInt(tag);
        }
        switch (tag) {
            case 24: // AligmentSpan.Standard
                AlignmentSpan.Standard as2 = (AlignmentSpan.Standard)style;
                dos.writeInt(as2.getAlignment().ordinal());
                break;
            case 25: // BulletSpan
                BulletSpan bs = (BulletSpan)style;
                dos.writeInt(bs.getLeadingMargin(true));
                dos.writeInt(bs.getLeadingMargin(false));

                break;
            case 30: // LeadingMarginSpan.Sandard
                LeadingMarginSpan.Standard lms = (LeadingMarginSpan.Standard)style;
                dos.writeInt(lms.getLeadingMargin(true));
                dos.writeInt(lms.getLeadingMargin(false));
                break;
            case 34: // QuoteSpan
                QuoteSpan qs = (QuoteSpan)style;
                dos.writeInt(qs.getColor());
                break;
            case 36: // TabStopSpan.Standard
                TabStopSpan.Standard tss = (TabStopSpan.Standard)style;
                dos.writeInt(tss.getTabStop());
                break;
            default:
        }
    } else {
        write(style,dos);
    }
}
 
Example 12
Project: wATLlib   File: SpannedSerializator.java   Source Code and License 5 votes vote down vote up
private SpanPlacementInfo readSingleParagraph(DataInputStream dis) throws IOException {
    SpanPlacementInfo spi = new SpanPlacementInfo();
    spi.start = dis.readInt();
    spi.end = dis.readInt();
    spi.mode = dis.readInt();
    int tag = dis.readInt(); // mCharacterStylesTags.get(clazz.getSimpleName());
    switch (tag) {
        case 24: // AligmentSpan.Standard
            spi.span = new AlignmentSpan.Standard(Alignment.values()[dis.readInt()]);
            break;
        case 25: // BulletSpan
            spi.span = new BulletSpan(dis.readInt());
            dis.readInt(); // skip gap width for other lines
            break;
        case 30: // LeadingMarginSpan.Sandard
            spi.span = new LeadingMarginSpan.Standard(dis.readInt(),dis.readInt());
            break;
        case 34: // QuoteSpan
            spi.span = new QuoteSpan(dis.readInt());
            break;
        case 36: // TabStopSpan.Standard
            spi.span = new TabStopSpan.Standard(dis.readInt());
            break;
        case 80: // RemoteDrawableSpan
            break;
        default:
            spi.span = read(tag,dis);
    }
    return spi;
}
 
Example 13
Project: wordpress_app_android   File: LegacyEditorFragment.java   Source Code and License 5 votes vote down vote up
@Override
public void onSelectionChanged() {
    if (!mIsLocalDraft) {
        return;
    }

    final Spannable s = mContentEditText.getText();
    if (s == null)
        return;
    // set toggle buttons if cursor is inside of a matching span
    mStyleStart = mContentEditText.getSelectionStart();
    Object[] spans = s.getSpans(mContentEditText.getSelectionStart(), mContentEditText.getSelectionStart(), Object.class);

    mBoldToggleButton.setChecked(false);
    mEmToggleButton.setChecked(false);
    mBquoteToggleButton.setChecked(false);
    mUnderlineToggleButton.setChecked(false);
    mStrikeToggleButton.setChecked(false);
    for (Object span : spans) {
        if (span instanceof StyleSpan) {
            StyleSpan ss = (StyleSpan) span;
            if (ss.getStyle() == android.graphics.Typeface.BOLD) {
                mBoldToggleButton.setChecked(true);
            }
            if (ss.getStyle() == android.graphics.Typeface.ITALIC) {
                mEmToggleButton.setChecked(true);
            }
        }
        if (span instanceof QuoteSpan) {
            mBquoteToggleButton.setChecked(true);
        }
        if (span instanceof WPUnderlineSpan) {
            mUnderlineToggleButton.setChecked(true);
        }
        if (span instanceof StrikethroughSpan) {
            mStrikeToggleButton.setChecked(true);
        }
    }
}
 
Example 14
Project: kaif-android   File: KmarkProcessorTest.java   Source Code and License 5 votes vote down vote up
public void testNestSpan_order_as_begin() {
  SpannableStringBuilder result = (SpannableStringBuilder) KmarkProcessor.process(getContext(),
      "> *Sample* text");
  Object[] spans = result.getSpans(0, result.length(), Object.class);
  assertEquals(QuoteSpan.class, spans[0].getClass());
  assertEquals(StyleSpan.class, spans[1].getClass());
}
 
Example 15
Project: Trestle   File: Trestle.java   Source Code and License 5 votes vote down vote up
private static void setUpQuoteSpan(Span span, SpannableString ss, int start, int end) {
    int quoteColor = span.getQuoteColor();
    if (quoteColor != 0) {
        ss.setSpan(
            new QuoteSpan(quoteColor),
            start,
            end,
            Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
    }
}
 
Example 16
Project: Knife   File: KnifeText.java   Source Code and License 5 votes vote down vote up
protected void quoteInvalid() {
    String[] lines = TextUtils.split(getEditableText().toString(), "\n");

    for (int i = 0; i < lines.length; i++) {
        if (!containQuote(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 quoteStart = 0;
        int quoteEnd = 0;
        if (lineStart <= getSelectionStart() && getSelectionEnd() <= lineEnd) {
            quoteStart = lineStart;
            quoteEnd = lineEnd;
        } else if (getSelectionStart() <= lineStart && lineEnd <= getSelectionEnd()) {
            quoteStart = lineStart;
            quoteEnd = lineEnd;
        }

        if (quoteStart < quoteEnd) {
            QuoteSpan[] spans = getEditableText().getSpans(quoteStart, quoteEnd, QuoteSpan.class);
            for (QuoteSpan span : spans) {
                getEditableText().removeSpan(span);
            }
        }
    }
}
 
Example 17
Project: Knife   File: KnifeParser.java   Source Code and License 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 18
Project: Poem   File: PoemFormater.java   Source Code and License 5 votes vote down vote up
@Nullable
    public static CharSequence formatComment(String comment, int color){
        if (TextUtils.isEmpty(comment)){
            return null;
        }
        SpannableString spannableString = new SpannableString(comment);
//        final int color = getActivity().getResources().getColor(R.color.primary);
        final QuoteSpan quoteSpan = new CommentQuoteSpan(color);
        spannableString.setSpan(quoteSpan, 0, comment.length(), Spanned.SPAN_INCLUSIVE_INCLUSIVE);
        return spannableString;
    }
 
Example 19
Project: Slide   File: SpoilerRobotoTextView.java   Source Code and License 5 votes vote down vote up
/**
 * Replaces the blue line produced by <blockquote>s with something more visible
 *
 * @param spannable parsed comment text #fromHtml
 */
private void replaceQuoteSpans(Spannable spannable) {
    QuoteSpan[] quoteSpans = spannable.getSpans(0, spannable.length(), QuoteSpan.class);

    for (QuoteSpan quoteSpan : quoteSpans) {
        final int start = spannable.getSpanStart(quoteSpan);
        final int end = spannable.getSpanEnd(quoteSpan);
        final int flags = spannable.getSpanFlags(quoteSpan);

        spannable.removeSpan(quoteSpan);

        //If the theme is Light or Sepia, use a darker blue; otherwise, use a lighter blue
        final int barColor =
                (SettingValues.currentTheme == 1 || SettingValues.currentTheme == 5)
                        ? ContextCompat.getColor(getContext(), R.color.md_blue_600)
                        : ContextCompat.getColor(getContext(), R.color.md_blue_400);

        final int BAR_WIDTH = 4;
        final int GAP = 5;

        spannable.setSpan(new CustomQuoteSpan(Color.TRANSPARENT, //background color
                        barColor, //bar color
                        BAR_WIDTH, //bar width
                        GAP), //bar + text gap
                start, end, flags);
    }
}
 
Example 20
Project: Android-Spans   File: Span.java   Source Code and License 4 votes vote down vote up
public static Node quote(Object... nodes) {
    return new SpanNode(new QuoteSpan(), nodes);
}
 
Example 21
Project: Android-Spans   File: Span.java   Source Code and License 4 votes vote down vote up
public static Node quote(@ColorInt Integer color, Object... nodes) {
    return new SpanNode(new QuoteSpan(color), nodes);
}
 
Example 22
Project: HtmlCompat   File: HtmlToSpannedConverter.java   Source Code and License 4 votes vote down vote up
private void endBlockquote(String tag, Editable text) {
    endBlockElement(tag, text);
    end(tag, text, Blockquote.class, new QuoteSpan());
}
 
Example 23
Project: ForPDA   File: Html.java   Source Code and License 4 votes vote down vote up
private static void endBlockquote(Editable text) {
    endBlockElement(text);
    end(text, Blockquote.class, new QuoteSpan());
}
 
Example 24
Project: text-decorator   File: TextDecorator.java   Source Code and License 4 votes vote down vote up
public TextDecorator quote(final int start, final int end) {
  checkIndexOutOfBoundsException(start, end);
  decoratedContent.setSpan(new QuoteSpan(), start, end, flags);

  return this;
}
 
Example 25
Project: memoir   File: ConverterHtmlToSpanned.java   Source Code and License 4 votes vote down vote up
private void handleEndTag(String tag) {
    if (tag.equalsIgnoreCase("br")) {
        handleBr();
    } else if (tag.equalsIgnoreCase("p")) {
        handleP();
    } else if (tag.equalsIgnoreCase("div")) {
        endDiv();
    } else if (tag.equalsIgnoreCase("ul")) {
        endList(false);
    } else if (tag.equalsIgnoreCase("ol")) {
        endList(true);
    } else if (tag.equalsIgnoreCase("li")) {
        endList();
    } else if (tag.equalsIgnoreCase("strong")) {
        end(Bold.class, new BoldSpan());
    } else if (tag.equalsIgnoreCase("b")) {
        end(Bold.class, new BoldSpan());
    } else if (tag.equalsIgnoreCase("em")) {
        end(Italic.class, new ItalicSpan());
    } else if (tag.equalsIgnoreCase("cite")) {
        end(Italic.class, new ItalicSpan());
    } else if (tag.equalsIgnoreCase("dfn")) {
        end(Italic.class, new ItalicSpan());
    } else if (tag.equalsIgnoreCase("i")) {
        end(Italic.class, new ItalicSpan());
    } else if (tag.equalsIgnoreCase("strike")) {
        end(Strikethrough.class, new StrikethroughSpan());
    } else if (tag.equalsIgnoreCase("del")) {
        end(Strikethrough.class, new StrikethroughSpan());
    } else if (tag.equalsIgnoreCase("big")) {
        end(Big.class, new RelativeSizeSpan(1.25f));
    } else if (tag.equalsIgnoreCase("small")) {
        end(Small.class, new RelativeSizeSpan(0.8f));
    } else if (tag.equalsIgnoreCase("font")) {
        endFont();
    } else if (tag.equalsIgnoreCase("blockquote")) {
        handleP();
        end(Blockquote.class, new QuoteSpan());
    } else if (tag.equalsIgnoreCase("a")) {
        endAHref();
    } else if (tag.equalsIgnoreCase("u")) {
        end(Underline.class, new UnderlineSpan());
    } else if (tag.equalsIgnoreCase("sup")) {
        end(Super.class, new SuperscriptSpan());
    } else if (tag.equalsIgnoreCase("sub")) {
        end(Sub.class, new SubscriptSpan());
    } else if (tag.length() == 2 &&
            Character.toLowerCase(tag.charAt(0)) == 'h' &&
            tag.charAt(1) >= '1' && tag.charAt(1) <= '6') {
        handleP();
        endHeader();
    } else if (sIgnoreTags.contains(tag.toLowerCase(Locale.getDefault()))) {
        mIgnoreContent = false;
    }
}
 
Example 26
Project: memoir   File: ConverterHtmlToSpanned.java   Source Code and License 4 votes vote down vote up
private void handleEndTag(String tag) {
    if (tag.equalsIgnoreCase("br")) {
        handleBr();
    } else if (tag.equalsIgnoreCase("p")) {
        handleP();
    } else if (tag.equalsIgnoreCase("div")) {
        endDiv();
    } else if (tag.equalsIgnoreCase("ul")) {
        endList(false);
    } else if (tag.equalsIgnoreCase("ol")) {
        endList(true);
    } else if (tag.equalsIgnoreCase("li")) {
        endList();
    } else if (tag.equalsIgnoreCase("strong")) {
        end(Bold.class, new BoldSpan());
    } else if (tag.equalsIgnoreCase("b")) {
        end(Bold.class, new BoldSpan());
    } else if (tag.equalsIgnoreCase("em")) {
        end(Italic.class, new ItalicSpan());
    } else if (tag.equalsIgnoreCase("cite")) {
        end(Italic.class, new ItalicSpan());
    } else if (tag.equalsIgnoreCase("dfn")) {
        end(Italic.class, new ItalicSpan());
    } else if (tag.equalsIgnoreCase("i")) {
        end(Italic.class, new ItalicSpan());
    } else if (tag.equalsIgnoreCase("strike")) {
        end(Strikethrough.class, new StrikethroughSpan());
    } else if (tag.equalsIgnoreCase("del")) {
        end(Strikethrough.class, new StrikethroughSpan());
    } else if (tag.equalsIgnoreCase("big")) {
        end(Big.class, new RelativeSizeSpan(1.25f));
    } else if (tag.equalsIgnoreCase("small")) {
        end(Small.class, new RelativeSizeSpan(0.8f));
    } else if (tag.equalsIgnoreCase("font")) {
        endFont();
    } else if (tag.equalsIgnoreCase("blockquote")) {
        handleP();
        end(Blockquote.class, new QuoteSpan());
    } else if (tag.equalsIgnoreCase("a")) {
        endAHref();
    } else if (tag.equalsIgnoreCase("u")) {
        end(Underline.class, new UnderlineSpan());
    } else if (tag.equalsIgnoreCase("sup")) {
        end(Super.class, new SuperscriptSpan());
    } else if (tag.equalsIgnoreCase("sub")) {
        end(Sub.class, new SubscriptSpan());
    } else if (tag.length() == 2 &&
            Character.toLowerCase(tag.charAt(0)) == 'h' &&
            tag.charAt(1) >= '1' && tag.charAt(1) <= '6') {
        handleP();
        endHeader();
    } else if (sIgnoreTags.contains(tag.toLowerCase(Locale.getDefault()))) {
        mIgnoreContent = false;
    }
}
 
Example 27
Project: RichEditText   File: HtmlToSpannedConverter.java   Source Code and License 4 votes vote down vote up
private void handleEndTag(String tag)
{
    switch (tag.toLowerCase()) {
        case "br":
            handleBr(mSpannableStringBuilder);
            break;
        case "p":
        case "div":
            handleP(mSpannableStringBuilder);
            break;
        case "strong":
        case "b":
            end(mSpannableStringBuilder, Bold.class, new StyleSpan(Typeface.BOLD));
            break;
        case "em":
        case "cite":
        case "dfn":
        case "i":
            end(mSpannableStringBuilder, Italic.class, new StyleSpan(Typeface.ITALIC));
            break;
        case "font":
            endFont(mSpannableStringBuilder);
            break;
        case "blockquote":
            handleP(mSpannableStringBuilder);
            end(mSpannableStringBuilder, Blockquote.class, new QuoteSpan());
            break;
        case "li":
            handleP(mSpannableStringBuilder);
            end(mSpannableStringBuilder, Li.class, new RichBulletSpan());
            break;
        case "a":
            endA(mSpannableStringBuilder);
            break;
        case "u":
            end(mSpannableStringBuilder, Underline.class, new UnderlineSpan());
            break;
        case "strike":
            end(mSpannableStringBuilder, Strike.class, new StrikethroughSpan());
        default:
            if (tag.length() == 2 &&
                    Character.toLowerCase(tag.charAt(0)) == 'h' &&
                    tag.charAt(1) >= '1' &&
                    tag.charAt(1) <= '6') {
                handleP(mSpannableStringBuilder);
                endHeader(mSpannableStringBuilder);
            } else if (mTagHandler != null) {
                mTagHandler.handleTag(false, tag, mSpannableStringBuilder, mReader);
            }
    }

}
 
Example 28
Project: AyoSunny   File: HtmlTagHandler.java   Source Code and License 4 votes vote down vote up
private void handleEndTag(String tag) {
    if (tag.equalsIgnoreCase("br")) {
        handleBr(mSpannableStringBuilder);
    } else if (tag.equalsIgnoreCase("p")) {
        handleP(mSpannableStringBuilder);
    } else if (tag.equalsIgnoreCase("div")) {
        handleP(mSpannableStringBuilder);
    } else if (tag.equalsIgnoreCase("strong")) {
        end(mSpannableStringBuilder, Bold.class, new StyleSpan(Typeface.BOLD));
    } else if (tag.equalsIgnoreCase("b")) {
        end(mSpannableStringBuilder, Bold.class, new StyleSpan(Typeface.BOLD));
    } else if (tag.equalsIgnoreCase("em")) {
        end(mSpannableStringBuilder, Italic.class, new StyleSpan(Typeface.ITALIC));
    } else if (tag.equalsIgnoreCase("cite")) {
        end(mSpannableStringBuilder, Italic.class, new StyleSpan(Typeface.ITALIC));
    } else if (tag.equalsIgnoreCase("dfn")) {
        end(mSpannableStringBuilder, Italic.class, new StyleSpan(Typeface.ITALIC));
    } else if (tag.equalsIgnoreCase("i")) {
        end(mSpannableStringBuilder, Italic.class, new StyleSpan(Typeface.ITALIC));
    } else if (tag.equalsIgnoreCase("big")) {
        end(mSpannableStringBuilder, Big.class, new RelativeSizeSpan(1.25f));
    } else if (tag.equalsIgnoreCase("small")) {
        end(mSpannableStringBuilder, Small.class, new RelativeSizeSpan(0.8f));
    } else if (tag.equalsIgnoreCase("font")) {
        endFont(mSpannableStringBuilder);
    } else if (tag.equalsIgnoreCase("blockquote")) {
        handleP(mSpannableStringBuilder);
        end(mSpannableStringBuilder, Blockquote.class, new QuoteSpan());
    } else if (tag.equalsIgnoreCase("tt")) {
        end(mSpannableStringBuilder, Monospace.class,
                new TypefaceSpan("monospace"));
    } else if (tag.equalsIgnoreCase("a")) {
        endA(mSpannableStringBuilder);
    } else if (tag.equalsIgnoreCase("u")) {
        end(mSpannableStringBuilder, Underline.class, new UnderlineSpan());
    } else if (tag.equalsIgnoreCase("sup")) {
        end(mSpannableStringBuilder, Super.class, new SuperscriptSpan());
    } else if (tag.equalsIgnoreCase("sub")) {
        end(mSpannableStringBuilder, Sub.class, new SubscriptSpan());
    } else if (tag.length() == 2 &&
            Character.toLowerCase(tag.charAt(0)) == 'h' &&
            tag.charAt(1) >= '1' && tag.charAt(1) <= '6') {
        handleP(mSpannableStringBuilder);
        endHeader(mSpannableStringBuilder);
    } else if (mTagHandler != null) {
        mTagHandler.handleTag(false, tag, mSpannableStringBuilder, null);
    }
}
 
Example 29
Project: AyoSunny   File: HtmlHandler.java   Source Code and License 4 votes vote down vote up
private void handleEndTag(String tag) {
    if (tag.equalsIgnoreCase("br")) {
        handleBr(mSpannableStringBuilder);
    } else if (tag.equalsIgnoreCase("p")) {
        handleP(mSpannableStringBuilder);
    } else if (tag.equalsIgnoreCase("div")) {
        handleP(mSpannableStringBuilder);
    } else if (tag.equalsIgnoreCase("strong")) {
        end(mSpannableStringBuilder, Bold.class, new StyleSpan(Typeface.BOLD));
    } else if (tag.equalsIgnoreCase("b")) {
        end(mSpannableStringBuilder, Bold.class, new StyleSpan(Typeface.BOLD));
    } else if (tag.equalsIgnoreCase("em")) {
        end(mSpannableStringBuilder, Italic.class, new StyleSpan(Typeface.ITALIC));
    } else if (tag.equalsIgnoreCase("cite")) {
        end(mSpannableStringBuilder, Italic.class, new StyleSpan(Typeface.ITALIC));
    } else if (tag.equalsIgnoreCase("dfn")) {
        end(mSpannableStringBuilder, Italic.class, new StyleSpan(Typeface.ITALIC));
    } else if (tag.equalsIgnoreCase("i")) {
        end(mSpannableStringBuilder, Italic.class, new StyleSpan(Typeface.ITALIC));
    } else if (tag.equalsIgnoreCase("big")) {
        end(mSpannableStringBuilder, Big.class, new RelativeSizeSpan(1.25f));
    } else if (tag.equalsIgnoreCase("small")) {
        end(mSpannableStringBuilder, Small.class, new RelativeSizeSpan(0.8f));
    } else if (tag.equalsIgnoreCase("font")) {
        endFont(mSpannableStringBuilder);
    } else if (tag.equalsIgnoreCase("blockquote")) {
        handleP(mSpannableStringBuilder);
        end(mSpannableStringBuilder, Blockquote.class, new QuoteSpan());
    } else if (tag.equalsIgnoreCase("tt")) {
        end(mSpannableStringBuilder, Monospace.class,
                new TypefaceSpan("monospace"));
    } else if (tag.equalsIgnoreCase("a")) {
        endA(mSpannableStringBuilder);
    } else if (tag.equalsIgnoreCase("u")) {
        end(mSpannableStringBuilder, Underline.class, new UnderlineSpan());
    } else if (tag.equalsIgnoreCase("sup")) {
        end(mSpannableStringBuilder, Super.class, new SuperscriptSpan());
    } else if (tag.equalsIgnoreCase("sub")) {
        end(mSpannableStringBuilder, Sub.class, new SubscriptSpan());
    } else if (tag.length() == 2 &&
            Character.toLowerCase(tag.charAt(0)) == 'h' &&
            tag.charAt(1) >= '1' && tag.charAt(1) <= '6') {
        handleP(mSpannableStringBuilder);
        endHeader(mSpannableStringBuilder);
    } else if (mTagHandler != null) {
        mTagHandler.handleTag(false, tag, mSpannableStringBuilder, null);
    }
}
 
Example 30
Project: Doctor   File: ConverterHtmlToSpanned.java   Source Code and License 4 votes vote down vote up
private void handleEndTag(String tag) {
    if (tag.equalsIgnoreCase("br")) {
        handleBr();
    } else if (tag.equalsIgnoreCase("p")) {
        handleP();
    } else if (tag.equalsIgnoreCase("div")) {
        endDiv();
    } else if (tag.equalsIgnoreCase("ul")) {
        endList(false);
    } else if (tag.equalsIgnoreCase("ol")) {
        endList(true);
    } else if (tag.equalsIgnoreCase("li")) {
        endList();
    } else if (tag.equalsIgnoreCase("strong")) {
        end(Bold.class, new BoldSpan());
    } else if (tag.equalsIgnoreCase("b")) {
        end(Bold.class, new BoldSpan());
    } else if (tag.equalsIgnoreCase("em")) {
        end(Italic.class, new ItalicSpan());
    } else if (tag.equalsIgnoreCase("cite")) {
        end(Italic.class, new ItalicSpan());
    } else if (tag.equalsIgnoreCase("dfn")) {
        end(Italic.class, new ItalicSpan());
    } else if (tag.equalsIgnoreCase("i")) {
        end(Italic.class, new ItalicSpan());
    } else if (tag.equalsIgnoreCase("strike")) {
        end(Strikethrough.class, new StrikethroughSpan());
    } else if (tag.equalsIgnoreCase("del")) {
        end(Strikethrough.class, new StrikethroughSpan());
    } else if (tag.equalsIgnoreCase("big")) {
        end(Big.class, new RelativeSizeSpan(1.25f));
    } else if (tag.equalsIgnoreCase("small")) {
        end(Small.class, new RelativeSizeSpan(0.8f));
    } else if (tag.equalsIgnoreCase("font")) {
        endFont();
    } else if (tag.equalsIgnoreCase("blockquote")) {
        handleP();
        end(Blockquote.class, new QuoteSpan());
    } else if (tag.equalsIgnoreCase("a")) {
        endAHref();
    } else if (tag.equalsIgnoreCase("u")) {
        end(Underline.class, new UnderlineSpan());
    } else if (tag.equalsIgnoreCase("sup")) {
        end(Super.class, new SuperscriptSpan());
    } else if (tag.equalsIgnoreCase("sub")) {
        end(Sub.class, new SubscriptSpan());
    } else if (tag.length() == 2 &&
            Character.toLowerCase(tag.charAt(0)) == 'h' &&
            tag.charAt(1) >= '1' && tag.charAt(1) <= '6') {
        handleP();
        endHeader();
    } else if (sIgnoreTags.contains(tag.toLowerCase(Locale.getDefault()))) {
        mIgnoreContent = false;
    }
}
 
Example 31
Project: Nimingban   File: Html.java   Source Code and License 4 votes vote down vote up
private void handleEndTag(String tag) {
    if (mTagHandler == null || !mTagHandler.handleTag(false, tag,
            mSpannableStringBuilder, mReader, null)) {
        if (tag.equalsIgnoreCase("br")) {
            handleBr(mSpannableStringBuilder);
        } else if (tag.equalsIgnoreCase("p")) {
            handleP(mSpannableStringBuilder);
        } else if (tag.equalsIgnoreCase("div")) {
            handleP(mSpannableStringBuilder);
        } else if (tag.equalsIgnoreCase("strong")) {
            end(mSpannableStringBuilder, Bold.class, new StyleSpan(Typeface.BOLD));
        } else if (tag.equalsIgnoreCase("b")) {
            end(mSpannableStringBuilder, Bold.class, new StyleSpan(Typeface.BOLD));
        } else if (tag.equalsIgnoreCase("em")) {
            end(mSpannableStringBuilder, Italic.class, new StyleSpan(Typeface.ITALIC));
        } else if (tag.equalsIgnoreCase("cite")) {
            end(mSpannableStringBuilder, Italic.class, new StyleSpan(Typeface.ITALIC));
        } else if (tag.equalsIgnoreCase("dfn")) {
            end(mSpannableStringBuilder, Italic.class, new StyleSpan(Typeface.ITALIC));
        } else if (tag.equalsIgnoreCase("i")) {
            end(mSpannableStringBuilder, Italic.class, new StyleSpan(Typeface.ITALIC));
        } else if (tag.equalsIgnoreCase("big")) {
            end(mSpannableStringBuilder, Big.class, new RelativeSizeSpan(1.25f));
        } else if (tag.equalsIgnoreCase("small")) {
            end(mSpannableStringBuilder, Small.class, new RelativeSizeSpan(0.8f));
        } else if (tag.equalsIgnoreCase("font")) {
            endFont(mSpannableStringBuilder);
        } else if (tag.equalsIgnoreCase("blockquote")) {
            handleP(mSpannableStringBuilder);
            end(mSpannableStringBuilder, Blockquote.class, new QuoteSpan());
        } else if (tag.equalsIgnoreCase("tt")) {
            end(mSpannableStringBuilder, Monospace.class,
                    new TypefaceSpan("monospace"));
        } else if (tag.equalsIgnoreCase("a")) {
            endA(mSpannableStringBuilder);
        } else if (tag.equalsIgnoreCase("u")) {
            end(mSpannableStringBuilder, Underline.class, new UnderlineSpan());
        } else if (tag.equalsIgnoreCase("ins")) {
            end(mSpannableStringBuilder, Underline.class, new UnderlineSpan());
        } else if (tag.equalsIgnoreCase("strike")) {
            end(mSpannableStringBuilder, Strike.class, new StrikethroughSpan());
        } else if (tag.equalsIgnoreCase("s")) {
            end(mSpannableStringBuilder, Strike.class, new StrikethroughSpan());
        } else if (tag.equalsIgnoreCase("del")) {
            end(mSpannableStringBuilder, Strike.class, new StrikethroughSpan());
        } else if (tag.equalsIgnoreCase("sup")) {
            end(mSpannableStringBuilder, Super.class, new SuperscriptSpan());
        } else if (tag.equalsIgnoreCase("sub")) {
            end(mSpannableStringBuilder, Sub.class, new SubscriptSpan());
        } else if (tag.length() == 2 &&
                Character.toLowerCase(tag.charAt(0)) == 'h' &&
                tag.charAt(1) >= '1' && tag.charAt(1) <= '6') {
            handleP(mSpannableStringBuilder);
            endHeader(mSpannableStringBuilder);
        }
    }
}
 
Example 32
Project: wordpress_app_android   File: LegacyEditorFragment.java   Source Code and License 4 votes vote down vote up
@Override
public void afterTextChanged(Editable s) {
    int position = Selection.getSelectionStart(mContentEditText.getText());
    if ((mIsBackspace && position != 1) || mLastPosition == position || !mIsLocalDraft)
        return;

    if (position < 0) {
        position = 0;
    }
    mLastPosition = position;
    if (position > 0) {
        if (mStyleStart > position) {
            mStyleStart = position - 1;
        }

        boolean shouldBold = mBoldToggleButton.isChecked();
        boolean shouldEm = mEmToggleButton.isChecked();
        boolean shouldUnderline = mUnderlineToggleButton.isChecked();
        boolean shouldStrike = mStrikeToggleButton.isChecked();
        boolean shouldQuote = mBquoteToggleButton.isChecked();

        Object[] allSpans = s.getSpans(mStyleStart, position, Object.class);
        for (Object span : allSpans) {
            if (span instanceof StyleSpan) {
                StyleSpan styleSpan = (StyleSpan) span;
                if (styleSpan.getStyle() == Typeface.BOLD)
                    shouldBold = false;
                else if (styleSpan.getStyle() == Typeface.ITALIC)
                    shouldEm = false;
            } else if (span instanceof WPUnderlineSpan) {
                shouldUnderline = false;
            } else if (span instanceof StrikethroughSpan) {
                shouldStrike = false;
            } else if (span instanceof QuoteSpan) {
                shouldQuote = false;
            }
        }

        if (shouldBold)
            s.setSpan(new StyleSpan(android.graphics.Typeface.BOLD), mStyleStart, position, Spannable.SPAN_INCLUSIVE_INCLUSIVE);
        if (shouldEm)
            s.setSpan(new StyleSpan(android.graphics.Typeface.ITALIC), mStyleStart, position, Spannable.SPAN_INCLUSIVE_INCLUSIVE);
        if (shouldUnderline)
            s.setSpan(new WPUnderlineSpan(), mStyleStart, position, Spannable.SPAN_INCLUSIVE_INCLUSIVE);
        if (shouldStrike)
            s.setSpan(new StrikethroughSpan(), mStyleStart, position, Spannable.SPAN_INCLUSIVE_INCLUSIVE);
        if (shouldQuote)
            s.setSpan(new QuoteSpan(), mStyleStart, position, Spannable.SPAN_INCLUSIVE_INCLUSIVE);
    }
}
 
Example 33
Project: wordpress_app_android   File: WPHtml.java   Source Code and License 4 votes vote down vote up
private void handleEndTag(String tag) {
    if (post != null) {
        if (!post.isLocalDraft())
            return;
    }
    if (!mysteryTagFound) {
        if (tag.equalsIgnoreCase("br")) {
            handleBr(mSpannableStringBuilder);
        } else if (tag.equalsIgnoreCase("p")) {
            handleP(mSpannableStringBuilder);
        } else if (tag.equalsIgnoreCase("div")) {
            handleP(mSpannableStringBuilder);
        } else if (tag.equalsIgnoreCase("em")) {
            end(mSpannableStringBuilder, Italic.class, new StyleSpan(
                    Typeface.ITALIC));
        } else if (tag.equalsIgnoreCase("b")) {
            end(mSpannableStringBuilder, Bold.class, new StyleSpan(
                    Typeface.BOLD));
        } else if (tag.equalsIgnoreCase("strong")) {
            end(mSpannableStringBuilder, Bold.class, new StyleSpan(
                    Typeface.BOLD));
        } else if (tag.equalsIgnoreCase("cite")) {
            end(mSpannableStringBuilder, Italic.class, new StyleSpan(
                    Typeface.ITALIC));
        } else if (tag.equalsIgnoreCase("dfn")) {
            end(mSpannableStringBuilder, Italic.class, new StyleSpan(
                    Typeface.ITALIC));
        } else if (tag.equalsIgnoreCase("i")) {
            end(mSpannableStringBuilder, Italic.class, new StyleSpan(
                    Typeface.ITALIC));
        } else if (tag.equalsIgnoreCase("big")) {
            end(mSpannableStringBuilder, Big.class, new RelativeSizeSpan(
                    1.25f));
        } else if (tag.equalsIgnoreCase("small")) {
            end(mSpannableStringBuilder, Small.class, new RelativeSizeSpan(
                    0.8f));
        } else if (tag.equalsIgnoreCase("font")) {
            endFont(mSpannableStringBuilder);
        } else if (tag.equalsIgnoreCase("blockquote")) {
            handleP(mSpannableStringBuilder);
            end(mSpannableStringBuilder, Blockquote.class, new QuoteSpan());
        } else if (tag.equalsIgnoreCase("tt")) {
            end(mSpannableStringBuilder, Monospace.class, new TypefaceSpan(
                    "monospace"));
        } else if (tag.equalsIgnoreCase("a")) {
            endA(mSpannableStringBuilder);
        } else if (tag.equalsIgnoreCase("u")) {
            end(mSpannableStringBuilder, Underline.class,
                    new WPUnderlineSpan());
        } else if (tag.equalsIgnoreCase("sup")) {
            end(mSpannableStringBuilder, Super.class, new SuperscriptSpan());
        } else if (tag.equalsIgnoreCase("sub")) {
            end(mSpannableStringBuilder, Sub.class, new SubscriptSpan());
        } else if (tag.equalsIgnoreCase("strike")) {
            end(mSpannableStringBuilder, Strike.class,
                    new StrikethroughSpan());
        } else if (tag.length() == 2
                && Character.toLowerCase(tag.charAt(0)) == 'h'
                && tag.charAt(1) >= '1' && tag.charAt(1) <= '6') {
            handleP(mSpannableStringBuilder);
            endHeader(mSpannableStringBuilder);
        }
    } else {
        if (tag.equalsIgnoreCase("html") || tag.equalsIgnoreCase("body")) {
            return;
        }

        if (mysteryTagName.equals(tag)) {
            mysteryTagFound = false;
            mSpannableStringBuilder.append(mysteryTagContent);
        }
        // mTagHandler.handleTag(false, tag, mSpannableStringBuilder,
        // mReader,
        // mysteryTagContent);
    }
}
 
Example 34
Project: kaif-android   File: DefaultDecorator.java   Source Code and License 4 votes vote down vote up
@Override
public void closeBlockquote(SpannableStringBuilder out) {
  end(out, Blockquote.class, new QuoteSpan());
}
 
Example 35
Project: android-customfonthtml   File: CustomHtml.java   Source Code and License 4 votes vote down vote up
private void handleEndTag(String tag) {
	if (tag.equalsIgnoreCase("br")) {
		handleBr(mSpannableStringBuilder);
	} else if (tag.equalsIgnoreCase("p")) {
		handleP(mSpannableStringBuilder);
	} else if (tag.equalsIgnoreCase("div")) {
		handleP(mSpannableStringBuilder);
	} else if (tag.equalsIgnoreCase("strong")) {
		end(mSpannableStringBuilder, Bold.class, new StyleSpan(
				Typeface.BOLD));
	} else if (tag.equalsIgnoreCase("b")) {
		end(mSpannableStringBuilder, Bold.class, new StyleSpan(
				Typeface.BOLD));
	} else if (tag.equalsIgnoreCase("em")) {
		end(mSpannableStringBuilder, Italic.class, new StyleSpan(
				Typeface.ITALIC));
	} else if (tag.equalsIgnoreCase("cite")) {
		end(mSpannableStringBuilder, Italic.class, new StyleSpan(
				Typeface.ITALIC));
	} else if (tag.equalsIgnoreCase("dfn")) {
		end(mSpannableStringBuilder, Italic.class, new StyleSpan(
				Typeface.ITALIC));
	} else if (tag.equalsIgnoreCase("i")) {
		end(mSpannableStringBuilder, Italic.class, new StyleSpan(
				Typeface.ITALIC));
	} else if (tag.equalsIgnoreCase("big")) {
		end(mSpannableStringBuilder, Big.class, new RelativeSizeSpan(
				1.25f));
	} else if (tag.equalsIgnoreCase("small")) {
		end(mSpannableStringBuilder, Small.class, new RelativeSizeSpan(
				0.8f));
	} else if (tag.equalsIgnoreCase("font")) {
		endFont(mSpannableStringBuilder);
	} else if (tag.equalsIgnoreCase("blockquote")) {
		handleP(mSpannableStringBuilder);
		end(mSpannableStringBuilder, Blockquote.class, new QuoteSpan());
	} else if (tag.equalsIgnoreCase("tt")) {
		end(mSpannableStringBuilder, Monospace.class, new TypefaceSpan(
				"monospace"));
	} else if (tag.equalsIgnoreCase("a")) {
		endA(mSpannableStringBuilder);
	} else if (tag.equalsIgnoreCase("u")) {
		end(mSpannableStringBuilder, Underline.class,
				new UnderlineSpan());
	} else if (tag.equalsIgnoreCase("sup")) {
		end(mSpannableStringBuilder, Super.class, new SuperscriptSpan());
	} else if (tag.equalsIgnoreCase("sub")) {
		end(mSpannableStringBuilder, Sub.class, new SubscriptSpan());
	} else if (tag.length() == 2
			&& Character.toLowerCase(tag.charAt(0)) == 'h'
			&& tag.charAt(1) >= '1' && tag.charAt(1) <= '6') {
		handleP(mSpannableStringBuilder);
		endHeader(mSpannableStringBuilder);
	} else if (mTagHandler != null) {
		mTagHandler.handleTag(false, tag, mSpannableStringBuilder,
				mReader);
	}
}
 
Example 36
Project: v2ex-android   File: Html.java   Source Code and License 4 votes vote down vote up
private void handleEndTag(String tag) {
    if (tag.equalsIgnoreCase("br")) {
        handleBr(mSpannableStringBuilder);
    } else if (tag.equalsIgnoreCase("p")) {
        handleP(mSpannableStringBuilder);
    } else if (tag.equalsIgnoreCase("div")) {
        handleP(mSpannableStringBuilder);
    } else if (tag.equalsIgnoreCase("strong")) {
        end(mSpannableStringBuilder, Bold.class, new StyleSpan(Typeface.BOLD));
    } else if (tag.equalsIgnoreCase("b")) {
        end(mSpannableStringBuilder, Bold.class, new StyleSpan(Typeface.BOLD));
    } else if (tag.equalsIgnoreCase("em")) {
        end(mSpannableStringBuilder, Italic.class, new StyleSpan(Typeface.ITALIC));
    } else if (tag.equalsIgnoreCase("cite")) {
        end(mSpannableStringBuilder, Italic.class, new StyleSpan(Typeface.ITALIC));
    } else if (tag.equalsIgnoreCase("dfn")) {
        end(mSpannableStringBuilder, Italic.class, new StyleSpan(Typeface.ITALIC));
    } else if (tag.equalsIgnoreCase("i")) {
        end(mSpannableStringBuilder, Italic.class, new StyleSpan(Typeface.ITALIC));
    } else if (tag.equalsIgnoreCase("big")) {
        end(mSpannableStringBuilder, Big.class, new RelativeSizeSpan(1.25f));
    } else if (tag.equalsIgnoreCase("small")) {
        end(mSpannableStringBuilder, Small.class, new RelativeSizeSpan(0.8f));
    } else if (tag.equalsIgnoreCase("font")) {
        endFont(mSpannableStringBuilder);
    } else if (tag.equalsIgnoreCase("blockquote")) {
        handleP(mSpannableStringBuilder);
        end(mSpannableStringBuilder, Blockquote.class, new QuoteSpan());
    } else if (tag.equalsIgnoreCase("tt")) {
        end(mSpannableStringBuilder, Monospace.class,
                new TypefaceSpan("monospace"));
    } else if (tag.equalsIgnoreCase("a")) {
        endA(mSpannableStringBuilder, mImageGetter);
    } else if (tag.equalsIgnoreCase("u")) {
        end(mSpannableStringBuilder, Underline.class, new UnderlineSpan());
    } else if (tag.equalsIgnoreCase("sup")) {
        end(mSpannableStringBuilder, Super.class, new SuperscriptSpan());
    } else if (tag.equalsIgnoreCase("sub")) {
        end(mSpannableStringBuilder, Sub.class, new SubscriptSpan());
    } else if (tag.length() == 2 &&
            Character.toLowerCase(tag.charAt(0)) == 'h' &&
            tag.charAt(1) >= '1' && tag.charAt(1) <= '6') {
        handleP(mSpannableStringBuilder);
        endHeader(mSpannableStringBuilder);
    } else if (tag.equalsIgnoreCase("script")) {
        endScript(mSpannableStringBuilder);
    } else if (tag.equalsIgnoreCase("iframe")) {
        endIframe(mSpannableStringBuilder);
    } else if (tag.equalsIgnoreCase("button")) {
        endButton(mSpannableStringBuilder);
    } else if (tag.equalsIgnoreCase("code")) {
        end(mSpannableStringBuilder, Code.class, new BackgroundColorSpan(0xFFEEEEEE));
    } else if (tag.equalsIgnoreCase("pre")) {
        mInPreTag = false;
        end(mSpannableStringBuilder, Pre.class, new BackgroundColorSpan(0xFFEEEEEE));
    } else if (tag.equalsIgnoreCase("li")) {
        mSpannableStringBuilder.append('\n');
    }
}
 
Example 37
Project: love   File: Html.java   Source Code and License 4 votes vote down vote up
private void handleEndTag(String tag) {
	if (tag.equalsIgnoreCase("br")) {
		handleBr(mSpannableStringBuilder);
	} else if (tag.equalsIgnoreCase("p")) {
		handleP(mSpannableStringBuilder);
	} else if (tag.equalsIgnoreCase("div")) {
		handleP(mSpannableStringBuilder);
	} else if (tag.equalsIgnoreCase("strong")) {
		end(mSpannableStringBuilder, Bold.class, new StyleSpan(
				Typeface.BOLD));
	} else if (tag.equalsIgnoreCase("b")) {
		end(mSpannableStringBuilder, Bold.class, new StyleSpan(
				Typeface.BOLD));
	} else if (tag.equalsIgnoreCase("em")) {
		endEm(mSpannableStringBuilder);
	} else if (tag.equalsIgnoreCase("cite")) {
		end(mSpannableStringBuilder, Italic.class, new StyleSpan(
				Typeface.ITALIC));
	} else if (tag.equalsIgnoreCase("dfn")) {
		end(mSpannableStringBuilder, Italic.class, new StyleSpan(
				Typeface.ITALIC));
	} else if (tag.equalsIgnoreCase("i")) {
		end(mSpannableStringBuilder, Italic.class, new StyleSpan(
				Typeface.ITALIC));
	} else if (tag.equalsIgnoreCase("big")) {
		end(mSpannableStringBuilder, Big.class, new RelativeSizeSpan(1.25f));
	} else if (tag.equalsIgnoreCase("small")) {
		end(mSpannableStringBuilder, Small.class,
				new RelativeSizeSpan(0.8f));
	} else if (tag.equalsIgnoreCase("font")) {
		endFont(mSpannableStringBuilder);
	} else if (tag.equalsIgnoreCase("blockquote")) {
		handleP(mSpannableStringBuilder);
		end(mSpannableStringBuilder, Blockquote.class, new QuoteSpan());
	} else if (tag.equalsIgnoreCase("tt")) {
		end(mSpannableStringBuilder, Monospace.class, new TypefaceSpan(
				"monospace"));
	} else if (tag.equalsIgnoreCase("a")) {
		endA(mSpannableStringBuilder);
	} else if (tag.equalsIgnoreCase("u")) {
		end(mSpannableStringBuilder, Underline.class, new UnderlineSpan());
	} else if (tag.equalsIgnoreCase("sup")) {
		end(mSpannableStringBuilder, Super.class, new SuperscriptSpan());
	} else if (tag.equalsIgnoreCase("sub")) {
		end(mSpannableStringBuilder, Sub.class, new SubscriptSpan());
	} else if (tag.length() == 2
			&& Character.toLowerCase(tag.charAt(0)) == 'h'
			&& tag.charAt(1) >= '1' && tag.charAt(1) <= '6') {
		handleP(mSpannableStringBuilder);
		endHeader(mSpannableStringBuilder);
	} else if (mTagHandler != null) {
		mTagHandler.handleTag(false, tag, mSpannableStringBuilder, mReader);
	}
}
 
Example 38
Project: FanFictionReader   File: HtmlParser.java   Source Code and License 4 votes vote down vote up
/***
 * Handles the tailing tag of every element
 *
 * @param element
 */
private void handleEndTag(Element element) {
	final Attributes attributes = element.attributes();
	if (attributes.hasKey("style"))
		handleCssEnd(attributes.get("style"));

	final String tag = element.tagName();
	switch (tag.toLowerCase()) {
		case "p":
		case "div":
			handleP();
			break;
		case "b":
		case "strong":
			endSpan(new StyleSpan(Typeface.BOLD));
			break;
		case "em":
		case "cite":
		case "dfn":
		case "i":
			endSpan(new StyleSpan(Typeface.ITALIC));
			break;
		case "big":
			endSpan(new RelativeSizeSpan(1.25f));
			break;
		case "small":
			endSpan(new RelativeSizeSpan(0.8f));
			break;
		case "blockquote":
			endSpan(new QuoteSpan());
			handleP();
			break;
		case "tt":
			endSpan(new TypefaceSpan("monospace"));
			break;
		case "u":
			endSpan(new UnderlineSpan());
			break;
		case "sub":
			endSpan(new SubscriptSpan());
			break;
		case "sup":
			endSpan(new SuperscriptSpan());
			break;
		case "a":
			handleLink(element.absUrl("href"));
	}
}
 
Example 39
Project: AndroidSpan   File: SpanOptions.java   Source Code and License 4 votes vote down vote up
public SpanOptions addQuoteSpan(int color) {
    QuoteSpan span = new QuoteSpan(color);
    listSpan.add(span);
    return this;
}
 
Example 40
Project: trezor-android   File: Html.java   Source Code and License 4 votes vote down vote up
protected void handleEndTag(String tag) {
	if (mTagHandler != null && mTagHandler.handleEndTag(tag, mSpannableStringBuilder, mReader)) {
		// 
	}
	else if (tag.equalsIgnoreCase("br")) {
        handleBr(mSpannableStringBuilder);
    } else if (tag.equalsIgnoreCase("p")) {
        handleP(mSpannableStringBuilder);
    } else if (tag.equalsIgnoreCase("div")) {
        handleP(mSpannableStringBuilder);
    } else if (tag.equalsIgnoreCase("em")) {
        end(mSpannableStringBuilder, Bold.class, new StyleSpan(Typeface.BOLD));
    } else if (tag.equalsIgnoreCase("b")) {
        end(mSpannableStringBuilder, Bold.class, new StyleSpan(Typeface.BOLD));
    } else if (tag.equalsIgnoreCase("strong")) {
        end(mSpannableStringBuilder, Italic.class, new StyleSpan(Typeface.ITALIC));
    } else if (tag.equalsIgnoreCase("cite")) {
        end(mSpannableStringBuilder, Italic.class, new StyleSpan(Typeface.ITALIC));
    } else if (tag.equalsIgnoreCase("dfn")) {
        end(mSpannableStringBuilder, Italic.class, new StyleSpan(Typeface.ITALIC));
    } else if (tag.equalsIgnoreCase("i")) {
        end(mSpannableStringBuilder, Italic.class, new StyleSpan(Typeface.ITALIC));
    } else if (tag.equalsIgnoreCase("big")) {
        end(mSpannableStringBuilder, Big.class, new RelativeSizeSpan(1.25f));
    } else if (tag.equalsIgnoreCase("small")) {
        end(mSpannableStringBuilder, Small.class, new RelativeSizeSpan(0.8f));
    } else if (tag.equalsIgnoreCase("font")) {
        endFont(mSpannableStringBuilder);
    } else if (tag.equalsIgnoreCase("blockquote")) {
        handleP(mSpannableStringBuilder);
        end(mSpannableStringBuilder, Blockquote.class, new QuoteSpan());
    } else if (tag.equalsIgnoreCase("tt")) {
        end(mSpannableStringBuilder, Monospace.class,
                new TypefaceSpan("monospace"));
    } else if (tag.equalsIgnoreCase("a")) {
        endA(mSpannableStringBuilder);
    } else if (tag.equalsIgnoreCase("u")) {
        end(mSpannableStringBuilder, Underline.class, new UnderlineSpan());
    } else if (tag.equalsIgnoreCase("sup")) {
        end(mSpannableStringBuilder, Super.class, new SuperscriptSpan());
    } else if (tag.equalsIgnoreCase("sub")) {
        end(mSpannableStringBuilder, Sub.class, new SubscriptSpan());
    } else if (tag.length() == 2 &&
            Character.toLowerCase(tag.charAt(0)) == 'h' &&
            tag.charAt(1) >= '1' && tag.charAt(1) <= '6') {
        handleP(mSpannableStringBuilder);
        endHeader(mSpannableStringBuilder);
    } 
}
 
Example 41
Project: EhViewer   File: Html.java   Source Code and License 4 votes vote down vote up
private void handleEndTag(String tag) {
    if (tag.equalsIgnoreCase("br")) {
        handleBr(mSpannableStringBuilder);
    } else if (tag.equalsIgnoreCase("p")) {
        handleP(mSpannableStringBuilder);
    } else if (tag.equalsIgnoreCase("div")) {
        handleP(mSpannableStringBuilder);
    } else if (tag.equalsIgnoreCase("strong")) {
        end(mSpannableStringBuilder, Bold.class, new StyleSpan(Typeface.BOLD));
    } else if (tag.equalsIgnoreCase("b")) {
        end(mSpannableStringBuilder, Bold.class, new StyleSpan(Typeface.BOLD));
    } else if (tag.equalsIgnoreCase("em")) {
        end(mSpannableStringBuilder, Italic.class, new StyleSpan(Typeface.ITALIC));
    } else if (tag.equalsIgnoreCase("cite")) {
        end(mSpannableStringBuilder, Italic.class, new StyleSpan(Typeface.ITALIC));
    } else if (tag.equalsIgnoreCase("dfn")) {
        end(mSpannableStringBuilder, Italic.class, new StyleSpan(Typeface.ITALIC));
    } else if (tag.equalsIgnoreCase("i")) {
        end(mSpannableStringBuilder, Italic.class, new StyleSpan(Typeface.ITALIC));
    } else if (tag.equalsIgnoreCase("big")) {
        end(mSpannableStringBuilder, Big.class, new RelativeSizeSpan(1.25f));
    } else if (tag.equalsIgnoreCase("small")) {
        end(mSpannableStringBuilder, Small.class, new RelativeSizeSpan(0.8f));
    } else if (tag.equalsIgnoreCase("font")) {
        endFont(mSpannableStringBuilder);
    } else if (tag.equalsIgnoreCase("blockquote")) {
        handleP(mSpannableStringBuilder);
        end(mSpannableStringBuilder, Blockquote.class, new QuoteSpan());
    } else if (tag.equalsIgnoreCase("tt")) {
        end(mSpannableStringBuilder, Monospace.class,
                new TypefaceSpan("monospace"));
    } else if (tag.equalsIgnoreCase("a")) {
        endA(mSpannableStringBuilder);
    } else if (tag.equalsIgnoreCase("u")) {
        end(mSpannableStringBuilder, Underline.class, new UnderlineSpan());
    } else if (tag.equalsIgnoreCase("ins")) {
        end(mSpannableStringBuilder, Underline.class, new UnderlineSpan());
    } else if (tag.equalsIgnoreCase("strike")) {
        end(mSpannableStringBuilder, Strike.class, new StrikethroughSpan());
    } else if (tag.equalsIgnoreCase("s")) {
        end(mSpannableStringBuilder, Strike.class, new StrikethroughSpan());
    } else if (tag.equalsIgnoreCase("del")) {
        end(mSpannableStringBuilder, Strike.class, new StrikethroughSpan());
    } else if (tag.equalsIgnoreCase("sup")) {
        end(mSpannableStringBuilder, Super.class, new SuperscriptSpan());
    } else if (tag.equalsIgnoreCase("sub")) {
        end(mSpannableStringBuilder, Sub.class, new SubscriptSpan());
    } else if (tag.length() == 2 &&
            Character.toLowerCase(tag.charAt(0)) == 'h' &&
            tag.charAt(1) >= '1' && tag.charAt(1) <= '6') {
        handleP(mSpannableStringBuilder);
        endHeader(mSpannableStringBuilder);
    } else if (mTagHandler != null) {
        mTagHandler.handleTag(false, tag, mSpannableStringBuilder, mReader);
    }
}
 
Example 42
Project: phimpme-android-v1   File: WPHtml.java   Source Code and License 4 votes vote down vote up
private void handleEndTag(String tag) {
	if (post != null) {
		if (!post.isLocalDraft())
			return;
	}
	if (!mysteryTagFound) {
		if (tag.equalsIgnoreCase("br")) {
			handleBr(mSpannableStringBuilder);
		} else if (tag.equalsIgnoreCase("p")) {
			handleP(mSpannableStringBuilder);
		} else if (tag.equalsIgnoreCase("div")) {
			handleP(mSpannableStringBuilder);
		} else if (tag.equalsIgnoreCase("em")) {
			end(mSpannableStringBuilder, Italic.class, new StyleSpan(
					Typeface.ITALIC));
		} else if (tag.equalsIgnoreCase("b")) {
			end(mSpannableStringBuilder, Bold.class, new StyleSpan(
					Typeface.BOLD));
		} else if (tag.equalsIgnoreCase("strong")) {
			end(mSpannableStringBuilder, Bold.class, new StyleSpan(
					Typeface.BOLD));
		} else if (tag.equalsIgnoreCase("cite")) {
			end(mSpannableStringBuilder, Italic.class, new StyleSpan(
					Typeface.ITALIC));
		} else if (tag.equalsIgnoreCase("dfn")) {
			end(mSpannableStringBuilder, Italic.class, new StyleSpan(
					Typeface.ITALIC));
		} else if (tag.equalsIgnoreCase("i")) {
			end(mSpannableStringBuilder, Italic.class, new StyleSpan(
					Typeface.ITALIC));
		} else if (tag.equalsIgnoreCase("big")) {
			end(mSpannableStringBuilder, Big.class, new RelativeSizeSpan(
					1.25f));
		} else if (tag.equalsIgnoreCase("small")) {
			end(mSpannableStringBuilder, Small.class, new RelativeSizeSpan(
					0.8f));
		} else if (tag.equalsIgnoreCase("font")) {
			endFont(mSpannableStringBuilder);
		} else if (tag.equalsIgnoreCase("blockquote")) {
			handleP(mSpannableStringBuilder);
			end(mSpannableStringBuilder, Blockquote.class, new QuoteSpan());
		} else if (tag.equalsIgnoreCase("tt")) {
			end(mSpannableStringBuilder, Monospace.class, new TypefaceSpan(
					"monospace"));
		} else if (tag.equalsIgnoreCase("a")) {
			endA(mSpannableStringBuilder);
		} else if (tag.equalsIgnoreCase("u")) {
			end(mSpannableStringBuilder, Underline.class,
					new WPUnderlineSpan());
		} else if (tag.equalsIgnoreCase("sup")) {
			end(mSpannableStringBuilder, Super.class, new SuperscriptSpan());
		} else if (tag.equalsIgnoreCase("sub")) {
			end(mSpannableStringBuilder, Sub.class, new SubscriptSpan());
		} else if (tag.equalsIgnoreCase("strike")) {
			end(mSpannableStringBuilder, Strike.class,
					new StrikethroughSpan());
		} else if (tag.length() == 2
				&& Character.toLowerCase(tag.charAt(0)) == 'h'
				&& tag.charAt(1) >= '1' && tag.charAt(1) <= '6') {
			handleP(mSpannableStringBuilder);
			endHeader(mSpannableStringBuilder);
		}
	} else {

		if (tag.equalsIgnoreCase("html") || tag.equalsIgnoreCase("body")) {
			return;
		}

		if (mysteryTagName.equals(tag)) {
			mysteryTagFound = false;
			mSpannableStringBuilder.append(mysteryTagContent);
		}
		// mTagHandler.handleTag(false, tag, mSpannableStringBuilder,
		// mReader,
		// mysteryTagContent);
	}
}
 
Example 43
Project: silent-contacts-android   File: HtmlUtils.java   Source Code and License 4 votes vote down vote up
/**
 * Replaces some spans with custom versions of those. Any extra new line characters at the end
 * of the text will be trimmed.
 */
@VisibleForTesting
static Spanned postprocess(Context context, Spanned original) {
    if (original == null) {
        return null;
    }
    final int length = original.length();
    if (length == 0) {
        return original; // Bail early.
    }

    // If it's a SpannableStringBuilder, just use it.  Otherwise, create a new
    // SpannableStringBuilder based on the passed Spanned.
    final SpannableStringBuilder builder;
    if (original instanceof SpannableStringBuilder) {
        builder = (SpannableStringBuilder) original;
    } else {
        builder = new SpannableStringBuilder(original);
    }

    final QuoteSpan[] quoteSpans = builder.getSpans(0, length, QuoteSpan.class);
    if (quoteSpans != null && quoteSpans.length != 0) {
        Resources resources = context.getResources();
        int color = resources.getColor(R.color.stream_item_stripe_color);
        int width = resources.getDimensionPixelSize(R.dimen.stream_item_stripe_width);
        for (int i = 0; i < quoteSpans.length; i++) {
            replaceSpan(builder, quoteSpans[i], new StreamItemQuoteSpan(color, width));
        }
    }

    final ImageSpan[] imageSpans = builder.getSpans(0, length, ImageSpan.class);
    if (imageSpans != null) {
        for (int i = 0; i < imageSpans.length; i++) {
            ImageSpan span = imageSpans[i];
            replaceSpan(builder, span, new ImageSpan(span.getDrawable(),
                    ImageSpan.ALIGN_BASELINE));
        }
    }

    // Trim the trailing new line characters at the end of the text (which can be added
    // when HTML block quote tags are turned into new line characters).
    int end = length;
    for (int i = builder.length() - 1; i >= 0; i--) {
        if (builder.charAt(i) != '\n') {
            break;
        }
        end = i;
    }

    // If there's no trailing newlines, just return it.
    if (end == length) {
        return builder;
    }

    // Otherwise, Return a substring of the original {@link Spanned} text
    // from the start index (inclusive) to the end index (exclusive).
    return new SpannableStringBuilder(builder, 0, end);
}
 
Example 44
Project: snippety   File: Snippety.java   Source Code and License 2 votes vote down vote up
/**
 * quote for text
 *
 * @param color of quote line
 * @return Snippety
 */
public Snippety quote(int color) {
    spans.add(new QuoteSpan(color));
    return this;
}
 
Example 45
Project: AndroidSpan   File: AndroidSpan.java   Source Code and License 2 votes vote down vote up
/**
 * 左侧添加一条表示引用的竖线
 *
 * @param text
 * @param color
 * @return
 */
public AndroidSpan drawQuoteSpan(String text, int color) {
    QuoteSpan span = new QuoteSpan(color);
    drawSpan(text, span);
    return this;
}