android.text.style.SubscriptSpan Java Examples

The following examples show how to use android.text.style.SubscriptSpan. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ConverterSpannedToHtml.java    From memoir with Apache License 2.0 6 votes vote down vote up
private void handleEndTag(CharacterStyle style) {
    if (style instanceof URLSpan) {
        mOut.append("</a>");
    } else if (style instanceof TypefaceSpan) {
        mOut.append("</font>");
    } else if (style instanceof ForegroundColorSpan) {
        mOut.append("</font>");
    } else if (style instanceof BackgroundColorSpan) {
        mOut.append("</font>");
    } else if (style instanceof AbsoluteSizeSpan) {
        mOut.append("</font>");
    } else if (style instanceof StrikethroughSpan) {
        mOut.append("</strike>");
    } else if (style instanceof SubscriptSpan) {
        mOut.append("</sub>");
    } else if (style instanceof SuperscriptSpan) {
        mOut.append("</sup>");
    } else if (style instanceof UnderlineSpan) {
        mOut.append("</u>");
    } else if (style instanceof BoldSpan) {
        mOut.append("</b>");
    } else if (style instanceof ItalicSpan) {
        mOut.append("</i>");
    }
}
 
Example #2
Source File: ConverterSpannedToHtml.java    From memoir with Apache License 2.0 6 votes vote down vote up
private void handleEndTag(CharacterStyle style) {
    if (style instanceof URLSpan) {
        mOut.append("</a>");
    } else if (style instanceof TypefaceSpan) {
        mOut.append("</font>");
    } else if (style instanceof ForegroundColorSpan) {
        mOut.append("</font>");
    } else if (style instanceof BackgroundColorSpan) {
        mOut.append("</font>");
    } else if (style instanceof AbsoluteSizeSpan) {
        mOut.append("</font>");
    } else if (style instanceof StrikethroughSpan) {
        mOut.append("</strike>");
    } else if (style instanceof SubscriptSpan) {
        mOut.append("</sub>");
    } else if (style instanceof SuperscriptSpan) {
        mOut.append("</sup>");
    } else if (style instanceof UnderlineSpan) {
        mOut.append("</u>");
    } else if (style instanceof BoldSpan) {
        mOut.append("</b>");
    } else if (style instanceof ItalicSpan) {
        mOut.append("</i>");
    }
}
 
Example #3
Source File: ConverterSpannedToHtml.java    From Android-RTEditor with Apache License 2.0 6 votes vote down vote up
private void handleEndTag(CharacterStyle style) {
    if (style instanceof URLSpan) {
        mOut.append("</a>");
    } else if (style instanceof TypefaceSpan) {
        mOut.append("</font>");
    } else if (style instanceof ForegroundColorSpan) {
        mOut.append("</font>");
    } else if (style instanceof BackgroundColorSpan) {
        mOut.append("</font>");
    } else if (style instanceof AbsoluteSizeSpan) {
        mOut.append("</font>");
    } else if (style instanceof StrikethroughSpan) {
        mOut.append("</strike>");
    } else if (style instanceof SubscriptSpan) {
        mOut.append("</sub>");
    } else if (style instanceof SuperscriptSpan) {
        mOut.append("</sup>");
    } else if (style instanceof UnderlineSpan) {
        mOut.append("</u>");
    } else if (style instanceof BoldSpan) {
        mOut.append("</b>");
    } else if (style instanceof ItalicSpan) {
        mOut.append("</i>");
    }
}
 
Example #4
Source File: EditView.java    From nono-android with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onSpanClick(SpanButton v) {
    View view=richEdit.findFocus();
    BaseRichEditText editText;
    if(view instanceof BaseRichEditText){
        editText=(BaseRichEditText)view;
    }else {
        return;
    }
    TypedValue typedValue = new TypedValue();
    getContext().getTheme().resolveAttribute(R.attr.colorAccent, typedValue, true);
    int color=typedValue.data;
    switch (v.getSpan()){
        case SpanButton.SPAN_BOLD:editText.toggleBold();if(editText.isBold()){editText.applyStyleSpan(Typeface.BOLD);v.setColor(color);}else {editText.removeSelectionSpan(Typeface.BOLD);v.setColor(0xff757575);}break;
        case SpanButton.SPAN_ITALIC:editText.toggleItalic();if(editText.isItalic()){editText.applyStyleSpan(Typeface.ITALIC);v.setColor(color);}else {editText.removeSelectionSpan(Typeface.ITALIC);v.setColor(0xff757575);}break;
        case SpanButton.SPAN_STRIKETHROUGH:editText.toggleStrikethrough();if(editText.isStrikethrough()){editText.applySelectionSpan(StrikethroughSpan.class);v.setColor(color);}else {editText.removeSelectionSpan(StrikethroughSpan.class);v.setColor(0xff757575);}break;
        case SpanButton.SPAN_UNDERLINE:editText.toggleUnderLine();if(editText.isUnderLine()){editText.applySelectionSpan(UnderlineSpan.class);v.setColor(color);}else {editText.removeSelectionSpan(UnderlineSpan.class);v.setColor(0xff757575);}break;
        case SpanButton.SPAN_FOREGROUND:editText.toggleForegroundColor();if(editText.isForegroundColor()){editText.applyColorSpan(ForegroundColorSpan.class,v.getGroundColor());v.setColor(v.getGroundColor());}else {editText.removeSelectionSpan(ForegroundColorSpan.class);v.setColor(0xff757575);}break;
        case SpanButton.SPAN_BACKGROUND:editText.toggleBackgroundColor();if(editText.isBackgroundColor()){editText.applyColorSpan(BackgroundColorSpan.class,v.getGroundColor());v.setColor(v.getGroundColor());}else {editText.removeSelectionSpan(BackgroundColorSpan.class);v.setColor(0xff757575);}break;
        case SpanButton.SPAN_SUBSCRIPT:editText.toggleSubscript();if(editText.isSubscript()){editText.applyScriptSpan(SubscriptSpan.class);v.setColor(color);}else {editText.removeSelectionSpan(SubscriptSpan.class);v.setColor(0xff757575);}break;
        case SpanButton.SPAN_SUPERSCRIPT:editText.toggleSuperscript();if(editText.isSuperscript()){editText.applyScriptSpan(SuperscriptSpan.class);v.setColor(color);}else {editText.removeSelectionSpan(SuperscriptSpan.class);v.setColor(0xff757575);}break;
        case SpanButton.SPAN_TODO:richEdit.addTodoLayout((BaseContainer) richEdit.findFocus().getParent().getParent());break;
        case SpanButton.SPAN_DOT:richEdit.addDotLayout((BaseContainer) richEdit.findFocus().getParent().getParent());break;
        case SpanButton.SPAN_NUMERIC:richEdit.addNumericLayout((BaseContainer) richEdit.findFocus().getParent().getParent());break;
        case SpanButton.SPAN_PHOTO:richEdit.addPhotoLayout((BaseContainer) richEdit.findFocus().getParent().getParent());break;
        //case SpanButton.SPAN_TEXTSIZE:editText.changeSize();editText.applyRelativeSpan();break;
        //case SpanButton.SPAN_BOLD:editText.toggleBold();if(editText.isBold()){editText.applyStyleSpan(Typeface.BOLD);v.setColor(color);}else {editText.removeSelectionSpan(Typeface.BOLD);v.setColor(0xff757575);}break;
    }
}
 
Example #5
Source File: SpanUtils.java    From styT with Apache License 2.0 5 votes vote down vote up
public static SpannableString getSubscriptSpan() {
    SpannableString spannableString = new SpannableString("水分子化学式为H20");
    SubscriptSpan subscriptSpan = new SubscriptSpan();
    RelativeSizeSpan sizeSpan = new RelativeSizeSpan(0.7f);
    spannableString.setSpan(subscriptSpan, 8, 9, Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
    spannableString.setSpan(sizeSpan, 8, 9, Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
    return spannableString;
}
 
Example #6
Source File: MyHtmlTagHandler.java    From nono-android with GNU General Public License v3.0 5 votes vote down vote up
private void processSub( boolean opening, Editable output) {

        int len = output.length();
        if(opening) {
            //output.setSpan(new RelativeSizeSpan(0.5f), len, len, Spannable.SPAN_MARK_MARK);
            output.setSpan(new SubscriptSpan(), len, len, Spannable.SPAN_MARK_MARK);
            //output.setSpan(new AbsoluteSizeSpan(scriptSize,false), len, len, Spannable.SPAN_MARK_MARK);
        } else {
            Object obj = getLast(output, SubscriptSpan.class);
            int where = output.getSpanStart(obj);
            output.removeSpan(obj);
            //obj = getLast(output, RelativeSizeSpan.class);
            //output.removeSpan(obj);
            if (where != len&&where>=0) {
                //output.setSpan(new AbsoluteSizeSpan(scriptSize, false), where, len, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
                output.setSpan(new RelativeSizeSpan(0.7f), where, len, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
                output.setSpan(new SubscriptSpan(), where, len, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
            }
           // obj = getLast(output, AbsoluteSizeSpan.class);
           // where = output.getSpanStart(obj);
           // output.removeSpan(obj);
           // if (where != len) {
           //     output.setSpan(new AbsoluteSizeSpan(scriptSize, false), where, len, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
           //     //output.setSpan(new RelativeSizeSpan(0.5f), where, len, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
           // }
        }
    }
 
Example #7
Source File: SpanEZTest.java    From SpanEZ with Apache License 2.0 5 votes vote down vote up
@Test
public void subscript_should_add_only_one_span() {
    spanBuilder.style(range, EZ.SUBSCRIPT)
               .apply();

    verify((SpanEZ) spanBuilder, times(1))
            .addSpan(isA(TargetRange.class), isA(SubscriptSpan.class));
}
 
Example #8
Source File: Trestle.java    From Trestle with Apache License 2.0 5 votes vote down vote up
private static void setUpSubscriptSpan(Span span, SpannableString ss, int start, int end) {
    if (span.isSubscript()) {
        ss.setSpan(
                new SubscriptSpan(),
                start,
                end,
                Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
    }
}
 
Example #9
Source File: Spans.java    From spanner with Apache License 2.0 5 votes vote down vote up
/**
 * @see SubscriptSpan#SubscriptSpan()
 */
public static Span subscript() {
    return new Span(new SpanBuilder() {
        @Override
        public Object build() {
            return new SubscriptSpan();
        }
    });
}
 
Example #10
Source File: TextDecorator.java    From text-decorator with Apache License 2.0 5 votes vote down vote up
public TextDecorator setSubscript(final String... texts) {
  int index;

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

  return this;
}
 
Example #11
Source File: BabushkaText.java    From RxAndroidBootstrap with Apache License 2.0 4 votes vote down vote up
private void applySpannablesTo(Piece aPiece, SpannableString finalString, int start, int end) {

        if(aPiece.subscript) {
            finalString.setSpan(new SubscriptSpan(), start, end,
                    Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        }

        if(aPiece.superscript) {
            finalString.setSpan(new SuperscriptSpan(), start, end,
                    Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        }

        if(aPiece.strike) {
            finalString.setSpan(new StrikethroughSpan(), start, end,
                    Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        }

        if(aPiece.underline) {
            finalString.setSpan(new UnderlineSpan(), start, end,
                    Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        }

        // style
        finalString.setSpan(new StyleSpan(aPiece.style), start, end,
                Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);

        // absolute text size
        finalString.setSpan(new AbsoluteSizeSpan(aPiece.textSize), start, end,
                Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);

        // relative text size
        finalString.setSpan(new RelativeSizeSpan(aPiece.textSizeRelative), start, end,
                Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);

        // text color
        finalString.setSpan(new ForegroundColorSpan(aPiece.textColor), start, end,
                Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);

        // background color
        if(aPiece.backgroundColor != -1) {
            finalString.setSpan(new BackgroundColorSpan(aPiece.backgroundColor), start, end,
                    Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        }
    }
 
Example #12
Source File: BaseRichEditText.java    From nono-android with GNU General Public License v3.0 4 votes vote down vote up
public void removeSpan(Object what,int start,int end) {
    int s = getEditableText().getSpanStart(what);
    int e = getEditableText().getSpanEnd(what);
    getEditableText().removeSpan(what);
    end = end > e ? e : end;
    start = start > s ? start : s;
    if (what instanceof AbsoluteSizeSpan) {
        setSpan(new AbsoluteSizeSpan(
                ((AbsoluteSizeSpan) what).getSize(), false), s, start, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        setSpan(new AbsoluteSizeSpan(
                ((AbsoluteSizeSpan) what).getSize(), false), end, e, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
    } else if (what instanceof RelativeSizeSpan) {
        setSpan(new RelativeSizeSpan(((RelativeSizeSpan) what).getSizeChange()), s, start, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        setSpan(new RelativeSizeSpan(((RelativeSizeSpan) what).getSizeChange()), end, e, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
    } else if (what instanceof StyleSpan) {
        if (((StyleSpan) what).getStyle() == Typeface.BOLD) {
            setSpan(new StyleSpan(Typeface.BOLD), s, start, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
            setSpan(new StyleSpan(Typeface.BOLD), end, e, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        } else if (((StyleSpan) what).getStyle() == Typeface.ITALIC) {
            setSpan(new StyleSpan(Typeface.ITALIC), s, start, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
            setSpan(new StyleSpan(Typeface.ITALIC), end, e, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        }
    } else if (what instanceof ForegroundColorSpan) {
        setSpan(new ForegroundColorSpan(((ForegroundColorSpan) what).getForegroundColor()), s, start, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        setSpan(new ForegroundColorSpan(((ForegroundColorSpan) what).getForegroundColor()), end, e, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
    } else if (what instanceof BackgroundColorSpan) {
        setSpan(new ForegroundColorSpan(((BackgroundColorSpan) what).getBackgroundColor()), s, start, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        setSpan(new ForegroundColorSpan(((BackgroundColorSpan) what).getBackgroundColor()), end, e, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
    } else if (what instanceof UnderlineSpan) {
        setSpan(new UnderlineSpan(), s, start, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        setSpan(new UnderlineSpan(), end, e, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
    } else if (what instanceof StrikethroughSpan) {
        setSpan(new StrikethroughSpan(), s, start, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        setSpan(new StrikethroughSpan(), end, e, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
    } else if (what instanceof SubscriptSpan) {
        setSpan(new SubscriptSpan(), s, start, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        setSpan(new SubscriptSpan(), end, e, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
    } else if (what instanceof SuperscriptSpan) {
        setSpan(new SuperscriptSpan(), s, start, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        setSpan(new SuperscriptSpan(), end, e, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
    }
}
 
Example #13
Source File: BaseRichEditText.java    From nono-android with GNU General Public License v3.0 4 votes vote down vote up
@Override
protected void onSelectionChanged(int selStart, int selEnd) {

    super.onSelectionChanged(selStart, selEnd);
    selStart=selStart<0?0:selStart;
    selEnd=selEnd<0?0:selEnd;
    if(selStart>selEnd) {
        int temp = selEnd;
        selEnd = selStart;
        selStart = temp;
    }
    if(length()==0){
        return;
    }
    isUnderLine = getSelectionSpan(UnderlineSpan.class,selStart,selEnd);
    isStrikethrough = getSelectionSpan(StrikethroughSpan.class,selStart,selEnd);
    isBold = getSelectionSpan(Typeface.BOLD,selStart,selEnd);
    isItalic = getSelectionSpan(Typeface.ITALIC,selStart,selEnd);
    isSubscript = getSelectionSpan(SubscriptSpan.class,selStart,selEnd);
    isSuperscript = getSelectionSpan(SuperscriptSpan.class,selStart,selEnd);
    isForegroundColor = getSelectionSpan(ForegroundColorSpan.class,selStart,selEnd);
    isBackgroundColor=getSelectionSpan(BackgroundColorSpan.class,selStart,selEnd);
    sizeFlag=MEDIUM_TEXT;
    RelativeSizeSpan[] spans;
    if(selStart==selEnd){
        if(selStart>1){
            selStart=selStart-1;
            spans= getEditableText().getSpans(selStart, selStart+1, RelativeSizeSpan.class);
        }else {
            spans = getEditableText().getSpans(selStart, selStart, RelativeSizeSpan.class);
        }
    }else {
        spans= getEditableText().getSpans(selStart, selStart+1, RelativeSizeSpan.class);
    }
    if(spans.length>0){
        float size=spans[0].getSizeChange();
        if(size==textMultiple[SMALL_TEXT]){
            sizeFlag=SMALL_TEXT;
        }else if(size==textMultiple[LARGE_TEXT]){
            sizeFlag=LARGE_TEXT;
        }else {
            sizeFlag=MEDIUM_TEXT;
        }
    }
    if(selectionSpanCallback!=null) {
        selectionSpanCallback.callback(
                isUnderLine,
                isStrikethrough,
                isBold,
                isItalic,
                isSubscript,
                isSuperscript,
                isForegroundColor,
                colorFontForeground,
                isBackgroundColor,
                colorFontBackground,
                sizeFlag);
    }
}
 
Example #14
Source File: Html.java    From Nimingban with Apache License 2.0 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 #15
Source File: BabushkaText.java    From MVPAndroidBootstrap with Apache License 2.0 4 votes vote down vote up
private void applySpannablesTo(Piece aPiece, SpannableString finalString, int start, int end) {

        if(aPiece.subscript) {
            finalString.setSpan(new SubscriptSpan(), start, end,
                    Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        }

        if(aPiece.superscript) {
            finalString.setSpan(new SuperscriptSpan(), start, end,
                    Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        }

        if(aPiece.strike) {
            finalString.setSpan(new StrikethroughSpan(), start, end,
                    Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        }

        if(aPiece.underline) {
            finalString.setSpan(new UnderlineSpan(), start, end,
                    Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        }

        // style
        finalString.setSpan(new StyleSpan(aPiece.style), start, end,
                Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);

        // absolute text size
        finalString.setSpan(new AbsoluteSizeSpan(aPiece.textSize), start, end,
                Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);

        // relative text size
        finalString.setSpan(new RelativeSizeSpan(aPiece.textSizeRelative), start, end,
                Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);

        // text color
        finalString.setSpan(new ForegroundColorSpan(aPiece.textColor), start, end,
                Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);

        // background color
        if(aPiece.backgroundColor != -1) {
            finalString.setSpan(new BackgroundColorSpan(aPiece.backgroundColor), start, end,
                    Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        }
    }
 
Example #16
Source File: CustomHtmlToSpannedConverter.java    From zulip-android with Apache License 2.0 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 CustomQuoteSpan());
    } else if (tag.equalsIgnoreCase("tt")) {
        end(mSpannableStringBuilder, Monospace.class, new TypefaceSpan(
                MONOSPACE));
    } else if (tag.equalsIgnoreCase("a")) {
        if (isStreamLink) {
            endStreamA(mSpannableStringBuilder);
            isStreamLink = true;
        } else {
            endA(mSpannableStringBuilder);
        }
    } else if (tag.equalsIgnoreCase("span")) {
        endSpan(mSpannableStringBuilder);
        isEmoji = false;
    } 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.equalsIgnoreCase("code")) {
        endMultiple(mSpannableStringBuilder, InlineCode.class,
                new Object[]{new TypefaceSpan(MONOSPACE),
                        new ForegroundColorSpan(0xffdd1144),
                        new BackgroundColorSpan(0xfff7f7f9)
                });
        isCode = false;
    } else if (tag.equalsIgnoreCase("pre")) {
        endMultiple(mSpannableStringBuilder, CodeBlock.class, new Object[]{
                new TypefaceSpan(MONOSPACE),
                new ForegroundColorSpan(0xff000000),
                new CodeBlockLine(0xfff5f5f5)
        });
        isCode = false;
    } else if (tag.equalsIgnoreCase("del")) {
        end(mSpannableStringBuilder, StrikeThrough.class, new StrikethroughSpan());
    } else if (tag.equalsIgnoreCase("s")) {
        end(mSpannableStringBuilder, StrikeThrough.class, new StrikethroughSpan());
    } else if (tag.equalsIgnoreCase("strike")) {
        end(mSpannableStringBuilder, StrikeThrough.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 (mTagHandler != null) {
        mTagHandler.handleTag(false, tag, mSpannableStringBuilder, mReader);
    }
}
 
Example #17
Source File: SpannableActivity.java    From AndroidSamples with Apache License 2.0 4 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_spannable);
    ButterKnife.bind(this);

    SpannableString spannableString = new SpannableString("前景色背景色相对大小删除线下划线" +
            "上标小上标下标粗体斜体显示图片点击超链接");

    ForegroundColorSpan foregroundColorSpan = new ForegroundColorSpan(Color.parseColor("#0099EE"));
    BackgroundColorSpan backgroundColorSpan = new BackgroundColorSpan(Color.parseColor("#AC00FF30"));
    RelativeSizeSpan relativeSizeSpan = new RelativeSizeSpan(2f);
    StrikethroughSpan strikethroughSpan = new StrikethroughSpan();
    UnderlineSpan underlineSpan = new UnderlineSpan();
    SuperscriptSpan superscriptSpan = new SuperscriptSpan();
    RelativeSizeSpan relativeSizeSpan2 = new RelativeSizeSpan(0.5f);
    SubscriptSpan subscriptSpan = new SubscriptSpan();
    StyleSpan styleSpan_B = new StyleSpan(Typeface.BOLD);
    StyleSpan styleSpan_I = new StyleSpan(Typeface.ITALIC);

    ImageSpan imageSpan = new ImageSpan(this, R.mipmap.ic_launcher);
    ClickableSpan clickableSpan = new ClickableSpan() {
        @Override
        public void onClick(View widget) {
            Toast.makeText(SpannableActivity.this, "点击", Toast.LENGTH_SHORT).show();
        }

        @Override
        public void updateDrawState(TextPaint ds) {
            // 文字不变色
            ds.setUnderlineText(false);
        }
    };
    URLSpan urlSpan = new URLSpan("http://www.sdwfqin.com");

    spannableString.setSpan(foregroundColorSpan, 0, 3, Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
    spannableString.setSpan(backgroundColorSpan, 3, 6, Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
    spannableString.setSpan(relativeSizeSpan, 6, 10, Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
    spannableString.setSpan(strikethroughSpan, 10, 13, Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
    spannableString.setSpan(underlineSpan, 13, 16, Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
    spannableString.setSpan(superscriptSpan, 16, 21, Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
    spannableString.setSpan(relativeSizeSpan2, 18, 21, Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
    spannableString.setSpan(subscriptSpan, 21, 23, Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
    spannableString.setSpan(styleSpan_B, 23, 25, Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
    spannableString.setSpan(styleSpan_I, 25, 27, Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
    spannableString.setSpan(imageSpan, 29, 31, Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
    spannableString.setSpan(clickableSpan, 31, 33, Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
    spannableString.setSpan(urlSpan, 33, 36, Spanned.SPAN_INCLUSIVE_EXCLUSIVE);

    spanString.setMovementMethod(LinkMovementMethod.getInstance());
    // 点击背景色
    // spanString.setHighlightColor(Color.parseColor("#36969696"));
    // 可以点击
    spanString.setText(spannableString);

    SpannableStringBuilder builder = new SpannableStringBuilder("哈哈哈");
    builder.setSpan(foregroundColorSpan, 0, 3, Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
    builder.append("lalala");
    // 注意:如果使用toString()方法设置的样式就没有了
    spanBuilder.setText(builder);
}
 
Example #18
Source File: HtmlParser.java    From Overchan-Android with GNU General Public License v3.0 4 votes vote down vote up
private void handleEndTag(String tag) {
    if (tag.equalsIgnoreCase("br")) {
        handleBr(mSpannableStringBuilder);
    } else if (tag.equalsIgnoreCase("p")) {
        handleP(mSpannableStringBuilder, mStartLength, mLastPTagLength);
    } else if (tag.equalsIgnoreCase("div")) {
        handleP(mSpannableStringBuilder, mStartLength, mLastPTagLength);
    } 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("s")) {
        end(mSpannableStringBuilder, Strike.class, new StrikethroughSpan());
    } else if (tag.equalsIgnoreCase("strike")) {
        end(mSpannableStringBuilder, Strike.class, new StrikethroughSpan());
    } else if (tag.equalsIgnoreCase("del")) {
        end(mSpannableStringBuilder, Strike.class, new StrikethroughSpan());    
    } 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, mStartLength, mLastPTagLength);
        endBlockquote(mSpannableStringBuilder, mColors);
    } else if (tag.equalsIgnoreCase("tt")) {
        end(mSpannableStringBuilder, Monospace.class, new TypefaceSpan("monospace"));
    } else if (tag.equalsIgnoreCase("code")) {
        end(mSpannableStringBuilder, Monospace.class, new TypefaceSpan("monospace"));
    } else if (tag.equalsIgnoreCase("ul")) {
        if (!mListTags.isEmpty()) mListTags.removeFirst();
    } else if (tag.equalsIgnoreCase("ol")) {
        if (!mListTags.isEmpty()) mListTags.removeFirst();
    } else if (tag.equalsIgnoreCase("li")) {
        //обрабатывается только открывающийся <li>
    } else if (tag.equalsIgnoreCase("tr")) {
        handleTr(mSpannableStringBuilder, false);
    } else if (tag.equalsIgnoreCase("td")) {
        handleTd(mSpannableStringBuilder, false);
    } 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, mStartLength, mLastPTagLength);
        endHeader(mSpannableStringBuilder);
    } else if (tag.equalsIgnoreCase("span")) {
        endSpan(mSpannableStringBuilder, mColors, mOpenSpoilers);
    } else if (tag.equalsIgnoreCase("aibquote")) {
        end(mSpannableStringBuilder, Aibquote.class, new ForegroundColorSpan(mColors != null ? mColors.quoteForeground : Color.GREEN));
    } else if (tag.equalsIgnoreCase("aibspoiler")) {
        endAibspoiler(mSpannableStringBuilder, mColors, mOpenSpoilers);
    }/* else if (mTagHandler != null) {
        mTagHandler.handleTag(false, tag, mSpannableStringBuilder, mReader);
    }*/
}
 
Example #19
Source File: SpanOptions.java    From AndroidSpan with Apache License 2.0 4 votes vote down vote up
public SpanOptions addSubscriptSpan() {
    SubscriptSpan span = new SubscriptSpan();
    listSpan.add(span);
    return this;
}
 
Example #20
Source File: NotificationPresets.java    From AndroidWearable-Samples with Apache License 2.0 4 votes vote down vote up
@Override
public Notification buildNotification(Context context) {
    Notification.Builder builder = buildBasicNotification(context);

    Notification.BigTextStyle style = new Notification.BigTextStyle();

    SpannableStringBuilder title = new SpannableStringBuilder();
    appendStyled(title, "Stylized", new StyleSpan(Typeface.BOLD_ITALIC));
    title.append(" title");
    SpannableStringBuilder text = new SpannableStringBuilder("Stylized text: ");
    appendStyled(text, "C", new ForegroundColorSpan(Color.RED));
    appendStyled(text, "O", new ForegroundColorSpan(Color.GREEN));
    appendStyled(text, "L", new ForegroundColorSpan(Color.BLUE));
    appendStyled(text, "O", new ForegroundColorSpan(Color.YELLOW));
    appendStyled(text, "R", new ForegroundColorSpan(Color.MAGENTA));
    appendStyled(text, "S", new ForegroundColorSpan(Color.CYAN));
    text.append("; ");
    appendStyled(text, "1.25x size", new RelativeSizeSpan(1.25f));
    text.append("; ");
    appendStyled(text, "0.75x size", new RelativeSizeSpan(0.75f));
    text.append("; ");
    appendStyled(text, "underline", new UnderlineSpan());
    text.append("; ");
    appendStyled(text, "strikethrough", new StrikethroughSpan());
    text.append("; ");
    appendStyled(text, "bold", new StyleSpan(Typeface.BOLD));
    text.append("; ");
    appendStyled(text, "italic", new StyleSpan(Typeface.ITALIC));
    text.append("; ");
    appendStyled(text, "sans-serif-thin", new TypefaceSpan("sans-serif-thin"));
    text.append("; ");
    appendStyled(text, "monospace", new TypefaceSpan("monospace"));
    text.append("; ");
    appendStyled(text, "sub", new SubscriptSpan());
    text.append("script");
    appendStyled(text, "super", new SuperscriptSpan());

    style.setBigContentTitle(title);
    style.bigText(text);

    builder.setStyle(style);
    return builder.build();
}
 
Example #21
Source File: NotificationPresets.java    From AndroidWearable-Samples with Apache License 2.0 4 votes vote down vote up
@Override
public Notification[] buildNotifications(Context context, BuildOptions options) {
    NotificationCompat.BigTextStyle style = new NotificationCompat.BigTextStyle();

    SpannableStringBuilder title = new SpannableStringBuilder();
    appendStyled(title, "Stylized", new StyleSpan(Typeface.BOLD_ITALIC));
    title.append(" title");
    SpannableStringBuilder text = new SpannableStringBuilder("Stylized text: ");
    appendStyled(text, "C", new ForegroundColorSpan(Color.RED));
    appendStyled(text, "O", new ForegroundColorSpan(Color.GREEN));
    appendStyled(text, "L", new ForegroundColorSpan(Color.BLUE));
    appendStyled(text, "O", new ForegroundColorSpan(Color.YELLOW));
    appendStyled(text, "R", new ForegroundColorSpan(Color.MAGENTA));
    appendStyled(text, "S", new ForegroundColorSpan(Color.CYAN));
    text.append("; ");
    appendStyled(text, "1.25x size", new RelativeSizeSpan(1.25f));
    text.append("; ");
    appendStyled(text, "0.75x size", new RelativeSizeSpan(0.75f));
    text.append("; ");
    appendStyled(text, "underline", new UnderlineSpan());
    text.append("; ");
    appendStyled(text, "strikethrough", new StrikethroughSpan());
    text.append("; ");
    appendStyled(text, "bold", new StyleSpan(Typeface.BOLD));
    text.append("; ");
    appendStyled(text, "italic", new StyleSpan(Typeface.ITALIC));
    text.append("; ");
    appendStyled(text, "sans-serif-thin", new TypefaceSpan("sans-serif-thin"));
    text.append("; ");
    appendStyled(text, "monospace", new TypefaceSpan("monospace"));
    text.append("; ");
    appendStyled(text, "sub", new SubscriptSpan());
    text.append("script");
    appendStyled(text, "super", new SuperscriptSpan());

    style.setBigContentTitle(title);
    style.bigText(text);

    NotificationCompat.Builder builder = new NotificationCompat.Builder(context)
            .setStyle(style);
    NotificationCompat.WearableExtender wearableOptions =
            new NotificationCompat.WearableExtender();
    applyBasicOptions(context, builder, wearableOptions, options);
    builder.extend(wearableOptions);
    return new Notification[] { builder.build() };
}
 
Example #22
Source File: Html.java    From EhViewer with Apache License 2.0 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 #23
Source File: BabushkaText.java    From BabushkaText with Apache License 2.0 4 votes vote down vote up
private void applySpannablesTo(Piece aPiece, SpannableString finalString, int start, int end) {

        if(aPiece.subscript) {
            finalString.setSpan(new SubscriptSpan(), start, end,
                    Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        }

        if(aPiece.superscript) {
            finalString.setSpan(new SuperscriptSpan(), start, end,
                    Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        }

        if(aPiece.strike) {
            finalString.setSpan(new StrikethroughSpan(), start, end,
                    Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        }

        if(aPiece.underline) {
            finalString.setSpan(new UnderlineSpan(), start, end,
                    Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        }

        // style
        finalString.setSpan(new StyleSpan(aPiece.style), start, end,
                Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);

        // absolute text size
        finalString.setSpan(new AbsoluteSizeSpan(aPiece.textSize), start, end,
                Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);

        // relative text size
        finalString.setSpan(new RelativeSizeSpan(aPiece.textSizeRelative), start, end,
                Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);

        // text color
        finalString.setSpan(new ForegroundColorSpan(aPiece.textColor), start, end,
                Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);

        // background color
        if(aPiece.backgroundColor != -1) {
            finalString.setSpan(new BackgroundColorSpan(aPiece.backgroundColor), start, end,
                    Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        }
    }
 
Example #24
Source File: AKHtml.java    From Mupdf with Apache License 2.0 4 votes vote down vote up
private void handleEndTag(String tag) {
    if (tag.equalsIgnoreCase("br")) {
        handleBr(mSpannableStringBuilder);
    } else if (tag.equalsIgnoreCase("p")) {
        endCssStyle(mSpannableStringBuilder);
        endBlockElement(mSpannableStringBuilder);
    } else if (tag.equalsIgnoreCase("ul")) {
        endBlockElement(mSpannableStringBuilder);
    } else if (tag.equalsIgnoreCase("li")) {
        endLi(mSpannableStringBuilder);
    } else if (tag.equalsIgnoreCase("div")) {
        endBlockElement(mSpannableStringBuilder);
    } else if (tag.equalsIgnoreCase("span")) {
        endCssStyle(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")) {
        endBlockquote(mSpannableStringBuilder);
    } 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("del")) {
        end(mSpannableStringBuilder, Strikethrough.class, new StrikethroughSpan());
    } else if (tag.equalsIgnoreCase("s")) {
        end(mSpannableStringBuilder, Strikethrough.class, new StrikethroughSpan());
    } else if (tag.equalsIgnoreCase("strike")) {
        end(mSpannableStringBuilder, Strikethrough.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') {
        endHeading(mSpannableStringBuilder);
    } else if (mTagHandler != null) {
        mTagHandler.handleTag(false, tag, mSpannableStringBuilder, mReader);
    }
}
 
Example #25
Source File: SubScriptHandler.java    From mvvm-template with GNU General Public License v3.0 4 votes vote down vote up
@Override public void handleTagNode(TagNode node, SpannableStringBuilder builder, int start, int end) {
    builder.setSpan(new SubscriptSpan(), start, end, 33);
    builder.setSpan(new RelativeSizeSpan(0.8f), start, end, 33);
}
 
Example #26
Source File: Html.java    From MHViewer with Apache License 2.0 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 #27
Source File: Html.java    From tysq-android with GNU General Public License v3.0 4 votes vote down vote up
private void handleEndTag(String tag) {
        if (tag.equalsIgnoreCase("br")) {
            handleBr(mSpannableStringBuilder);
        } else if (tag.equalsIgnoreCase("p")) {
            endCssStyle(mSpannableStringBuilder);
            endBlockElement(mSpannableStringBuilder);
        } else if (tag.equalsIgnoreCase("ul")) {
            endBlockElement(mSpannableStringBuilder);
        } else if (tag.equalsIgnoreCase("li")) {
            endLi(mSpannableStringBuilder);
        } else if (tag.equalsIgnoreCase("div")) {
            endBlockElement(mSpannableStringBuilder);
        } else if (tag.equalsIgnoreCase("span")) {
            endCssStyle(mSpannableStringBuilder);
        } else if (tag.equalsIgnoreCase("strong")) {
//            end(mSpannableStringBuilder, Bold.class, new StyleSpan(Typeface.BOLD));
            end(mSpannableStringBuilder, Bold.class, new JerryBoldSpan());
        } else if (tag.equalsIgnoreCase("b")) {
            end(mSpannableStringBuilder, Bold.class, new JerryBoldSpan());
        } else if (tag.equalsIgnoreCase("em")) {
            end(mSpannableStringBuilder, Italic.class, new JerryItalicSpan());
        } else if (tag.equalsIgnoreCase("cite")) {
            end(mSpannableStringBuilder, Italic.class, new JerryItalicSpan());
        } else if (tag.equalsIgnoreCase("dfn")) {
            end(mSpannableStringBuilder, Italic.class, new JerryItalicSpan());
        } else if (tag.equalsIgnoreCase("i")) {
            end(mSpannableStringBuilder, Italic.class, new JerryItalicSpan());
        } 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")) {
            endBlockquote(mSpannableStringBuilder);
        } 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 JerryUnderlineSpan());
        } else if (tag.equalsIgnoreCase("del")) {
            end(mSpannableStringBuilder, Strikethrough.class, new JerryStrikeThroughSpan());
        } else if (tag.equalsIgnoreCase("s")) {
            end(mSpannableStringBuilder, Strikethrough.class, new JerryStrikeThroughSpan());
        } else if (tag.equalsIgnoreCase("strike")) {
            end(mSpannableStringBuilder, Strikethrough.class, new JerryStrikeThroughSpan());
        } 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') {
            endHeading(mSpannableStringBuilder);
        } else if (mTagHandler != null) {
            mTagHandler.handleTag(false, tag, mSpannableStringBuilder, mReader);
        }
    }
 
Example #28
Source File: SpannableStringUtils.java    From DevUtils with Apache License 2.0 4 votes vote down vote up
/**
 * 更新 CharSequence 字符
 */
private void updateCharCharSequence() {
    if (mText.length() == 0) return;
    int start = mBuilder.length();
    if (start == 0 && lineHeight != -1) { // bug of LineHeightSpan when first line
        mBuilder.append(Character.toString((char) 2)).append("\n")
                .setSpan(new AbsoluteSizeSpan(0), 0, 2, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        start = 2;
    }
    mBuilder.append(mText);
    int end = mBuilder.length();
    if (verticalAlign != -1) {
        mBuilder.setSpan(new VerticalAlignSpan(verticalAlign), start, end, flag);
    }
    if (foregroundColor != COLOR_DEFAULT) {
        mBuilder.setSpan(new ForegroundColorSpan(foregroundColor), start, end, flag);
    }
    if (backgroundColor != COLOR_DEFAULT) {
        mBuilder.setSpan(new BackgroundColorSpan(backgroundColor), start, end, flag);
    }
    if (first != -1) {
        mBuilder.setSpan(new LeadingMarginSpan.Standard(first, rest), start, end, flag);
    }
    if (quoteColor != COLOR_DEFAULT) {
        mBuilder.setSpan(new CustomQuoteSpan(quoteColor, stripeWidth, quoteGapWidth), start, end, flag);
    }
    if (bulletColor != COLOR_DEFAULT) {
        mBuilder.setSpan(new CustomBulletSpan(bulletColor, bulletRadius, bulletGapWidth), start, end, flag);
    }
    if (fontSize != -1) {
        mBuilder.setSpan(new AbsoluteSizeSpan(fontSize, fontSizeIsDp), start, end, flag);
    }
    if (proportion != -1) {
        mBuilder.setSpan(new RelativeSizeSpan(proportion), start, end, flag);
    }
    if (xProportion != -1) {
        mBuilder.setSpan(new ScaleXSpan(xProportion), start, end, flag);
    }
    if (lineHeight != -1) {
        mBuilder.setSpan(new CustomLineHeightSpan(lineHeight, alignLine), start, end, flag);
    }
    if (isStrikethrough) {
        mBuilder.setSpan(new StrikethroughSpan(), start, end, flag);
    }
    if (isUnderline) {
        mBuilder.setSpan(new UnderlineSpan(), start, end, flag);
    }
    if (isSuperscript) {
        mBuilder.setSpan(new SuperscriptSpan(), start, end, flag);
    }
    if (isSubscript) {
        mBuilder.setSpan(new SubscriptSpan(), start, end, flag);
    }
    if (isBold) {
        mBuilder.setSpan(new StyleSpan(Typeface.BOLD), start, end, flag);
    }
    if (isItalic) {
        mBuilder.setSpan(new StyleSpan(Typeface.ITALIC), start, end, flag);
    }
    if (isBoldItalic) {
        mBuilder.setSpan(new StyleSpan(Typeface.BOLD_ITALIC), start, end, flag);
    }
    if (fontFamily != null) {
        mBuilder.setSpan(new TypefaceSpan(fontFamily), start, end, flag);
    }
    if (typeface != null) {
        mBuilder.setSpan(new CustomTypefaceSpan(typeface), start, end, flag);
    }
    if (alignment != null) {
        mBuilder.setSpan(new AlignmentSpan.Standard(alignment), start, end, flag);
    }
    if (clickSpan != null) {
        mBuilder.setSpan(clickSpan, start, end, flag);
    }
    if (url != null) {
        mBuilder.setSpan(new URLSpan(url), start, end, flag);
    }
    if (blurRadius != -1) {
        mBuilder.setSpan(new MaskFilterSpan(new BlurMaskFilter(blurRadius, style)), start, end, flag);
    }
    if (shader != null) {
        mBuilder.setSpan(new ShaderSpan(shader), start, end, flag);
    }
    if (shadowRadius != -1) {
        mBuilder.setSpan(new ShadowSpan(shadowRadius, shadowDx, shadowDy, shadowColor), start, end, flag);
    }
    if (spans != null) {
        for (Object span : spans) {
            mBuilder.setSpan(span, start, end, flag);
        }
    }
}
 
Example #29
Source File: SpanUtils.java    From MvpRoute with Apache License 2.0 4 votes vote down vote up
/**
 * 为文字设置下标
 * @return
 */
public SpanUtils setSubscriptSpan(){
	SubscriptSpan subscriptSpan = new SubscriptSpan();
	span.setSpan(subscriptSpan, startIndex, endIndex, Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
	return this;
}
 
Example #30
Source File: Span.java    From Android-Spans with Apache License 2.0 4 votes vote down vote up
public static Node subscript(Object... nodes) {
    return new SpanNode(new SubscriptSpan(), nodes);
}