android.text.style.SuperscriptSpan Java Examples
The following examples show how to use
android.text.style.SuperscriptSpan.
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: HelpListView.java From materialistic with Apache License 2.0 | 6 votes |
@Override protected void onFinishInflate() { super.onFinishInflate(); ((TextView) findViewById(R.id.item_new).findViewById(R.id.rank)) .append(makeAsteriskSpan()); SpannableString spannable = new SpannableString("+5"); spannable.setSpan(new SuperscriptSpan(), 0, spannable.length(), Spanned.SPAN_INCLUSIVE_EXCLUSIVE); spannable.setSpan(new RelativeSizeSpan(0.6f), 0, spannable.length(), Spanned.SPAN_INCLUSIVE_EXCLUSIVE); spannable.setSpan(new ForegroundColorSpan( ContextCompat.getColor(getContext(), R.color.greenA700)), 0, spannable.length(), Spanned.SPAN_INCLUSIVE_EXCLUSIVE); ((TextView) findViewById(R.id.item_promoted).findViewById(R.id.rank)).append(spannable); TextView comments = (TextView) findViewById(R.id.item_new_comments).findViewById(R.id.comment); SpannableStringBuilder sb = new SpannableStringBuilder("46"); sb.append(makeAsteriskSpan()); comments.setText(sb); }
Example #2
Source File: MyHtmlTagHandler.java From nono-android with GNU General Public License v3.0 | 6 votes |
private void processSup( boolean opening, Editable output) { int len = output.length(); if(opening) { //output.setSpan(new AbsoluteSizeSpan(scriptSize,false), len, len, Spannable.SPAN_MARK_MARK); //output.setSpan(new RelativeSizeSpan(0.5f), len, len, Spannable.SPAN_MARK_MARK); output.setSpan(new SuperscriptSpan(), len, len, Spannable.SPAN_MARK_MARK); } else { Object obj = getLast(output, SuperscriptSpan.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 SuperscriptSpan(), 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 #3
Source File: ConverterSpannedToHtml.java From Android-RTEditor with Apache License 2.0 | 6 votes |
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: LocaleUtils.java From prayer-times-android with Apache License 2.0 | 6 votes |
public static CharSequence formatTimeForHTML(LocalTime localTime) { String time = formatTime(localTime); if (!Preferences.CLOCK_12H.get()) { return time; } int d = time.indexOf(" "); if (d < 0) return time; time = time.replace(" ", ""); int s = time.length(); Spannable span = new SpannableString(time); span.setSpan(new SuperscriptSpan(), d, s, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); span.setSpan(new RelativeSizeSpan(0.5f), d, s, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); return span; }
Example #5
Source File: ConverterSpannedToHtml.java From memoir with Apache License 2.0 | 6 votes |
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 #6
Source File: ConverterSpannedToHtml.java From memoir with Apache License 2.0 | 6 votes |
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 #7
Source File: LocaleUtils.java From prayer-times-android with Apache License 2.0 | 6 votes |
public static CharSequence formatTimeForHTML(LocalTime localTime) { String time = formatTime(localTime); if (!Preferences.CLOCK_12H.get()) { return time; } int d = time.indexOf(" "); if (d < 0) return time; time = time.replace(" ", ""); int s = time.length(); Spannable span = new SpannableString(time); span.setSpan(new SuperscriptSpan(), d, s, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); span.setSpan(new RelativeSizeSpan(0.5f), d, s, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); return span; }
Example #8
Source File: Transformers.java From hashtag-view with MIT License | 5 votes |
@Override public CharSequence prepare(String item) { SpannableString spannableString = new SpannableString("#" + item); spannableString.setSpan(new ForegroundColorSpan(Color.parseColor("#85F5F5F5")), 0, 1, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); spannableString.setSpan(new SuperscriptSpan(), 0, 1, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); return spannableString; }
Example #9
Source File: StoryView.java From materialistic with Apache License 2.0 | 5 votes |
public void setPromoted(int change) { SpannableString spannable = new SpannableString(String.format(Locale.US, PROMOTED, change)); spannable.setSpan(new SuperscriptSpan(), 0, spannable.length(), Spanned.SPAN_INCLUSIVE_EXCLUSIVE); spannable.setSpan(new RelativeSizeSpan(0.6f), 0, spannable.length(), Spanned.SPAN_INCLUSIVE_EXCLUSIVE); spannable.setSpan(new ForegroundColorSpan(mPromotedColorResId), 0, spannable.length(), Spanned.SPAN_INCLUSIVE_EXCLUSIVE); mRankTextView.append(spannable); }
Example #10
Source File: EditView.java From nono-android with GNU General Public License v3.0 | 5 votes |
@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 #11
Source File: Transformers.java From Loop with Apache License 2.0 | 5 votes |
@Override public CharSequence prepare(String item) { SpannableString spannableString = new SpannableString("#" + item); spannableString.setSpan(new ForegroundColorSpan(Color.parseColor("#85F5F5F5")), 0, 1, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); spannableString.setSpan(new SuperscriptSpan(), 0, 1, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); return spannableString; }
Example #12
Source File: TextDecorator.java From text-decorator with Apache License 2.0 | 5 votes |
public TextDecorator setSuperscript(final String... texts) { int index; for (String text : texts) { if (content.contains(text)) { index = content.indexOf(text); decoratedContent.setSpan(new SuperscriptSpan(), index, index + text.length(), flags); } } return this; }
Example #13
Source File: Trestle.java From Trestle with Apache License 2.0 | 5 votes |
private static void setUpSuperscriptSpan(Span span, SpannableString ss, int start, int end) { if (span.isSuperscript()) { ss.setSpan( new SuperscriptSpan(), start, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); } }
Example #14
Source File: Spans.java From spanner with Apache License 2.0 | 5 votes |
/** * @see SuperscriptSpan#SuperscriptSpan() */ public static Span superscript() { return new Span(new SpanBuilder() { @Override public Object build() { return new SuperscriptSpan(); } }); }
Example #15
Source File: StringUtils.java From arcusandroid with Apache License 2.0 | 5 votes |
public static SpannableString getSuperscriptSpan(@NonNull final String normal, @NonNull final String sup, final int superScriptColor) { SpannableStringBuilder cs = new SpannableStringBuilder(normal + sup); cs.setSpan(new SuperscriptSpan(), normal.length(), normal.length() + sup.length(), 0); cs.setSpan(new RelativeSizeSpan(0.5f), normal.length(), normal.length() + sup.length(), 0); cs.setSpan(new ForegroundColorSpan(superScriptColor), normal.length(), normal.length() + sup.length(), 0); return SpannableString.valueOf(cs); }
Example #16
Source File: StringUtils.java From arcusandroid with Apache License 2.0 | 5 votes |
/** * helper method to get prefix superscripted * @param sup string displayed on the top left * @param normal string displayed in its normal position * @return a SpannableString accepted by a textview */ public static SpannableString getPrefixSuperscriptSpan(@NonNull final String sup, @NonNull final String normal){ SpannableStringBuilder cs = new SpannableStringBuilder(sup + normal); cs.setSpan(new SuperscriptSpan(), 0, sup.length(), 0); cs.setSpan(new RelativeSizeSpan(0.5f), 0, sup.length(), 0); return SpannableString.valueOf(cs); }
Example #17
Source File: StringUtils.java From arcusandroid with Apache License 2.0 | 5 votes |
/** * helper method to get a superscripted string * @param normal string displayed in its normal position * @param sup string displayed on the top right * @return a SpannableString accepted by a textview */ public static SpannableString getSuperscriptSpan(@NonNull final String normal, @NonNull final String sup){ SpannableStringBuilder cs = new SpannableStringBuilder(normal + sup); cs.setSpan(new SuperscriptSpan(), normal.length(), normal.length() + sup.length(), 0); cs.setSpan(new RelativeSizeSpan(0.5f), normal.length(), normal.length() + sup.length(), 0); return SpannableString.valueOf(cs); }
Example #18
Source File: SpanEZTest.java From SpanEZ with Apache License 2.0 | 5 votes |
@Test public void superscript_should_add_only_one_span() { spanBuilder.style(range, EZ.SUPERSCRIPT) .apply(); verify((SpanEZ) spanBuilder, times(1)) .addSpan(isA(TargetRange.class), isA(SuperscriptSpan.class)); }
Example #19
Source File: SpanUtils.java From styT with Apache License 2.0 | 5 votes |
public static SpannableString getSuperscriptSpan() { SpannableString spannableString = new SpannableString("刚在北京望京买了套1202m的房子"); SuperscriptSpan superscriptSpan = new SuperscriptSpan(); RelativeSizeSpan sizeSpan = new RelativeSizeSpan(0.7f); spannableString.setSpan(superscriptSpan, 12, 13, Spanned.SPAN_INCLUSIVE_EXCLUSIVE); spannableString.setSpan(sizeSpan, 12, 13, Spanned.SPAN_INCLUSIVE_EXCLUSIVE); return spannableString; }
Example #20
Source File: BabushkaText.java From RxAndroidBootstrap with Apache License 2.0 | 4 votes |
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 #21
Source File: Html.java From Nimingban with Apache License 2.0 | 4 votes |
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 #22
Source File: AKHtml.java From Mupdf with Apache License 2.0 | 4 votes |
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 #23
Source File: BabushkaText.java From BabushkaText with Apache License 2.0 | 4 votes |
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: BabushkaText.java From MVPAndroidBootstrap with Apache License 2.0 | 4 votes |
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 #25
Source File: LookItemAdapter.java From Devred-PE-2014 with Apache License 2.0 | 4 votes |
public LookItemAdapter(Context context, List<LookItem> objects) { super(context, R.layout.row_look_detail, objects); mSuperscriptSpan = new SuperscriptSpan(); mAbsoluteSizeSpan = new AbsoluteSizeSpan(14, true); mForegroundColorSpan = new ForegroundColorSpan(context.getResources().getColor(android.R.color.holo_red_dark)); }
Example #26
Source File: CustomHtmlToSpannedConverter.java From zulip-android with Apache License 2.0 | 4 votes |
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 #27
Source File: AndroidSpan.java From AndroidSpan with Apache License 2.0 | 4 votes |
/** * 上标样式,比如数学上的次方运算 * @param text * @return */ public AndroidSpan drawSuperscriptSpan(String text) { SuperscriptSpan span = new SuperscriptSpan(); drawSpan(text, span); return this; }
Example #28
Source File: Html.java From EhViewer with Apache License 2.0 | 4 votes |
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 #29
Source File: NotificationPresets.java From AndroidWearable-Samples with Apache License 2.0 | 4 votes |
@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 #30
Source File: NotificationPresets.java From AndroidWearable-Samples with Apache License 2.0 | 4 votes |
@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(); }