List of usage examples for android.text.style ForegroundColorSpan ForegroundColorSpan
public ForegroundColorSpan(@NonNull Parcel src)
From source file:com.example.cassi.hal.adapter.CardPresenter.java
private Spannable getSeedAndLeech(T411TorrentItem item) { String text = "Seed : " + String.valueOf(item.getSeeders()) + " Leech : " + String.valueOf(item.getLeechers()); Spannable spannable = new SpannableString(text); spannable.setSpan(new ForegroundColorSpan(ContextCompat.getColor(mContext, R.color.seedColor)), text.indexOf(String.valueOf(item.getSeeders())), text.indexOf(String.valueOf(item.getSeeders())) + String.valueOf(item.getSeeders()).length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); spannable.setSpan(new ForegroundColorSpan(ContextCompat.getColor(mContext, R.color.leechColor)), text.lastIndexOf(String.valueOf(item.getLeechers())), text.lastIndexOf(String.valueOf(item.getLeechers())) + String.valueOf(item.getLeechers()).length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); return spannable; }
From source file:com.collecdoo.fragment.main.RegisterDriverPhotoFragment.java
private void setColorSpan(TextView textView, int fromPos, int toPos) { SpannableStringBuilder sb = new SpannableStringBuilder(textView.getText()); ForegroundColorSpan fcs = new ForegroundColorSpan(Color.RED); sb.setSpan(fcs, fromPos, toPos, Spannable.SPAN_INCLUSIVE_INCLUSIVE); textView.setText(sb);/* w ww .j a va2 s .com*/ }
From source file:com.android.mms.ui.ConversationListItem.java
private CharSequence formatMessage() { final int color = android.R.styleable.Theme_textColorSecondary; String from = mConversation.getRecipients().formatNames(", "); if (MessageUtils.isWapPushNumber(from)) { String[] mAddresses = from.split(":"); from = mAddresses[mContext.getResources().getInteger(R.integer.wap_push_address_index)]; }//from ww w .j a v a2s . c o m /** * Add boolean to know that the "from" haven't the Arabic and '+'. * Make sure the "from" display normally for RTL. */ boolean isEnName = false; boolean isLayoutRtl = (TextUtils .getLayoutDirectionFromLocale(Locale.getDefault()) == View.LAYOUT_DIRECTION_RTL); if (isLayoutRtl && from != null) { if (from.length() >= 1) { Pattern pattern = Pattern.compile("[^-]+"); Matcher matcher = pattern.matcher(from); isEnName = matcher.matches(); if (isEnName && from.charAt(0) != '\u202D') { from = "\u202D" + from + "\u202C"; } } } SpannableStringBuilder buf = new SpannableStringBuilder(from); if (mConversation.getMessageCount() > 1) { int before = buf.length(); if (isLayoutRtl && isEnName) { buf.insert(1, mConversation.getMessageCount() + " "); buf.setSpan(new ForegroundColorSpan(mContext.getResources().getColor(R.color.message_count_color)), 1, buf.length() - before, Spannable.SPAN_INCLUSIVE_EXCLUSIVE); } else { buf.append(mContext.getResources().getString(R.string.message_count_format, mConversation.getMessageCount())); buf.setSpan(new ForegroundColorSpan(mContext.getResources().getColor(R.color.message_count_color)), before, buf.length(), Spannable.SPAN_INCLUSIVE_EXCLUSIVE); } } if (mConversation.hasDraft()) { if (isLayoutRtl && isEnName) { int before = buf.length(); buf.insert(1, '\u202E' + mContext.getResources().getString(R.string.draft_separator) + '\u202C'); buf.setSpan(new ForegroundColorSpan(mContext.getResources().getColor(R.drawable.text_color_black)), 1, buf.length() - before + 1, Spannable.SPAN_INCLUSIVE_EXCLUSIVE); before = buf.length(); int size; buf.insert(1, mContext.getResources().getString(R.string.has_draft)); size = android.R.style.TextAppearance_Small; buf.setSpan(new TextAppearanceSpan(mContext, size), 1, buf.length() - before + 1, Spannable.SPAN_INCLUSIVE_EXCLUSIVE); buf.setSpan(new ForegroundColorSpan(mContext.getResources().getColor(R.drawable.text_color_red)), 1, buf.length() - before + 1, Spannable.SPAN_INCLUSIVE_EXCLUSIVE); } else { buf.append(mContext.getResources().getString(R.string.draft_separator)); int before = buf.length(); int size; buf.append(mContext.getResources().getString(R.string.has_draft)); size = android.R.style.TextAppearance_Small; buf.setSpan(new TextAppearanceSpan(mContext, size, color), before, buf.length(), Spannable.SPAN_INCLUSIVE_EXCLUSIVE); buf.setSpan(new ForegroundColorSpan(mContext.getResources().getColor(R.drawable.text_color_red)), before, buf.length(), Spannable.SPAN_INCLUSIVE_EXCLUSIVE); } } // Unread messages are shown in bold if (mConversation.hasUnreadMessages()) { buf.setSpan(STYLE_BOLD, 0, buf.length(), Spannable.SPAN_INCLUSIVE_EXCLUSIVE); } return buf; }
From source file:com.orange.ocara.ui.activity.BaseActivityManagingAudit.java
public void showAuditObjectProgress(AuditObject auditObject, final boolean terminateActivityWhenDone) { CharSequence info = getText(com.orange.ocara.R.string.auditing_progress_info); Spannable auditingStatus = new SpannableString(""); int color = getResources().getColor(com.orange.ocara.R.color.black); switch (auditObject.getResponse()) { case OK://from w w w .j a v a 2 s. c om auditingStatus = new SpannableString(getText(com.orange.ocara.R.string.auditing_progress_status_ok)); color = getResources().getColor(com.orange.ocara.R.color.green); break; case NOK: if (auditObject.hasAtLeastOneBlockingRule()) { auditingStatus = new SpannableString( getText(com.orange.ocara.R.string.auditing_progress_status_nok)); color = getResources().getColor(com.orange.ocara.R.color.red); } else { auditingStatus = new SpannableString( getText(com.orange.ocara.R.string.auditing_progress_status_anoying)); color = getResources().getColor(com.orange.ocara.R.color.orange); } break; case DOUBT: auditingStatus = new SpannableString(getText(com.orange.ocara.R.string.auditing_progress_status_doubt)); color = getResources().getColor(com.orange.ocara.R.color.yellow); break; case NoAnswer: auditingStatus = new SpannableString( getText(com.orange.ocara.R.string.auditing_progress_status_no_answer)); color = getResources().getColor(com.orange.ocara.R.color.blue); break; } auditingStatus.setSpan(new ForegroundColorSpan(color), info.length(), auditingStatus.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); StringBuffer stringBuffer = new StringBuffer(info); stringBuffer.append("<br>").append(auditingStatus); // get application preference to know if he wants to audit object now SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this); int displayAuditingProgessDialog = Integer.parseInt(sharedPreferences .getString(getString(com.orange.ocara.R.string.setting_display_auditing_progress_key), "1")); switch (displayAuditingProgessDialog) { case 1: final NotificationDialogBuilder dialogBuilder = new NotificationDialogBuilder(this); final AlertDialog dialog = dialogBuilder.setInfo(auditingStatus) .setOption(getString(com.orange.ocara.R.string.auditing_progress_option)).setCancelable(false) .setTitle(com.orange.ocara.R.string.auditing_progress_title) .setOnDismissListener(new DialogInterface.OnDismissListener() { @Override public void onDismiss(DialogInterface dialog) { auditingProgressDismiss(dialogBuilder.getOptionValue()); if (terminateActivityWhenDone) { BaseActivityManagingAudit.this.finish(); } } }).setPositiveButton(com.orange.ocara.R.string.action_close, null).create(); Handler handler = new Handler(); handler.postDelayed(new Runnable() { @Override public void run() { dialog.dismiss(); } }, 3500); dialog.show(); break; default: if (terminateActivityWhenDone) { BaseActivityManagingAudit.this.finish(); } break; } }
From source file:com.ubergeek42.WeechatAndroid.ChatLinesAdapter.java
@Override public View getView(int position, View convertView, ViewGroup parent) { ViewHolder holder;//from ww w. jav a2 s .c o m // If we don't have the view, or we were using a filteredView, inflate a new one if (convertView == null) { convertView = inflater.inflate(R.layout.chatview_line, null); holder = new ViewHolder(); holder.timestamp = (TextView) convertView.findViewById(R.id.chatline_timestamp); holder.prefix = (TextView) convertView.findViewById(R.id.chatline_prefix); holder.message = (TextView) convertView.findViewById(R.id.chatline_message); convertView.setTag(holder); } else { holder = (ViewHolder) convertView.getTag(); } // Change the font sizes holder.timestamp.setTextSize(textSize); holder.prefix.setTextSize(textSize); holder.message.setTextSize(textSize); BufferLine chatLine = (BufferLine) getItem(position); // Render the timestamp if (enableTimestamp) { holder.timestamp.setText(timestampFormat.format(chatLine.getTimestamp())); holder.timestamp.setPadding(holder.timestamp.getPaddingLeft(), holder.timestamp.getPaddingTop(), 5, holder.timestamp.getPaddingBottom()); } else { holder.timestamp.setText(""); holder.timestamp.setPadding(holder.timestamp.getPaddingLeft(), holder.timestamp.getPaddingTop(), 0, holder.timestamp.getPaddingBottom()); } // Recalculate the prefix width based on the size of one character(fixed width font) if (prefixWidth == 0) { holder.prefix.setMinimumWidth(0); StringBuilder sb = new StringBuilder(); for (int i = 0; i < maxPrefix; i++) { sb.append("m"); } holder.prefix.setText(sb.toString()); holder.prefix.measure(convertView.getWidth(), convertView.getHeight()); prefixWidth = holder.prefix.getMeasuredWidth(); } // Render the prefix if (chatLine.getHighlight()) { String prefixStr = chatLine.getPrefix(); Spannable highlightText = new SpannableString(prefixStr); highlightText.setSpan(new ForegroundColorSpan(Color.YELLOW), 0, prefixStr.length(), Spanned.SPAN_INCLUSIVE_INCLUSIVE); highlightText.setSpan(new BackgroundColorSpan(Color.MAGENTA), 0, prefixStr.length(), Spanned.SPAN_INCLUSIVE_INCLUSIVE); holder.prefix.setText(highlightText); } else { if (enableColor) { holder.prefix.setText(Html.fromHtml(chatLine.getPrefixHTML()), TextView.BufferType.SPANNABLE); } else { holder.prefix.setText(chatLine.getPrefix()); } } if (prefix_align.equals("right")) { holder.prefix.setGravity(Gravity.RIGHT); holder.prefix.setMinimumWidth(prefixWidth); } else if (prefix_align.equals("left")) { holder.prefix.setGravity(Gravity.LEFT); holder.prefix.setMinimumWidth(prefixWidth); } else { holder.prefix.setGravity(Gravity.LEFT); holder.prefix.setMinimumWidth(0); } // Render the message if (enableColor) { holder.message.setText(Html.fromHtml(chatLine.getMessageHTML()), TextView.BufferType.SPANNABLE); } else { holder.message.setText(chatLine.getMessage()); } return convertView; }
From source file:com.github.michalbednarski.intentslab.providerlab.proxy.LogViewerFragment.java
@Override public void onLoadFinished(Loader<Cursor> loader, Cursor data) { setListAdapter(new CursorAdapter(getActivity(), data, false) { @Override/*from w w w . j a va2 s. c o m*/ public View newView(Context context, Cursor cursor, ViewGroup parent) { return ((LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE)) .inflate(android.R.layout.simple_list_item_2, parent, false); } @Override public void bindView(View view, Context context, Cursor cursor) { // First row: method and app name final String appName = getActivity().getPackageManager().getNameForUid(cursor.getInt(3)); final String methodName = methodIdToName(cursor.getInt(1)); ((TextView) view.findViewById(android.R.id.text1)).setText(methodName + "() by " + appName); // Second row: uri and exception final String uri = cursor.getString(2); String exception = cursor.getString(4); SpannableStringBuilder text2 = new SpannableStringBuilder(uri); if (exception != null) { text2.append("\n"); final int start = text2.length(); text2.append(exception); final int end = text2.length(); text2.setSpan(new ForegroundColorSpan(Color.RED), start, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); } else { // TODO: result / empty result warning } ((TextView) view.findViewById(android.R.id.text2)).setText(text2); } }); }
From source file:com.duy.pascal.ui.editor.highlight.CodeHighlighter.java
private void highlightOther(@NonNull Editable allText, @NonNull CharSequence textToHighlight, int start) { //high light number for (Matcher m = NUMBERS.matcher(textToHighlight); m.find();) { allText.setSpan(new ForegroundColorSpan(codeTheme.getNumberColor()), start + m.start(), start + m.end(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); }// w ww. ja v a 2 s .co m for (Matcher m = KEYWORDS.matcher(textToHighlight); m.find();) { allText.setSpan(new ForegroundColorSpan(codeTheme.getKeywordColor()), start + m.start(), start + m.end(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); } for (Matcher m = BUILTIN_FUNCTIONS.matcher(textToHighlight); m.find();) { allText.setSpan(new ForegroundColorSpan(codeTheme.getKeywordColor()), start + m.start(), start + m.end(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); } for (Matcher m = SYMBOLS.matcher(textToHighlight); m.find();) { allText.setSpan(new ForegroundColorSpan(codeTheme.getOptColor()), start + m.start(), start + m.end(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); } for (Matcher m = RGB_FUNCTION.matcher(textToHighlight); m.find();) { try { int r = Integer.parseInt(m.group(3).trim()); int g = Integer.parseInt(m.group(5).trim()); int b = Integer.parseInt(m.group(7).trim()); int back = Color.rgb(r, g, b); int fore = Color.rgb(255 - r, 255 - g, 255 - b); allText.setSpan(new BackgroundColorSpan(back), start + m.start(1), start + m.end(1), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); allText.setSpan(new ForegroundColorSpan(fore), start + m.start(1), start + m.end(1), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); } catch (Exception e) { } } for (Matcher m = ARGB_FUNCTION.matcher(textToHighlight); m.find();) { try { int r = Integer.parseInt(m.group(3).trim()); int g = Integer.parseInt(m.group(5).trim()); int b = Integer.parseInt(m.group(7).trim()); int back = Color.rgb(r, g, b); int fore = Color.rgb(255 - r, 255 - g, 255 - b); allText.setSpan(new BackgroundColorSpan(back), start + m.start(1), start + m.end(1), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); allText.setSpan(new ForegroundColorSpan(fore), start + m.start(1), start + m.end(1), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); } catch (Exception e) { } } }
From source file:com.tasomaniac.android.widget.IntegrationPreference.java
private SpannableString getErrorString(CharSequence originalString) { SpannableString errorSpan = new SpannableString(originalString); ForegroundColorSpan colorSpan = new ForegroundColorSpan( ContextCompat.getColor(getContext(), R.color.error_color)); errorSpan.setSpan(colorSpan, 0, originalString.length(), 0); return errorSpan; }
From source file:net.kourlas.voipms_sms.adapters.ConversationRecyclerViewAdapter.java
@Override public void onBindViewHolder(MessageViewHolder messageViewHolder, int i) { Message message = messages.get(i);// ww w . j av a2s . com int viewType = getItemViewType(i); if (viewType == ITEM_LEFT_PRIMARY || viewType == ITEM_RIGHT_PRIMARY) { QuickContactBadge contactBadge = messageViewHolder.getContactBadge(); if (viewType == ITEM_LEFT_PRIMARY) { contactBadge.assignContactFromPhone(message.getContact(), true); } else { contactBadge.assignContactFromPhone(message.getDid(), true); } String photoUri; if (viewType == ITEM_LEFT_PRIMARY) { photoUri = Utils.getContactPhotoUri(applicationContext, message.getContact()); } else { photoUri = Utils.getContactPhotoUri(applicationContext, ContactsContract.Profile.CONTENT_URI); if (photoUri == null) { photoUri = Utils.getContactPhotoUri(applicationContext, message.getDid()); } } if (photoUri != null) { contactBadge.setImageURI(Uri.parse(photoUri)); } else { contactBadge.setImageToDefault(); } } View smsContainer = messageViewHolder.getSmsContainer(); TextView messageText = messageViewHolder.getMessageText(); SpannableStringBuilder messageTextBuilder = new SpannableStringBuilder(); messageTextBuilder.append(message.getText()); if (!filterConstraint.equals("")) { int index = message.getText().toLowerCase().indexOf(filterConstraint.toLowerCase()); if (index != -1) { messageTextBuilder.setSpan( new BackgroundColorSpan(ContextCompat.getColor(applicationContext, R.color.highlight)), index, index + filterConstraint.length(), SpannableString.SPAN_INCLUSIVE_EXCLUSIVE); messageTextBuilder.setSpan( new ForegroundColorSpan(ContextCompat.getColor(applicationContext, R.color.dark_gray)), index, index + filterConstraint.length(), SpannableString.SPAN_INCLUSIVE_EXCLUSIVE); } } messageText.setText(messageTextBuilder); TextView dateText = messageViewHolder.getDateText(); if (!message.isDelivered()) { if (!message.isDeliveryInProgress()) { SpannableStringBuilder dateTextBuilder = new SpannableStringBuilder(); if (isItemChecked(i)) { dateTextBuilder .append(applicationContext.getString(R.string.conversation_message_not_sent_selected)); } else { dateTextBuilder.append(applicationContext.getString(R.string.conversation_message_not_sent)); } dateTextBuilder.setSpan( new ForegroundColorSpan( isItemChecked(i) ? ContextCompat.getColor(applicationContext, android.R.color.white) : ContextCompat.getColor(applicationContext, android.R.color.holo_red_dark)), 0, dateTextBuilder.length(), Spanned.SPAN_INCLUSIVE_EXCLUSIVE); dateText.setText(dateTextBuilder); dateText.setVisibility(View.VISIBLE); } else { dateText.setText(applicationContext.getString(R.string.conversation_message_sending)); dateText.setVisibility(View.VISIBLE); } } else if (i == messages.size() - 1 || ((viewType == ITEM_LEFT_PRIMARY || viewType == ITEM_LEFT_SECONDARY) && getItemViewType(i + 1) != ITEM_LEFT_SECONDARY) || ((viewType == ITEM_RIGHT_PRIMARY || viewType == ITEM_RIGHT_SECONDARY) && getItemViewType(i + 1) != ITEM_RIGHT_SECONDARY)) { dateText.setText(Utils.getFormattedDate(applicationContext, message.getDate(), false)); dateText.setVisibility(View.VISIBLE); } else { dateText.setVisibility(View.GONE); } if (viewType == ITEM_LEFT_PRIMARY || viewType == ITEM_LEFT_SECONDARY) { smsContainer.setBackgroundResource(isItemChecked(i) ? android.R.color.holo_blue_dark : R.color.primary); } else { smsContainer.setBackgroundResource( isItemChecked(i) ? android.R.color.holo_blue_dark : android.R.color.white); messageText.setTextColor( isItemChecked(i) ? ContextCompat.getColor(applicationContext, android.R.color.white) : ContextCompat.getColor(applicationContext, R.color.dark_gray)); messageText.setLinkTextColor( isItemChecked(i) ? ContextCompat.getColor(applicationContext, android.R.color.white) : ContextCompat.getColor(applicationContext, R.color.dark_gray)); dateText.setTextColor( isItemChecked(i) ? ContextCompat.getColor(applicationContext, R.color.message_translucent_white) : ContextCompat.getColor(applicationContext, R.color.message_translucent_dark_grey)); } }
From source file:eu.veldsoft.adsbobball.ActivityStateEnum.java
public SpannableStringBuilder formatPerPlayer(String fixed, playstat query) { SpannableStringBuilder sps = SpannableStringBuilder.valueOf(fixed); for (Player p : gameManager.getCurrGameState().getPlayers()) { if (p.getPlayerId() == 0) continue; SpannableString s = new SpannableString(String.valueOf(query.call(p)) + " "); s.setSpan(new ForegroundColorSpan(p.getColor()), 0, s.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); sps.append(s);//from ww w . j av a2 s . c o m } return sps; }