Search in sources :

Example 56 with RelativeSizeSpan

use of android.text.style.RelativeSizeSpan in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class DataUsageSummary method verySmallSpanExcept.

private static void verySmallSpanExcept(SpannableString s, CharSequence exception) {
    final float SIZE = 0.8f * 0.8f;
    final int FLAGS = Spannable.SPAN_INCLUSIVE_INCLUSIVE;
    final int exceptionStart = TextUtils.indexOf(s, exception);
    if (exceptionStart == -1) {
        s.setSpan(new RelativeSizeSpan(SIZE), 0, s.length(), FLAGS);
    } else {
        if (exceptionStart > 0) {
            s.setSpan(new RelativeSizeSpan(SIZE), 0, exceptionStart, FLAGS);
        }
        final int exceptionEnd = exceptionStart + exception.length();
        if (exceptionEnd < s.length()) {
            s.setSpan(new RelativeSizeSpan(SIZE), exceptionEnd, s.length(), FLAGS);
        }
    }
}
Also used : RelativeSizeSpan(android.text.style.RelativeSizeSpan)

Example 57 with RelativeSizeSpan

use of android.text.style.RelativeSizeSpan in project android_frameworks_base by DirtyUnicorns.

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 58 with RelativeSizeSpan

use of android.text.style.RelativeSizeSpan in project android_frameworks_base by DirtyUnicorns.

the class HtmlToSpannedConverter method endHeading.

private static void endHeading(Editable text) {
    // RelativeSizeSpan and StyleSpan are CharacterStyles
    // Their ranges should not include the newlines at the end
    Heading h = getLast(text, Heading.class);
    if (h != null) {
        setSpanFromMark(text, h, new RelativeSizeSpan(HEADING_SIZES[h.mLevel]), new StyleSpan(Typeface.BOLD));
    }
    endBlockElement(text);
}
Also used : StyleSpan(android.text.style.StyleSpan) RelativeSizeSpan(android.text.style.RelativeSizeSpan)

Example 59 with RelativeSizeSpan

use of android.text.style.RelativeSizeSpan in project MPAndroidChart by PhilJay.

the class HalfPieChartActivity method generateCenterSpannableText.

private SpannableString generateCenterSpannableText() {
    SpannableString s = new SpannableString("MPAndroidChart\ndeveloped by Philipp Jahoda");
    s.setSpan(new RelativeSizeSpan(1.7f), 0, 14, 0);
    s.setSpan(new StyleSpan(Typeface.NORMAL), 14, s.length() - 15, 0);
    s.setSpan(new ForegroundColorSpan(Color.GRAY), 14, s.length() - 15, 0);
    s.setSpan(new RelativeSizeSpan(.8f), 14, s.length() - 15, 0);
    s.setSpan(new StyleSpan(Typeface.ITALIC), s.length() - 14, s.length(), 0);
    s.setSpan(new ForegroundColorSpan(ColorTemplate.getHoloBlue()), s.length() - 14, s.length(), 0);
    return s;
}
Also used : SpannableString(android.text.SpannableString) ForegroundColorSpan(android.text.style.ForegroundColorSpan) StyleSpan(android.text.style.StyleSpan) RelativeSizeSpan(android.text.style.RelativeSizeSpan)

Example 60 with RelativeSizeSpan

use of android.text.style.RelativeSizeSpan in project MPAndroidChart by PhilJay.

the class PieChartActivity method generateCenterSpannableText.

private SpannableString generateCenterSpannableText() {
    SpannableString s = new SpannableString("MPAndroidChart\ndeveloped by Philipp Jahoda");
    s.setSpan(new RelativeSizeSpan(1.7f), 0, 14, 0);
    s.setSpan(new StyleSpan(Typeface.NORMAL), 14, s.length() - 15, 0);
    s.setSpan(new ForegroundColorSpan(Color.GRAY), 14, s.length() - 15, 0);
    s.setSpan(new RelativeSizeSpan(.8f), 14, s.length() - 15, 0);
    s.setSpan(new StyleSpan(Typeface.ITALIC), s.length() - 14, s.length(), 0);
    s.setSpan(new ForegroundColorSpan(ColorTemplate.getHoloBlue()), s.length() - 14, s.length(), 0);
    return s;
}
Also used : SpannableString(android.text.SpannableString) ForegroundColorSpan(android.text.style.ForegroundColorSpan) StyleSpan(android.text.style.StyleSpan) RelativeSizeSpan(android.text.style.RelativeSizeSpan)

Aggregations

RelativeSizeSpan (android.text.style.RelativeSizeSpan)65 StyleSpan (android.text.style.StyleSpan)32 ForegroundColorSpan (android.text.style.ForegroundColorSpan)22 SpannableString (android.text.SpannableString)19 SpannableStringBuilder (android.text.SpannableStringBuilder)17 CharacterStyle (android.text.style.CharacterStyle)16 AbsoluteSizeSpan (android.text.style.AbsoluteSizeSpan)10 SuperscriptSpan (android.text.style.SuperscriptSpan)10 TypefaceSpan (android.text.style.TypefaceSpan)10 JustifiedSpan (com.bluejamesbond.text.style.JustifiedSpan)9 ArticleBuilder (com.bluejamesbond.text.util.ArticleBuilder)9 SubscriptSpan (android.text.style.SubscriptSpan)8 ImageSpan (android.text.style.ImageSpan)7 StrikethroughSpan (android.text.style.StrikethroughSpan)7 UnderlineSpan (android.text.style.UnderlineSpan)7 LeftSpan (com.bluejamesbond.text.style.LeftSpan)7 SimpleDateFormat (java.text.SimpleDateFormat)7 Context (android.content.Context)6 BackgroundColorSpan (android.text.style.BackgroundColorSpan)6 MyQuoteSpan (com.bluejamesbond.text.sample.helper.MyQuoteSpan)6