Java Code Examples for android.text.style.StrikethroughSpan

The following are top voted examples for showing how to use android.text.style.StrikethroughSpan. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: Delightful-SQLBrite   File: ItemsAdapter.java   Source Code and License 6 votes vote down vote up
@Override
public View getView(int position, View convertView, ViewGroup parent) {
    if (convertView == null) {
        convertView = inflater.inflate(android.R.layout.simple_list_item_multiple_choice,
                parent, false);
    }

    TodoItem item = getItem(position);
    CheckedTextView textView = (CheckedTextView) convertView;
    textView.setChecked(item.complete());

    CharSequence description = item.description();
    if (item.complete()) {
        SpannableString spannable = new SpannableString(description);
        spannable.setSpan(new StrikethroughSpan(), 0, description.length(), 0);
        description = spannable;
    }

    textView.setText(description);

    return convertView;
}
 
Example 2
Project: Slide-RSS   File: SpoilerRobotoTextView.java   Source Code and License 6 votes vote down vote up
private void setStrikethrough(SpannableStringBuilder builder) {
    final int offset = "[[d[".length(); // == "]d]]".length()

    int start = -1;
    int end;

    for (int i = 0; i < builder.length() - 3; i++) {
        if (builder.charAt(i) == '['
                && builder.charAt(i + 1) == '['
                && builder.charAt(i + 2) == 'd'
                && builder.charAt(i + 3) == '[') {
            start = i + offset;
        } else if (builder.charAt(i) == ']'
                && builder.charAt(i + 1) == 'd'
                && builder.charAt(i + 2) == ']'
                && builder.charAt(i + 3) == ']') {
            end = i;
            builder.setSpan(new StrikethroughSpan(), start, end,
                    Spanned.SPAN_INCLUSIVE_INCLUSIVE);
            builder.delete(end, end + offset);
            builder.delete(start - offset, start);
            i -= offset + (end - start); // length of text
        }
    }
}
 
Example 3
Project: OSchina_resources_android   File: RichEditText.java   Source Code and License 6 votes vote down vote up
/**
 * 中横线,即删除线
 *
 * @param isMidLine isMidLine
 */
void setMidLine(boolean isMidLine) {
    int index = getSelectionIndex();
    if (index >= 0 && index < mSections.size()) {
        mSections.get(index).setMidLine(isMidLine);
    }
    Editable edit = getEditableText();
    int star = getSectionStart();
    int end = getSectionEnd();
    if (isMidLine) {
        edit.setSpan(new StrikethroughSpan(),
                star,
                end,
                Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
    } else {
        StrikethroughSpan[] styleSpans = edit.getSpans(star,
                end, StrikethroughSpan.class);
        for (StrikethroughSpan span : styleSpans) {
            edit.removeSpan(span);
        }
    }
}
 
Example 4
Project: OSchina_resources_android   File: RichEditText.java   Source Code and License 6 votes vote down vote up
/**
 * 中横线,即删除线
 *
 * @param isMidLine isMidLine
 */
void setMidLine(boolean isMidLine, int index) {
    if (index >= 0 && index < mSections.size()) {
        mSections.get(index).setMidLine(isMidLine);
    }
    Editable edit = getEditableText();
    int star = getSectionStart();
    int end = getSectionEnd();
    if (isMidLine) {
        edit.setSpan(new StrikethroughSpan(),
                star,
                end,
                Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
    } else {
        StrikethroughSpan[] styleSpans = edit.getSpans(star,
                end, StrikethroughSpan.class);
        for (StrikethroughSpan span : styleSpans) {
            edit.removeSpan(span);
        }
    }
}
 
Example 5
Project: HtmlCompat   File: HtmlToSpannedConverter.java   Source Code and License 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 6
Project: sqlbrite-sqlcipher   File: ItemsAdapter.java   Source Code and License 6 votes vote down vote up
@Override public View getView(int position, View convertView, ViewGroup parent) {
  if (convertView == null) {
    convertView = inflater.inflate(android.R.layout.simple_list_item_multiple_choice, parent, false);
  }

  TodoItem item = getItem(position);
  CheckedTextView textView = (CheckedTextView) convertView;
  textView.setChecked(item.complete());

  CharSequence description = item.description();
  if (item.complete()) {
    SpannableString spannable = new SpannableString(description);
    spannable.setSpan(new StrikethroughSpan(), 0, description.length(), 0);
    description = spannable;
  }

  textView.setText(description);

  return convertView;
}
 
Example 7
Project: RNLearn_Project1   File: ReactTextTest.java   Source Code and License 6 votes vote down vote up
@Test
public void testTextDecorationLineUnderlineApplied() {
  UIManagerModule uiManager = getUIManagerModule();

  ReactRootView rootView = createText(
      uiManager,
      JavaOnlyMap.of(ViewProps.TEXT_DECORATION_LINE, "underline"),
      JavaOnlyMap.of(ReactTextShadowNode.PROP_TEXT, "test text"));

  TextView textView = (TextView) rootView.getChildAt(0);
  Spanned text = (Spanned) textView.getText();
  UnderlineSpan underlineSpan = getSingleSpan(textView, UnderlineSpan.class);
  StrikethroughSpan[] strikeThroughSpans =
      text.getSpans(0, text.length(), StrikethroughSpan.class);
  assertThat(underlineSpan instanceof UnderlineSpan).isTrue();
  assertThat(strikeThroughSpans).hasSize(0);
}
 
Example 8
Project: RNLearn_Project1   File: ReactTextTest.java   Source Code and 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(ReactTextShadowNode.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 9
Project: RNLearn_Project1   File: ReactTextTest.java   Source Code and License 6 votes vote down vote up
@Test
public void testTextDecorationLineUnderlineLineThroughApplied() {
  UIManagerModule uiManager = getUIManagerModule();

  ReactRootView rootView = createText(
      uiManager,
      JavaOnlyMap.of(ViewProps.TEXT_DECORATION_LINE, "underline line-through"),
      JavaOnlyMap.of(ReactTextShadowNode.PROP_TEXT, "test text"));

  UnderlineSpan underlineSpan =
      getSingleSpan((TextView) rootView.getChildAt(0), UnderlineSpan.class);
  StrikethroughSpan strikeThroughSpan =
      getSingleSpan((TextView) rootView.getChildAt(0), StrikethroughSpan.class);
  assertThat(underlineSpan instanceof UnderlineSpan).isTrue();
  assertThat(strikeThroughSpan instanceof StrikethroughSpan).isTrue();
}
 
Example 10
Project: RNLearn_Project1   File: ReactTextTest.java   Source Code and License 6 votes vote down vote up
@Test
public void testTextDecorationLineUnderlineApplied() {
  UIManagerModule uiManager = getUIManagerModule();

  ReactRootView rootView = createText(
      uiManager,
      JavaOnlyMap.of(ViewProps.TEXT_DECORATION_LINE, "underline"),
      JavaOnlyMap.of(ReactTextShadowNode.PROP_TEXT, "test text"));

  TextView textView = (TextView) rootView.getChildAt(0);
  Spanned text = (Spanned) textView.getText();
  UnderlineSpan underlineSpan = getSingleSpan(textView, UnderlineSpan.class);
  StrikethroughSpan[] strikeThroughSpans =
      text.getSpans(0, text.length(), StrikethroughSpan.class);
  assertThat(underlineSpan instanceof UnderlineSpan).isTrue();
  assertThat(strikeThroughSpans).hasSize(0);
}
 
Example 11
Project: RNLearn_Project1   File: ReactTextTest.java   Source Code and 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(ReactTextShadowNode.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 12
Project: RNLearn_Project1   File: ReactTextTest.java   Source Code and License 6 votes vote down vote up
@Test
public void testTextDecorationLineUnderlineLineThroughApplied() {
  UIManagerModule uiManager = getUIManagerModule();

  ReactRootView rootView = createText(
      uiManager,
      JavaOnlyMap.of(ViewProps.TEXT_DECORATION_LINE, "underline line-through"),
      JavaOnlyMap.of(ReactTextShadowNode.PROP_TEXT, "test text"));

  UnderlineSpan underlineSpan =
      getSingleSpan((TextView) rootView.getChildAt(0), UnderlineSpan.class);
  StrikethroughSpan strikeThroughSpan =
      getSingleSpan((TextView) rootView.getChildAt(0), StrikethroughSpan.class);
  assertThat(underlineSpan instanceof UnderlineSpan).isTrue();
  assertThat(strikeThroughSpan instanceof StrikethroughSpan).isTrue();
}
 
Example 13
Project: instantsearch-android-examples   File: PriceView.java   Source Code and License 6 votes vote down vote up
@SuppressLint("SetTextI18n") /* This will only display US prices */
@Override
public void onUpdateView(JSONObject result) {
    try {
        double salePrice = result.getDouble("salePrice");
        double promoPrice = result.getDouble("promoPrice");
        double lowestPrice = Math.min(salePrice, promoPrice);

        final String priceText = SYMBOL_MONEY + lowestPrice;
        final SpannableStringBuilder finalText = new SpannableStringBuilder(priceText);

        finalText.setSpan(new ForegroundColorSpan(getResources().getColor(R.color.colorPrice)), 0, priceText.length(), Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
        finalText.setSpan(new StyleSpan(Typeface.BOLD), 0, priceText.length(), Spanned.SPAN_INCLUSIVE_EXCLUSIVE);

        if (salePrice != promoPrice) {
            finalText.append(" ").append(SYMBOL_MONEY).append(Double.toString(salePrice));
            finalText.setSpan(new StrikethroughSpan(), priceText.length() + 1, finalText.length(), Spanned.SPAN_EXCLUSIVE_INCLUSIVE);
        }
        setText(finalText, BufferType.SPANNABLE);
    } catch (JSONException e) {
        Toast.makeText(context, "Error parsing result:" + e.getMessage(), Toast.LENGTH_SHORT).show();
    }
}
 
Example 14
Project: Delightful-SQLBrite   File: ItemsAdapter.java   Source Code and License 6 votes vote down vote up
@Override
public View getView(int position, View convertView, ViewGroup parent) {
    if (convertView == null) {
        convertView = inflater.inflate(android.R.layout.simple_list_item_multiple_choice,
                parent, false);
    }

    TodoItem item = getItem(position);
    CheckedTextView textView = (CheckedTextView) convertView;
    textView.setChecked(item.complete());

    CharSequence description = item.description();
    if (item.complete()) {
        SpannableString spannable = new SpannableString(description);
        spannable.setSpan(new StrikethroughSpan(), 0, description.length(), 0);
        description = spannable;
    }

    textView.setText(description);

    return convertView;
}
 
Example 15
Project: FloatText   File: ListViewAdapter.java   Source Code and License 6 votes vote down vote up
private void TextReshow(int index, App utils, ViewHolder view, boolean show, String listtext) {
    FloatTextUtils textutils = utils.getTextutil();
    if (!show) {
        SpannableString str = new SpannableString(listtext);
        str.setSpan(new StrikethroughSpan(), 0, str.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        view.textView.setText(str);
    } else {
        view.textView.setText(listtext);
    }
    if (typeface != null) {
        view.textView.setTypeface(typeface);
    }
    if (textutils.getTextShadow().get(index)) {
        view.textView.setShadowLayer(textutils.getTextShadowRadius().get(index), textutils.getTextShadowX().get(index), textutils.getTextShadowY().get(index), textutils.getTextShadowColor().get(index));
    } else {
        view.textView.setShadowLayer(0, 0, 0, 0);
    }
    view.textView.getPaint().setFakeBoldText(utils.getTextutil().getThickShow().get(index));
    view.textView.setTextColor(utils.getTextutil().getColorShow().get(index));
    view.textView.setEllipsize(TextUtils.TruncateAt.END);
}
 
Example 16
Project: ForPDA   File: Html.java   Source Code and License 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 17
Project: react-native-box-loaders   File: ReactTextTest.java   Source Code and License 6 votes vote down vote up
@Test
public void testTextDecorationLineUnderlineApplied() {
  UIManagerModule uiManager = getUIManagerModule();

  ReactRootView rootView = createText(
      uiManager,
      JavaOnlyMap.of(ViewProps.TEXT_DECORATION_LINE, "underline"),
      JavaOnlyMap.of(ReactTextShadowNode.PROP_TEXT, "test text"));

  TextView textView = (TextView) rootView.getChildAt(0);
  Spanned text = (Spanned) textView.getText();
  UnderlineSpan underlineSpan = getSingleSpan(textView, UnderlineSpan.class);
  StrikethroughSpan[] strikeThroughSpans =
      text.getSpans(0, text.length(), StrikethroughSpan.class);
  assertThat(underlineSpan instanceof UnderlineSpan).isTrue();
  assertThat(strikeThroughSpans).hasSize(0);
}
 
Example 18
Project: react-native-box-loaders   File: ReactTextTest.java   Source Code and 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(ReactTextShadowNode.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 19
Project: react-native-box-loaders   File: ReactTextTest.java   Source Code and License 6 votes vote down vote up
@Test
public void testTextDecorationLineUnderlineLineThroughApplied() {
  UIManagerModule uiManager = getUIManagerModule();

  ReactRootView rootView = createText(
      uiManager,
      JavaOnlyMap.of(ViewProps.TEXT_DECORATION_LINE, "underline line-through"),
      JavaOnlyMap.of(ReactTextShadowNode.PROP_TEXT, "test text"));

  UnderlineSpan underlineSpan =
      getSingleSpan((TextView) rootView.getChildAt(0), UnderlineSpan.class);
  StrikethroughSpan strikeThroughSpan =
      getSingleSpan((TextView) rootView.getChildAt(0), StrikethroughSpan.class);
  assertThat(underlineSpan instanceof UnderlineSpan).isTrue();
  assertThat(strikeThroughSpan instanceof StrikethroughSpan).isTrue();
}
 
Example 20
Project: azure-mobile-engagement-app-android   File: ProductDiscountActivity.java   Source Code and License 6 votes vote down vote up
/**
 * Method that adds or removes a strike from a TextView object
 *
 * @param textView The textView to manage
 */
private final void addOrRemoveStrikeTextView(TextView textView, boolean toAdd)
{
  textView.setText(textView.getText().toString(), TextView.BufferType.SPANNABLE);
  final Spannable spannable = (Spannable) textView.getText();

  if (toAdd == true)
  {
    // Add a StrikethroughSpan style
    final StrikethroughSpan strikethroughSpan = new StrikethroughSpan();
    spannable.setSpan(strikethroughSpan, 0, textView.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
  }
  else
  {
    // Remove only StrikethroughSpan style
    final Object spans[] = spannable.getSpans(0, textView.length(), Object.class);
    for (final Object span : spans)
    {
      if (span instanceof StrikethroughSpan == true)
      {
        spannable.removeSpan(span);
        return;
      }
    }
  }
}
 
Example 21
Project: Ironman   File: ReactTextTest.java   Source Code and License 6 votes vote down vote up
@Test
public void testTextDecorationLineUnderlineApplied() {
  UIManagerModule uiManager = getUIManagerModule();

  ReactRootView rootView = createText(
      uiManager,
      JavaOnlyMap.of(ViewProps.TEXT_DECORATION_LINE, "underline"),
      JavaOnlyMap.of(ReactTextShadowNode.PROP_TEXT, "test text"));

  TextView textView = (TextView) rootView.getChildAt(0);
  Spanned text = (Spanned) textView.getText();
  UnderlineSpan underlineSpan = getSingleSpan(textView, UnderlineSpan.class);
  StrikethroughSpan[] strikeThroughSpans =
      text.getSpans(0, text.length(), StrikethroughSpan.class);
  assertThat(underlineSpan instanceof UnderlineSpan).isTrue();
  assertThat(strikeThroughSpans).hasSize(0);
}
 
Example 22
Project: Ironman   File: ReactTextTest.java   Source Code and 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(ReactTextShadowNode.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 23
Project: Ironman   File: ReactTextTest.java   Source Code and License 6 votes vote down vote up
@Test
public void testTextDecorationLineUnderlineLineThroughApplied() {
  UIManagerModule uiManager = getUIManagerModule();

  ReactRootView rootView = createText(
      uiManager,
      JavaOnlyMap.of(ViewProps.TEXT_DECORATION_LINE, "underline line-through"),
      JavaOnlyMap.of(ReactTextShadowNode.PROP_TEXT, "test text"));

  UnderlineSpan underlineSpan =
      getSingleSpan((TextView) rootView.getChildAt(0), UnderlineSpan.class);
  StrikethroughSpan strikeThroughSpan =
      getSingleSpan((TextView) rootView.getChildAt(0), StrikethroughSpan.class);
  assertThat(underlineSpan instanceof UnderlineSpan).isTrue();
  assertThat(strikeThroughSpan instanceof StrikethroughSpan).isTrue();
}
 
Example 24
Project: memoir   File: ConverterSpannedToHtml.java   Source Code and License 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 25
Project: memoir   File: ConverterSpannedToHtml.java   Source Code and License 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 26
Project: Type   File: KnifeText.java   Source Code and License 6 votes vote down vote up
private void strikethroughInvalid(int start, int end) {
    if (start >= end) {
        return;
    }

    StrikethroughSpan[] spans = getEditableText().getSpans(start, end, StrikethroughSpan.class);
    List<KnifePart> list = new ArrayList<>();

    for (StrikethroughSpan span : spans) {
        list.add(new KnifePart(getEditableText().getSpanStart(span), getEditableText().getSpanEnd(span)));
        getEditableText().removeSpan(span);
    }

    for (KnifePart part : list) {
        if (part.isValid()) {
            if (part.getStart() < start) {
                strikethroughValid(part.getStart(), start);
            }

            if (part.getEnd() > end) {
                strikethroughValid(end, part.getEnd());
            }
        }
    }
}
 
Example 27
Project: Type   File: KnifeText.java   Source Code and License 6 votes vote down vote up
private boolean containStrikethrough(int start, int end) {
    if (start > end) {
        return false;
    }

    if (start == end) {
        if (start - 1 < 0 || start + 1 > getEditableText().length()) {
            return false;
        } else {
            StrikethroughSpan[] before = getEditableText().getSpans(start - 1, start, StrikethroughSpan.class);
            StrikethroughSpan[] after = getEditableText().getSpans(start, start + 1, StrikethroughSpan.class);
            return before.length > 0 && after.length > 0;
        }
    } else {
        StringBuilder builder = new StringBuilder();

        for (int i = start; i < end; i++) {
            if (getEditableText().getSpans(i, i + 1, StrikethroughSpan.class).length > 0) {
                builder.append(getEditableText().subSequence(i, i + 1).toString());
            }
        }

        return getEditableText().subSequence(start, end).toString().equals(builder.toString());
    }
}
 
Example 28
Project: S1-Next   File: HtmlTagHandlerCompat.java   Source Code and License 6 votes vote down vote up
public void handleEndTag(String tag) {
    if (tag.equalsIgnoreCase("ul")) {
        endBlockElement(mSpannableStringBuilder);
    } else if (tag.equalsIgnoreCase("li")) {
        endLi(mSpannableStringBuilder);
    } else if (tag.equalsIgnoreCase("span")) {
        endCssStyle(mSpannableStringBuilder);
    } 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 (mTagHandler != null) {
        mTagHandler.handleTag(false, tag, mSpannableStringBuilder, mReader);
    }
}
 
Example 29
Project: S1-Next   File: HtmlTagHandlerCompat.java   Source Code and License 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 30
Project: AndroidStudyDemo   File: CouponPriceUtil.java   Source Code and License 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 31
Project: Doctor   File: ConverterSpannedToHtml.java   Source Code and License 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 32
Project: materialistic   File: HackerNewsItem.java   Source Code and License 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 33
Project: FMTech   File: idd.java   Source Code and License 6 votes vote down vote up
public final void a(SpannableStringBuilder paramSpannableStringBuilder, int paramInt, qpa paramqpa)
{
  boolean bool1 = paramqpa.p().a;
  boolean bool2 = paramqpa.p().b;
  boolean bool3 = paramqpa.p().c;
  int i = paramSpannableStringBuilder.length();
  if ((bool1) && (bool2)) {
    paramSpannableStringBuilder.setSpan(new StyleSpan(3), paramInt, i, 33);
  }
  for (;;)
  {
    if (bool3) {
      paramSpannableStringBuilder.setSpan(new StrikethroughSpan(), paramInt, i, 33);
    }
    return;
    if (bool1) {
      paramSpannableStringBuilder.setSpan(new StyleSpan(1), paramInt, i, 33);
    } else if (bool2) {
      paramSpannableStringBuilder.setSpan(new StyleSpan(2), paramInt, i, 33);
    }
  }
}
 
Example 34
Project: FMTech   File: lwi.java   Source Code and License 6 votes vote down vote up
public final void handleTag(boolean paramBoolean, String paramString, Editable paramEditable, XMLReader paramXMLReader)
{
  String str = paramString.toLowerCase();
  if ((TextUtils.equals(str, "strike")) || (TextUtils.equals(str, "s")))
  {
    if (paramBoolean)
    {
      int i = paramEditable.length();
      paramEditable.setSpan(new StrikethroughSpan(), i, i, 17);
    }
  }
  else {
    return;
  }
  a(paramEditable);
}
 
Example 35
Project: FMTech   File: hfx.java   Source Code and License 6 votes vote down vote up
public final void a(SpannableStringBuilder paramSpannableStringBuilder, int paramInt, qop paramqop)
{
  boolean bool1 = efj.b(paramqop.c.a);
  boolean bool2 = efj.b(paramqop.c.b);
  boolean bool3 = efj.b(paramqop.c.c);
  int i = paramSpannableStringBuilder.length();
  if ((bool1) && (bool2)) {
    paramSpannableStringBuilder.setSpan(new StyleSpan(3), paramInt, i, 33);
  }
  for (;;)
  {
    if (bool3) {
      paramSpannableStringBuilder.setSpan(new StrikethroughSpan(), paramInt, i, 33);
    }
    return;
    if (bool1) {
      paramSpannableStringBuilder.setSpan(new StyleSpan(1), paramInt, i, 33);
    } else if (bool2) {
      paramSpannableStringBuilder.setSpan(new StyleSpan(2), paramInt, i, 33);
    }
  }
}
 
Example 36
Project: Android-RTEditor   File: ConverterSpannedToHtml.java   Source Code and License 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 37
Project: Knife   File: KnifeText.java   Source Code and License 6 votes vote down vote up
protected void strikethroughInvalid(int start, int end) {
    if (start >= end) {
        return;
    }

    StrikethroughSpan[] spans = getEditableText().getSpans(start, end, StrikethroughSpan.class);
    List<KnifePart> list = new ArrayList<>();

    for (StrikethroughSpan span : spans) {
        list.add(new KnifePart(getEditableText().getSpanStart(span), getEditableText().getSpanEnd(span)));
        getEditableText().removeSpan(span);
    }

    for (KnifePart part : list) {
        if (part.isValid()) {
            if (part.getStart() < start) {
                strikethroughValid(part.getStart(), start);
            }

            if (part.getEnd() > end) {
                strikethroughValid(end, part.getEnd());
            }
        }
    }
}
 
Example 38
Project: Knife   File: KnifeText.java   Source Code and License 6 votes vote down vote up
protected boolean containStrikethrough(int start, int end) {
    if (start > end) {
        return false;
    }

    if (start == end) {
        if (start - 1 < 0 || start + 1 > getEditableText().length()) {
            return false;
        } else {
            StrikethroughSpan[] before = getEditableText().getSpans(start - 1, start, StrikethroughSpan.class);
            StrikethroughSpan[] after = getEditableText().getSpans(start, start + 1, StrikethroughSpan.class);
            return before.length > 0 && after.length > 0;
        }
    } else {
        StringBuilder builder = new StringBuilder();

        for (int i = start; i < end; i++) {
            if (getEditableText().getSpans(i, i + 1, StrikethroughSpan.class).length > 0) {
                builder.append(getEditableText().subSequence(i, i + 1).toString());
            }
        }

        return getEditableText().subSequence(start, end).toString().equals(builder.toString());
    }
}
 
Example 39
Project: Knife   File: KnifeTagHandler.java   Source Code and License 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 40
Project: Slide   File: SpoilerRobotoTextView.java   Source Code and License 6 votes vote down vote up
private void setStrikethrough(SpannableStringBuilder builder) {
    final int offset = "[[d[".length(); // == "]d]]".length()

    int start = -1;
    int end;

    for (int i = 0; i < builder.length() - 3; i++) {
        if (builder.charAt(i) == '['
                && builder.charAt(i + 1) == '['
                && builder.charAt(i + 2) == 'd'
                && builder.charAt(i + 3) == '[') {
            start = i + offset;
        } else if (builder.charAt(i) == ']'
                && builder.charAt(i + 1) == 'd'
                && builder.charAt(i + 2) == ']'
                && builder.charAt(i + 3) == ']') {
            end = i;
            builder.setSpan(new StrikethroughSpan(), start, end,
                    Spanned.SPAN_INCLUSIVE_INCLUSIVE);
            builder.delete(end, end + offset);
            builder.delete(start - offset, start);
            i -= offset + (end - start); // length of text
        }
    }
}
 
Example 41
Project: ParcelGen   File: ParcelGenTest.java   Source Code and License 6 votes vote down vote up
@Test
public void testCharSequence() {

    final Spannable.Factory factory = Spannable.Factory.getInstance();

    final Spannable single = factory.newSpannable("Hello Single Spannable");
    single.setSpan(new UnderlineSpan(), 0, single.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);

    final Spannable s1 = factory.newSpannable("S1");
    s1.setSpan(new SuperscriptSpan(), 0, s1.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);

    final Spannable s2 = factory.newSpannable("[email protected]_dskfjsjdhfkjf");
    s2.setSpan(new StrikethroughSpan(), 0, s2.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);

    final SomeParcelableSibling sibling = new SomeParcelableSibling()
            .setCharSequence(single)
            .setCharSequenceArray(new CharSequence[]{s1, s2});

    assertParcelable(sibling, false);
}
 
Example 42
Project: sqlbrite   File: ItemsAdapter.java   Source Code and License 6 votes vote down vote up
@Override public View getView(int position, View convertView, ViewGroup parent) {
  if (convertView == null) {
    convertView = inflater.inflate(android.R.layout.simple_list_item_multiple_choice, parent, false);
  }

  TodoItem item = getItem(position);
  CheckedTextView textView = (CheckedTextView) convertView;
  textView.setChecked(item.complete());

  CharSequence description = item.description();
  if (item.complete()) {
    SpannableString spannable = new SpannableString(description);
    spannable.setSpan(new StrikethroughSpan(), 0, description.length(), 0);
    description = spannable;
  }

  textView.setText(description);

  return convertView;
}
 
Example 43
Project: cwac-richtextutils   File: ManualTests.java   Source Code and License 6 votes vote down vote up
public void testClassSpanTagHandler() throws IOException, SAXException, ParserConfigurationException {
  SpanTagRoster tagRoster=new SpanTagRoster();

  tagRoster.registerSpanTagHandler(new ClassSpanTagHandler<StrikethroughSpan>("myCustomClass") {
    @Override
    public StrikethroughSpan buildSpanForTag(String name, Attributes a, String context) {
      return(new StrikethroughSpan());
    }

    @Override
    public Class getSupportedCharacterStyle() {
      return(StrikethroughSpan.class);
    }
  });

  String input="The <span class=\"myCustomClass\">slow</span> quick brown fox jumped over the lazy dog.";
  Spanned fromInput=new SpannableStringGenerator(tagRoster).fromXhtml(input);
  String roundTrip=new SpannedXhtmlGenerator(tagRoster).toXhtml(fromInput);

  assertEquals(input, roundTrip);
}
 
Example 44
Project: markor   File: Highlighter.java   Source Code and License 5 votes vote down vote up
protected void clearSpans(Editable editable) {
    clearCharacterSpanType(editable, TextAppearanceSpan.class);
    clearCharacterSpanType(editable, ForegroundColorSpan.class);
    clearCharacterSpanType(editable, BackgroundColorSpan.class);
    clearCharacterSpanType(editable, StrikethroughSpan.class);
    clearCharacterSpanType(editable, RelativeSizeSpan.class);
    clearCharacterSpanType(editable, StyleSpan.class);
    clearCharacterSpanType(editable, ColorUnderlineSpan.class);
    clearParagraphSpanType(editable, LineBackgroundSpan.class);
    clearParagraphSpanType(editable, LineHeightSpan.class);
}
 
Example 45
Project: SpanEZ   File: SpanEZTest.java   Source Code and License 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 46
Project: weex-3d-map   File: WXTextDomObject.java   Source Code and 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) {
  List<SetSpanOperation> ops = new LinkedList<>();
  int start = 0;
  if (end >= start) {
    if (mTextDecoration == WXTextDecoration.UNDERLINE) {
      ops.add(new SetSpanOperation(start, end,
                                   new UnderlineSpan()));
    }
    if (mTextDecoration == WXTextDecoration.LINETHROUGH) {
      ops.add(new SetSpanOperation(start, end,
                                   new StrikethroughSpan()));
    }
    if (mIsColorSet) {
      ops.add(new SetSpanOperation(start, end,
                                   new ForegroundColorSpan(mColor)));
    }
    if (mFontSize != UNSET) {
      ops.add(new SetSpanOperation(start, end, new AbsoluteSizeSpan(mFontSize)));
    }
    if (mFontStyle != UNSET
        || mFontWeight != UNSET
        || mFontFamily != null) {
      ops.add(new SetSpanOperation(start, end,
                                   new WXCustomStyleSpan(mFontStyle, mFontWeight, mFontFamily)));
    }
    ops.add(new SetSpanOperation(start, end, new AlignmentSpan.Standard(mAlignment)));
    if (mLineHeight != UNSET) {
      ops.add(new SetSpanOperation(start, end, new WXLineHeightSpan(mLineHeight)));
    }
  }
  return ops;
}
 
Example 47
Project: amap   File: MIP_TextStyle.java   Source Code and License 5 votes vote down vote up
public MIP_TextStyle setStrikethroughSpan(int start, int end)
{
    if (spannableString == null)
    {
        return this;
    }
    spannableString.setSpan(new StrikethroughSpan(), start, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); // 设置前景色为洋红色
    return this;
}
 
Example 48
Project: GSLayout   File: GSLayoutLine.java   Source Code and License 5 votes vote down vote up
private void drawStrikeThrough(Canvas canvas) {
    if (!(text instanceof Spanned)) {
        return;
    }
    Spanned spanned = (Spanned) text;
    StrikethroughSpan[] spans = spanned.getSpans(start, end, StrikethroughSpan.class);
    if (spans == null || spans.length == 0) {
        return;
    }
    Paint paint = new Paint();
    paint.setAntiAlias(true);
    paint.setStyle(Paint.Style.STROKE);
    paint.setStrokeWidth(2); // TODO
    paint.setARGB(0xFF, 0, 0, 0); // TODO
    for (StrikethroughSpan span : spans) {
        RectF spanRect = getRect(span);
        if (spanRect == null) {
            continue;
        }
        spanRect.offset(originX, originY);
        if (vertical) {
            float lineX = (spanRect.left + spanRect.right) / 2;
            canvas.drawLine(lineX, spanRect.top, lineX, spanRect.bottom, paint);
        } else {
            float lineY = (spanRect.top + spanRect.bottom + originY) / 3;
            canvas.drawLine(spanRect.left, lineY, spanRect.right, lineY, paint);
        }
    }
}
 
Example 49
Project: spanner   File: Spans.java   Source Code and License 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 50
Project: DailyStudy   File: SpannableStringActivity.java   Source Code and License 5 votes vote down vote up
/**
 * StrikethroughSpan 删除线
 */

private void strikethrough () {
    SpannableString string = new SpannableString("设置文字的前景色为淡蓝色");
    StrikethroughSpan sizeSpan = new StrikethroughSpan();
    string.setSpan(sizeSpan, 0, 5, Spanned.SPAN_EXCLUSIVE_INCLUSIVE);
    bgtext.setText(string);
}
 
Example 51
Project: weex-uikit   File: WXTextDomObject.java   Source Code and 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 52
Project: RespawnIRC-Android   File: CustomTagHandler.java   Source Code and License 5 votes vote down vote up
@Override
public void handleTag(boolean opening, String tag, Editable output, XMLReader xmlReader) {
    if (tag.toLowerCase().equals("s")) {
        processAddOfSpan(opening, output, new StrikethroughSpan());
    } else if (tag.toLowerCase().equals("bg_spoil_button")) {
        processAddOfSpan(opening, output, new BackgroundColorSpan(ThemeManager.currentThemeUseDarkColors() ? Color.WHITE : Color.BLACK));
    } else if (tag.toLowerCase().equals("bg_spoil_content")) {
        processAddOfSpan(opening, output, new BackgroundColorSpan(ThemeManager.currentThemeUseDarkColors() ? almostDimGray : Color.LTGRAY));
    } else if (tag.toLowerCase().startsWith("holdstring_")) {
        String stringToHold = tag.substring(tag.indexOf("_") + 1);
        processAddOfSpan(opening, output, new HoldingStringSpan(stringToHold));
    }
}
 
Example 53
Project: ToBuy   File: ItemsItemViewModel.java   Source Code and License 5 votes vote down vote up
@Bindable
public CharSequence getText() {

    CharSequence description = text;
    if (complete) {
        SpannableString spannable = new SpannableString(description);
        spannable.setSpan(new StrikethroughSpan(), 0, description.length(), 0);
        description = spannable;
    }

    return description;
}
 
Example 54
Project: text-decorator   File: TextDecorator.java   Source Code and License 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 55
Project: weex-3d-map   File: WXTextDomObject.java   Source Code and 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) {
  List<SetSpanOperation> ops = new LinkedList<>();
  int start = 0;
  if (end >= start) {
    if (mTextDecoration == WXTextDecoration.UNDERLINE) {
      ops.add(new SetSpanOperation(start, end,
                                   new UnderlineSpan()));
    }
    if (mTextDecoration == WXTextDecoration.LINETHROUGH) {
      ops.add(new SetSpanOperation(start, end,
                                   new StrikethroughSpan()));
    }
    if (mIsColorSet) {
      ops.add(new SetSpanOperation(start, end,
                                   new ForegroundColorSpan(mColor)));
    }
    if (mFontSize != UNSET) {
      ops.add(new SetSpanOperation(start, end, new AbsoluteSizeSpan(mFontSize)));
    }
    if (mFontStyle != UNSET
        || mFontWeight != UNSET
        || mFontFamily != null) {
      ops.add(new SetSpanOperation(start, end,
                                   new WXCustomStyleSpan(mFontStyle, mFontWeight, mFontFamily)));
    }
    ops.add(new SetSpanOperation(start, end, new AlignmentSpan.Standard(mAlignment)));
    if (mLineHeight != UNSET) {
      ops.add(new SetSpanOperation(start, end, new WXLineHeightSpan(mLineHeight)));
    }
  }
  return ops;
}
 
Example 56
Project: xDrip   File: BestGlucose.java   Source Code and License 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 57
Project: xDrip-plus   File: BestGlucose.java   Source Code and License 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 58
Project: materialup   File: Post.java   Source Code and License 5 votes vote down vote up
public CharSequence getPrice() {
    if(price != null && price.lastIndexOf("$") > 0) {
        int i = price.lastIndexOf("$");
        SpannableStringBuilder ssb = new SpannableStringBuilder(price);
        ssb.setSpan(new ForegroundColorSpan(Color.GRAY),0,i-1, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        ssb.setSpan(new StrikethroughSpan(),0,i-1, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        return ssb;
    }
    return price;
}
 
Example 59
Project: redux   File: MainActivity.java   Source Code and License 5 votes vote down vote up
public void bind(int index, Object action) {
    this.index = index;
    if (replayMiddleware.isDisabled(index)) {
        SpannableString str = new SpannableString(action.toString());
        str.setSpan(new StrikethroughSpan(), 0, str.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        textView.setText(str);
    } else {
        textView.setText(action.toString());
    }
}
 
Example 60
Project: Weex-TestDemo   File: WXTextDomObject.java   Source Code and 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) {
  List<SetSpanOperation> ops = new LinkedList<>();
  int start = 0;
  if (end >= start) {
    if (mTextDecoration == WXTextDecoration.UNDERLINE) {
      ops.add(new SetSpanOperation(start, end,
                                   new UnderlineSpan()));
    }
    if (mTextDecoration == WXTextDecoration.LINETHROUGH) {
      ops.add(new SetSpanOperation(start, end,
                                   new StrikethroughSpan()));
    }
    if (mIsColorSet) {
      ops.add(new SetSpanOperation(start, end,
                                   new ForegroundColorSpan(mColor)));
    }
    if (mFontSize != UNSET) {
      ops.add(new SetSpanOperation(start, end, new AbsoluteSizeSpan(mFontSize)));
    }
    if (mFontStyle != UNSET
        || mFontWeight != UNSET
        || mFontFamily != null) {
      ops.add(new SetSpanOperation(start, end,
                                   new WXCustomStyleSpan(mFontStyle, mFontWeight, mFontFamily)));
    }
    ops.add(new SetSpanOperation(start, end, new AlignmentSpan.Standard(mAlignment)));
    if (mLineHeight != UNSET) {
      ops.add(new SetSpanOperation(start, end, new WXLineHeightSpan(mLineHeight)));
    }
  }
  return ops;
}