android.text.style.StrikethroughSpan Java Examples
The following examples show how to use
android.text.style.StrikethroughSpan.
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 |
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: CouponPriceUtil.java From AndroidStudyDemo with GNU General Public License v2.0 | 6 votes |
/** * 现金券显示价格样式 */ public static SpannableString getCashPrice(Context context, double oldPrice, double newPrice) { StringBuilder builder = new StringBuilder(); builder.append(handleDouble(newPrice)).append("元").append(" ").append(handleDouble(oldPrice)).append("元"); int start = 0; int middle = builder.indexOf(" ") + 1; int end = builder.length(); SpannableString string = new SpannableString(builder); /*改变文字的大小*/ string.setSpan(new AbsoluteSizeSpan(sp2px(context, 20)), start, middle, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); string.setSpan(new AbsoluteSizeSpan(sp2px(context, 14)), middle, end, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); /*给文字设置删除线*/ string.setSpan(new StrikethroughSpan(), middle, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); /*改变文字的颜色*/ int textOrange = context.getResources().getColor(android.R.color.holo_red_light); int textGray = context.getResources().getColor(android.R.color.darker_gray); string.setSpan(new ForegroundColorSpan(textOrange), start, middle, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); string.setSpan(new ForegroundColorSpan(textGray), middle, end, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); return string; }
Example #3
Source File: ReactTextTest.java From react-native-GPay with MIT License | 6 votes |
@Test public void testTextDecorationLineLineThroughApplied() { UIManagerModule uiManager = getUIManagerModule(); ReactRootView rootView = createText( uiManager, JavaOnlyMap.of(ViewProps.TEXT_DECORATION_LINE, "line-through"), JavaOnlyMap.of(ReactRawTextShadowNode.PROP_TEXT, "test text")); TextView textView = (TextView) rootView.getChildAt(0); Spanned text = (Spanned) textView.getText(); UnderlineSpan[] underlineSpans = text.getSpans(0, text.length(), UnderlineSpan.class); StrikethroughSpan strikeThroughSpan = getSingleSpan(textView, StrikethroughSpan.class); assertThat(underlineSpans).hasSize(0); assertThat(strikeThroughSpan instanceof StrikethroughSpan).isTrue(); }
Example #4
Source File: KnifeTagHandler.java From Knife with Apache License 2.0 | 6 votes |
@Override public void handleTag(boolean opening, String tag, Editable output, XMLReader xmlReader) { if (opening) { if (tag.equalsIgnoreCase(BULLET_LI)) { if (output.length() > 0 && output.charAt(output.length() - 1) != '\n') { output.append("\n"); } start(output, new Li()); } else if (tag.equalsIgnoreCase(STRIKETHROUGH_S) || tag.equalsIgnoreCase(STRIKETHROUGH_STRIKE) || tag.equalsIgnoreCase(STRIKETHROUGH_DEL)) { start(output, new Strike()); } } else { if (tag.equalsIgnoreCase(BULLET_LI)) { if (output.length() > 0 && output.charAt(output.length() - 1) != '\n') { output.append("\n"); } end(output, Li.class, new BulletSpan()); } else if (tag.equalsIgnoreCase(STRIKETHROUGH_S) || tag.equalsIgnoreCase(STRIKETHROUGH_STRIKE) || tag.equalsIgnoreCase(STRIKETHROUGH_DEL)) { end(output, Strike.class, new StrikethroughSpan()); } } }
Example #5
Source File: StrikethroughEditHandler.java From Markwon with Apache License 2.0 | 6 votes |
@Override public void handleMarkdownSpan( @NonNull PersistedSpans persistedSpans, @NonNull Editable editable, @NonNull String input, @NonNull StrikethroughSpan span, int spanStart, int spanTextLength) { final MarkwonEditorUtils.Match match = MarkwonEditorUtils.findDelimited(input, spanStart, "~~"); if (match != null) { editable.setSpan( persistedSpans.get(StrikethroughSpan.class), match.start(), match.end(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE ); } }
Example #6
Source File: RichEditText.java From RichEditText with Apache License 2.0 | 6 votes |
private ImageView getHtmloptionToolButton(Object span) { if (span instanceof StyleSpan) { switch (((StyleSpan) span).getStyle()) { case Typeface.BOLD: return (ImageView) findViewById(R.id.makeBold); case Typeface.ITALIC: return (ImageView) findViewById(R.id.makeItalic); default: return null; } } else if (span instanceof UnderlineSpan) { return (ImageView) findViewById(R.id.makeUnderline); } else if(span instanceof StrikethroughSpan) return (ImageView) findViewById(R.id.makeStrikethrough); return null; }
Example #7
Source File: HtmlToSpannedConverter.java From HtmlCompat with Apache License 2.0 | 6 votes |
private void endCssStyle(String tag, Editable text) { Strikethrough s = getLast(text, Strikethrough.class); if (s != null) { setSpanFromMark(tag, text, s, new StrikethroughSpan()); } Background b = getLast(text, Background.class); if (b != null) { setSpanFromMark(tag, text, b, new BackgroundColorSpan(b.mBackgroundColor)); } Foreground f = getLast(text, Foreground.class); if (f != null) { setSpanFromMark(tag, text, f, new ForegroundColorSpan(f.mForegroundColor)); } AbsoluteSize a = getLast(text, AbsoluteSize.class); if (a != null) { setSpanFromMark(tag, text, a, new AbsoluteSizeSpan(a.getTextSize())); } RelativeSize r = getLast(text, RelativeSize.class); if (r != null) { setSpanFromMark(tag, text, r, new RelativeSizeSpan(r.getTextProportion())); } }
Example #8
Source File: HackerNewsItem.java From materialistic with Apache License 2.0 | 6 votes |
@Override public Spannable getDisplayedTime(Context context) { if (displayedTime == null) { SpannableStringBuilder builder = new SpannableStringBuilder(dead ? context.getString(R.string.dead_prefix) + " " : ""); SpannableString timeSpannable = new SpannableString( AppUtils.getAbbreviatedTimeSpan(time * 1000)); if (deleted) { timeSpannable.setSpan(new StrikethroughSpan(), 0, timeSpannable.length(), Spanned.SPAN_INCLUSIVE_EXCLUSIVE); } builder.append(timeSpannable); displayedTime = builder; } return displayedTime; }
Example #9
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 #10
Source File: Html.java From ForPDA with GNU General Public License v3.0 | 6 votes |
private static void endCssStyle(Editable text) { Font font = getLast(text, Font.class); if (font != null) { if (font.mFace.equalsIgnoreCase("fontello")) { setSpanFromMark(text, font, new AssetsTypefaceSpan(App.getContext(), "fontello/fontello.ttf")); } } Strikethrough s = getLast(text, Strikethrough.class); if (s != null) { setSpanFromMark(text, s, new StrikethroughSpan()); } Background b = getLast(text, Background.class); if (b != null) { setSpanFromMark(text, b, new BackgroundColorSpan(b.mBackgroundColor)); } Foreground f = getLast(text, Foreground.class); if (f != null) { setSpanFromMark(text, f, new ForegroundColorSpan(f.mForegroundColor)); } }
Example #11
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 #12
Source File: Html.java From android_9.0.0_r45 with Apache License 2.0 | 6 votes |
private static void endCssStyle(Editable text) { Strikethrough s = getLast(text, Strikethrough.class); if (s != null) { setSpanFromMark(text, s, new StrikethroughSpan()); } Background b = getLast(text, Background.class); if (b != null) { setSpanFromMark(text, b, new BackgroundColorSpan(b.mBackgroundColor)); } Foreground f = getLast(text, Foreground.class); if (f != null) { setSpanFromMark(text, f, new ForegroundColorSpan(f.mForegroundColor)); } }
Example #13
Source File: Utils.java From frpc-Android with Apache License 2.0 | 5 votes |
public static SpannableString getPrict(String price1,String price2){ String s = "¥" + price1 + " 原价" + price2; int pos = s.indexOf(" "); int end = s.length(); SpannableString spanString = new SpannableString(s); ForegroundColorSpan span = new ForegroundColorSpan(0xff999999); StrikethroughSpan span2 = new StrikethroughSpan(); spanString.setSpan(span, pos+1, end, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); spanString.setSpan(span2, pos+1, end, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); return spanString; }
Example #14
Source File: SpannableStringUtil.java From SimpleProject with MIT License | 5 votes |
/** * 为多个位置的文字添加删除线 * @param text * @param startPos * @param len * @return */ public static SpannableString getStrikeThroughSpannable(String text, int[] startPos, int[] len) { SpannableString span = new SpannableString(text); if (startPos != null && len != null && startPos.length > 0 && len.length > 0 && startPos.length == len.length) { for (int i = 0; i < startPos.length; i++) { span.setSpan(new StrikethroughSpan(), startPos[i], startPos[i]+len[i], Spanned.SPAN_INCLUSIVE_INCLUSIVE); } } return span; }
Example #15
Source File: StylingHelper.java From Pix-Art-Messenger with GNU General Public License v3.0 | 5 votes |
private static ParcelableSpan clone(ParcelableSpan span) { if (span instanceof ForegroundColorSpan) { return new ForegroundColorSpan(((ForegroundColorSpan) span).getForegroundColor()); } else if (span instanceof TypefaceSpan) { return new TypefaceSpan(((TypefaceSpan) span).getFamily()); } else if (span instanceof StyleSpan) { return new StyleSpan(((StyleSpan) span).getStyle()); } else if (span instanceof StrikethroughSpan) { return new StrikethroughSpan(); } else { throw new AssertionError("Unknown Span"); } }
Example #16
Source File: SendLocalArchiveTask.java From Dashchan with Apache License 2.0 | 5 votes |
private Object[] getSpanType(Object span, Object[] result) { result[0] = 0; result[1] = null; if (span instanceof LinkSpan) { result[0] = ChanMarkup.TAG_SPECIAL_LINK; result[1] = ((LinkSpan) span).getUriString(); } else if (span instanceof SpoilerSpan) { result[0] = ChanMarkup.TAG_SPOILER; } else if (span instanceof QuoteSpan) { result[0] = ChanMarkup.TAG_QUOTE; } else if (span instanceof ScriptSpan) { result[0] = ((ScriptSpan) span).isSuperscript() ? ChanMarkup.TAG_SUPERSCRIPT : ChanMarkup.TAG_SUBSCRIPT; } else if (span instanceof StyleSpan) { int style = ((StyleSpan) span).getStyle(); if (style == Typeface.BOLD) { result[0] = ChanMarkup.TAG_BOLD; } else { if (style == Typeface.ITALIC) { result[0] = ChanMarkup.TAG_ITALIC; } } } else if (span instanceof UnderlineSpan) { result[0] = ChanMarkup.TAG_UNDERLINE; } else if (span instanceof OverlineSpan) { result[0] = ChanMarkup.TAG_OVERLINE; } else if (span instanceof StrikethroughSpan) { result[0] = ChanMarkup.TAG_STRIKE; } else if (span instanceof GainedColorSpan) { result[0] = ChanMarkup.TAG_SPECIAL_COLOR; result[1] = ((GainedColorSpan) span).getForegroundColor(); } else if (span instanceof MonospaceSpan) { result[0] = ((MonospaceSpan) span).isAsciiArt() ? ChanMarkup.TAG_ASCII_ART : ChanMarkup.TAG_CODE; } else if (span instanceof HeadingSpan) { result[0] = ChanMarkup.TAG_HEADING; } return result; }
Example #17
Source File: ItemsAdapter.java From sqlitemagic with Apache License 2.0 | 5 votes |
@Override void setItem(@NonNull Item item) { this.item = item; final CheckedTextView textView = (CheckedTextView) itemView; final boolean complete = item.complete(); textView.setChecked(complete); CharSequence description = item.description(); if (complete) { SpannableString spannable = new SpannableString(description); spannable.setSpan(new StrikethroughSpan(), 0, description.length(), 0); description = spannable; } textView.setText(description); }
Example #18
Source File: MyHtmlTagHandler.java From nono-android with GNU General Public License v3.0 | 5 votes |
private void processStrike(boolean opening, Editable output) { int len = output.length(); if(opening) { output.setSpan(new StrikethroughSpan(), len, len, Spannable.SPAN_MARK_MARK); } else { Object obj = getLast(output, StrikethroughSpan.class); int where = output.getSpanStart(obj); output.removeSpan(obj); if (where != len&&where>=0) { output.setSpan(new StrikethroughSpan(), where, len, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); } } }
Example #19
Source File: SpanEZTest.java From SpanEZ with Apache License 2.0 | 5 votes |
@Test public void strikethrough_should_add_only_one_span() { spanBuilder.style(range, EZ.STRIKETHROUGH) .apply(); verify((SpanEZ) spanBuilder, times(1)) .addSpan(isA(TargetRange.class), isA(StrikethroughSpan.class)); }
Example #20
Source File: StyleBuilderImpl.java From Markdown with MIT License | 5 votes |
@Override public SpannableStringBuilder delete(CharSequence charSequence) { SpannableStringBuilder builder = SpannableStringBuilder.valueOf(charSequence); StrikethroughSpan span = new StrikethroughSpan(); ForegroundColorSpan colorSpan = new ForegroundColorSpan(h1_text_color); builder.setSpan(colorSpan, 0, charSequence.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); builder.setSpan(span, 0, charSequence.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); return builder; }
Example #21
Source File: Spans.java From spanner with Apache License 2.0 | 5 votes |
/** * @see StrikethroughSpan#StrikethroughSpan() */ public static Span strikeThrough() { return new Span(new SpanBuilder() { @Override public Object build() { return new StrikethroughSpan(); } }); }
Example #22
Source File: BestGlucose.java From xDrip with GNU General Public License v3.0 | 5 votes |
public SpannableString spannableString(String str, boolean color) { final SpannableString ret = new SpannableString((str != null) ? str : ""); if (isStale()) wholeSpan(ret, new StrikethroughSpan()); if (color) { if (isLow()) { // TODO should colors be configurable? wholeSpan(ret, new ForegroundColorSpan(Color.parseColor("#C30909"))); } else if (isHigh()) { wholeSpan(ret, new ForegroundColorSpan(Color.parseColor("#FFBB33"))); } // else default to whatever default is? } return ret; }
Example #23
Source File: HiHtmlTagHandler.java From hipda with GNU General Public License v2.0 | 5 votes |
private void processStrike(boolean opening, Editable output) { int len = output.length(); if (opening) { output.setSpan(new StrikethroughSpan(), len, len, Spannable.SPAN_MARK_MARK); } else { Object obj = getLast(output, StrikethroughSpan.class); int where = output.getSpanStart(obj); output.removeSpan(obj); if (where != len) { output.setSpan(new StrikethroughSpan(), where, len, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); } } }
Example #24
Source File: StylingHelper.java From Pix-Art-Messenger with GNU General Public License v3.0 | 5 votes |
private static ParcelableSpan createSpanForStyle(ImStyleParser.Style style) { switch (style.getKeyword()) { case "*": return new StyleSpan(Typeface.BOLD); case "_": return new StyleSpan(Typeface.ITALIC); case "~": return new StrikethroughSpan(); case "`": case "```": return new TypefaceSpan("monospace"); default: throw new AssertionError("Unknown Style"); } }
Example #25
Source File: TextDecorator.java From text-decorator with Apache License 2.0 | 5 votes |
public TextDecorator strikethrough(final String... texts) { int index; for (String text : texts) { if (content.contains(text)) { index = content.indexOf(text); decoratedContent.setSpan(new StrikethroughSpan(), index, index + text.length(), flags); } } return this; }
Example #26
Source File: CustomHtmlTagHandler.java From SteamGifts with MIT License | 5 votes |
private void processStrike(boolean opening, Editable output) { int len = output.length(); if (opening) { output.setSpan(new StrikethroughSpan(), len, len, Spannable.SPAN_MARK_MARK); } else { Object obj = getLast(output, StrikethroughSpan.class); int where = output.getSpanStart(obj); output.removeSpan(obj); if (where != len) { output.setSpan(new StrikethroughSpan(), where, len, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); } } }
Example #27
Source File: BestGlucose.java From xDrip with GNU General Public License v3.0 | 5 votes |
public SpannableString spannableString(String str, boolean color) { final SpannableString ret = new SpannableString((str != null) ? str : ""); if (isStale()) wholeSpan(ret, new StrikethroughSpan()); if (color) { if (isLow()) { // TODO should colors be configurable? wholeSpan(ret, new ForegroundColorSpan(Color.parseColor("#C30909"))); } else if (isHigh()) { wholeSpan(ret, new ForegroundColorSpan(Color.parseColor("#FFBB33"))); } // else default to whatever default is? } return ret; }
Example #28
Source File: WXTextDomObject.java From weex-uikit with MIT License | 5 votes |
/** * Create a task list which contains {@link SetSpanOperation}. The task list will be executed * in other method. * @param end the end character of the text. * @return a task list which contains {@link SetSpanOperation}. */ private List<SetSpanOperation> createSetSpanOperation(int end, int spanFlag) { List<SetSpanOperation> ops = new LinkedList<>(); int start = 0; if (end >= start) { if (mTextDecoration == WXTextDecoration.UNDERLINE) { ops.add(new SetSpanOperation(start, end, new UnderlineSpan(), spanFlag)); } if (mTextDecoration == WXTextDecoration.LINETHROUGH) { ops.add(new SetSpanOperation(start, end, new StrikethroughSpan(), spanFlag)); } if (mIsColorSet) { ops.add(new SetSpanOperation(start, end, new ForegroundColorSpan(mColor), spanFlag)); } if (mFontSize != UNSET) { ops.add(new SetSpanOperation(start, end, new AbsoluteSizeSpan(mFontSize), spanFlag)); } if (mFontStyle != UNSET || mFontWeight != UNSET || mFontFamily != null) { ops.add(new SetSpanOperation(start, end, new WXCustomStyleSpan(mFontStyle, mFontWeight, mFontFamily), spanFlag)); } ops.add(new SetSpanOperation(start, end, new AlignmentSpan.Standard(mAlignment), spanFlag)); if (mLineHeight != UNSET) { ops.add(new SetSpanOperation(start, end, new WXLineHeightSpan(mLineHeight), spanFlag)); } } return ops; }
Example #29
Source File: Transformers.java From hashtag-view with MIT License | 5 votes |
@Override public CharSequence prepareSelected(String item) { SpannableString spannableString = new SpannableString("#" + item); spannableString.setSpan(new ForegroundColorSpan(Color.parseColor("#85F5F5F5")), 0, spannableString.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); spannableString.setSpan(new StrikethroughSpan(), 0, spannableString.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); return spannableString; }
Example #30
Source File: BestGlucose.java From xDrip-plus with GNU General Public License v3.0 | 5 votes |
public SpannableString spannableString(String str, boolean color) { final SpannableString ret = new SpannableString((str != null) ? str : ""); if (isStale()) wholeSpan(ret, new StrikethroughSpan()); if (color) { if (isLow()) { // TODO should colors be configurable? wholeSpan(ret, new ForegroundColorSpan(Color.parseColor("#C30909"))); } else if (isHigh()) { wholeSpan(ret, new ForegroundColorSpan(Color.parseColor("#FFBB33"))); } // else default to whatever default is? } return ret; }