List of usage examples for android.text.style TextAppearanceSpan TextAppearanceSpan
public TextAppearanceSpan(Context context, int appearance)
From source file:com.tct.mail.utils.NotificationUtils.java
private static CharSequence getSingleMessageBigText(Context context, final Message message, String from) { final TextAppearanceSpan notificationSubjectSpan = new TextAppearanceSpan(context, R.style.NotificationPrimaryText); final String snippet = getMessageBodyWithoutElidedText(message); // Change multiple newlines (with potential white space between), into a single new line final String collapsedSnippet = !TextUtils.isEmpty(snippet) ? snippet.replaceAll("\\n\\s+", "\n") : ""; if (TextUtils.isEmpty(from)) { // If the subject is empty, just use the snippet. return snippet; } else if (TextUtils.isEmpty(collapsedSnippet)) { // If the snippet is empty, just use the subject. final SpannableString spannableString = new SpannableString(from); spannableString.setSpan(notificationSubjectSpan, 0, from.length(), 0); return spannableString; } else {//from w ww . j a v a 2s . com final String notificationBigTextFormat = context.getResources() .getString(R.string.single_new_message_notification_big_text); // Localizers may change the order of the parameters, look at how the format // string is structured. final boolean isSubjectFirst = notificationBigTextFormat.indexOf("%2$s") > notificationBigTextFormat .indexOf("%1$s"); final String bigText = String.format(notificationBigTextFormat, from, collapsedSnippet); final SpannableString spannableString = new SpannableString(bigText); final int subjectOffset = (isSubjectFirst ? bigText.indexOf(from) : bigText.lastIndexOf(from)); spannableString.setSpan(new ForegroundColorSpan(Color.BLACK), subjectOffset, subjectOffset + from.length(), Spanned.SPAN_EXCLUSIVE_INCLUSIVE); return spannableString; } }