Search in sources :

Example 16 with StrikethroughSpan

use of android.text.style.StrikethroughSpan in project Reader by TheKeeperOfPie.

the class TagHandlerReddit method handleTag.

@Override
public void handleTag(boolean opening, String tag, Editable output, XMLReader xmlReader) {
    if (tag.equalsIgnoreCase("del") || tag.equalsIgnoreCase("strike") || tag.equals("s")) {
        if (opening) {
            start(output, new Strike());
        } else {
            end(output, Strike.class, new StrikethroughSpan());
        }
    } else if (tag.equalsIgnoreCase("ul")) {
        if (opening) {
            lists.push(tag);
        } else {
            lists.pop();
        }
    } else if (tag.equalsIgnoreCase("ol")) {
        if (opening) {
            lists.push(tag);
            olNextIndex.push(1);
        } else {
            lists.pop();
            olNextIndex.pop();
        }
    } else if (tag.equalsIgnoreCase("li")) {
        if (opening) {
            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(String.valueOf(olNextIndex.peek())).append(". ");
                olNextIndex.push(olNextIndex.pop() + 1);
            } else if (parentList.equalsIgnoreCase("ul")) {
                start(output, new Ul());
            }
        } else {
            if (lists.peek().equalsIgnoreCase("ul")) {
                if (output.length() > 0 && output.charAt(output.length() - 1) != '\n') {
                    output.append("\n");
                }
                int bulletMargin = indent;
                if (lists.size() > 1) {
                    bulletMargin = indent - bullet.getLeadingMargin(true);
                    if (lists.size() > 2) {
                        bulletMargin -= (lists.size() - 2) * listItemIndent;
                    }
                }
                BulletSpan newBullet = new BulletSpan(bulletMargin);
                end(output, Ul.class, 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) {
                    numberMargin -= (lists.size() - 2) * listItemIndent;
                }
                end(output, Ol.class, new LeadingMarginSpan.Standard(numberMargin));
            }
        }
    }
}
Also used : BulletSpan(android.text.style.BulletSpan) LeadingMarginSpan(android.text.style.LeadingMarginSpan) StrikethroughSpan(android.text.style.StrikethroughSpan)

Example 17 with StrikethroughSpan

use of android.text.style.StrikethroughSpan in project weiciyuan by qii.

the class UpdateMessageTask method setTextViewDeleted.

private void setTextViewDeleted(TextView tv) {
    SpannableString ss = SpannableString.valueOf(tv.getText());
    ss.setSpan(new StrikethroughSpan(), 0, ss.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
    tv.setText(ss);
}
Also used : SpannableString(android.text.SpannableString) StrikethroughSpan(android.text.style.StrikethroughSpan)

Example 18 with StrikethroughSpan

use of android.text.style.StrikethroughSpan in project platform_frameworks_base by android.

the class HtmlToSpannedConverter method withinParagraph.

private static void withinParagraph(StringBuilder out, Spanned text, int start, int end) {
    int next;
    for (int i = start; i < end; i = next) {
        next = text.nextSpanTransition(i, end, CharacterStyle.class);
        CharacterStyle[] style = text.getSpans(i, next, CharacterStyle.class);
        for (int j = 0; j < style.length; j++) {
            if (style[j] instanceof StyleSpan) {
                int s = ((StyleSpan) style[j]).getStyle();
                if ((s & Typeface.BOLD) != 0) {
                    out.append("<b>");
                }
                if ((s & Typeface.ITALIC) != 0) {
                    out.append("<i>");
                }
            }
            if (style[j] instanceof TypefaceSpan) {
                String s = ((TypefaceSpan) style[j]).getFamily();
                if ("monospace".equals(s)) {
                    out.append("<tt>");
                }
            }
            if (style[j] instanceof SuperscriptSpan) {
                out.append("<sup>");
            }
            if (style[j] instanceof SubscriptSpan) {
                out.append("<sub>");
            }
            if (style[j] instanceof UnderlineSpan) {
                out.append("<u>");
            }
            if (style[j] instanceof StrikethroughSpan) {
                out.append("<span style=\"text-decoration:line-through;\">");
            }
            if (style[j] instanceof URLSpan) {
                out.append("<a href=\"");
                out.append(((URLSpan) style[j]).getURL());
                out.append("\">");
            }
            if (style[j] instanceof ImageSpan) {
                out.append("<img src=\"");
                out.append(((ImageSpan) style[j]).getSource());
                out.append("\">");
                // Don't output the dummy character underlying the image.
                i = next;
            }
            if (style[j] instanceof AbsoluteSizeSpan) {
                AbsoluteSizeSpan s = ((AbsoluteSizeSpan) style[j]);
                float sizeDip = s.getSize();
                if (!s.getDip()) {
                    Application application = ActivityThread.currentApplication();
                    sizeDip /= application.getResources().getDisplayMetrics().density;
                }
                // px in CSS is the equivalance of dip in Android
                out.append(String.format("<span style=\"font-size:%.0fpx\";>", sizeDip));
            }
            if (style[j] instanceof RelativeSizeSpan) {
                float sizeEm = ((RelativeSizeSpan) style[j]).getSizeChange();
                out.append(String.format("<span style=\"font-size:%.2fem;\">", sizeEm));
            }
            if (style[j] instanceof ForegroundColorSpan) {
                int color = ((ForegroundColorSpan) style[j]).getForegroundColor();
                out.append(String.format("<span style=\"color:#%06X;\">", 0xFFFFFF & color));
            }
            if (style[j] instanceof BackgroundColorSpan) {
                int color = ((BackgroundColorSpan) style[j]).getBackgroundColor();
                out.append(String.format("<span style=\"background-color:#%06X;\">", 0xFFFFFF & color));
            }
        }
        withinStyle(out, text, i, next);
        for (int j = style.length - 1; j >= 0; j--) {
            if (style[j] instanceof BackgroundColorSpan) {
                out.append("</span>");
            }
            if (style[j] instanceof ForegroundColorSpan) {
                out.append("</span>");
            }
            if (style[j] instanceof RelativeSizeSpan) {
                out.append("</span>");
            }
            if (style[j] instanceof AbsoluteSizeSpan) {
                out.append("</span>");
            }
            if (style[j] instanceof URLSpan) {
                out.append("</a>");
            }
            if (style[j] instanceof StrikethroughSpan) {
                out.append("</span>");
            }
            if (style[j] instanceof UnderlineSpan) {
                out.append("</u>");
            }
            if (style[j] instanceof SubscriptSpan) {
                out.append("</sub>");
            }
            if (style[j] instanceof SuperscriptSpan) {
                out.append("</sup>");
            }
            if (style[j] instanceof TypefaceSpan) {
                String s = ((TypefaceSpan) style[j]).getFamily();
                if (s.equals("monospace")) {
                    out.append("</tt>");
                }
            }
            if (style[j] instanceof StyleSpan) {
                int s = ((StyleSpan) style[j]).getStyle();
                if ((s & Typeface.BOLD) != 0) {
                    out.append("</b>");
                }
                if ((s & Typeface.ITALIC) != 0) {
                    out.append("</i>");
                }
            }
        }
    }
}
Also used : SuperscriptSpan(android.text.style.SuperscriptSpan) ForegroundColorSpan(android.text.style.ForegroundColorSpan) RelativeSizeSpan(android.text.style.RelativeSizeSpan) URLSpan(android.text.style.URLSpan) CharacterStyle(android.text.style.CharacterStyle) UnderlineSpan(android.text.style.UnderlineSpan) AbsoluteSizeSpan(android.text.style.AbsoluteSizeSpan) StyleSpan(android.text.style.StyleSpan) SubscriptSpan(android.text.style.SubscriptSpan) Application(android.app.Application) BackgroundColorSpan(android.text.style.BackgroundColorSpan) TypefaceSpan(android.text.style.TypefaceSpan) StrikethroughSpan(android.text.style.StrikethroughSpan) ImageSpan(android.text.style.ImageSpan)

Example 19 with StrikethroughSpan

use of android.text.style.StrikethroughSpan in project platform_frameworks_base by android.

the class HtmlToSpannedConverter method endCssStyle.

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

Example 20 with StrikethroughSpan

use of android.text.style.StrikethroughSpan in project sqlbrite by square.

the class ItemsAdapter method getView.

@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;
}
Also used : SpannableString(android.text.SpannableString) TodoItem(com.example.sqlbrite.todo.db.TodoItem) CheckedTextView(android.widget.CheckedTextView) StrikethroughSpan(android.text.style.StrikethroughSpan)

Aggregations

StrikethroughSpan (android.text.style.StrikethroughSpan)31 ForegroundColorSpan (android.text.style.ForegroundColorSpan)14 StyleSpan (android.text.style.StyleSpan)12 BackgroundColorSpan (android.text.style.BackgroundColorSpan)11 TypefaceSpan (android.text.style.TypefaceSpan)10 SpannableString (android.text.SpannableString)8 AbsoluteSizeSpan (android.text.style.AbsoluteSizeSpan)8 SubscriptSpan (android.text.style.SubscriptSpan)8 SuperscriptSpan (android.text.style.SuperscriptSpan)8 UnderlineSpan (android.text.style.UnderlineSpan)8 RelativeSizeSpan (android.text.style.RelativeSizeSpan)7 URLSpan (android.text.style.URLSpan)7 CharacterStyle (android.text.style.CharacterStyle)6 Application (android.app.Application)5 ImageSpan (android.text.style.ImageSpan)5 SpannableStringBuilder (android.text.SpannableStringBuilder)4 WPUnderlineSpan (org.wordpress.android.util.helpers.WPUnderlineSpan)4 Spannable (android.text.Spannable)3 LeadingMarginSpan (android.text.style.LeadingMarginSpan)3 QuoteSpan (android.text.style.QuoteSpan)3