Search in sources :

Example 56 with StrikethroughSpan

use of android.text.style.StrikethroughSpan in project matrix-android-sdk by matrix-org.

the class HtmlTagHandler method handleTag.

@Override
public void handleTag(final boolean opening, final String tag, Editable output, final XMLReader xmlReader) {
    if (opening) {
        if (tag.equalsIgnoreCase("ul")) {
            lists.push(tag);
        } else if (tag.equalsIgnoreCase("ol")) {
            lists.push(tag);
            olNextIndex.push(1);
        } else if (tag.equalsIgnoreCase("li")) {
            if (output.length() > 0 && output.charAt(output.length() - 1) != '\n') {
                output.append("\n");
            }
            String parentList = lists.peek();
            if (parentList.equalsIgnoreCase("ol")) {
                start(output, new Ol());
                output.append(olNextIndex.peek().toString()).append(". ");
                olNextIndex.push(olNextIndex.pop() + 1);
            } else if (parentList.equalsIgnoreCase("ul")) {
                start(output, new Ul());
            }
        } else if (tag.equalsIgnoreCase("code")) {
            start(output, new Code());
        } else if (tag.equalsIgnoreCase("center")) {
            start(output, new Center());
        } else if (tag.equalsIgnoreCase("s") || tag.equalsIgnoreCase("strike")) {
            start(output, new Strike());
        } else if (tag.equalsIgnoreCase("table")) {
            start(output, new Table());
            if (tableTagLevel == 0) {
                tableHtmlBuilder = new StringBuilder();
                // We need some text for the table to be replaced by the span because
                // the other tags will remove their text when their text is extracted
                output.append("table placeholder");
            }
            tableTagLevel++;
        } else if (tag.equalsIgnoreCase("tr")) {
            start(output, new Tr());
        } else if (tag.equalsIgnoreCase("th")) {
            start(output, new Th());
        } else if (tag.equalsIgnoreCase("td")) {
            start(output, new Td());
        }
    } else {
        if (tag.equalsIgnoreCase("ul")) {
            lists.pop();
        } else if (tag.equalsIgnoreCase("ol")) {
            lists.pop();
            olNextIndex.pop();
        } else if (tag.equalsIgnoreCase("li")) {
            if (lists.peek().equalsIgnoreCase("ul")) {
                if (output.length() > 0 && output.charAt(output.length() - 1) != '\n') {
                    output.append("\n");
                }
                // Nested BulletSpans increases distance between bullet and text, so we must prevent it.
                int bulletMargin = indent;
                if (lists.size() > 1) {
                    bulletMargin = indent - bullet.getLeadingMargin(true);
                    if (lists.size() > 2) {
                        // This get's more complicated when we add a LeadingMarginSpan into the same line:
                        // we have also counter it's effect to BulletSpan
                        bulletMargin -= (lists.size() - 2) * listItemIndent;
                    }
                }
                BulletSpan newBullet = new BulletSpan(bulletMargin);
                end(output, Ul.class, false, new LeadingMarginSpan.Standard(listItemIndent * (lists.size() - 1)), newBullet);
            } else if (lists.peek().equalsIgnoreCase("ol")) {
                if (output.length() > 0 && output.charAt(output.length() - 1) != '\n') {
                    output.append("\n");
                }
                int numberMargin = listItemIndent * (lists.size() - 1);
                if (lists.size() > 2) {
                    // Same as in ordered lists: counter the effect of nested Spans
                    numberMargin -= (lists.size() - 2) * listItemIndent;
                }
                end(output, Ol.class, false, new LeadingMarginSpan.Standard(numberMargin));
            }
        } else if (tag.equalsIgnoreCase("code")) {
            if (-1 == mCodeBlockBackgroundColor) {
                mCodeBlockBackgroundColor = ContextCompat.getColor(mContext, android.R.color.darker_gray);
            }
            end(output, Code.class, false, new BackgroundColorSpan(mCodeBlockBackgroundColor), new TypefaceSpan("monospace"));
        } else if (tag.equalsIgnoreCase("center")) {
            end(output, Center.class, true, new AlignmentSpan.Standard(Layout.Alignment.ALIGN_CENTER));
        } else if (tag.equalsIgnoreCase("s") || tag.equalsIgnoreCase("strike")) {
            end(output, Strike.class, false, new StrikethroughSpan());
        } else if (tag.equalsIgnoreCase("table")) {
            tableTagLevel--;
            // When we're back at the root-level table
            end(output, Table.class, false);
        } else if (tag.equalsIgnoreCase("tr")) {
            end(output, Tr.class, false);
        } else if (tag.equalsIgnoreCase("th")) {
            end(output, Th.class, false);
        } else if (tag.equalsIgnoreCase("td")) {
            end(output, Td.class, false);
        }
    }
    storeTableTags(opening, tag);
}
Also used : AlignmentSpan(android.text.style.AlignmentSpan) BulletSpan(android.text.style.BulletSpan) LeadingMarginSpan(android.text.style.LeadingMarginSpan) BackgroundColorSpan(android.text.style.BackgroundColorSpan) TypefaceSpan(android.text.style.TypefaceSpan) StrikethroughSpan(android.text.style.StrikethroughSpan)

Example 57 with StrikethroughSpan

use of android.text.style.StrikethroughSpan in project MyDiary by erttyy8821.

the class MemoAdapter method setMemoContent.

private void setMemoContent(MemoViewHolder holder, final int position) {
    if (memoList.get(position).isChecked()) {
        SpannableString spannableContent = new SpannableString(memoList.get(position).getContent());
        spannableContent.setSpan(new StrikethroughSpan(), 0, spannableContent.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        holder.getTVContent().setText(spannableContent);
        holder.getTVContent().setAlpha(0.4F);
    } else {
        holder.getTVContent().setText(memoList.get(position).getContent());
        holder.getTVContent().setAlpha(1F);
    }
}
Also used : SpannableString(android.text.SpannableString) StrikethroughSpan(android.text.style.StrikethroughSpan)

Example 58 with StrikethroughSpan

use of android.text.style.StrikethroughSpan in project MarkyMark-Android by M2Mobi.

the class StrikeInlineDisplayItem method create.

@Override
public Spanned create(final InlineConverter<Spanned> pInlineConverter, final StrikeString pMarkDownString) {
    final Spannable spannable = SpannableUtils.createSpannable(pInlineConverter, pMarkDownString);
    spannable.setSpan(new StrikethroughSpan(), 0, spannable.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
    return spannable;
}
Also used : Spannable(android.text.Spannable) StrikethroughSpan(android.text.style.StrikethroughSpan)

Example 59 with StrikethroughSpan

use of android.text.style.StrikethroughSpan in project ForPDA by RadiationX.

the class HtmlToSpannedConverter method endCssStyle.

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));
    }
}
Also used : ForegroundColorSpan(android.text.style.ForegroundColorSpan) BackgroundColorSpan(android.text.style.BackgroundColorSpan) StrikethroughSpan(android.text.style.StrikethroughSpan)

Aggregations

StrikethroughSpan (android.text.style.StrikethroughSpan)59 ForegroundColorSpan (android.text.style.ForegroundColorSpan)27 StyleSpan (android.text.style.StyleSpan)27 TypefaceSpan (android.text.style.TypefaceSpan)24 BackgroundColorSpan (android.text.style.BackgroundColorSpan)23 UnderlineSpan (android.text.style.UnderlineSpan)20 RelativeSizeSpan (android.text.style.RelativeSizeSpan)19 AbsoluteSizeSpan (android.text.style.AbsoluteSizeSpan)16 SpannableString (android.text.SpannableString)15 SubscriptSpan (android.text.style.SubscriptSpan)15 SuperscriptSpan (android.text.style.SuperscriptSpan)15 URLSpan (android.text.style.URLSpan)14 LeadingMarginSpan (android.text.style.LeadingMarginSpan)11 CharacterStyle (android.text.style.CharacterStyle)9 ImageSpan (android.text.style.ImageSpan)9 SpannableStringBuilder (android.text.SpannableStringBuilder)8 TextPaint (android.text.TextPaint)7 QuoteSpan (android.text.style.QuoteSpan)7 Application (android.app.Application)6 AlignmentSpan (android.text.style.AlignmentSpan)6