android.text.style.ForegroundColorSpan Java Examples

The following examples show how to use android.text.style.ForegroundColorSpan. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: MeechaoDataUtils.java    From timecat with Apache License 2.0 6 votes vote down vote up
/**
 * 文字格式化,适用但不局限于心得内容,用于处理给定内容 str 中的标签
 *
 * @param str 给定内容
 *
 * @return s
 */
public static SpannableStringBuilder covArticleContent(String str) {
    if (TextUtils.isEmpty(str)) {
        return null;
    }
    SpannableStringBuilder builder = new SpannableStringBuilder(str);
    List<String> tagList = RegexUtil.getMathcherStr(str, RegexUtil.topicValReg);
    if (null != tagList && tagList.size() != 0) {
        int fromIndex = 0;
        for (String tagVal : tagList) {
            int _start = str.indexOf(tagVal, fromIndex);
            builder.setSpan(new ForegroundColorSpan(Color.parseColor("#ffaa31")),
                    _start, _start + tagVal.length(), Spannable.SPAN_EXCLUSIVE_INCLUSIVE);
            builder.setSpan(new AbsoluteSizeSpan(0, true), _start + tagVal.indexOf("["), _start + tagVal.indexOf("]") + 1,
                    Spannable.SPAN_EXCLUSIVE_INCLUSIVE);
            fromIndex = _start + tagVal.length();
        }
    }
    return builder;
}
 
Example #2
Source File: ContactViewDialogFragment.java    From natrium-android-wallet with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public void onClickRemove(View v) {
    int style = android.os.Build.VERSION.SDK_INT >= 21 ? R.style.AlertDialogCustom : android.R.style.Theme_Holo_Dialog;
    AlertDialog.Builder builder = new AlertDialog.Builder(getContext(), style);
    SpannableString title = new SpannableString(getString(R.string.contact_remove_btn));
    title.setSpan(new ForegroundColorSpan(getResources().getColor(R.color.ltblue)), 0, title.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);

    SpannableString positive = new SpannableString(getString(R.string.intro_new_wallet_backup_yes));
    positive.setSpan(new ForegroundColorSpan(getResources().getColor(R.color.ltblue)), 0, positive.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
    SpannableString negative = new SpannableString(getString(R.string.intro_new_wallet_backup_no));
    negative.setSpan(new ForegroundColorSpan(getResources().getColor(R.color.ltblue)), 0, negative.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
    builder.setTitle(title)
            .setMessage(getString(R.string.contact_remove_sure, binding.contactName.getText().toString()))
            .setPositiveButton(positive, (dialog, which) -> {
                realm.executeTransaction(realm -> {
                    RealmResults<Contact> contact = realm.where(Contact.class).equalTo("name", binding.contactName.getText().toString()).findAll();
                    contact.deleteAllFromRealm();
                });
                RxBus.get().post(new ContactRemoved(binding.contactName.getText().toString(), binding.contactAddress.getText().toString()));
                dismiss();
            })
            .setNegativeButton(negative, (dialog, which) -> {
                // do nothing which dismisses the dialog
            })
            .show();
}
 
Example #3
Source File: MediaPlayerFragment.java    From PowerFileExplorer with GNU General Public License v3.0 6 votes vote down vote up
private CharSequence generateFastForwardOrRewindTxt(long changingTime) {

        long duration = player == null ? 0 : player.getDuration();
        String result = stringForTime(changingTime) + " / " + stringForTime(duration);

        int index = result.indexOf("/");
        SpannableString spannableString = new SpannableString(result);

        TypedValue typedValue = new TypedValue();
        TypedArray a = getContext().obtainStyledAttributes(typedValue.data, new int[]{R.attr.colorAccent});
        int color = a.getColor(0, 0);
        a.recycle();
        spannableString.setSpan(new ForegroundColorSpan(color), 0, index, Spanned.SPAN_INCLUSIVE_EXCLUSIVE);

        return spannableString;
    }
 
Example #4
Source File: VoIPActivity.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
private CharSequence getFormattedDebugString(){
    String in=VoIPService.getSharedInstance().getDebugString();
    SpannableString ss=new SpannableString(in);

    int offset=0;
    do{
        int lineEnd=in.indexOf('\n', offset+1);
        if(lineEnd==-1)
            lineEnd=in.length();
        String line=in.substring(offset, lineEnd);
        if(line.contains("IN_USE")){
            ss.setSpan(new ForegroundColorSpan(0xFF00FF00), offset, lineEnd, 0);
        }else{
            if(line.contains(": ")){
                ss.setSpan(new ForegroundColorSpan(0xAAFFFFFF), offset, offset+line.indexOf(':')+1, 0);
            }
        }
    }while((offset=in.indexOf('\n', offset+1))!=-1);

    return ss;
}
 
Example #5
Source File: Util.java    From QuranyApp with Apache License 2.0 6 votes vote down vote up
public static Spannable getSpanOfText(String text, String word) {
        Spannable spannable = new SpannableString(text);
        String REGEX = word;
        Pattern p = Pattern.compile(REGEX);
        Matcher m = p.matcher(text);

        //    Log.d(TAG, text + "getSpanOfText: word " + word);
        while (m.find()) {
//            Log.d(TAG, "getSpanOfText: start " + m.start());
//            Log.d(TAG, "getSpanOfText: end " + m.end());
            spannable.setSpan(new ForegroundColorSpan(Color.YELLOW), m.start(), m.end(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);

        }
        return spannable;

    }
 
Example #6
Source File: TopicTimelineAdapterWithThirdLib.java    From JReadHub with GNU General Public License v3.0 6 votes vote down vote up
@Override
protected void convert(BaseViewHolder holder, RelevantTopicBean relevantTopicBean) {
    LocalDate date = relevantTopicBean.getCreatedAt().toLocalDate();
    int year = date.getYear();
    int month = date.getMonthValue();
    int day = date.getDayOfMonth();
    if (year == OffsetDateTime.now().getYear()) {
        holder.setText(R.id.txt_date, mContext.getString(R.string.month__day, month, day));
    } else {
        SpannableString spannableTitle = SpannableString.valueOf(mContext.getString(R.string.month__day__year, month, day, year));
        spannableTitle.setSpan(new ForegroundColorSpan(ContextCompat.getColor(mContext, R.color.text_topic_detail_news_author)),
                spannableTitle.toString().indexOf("\n") + 1,
                spannableTitle.toString().indexOf("\n") + 5,
                Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        holder.setText(R.id.txt_date, spannableTitle);
    }
    holder.setText(R.id.txt_topic_trace_content, relevantTopicBean.getTitle());
    holder.setVisible(R.id.view_top_line, holder.getItemViewType() == VIEW_TYPE_TOP || holder.getItemViewType() == VIEW_TYPE_ONLY_ONE ? false : true);
    holder.setVisible(R.id.view_bottom_line, holder.getItemViewType() == VIEW_TYPE_BOTTOM || holder.getItemViewType() == VIEW_TYPE_ONLY_ONE ? false : true);
}
 
Example #7
Source File: ForgetIphonePasswordFragment.java    From FimiX8-RE with MIT License 6 votes vote down vote up
private SpannableString getSpannableString() {
    String str1 = this.mContext.getString(R.string.login_send_email_hint1);
    String str2 = this.mContext.getString(R.string.login_send_email_hint2);
    String str3 = this.mContext.getString(R.string.login_send_email_hint3);
    SpannableString spannableString = new SpannableString(str1 + str2 + str3);
    spannableString.setSpan(new ForegroundColorSpan(this.mContext.getResources().getColor(R.color.register_agreement)), 0, str1.length(), 33);
    spannableString.setSpan(new ForegroundColorSpan(this.mContext.getResources().getColor(R.color.register_agreement)), str1.length() + str2.length(), (str1.length() + str2.length()) + str3.length(), 33);
    spannableString.setSpan(new ClickableSpan() {
        public void updateDrawState(TextPaint ds) {
            super.updateDrawState(ds);
            ds.setColor(ForgetIphonePasswordFragment.this.getResources().getColor(R.color.register_agreement_click));
            ds.setUnderlineText(false);
        }

        public void onClick(View widget) {
        }
    }, str1.length(), str1.length() + str2.length(), 33);
    return spannableString;
}
 
Example #8
Source File: RankTipActivity.java    From tysq-android with GNU General Public License v3.0 6 votes vote down vote up
/**
 * 组装红色字体
 */
private void AssemBleText(String score, String tip, boolean isGrade){

    int scoreStartIndex = tip.indexOf(score);
    int scoreEndIndex = scoreStartIndex + score.length();
    if (!isGrade){
        scoreEndIndex += 2;
    }

    SpannableString tipSpanBuilder = new SpannableString(tip);
    ForegroundColorSpan span = new ForegroundColorSpan(ContextCompat.getColor(this, R.color.red));
    tipSpanBuilder.setSpan(span, scoreStartIndex,
            scoreEndIndex,
            Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);

    tvTip.setText(tipSpanBuilder);
}
 
Example #9
Source File: StickerSetNameCell.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
public void setText(CharSequence text, int resId, int index, int searchLength) {
    if (text == null) {
        empty = true;
        textView.setText("");
        buttonView.setVisibility(INVISIBLE);
    } else {
        if (searchLength != 0) {
            SpannableStringBuilder builder = new SpannableStringBuilder(text);
            try {
                builder.setSpan(new ForegroundColorSpan(Theme.getColor(Theme.key_windowBackgroundWhiteBlueText4)), index, index + searchLength, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
            } catch (Exception ignore) {

            }
            textView.setText(builder);
        } else {
            textView.setText(Emoji.replaceEmoji(text, textView.getPaint().getFontMetricsInt(), AndroidUtilities.dp(14), false));
        }
        if (resId != 0) {
            buttonView.setImageResource(resId);
            buttonView.setVisibility(VISIBLE);
        } else {
            buttonView.setVisibility(INVISIBLE);
        }
    }
}
 
Example #10
Source File: ForgetPasswordFragment.java    From FimiX8-RE with MIT License 6 votes vote down vote up
private SpannableString getEmailVerficationSpannableString() {
    String str1 = this.mContext.getString(R.string.login_email_send_hint1);
    String str2 = this.mContext.getString(R.string.login_send_email_hint2);
    SpannableString spannableString = new SpannableString(str1 + str2);
    spannableString.setSpan(new ForegroundColorSpan(this.mContext.getResources().getColor(R.color.register_agreement)), 0, str1.length(), 33);
    spannableString.setSpan(new ForegroundColorSpan(this.mContext.getResources().getColor(R.color.register_agreement)), str1.length() + str2.length(), str1.length() + str2.length(), 33);
    spannableString.setSpan(new ClickableSpan() {
        public void updateDrawState(TextPaint ds) {
            super.updateDrawState(ds);
            ds.setColor(ForgetPasswordFragment.this.getResources().getColor(R.color.register_agreement_click));
            ds.setUnderlineText(false);
        }

        public void onClick(View widget) {
        }
    }, str1.length(), str1.length() + str2.length(), 33);
    return spannableString;
}
 
Example #11
Source File: SocialMentionAutoComplete.java    From SocialMentionAutoComplete with Apache License 2.0 6 votes vote down vote up
public CharSequence terminateToken(CharSequence text) {

            int i = text.length();

            while (i > 0 && text.charAt(i - 1) == ' ') {
                i--;
            }

            if (i > 0 && text.charAt(i - 1) == ' ') {
                return text;
            } else {
                // Returns colored text for selected token
                SpannableString sp = new SpannableString(String.format(formattedOfString, text));
                int textColor = ResourcesCompat.getColor(getResources(), R.color.colorPrimary, null);
                sp.setSpan(new ForegroundColorSpan(textColor), 0, text.length() + 1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
                return sp;
            }
        }
 
Example #12
Source File: HighLightKeyWordUtil.java    From styT with Apache License 2.0 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 #13
Source File: HomePageSearchAdapter.java    From tysq-android with GNU General Public License v3.0 6 votes vote down vote up
/**
 * 拼装红色字体
 */
private SpannableStringBuilder setTextColor(String content, String input) {
    int startIndex = content.indexOf(input);
    SpannableStringBuilder stringBuilder = new SpannableStringBuilder(content);
    if (startIndex != -1) {

        ForegroundColorSpan colorSpan
                = new ForegroundColorSpan(context.getResources().getColor(R.color.search_color));
        stringBuilder.setSpan(colorSpan,
                startIndex,
                startIndex + input.length(),
                Spannable.SPAN_EXCLUSIVE_INCLUSIVE);
        Log.d("few", "fwe");
    }
    return stringBuilder;
}
 
Example #14
Source File: Html.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
private static void endCssStyle(Editable text) {
    Strikethrough s = getLast(text, Strikethrough.class);
    if (s != null) {
        setSpanFromMark(text, s, new StrikethroughSpan());
    }

    Background b = getLast(text, Background.class);
    if (b != null) {
        setSpanFromMark(text, b, new BackgroundColorSpan(b.mBackgroundColor));
    }

    Foreground f = getLast(text, Foreground.class);
    if (f != null) {
        setSpanFromMark(text, f, new ForegroundColorSpan(f.mForegroundColor));
    }
}
 
Example #15
Source File: AboutActivity.java    From mhzs with MIT License 6 votes vote down vote up
private void initData() {
    isAboutActivity = true;
    ForegroundColorSpan colorSpan = new ForegroundColorSpan(ContextCompat.getColor(this, R.color.colorAccent));

    SpannableString spannableString = new SpannableString("麻花助手当前版本:" + HYHelper.getVerisonName(this));
    spannableString.setSpan(colorSpan, 9, spannableString.length(), Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
    versionTextView.setText(spannableString);

    SpannableString spannableString2 = new SpannableString("支持麻花影视版本:" + Config.SUPPORT_MHYS_VERISON);
    spannableString2.setSpan(colorSpan, 9, spannableString2.length(), Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
    supportVersionText.setText(spannableString2);

    SpannableString spannableString3 = new SpannableString("支持贝贝影视版本:" + Config.SUPPORT_MHYS_VERISON);
    spannableString3.setSpan(colorSpan, 9, spannableString3.length(), Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
    supportBBVersionText.setText(spannableString3);
}
 
Example #16
Source File: BindingAdapters.java    From lttrs-android with Apache License 2.0 6 votes vote down vote up
@BindingAdapter("android:text")
public static void setText(final TextView textView, final FullEmail.From from) {
    if (from instanceof FullEmail.NamedFrom) {
        final FullEmail.NamedFrom named = (FullEmail.NamedFrom) from;
        textView.setText(named.getName());
    } else if (from instanceof FullEmail.DraftFrom) {
        final Context context = textView.getContext();
        final SpannableString spannable = new SpannableString(context.getString(R.string.draft));
        spannable.setSpan(
                new ForegroundColorSpan(ContextCompat.getColor(context, R.color.colorPrimary)),
                0,
                spannable.length(),
                Spannable.SPAN_EXCLUSIVE_EXCLUSIVE
        );
        textView.setText(spannable);
    }
}
 
Example #17
Source File: ConfirmDialog.java    From PocketEOS-Android with GNU Lesser General Public License v3.0 5 votes vote down vote up
public ConfirmDialog setContent(String cont) {
    SpannableString spannableString = new SpannableString(cont);
    int start = cont.indexOf("消费您 ") + 3;
    int end = cont.length() - 3 - 1;
    spannableString.setSpan(new ForegroundColorSpan(context.getResources().getColor(R.color.red_packet_color)), start, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
    content.setText(spannableString);
    return this;
}
 
Example #18
Source File: FileRenamingDialog.java    From apkextractor with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onBindViewHolder(@NonNull ViewHolder viewHolder, int i) {
    final String oldName=getCurrentFileName(viewHolder.getAdapterPosition());
    final String newName=getPreviewRenamedFileName(viewHolder.getAdapterPosition());
    SpannableStringBuilder builder=new SpannableStringBuilder(oldName
            +FILE_RENAME_ARROW
            +newName
            +"\n\n");
    builder.setSpan(new ForegroundColorSpan(getContext().getResources().getColor(R.color.color_text_normal)),0,oldName.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
    builder.setSpan(new ForegroundColorSpan(getContext().getResources().getColor(R.color.colorAccent)),oldName.length(),oldName.length()+FILE_RENAME_ARROW.length(),Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
    builder.setSpan(new ForegroundColorSpan(getContext().getResources().getColor(R.color.colorFirstAttention)),oldName.length()+FILE_RENAME_ARROW.length(),builder.toString().length(),Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
    viewHolder.textView.setText(builder);
}
 
Example #19
Source File: PersonalHomePageFragment.java    From tysq-android with GNU General Public License v3.0 5 votes vote down vote up
/**
 * 设置个人成就富文本
 */
private void setAchievementInfo(TextView textView, String quantity, int stringRes) {

    String content = getString(stringRes);

    String resultContent = String.format(content, quantity);

    int length = quantity.length();

    SpannableStringBuilder builder = new SpannableStringBuilder(resultContent);
    builder.setSpan(new JerryBoldSpan(),
            0,
            length,
            Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);

    builder.setSpan(new ForegroundColorSpan(ContextCompat.getColor(getContext(), R.color.main_text_color)),
            0,
            length,
            Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);

    builder.setSpan(new AbsoluteSizeSpan(16, true),
            0,
            length,
            Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);

    textView.setText(builder);

}
 
Example #20
Source File: Cea608Decoder.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
private static void setColorSpan(
    SpannableStringBuilder builder, int start, int end, int color) {
  if (color == Color.WHITE) {
    // White is treated as the default color (i.e. no span is attached).
    return;
  }
  builder.setSpan(new ForegroundColorSpan(color), start, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
}
 
Example #21
Source File: TerminalFragment.java    From SimpleBluetoothTerminal with MIT License 5 votes vote down vote up
private void send(String str) {
    if(connected != Connected.True) {
        Toast.makeText(getActivity(), "not connected", Toast.LENGTH_SHORT).show();
        return;
    }
    try {
        SpannableStringBuilder spn = new SpannableStringBuilder(str+'\n');
        spn.setSpan(new ForegroundColorSpan(getResources().getColor(R.color.colorSendText)), 0, spn.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        receiveText.append(spn);
        byte[] data = (str + newline).getBytes();
        service.write(data);
    } catch (Exception e) {
        onSerialIoError(e);
    }
}
 
Example #22
Source File: UIUtil.java    From natrium-android-wallet with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public static void colorizeSpannableBright(String prependString, Spannable s, Context context) {
    if (context == null) {
        return;
    }
    int offset = prependString.length();
    if (s.length() > 0) {
        s.setSpan(new ForegroundColorSpan(ContextCompat.getColor(context, R.color.ltblue)), 0, s.length() > 10 ? 11 + offset : s.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        if (s.length() > 58) {
            s.setSpan(new ForegroundColorSpan(ContextCompat.getColor(context, R.color.ltblue)), 58 + offset, s.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        }
    }
}
 
Example #23
Source File: ImageUploadFragment.java    From mcumgr-android with Apache License 2.0 5 votes vote down vote up
private void printError(@NonNull final String error) {
    final SpannableString spannable = new SpannableString(error);
    spannable.setSpan(new ForegroundColorSpan(
                    ContextCompat.getColor(requireContext(), R.color.colorError)),
            0, error.length(), Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
    spannable.setSpan(new StyleSpan(Typeface.BOLD),
            0, error.length(), Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
    mStatus.setText(spannable);
}
 
Example #24
Source File: Cea708Decoder.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
public void setPenColor(int foregroundColor, int backgroundColor, int edgeColor) {
  if (foregroundColorStartPosition != C.POSITION_UNSET) {
    if (this.foregroundColor != foregroundColor) {
      captionStringBuilder.setSpan(new ForegroundColorSpan(this.foregroundColor),
          foregroundColorStartPosition, captionStringBuilder.length(),
          Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
    }
  }
  if (foregroundColor != COLOR_SOLID_WHITE) {
    foregroundColorStartPosition = captionStringBuilder.length();
    this.foregroundColor = foregroundColor;
  }

  if (backgroundColorStartPosition != C.POSITION_UNSET) {
    if (this.backgroundColor != backgroundColor) {
      captionStringBuilder.setSpan(new BackgroundColorSpan(this.backgroundColor),
          backgroundColorStartPosition, captionStringBuilder.length(),
          Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
    }
  }
  if (backgroundColor != COLOR_SOLID_BLACK) {
    backgroundColorStartPosition = captionStringBuilder.length();
    this.backgroundColor = backgroundColor;
  }

  // TODO: Add support for edge color.
}
 
Example #25
Source File: LogbookActivity.java    From homeassist with Apache License 2.0 5 votes vote down vote up
@Override
public void onBindViewHolder(final LogbookViewHolder viewHolder, final int position) {
    final LogSheet logSheet = items.get(position);
    Log.d("YouQi", "rendering: " + position + "logSheet.message: " + logSheet.message);
    //viewHolder.mNameView.setText(logSheet.name);
    viewHolder.mStateText.setText(TextUtils.concat(dateFormat.format(logSheet.when.getTime()), "\n", CommonUtil.getSpanText(LogbookActivity.this, DateUtils.getRelativeTimeSpanString(logSheet.when.getTime()).toString(), null, 0.9f)));
    viewHolder.mIconView.setText(MDIFont.getIcon("mdi:information-outline"));

    Entity entity = getEntity(logSheet.entityId);
    if (entity != null) {
        viewHolder.mIconView.setText(entity.getMdiIcon());
    }


    Spannable wordtoSpan1 = new SpannableString(logSheet.name);
    wordtoSpan1.setSpan(new RelativeSizeSpan(1.0f), 0, wordtoSpan1.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
    wordtoSpan1.setSpan(new StyleSpan(android.graphics.Typeface.BOLD), 0, wordtoSpan1.length(), 0);

    Spannable wordtoSpan2 = new SpannableString(logSheet.message);
    wordtoSpan2.setSpan(new ForegroundColorSpan(ResourcesCompat.getColor(getResources(), R.color.md_grey_500, null)), 0, wordtoSpan2.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
    wordtoSpan2.setSpan(new RelativeSizeSpan(0.95f), 0, wordtoSpan2.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);

    //viewHolder.mNameView.setText(TextUtils.concat(wordtoSpan1, " ", wordtoSpan2));
    viewHolder.mNameView.setText(logSheet.name);
    viewHolder.mSubText.setText(logSheet.message);

}
 
Example #26
Source File: StringHighlighter.java    From java-n-IDE-for-Android with Apache License 2.0 5 votes vote down vote up
@Override
public void highlight(@NonNull Editable allText, @NonNull CharSequence textToHighlight, int start) {
    mStringRegion.clear();
    for (Matcher m = STRINGS.matcher(textToHighlight); m.find(); ) {
        allText.setSpan(new ForegroundColorSpan(codeTheme.getStringColor()),
                start + m.start(),
                start + m.end(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        mStringRegion.add(new Pair<>(start + m.start(), start + m.end()));
    }
}
 
Example #27
Source File: Tx3gDecoder.java    From TelePlus-Android with GNU General Public License v2.0 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 #28
Source File: UIUtil.java    From nano-wallet-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
/**
 * Colorize a string in the following manner:
 * First 9 characters are blue
 * Last 5 characters are orange
 *
 * @param s       Spannable
 * @param context Context
 */
public static void colorizeSpannable(Spannable s, Context context) {
    if (context == null) {
        return;
    }
    if (s.length() > 0) {
        s.setSpan(new ForegroundColorSpan(ContextCompat.getColor(context, R.color.dark_sky_blue)), 0, s.length() > 8 ? 9 : s.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        if (s.length() > 59) {
            s.setSpan(new ForegroundColorSpan(ContextCompat.getColor(context, R.color.burnt_yellow)), 59, s.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        }
    }
}
 
Example #29
Source File: XmlCommentHighlighter.java    From java-n-IDE-for-Android with Apache License 2.0 5 votes vote down vote up
@Override
public void highlight(@NonNull Editable allText, @NonNull CharSequence textToHighlight, int start) {
    mCommentRegion.clear();
    for (Matcher m = XML_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()));
    }
}
 
Example #30
Source File: SearchResultAdapter.java    From CrawlerForReader with Apache License 2.0 5 votes vote down vote up
public SpannableString changeTxtColor(String content, String splitText, int color) {
    int start = 0, end;
    SpannableString result = new SpannableString(content = (content == null ? "" : content));
    if (TextUtils.isEmpty(splitText)) {
        return result;
    }
    if (!TextUtils.isEmpty(splitText) && (content.length() >= splitText.length())) {
        while ((start = content.indexOf(splitText, start)) >= 0) {
            end = start + splitText.length();
            result.setSpan(new ForegroundColorSpan(color), start, end, Spanned.SPAN_EXCLUSIVE_INCLUSIVE);
            start = end;
        }
    }
    return result;
}