Example usage for android.text.style CharacterStyle wrap

List of usage examples for android.text.style CharacterStyle wrap

Introduction

In this page you can find the example usage for android.text.style CharacterStyle wrap.

Prototype

public static CharacterStyle wrap(CharacterStyle cs) 

Source Link

Document

A given CharacterStyle can only applied to a single region of a given Spanned.

Usage

From source file:Main.java

public static void setSpanBetweenTokens(SpannableString ss, String text, String token, CharacterStyle... cs) {
    // Start and end refer to the points where the span will apply
    int tokenLen = token.length();
    int base = 0;

    while (true) {
        int start = text.indexOf(token, base);
        int end = text.indexOf(token, start + tokenLen);

        if (start < 0 || end < 0) {
            break;
        }//from   w  w  w. j  a va2  s. c  o  m

        base = end + tokenLen;

        for (CharacterStyle c : cs) {
            ss.setSpan(CharacterStyle.wrap(c), start + tokenLen, end, 0);
        }

        Drawable blankDrawable = new Drawable() {

            @Override
            public void setColorFilter(ColorFilter cf) {
            }

            @Override
            public void setAlpha(int alpha) {
            }

            @Override
            public int getOpacity() {
                return 0;
            }

            @Override
            public void draw(Canvas canvas) {
            }
        };

        // because AbsoluteSizeSpan(0) doesn't work on older versions
        ss.setSpan(new ImageSpan(blankDrawable), start, start + tokenLen, 0);
        ss.setSpan(new ImageSpan(blankDrawable), end, end + tokenLen, 0);
    }
}

From source file:com.chen.mail.browse.SendersView.java

public static SpannableStringBuilder createMessageInfo(Context context, Conversation conv,
        final boolean resourceCachingRequired) {
    SpannableStringBuilder messageInfo = new SpannableStringBuilder();

    try {//from w w w  . j  a va  2s.co  m
        ConversationInfo conversationInfo = conv.conversationInfo;
        int sendingStatus = conv.sendingState;
        boolean hasSenders = false;
        // This covers the case where the sender is "me" and this is a draft
        // message, which means this will only run once most of the time.
        for (MessageInfo m : conversationInfo.messageInfos) {
            if (!TextUtils.isEmpty(m.sender)) {
                hasSenders = true;
                break;
            }
        }
        getSenderResources(context, resourceCachingRequired);
        if (conversationInfo != null) {
            int count = conversationInfo.messageCount;
            int draftCount = conversationInfo.draftCount;
            boolean showSending = sendingStatus == UIProvider.ConversationSendingState.SENDING;
            if (count > 1) {
                messageInfo.append(count + "");
            }
            messageInfo.setSpan(
                    CharacterStyle.wrap(conv.read ? sMessageInfoReadStyleSpan : sMessageInfoUnreadStyleSpan), 0,
                    messageInfo.length(), 0);
            if (draftCount > 0) {
                // If we are showing a message count or any draft text and there
                // is at least 1 sender, prepend the sending state text with a
                // comma.
                if (hasSenders || count > 1) {
                    messageInfo.append(sSendersSplitToken);
                }
                SpannableStringBuilder draftString = new SpannableStringBuilder();
                if (draftCount == 1) {
                    draftString.append(sDraftSingularString);
                } else {
                    draftString.append(sDraftPluralString + String.format(sDraftCountFormatString, draftCount));
                }
                draftString.setSpan(CharacterStyle.wrap(sDraftsStyleSpan), 0, draftString.length(),
                        Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
                messageInfo.append(draftString);
            }
            if (showSending) {
                // If we are showing a message count or any draft text, prepend
                // the sending state text with a comma.
                if (count > 1 || draftCount > 0) {
                    messageInfo.append(sSendersSplitToken);
                }
                SpannableStringBuilder sending = new SpannableStringBuilder();
                sending.append(sSendingString);
                sending.setSpan(sSendingStyleSpan, 0, sending.length(), 0);
                messageInfo.append(sending);
            }
            // Prepend a space if we are showing other message info text.
            if (count > 1 || (draftCount > 0 && hasSenders) || showSending) {
                messageInfo.insert(0, sMessageCountSpacerString);
            }
        }
    } finally {
        if (!resourceCachingRequired) {
            clearResourceCache();
        }
    }

    return messageInfo;
}

From source file:com.android.mail.browse.SendersView.java

public static SpannableStringBuilder createMessageInfo(Context context, Conversation conv,
        final boolean resourceCachingRequired) {
    SpannableStringBuilder messageInfo = new SpannableStringBuilder();

    try {//  w  w w  . jav  a  2  s . co  m
        final ConversationInfo conversationInfo = conv.conversationInfo;
        final int sendingStatus = conv.sendingState;
        boolean hasSenders = false;
        // This covers the case where the sender is "me" and this is a draft
        // message, which means this will only run once most of the time.
        for (ParticipantInfo p : conversationInfo.participantInfos) {
            if (!TextUtils.isEmpty(p.name)) {
                hasSenders = true;
                break;
            }
        }
        getSenderResources(context, resourceCachingRequired);
        final int count = conversationInfo.messageCount;
        final int draftCount = conversationInfo.draftCount;
        if (count > 1) {
            appendMessageInfo(messageInfo, Integer.toString(count),
                    CharacterStyle.wrap(conv.read ? sMessageInfoReadStyleSpan : sMessageInfoUnreadStyleSpan),
                    false, conv.read);
        }

        boolean appendSplitToken = hasSenders || count > 1;
        if (draftCount > 0) {
            final CharSequence draftText;
            if (draftCount == 1) {
                draftText = sDraftSingularString;
            } else {
                draftText = sDraftPluralString + String.format(sDraftCountFormatString, draftCount);
            }

            appendMessageInfo(messageInfo, draftText, sDraftsStyleSpan, appendSplitToken, conv.read);
        }

        final boolean showState = sendingStatus == UIProvider.ConversationSendingState.SENDING
                || sendingStatus == UIProvider.ConversationSendingState.RETRYING
                || sendingStatus == UIProvider.ConversationSendingState.SEND_ERROR;
        if (showState) {
            appendSplitToken |= draftCount > 0;

            final CharSequence statusText;
            final Object span;
            if (sendingStatus == UIProvider.ConversationSendingState.SENDING) {
                statusText = sSendingString;
                span = sSendingStyleSpan;
            } else if (sendingStatus == UIProvider.ConversationSendingState.RETRYING) {
                statusText = sSendingString;
                span = sSendingStyleSpan;
            } else {
                statusText = sFailedString;
                span = sFailedStyleSpan;
            }

            appendMessageInfo(messageInfo, statusText, span, appendSplitToken, conv.read);
        }

        // Prepend a space if we are showing other message info text.
        if (count > 1 || (draftCount > 0 && hasSenders) || showState) {
            messageInfo.insert(0, sMessageCountSpacerString);
        }
    } finally {
        if (!resourceCachingRequired) {
            clearResourceCache();
        }
    }

    return messageInfo;
}

From source file:com.tct.mail.browse.SendersView.java

public static SpannableStringBuilder createMessageInfo(Context context, Conversation conv,
        final boolean resourceCachingRequired) {
    SpannableStringBuilder messageInfo = new SpannableStringBuilder();

    try {/*  w  ww. j  a  v a 2  s  . c om*/
        ConversationInfo conversationInfo = conv.conversationInfo;
        int sendingStatus = conv.sendingState;
        boolean hasSenders = false;
        // This covers the case where the sender is "me" and this is a draft
        // message, which means this will only run once most of the time.
        for (ParticipantInfo p : conversationInfo.participantInfos) {
            if (!TextUtils.isEmpty(p.name)) {
                hasSenders = true;
                break;
            }
        }
        getSenderResources(context, resourceCachingRequired);
        int count = conversationInfo.messageCount;
        int draftCount = conversationInfo.draftCount;
        if (count > 1) {
            messageInfo.append(count + "");
        }
        messageInfo.setSpan(
                CharacterStyle.wrap(conv.read ? sMessageInfoReadStyleSpan : sMessageInfoUnreadStyleSpan), 0,
                messageInfo.length(), 0);
        if (draftCount > 0) {
            // If we are showing a message count or any draft text and there
            // is at least 1 sender, prepend the sending state text with a
            // comma.
            if (hasSenders || count > 1) {
                messageInfo.append(sSendersSplitToken);
            }
            SpannableStringBuilder draftString = new SpannableStringBuilder();
            if (draftCount == 1) {
                draftString.append(sDraftSingularString);
            } else {
                draftString.append(sDraftPluralString)
                        .append(String.format(sDraftCountFormatString, draftCount));
            }
            draftString.setSpan(CharacterStyle.wrap(sDraftsStyleSpan), 0, draftString.length(),
                    Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
            messageInfo.append(draftString);
        }
        // TS: chao.zhang 2015-09-29 EMAIL FEATURE-585337 MOD_S
        //NOTE:currently,we DONOT show the status in senderView, with our ERGO,show the status on the side if Subject.diable it!!!
        //boolean showState = sendingStatus == UIProvider.ConversationSendingState.SENDING ||
        //        sendingStatus == UIProvider.ConversationSendingState.RETRYING ||
        //       sendingStatus == UIProvider.ConversationSendingState.SEND_ERROR;
        boolean showState = false;
        // TS: chao.zhang 2015-09-29 EMAIL FEATURE-585337 MOD_E
        if (showState) {
            // If we are showing a message count or any draft text, prepend
            // the sending state text with a comma.
            if (count > 1 || draftCount > 0) {
                messageInfo.append(sSendersSplitToken);
            }

            SpannableStringBuilder stateSpan = new SpannableStringBuilder();

            if (sendingStatus == UIProvider.ConversationSendingState.SENDING) {
                stateSpan.append(sSendingString);
                stateSpan.setSpan(sSendingStyleSpan, 0, stateSpan.length(), 0);
            } else if (sendingStatus == UIProvider.ConversationSendingState.RETRYING) {
                stateSpan.append(sQueuedString);
                stateSpan.setSpan(sQueuedStyleSpan, 0, stateSpan.length(), 0);
            } else if (sendingStatus == UIProvider.ConversationSendingState.SEND_ERROR) {
                stateSpan.append(sFailedString);
                stateSpan.setSpan(sFailedStyleSpan, 0, stateSpan.length(), 0);
            }
            messageInfo.append(stateSpan);
        }

        // Prepend a space if we are showing other message info text.
        if (count > 1 || (draftCount > 0 && hasSenders) || showState) {
            messageInfo.insert(0, sMessageCountSpacerString);
        }
    } finally {
        if (!resourceCachingRequired) {
            clearResourceCache();
        }
    }

    return messageInfo;
}

From source file:com.android.mail.browse.SendersView.java

private static void appendMessageInfo(SpannableStringBuilder sb, CharSequence text, Object span,
        boolean appendSplitToken, boolean convRead) {
    int startIndex = sb.length();
    if (appendSplitToken) {
        sb.append(sSendersSplitToken);//  w  ww  . j a va2s . c om
        sb.setSpan(CharacterStyle.wrap(convRead ? sMessageInfoReadStyleSpan : sMessageInfoUnreadStyleSpan),
                startIndex, sb.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
    }

    startIndex = sb.length();
    sb.append(text);
    sb.setSpan(span, startIndex, sb.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
}

From source file:com.android.mail.browse.SendersView.java

private static void handlePriority(int maxChars, String messageInfoString, ConversationInfo conversationInfo,
        ArrayList<SpannableString> styledSenders, ArrayList<String> displayableSenderNames,
        ConversationItemViewModel.SenderAvatarModel senderAvatarModel, Account account,
        final TextAppearanceSpan unreadStyleSpan, final CharacterStyle readStyleSpan,
        final boolean showToHeader) {
    final boolean shouldSelectSenders = displayableSenderNames != null;
    final boolean shouldSelectAvatar = senderAvatarModel != null;
    int maxPriorityToInclude = -1; // inclusive
    int numCharsUsed = messageInfoString.length(); // draft, number drafts,
                                                   // count
    int numSendersUsed = 0;
    int numCharsToRemovePerWord = 0;
    int maxFoundPriority = 0;
    if (numCharsUsed > maxChars) {
        numCharsToRemovePerWord = numCharsUsed - maxChars;
    }/*w  w  w  .j a v  a 2 s  .  c  o  m*/

    final Map<Integer, Integer> priorityToLength = PRIORITY_LENGTH_MAP_CACHE.get();
    try {
        priorityToLength.clear();
        int senderLength;
        for (ParticipantInfo info : conversationInfo.participantInfos) {
            final String senderName = info.name;
            senderLength = !TextUtils.isEmpty(senderName) ? senderName.length() : 0;
            priorityToLength.put(info.priority, senderLength);
            maxFoundPriority = Math.max(maxFoundPriority, info.priority);
        }
        while (maxPriorityToInclude < maxFoundPriority) {
            if (priorityToLength.containsKey(maxPriorityToInclude + 1)) {
                int length = numCharsUsed + priorityToLength.get(maxPriorityToInclude + 1);
                if (numCharsUsed > 0)
                    length += 2;
                // We must show at least two senders if they exist. If we don't
                // have space for both
                // then we will truncate names.
                if (length > maxChars && numSendersUsed >= 2) {
                    break;
                }
                numCharsUsed = length;
                numSendersUsed++;
            }
            maxPriorityToInclude++;
        }
    } finally {
        PRIORITY_LENGTH_MAP_CACHE.release(priorityToLength);
    }

    SpannableString spannableDisplay;
    boolean appendedElided = false;
    final Map<String, Integer> displayHash = Maps.newHashMap();
    final List<String> senderEmails = Lists.newArrayListWithExpectedSize(MAX_SENDER_COUNT);
    String firstSenderEmail = null;
    String firstSenderName = null;
    for (int i = 0; i < conversationInfo.participantInfos.size(); i++) {
        final ParticipantInfo currentParticipant = conversationInfo.participantInfos.get(i);
        final String currentEmail = currentParticipant.email;

        final String currentName = currentParticipant.name;
        String nameString = !TextUtils.isEmpty(currentName) ? currentName : "";
        if (nameString.length() == 0) {
            // if we're showing the To: header, show the object version of me.
            nameString = getMe(showToHeader /* useObjectMe */);
        }
        if (numCharsToRemovePerWord != 0) {
            nameString = nameString.substring(0, Math.max(nameString.length() - numCharsToRemovePerWord, 0));
        }

        final int priority = currentParticipant.priority;
        final CharacterStyle style = CharacterStyle
                .wrap(currentParticipant.readConversation ? readStyleSpan : unreadStyleSpan);
        if (priority <= maxPriorityToInclude) {
            spannableDisplay = new SpannableString(sBidiFormatter.unicodeWrap(nameString));
            // Don't duplicate senders; leave the first instance, unless the
            // current instance is also unread.
            int oldPos = displayHash.containsKey(currentName) ? displayHash.get(currentName) : DOES_NOT_EXIST;
            // If this sender doesn't exist OR the current message is
            // unread, add the sender.
            if (oldPos == DOES_NOT_EXIST || !currentParticipant.readConversation) {
                // If the sender entry already existed, and is right next to the
                // current sender, remove the old entry.
                if (oldPos != DOES_NOT_EXIST && i > 0 && oldPos == i - 1 && oldPos < styledSenders.size()) {
                    // Remove the old one!
                    styledSenders.set(oldPos, null);
                    if (shouldSelectSenders && !TextUtils.isEmpty(currentEmail)) {
                        senderEmails.remove(currentEmail);
                        displayableSenderNames.remove(currentName);
                    }
                }
                displayHash.put(currentName, i);
                spannableDisplay.setSpan(style, 0, spannableDisplay.length(), 0);
                styledSenders.add(spannableDisplay);
            }
        } else {
            if (!appendedElided) {
                spannableDisplay = new SpannableString(sElidedString);
                spannableDisplay.setSpan(style, 0, spannableDisplay.length(), 0);
                appendedElided = true;
                styledSenders.add(spannableDisplay);
            }
        }

        final String senderEmail = TextUtils.isEmpty(currentName) ? account.getEmailAddress()
                : TextUtils.isEmpty(currentEmail) ? currentName : currentEmail;

        if (shouldSelectSenders) {
            if (i == 0) {
                // Always add the first sender!
                firstSenderEmail = senderEmail;
                firstSenderName = currentName;
            } else {
                if (!Objects.equal(firstSenderEmail, senderEmail)) {
                    int indexOf = senderEmails.indexOf(senderEmail);
                    if (indexOf > -1) {
                        senderEmails.remove(indexOf);
                        displayableSenderNames.remove(indexOf);
                    }
                    senderEmails.add(senderEmail);
                    displayableSenderNames.add(currentName);
                    if (senderEmails.size() > MAX_SENDER_COUNT) {
                        senderEmails.remove(0);
                        displayableSenderNames.remove(0);
                    }
                }
            }
        }

        // if the corresponding message from this participant is unread and no sender avatar
        // is yet chosen, choose this one
        if (shouldSelectAvatar && senderAvatarModel.isNotPopulated() && !currentParticipant.readConversation) {
            senderAvatarModel.populate(currentName, senderEmail);
        }
    }

    // always add the first sender to the display
    if (shouldSelectSenders && !TextUtils.isEmpty(firstSenderEmail)) {
        if (displayableSenderNames.size() < MAX_SENDER_COUNT) {
            displayableSenderNames.add(0, firstSenderName);
        } else {
            displayableSenderNames.set(0, firstSenderName);
        }
    }

    // if all messages in the thread were read, we must search for an appropriate avatar
    if (shouldSelectAvatar && senderAvatarModel.isNotPopulated()) {
        // search for the last sender that is not the current account
        for (int i = conversationInfo.participantInfos.size() - 1; i >= 0; i--) {
            final ParticipantInfo participant = conversationInfo.participantInfos.get(i);
            // empty name implies it is the current account and should not be chosen
            if (!TextUtils.isEmpty(participant.name)) {
                // use the participant name in place of unusable email addresses
                final String senderEmail = TextUtils.isEmpty(participant.email) ? participant.name
                        : participant.email;
                senderAvatarModel.populate(participant.name, senderEmail);
                break;
            }
        }

        // if we still don't have an avatar, the account is emailing itself
        if (senderAvatarModel.isNotPopulated()) {
            senderAvatarModel.populate(account.getDisplayName(), account.getEmailAddress());
        }
    }
}

From source file:com.tct.mail.browse.SendersView.java

private static void handlePriority(int maxChars, String messageInfoString, ConversationInfo conversationInfo,
        ArrayList<SpannableString> styledSenders, ArrayList<String> displayableSenderNames,
        ArrayList<String> displayableSenderEmails, String account, final TextAppearanceSpan unreadStyleSpan,
        final CharacterStyle readStyleSpan, final boolean showToHeader) {
    boolean shouldAddPhotos = displayableSenderEmails != null;
    int maxPriorityToInclude = -1; // inclusive
    int numCharsUsed = messageInfoString.length(); // draft, number drafts,
                                                   // count
    int numSendersUsed = 0;
    int numCharsToRemovePerWord = 0;
    int maxFoundPriority = 0;
    if (numCharsUsed > maxChars) {
        numCharsToRemovePerWord = numCharsUsed - maxChars;
    }//from w  ww  .ja  va2 s. c o m

    final Map<Integer, Integer> priorityToLength = PRIORITY_LENGTH_MAP_CACHE.get();
    try {
        priorityToLength.clear();
        int senderLength;
        for (ParticipantInfo info : conversationInfo.participantInfos) {
            final String senderName = info.name;
            senderLength = !TextUtils.isEmpty(senderName) ? senderName.length() : 0;
            priorityToLength.put(info.priority, senderLength);
            maxFoundPriority = Math.max(maxFoundPriority, info.priority);
        }
        while (maxPriorityToInclude < maxFoundPriority) {
            if (priorityToLength.containsKey(maxPriorityToInclude + 1)) {
                int length = numCharsUsed + priorityToLength.get(maxPriorityToInclude + 1);
                if (numCharsUsed > 0)
                    length += 2;
                // We must show at least two senders if they exist. If we don't
                // have space for both
                // then we will truncate names.
                if (length > maxChars && numSendersUsed >= 2) {
                    break;
                }
                numCharsUsed = length;
                numSendersUsed++;
            }
            maxPriorityToInclude++;
        }
    } finally {
        PRIORITY_LENGTH_MAP_CACHE.release(priorityToLength);
    }
    // We want to include this entry if
    // 1) The onlyShowUnread flags is not set
    // 2) The above flag is set, and the message is unread
    ParticipantInfo currentParticipant;
    SpannableString spannableDisplay;
    CharacterStyle style;
    boolean appendedElided = false;
    Map<String, Integer> displayHash = Maps.newHashMap();
    String firstDisplayableSenderEmail = null;
    String firstDisplayableSender = null;
    for (int i = 0; i < conversationInfo.participantInfos.size(); i++) {
        currentParticipant = conversationInfo.participantInfos.get(i);
        final String currentEmail = currentParticipant.email;

        final String currentName = currentParticipant.name;
        String nameString = !TextUtils.isEmpty(currentName) ? currentName : "";
        if (nameString.length() == 0) {
            // if we're showing the To: header, show the object version of me.
            nameString = getMe(showToHeader /* useObjectMe */);
        }
        if (numCharsToRemovePerWord != 0) {
            nameString = nameString.substring(0, Math.max(nameString.length() - numCharsToRemovePerWord, 0));
        }

        final int priority = currentParticipant.priority;
        style = CharacterStyle.wrap(currentParticipant.readConversation ? readStyleSpan : unreadStyleSpan);
        if (priority <= maxPriorityToInclude) {
            spannableDisplay = new SpannableString(sBidiFormatter.unicodeWrap(nameString));
            // Don't duplicate senders; leave the first instance, unless the
            // current instance is also unread.
            int oldPos = displayHash.containsKey(currentName) ? displayHash.get(currentName) : DOES_NOT_EXIST;
            // If this sender doesn't exist OR the current message is
            // unread, add the sender.
            if (oldPos == DOES_NOT_EXIST || !currentParticipant.readConversation) {
                // If the sender entry already existed, and is right next to the
                // current sender, remove the old entry.
                if (oldPos != DOES_NOT_EXIST && i > 0 && oldPos == i - 1 && oldPos < styledSenders.size()) {
                    // Remove the old one!
                    styledSenders.set(oldPos, null);
                    if (shouldAddPhotos && !TextUtils.isEmpty(currentEmail)) {
                        displayableSenderEmails.remove(currentEmail);
                        displayableSenderNames.remove(currentName);
                    }
                }
                displayHash.put(currentName, i);
                spannableDisplay.setSpan(style, 0, spannableDisplay.length(), 0);
                styledSenders.add(spannableDisplay);
            }
        } else {
            if (!appendedElided) {
                spannableDisplay = new SpannableString(sElidedString);
                spannableDisplay.setSpan(style, 0, spannableDisplay.length(), 0);
                appendedElided = true;
                styledSenders.add(spannableDisplay);
            }
        }
        if (shouldAddPhotos) {
            String senderEmail = TextUtils.isEmpty(currentName) ? account
                    : TextUtils.isEmpty(currentEmail) ? currentName : currentEmail;
            if (i == 0) {
                // Always add the first sender!
                firstDisplayableSenderEmail = senderEmail;
                firstDisplayableSender = currentName;
            } else {
                if (!Objects.equal(firstDisplayableSenderEmail, senderEmail)) {
                    int indexOf = displayableSenderEmails.indexOf(senderEmail);
                    if (indexOf > -1) {
                        displayableSenderEmails.remove(indexOf);
                        displayableSenderNames.remove(indexOf);
                    }
                    displayableSenderEmails.add(senderEmail);
                    displayableSenderNames.add(currentName);
                    if (displayableSenderEmails.size() > DividedImageCanvas.MAX_DIVISIONS) {
                        displayableSenderEmails.remove(0);
                        displayableSenderNames.remove(0);
                    }
                }
            }
        }
    }
    if (shouldAddPhotos && !TextUtils.isEmpty(firstDisplayableSenderEmail)) {
        if (displayableSenderEmails.size() < DividedImageCanvas.MAX_DIVISIONS) {
            displayableSenderEmails.add(0, firstDisplayableSenderEmail);
            displayableSenderNames.add(0, firstDisplayableSender);
        } else {
            displayableSenderEmails.set(0, firstDisplayableSenderEmail);
            displayableSenderNames.set(0, firstDisplayableSender);
        }
    }
}

From source file:com.chen.mail.browse.SendersView.java

private static CharacterStyle getWrappedStyleSpan(final CharacterStyle characterStyle) {
    return CharacterStyle.wrap(characterStyle);
}

From source file:com.android.mail.browse.ConversationItemView.java

private static synchronized void getItemViewResources(Context context) {
    if (sConfigurationChangedReceiver == null) {
        sConfigurationChangedReceiver = new BroadcastReceiver() {
            @Override//from  w  w  w  .j  av a2 s . c  o  m
            public void onReceive(Context context, Intent intent) {
                STAR_OFF = null;
                getItemViewResources(context);
            }
        };
        context.registerReceiver(sConfigurationChangedReceiver,
                new IntentFilter(Intent.ACTION_CONFIGURATION_CHANGED));
    }
    if (STAR_OFF == null) {
        final Resources res = context.getResources();
        // Initialize static bitmaps.
        STAR_OFF = BitmapFactory.decodeResource(res, R.drawable.ic_star_outline_20dp);
        STAR_ON = BitmapFactory.decodeResource(res, R.drawable.ic_star_20dp);
        ATTACHMENT = BitmapFactory.decodeResource(res, R.drawable.ic_attach_file_18dp);
        ONLY_TO_ME = BitmapFactory.decodeResource(res, R.drawable.ic_email_caret_double);
        TO_ME_AND_OTHERS = BitmapFactory.decodeResource(res, R.drawable.ic_email_caret_single);
        IMPORTANT_ONLY_TO_ME = BitmapFactory.decodeResource(res,
                R.drawable.ic_email_caret_double_important_unread);
        IMPORTANT_TO_ME_AND_OTHERS = BitmapFactory.decodeResource(res,
                R.drawable.ic_email_caret_single_important_unread);
        IMPORTANT = BitmapFactory.decodeResource(res, R.drawable.ic_email_caret_none_important_unread);
        STATE_REPLIED = BitmapFactory.decodeResource(res, R.drawable.ic_badge_reply_holo_light);
        STATE_FORWARDED = BitmapFactory.decodeResource(res, R.drawable.ic_badge_forward_holo_light);
        STATE_REPLIED_AND_FORWARDED = BitmapFactory.decodeResource(res,
                R.drawable.ic_badge_reply_forward_holo_light);
        STATE_CALENDAR_INVITE = BitmapFactory.decodeResource(res, R.drawable.ic_badge_invite_holo_light);
        FOCUSED_CONVERSATION_HIGHLIGHT = res.getDrawable(R.drawable.visible_conversation_highlight);

        // Initialize colors.
        sActivatedTextSpan = CharacterStyle
                .wrap(new ForegroundColorSpan(res.getColor(R.color.senders_text_color)));
        sSendersTextColor = res.getColor(R.color.senders_text_color);
        sSubjectTextUnreadSpan = new TextAppearanceSpan(context, R.style.SubjectAppearanceUnreadStyle);
        sSubjectTextReadSpan = new TextAppearanceSpan(context, R.style.SubjectAppearanceReadStyle);

        sBadgeTextSpan = new TextAppearanceSpan(context, R.style.BadgeTextStyle);
        sBadgeBackgroundSpan = new BackgroundColorSpan(res.getColor(R.color.badge_background_color));
        sDateTextColorRead = res.getColor(R.color.date_text_color_read);
        sDateTextColorUnread = res.getColor(R.color.date_text_color_unread);
        sStarTouchSlop = res.getDimensionPixelSize(R.dimen.star_touch_slop);
        sSenderImageTouchSlop = res.getDimensionPixelSize(R.dimen.sender_image_touch_slop);
        sShrinkAnimationDuration = res.getInteger(R.integer.shrink_animation_duration);
        sSlideAnimationDuration = res.getInteger(R.integer.slide_animation_duration);
        // Initialize static color.
        sSendersSplitToken = res.getString(R.string.senders_split_token);
        sElidedPaddingToken = res.getString(R.string.elided_padding_token);
        sScrollSlop = res.getInteger(R.integer.swipeScrollSlop);
        sFoldersMaxCount = res.getInteger(R.integer.conversation_list_max_folder_count);
        sCabAnimationDuration = res.getInteger(R.integer.conv_item_view_cab_anim_duration);
        sBadgePaddingExtraWidth = res.getDimensionPixelSize(R.dimen.badge_padding_extra_width);
        sBadgeRoundedCornerRadius = res.getDimensionPixelSize(R.dimen.badge_rounded_corner_radius);
        sDividerPaint.setColor(res.getColor(R.color.divider_color));
        sDividerHeight = res.getDimensionPixelSize(R.dimen.divider_height);
    }
}

From source file:com.tct.mail.browse.SendersView.java

public static SpannableString getFormattedToHeader() {
    // TS: junwei-xu 2015-03-26 EMAIL BUGFIX-959039 MOD_S
    final SpannableString formattedToHeader = new SpannableString(
            sToHeaderString == null ? "" : sToHeaderString);
    // TS: junwei-xu 2015-03-26 EMAIL BUGFIX-959039 MOD_E
    final CharacterStyle readStyle = CharacterStyle.wrap(sReadStyleSpan);
    formattedToHeader.setSpan(readStyle, 0, formattedToHeader.length(), 0);
    return formattedToHeader;
}