List of usage examples for android.text.style TextAppearanceSpan TextAppearanceSpan
public TextAppearanceSpan(Context context, int appearance)
From source file:com.android.messaging.datamodel.BugleNotifications.java
static CharSequence formatInboxMessage(final String sender, final CharSequence message, final Uri attachmentUri, final String attachmentType) { final Context context = Factory.get().getApplicationContext(); final TextAppearanceSpan notificationSenderSpan = new TextAppearanceSpan(context, R.style.NotificationSenderText); final TextAppearanceSpan notificationTertiaryText = new TextAppearanceSpan(context, R.style.NotificationTertiaryText); final SpannableStringBuilder spannableStringBuilder = new SpannableStringBuilder(); if (!TextUtils.isEmpty(sender)) { spannableStringBuilder.append(sender); spannableStringBuilder.setSpan(notificationSenderSpan, 0, sender.length(), 0); }/*from w ww . j a v a 2 s . c o m*/ final String separator = context.getString(R.string.notification_separator); if (!TextUtils.isEmpty(message)) { if (spannableStringBuilder.length() > 0) { spannableStringBuilder.append(separator); } final int start = spannableStringBuilder.length(); spannableStringBuilder.append(message); spannableStringBuilder.setSpan(notificationTertiaryText, start, start + message.length(), 0); } if (attachmentUri != null) { if (spannableStringBuilder.length() > 0) { spannableStringBuilder.append(separator); } spannableStringBuilder.append(formatAttachmentTag(null, attachmentType)); } return spannableStringBuilder; }
From source file:com.chen.mail.utils.NotificationUtils.java
private static SpannableStringBuilder getStyledSenders(final Context context, final Cursor conversationCursor, final int maxLength, final String account) { final Conversation conversation = new Conversation(conversationCursor); final ConversationInfo conversationInfo = conversation.conversationInfo; final ArrayList<SpannableString> senders = new ArrayList<SpannableString>(); if (sNotificationUnreadStyleSpan == null) { sNotificationUnreadStyleSpan = new TextAppearanceSpan(context, R.style.NotificationSendersUnreadTextAppearance); sNotificationReadStyleSpan = new TextAppearanceSpan(context, R.style.NotificationSendersReadTextAppearance); }// w w w . j av a 2s . c o m SendersView.format(context, conversationInfo, "", maxLength, senders, null, null, account, sNotificationUnreadStyleSpan, sNotificationReadStyleSpan, false); return ellipsizeStyledSenders(context, senders); }
From source file:com.android.messaging.datamodel.BugleNotifications.java
static CharSequence formatAttachmentTag(final String author, final String attachmentType) { final Context context = Factory.get().getApplicationContext(); final TextAppearanceSpan notificationSecondaryText = new TextAppearanceSpan(context, R.style.NotificationSecondaryText); final SpannableStringBuilder spannableStringBuilder = new SpannableStringBuilder(); if (!TextUtils.isEmpty(author)) { final TextAppearanceSpan notificationSenderSpan = new TextAppearanceSpan(context, R.style.NotificationSenderText); spannableStringBuilder.append(author); spannableStringBuilder.setSpan(notificationSenderSpan, 0, author.length(), 0); final String separator = context.getString(R.string.notification_separator); spannableStringBuilder.append(separator); }//w ww. j a v a 2 s . c o m final int start = spannableStringBuilder.length(); // The default attachment type is an image, since that's what was originally // supported. When there's no content type, assume it's an image. int message = R.string.notification_picture; if (ContentType.isAudioType(attachmentType)) { message = R.string.notification_audio; } else if (ContentType.isVideoType(attachmentType)) { message = R.string.notification_video; } else if (ContentType.isVCardType(attachmentType)) { message = R.string.notification_vcard; } spannableStringBuilder.append(context.getText(message)); spannableStringBuilder.setSpan(notificationSecondaryText, start, spannableStringBuilder.length(), 0); return spannableStringBuilder; }
From source file:com.chen.mail.utils.NotificationUtils.java
/** * Sets the bigtext for a notification for a single new conversation * * @param context/*from w w w.ja va2s . com*/ * @param senders Sender of the new message that triggered the notification. * @param subject Subject of the new message that triggered the notification * @param snippet Snippet of the new message that triggered the notification * @return a {@link CharSequence} suitable for use in * {@link android.support.v4.app.NotificationCompat.BigTextStyle} */ private static CharSequence getSingleMessageInboxLine(Context context, String senders, String subject, String snippet) { // TODO(cwren) finish this step toward commmon code with getSingleMessageBigText final String subjectSnippet = !TextUtils.isEmpty(subject) ? subject : snippet; final TextAppearanceSpan notificationPrimarySpan = new TextAppearanceSpan(context, R.style.NotificationPrimaryText); if (TextUtils.isEmpty(senders)) { // If the senders are empty, just use the subject/snippet. return subjectSnippet; } else if (TextUtils.isEmpty(subjectSnippet)) { // If the subject/snippet is empty, just use the senders. final SpannableString spannableString = new SpannableString(senders); spannableString.setSpan(notificationPrimarySpan, 0, senders.length(), 0); return spannableString; } else { final String formatString = context.getResources() .getString(R.string.multiple_new_message_notification_item); final TextAppearanceSpan notificationSecondarySpan = new TextAppearanceSpan(context, R.style.NotificationSecondaryText); // senders is already individually unicode wrapped so it does not need to be done here final String instantiatedString = String.format(formatString, senders, BIDI_FORMATTER.unicodeWrap(subjectSnippet)); final SpannableString spannableString = new SpannableString(instantiatedString); final boolean isOrderReversed = formatString.indexOf("%2$s") < formatString.indexOf("%1$s"); final int primaryOffset = (isOrderReversed ? instantiatedString.lastIndexOf(senders) : instantiatedString.indexOf(senders)); final int secondaryOffset = (isOrderReversed ? instantiatedString.lastIndexOf(subjectSnippet) : instantiatedString.indexOf(subjectSnippet)); spannableString.setSpan(notificationPrimarySpan, primaryOffset, primaryOffset + senders.length(), 0); spannableString.setSpan(notificationSecondarySpan, secondaryOffset, secondaryOffset + subjectSnippet.length(), 0); return spannableString; } }
From source file:com.android.mail.utils.NotificationUtils.java
private static SpannableStringBuilder getStyledSenders(final Context context, final Cursor conversationCursor, final int maxLength, final Account account) { final Conversation conversation = new Conversation(conversationCursor); final com.android.mail.providers.ConversationInfo conversationInfo = conversation.conversationInfo; final ArrayList<SpannableString> senders = new ArrayList<>(); if (sNotificationUnreadStyleSpan == null) { sNotificationUnreadStyleSpan = new TextAppearanceSpan(context, R.style.NotificationSendersUnreadTextAppearance); sNotificationReadStyleSpan = new TextAppearanceSpan(context, R.style.NotificationSendersReadTextAppearance); }// w w w .ja v a 2 s.com SendersView.format(context, conversationInfo, "", maxLength, senders, null, null, account, sNotificationUnreadStyleSpan, sNotificationReadStyleSpan, false /* showToHeader */, false /* resourceCachingRequired */); return ellipsizeStyledSenders(context, senders); }
From source file:com.android.mail.utils.NotificationUtils.java
/** * Sets the bigtext for a notification for a single new conversation * * @param context/* w ww.j av a 2 s . c o m*/ * @param senders Sender of the new message that triggered the notification. * @param subject Subject of the new message that triggered the notification * @param snippet Snippet of the new message that triggered the notification * @return a {@link CharSequence} suitable for use in * {@link android.support.v4.app.NotificationCompat.BigTextStyle} */ private static CharSequence getSingleMessageInboxLine(Context context, String senders, String subject, String snippet) { // TODO(cwren) finish this step toward commmon code with getSingleMessageBigText final String subjectSnippet = !TextUtils.isEmpty(subject) ? subject : snippet; final TextAppearanceSpan notificationPrimarySpan = new TextAppearanceSpan(context, R.style.NotificationPrimaryText); if (TextUtils.isEmpty(senders)) { // If the senders are empty, just use the subject/snippet. return subjectSnippet; } else if (TextUtils.isEmpty(subjectSnippet)) { // If the subject/snippet is empty, just use the senders. final SpannableString spannableString = new SpannableString(senders); spannableString.setSpan(notificationPrimarySpan, 0, senders.length(), 0); return spannableString; } else { final String formatString = context.getResources() .getString(R.string.multiple_new_message_notification_item); final TextAppearanceSpan notificationSecondarySpan = new TextAppearanceSpan(context, R.style.NotificationSecondaryText); // senders is already individually unicode wrapped so it does not need to be done here final String instantiatedString = String.format(formatString, senders, sBidiFormatter.unicodeWrap(subjectSnippet)); final SpannableString spannableString = new SpannableString(instantiatedString); final boolean isOrderReversed = formatString.indexOf("%2$s") < formatString.indexOf("%1$s"); final int primaryOffset = (isOrderReversed ? instantiatedString.lastIndexOf(senders) : instantiatedString.indexOf(senders)); final int secondaryOffset = (isOrderReversed ? instantiatedString.lastIndexOf(subjectSnippet) : instantiatedString.indexOf(subjectSnippet)); spannableString.setSpan(notificationPrimarySpan, primaryOffset, primaryOffset + senders.length(), 0); spannableString.setSpan(notificationSecondarySpan, secondaryOffset, secondaryOffset + subjectSnippet.length(), 0); return spannableString; } }
From source file:com.android.mail.utils.NotificationUtils.java
/** * Sets the bigtext for a notification for a single new conversation * @param context/*w w w . jav a 2 s . c om*/ * @param subject Subject of the new message that triggered the notification * @return a {@link CharSequence} suitable for use in * {@link NotificationCompat.Builder#setContentText} */ private static CharSequence getSingleMessageLittleText(Context context, String subject) { final TextAppearanceSpan notificationSubjectSpan = new TextAppearanceSpan(context, R.style.NotificationPrimaryText); final SpannableString spannableString = new SpannableString(subject); spannableString.setSpan(notificationSubjectSpan, 0, subject.length(), 0); return spannableString; }
From source file:com.android.mail.utils.NotificationUtils.java
/** * Sets the bigtext for a notification for a single new conversation * * @param context// w w w. j av a 2s . co m * @param subject Subject of the new message that triggered the notification * @param message the {@link Message} to be displayed. * @return a {@link CharSequence} suitable for use in * {@link android.support.v4.app.NotificationCompat.BigTextStyle} */ private static CharSequence getSingleMessageBigText(Context context, String subject, final Message message) { 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(subject)) { // 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(subject); spannableString.setSpan(notificationSubjectSpan, 0, subject.length(), 0); return spannableString; } else { 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, subject, collapsedSnippet); final SpannableString spannableString = new SpannableString(bigText); final int subjectOffset = (isSubjectFirst ? bigText.indexOf(subject) : bigText.lastIndexOf(subject)); spannableString.setSpan(notificationSubjectSpan, subjectOffset, subjectOffset + subject.length(), 0); return spannableString; } }
From source file:com.tct.mail.utils.NotificationUtils.java
private static SpannableStringBuilder getStyledSenders(final Context context, final Cursor conversationCursor, final int maxLength, final String account) { final Conversation conversation = new Conversation(conversationCursor); final com.tct.mail.providers.ConversationInfo conversationInfo = conversation.conversationInfo; final ArrayList<SpannableString> senders = new ArrayList<SpannableString>(); if (sNotificationUnreadStyleSpan == null) { sNotificationUnreadStyleSpan = new TextAppearanceSpan(context, R.style.NotificationSendersUnreadTextAppearance); sNotificationReadStyleSpan = new TextAppearanceSpan(context, R.style.NotificationSendersReadTextAppearance); }/* www . ja va 2 s .com*/ SendersView.format(context, conversationInfo, "", maxLength, senders, null, null, account, sNotificationUnreadStyleSpan, sNotificationReadStyleSpan, false /* showToHeader */, false /* resourceCachingRequired */); return ellipsizeStyledSenders(context, senders); }
From source file:com.android.mail.utils.NotificationUtils.java
/** * Gets the title for a notification for a single new conversation * @param context//from www.j a va 2 s . c o m * @param sender Sender of the new message that triggered the notification. * @param subject Subject of the new message that triggered the notification * @return a {@link CharSequence} suitable for use as a {@link Notification} title. */ private static CharSequence getSingleMessageNotificationTitle(Context context, String sender, String subject) { if (TextUtils.isEmpty(subject)) { // If the subject is empty, just set the title to the sender's information. return sender; } else { final String notificationTitleFormat = context.getResources() .getString(R.string.single_new_message_notification_title); // Localizers may change the order of the parameters, look at how the format // string is structured. final boolean isSubjectLast = notificationTitleFormat.indexOf("%2$s") > notificationTitleFormat .indexOf("%1$s"); final String titleString = String.format(notificationTitleFormat, sender, subject); // Format the string so the subject is using the secondaryText style final SpannableString titleSpannable = new SpannableString(titleString); // Find the offset of the subject. final int subjectOffset = isSubjectLast ? titleString.lastIndexOf(subject) : titleString.indexOf(subject); final TextAppearanceSpan notificationSubjectSpan = new TextAppearanceSpan(context, R.style.NotificationSecondaryText); titleSpannable.setSpan(notificationSubjectSpan, subjectOffset, subjectOffset + subject.length(), 0); return titleSpannable; } }