List of usage examples for android.text.style ForegroundColorSpan ForegroundColorSpan
public ForegroundColorSpan(@NonNull Parcel src)
From source file:com.just.agentweb.AgentWebUtils.java
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);/* ww w . j ava 2 s .co m*/ if (actionText != null && actionText.length() > 0 && listener != null) { snackbar.setActionTextColor(actionTextColor); snackbar.setAction(actionText, listener); } snackbar.show(); }
From source file:org.bobstuff.bobball.ActivityStateEnum.java
private void updateStatus(final GameState currGameState) { SpannableStringBuilder timeLeftStr = SpannableStringBuilder .valueOf(getString(R.string.timeLeftLabel, gameManager.timeLeft() / 10)); SpannableStringBuilder livesStr = formatPerPlayer(getString(R.string.livesLabel), new playstat() { @Override//from w w w. java 2 s . c o m public int call(Player p) { return p.getLives(); } }); SpannableStringBuilder scoreStr = formatPerPlayer(getString(R.string.scoreLabel), new playstat() { @Override public int call(Player p) { return p.getScore(); } }); SpannableStringBuilder clearedStr = formatPerPlayer(getString(R.string.areaClearedLabel), new playstat() { @Override public int call(Player p) { Grid grid = currGameState.getGrid(); if (grid != null) return currGameState.getGrid().getPercentComplete(p.getPlayerId()); else return 0; } }); //display fps if (secretHandshake >= 3) { float fps = displayLoop.getFPS(); int color = (fps < NUMBER_OF_FRAMES_PER_SECOND * 0.98f ? Color.RED : Color.GREEN); SpannableString s = new SpannableString(String.format(" FPS: %2.1f", fps)); s.setSpan(new ForegroundColorSpan(color), 0, s.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); timeLeftStr.append(s); color = (gameManager.getUPS() < gameManager.NUMBER_OF_UPDATES_PER_SECOND * 0.98f ? Color.RED : Color.GREEN); s = new SpannableString(String.format(" UPS: %3.1f", gameManager.getUPS())); s.setSpan(new ForegroundColorSpan(color), 0, s.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); timeLeftStr.append(s); } statusTopleft.setText(timeLeftStr); statusTopright.setText(livesStr); statusBotleft.setText(scoreStr); statusBotright.setText(clearedStr); }
From source file:com.viewpagerindicator.TabTextPageIndicator.java
/** * textview/* www .j a va 2 s .c o m*/ * * @param textView */ private void setTextColor(TextView textView) { if (textView == null) { return; } String textString = textView.getText().toString(); if (textString.isEmpty()) { return; } int start = textString.indexOf("("); int end = textString.indexOf(")"); if (start < 0 || end < 0 || end < start) { return; } SpannableStringBuilder builder = new SpannableStringBuilder(textString); // ForegroundColorSpan ?BackgroundColorSpan ForegroundColorSpan redSpan = new ForegroundColorSpan(Color.parseColor("#39a5ec")); builder.setSpan(redSpan, start, end + 1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); // ? builder.setSpan(new MyStyleSpan(Typeface.NORMAL), start, end + 1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); textView.setText(builder); }
From source file:nl.mpcjanssen.simpletask.util.Util.java
public static void setColor(SpannableString ss, int color) { ss.setSpan(new ForegroundColorSpan(color), 0, ss.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); }
From source file:io.realm.realmtasks.list.ItemViewHolder.java
public void setStrikeThroughRatio(float strikeThroughRatio) { final CharSequence text = this.text.getText(); final int textLength = text.length(); int firstLength = (int) (textLength * strikeThroughRatio); if (firstLength > textLength) { firstLength = textLength;//from www. j av a2s. co m } else if (firstLength == textLength - 1) { firstLength = textLength; } if (firstLength == previousFirstLength) { return; } previousFirstLength = firstLength; final int appendedLength = textLength - firstLength; final SpannableStringBuilder stringBuilder = new SpannableStringBuilder(text, 0, textLength); stringBuilder.clearSpans(); this.text.setPaintFlags(this.text.getPaintFlags() & ~Paint.STRIKE_THRU_TEXT_FLAG); final CharacterStyle firstCharStyle, secondCharStyle; if (completed) { firstCharStyle = new ForegroundColorSpan(cellCompletedColor); secondCharStyle = new StrikethroughSpan(); } else { firstCharStyle = new StrikethroughSpan(); secondCharStyle = new ForegroundColorSpan(cellDefaultColor); } stringBuilder.setSpan(firstCharStyle, 0, firstLength, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); stringBuilder.setSpan(secondCharStyle, textLength - appendedLength, textLength, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); this.text.setText(stringBuilder); }
From source file:com.keylesspalace.tusky.activity.ComposeActivity.java
private static void highlightSpans(Spannable text, int colour) { // Strip all existing colour spans. int n = text.length(); ForegroundColorSpan[] oldSpans = text.getSpans(0, n, ForegroundColorSpan.class); for (int i = oldSpans.length - 1; i >= 0; i--) { text.removeSpan(oldSpans[i]);/*from ww w . j a va 2s. c o m*/ } // Colour the mentions and hashtags. String string = text.toString(); int start; int end = 0; while (end < n) { char[] chars = { '#', '@' }; FindCharsResult found = findStart(string, end, chars); start = found.stringIndex; if (start < 0) { break; } if (found.charIndex == 0) { end = findEndOfHashtag(string, start); } else if (found.charIndex == 1) { end = findEndOfMention(string, start); } else { break; } if (end < 0) { break; } text.setSpan(new ForegroundColorSpan(colour), start, end, Spanned.SPAN_INCLUSIVE_EXCLUSIVE); } }
From source file:com.coinblesk.client.utils.UIUtils.java
public static SpannableString toLargeSpannable(Context context, String amount, String currency, float sizeSpan) { final int amountLength = amount.length(); SpannableString result = new SpannableString(new StringBuffer(amount + " " + currency)); result.setSpan(new RelativeSizeSpan(sizeSpan), 0, amountLength, 0); result.setSpan(new ForegroundColorSpan(Color.WHITE), 0, amountLength, 0); result.setSpan(new ForegroundColorSpan(ContextCompat.getColor(context, R.color.colorAccent)), amountLength, result.length(), 0);/*from www . ja v a2s. co m*/ return result; }
From source file:com.fowlcorp.homebank4android.gui.AccountRecyclerAdapter.java
private Spannable colorText(String fieldName, String value) { Spannable span = new SpannableString(fieldName + value + getCurrency()); span.setSpan(/* w w w .j a va2 s .c o m*/ new ForegroundColorSpan((value.charAt(0) == '-' ? Color.rgb(206, 92, 0) : Color.rgb(78, 154, 54))), fieldName.length(), fieldName.length() + value.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); return span; }
From source file:uk.org.ngo.squeezer.itemlist.AlarmView.java
private void setDowText(AlarmViewHolder viewHolder, int day) { SpannableString text = new SpannableString(ServerString.getAlarmShortDayText(day)); if (viewHolder.alarm.isDayActive(day)) { text.setSpan(new StyleSpan(Typeface.BOLD), 0, text.length(), 0); text.setSpan(new ForegroundColorSpan(mColorSelected), 0, text.length(), 0); Drawable underline = mResources.getDrawable(R.drawable.underline); float textSize = (new Paint()).measureText(text.toString()); underline.setBounds(0, 0, (int) (textSize * mDensity), (int) (1 * mDensity)); viewHolder.dowTexts[day].setCompoundDrawables(null, null, null, underline); } else//from w ww .j a v a 2s. c om viewHolder.dowTexts[day].setCompoundDrawables(null, null, null, null); viewHolder.dowTexts[day].setText(text); }
From source file:se.tmeit.app.ui.members.MemberInfoFragment.java
private void setTextWithPrefix(TextView textView, int prefixResId, String str) { String prefixStr = getString(prefixResId); SpannableString teamStr = new SpannableString(prefixStr + " " + str); teamStr.setSpan(new RelativeSizeSpan(0.8f), 0, prefixStr.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); int foregroundColor = ContextCompat.getColor(getContext(), R.color.insektionen); teamStr.setSpan(new ForegroundColorSpan(foregroundColor), 0, prefixStr.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); textView.setText(teamStr);/* w w w .j ava 2 s . c om*/ }