Java Code Examples for android.text.style.ForegroundColorSpan

The following are top voted examples for showing how to use android.text.style.ForegroundColorSpan. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: Quizca-UI-Concept   File: MainActivity.java   Source Code and License 7 votes vote down vote up
public SpannableString getDesignationText()
{
    String text = txtDesignation.getText().toString();

    SpannableString s = new SpannableString(text);

    s.setSpan(new ForegroundColorSpan(getResources().getColor(R.color.colorAccent)), text.indexOf("@"), text.length(), 0);

    /*
    s.setSpan(new RelativeSizeSpan(1.2f), text.indexOf("A"), text.length(), 0);
    s.setSpan(new StyleSpan(Typeface.NORMAL), text.indexOf("A"), text.length(), 0);
    s.setSpan(new ForegroundColorSpan(Color.BLACK), text.indexOf("A"), text.length(), 0);
    */

    return s;
}
 
Example 2
Project: Sega   File: SearchAdapter.java   Source Code and License 6 votes vote down vote up
@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());
    }
}
 
Example 3
Project: letv   File: StringUtils.java   Source Code and License 6 votes vote down vote up
public static SpannableString highlightParamTextOffsetRightOne(String inputString, String highlight, int color) {
    inputString = String.format(inputString, new Object[]{highlight});
    SpannableString spanString = new SpannableString(inputString);
    if (!TextUtils.isEmpty(inputString)) {
        int beginPos = inputString.indexOf(highlight);
        if (beginPos > -1) {
            int endPos;
            if ((highlight.length() + beginPos) + 1 > inputString.length()) {
                endPos = inputString.length();
            } else {
                endPos = (highlight.length() + beginPos) + 1;
            }
            spanString.setSpan(new ForegroundColorSpan(color), beginPos, endPos, 33);
        }
    }
    return spanString;
}
 
Example 4
Project: SciChart.Android.Examples   File: CustomTooltipsWithModifiersFragment.java   Source Code and License 6 votes vote down vote up
@Override
protected void internalUpdate(XySeriesInfo seriesInfo) {
    final SpannableStringBuilder sb = new SpannableStringBuilder();
    sb.append(modifierName).append(StringUtil.NEW_LINE);

    if (seriesInfo.seriesName != null) {
        sb.append(seriesInfo.seriesName);
        sb.setSpan(new ForegroundColorSpan(ColorUtil.Black), 0, sb.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        sb.append(StringUtil.NEW_LINE);
    }

    sb.append("X: ").append(seriesInfo.getFormattedXValue());
    sb.append(" Y: ").append(seriesInfo.getFormattedYValue());

    setText(sb);

    // stroke 0xffff4500
    setSeriesColor(0xffe2460c);
}
 
Example 5
Project: TextReader   File: BookMarkAdapter.java   Source Code and License 6 votes vote down vote up
@Override
public void convert(EasyLVHolder holder, int position, BookMark item) {
    TextView tv = holder.getView(R.id.tvMarkItem);

    SpannableString spanText = new SpannableString((position + 1) + ". " + item.title + ": ");
    spanText.setSpan(new ForegroundColorSpan(ContextCompat.getColor(mContext, R.color.light_coffee)),
            0, spanText.length(), Spannable.SPAN_INCLUSIVE_EXCLUSIVE);

    tv.setText(spanText);

    if (item.desc != null) {
        tv.append(item.desc
                .replaceAll(" ", "")
                .replaceAll(" ", "")
                .replaceAll("\n", ""));
    }

}
 
Example 6
Project: stynico   File: HighLightKeyWordUtil.java   Source Code and License 6 votes vote down vote up
/** 
    * @param color 关键字颜色 
    * @param text 文本 
    * @param keyword 多个关键字 
    * @return 
    */  
   public static SpannableString getHighLightKeyWord(int color, String text, String[] keyword)
{  
       SpannableString s = new SpannableString(text);  
       for (int i = 0; i < keyword.length; i++)
	{  
           Pattern p = Pattern.compile(keyword[i]);  
           Matcher m = p.matcher(s);  
           while (m.find())
		{  
               int start = m.start();  
               int end = m.end();  
               s.setSpan(new ForegroundColorSpan(color), start, end, 
					  Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);  
           }  
       }  
       return s;  

   }
 
Example 7
Project: yyox   File: OrderDetailActivity.java   Source Code and License 6 votes vote down vote up
@Override
    public void setFeeValue(Fee fee) {
        if (fee != null || 1 == getIntent().getIntExtra("type", OrderStatus.ORDER_STATUS_DETAIL)) {
            totalAmount = fee.getMoney().getTotalAmount();
            if (mOrderDetail.getCouponList() == null || mOrderDetail.getCouponList().getCoupon() == null || mOrderDetail.getCouponList().getCoupon().getName().equals("")) {
                mTextView_Coupon_Value.setText("有" + fee.getCouponNumber() + "张可用");
            }
//            mTextView_Fee.setText("运费:" + CommonUtils.doubleFormat(fee.getMoney().getTotalAmount()));

            SpannableString styledText = new SpannableString("运费:¥"+CommonUtils.doubleFormat(fee.getMoney().getTotalAmount()));
            int color = getResources().getColor(R.color.my_yellow);
            styledText.setSpan(new ForegroundColorSpan(color), 0, 3, Spanned.SPAN_INCLUSIVE_INCLUSIVE);
            mTextView_Fee.setText(styledText);

            mOrderDetail.setValueAddedlist(fee.getValueAddedlist());
            this.fee = fee.getMoney().getTotalAmount();
        }
    }
 
Example 8
Project: revolution-irc   File: StorageSettingsAdapter.java   Source Code and License 6 votes vote down vote up
public void bind(ServerLogsEntry entry, int pos) {
    int colorId = R.color.storageSettingsChartOthers;
    if (entry.size > 0L) {
        if (pos == 0)
            colorId = R.color.storageSettingsChartFirst;
        else if (pos == 1)
            colorId = R.color.storageSettingsChartSecond;
        else if (pos == 2)
            colorId = R.color.storageSettingsChartThird;
    }
    ColoredTextBuilder builder = new ColoredTextBuilder();
    builder.append(entry.name, new ForegroundColorSpan(mText.getResources().getColor(colorId)));
    builder.append("  ");
    builder.append(formatFileSize(entry.size));
    mText.setText(builder.getSpannable());
    mText.setTag(entry.uuid);
}
 
Example 9
Project: LikeGank   File: IOSItemBinder.java   Source Code and License 6 votes vote down vote up
@Override
protected void onBindViewHolder(@NonNull IOSItemBinder.ViewHolder viewHolder,
                                @NonNull IOS ios) {
    SpannableString span = new SpannableString(new StringBuilder()
            .append(ios.content)
            .append("(via-")
            .append(ios.author)
            .append(")"));
    span.setSpan(new ForegroundColorSpan(Color.parseColor("#9e9e9e"))
            , ios.content.length()
            , span.length()
            , Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
    viewHolder.content.setText(span);
    viewHolder.url = ios.url;
    viewHolder.title = ios.content;
}
 
Example 10
Project: AgentWeb   File: AgentWebUtils.java   Source Code and License 6 votes vote down vote up
static void show(View parent,
                 CharSequence text,
                 int duration,
                 @ColorInt int textColor,
                 @ColorInt int bgColor,
                 CharSequence actionText,
                 @ColorInt int actionTextColor,
                 View.OnClickListener listener) {
    SpannableString spannableString = new SpannableString(text);
    ForegroundColorSpan colorSpan = new ForegroundColorSpan(textColor);
    spannableString.setSpan(colorSpan, 0, spannableString.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
    snackbarWeakReference = new WeakReference<>(Snackbar.make(parent, spannableString, duration));
    Snackbar snackbar = snackbarWeakReference.get();
    View view = snackbar.getView();
    view.setBackgroundColor(bgColor);
    if (actionText != null && actionText.length() > 0 && listener != null) {
        snackbar.setActionTextColor(actionTextColor);
        snackbar.setAction(actionText, listener);
    }
    snackbar.show();

}
 
Example 11
Project: Exoplayer2Radio   File: Cea608Decoder.java   Source Code and License 6 votes vote down vote up
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);
  }
}
 
Example 12
Project: SciChart.Android.Examples   File: CustomTooltipsWithModifiersFragment.java   Source Code and License 6 votes vote down vote up
@Override
protected void internalUpdate(XySeriesInfo seriesInfo) {
    final SpannableStringBuilder sb = new SpannableStringBuilder();

    sb.append("X: ").append(seriesInfo.getFormattedXValue()).append(StringUtil.NEW_LINE);
    sb.append("Y: ").append(seriesInfo.getFormattedYValue()).append(StringUtil.NEW_LINE);

    if (seriesInfo.seriesName != null) {
        final int start = sb.length();

        sb.append(seriesInfo.seriesName);
        sb.setSpan(new ForegroundColorSpan(ColorUtil.White), start, sb.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        sb.append(StringUtil.NEW_LINE);
    }
    sb.append(modifierName);
    setText(sb);

    // stroke 0xff4d81dd
    setSeriesColor(0xff6495ed);
}
 
Example 13
Project: mvvm-template   File: PreTagHandler.java   Source Code and License 6 votes vote down vote up
@Override public void handleTagNode(TagNode node, SpannableStringBuilder builder, int start, int end) {
    if (isPre) {
        StringBuffer buffer = new StringBuffer();
        buffer.append("\n");//fake padding top + make sure, pre is always by itself
        getPlainText(buffer, node);
        buffer.append("\n");//fake padding bottom + make sure, pre is always by itself
        builder.append(replace(buffer.toString()));
        builder.append("\n");
        builder.setSpan(new CodeBackgroundRoundedSpan(color), start, builder.length(), SPAN_EXCLUSIVE_EXCLUSIVE);
        builder.append("\n");
        this.appendNewLine(builder);
        this.appendNewLine(builder);
    } else {
        StringBuffer text = node.getText();
        builder.append(" ");
        builder.append(replace(text.toString()));
        builder.append(" ");
        final int stringStart = start + 1;
        final int stringEnd = builder.length() - 1;
        builder.setSpan(new BackgroundColorSpan(color), stringStart, stringEnd, SPAN_EXCLUSIVE_EXCLUSIVE);
        if (theme == PrefGetter.LIGHT) {
            builder.setSpan(new ForegroundColorSpan(Color.RED), stringStart, stringEnd, SPAN_EXCLUSIVE_EXCLUSIVE);
        }
        builder.setSpan(new TypefaceSpan("monospace"), stringStart, stringEnd, SPAN_EXCLUSIVE_EXCLUSIVE);
    }
}
 
Example 14
Project: revolution-irc   File: MessageFormatSettingsFormatBar.java   Source Code and License 6 votes vote down vote up
@Override
protected ColorListPickerDialog createColorPicker(boolean fillColor, int selectedColor) {
    ColorListPickerDialog ret = super.createColorPicker(fillColor, selectedColor);
    if (!fillColor) {
        ret.setColors(getResources().getIntArray(R.array.formatTextColors), -1);
        ret.setSelectedColor(selectedColor);
        ret.setNeutralButton(R.string.message_format_sender_color,
                (DialogInterface dialog, int which) -> {
                    setSpan(new MessageBuilder.MetaForegroundColorSpan(getContext(),
                            MessageBuilder.MetaForegroundColorSpan.COLOR_SENDER));
                });
        ret.setOnColorChangeListener((ColorListPickerDialog d, int newColorIndex, int color) -> {
            removeSpan(ForegroundColorSpan.class);
            if (color == IRCColorUtils.getStatusTextColor(getContext()))
                setSpan(new MessageBuilder.MetaForegroundColorSpan(getContext(), MessageBuilder.MetaForegroundColorSpan.COLOR_STATUS));
            if (color == IRCColorUtils.getTimestampTextColor(getContext()))
                setSpan(new MessageBuilder.MetaForegroundColorSpan(getContext(), MessageBuilder.MetaForegroundColorSpan.COLOR_TIMESTAMP));
            else
                setSpan(new ForegroundColorSpan(color));
            d.cancel();
        });
    }
    return ret;
}
 
Example 15
Project: sctalk   File: IMUIHelper.java   Source Code and License 6 votes vote down vote up
public static void setTextHilighted(TextView textView, String text,SearchElement searchElement) {
    textView.setText(text);
    if (textView == null
            || TextUtils.isEmpty(text)
            || searchElement ==null) {
        return;
    }

    int startIndex = searchElement.startIndex;
    int endIndex = searchElement.endIndex;
    if (startIndex < 0 || endIndex > text.length()) {
        return;
    }
    // 开始高亮处理
    int color =  Color.rgb(69, 192, 26);
    textView.setText(text, BufferType.SPANNABLE);
    Spannable span = (Spannable) textView.getText();
    span.setSpan(new ForegroundColorSpan(color), startIndex, endIndex, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
}
 
Example 16
Project: revolution-irc   File: TextFormatBar.java   Source Code and License 6 votes vote down vote up
protected ColorListPickerDialog createColorPicker(boolean fillColor, int selectedColor) {
    ColorListPickerDialog dialog = new ColorListPickerDialog(getContext());
    if (!fillColor) {
        dialog.setTitle(R.string.format_text_color);
    } else {
        dialog.setTitle(R.string.format_fill_color);
    }
    dialog.setSelectedColor(selectedColor);
    dialog.setPositiveButton(R.string.action_cancel, null);
    dialog.setOnColorChangeListener((ColorListPickerDialog d, int newColorIndex, int color) -> {
        if (!fillColor) {
            removeSpan(ForegroundColorSpan.class);
            setSpan(new ForegroundColorSpan(color));
        } else {
            removeSpan(BackgroundColorSpan.class);
            setSpan(new BackgroundColorSpan(color));
        }
        d.cancel();
    });
    return dialog;
}
 
Example 17
Project: AndroidUtilCode-master   File: SnackbarUtils.java   Source Code and License 6 votes vote down vote up
/**
 * 设置snackbar文字和背景颜色
 *
 * @param parent          父视图(CoordinatorLayout或者DecorView)
 * @param text            文本
 * @param duration        显示时长
 * @param textColor       文本颜色
 * @param bgColor         背景色
 * @param actionText      事件文本
 * @param actionTextColor 事件文本颜色
 * @param listener        监听器
 */
private static void show(View parent,
                         CharSequence text,
                         int duration,
                         @ColorInt int textColor,
                         @ColorInt int bgColor,
                         CharSequence actionText,
                         @ColorInt int actionTextColor,
                         View.OnClickListener listener) {
    SpannableString spannableString = new SpannableString(text);
    ForegroundColorSpan colorSpan = new ForegroundColorSpan(textColor);
    spannableString.setSpan(colorSpan, 0, spannableString.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
    snackbarWeakReference = new WeakReference<>(Snackbar.make(parent, spannableString, duration));
    Snackbar snackbar = snackbarWeakReference.get();
    View view = snackbar.getView();
    view.setBackgroundColor(bgColor);
    if (actionText != null && actionText.length() > 0 && listener != null) {
        snackbar.setActionTextColor(actionTextColor);
        snackbar.setAction(actionText, listener);
    }
    snackbar.show();
}
 
Example 18
Project: orgzly-android   File: BookUtils.java   Source Code and License 6 votes vote down vote up
private static CharSequence replaceWithLastActionError(Context context, Book book, CharSequence str) {
    BookAction action = book.getLastAction();

    if (action != null && action.getType() == BookAction.Type.ERROR) {
        SpannableStringBuilder builder = new SpannableStringBuilder(action.getMessage());

        /* Get error color attribute. */
        TypedArray arr = context.obtainStyledAttributes(
                new int[]{R.attr.item_book_error_color});
        int color = arr.getColor(0, 0);
        arr.recycle();

        /* Set error color. */
        builder.setSpan(new ForegroundColorSpan(color), 0, builder.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);

        return builder;
    }

    return str;
}
 
Example 19
Project: Intelligent_Indoor_Localization_System   File: J2xxHyperTerm.java   Source Code and License 6 votes vote down vote up
void appendData(String data) 
{
	if(true == bContentFormatHex)
	{
		if(timesMessageHexFormatWriteData < 3)
		{
			timesMessageHexFormatWriteData++;
			midToast("The writing data won��t be showed on data area while content format is hexadecimal format.",Toast.LENGTH_LONG);
		}
		return;
	}

	if(true == bSendHexData)
	{
		SpannableString text = new SpannableString(data);
		text.setSpan(new ForegroundColorSpan(Color.YELLOW), 0, data.length(), 0);
		//readText.append(text);
		bSendHexData = false;
	}
	else
	{
		read_zigbee(data);
	}
}
 
Example 20
Project: revolution-irc   File: ChannelSearchDialog.java   Source Code and License 5 votes vote down vote up
@Override
public void bind(Pair<ServerConnectionInfo, String> item) {
    String name = item.first.getName();
    String channel = item.second;
    int iof = channel.indexOf(mHighlightQuery);
    SpannableString str = new SpannableString(channel + "  " + name);
    str.setSpan(new ForegroundColorSpan(mHighlightTextColor), iof, iof + mHighlightQuery.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
    str.setSpan(new ForegroundColorSpan(mSecondaryTextColor), channel.length() + 2, channel.length() + 2 + name.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
    mText.setText(str);
}
 
Example 21
Project: decoy   File: AitHelper.java   Source Code and License 5 votes vote down vote up
public static void replaceAitForeground(String value, SpannableString mSpannableString) {
    if (TextUtils.isEmpty(value) || TextUtils.isEmpty(mSpannableString)) {
        return;
    }
    Pattern pattern = Pattern.compile("(\\[有人@你\\])");
    Matcher matcher = pattern.matcher(value);
    while (matcher.find()) {
        int start = matcher.start();
        if (start != 0) {
            continue;
        }
        int end = matcher.end();
        mSpannableString.setSpan(new ForegroundColorSpan(Color.RED), start, end, Spannable.SPAN_EXCLUSIVE_INCLUSIVE);
    }
}
 
Example 22
Project: showroom-android   File: OuterItem.java   Source Code and License 5 votes vote down vote up
void setContent(@NonNull List<InnerData> innerDataList) {
    final Context context = itemView.getContext();

    final InnerData header = innerDataList.subList(0, 1).get(0);
    final List<InnerData> tail = innerDataList.subList(1, innerDataList.size());

    mRecyclerView.setLayoutManager(new InnerLayoutManager());
    ((InnerAdapter) mRecyclerView.getAdapter()).addData(tail);

    Glide.with(context)
            .load(header.avatarUrl)
            .placeholder(R.drawable.gv_avatar_placeholder)
            .bitmapTransform(new CropCircleTransformation(context))
            .into(mAvatar);

    final String title1 = header.title + "?";

    final Spannable title2 = new SpannableString(header.title + "? - " + header.name);
    title2.setSpan(new AbsoluteSizeSpan(mTitleSize1), 0, title1.length(), SPAN_INCLUSIVE_INCLUSIVE);
    title2.setSpan(new AbsoluteSizeSpan(mTitleSize2), title1.length(), title2.length(), SPAN_INCLUSIVE_INCLUSIVE);
    title2.setSpan(new ForegroundColorSpan(Color.argb(204, 255, 255, 255)), title1.length(), title2.length(), SPAN_INCLUSIVE_INCLUSIVE);

    mHeaderCaption1.setText(title1);
    mHeaderCaption2.setText(title2);

    mName.setText(String.format("%s %s", header.name, context.getString(R.string.gv_asked)));
    mInfo.setText(String.format("%s %s · %s", header.age, context.getString(R.string.gv_years), header.address));
}
 
Example 23
Project: yjPlay   File: GestureVideoPlayer.java   Source Code and License 5 votes vote down vote up
/****
 * 滑动进度
 *
 * @param  seekTimePosition  滑动的时间
 * @param  duration         视频总长
 * @param  seekTime    滑动的时间 格式化00:00
 * @param  totalTime    视频总长 格式化00:00
 **/
private void showProgressDialog(long seekTimePosition, long duration, String seekTime, String totalTime) {
    newPosition = seekTimePosition;
    if (onGestureProgressListener != null) {
        onGestureProgressListener.showProgressDialog(seekTimePosition, duration, seekTime, totalTime);
    } else {
        String stringBuilder = seekTime + "/" + totalTime;
        ForegroundColorSpan blueSpan = new ForegroundColorSpan(ContextCompat.getColor(activity, R.color.simple_exo_style_color));
        SpannableString spannableString = new SpannableString(stringBuilder);
        spannableString.setSpan(blueSpan, 0, seekTime.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        getPlayerViewListener().setTimePosition(spannableString);
    }
}
 
Example 24
Project: q-mail   File: MessageListAdapter.java   Source Code and License 5 votes vote down vote up
private void formatPreviewText(TextView preview, CharSequence beforePreviewText, String sigil) {
    Spannable previewText = (Spannable)preview.getText();
    previewText.setSpan(buildSenderSpan(), 0, beforePreviewText.length() + sigil.length(),
            Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);

    int previewSpanColor = buildPreviewSpanColor();

    // Set span (color) for preview message
    previewText.setSpan(new ForegroundColorSpan(previewSpanColor), beforePreviewText.length() + sigil.length(),
            previewText.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
}
 
Example 25
Project: q-mail   File: ICalendarHelper.java   Source Code and License 5 votes vote down vote up
@VisibleForTesting
static CharSequence toFriendly(Organizer organizer, Contacts contacts,
                               boolean showCorrespondentNames,
                               boolean changeContactNameColor,
                               int contactNameColor) {
    if (organizer == null) {
        return null;
    }
    if (!showCorrespondentNames) {
        return organizer.getEmail();
    } else if (contacts != null) {
        final String name = contacts.getNameForAddress(organizer.getEmail());
        // TODO: The results should probably be cached for performance reasons.
        if (name != null) {
            if (changeContactNameColor) {
                final SpannableString coloredName = new SpannableString(name);
                coloredName.setSpan(new ForegroundColorSpan(contactNameColor),
                        0,
                        coloredName.length(),
                        Spannable.SPAN_EXCLUSIVE_EXCLUSIVE
                );
                return coloredName;
            } else {
                return name;
            }
        }
    }

    return (!TextUtils.isEmpty(organizer.getCommonName())) ? organizer.getCommonName() : organizer.getEmail();
}
 
Example 26
Project: q-mail   File: RecipientAdapter.java   Source Code and License 5 votes vote down vote up
private Spannable highlightText(String text) {
    Spannable highlightedSpannable = Spannable.Factory.getInstance().newSpannable(text);

    if (highlight == null) {
        return highlightedSpannable;
    }

    Pattern pattern = Pattern.compile(highlight, Pattern.LITERAL | Pattern.CASE_INSENSITIVE);
    Matcher matcher = pattern.matcher(text);
    while (matcher.find()) {
        highlightedSpannable.setSpan(
                new ForegroundColorSpan(context.getResources().getColor(android.R.color.holo_blue_light)),
                matcher.start(), matcher.end(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
    }

    return highlightedSpannable;
}
 
Example 27
Project: javaide   File: ConsoleEditText.java   Source Code and License 5 votes vote down vote up
public CharSequence updateStr(CharSequence oldChars, int startPos, CharSequence newChars) {
    if (startPos < mLength) {
        return oldChars; //don't edit

    } else {//if (startPos >= mLength)
        SpannableString spannableString = new SpannableString(newChars);
        spannableString.setSpan(new ForegroundColorSpan(Color.GREEN), 0,
                spannableString.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        return spannableString;
    }
}
 
Example 28
Project: GitHub   File: PiePolylineChartActivity.java   Source Code and License 5 votes vote down vote up
private SpannableString generateCenterSpannableText() {

        SpannableString s = new SpannableString("MPAndroidChart\ndeveloped by Philipp Jahoda");
        s.setSpan(new RelativeSizeSpan(1.5f), 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(.65f), 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;
    }
 
Example 29
Project: GitHub   File: HalfPieChartActivity.java   Source Code and License 5 votes vote down vote up
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;
    }
 
Example 30
Project: Cable-Android   File: ContactSelectionListAdapter.java   Source Code and License 5 votes vote down vote up
private CharSequence getSpannedHeaderString(int position) {
  final String headerString = getHeaderString(position);
  if (isPush(position)) {
    SpannableString spannable = new SpannableString(headerString);
    spannable.setSpan(new ForegroundColorSpan(getContext().getResources().getColor(R.color.signal_primary)), 0, headerString.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
    return spannable;
  } else {
    return headerString;
  }
}
 
Example 31
Project: GitHub   File: PieChartItem.java   Source Code and License 5 votes vote down vote up
private SpannableString generateCenterText() {
    SpannableString s = new SpannableString("MPAndroidChart\ncreated by\nPhilipp Jahoda");
    s.setSpan(new RelativeSizeSpan(1.6f), 0, 14, 0);
    s.setSpan(new ForegroundColorSpan(ColorTemplate.VORDIPLOM_COLORS[0]), 0, 14, 0);
    s.setSpan(new RelativeSizeSpan(.9f), 14, 25, 0);
    s.setSpan(new ForegroundColorSpan(Color.GRAY), 14, 25, 0);
    s.setSpan(new RelativeSizeSpan(1.4f), 25, s.length(), 0);
    s.setSpan(new ForegroundColorSpan(ColorTemplate.getHoloBlue()), 25, s.length(), 0);
    return s;
}
 
Example 32
Project: BaseCore   File: CountDownTimerUtils.java   Source Code and License 5 votes vote down vote up
@Override
    public void onTick(long millisUntilFinished) {
        mTextView.setClickable(false); //设置不可点击
        mTextView.setText(String.format(strFormate, String.valueOf(millisUntilFinished / 1000)));  //设置倒计时时间
//        mTextView.setBackgroundResource(R.drawable.bg_identify_code_press); //设置按钮为灰色,这时是不能点击的
        mTextView.setTextColor(ContextCompat.getColor(mTextView.getContext(), R.color.grey));

        /**
         * 超链接 URLSpan
         * 文字背景颜色 BackgroundColorSpan
         * 文字颜色 ForegroundColorSpan
         * 字体大小 AbsoluteSizeSpan
         * 粗体、斜体 StyleSpan
         * 删除线 StrikethroughSpan
         * 下划线 UnderlineSpan
         * 图片 ImageSpan
         * http://blog.csdn.net/ah200614435/article/details/7914459
         */
        SpannableString spannableString = new SpannableString(mTextView.getText().toString());  //获取按钮上的文字
        ForegroundColorSpan span = new ForegroundColorSpan(Color.RED);
        /**
         * public void setSpan(Object what, int start, int end, int flags) {
         * 主要是start跟end,start是起始位置,无论中英文,都算一个。
         * 从0开始计算起。end是结束位置,所以处理的文字,包含开始位置,但不包含结束位置。
         */
        spannableString.setSpan(span, 0, 2, Spannable.SPAN_INCLUSIVE_EXCLUSIVE);//将倒计时的时间设置为红色
        mTextView.setText(spannableString);
    }
 
Example 33
Project: boohee_v5.6   File: StatusBlockFragment.java   Source Code and License 5 votes vote down vote up
private void setCheckInUI(int count, boolean isChecked) {
    boolean z;
    String message = String.format(getString(R.string.d7), new Object[]{Integer.valueOf
            (count)});
    SpannableString ss = new SpannableString(message);
    ss.setSpan(new ForegroundColorSpan(SupportMenu.CATEGORY_MASK), 5, message.length() - 1, 33);
    this.checkInMsgText.setText(ss);
    this.checkInBtn.setText(isChecked ? R.string.d4 : R.string.d6);
    TextView textView = this.checkInBtn;
    if (isChecked) {
        z = false;
    } else {
        z = true;
    }
    textView.setEnabled(z);
}
 
Example 34
Project: GitHub   File: RecyclerViewAdapterHelper.java   Source Code and License 5 votes vote down vote up
/**
 * 处理关键字高亮
 * 如果需要检索算法库,请联系我
 *
 * @param originStr       被处理字符串
 * @param keyWord         关键字
 * @param hightLightColor 高亮颜色
 * @return CharSequence
 */
public static CharSequence handleKeyWordHighLight
(String originStr, String keyWord, @ColorInt int hightLightColor) {

    SpannableString ss = new SpannableString(originStr);
    Pattern p = Pattern.compile(keyWord);
    Matcher m = p.matcher(ss);

    while (m.find()) {
        ss.setSpan(new ForegroundColorSpan(hightLightColor), m.start(), m.end(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
    }

    return ss;
}
 
Example 35
Project: revolution-irc   File: SpannableStringHelper.java   Source Code and License 5 votes vote down vote up
public static Object cloneSpan(Object span) {
    if (span instanceof ForegroundColorSpan)
        return new ForegroundColorSpan(((ForegroundColorSpan) span).getForegroundColor());
    if (span instanceof BackgroundColorSpan)
        return new BackgroundColorSpan(((BackgroundColorSpan) span).getBackgroundColor());
    if (span instanceof StyleSpan)
        return new StyleSpan(((StyleSpan) span).getStyle());
    return null;
}
 
Example 36
Project: UltimateRecyclerView   File: StickyAdapter.java   Source Code and License 5 votes vote down vote up
private void setData(SuperViewHolder holder, StockEntity.StockInfo item) {
    final String stockNameAndCode = item.stock_name + "\n" + item.stock_code;
    SpannableStringBuilder ssb = new SpannableStringBuilder(stockNameAndCode);
    ssb.setSpan(new ForegroundColorSpan(Color.parseColor("#a4a4a7")), item.stock_name.length(), stockNameAndCode.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
    ssb.setSpan(new AbsoluteSizeSpan(dip2px(holder.itemView.getContext(), 13)), item.stock_name.length(), stockNameAndCode.length(),
            Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);

    ((TextView) holder.getView(R.id.tv_stock_name_code)).setText(ssb);
    ((TextView) holder.getView(R.id.tv_current_price)).setText(item.current_price);
    ((TextView) holder.getView(R.id.tv_rate)).setText(item.rate < 0 ? String.format("%.2f", item.rate) : ("+" + String.format("%.2f", item.rate)) + "%");
}
 
Example 37
Project: QMark   File: EditSourceListAdapter.java   Source Code and License 5 votes vote down vote up
@Override
public void bind(int position, EditSourceListBean data) {
	mFB.display(mImgBg, data.imgBgUrl);
	mFB.display(mImgCatgy, data.ImgCatgyUrl);
	mTextLeft.setText(data.textLeft);
	Resources resources = getView().getResources();
	SpannableStringBuilder spans = new SpannableStringBuilder(resources.getString(R.string.i_m_category_text_sign_count, data.textSignSize));
	spans.setSpan(new ForegroundColorSpan(resources.getColor(R.color.text_title_orange)), 0, 2, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
	spans.setSpan(new ForegroundColorSpan(resources.getColor(R.color.text_title_orange)), spans.length() - 3, spans.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
	mTextSignSize.setText(spans);
}
 
Example 38
Project: reactive-architectures-playground   File: FactsViewModelMapper.java   Source Code and License 5 votes vote down vote up
private FactViewModel composedWithSpans(FactAboutNumber fact) {

        int accent = ContextCompat.getColor(context, R.color.colorAccent);

        return ComposedWithSpannedStyles.with(
                fact.number,
                " " + formatFact(fact.number, fact.fact),
                new ForegroundColorSpan(accent)
        );
    }
 
Example 39
Project: GongXianSheng   File: AbstractStockListFragment.java   Source Code and License 5 votes vote down vote up
@Override
public void onBindViewHolder(ViewHolder viewHolder, int position) {
    final StockItem bean = mStockList.get(position);
    StockItem.Product productBean = bean.getProduct();
    if (productBean != null) {
        if (!TextUtils.isEmpty(mKeyword)) {
            int index = productBean.getName().indexOf(mKeyword);
            if (index != -1) {
                SpannableString spannStr = new SpannableString(productBean.getName());
                spannStr.setSpan(new ForegroundColorSpan(Color.parseColor("#6bb400")), index, index + mKeyword.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
                viewHolder.name.setText(spannStr);
            }
        } else {
            viewHolder.name.setText(productBean.getName());
        }
        viewHolder.number.setText(productBean.getDefaultCode() + " | ");
        viewHolder.content.setText(productBean.getUnit());
        if (productBean.getImage() !=null){
            FrecoFactory.getInstance(getActivity()).disPlay(viewHolder.sDv, RunwiseService.ENDPOINT + productBean.getImage().getImageSmall());
        }
    }
    viewHolder.value.setText(NumberUtil.getIOrD(String.valueOf(bean.getQty())));
    viewHolder.uom.setText(bean.getUom());
    if (TextUtils.isEmpty(bean.getLotNum())){
        viewHolder.dateNumber.setVisibility(View.INVISIBLE);
    }else{
        viewHolder.dateNumber.setText(bean.getLotNum());
        viewHolder.dateNumber.setVisibility(View.VISIBLE);
    }
    viewHolder.dateLate.setText(DateFormateUtil.getLaterFormat(bean.getLifeEndDate()));
}
 
Example 40
Project: Exoplayer2Radio   File: Tx3gDecoder.java   Source Code and License 5 votes vote down vote up
private static void attachColor(SpannableStringBuilder cueText, int colorRgba,
    int defaultColorRgba, int start, int end, int spanPriority) {
  if (colorRgba != defaultColorRgba) {
    int colorArgb = ((colorRgba & 0xFF) << 24) | (colorRgba >>> 8);
    cueText.setSpan(new ForegroundColorSpan(colorArgb), start, end,
        Spanned.SPAN_EXCLUSIVE_EXCLUSIVE | spanPriority);
  }
}
 
Example 41
Project: LiteReader   File: MovieItemDialog.java   Source Code and License 5 votes vote down vote up
public Spanned getRating() {
    String text = item.rating.average + "/" + item.rating.max;
    Spannable builder = new SpannableStringBuilder(text);
    int start = text.indexOf('/');
    builder.setSpan(new AbsoluteSizeSpan(60), 0, start, Spanned.SPAN_INCLUSIVE_INCLUSIVE);
    builder.setSpan(new ForegroundColorSpan(getContext().getResources().getColor(R.color.colorPrimary)), 0, start, Spanned.SPAN_INCLUSIVE_INCLUSIVE);
    return builder;
}
 
Example 42
Project: RNLearn_Project1   File: ReactEditText.java   Source Code and License 5 votes vote down vote up
/**
 * Remove and/or add {@link Spanned.SPAN_EXCLUSIVE_EXCLUSIVE} spans, since they should only exist
 * as long as the text they cover is the same. All other spans will remain the same, since they
 * will adapt to the new text, hence why {@link SpannableStringBuilder#replace} never removes
 * them.
 */
private void manageSpans(SpannableStringBuilder spannableStringBuilder) {
  Object[] spans = getText().getSpans(0, length(), Object.class);
  for (int spanIdx = 0; spanIdx < spans.length; spanIdx++) {
    // Remove all styling spans we might have previously set
    if (ForegroundColorSpan.class.isInstance(spans[spanIdx]) ||
        BackgroundColorSpan.class.isInstance(spans[spanIdx]) ||
        AbsoluteSizeSpan.class.isInstance(spans[spanIdx]) ||
        CustomStyleSpan.class.isInstance(spans[spanIdx]) ||
        ReactTagSpan.class.isInstance(spans[spanIdx])) {
      getText().removeSpan(spans[spanIdx]);
    }

    if ((getText().getSpanFlags(spans[spanIdx]) & Spanned.SPAN_EXCLUSIVE_EXCLUSIVE) !=
        Spanned.SPAN_EXCLUSIVE_EXCLUSIVE) {
      continue;
    }
    Object span = spans[spanIdx];
    final int spanStart = getText().getSpanStart(spans[spanIdx]);
    final int spanEnd = getText().getSpanEnd(spans[spanIdx]);
    final int spanFlags = getText().getSpanFlags(spans[spanIdx]);

    // Make sure the span is removed from existing text, otherwise the spans we set will be
    // ignored or it will cover text that has changed.
    getText().removeSpan(spans[spanIdx]);
    if (sameTextForSpan(getText(), spannableStringBuilder, spanStart, spanEnd)) {
      spannableStringBuilder.setSpan(span, spanStart, spanEnd, spanFlags);
    }
  }
}
 
Example 43
Project: AboutView   File: BaseCustomTagHandler.java   Source Code and License 5 votes vote down vote up
private void endCode(Editable output, XMLReader xmlReader) {
    output.append(" ");
    int code_end = output.length();
    output.setSpan(new ForegroundColorSpan(Color.parseColor("#f44336")), code_start, code_end, Spannable.SPAN_MARK_MARK);
    output.setSpan(new BackgroundColorSpan(Color.parseColor("#ffebee")), code_start, code_end, Spannable.SPAN_MARK_MARK);
    //output.append(" ");
}
 
Example 44
Project: CommentView   File: SpanUtil.java   Source Code and License 5 votes vote down vote up
/**
 * 描述: 每一个spannable都需要单独的spannable对象设置,
 * 不然多个循环使用同一个只有last现实.
 * @param selectColor
 * @param list
 * @param callback
 * @param ss
 */
private static void setListSpan(int selectColor, @NonNull List<Extractor.Entity> list,
                                OnCommentTouchListener callback, SpannableString ss) {
    for (Extractor.Entity en : list) {
        TouchableSpan touchableSpan = new TouchableSpan(en.getType(), en.getValue(), callback);
        ss.setSpan(touchableSpan, en.getStart(), en.getEnd(), Constants.SPAN_FLAGS);
        ForegroundColorSpan foregroundColorSpan = new ForegroundColorSpan(selectColor);
        ss.setSpan(foregroundColorSpan, en.getStart(), en.getEnd(), Constants.SPAN_FLAGS);
    }
}
 
Example 45
Project: letv   File: LetvWoFlowActivity.java   Source Code and License 5 votes vote down vote up
public void showOrderSuccessUI() {
    this.mOrder_already.setVisibility(8);
    this.mOrder_fail.setVisibility(8);
    this.mOreder.setVisibility(8);
    this.mGoSeeVideo.setVisibility(8);
    this.mUnOrder_success.setVisibility(8);
    this.mUnOrder_fail.setVisibility(8);
    this.mOrderNotSameVip.setVisibility(8);
    this.mNotUnorder.setVisibility(8);
    this.mOrder_success.setVisibility(0);
    SpannableString sp = new SpannableString(getString(2131101210, new Object[]{this.phoneNum, this.phoneNum}));
    sp.setSpan(new ForegroundColorSpan(Color.parseColor("#ec8e1f")), 7, 18, 34);
    this.mOrderSuccessPhoneNum.setText(sp);
    StatisticsUtils.staticticsInfoPost(this, "19", null, null, -1, null, PageIdConstant.woOrderSuccessPage, null, null, null, null, null);
}
 
Example 46
Project: revolution-irc   File: MessageBuilder.java   Source Code and License 5 votes vote down vote up
public CharSequence createTimestamp(Date date, boolean addDefaultColorSpan) {
    String ds = getMessageTimeFormat().format(date);
    if (!mMessageTimeFixedWidth && !addDefaultColorSpan)
        return ds;
    SpannableString ret = new SpannableString(ds + (mMessageTimeFixedWidth ? " " : ""));
    if (mMessageTimeFixedWidth)
        ret.setSpan(new FixedWidthTimestampSpan(ds.length()), ds.length(), ret.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
    if (addDefaultColorSpan)
        ret.setSpan(new ForegroundColorSpan(mContext.getResources().getColor(R.color.messageTimestamp)), 0, ret.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
    return ret;
}
 
Example 47
Project: letv   File: StringUtils.java   Source Code and License 5 votes vote down vote up
public static SpannableString highlightParamText(String inputString, String highlight, int color) {
    inputString = String.format(inputString, new Object[]{highlight});
    SpannableString spanString = new SpannableString(inputString);
    if (!TextUtils.isEmpty(inputString)) {
        int beginPos = inputString.indexOf(highlight);
        if (beginPos > -1) {
            spanString.setSpan(new ForegroundColorSpan(color), beginPos, highlight.length() + beginPos, 33);
        }
    }
    return spanString;
}
 
Example 48
Project: PeSanKita-android   File: ContactSelectionListAdapter.java   Source Code and License 5 votes vote down vote up
private CharSequence getSpannedHeaderString(int position) {
  final String headerString = getHeaderString(position);
  if (isPush(position)) {
    SpannableString spannable = new SpannableString(headerString);
    spannable.setSpan(new ForegroundColorSpan(getContext().getResources().getColor(R.color.signal_primary)), 0, headerString.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
    return spannable;
  } else {
    return headerString;
  }
}
 
Example 49
Project: godlibrary   File: SpannableUtils.java   Source Code and License 5 votes vote down vote up
public static SpannableString setTextSpannable(TextView textView, String[] strings, int[] color, final OnItemViewListener listener) {
    int start = 0;
    int end = 0;
    StringBuilder sb = new StringBuilder();
    for (String str : strings) {
        if (str != null) {
            sb.append(str);
        }
    }
    SpannableString spannableString = new SpannableString(sb.toString());
    for (int i = 0; i < strings.length; ++i) {
        if (strings[i] != null) {
            end += strings[i].length();
            if (color.length == 1) {
                spannableString.setSpan(new ForegroundColorSpan(textView.getResources().getColor(color[0])), start, end, Spanned.SPAN_EXCLUSIVE_INCLUSIVE);
            } else if (color[i] > 0) {
                spannableString.setSpan(new ForegroundColorSpan(textView.getResources().getColor(color[i])), start, end, Spanned.SPAN_EXCLUSIVE_INCLUSIVE);
            }
            if (listener != null) {
                final int finalI = i;
                ClickableSpan cbs = new ClickableSpan() {
                    @Override
                    public void onClick(View view) {
                        listener.onItemViewClick(null, view, finalI);
                    }
                    @Override
                    public void updateDrawState(TextPaint textPaint) {
                        textPaint.setUnderlineText(false);
                    }
                };
                spannableString.setSpan(cbs, start, end, Spanned.SPAN_EXCLUSIVE_INCLUSIVE);
            }
            start += strings[i].length();
        }
    }

    textView.setMovementMethod(LinkMovementMethod.getInstance());
    textView.setText(spannableString);
    return spannableString;
}
 
Example 50
Project: search-dialog   File: StringsHelper.java   Source Code and License 5 votes vote down vote up
public static SpannableStringBuilder highlightLCS(String text1, String text2,
                                                  int highlightColor) {
    // TODO fix exact match highlighting
    String lcs = lcs(text1.toLowerCase(), text2.toLowerCase());
    String tLower = text1.toLowerCase();
    SpannableStringBuilder builder = new SpannableStringBuilder();
    builder.append(text1);
    for (int i = 0; i < tLower.length() && lcs.length() > 0; i++) {
        if (tLower.charAt(i) == lcs.charAt(0)) {
            builder.setSpan(new ForegroundColorSpan(highlightColor), i, i + 1, 0);
            lcs = lcs.substring(1);
        }
    }
    return builder;
}
 
Example 51
Project: letv   File: DownloadVideoPageActivity.java   Source Code and License 5 votes vote down vote up
public SpannableString highlightLoginText(String inputString) {
    SpannableString spanString = new SpannableString(inputString);
    if (!TextUtils.isEmpty(inputString)) {
        int beginPos = inputString.indexOf(LOGIN_TEXT);
        if (beginPos > -1) {
            spanString.setSpan(new ForegroundColorSpan(getResources().getColor(2131493195)), beginPos, beginPos + 2, 33);
        }
    }
    return spanString;
}
 
Example 52
Project: letv   File: DownloadVideoAlbumPageActivity.java   Source Code and License 5 votes vote down vote up
public SpannableString highlightLoginText(String inputString) {
    SpannableString spanString = new SpannableString(inputString);
    if (!TextUtils.isEmpty(inputString)) {
        int beginPos = inputString.indexOf(LOGIN_TEXT);
        if (beginPos > -1) {
            spanString.setSpan(new ForegroundColorSpan(getResources().getColor(R.color.letv_color_ee7a24)), beginPos, beginPos + 2, 33);
        }
    }
    return spanString;
}
 
Example 53
Project: StallBuster   File: ReportDetailActivity.java   Source Code and License 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_report_detail);

    mActivityRecord = (ActivityRecord) getIntent().getSerializableExtra("activity_record");

    if (mActivityRecord == null) {
        finish();
        return;
    }

    ((TextView) findViewById(R.id.time)).setText(Utils.DATE_FORMAT.format(new Date(mActivityRecord.when)));
    String title = getString(R.string.record_cost, mActivityRecord.cost, mActivityRecord.activity_name);
    SpannableString ss = new SpannableString(title);
    ForegroundColorSpan colorSpan = new ForegroundColorSpan(mActivityRecord.cost >= StallBuster.getInstance().getThreshold() ? Constants.COLOR_WARNING : Constants.COLOR_NORMAL);
    ss.setSpan(colorSpan, 0, title.indexOf(" "), Spanned.SPAN_INCLUSIVE_INCLUSIVE);
    ((TextView) findViewById(R.id.title)).setText(ss);
    mFilterCb = (CheckBox) findViewById(R.id.filter);
    mFilterCb.setText(getString(R.string.cb_hide_system_callbacks_executed_less_than_some_ms, StallBuster.getInstance().getCallbackThreshold()));
    mFilterCb.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
            mAdapter.setData(filteredRecords());
        }
    });

    mAdapter = new ReportDetailAdapter();
    RecyclerView container = (RecyclerView) findViewById(R.id.container);
    LinearLayoutManager lm = new LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false);
    container.setLayoutManager(lm);
    container.addItemDecoration(new SimpleDecoration());
    mAdapter.setData(filteredRecords());
    container.setAdapter(mAdapter);
}
 
Example 54
Project: letv   File: AlbumPlayVipTrailController.java   Source Code and License 5 votes vote down vote up
public void vipTrailEndByHasTicket(boolean hasTicket) {
    int i;
    this.mErrState = hasTicket ? VipTrailErrorState.END_WITH_TICKET : VipTrailErrorState.END_WITH_NOT_TICKET;
    vipTrailEndInit();
    this.mEndBuyVipView.setVisibility(8);
    View view = this.mEndUseTicketView;
    if (hasTicket) {
        i = 0;
    } else {
        i = 8;
    }
    view.setVisibility(i);
    view = this.mEndTicketNoneView;
    if (hasTicket) {
        i = 8;
    } else {
        i = 0;
    }
    view.setVisibility(i);
    if (hasTicket && this.mPayInfo != null) {
        this.mEndUseTicketTitleView.setText(R.string.vip_trail_has_be_member);
        SpannableStringBuilder style = new SpannableStringBuilder(String.format(this.mActivity.getString(R.string.vip_trail_over_use_ticket_text2), new Object[]{Integer.valueOf(this.mPayInfo.vipTicketSize)}));
        style.setSpan(new ForegroundColorSpan(this.mActivity.getResources().getColor(R.color.letv_color_ffec8e1f)), 8, String.valueOf(this.mPayInfo.vipTicketSize).length() + 8, 33);
        this.mEndUseTicketTextView.setText(style);
        this.mEndUseTicketTipView.setText(this.mActivity.getString(R.string.vip_trail_ticket_use_success, new Object[]{this.mPayInfo.validDays}));
        this.mUseTicketSuccessTipView.setText(this.mActivity.getString(R.string.vip_trail_ticket_use_success, new Object[]{this.mPayInfo.validDays}));
        this.mEndUseTicketBtn.setText(R.string.vip_trail_use_ticket);
        this.mEndUseTicketTipView.setVisibility(0);
        this.mEndUseTicketByVipFrame.setVisibility(8);
    }
}
 
Example 55
Project: BilibiliClient   File: HomeRecommendedSection.java   Source Code and License 5 votes vote down vote up
@SuppressLint("SetTextI18n")
@Override
public void onBindHeaderViewHolder(RecyclerView.ViewHolder holder) {

  HeaderViewHolder headerViewHolder = (HeaderViewHolder) holder;
  setTypeIcon(headerViewHolder);
  headerViewHolder.mTypeTv.setText(title);
  headerViewHolder.mTypeRankBtn.setOnClickListener(v -> mContext.startActivity(
      new Intent(mContext, OriginalRankActivity.class)));

  switch (type) {
    case TYPE_RECOMMENDED:
      headerViewHolder.mTypeMore.setVisibility(View.GONE);
      headerViewHolder.mTypeRankBtn.setVisibility(View.VISIBLE);
      headerViewHolder.mAllLiveNum.setVisibility(View.GONE);
      break;
    case TYPE_LIVE:
      headerViewHolder.mTypeRankBtn.setVisibility(View.GONE);
      headerViewHolder.mTypeMore.setVisibility(View.VISIBLE);
      headerViewHolder.mAllLiveNum.setVisibility(View.VISIBLE);
      SpannableStringBuilder stringBuilder = new SpannableStringBuilder("当前" + liveCount + "个直播");
      ForegroundColorSpan foregroundColorSpan = new ForegroundColorSpan(
          mContext.getResources().getColor(R.color.pink_text_color));
      stringBuilder.setSpan(foregroundColorSpan, 2,
          stringBuilder.length() - 3, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
      headerViewHolder.mAllLiveNum.setText(stringBuilder);
      break;
    default:
      headerViewHolder.mTypeRankBtn.setVisibility(View.GONE);
      headerViewHolder.mTypeMore.setVisibility(View.VISIBLE);
      headerViewHolder.mAllLiveNum.setVisibility(View.GONE);
      break;
  }
}
 
Example 56
Project: BilibiliClient   File: HomeRecommendedSection.java   Source Code and License 5 votes vote down vote up
@Override
public void onBindHeaderViewHolder(RecyclerView.ViewHolder holder) {
    HeaderViewHolder viewHolder = (HeaderViewHolder) holder;
    setTypeIcon(viewHolder);
    viewHolder.mTypeTv.setText(title);
    viewHolder.mTypeRankBtn.setOnClickListener(v -> {
        mContext.startActivity(new Intent(mContext, OriginalRankActivity.class));
    });
    switch(type){
        case TYPE_RECOMMENDED:
            viewHolder.mTypeMore.setVisibility(View.GONE);
            viewHolder.mTypeRankBtn.setVisibility(View.VISIBLE);
            viewHolder.mAllLiveNum.setVisibility(View.GONE);
            break;
        case TYPE_LIVE:
            viewHolder.mTypeMore.setVisibility(View.VISIBLE);
            viewHolder.mTypeRankBtn.setVisibility(View.GONE);
            viewHolder.mAllLiveNum.setVisibility(View.VISIBLE);
            SpannableStringBuilder builder = new SpannableStringBuilder("当前" + liveCount + "个直播");
            ForegroundColorSpan colorSpan = new ForegroundColorSpan(mContext.getResources().getColor(R.color.pink_text_color));
            builder.setSpan(colorSpan, 2, builder.length() - 3, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
            viewHolder.mAllLiveNum.setText(builder);
            break;
        default :
            viewHolder.mTypeMore.setVisibility(View.VISIBLE);
            viewHolder.mTypeRankBtn.setVisibility(View.GONE);
            viewHolder.mAllLiveNum.setVisibility(View.GONE);
            break;
    }
}
 
Example 57
Project: WeChatFingerprintPay   File: PaySettingActivity.java   Source Code and License 5 votes vote down vote up
private void onError(String msg) {
    Spannable summary = new SpannableString(msg);
    summary.setSpan(new ForegroundColorSpan(mContext.getColor(R.color.colorError)), 0, summary.length(), 0);
    prefEnable.setSummary(summary);
    prefEnable.setEnabled(false);
    prefEnable.setShouldDisableView(true);
}
 
Example 58
Project: stay-awake-app   File: MainActivity.java   Source Code and License 5 votes vote down vote up
private void setColorSpanOnTextView(TextView view, String fulltext, String subtext, int color) {
    view.setText(fulltext, TextView.BufferType.SPANNABLE);
    Spannable str = (Spannable) view.getText();
    int i = fulltext.indexOf(subtext);
    str.setSpan(new ForegroundColorSpan(color), i, i + subtext.length(),
                Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
}
 
Example 59
Project: Hitalk   File: SearchFriend2Layout.java   Source Code and License 5 votes vote down vote up
private void setStartContent(String text){
    startContentBuilder.clearSpans();
    startContentBuilder.clear();
    SpannableString searchStr = new SpannableString(mRes.getString(R.string.search) + ":");
    searchStr.setSpan(new ForegroundColorSpan(Color.BLACK),0,searchStr.length(), Spannable.SPAN_INCLUSIVE_INCLUSIVE);
    SpannableString startContent = new SpannableString(text);
    startContent.setSpan(new ForegroundColorSpan(mRes.getColor(R.color.hitalk_yellow))
            ,0,startContent.length(), Spannable.SPAN_INCLUSIVE_INCLUSIVE);
    startContentBuilder.append(searchStr).append(startContent);
    searchStartTv.setText(startContentBuilder);
}
 
Example 60
Project: boohee_v5.6   File: MQChatAdapter.java   Source Code and License 5 votes vote down vote up
private void setDirectionMessageContent(String agentNickName, TextView tipTv) {
    if (agentNickName != null) {
        String text = String.format(tipTv.getResources().getString(R.string
                .mq_direct_content), new Object[]{agentNickName});
        int start = text.indexOf(agentNickName);
        SpannableStringBuilder style = new SpannableStringBuilder(text);
        style.setSpan(new ForegroundColorSpan(tipTv.getResources().getColor(R.color
                .mq_chat_direct_agent_nickname_textColor)), start, agentNickName.length() +
                start, 34);
        tipTv.setText(style);
    }
}