Example usage for android.text.style ForegroundColorSpan ForegroundColorSpan

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

Introduction

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

Prototype

public ForegroundColorSpan(@NonNull Parcel src) 

Source Link

Document

Creates a ForegroundColorSpan from a parcel.

Usage

From source file:org.sufficientlysecure.keychain.ui.adapter.HighlightQueryCursorAdapter.java

protected Spannable highlightSearchQuery(String text) {
    Spannable highlight = Spannable.Factory.getInstance().newSpannable(text);

    if (mCurQuery != null) {
        Pattern pattern = Pattern.compile("(?i)" + mCurQuery);
        Matcher matcher = pattern.matcher(text);
        if (matcher.find()) {
            highlight.setSpan(new ForegroundColorSpan(mContext.getResources().getColor(R.color.emphasis)),
                    matcher.start(), matcher.end(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        }/*from   w w w.  j a v a2  s.  c o  m*/
        return highlight;
    } else {
        return highlight;
    }
}

From source file:com.example.sample2.MainActivity.java

private void setActionBarTitle() {
    if (getSupportActionBar() == null)
        return;/*from  ww w. j  a  v  a  2  s  . com*/
    TypefaceSpan span = new TypefaceSpan(this, "Audiowide-Regular");
    ForegroundColorSpan colorSpan = new ForegroundColorSpan(Color.CYAN);

    SpannableString title = new SpannableString("TextViews2");
    title.setSpan(span, 0, title.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
    title.setSpan(colorSpan, 4, title.length() - 1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
    getSupportActionBar().setTitle(title);
}

From source file:com.none.tom.simplerssreader.utils.SearchUtils.java

public static void setSearchResultsSpan(final Activity activity, final SearchResults results, final Spannable s,
        final int colorHighlightCurrent, final int colorHighlight, final int colorFont, final int position) {
    final int index = results.columnIndexOf(position);

    int i = 0;/*from  w w w  .ja va  2s.  co  m*/

    for (final Map.Entry<Integer, Integer> entry : results.getRowIndicesAt(index).entrySet()) {
        final int start = entry.getKey();
        final int end = entry.getValue();

        final BackgroundColorSpan span;

        if (results.isCurrent(index, i)) {
            span = new BackgroundColorSpan(colorHighlightCurrent);
        } else {
            span = new BackgroundColorSpan(colorHighlight);
        }

        s.setSpan(span, start, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);

        if (ThemeUtils.isDarkThemeSelected(activity)) {
            s.setSpan(new ForegroundColorSpan(colorFont), start, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        }

        i++;
    }
}

From source file:io.github.hidroh.materialistic.widget.preference.HelpListView.java

@Override
protected void onFinishInflate() {
    super.onFinishInflate();
    ((TextView) findViewById(R.id.item_new).findViewById(R.id.rank)).append(makeAsteriskSpan());
    SpannableString spannable = new SpannableString("+5");
    spannable.setSpan(new SuperscriptSpan(), 0, spannable.length(), Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
    spannable.setSpan(new RelativeSizeSpan(0.6f), 0, spannable.length(), Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
    spannable.setSpan(new ForegroundColorSpan(ContextCompat.getColor(getContext(), R.color.greenA700)), 0,
            spannable.length(), Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
    ((TextView) findViewById(R.id.item_promoted).findViewById(R.id.rank)).append(spannable);
    TextView comments = (TextView) findViewById(R.id.item_new_comments).findViewById(R.id.comment);
    SpannableStringBuilder sb = new SpannableStringBuilder("46");
    sb.append(makeAsteriskSpan());//from  w ww.  j  a  v a2s  .c  om
    comments.setText(sb);
}

From source file:Main.java

public static SpannableStringBuilder replaceTags(String str, int flag) {
    try {//from w ww . j ava 2s  . co  m
        int start;
        int end;
        StringBuilder stringBuilder = new StringBuilder(str);
        if ((flag & FLAG_TAG_BR) != 0) {
            while ((start = stringBuilder.indexOf("<br>")) != -1) {
                stringBuilder.replace(start, start + 4, "\n");
            }
            while ((start = stringBuilder.indexOf("<br/>")) != -1) {
                stringBuilder.replace(start, start + 5, "\n");
            }
        }
        ArrayList<Integer> bolds = new ArrayList<>();
        if ((flag & FLAG_TAG_BOLD) != 0) {
            while ((start = stringBuilder.indexOf("<b>")) != -1) {
                stringBuilder.replace(start, start + 3, "");
                end = stringBuilder.indexOf("</b>");
                if (end == -1) {
                    end = stringBuilder.indexOf("<b>");
                }
                stringBuilder.replace(end, end + 4, "");
                bolds.add(start);
                bolds.add(end);
            }
        }
        ArrayList<Integer> colors = new ArrayList<>();
        if ((flag & FLAG_TAG_COLOR) != 0) {
            while ((start = stringBuilder.indexOf("<c#")) != -1) {
                stringBuilder.replace(start, start + 2, "");
                end = stringBuilder.indexOf(">", start);
                int color = Color.parseColor(stringBuilder.substring(start, end));
                stringBuilder.replace(start, end + 1, "");
                end = stringBuilder.indexOf("</c>");
                stringBuilder.replace(end, end + 4, "");
                colors.add(start);
                colors.add(end);
                colors.add(color);
            }
        }
        SpannableStringBuilder spannableStringBuilder = new SpannableStringBuilder(stringBuilder);
        // for (int a = 0; a < bolds.size() / 2; a++) {
        // spannableStringBuilder.setSpan(
        // new TypefaceSpan(AndroidUtilities.getTypeface("fonts/rmedium.ttf")),
        // bolds.get(a * 2), bolds.get(a * 2 + 1), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        // }
        for (int a = 0; a < colors.size() / 3; a++) {
            spannableStringBuilder.setSpan(new ForegroundColorSpan(colors.get(a * 3 + 2)), colors.get(a * 3),
                    colors.get(a * 3 + 1), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        }
        return spannableStringBuilder;
    } catch (Exception e) {
        e.printStackTrace();
    }
    return new SpannableStringBuilder(str);
}

From source file:in.shick.diode.common.util.Util.java

public static ForegroundColorSpan getOPSpan(Context context, int theme) {
    if (Util.isLightTheme(theme)) {
        if (LIGHT_OP_FGCS == null) {
            LIGHT_OP_FGCS = new ForegroundColorSpan(context.getResources().getColor(R.color.blue));
        }//w ww . jav a  2  s  .c  om
        return LIGHT_OP_FGCS;
    } else {
        if (DARK_OP_FGCS == null) {
            DARK_OP_FGCS = new ForegroundColorSpan(context.getResources().getColor(R.color.pale_blue));
        }
        return DARK_OP_FGCS;
    }
}

From source file:com.duy.pascal.ui.editor.highlight.CommentHighlighter.java

@Override
public void highlight(@NonNull Editable allText, @NonNull CharSequence textToHighlight, int start) {
    mCommentRegion.clear();//from w  ww .  j av a  2 s .c  om
    for (Matcher m = COMMENTS.matcher(textToHighlight); m.find();) {
        allText.setSpan(new ForegroundColorSpan(codeTheme.getCommentColor()), start + m.start(),
                start + m.end(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        mCommentRegion.add(new Pair<>(start + m.start(), start + m.end()));
    }
}

From source file:com.manning.androidhacks.hack010.MainActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);//from  w w  w . j  a  v  a  2 s.com

    final TextView textView1 = (TextView) findViewById(R.id.my_text_view_html);
    textView1.setText(Html.fromHtml(getString(R.string.text1)));
    textView1.setMovementMethod(LinkMovementMethod.getInstance());

    final Spannable text2 = new SpannableString(getString(R.string.text2));
    text2.setSpan(new BackgroundColorSpan(Color.RED), 1, 4, 0);
    text2.setSpan(new ForegroundColorSpan(Color.BLUE), 5, 9, 0);

    ((TextView) findViewById(R.id.my_text_view_spannable)).setText(text2);
}

From source file:ru.tinkoff.acquiring.sample.ui.PaymentResultActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_payment_result);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);

    final TextView textView = (TextView) findViewById(R.id.tv_confirm);
    Intent intent = getIntent();//  w  w  w  .jav  a  2 s .  com
    if (intent.hasExtra(EXTRA_PRICE)) {
        final Money price = (Money) intent.getSerializableExtra(EXTRA_PRICE);

        final SpannableString coloredPrice = new SpannableString(price.toString());
        coloredPrice.setSpan(new ForegroundColorSpan(ContextCompat.getColor(this, R.color.colorPrimary)), 0,
                coloredPrice.length(), SpannedString.SPAN_INCLUSIVE_INCLUSIVE);

        final String text = getString(R.string.payment_result_success, coloredPrice);
        textView.setText(text);
    } else {
        String cardId = intent.getStringExtra(EXTRA_CARD_ID);
        final String text = getString(R.string.attachment_result_success, cardId);
        textView.setText(text);
    }
}

From source file:tw.com.geminihsu.app01.fragment.Fragment_OrderFilter.java

@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    MenuItem item = menu.add(Menu.NONE, ACTIONBAR_MENU_ITEM_FINISH, Menu.NONE, getString(R.string.btn_finish));
    SpannableString spanString = new SpannableString(item.getTitle().toString());
    spanString.setSpan(new ForegroundColorSpan(Color.WHITE), 0, spanString.length(), 0); //fix the color to white
    item.setTitle(spanString);// w w w. j  a v a2 s.  c  o m
    item.setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);
    super.onCreateOptionsMenu(menu, inflater);
}