Search in sources :

Example 86 with ForegroundColorSpan

use of android.text.style.ForegroundColorSpan in project SearchView by lapism.

the class SearchAdapter method onBindViewHolder.

@Override
public void onBindViewHolder(ResultViewHolder viewHolder, int position) {
    SearchItem item = mResultList.get(position);
    viewHolder.icon_left.setImageResource(item.get_icon());
    viewHolder.icon_left.setColorFilter(SearchView.getIconColor(), PorterDuff.Mode.SRC_IN);
    viewHolder.text.setTypeface((Typeface.create(SearchView.getTextFont(), SearchView.getTextStyle())));
    viewHolder.text.setTextColor(SearchView.getTextColor());
    String itemText = item.get_text().toString();
    String itemTextLower = itemText.toLowerCase(Locale.getDefault());
    if (itemTextLower.contains(key) && !key.isEmpty()) {
        SpannableString s = new SpannableString(itemText);
        s.setSpan(new ForegroundColorSpan(SearchView.getTextHighlightColor()), itemTextLower.indexOf(key), itemTextLower.indexOf(key) + key.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        viewHolder.text.setText(s, TextView.BufferType.SPANNABLE);
    } else {
        viewHolder.text.setText(item.get_text());
    }
    viewHolder.id_tag = item.get_tag();
}
Also used : SpannableString(android.text.SpannableString) ForegroundColorSpan(android.text.style.ForegroundColorSpan) SpannableString(android.text.SpannableString)

Example 87 with ForegroundColorSpan

use of android.text.style.ForegroundColorSpan in project FlexibleAdapter by davideas.

the class Utils method highlightText.

/**
	 * Sets a spannable text with any highlight color into the provided TextView.
	 *
	 * @param textView     the TextView to transform
	 * @param originalText the original text which the transformation is applied to
	 * @param constraint   the text to highlight
	 * @param color        the highlight color
	 * @see #fetchAccentColor(Context, int)
	 * @see #highlightText(TextView, String, String)
	 * @since 5.0.0-rc1
	 */
public static void highlightText(@NonNull TextView textView, @Nullable String originalText, @Nullable String constraint, @ColorInt int color) {
    if (originalText == null)
        originalText = "";
    if (constraint == null)
        constraint = "";
    int i = originalText.toLowerCase(Locale.getDefault()).indexOf(constraint.toLowerCase(Locale.getDefault()));
    if (i != -1) {
        Spannable spanText = Spannable.Factory.getInstance().newSpannable(originalText);
        spanText.setSpan(new ForegroundColorSpan(color), i, i + constraint.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        spanText.setSpan(new StyleSpan(Typeface.BOLD), i, i + constraint.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        textView.setText(spanText, TextView.BufferType.SPANNABLE);
    } else {
        textView.setText(originalText, TextView.BufferType.NORMAL);
    }
}
Also used : ForegroundColorSpan(android.text.style.ForegroundColorSpan) StyleSpan(android.text.style.StyleSpan) SuppressLint(android.annotation.SuppressLint) Spannable(android.text.Spannable)

Example 88 with ForegroundColorSpan

use of android.text.style.ForegroundColorSpan in project GeekNews by codeestX.

the class CommentAdapter method onBindViewHolder.

@Override
public void onBindViewHolder(final ViewHolder holder, int position) {
    CommentBean.CommentsBean info = mList.get(position);
    ImageLoader.load(mContext, info.getAvatar(), holder.civFace);
    holder.tvName.setText(info.getAuthor());
    holder.tvContent.setText(info.getContent());
    holder.tvTime.setText(DateUtil.formatTime2String(info.getTime()));
    holder.tvLike.setText(String.valueOf(info.getLikes()));
    if (info.getReply_to() != null && info.getReply_to().getId() != 0) {
        holder.tvReply.setVisibility(View.VISIBLE);
        SpannableString ss = new SpannableString("@" + info.getReply_to().getAuthor() + ": " + info.getReply_to().getContent());
        ss.setSpan(new ForegroundColorSpan(ContextCompat.getColor(mContext, R.color.comment_at)), 0, info.getReply_to().getAuthor().length() + 2, Spanned.SPAN_INCLUSIVE_INCLUSIVE);
        //            holder.tvReply.setText(String.format("@%s: %s",info.getReply_to().getAuthor(),info.getReply_to().getContent()));
        holder.tvReply.setText(ss);
        if (info.getReply_to().getExpandState() == STATE_NULL) {
            //未知
            holder.tvReply.post(new Runnable() {

                @Override
                public void run() {
                    if (holder.tvReply.getLineCount() > MAX_LINE) {
                        holder.tvReply.setMaxLines(MAX_LINE);
                        holder.tvExpand.setVisibility(View.VISIBLE);
                        holder.tvExpand.setText("展开");
                        mList.get(holder.getAdapterPosition()).getReply_to().setExpandState(STATE_SHRINK);
                        holder.tvExpand.setOnClickListener(new OnStateClickListener(holder.getAdapterPosition(), holder.tvReply));
                    } else {
                        holder.tvExpand.setVisibility(View.GONE);
                        mList.get(holder.getAdapterPosition()).getReply_to().setExpandState(STATE_NONE);
                    }
                }
            });
        } else if (info.getReply_to().getExpandState() == STATE_NONE) {
            //无需展开
            holder.tvExpand.setVisibility(View.GONE);
        } else if (info.getReply_to().getExpandState() == STATE_EXPAND) {
            //已展开
            holder.tvReply.setMaxLines(Integer.MAX_VALUE);
            holder.tvExpand.setText("收起");
            holder.tvExpand.setVisibility(View.VISIBLE);
            holder.tvExpand.setOnClickListener(new OnStateClickListener(holder.getAdapterPosition(), holder.tvReply));
        } else {
            //已收缩
            holder.tvReply.setMaxLines(MAX_LINE);
            holder.tvExpand.setText("展开");
            holder.tvExpand.setVisibility(View.VISIBLE);
            holder.tvExpand.setOnClickListener(new OnStateClickListener(holder.getAdapterPosition(), holder.tvReply));
        }
    } else {
        holder.tvReply.setVisibility(View.GONE);
        holder.tvExpand.setVisibility(View.GONE);
    }
}
Also used : SpannableString(android.text.SpannableString) ForegroundColorSpan(android.text.style.ForegroundColorSpan) CommentBean(com.codeest.geeknews.model.bean.CommentBean)

Example 89 with ForegroundColorSpan

use of android.text.style.ForegroundColorSpan in project TextJustify-Android by bluejamesbond.

the class QuoteSpanTest method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    addDocumentView(new ArticleBuilder().append(testName, false, new RelativeSizeSpan(2f), new StyleSpan(Typeface.BOLD), new LeftSpan()).append("<font color=0xFFC801>Jon Brodkin</font><font color=0x888888> Oct. 28, 2014</font>", true, new RelativeSizeSpan(0.8f), new StyleSpan(Typeface.BOLD)).append("But now we have more numbers on the performance declines, thanks to a new report from the Measurement Lab Consortium (M-Lab). M-Lab hosts measuring equipment at Internet exchange points to analyze connections between network operators and has more than five years' worth of measurements. A report released today examines connections between consumer Internet service providers (\"Access ISPs\" in M-Lab parlance) and backbone operators (\"Transit ISPs\"), including the ones that sent traffic from Netflix to ISPs while the money fights were still going on.", true, new RelativeSizeSpan(0.8f), new JustifiedSpan(), new MyQuoteSpan(0xFFFFC801, 2, 50), new StyleSpan(Typeface.ITALIC), new ForegroundColorSpan(0xFF555555)).append("Using Measurement Lab (M-Lab) data, and constraining our research to the United States, we observed sustained performance degradation experienced by customers of Access ISPs AT&T, Comcast, CenturyLink, Time Warner Cable, and Verizon when their traffic passed over interconnections with Transit ISPs Cogent Communications (Cogent), Level 3 Communications (Level 3), and XO Communications (XO),\" researchers wrote. \"In a large number of cases we observed similar patterns of performance degradation whenever and wherever specific pairs of Access/Transit ISPs interconnected. From this we conclude that ISP interconnection has a substantial impact on consumer internet performance—sometimes a severely negative impact—and that business relationships between ISPs, and not major technical problems, are at the root of the problems we observed.", true, new RelativeSizeSpan(1f), new JustifiedSpan()).append("Using Measurement Lab (M-Lab) data, and constraining our research to the United States, we observed sustained performance degradation experienced by customers of Access ISPs AT&T, Comcast, CenturyLink, Time Warner Cable, and Verizon when their traffic passed over interconnections with Transit ISPs Cogent Communications (Cogent), Level 3 Communications (Level 3), and XO Communications (XO),\" researchers wrote. \"In a large number of cases we observed similar patterns of performance degradation whenever and wherever specific pairs of Access/Transit ISPs interconnected. From this we conclude that ISP interconnection has a substantial impact on consumer internet performance—sometimes a severely negative impact—and that business relationships between ISPs, and not major technical problems, are at the root of the problems we observed.", false, new RelativeSizeSpan(0.8f), new RightSpan(), new MyQuoteSpan(0xFFFFC801, 2, 50), new StyleSpan(Typeface.ITALIC), new ForegroundColorSpan(0xFF555555)), DocumentView.FORMATTED_TEXT);
}
Also used : JustifiedSpan(com.bluejamesbond.text.style.JustifiedSpan) ForegroundColorSpan(android.text.style.ForegroundColorSpan) LeftSpan(com.bluejamesbond.text.style.LeftSpan) StyleSpan(android.text.style.StyleSpan) MyQuoteSpan(com.bluejamesbond.text.sample.helper.MyQuoteSpan) ArticleBuilder(com.bluejamesbond.text.util.ArticleBuilder) RelativeSizeSpan(android.text.style.RelativeSizeSpan) RightSpan(com.bluejamesbond.text.style.RightSpan)

Example 90 with ForegroundColorSpan

use of android.text.style.ForegroundColorSpan in project ExoPlayer by google.

the class Cea608Decoder method handleMidrowCtrl.

private void handleMidrowCtrl(byte cc2) {
    // TODO: support the extended styles (i.e. backgrounds and transparencies)
    // cc2 - 0|0|1|0|ATRBT|U
    // ATRBT is the 3-byte encoded attribute, and U is the underline toggle
    boolean isUnderlined = (cc2 & 0x01) == 0x01;
    currentCueBuilder.setUnderline(isUnderlined);
    int attribute = (cc2 >> 1) & 0x0F;
    if (attribute == 0x07) {
        currentCueBuilder.setMidrowStyle(new StyleSpan(Typeface.ITALIC), 2);
        currentCueBuilder.setMidrowStyle(new ForegroundColorSpan(Color.WHITE), 1);
    } else {
        currentCueBuilder.setMidrowStyle(new ForegroundColorSpan(COLORS[attribute]), 1);
    }
}
Also used : ForegroundColorSpan(android.text.style.ForegroundColorSpan) StyleSpan(android.text.style.StyleSpan)

Aggregations

ForegroundColorSpan (android.text.style.ForegroundColorSpan)157 SpannableStringBuilder (android.text.SpannableStringBuilder)57 SpannableString (android.text.SpannableString)50 StyleSpan (android.text.style.StyleSpan)25 TextView (android.widget.TextView)25 ImageSpan (android.text.style.ImageSpan)23 Spannable (android.text.Spannable)22 RelativeSizeSpan (android.text.style.RelativeSizeSpan)22 View (android.view.View)22 BackgroundColorSpan (android.text.style.BackgroundColorSpan)19 TypefaceSpan (android.text.style.TypefaceSpan)16 StrikethroughSpan (android.text.style.StrikethroughSpan)14 UnderlineSpan (android.text.style.UnderlineSpan)13 Drawable (android.graphics.drawable.Drawable)12 CharacterStyle (android.text.style.CharacterStyle)11 EditText (android.widget.EditText)11 AbsoluteSizeSpan (android.text.style.AbsoluteSizeSpan)10 SuperscriptSpan (android.text.style.SuperscriptSpan)8 LinearLayout (android.widget.LinearLayout)8 URLSpan (android.text.style.URLSpan)7