Example usage for android.text.style TextAppearanceSpan TextAppearanceSpan

List of usage examples for android.text.style TextAppearanceSpan TextAppearanceSpan

Introduction

In this page you can find the example usage for android.text.style TextAppearanceSpan TextAppearanceSpan.

Prototype

public TextAppearanceSpan(String family, int style, int size, ColorStateList color, ColorStateList linkColor) 

Source Link

Document

Makes text be drawn with the specified typeface, size, style, and colors.

Usage

From source file:com.thatkawaiiguy.meleehandbook.adapter.SearchAdapter.java

private void highlight(String search, String originalText, TextView textView) {
    int startPos = originalText.toLowerCase(Locale.US).indexOf(search.toLowerCase(Locale.US));
    int endPos = startPos + search.length();

    if (startPos != -1) {
        Spannable spannable = new SpannableString(originalText);
        ColorStateList yellowColor = new ColorStateList(new int[][] { new int[] {} },
                new int[] { ContextCompat.getColor(mContext, R.color.overscroll_color) });
        TextAppearanceSpan highlightSpan = new TextAppearanceSpan(null, Typeface.BOLD, -1, yellowColor, null);

        spannable.setSpan(highlightSpan, startPos, endPos, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        textView.setText(spannable);/*  w w  w .  jav a  2s  . c om*/
    } else
        textView.setText(originalText);
}

From source file:com.thatkawaiiguy.meleehandbook.adapter.SearchAdapter.java

private void highlightAndCut(String search, String originalText, TextView textView) {
    int startPos = originalText.toLowerCase().indexOf(search);
    int endPos = startPos + search.length();

    int wholeStart = originalText.toLowerCase().indexOf(" ", startPos - 100);
    if (wholeStart == -1)
        wholeStart = 0;/*from   w  w  w .  j  a  v a 2 s .  c o  m*/

    if (originalText.substring(wholeStart, wholeStart + 1).equals(","))
        wholeStart += 1;

    int wholeEnd = originalText.toLowerCase().indexOf(" ",
            endPos + 100 < originalText.length() - 1 ? endPos + 100 : endPos - search.length() - 1);

    if (wholeEnd == -1)
        wholeEnd = endPos;

    originalText = originalText.substring(wholeStart, wholeEnd).trim() + " (Click for more)";

    startPos = originalText.toLowerCase().indexOf(search);
    endPos = startPos + search.length();
    // This should always be true, just a sanity check
    if (startPos != -1) {
        Spannable spannable = new SpannableString(originalText);
        ColorStateList yellowColor = new ColorStateList(new int[][] { new int[] {} },
                new int[] { ContextCompat.getColor(mContext, R.color.overscroll_color) });
        TextAppearanceSpan highlightSpan = new TextAppearanceSpan(null, Typeface.BOLD, -1, yellowColor, null);

        spannable.setSpan(highlightSpan, startPos, endPos, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        textView.setText(spannable);
    } else
        textView.setText(originalText);
}

From source file:tk.wasdennnoch.androidn_ify.utils.NotificationColorUtil.java

private TextAppearanceSpan processTextAppearanceSpan(TextAppearanceSpan span) {
    ColorStateList colorStateList = span.getTextColor();
    if (colorStateList != null) {
        int[] colors = (int[]) XposedHelpers.callMethod(colorStateList, "getColors");
        boolean changed = false;
        for (int i = 0; i < colors.length; i++) {
            if (ImageUtils.isGrayscale(colors[i])) {

                // Allocate a new array so we don't change the colors in the old color state
                // list.
                if (!changed) {
                    colors = Arrays.copyOf(colors, colors.length);
                }//from www .j av  a2s  .c o m
                colors[i] = processColor(colors[i]);
                changed = true;
            }
        }
        if (changed) {
            return new TextAppearanceSpan(span.getFamily(), span.getTextStyle(), span.getTextSize(),
                    new ColorStateList((int[][]) XposedHelpers.callMethod(colorStateList, "getStates"), colors),
                    span.getLinkTextColor());
        }
    }
    return span;
}

From source file:com.android.tv.guide.ProgramItemView.java

private void initIfNeeded() {
    if (sVisibleThreshold != 0) {
        return;/*from w  w  w  .  j a  v  a 2 s  .  c  o  m*/
    }
    Resources res = getContext().getResources();

    sVisibleThreshold = res.getDimensionPixelOffset(R.dimen.program_guide_table_item_visible_threshold);

    sItemPadding = res.getDimensionPixelOffset(R.dimen.program_guide_table_item_padding);

    ColorStateList programTitleColor = ColorStateList
            .valueOf(Utils.getColor(res, R.color.program_guide_table_item_program_title_text_color));
    ColorStateList grayedOutProgramTitleColor = Utils.getColorStateList(res,
            R.color.program_guide_table_item_grayed_out_program_text_color);
    ColorStateList episodeTitleColor = ColorStateList
            .valueOf(Utils.getColor(res, R.color.program_guide_table_item_program_episode_title_text_color));
    ColorStateList grayedOutEpisodeTitleColor = ColorStateList.valueOf(
            Utils.getColor(res, R.color.program_guide_table_item_grayed_out_program_episode_title_text_color));
    int programTitleSize = res.getDimensionPixelSize(R.dimen.program_guide_table_item_program_title_font_size);
    int episodeTitleSize = res
            .getDimensionPixelSize(R.dimen.program_guide_table_item_program_episode_title_font_size);

    sProgramTitleStyle = new TextAppearanceSpan(null, 0, programTitleSize, programTitleColor, null);
    sGrayedOutProgramTitleStyle = new TextAppearanceSpan(null, 0, programTitleSize, grayedOutProgramTitleColor,
            null);
    sEpisodeTitleStyle = new TextAppearanceSpan(null, 0, episodeTitleSize, episodeTitleColor, null);
    sGrayedOutEpisodeTitleStyle = new TextAppearanceSpan(null, 0, episodeTitleSize, grayedOutEpisodeTitleColor,
            null);
}

From source file:com.aboveware.sms.contacts.ContactSuggestionsAdapter.java

private CharSequence formatUrl(CharSequence url) {
    if (mUrlColor == null) {
        // Lazily get the URL color from the current theme.
        TypedValue colorValue = new TypedValue();
        mContext.getTheme().resolveAttribute(R.attr.textColorSearchUrl, colorValue, true);
        mUrlColor = mContext.getResources().getColorStateList(colorValue.resourceId);
    }/*  w ww. j  a  v a  2  s .c om*/

    SpannableString text = new SpannableString(url);
    text.setSpan(new TextAppearanceSpan(null, 0, 0, mUrlColor, null), 0, url.length(),
            Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
    return text;
}

From source file:android.support.v7.widget.SuggestionsAdapter.java

private CharSequence formatUrl(CharSequence url) {
    if (mUrlColor == null) {
        // Lazily get the URL color from the current theme.
        TypedValue colorValue = new TypedValue();
        mContext.getTheme().resolveAttribute(R.attr.textColorSearchUrl, colorValue, true);
        mUrlColor = mContext.getResources().getColorStateList(colorValue.resourceId);
    }/*from  w  w w. j av a  2  s.  c  o m*/

    SpannableString text = new SpannableString(url);
    text.setSpan(new TextAppearanceSpan(null, 0, 0, mUrlColor, null), 0, url.length(),
            Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
    return text;
}

From source file:android.support.v7ox.widget.SuggestionsAdapter.java

private CharSequence formatUrl(CharSequence url) {
    if (mUrlColor == null) {
        // Lazily get the URL color from the current theme.
        TypedValue colorValue = new TypedValue();
        mContext.getTheme().resolveAttribute(R.attr.textColorSearchUrl_ox, colorValue, true);
        mUrlColor = mContext.getResources().getColorStateList(colorValue.resourceId);
    }//from   ww  w.  j  a  v  a 2  s. co m

    SpannableString text = new SpannableString(url);
    text.setSpan(new TextAppearanceSpan(null, 0, 0, mUrlColor, null), 0, url.length(),
            Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
    return text;
}

From source file:com.zulip.android.util.CustomHtmlToSpannedConverter.java

private static void endFont(SpannableStringBuilder text) {
    int len = text.length();
    Object obj = getLast(text, Font.class);
    int where = text.getSpanStart(obj);

    text.removeSpan(obj);/*from www.j a  v a2  s  . c om*/

    if (where != len) {
        Font f = (Font) obj;

        if (!TextUtils.isEmpty(f.mColor)) {
            if (f.mColor.startsWith("@")) {
                Resources res = Resources.getSystem();
                String name = f.mColor.substring(1);
                int colorRes = res.getIdentifier(name, "color", "android");
                if (colorRes != 0) {
                    ColorStateList colors = res.getColorStateList(colorRes);
                    text.setSpan(new TextAppearanceSpan(null, 0, 0, colors, null), where, len,
                            Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
                }
            } else {
                int c = getHtmlColor(f.mColor);
                if (c != -1) {
                    text.setSpan(new ForegroundColorSpan(c | 0xFF000000), where, len,
                            Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
                }
            }
        }

        if (f.mFace != null) {
            text.setSpan(new TypefaceSpan(f.mFace), where, len, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        }
    }
}

From source file:com.tandong.sa.sherlock.widget.SuggestionsAdapter.java

private CharSequence formatUrl(CharSequence url) {
    if (mUrlColor == null) {
        // Lazily get the URL color from the current theme.
        TypedValue colorValue = new TypedValue();
        mContext.getTheme().resolveAttribute(
                mContext.getResources().getIdentifier("textColorSearchUrl", "attr", mContext.getPackageName()),
                // mContext.getTheme().resolveAttribute(R.attr.textColorSearchUrl,
                colorValue, true);//from  www .j a va 2s. com
        mUrlColor = mContext.getResources().getColorStateList(colorValue.resourceId);
    }

    SpannableString text = new SpannableString(url);
    text.setSpan(new TextAppearanceSpan(null, 0, 0, mUrlColor, null), 0, url.length(),
            Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
    return text;
}

From source file:com.nttec.everychan.ui.presentation.HtmlParser.java

private static void endFont(SpannableStringBuilder text) {
    int len = text.length();
    Object obj = getLast(text, Font.class);
    int where = text.getSpanStart(obj);

    text.removeSpan(obj);/*from ww w  .  j  a v  a2 s . co m*/

    if (where != len) {
        Font f = (Font) obj;

        if (!TextUtils.isEmpty(f.mColor)) {
            if (f.mColor.startsWith("@")) {
                Resources res = Resources.getSystem();
                String name = f.mColor.substring(1);
                int colorRes = res.getIdentifier(name, "color", "android");
                if (colorRes != 0) {
                    ColorStateList colors = CompatibilityUtils.getColorStateList(res, colorRes);
                    text.setSpan(new TextAppearanceSpan(null, 0, 0, colors, null), where, len,
                            Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
                }
            } else {
                int c = ColorHidden.getHtmlColor(f.mColor);
                if (c != -1) {
                    text.setSpan(new ForegroundColorSpan(c | 0xFF000000), where, len,
                            Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
                }
            }
        }

        if (f.mFace != null) {
            text.setSpan(new TypefaceSpan(f.mFace), where, len, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        }

        if (f.mStyle != null) {
            List<Object> styleSpans = parseStyleAttributes(f.mStyle);
            for (Object span : styleSpans) {
                text.setSpan(span, where, len, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
            }
        }
    }
}