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 Project: android_9.0.0_r45   Author: lulululbj   File: Html.java    License: Apache License 2.0 6 votes vote down vote up
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 #2
Source Project: react-native-GPay   Author: hellochirag   File: ReactTextTest.java    License: MIT License 6 votes vote down vote up
@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 #3
Source Project: Knife   Author: mthli   File: KnifeTagHandler.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void handleTag(boolean opening, String tag, Editable output, XMLReader xmlReader) {
    if (opening) {
        if (tag.equalsIgnoreCase(BULLET_LI)) {
            if (output.length() > 0 && output.charAt(output.length() - 1) != '\n') {
                output.append("\n");
            }
            start(output, new Li());
        } else if (tag.equalsIgnoreCase(STRIKETHROUGH_S) || tag.equalsIgnoreCase(STRIKETHROUGH_STRIKE) || tag.equalsIgnoreCase(STRIKETHROUGH_DEL)) {
            start(output, new Strike());
        }
    } else {
        if (tag.equalsIgnoreCase(BULLET_LI)) {
            if (output.length() > 0 && output.charAt(output.length() - 1) != '\n') {
                output.append("\n");
            }
            end(output, Li.class, new BulletSpan());
        } else if (tag.equalsIgnoreCase(STRIKETHROUGH_S) || tag.equalsIgnoreCase(STRIKETHROUGH_STRIKE) || tag.equalsIgnoreCase(STRIKETHROUGH_DEL)) {
            end(output, Strike.class, new StrikethroughSpan());
        }
    }
}
 
Example #4
Source Project: Markwon   Author: noties   File: StrikethroughEditHandler.java    License: Apache License 2.0 6 votes vote down vote up
@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 #5
Source Project: RichEditText   Author: chen-xiao-dong   File: RichEditText.java    License: Apache License 2.0 6 votes vote down vote up
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 #6
Source Project: HtmlCompat   Author: Pixplicity   File: HtmlToSpannedConverter.java    License: Apache License 2.0 6 votes vote down vote up
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 #7
Source Project: ForPDA   Author: RadiationX   File: Html.java    License: GNU General Public License v3.0 6 votes vote down vote up
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 #8
Source Project: memoir   Author: ronak-manglani   File: ConverterSpannedToHtml.java    License: 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 #9
Source Project: memoir   Author: ronak-manglani   File: ConverterSpannedToHtml.java    License: 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 #10
Source Project: AndroidStudyDemo   Author: DIY-green   File: CouponPriceUtil.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * 现金券显示价格样式
 */
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 #11
Source Project: materialistic   Author: hidroh   File: HackerNewsItem.java    License: Apache License 2.0 6 votes vote down vote up
@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 #12
Source Project: Android-RTEditor   Author: 1gravity   File: ConverterSpannedToHtml.java    License: 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 #13
Source Project: Dashchan   Author: Mishiranu   File: SendLocalArchiveTask.java    License: Apache License 2.0 5 votes vote down vote up
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 #14
Source Project: green_android   Author: Blockstream   File: MnemonicActivity.java    License: GNU General Public License v3.0 5 votes vote down vote up
private boolean markInvalidWord(final Editable e) {
    for (final StrikethroughSpan s : e.getSpans(0, e.length(), StrikethroughSpan.class))
        e.removeSpan(s);

    final String word = e.toString();
    if (isHexSeed(word))
        return true;
    final int end = word.length();
    if (!MnemonicHelper.isPrefix(word))
        e.setSpan(new StrikethroughSpan(), 0, end, 0);
    return !MnemonicHelper.mWords.contains(word);
}
 
Example #15
Source Project: frpc-Android   Author: FrpcCluster   File: Utils.java    License: Apache License 2.0 5 votes vote down vote up
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 #16
Source Project: Pix-Art-Messenger   Author: kriztan   File: StylingHelper.java    License: GNU General Public License v3.0 5 votes vote down vote up
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 #17
Source Project: SimpleProject   Author: Liberuman   File: SpannableStringUtil.java    License: MIT License 5 votes vote down vote up
/**
 * 为多个位置的文字添加删除线
 * @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 #18
Source Project: Knife   Author: mthli   File: KnifeText.java    License: Apache License 2.0 5 votes vote down vote up
protected void strikethroughValid(int start, int end) {
    if (start >= end) {
        return;
    }

    getEditableText().setSpan(new StrikethroughSpan(), start, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
}
 
Example #19
Source Project: dante   Author: fourlastor   File: MainActivity.java    License: MIT License 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    html = ((TextView) findViewById(R.id.html));

    flavoredHtml = new FlavoredHtml.Builder(this)
            .newLine("p", "h1", "h2", "h3", "h4", "h5", "h6", "li")
            .textAppearance(R.style.headline, "h1")
            .textAppearance(R.style.title, "h2")
            .textAppearance(R.style.subhead, "h3")
            .textAppearance(R.style.body, "p", "li")
            .style(Typeface.BOLD, "b", "strong")
            .style(Typeface.ITALIC, "i", "em")
            .bullet(15, "li")
            .img(new ImgLoader.BitmapLoader(getResources()) {
                @Override
                protected Bitmap loadBitmap(String src) {
                    try {
                        return Picasso.with(MainActivity.this)
                                .load(src)
                                .get();
                    } catch (IOException e) {
                        throw new RuntimeException("Whoops!");
                    }
                }
            })
            .blockStyle(new BlockStyleListener("s") {
                @Override
                protected Object getStyleSpan() {
                    return new StrikethroughSpan();
                }
            })
            .build();
}
 
Example #20
Source Project: RichEditor   Author: DrownCoder   File: MarkDownParser.java    License: Apache License 2.0 5 votes vote down vote up
private String spanToMarkDown(List<Object> mSpans, String source, int start, int end) {
    if (mSpans == null || mSpans.size() == 0) {
        return source.substring(start, end);
    }
    String str = source.substring(start, end);
    for (Object obj : mSpans) {
        if (obj instanceof StyleSpan) {
            StyleSpan objSpan = (StyleSpan) obj;
            switch (objSpan.getStyle()) {
                case Typeface.BOLD:
                    str = formater.formatBold(str);
                    break;
                case Typeface.ITALIC:
                    str = formater.formatItalics(str);
                    break;
            }
        } else if (obj instanceof UnderlineSpan) {
            //markdown是不支持下划线的!!!,后期考虑注释掉
            str = formater.formatUnderLine(str);
        } else if (obj instanceof StrikethroughSpan) {
            str = formater.formatCenterLine(str);
        } else if (obj instanceof URLSpanNoUnderline) {
            URLSpanNoUnderline url = (URLSpanNoUnderline) obj;
            str = formater.formatLink(str, url.getURL());
        }
    }
    return str;
}
 
Example #21
Source Project: SpanEZ   Author: yombunker   File: SpanEZTest.java    License: Apache License 2.0 5 votes vote down vote up
@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 #22
Source Project: spanner   Author: neworld   File: Spans.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * @see StrikethroughSpan#StrikethroughSpan()
 */
public static Span strikeThrough() {
    return new Span(new SpanBuilder() {
        @Override
        public Object build() {
            return new StrikethroughSpan();
        }
    });
}
 
Example #23
Source Project: hipda   Author: GreenSkinMonster   File: HiHtmlTagHandler.java    License: GNU General Public License v2.0 5 votes vote down vote up
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 Project: Pix-Art-Messenger   Author: kriztan   File: StylingHelper.java    License: GNU General Public License v3.0 5 votes vote down vote up
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 Project: SteamGifts   Author: SteamGifts   File: CustomHtmlTagHandler.java    License: MIT License 5 votes vote down vote up
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 #26
Source Project: weex-uikit   Author: erguotou520   File: WXTextDomObject.java    License: MIT License 5 votes vote down vote up
/**
 * 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 #27
Source Project: text-decorator   Author: nntuyen   File: TextDecorator.java    License: Apache License 2.0 5 votes vote down vote up
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 #28
Source Project: xDrip   Author: NightscoutFoundation   File: BestGlucose.java    License: GNU General Public License v3.0 5 votes vote down vote up
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 #29
Source Project: xDrip   Author: NightscoutFoundation   File: BestGlucose.java    License: GNU General Public License v3.0 5 votes vote down vote up
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 #30
Source Project: xDrip-plus   Author: jamorham   File: BestGlucose.java    License: GNU General Public License v3.0 5 votes vote down vote up
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;
}