Example usage for android.text.style BackgroundColorSpan BackgroundColorSpan

List of usage examples for android.text.style BackgroundColorSpan BackgroundColorSpan

Introduction

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

Prototype

public BackgroundColorSpan(@NonNull Parcel src) 

Source Link

Document

Creates a BackgroundColorSpan from a parcel.

Usage

From source file:com.ubergeek42.WeechatAndroid.ChatLinesAdapter.java

@Override
public View getView(int position, View convertView, ViewGroup parent) {
    ViewHolder holder;//from   w ww .j  av  a 2s  .  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:net.kourlas.voipms_sms.adapters.ConversationRecyclerViewAdapter.java

@Override
public void onBindViewHolder(MessageViewHolder messageViewHolder, int i) {
    Message message = messages.get(i);/* ww  w.  ja  va  2s . c om*/
    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:org.mozilla.focus.widget.InlineAutocompleteEditText.java

/**
 * Reset autocomplete states to their initial values
 *//*  w w  w. j  a  va 2s .  c o  m*/
private void resetAutocompleteState() {
    mAutoCompleteSpans = new Object[] {
            // Span to mark the autocomplete text
            AUTOCOMPLETE_SPAN,
            // Span to change the autocomplete text color
            new BackgroundColorSpan(ContextCompat.getColor(getContext(), R.color.colorAutocompleteHighlight)) };

    mAutoCompleteResult = "";

    // Pretend we already autocompleted the existing text,
    // so that actions like backspacing don't trigger autocompletion.
    mAutoCompletePrefixLength = getText().length();

    // Show the cursor.
    setCursorVisible(true);
}

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);
    }/*from w w w . j  a 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.ruesga.rview.tasks.AsyncTextDiffProcessor.java

private List<DiffView.AbstractModel> processSideBySideDiffs() {
    final List<DiffView.AbstractModel> model = new ArrayList<>();
    addBinaryAdviseIfNeeded(model);/*from  ww  w. j av  a  2 s . c  o m*/

    if (mDiffs == null) {
        return model;
    }

    int lineNumberA = 0;
    int lineNumberB = 0;

    final Spannable.Factory spannableFactory = Spannable.Factory.getInstance();
    final int noColor = ContextCompat.getColor(mContext, android.R.color.transparent);
    final int addedBgColor = ContextCompat.getColor(mContext, R.color.diffAddedBackgroundColor);
    final int addedFgColor = ContextCompat.getColor(mContext, R.color.diffAddedForegroundColor);
    final int deletedBgColor = ContextCompat.getColor(mContext, R.color.diffDeletedBackgroundColor);
    final int deletedFgColor = ContextCompat.getColor(mContext, R.color.diffDeletedForegroundColor);

    boolean noDiffs = mDiffs.length == 1 && mDiffs[0].a == null && mDiffs[0].b == null;
    int j = 0;
    for (DiffContentInfo diff : mDiffs) {
        if (diff.ab != null) {
            // Unchanged lines
            int[] p = processUnchangedLines(diff, model, j, lineNumberA, lineNumberB, noColor, noDiffs);
            lineNumberA = p[0];
            lineNumberB = p[1];
        } else {
            int posA = 0;
            int posB = 0;
            int count = Math.max(diff.a == null ? 0 : diff.a.length, diff.b == null ? 0 : diff.b.length);
            for (int i = 0; i < count; i++) {
                DiffInfoModel m = new DiffInfoModel();
                m.colorA = noColor;
                m.colorB = noColor;

                if (diff.a != null && i < diff.a.length) {
                    String line = diff.a[i];
                    m.a = ++lineNumberA;
                    m.lineNumberA = String.valueOf(m.a);
                    if (diff.editA != null) {
                        Spannable span = spannableFactory.newSpannable(prepareTabs(line));
                        if (mHighlightIntralineDiffs) {
                            int s2 = 0;
                            for (ArrayList<Integer> intra : diff.editA) {
                                int s1 = s2 + intra.get(0);
                                s2 = s1 + intra.get(1);
                                int l = posA + line.length();
                                if ((s1 >= posA && s1 <= l) || (s2 >= posA && s2 <= l)
                                        || (s1 <= posA && s2 >= l)) {
                                    span.setSpan(new BackgroundColorSpan(deletedFgColor),
                                            Math.max(posA, s1) - posA, Math.min(l, s2) - posA,
                                            Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
                                }
                            }
                        }
                        m.lineA = span;
                    } else {
                        // No intraline data, but it still could differ at start or at end
                        processNoIntralineDataA(diff, m, line, deletedFgColor);
                    }
                    m.colorA = deletedBgColor;
                    posA += line.length() + 1;
                }

                if (diff.b != null && i < diff.b.length) {
                    String line = diff.b[i];
                    m.b = ++lineNumberB;
                    m.lineNumberB = String.valueOf(m.b);
                    if (diff.editB != null) {
                        Spannable span = spannableFactory.newSpannable(prepareTabs(line));
                        if (mHighlightIntralineDiffs) {
                            int s2 = 0;
                            for (ArrayList<Integer> intra : diff.editB) {
                                int s1 = s2 + intra.get(0);
                                s2 = s1 + intra.get(1);
                                int l = posB + line.length();
                                if ((s1 >= posB && s1 <= l) || (s2 >= posB && s2 <= l)
                                        || (s1 <= posB && s2 >= l)) {
                                    span.setSpan(new BackgroundColorSpan(addedFgColor),
                                            Math.max(posB, s1) - posB, Math.min(l, s2) - posB,
                                            Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
                                }
                            }
                        }
                        m.lineB = span;
                    } else {
                        // No intraline data, but it still could differ at start or at end
                        processNoIntralineDataB(diff, m, line, addedFgColor);
                    }
                    m.colorB = addedBgColor;
                    posB += line.length() + 1;
                }
                processHighlights(m);
                model.add(m);
            }
        }
        j++;
    }
    return model;
}

From source file:com.weebly.opus1269.copyeverywhere.ui.clipviewer.ClipViewerFragment.java

/**
 * Highlight all occurrences of the given String
 *
 * @param highlightText the text to highlight (case insensitive)
 *//*  w ww.  j  a v a 2s .com*/
public void setHighlightText(String highlightText) {
    if (Collator.getInstance().equals(mHighlightText, highlightText)) {
        return;
    }

    mHighlightText = highlightText;

    final TextView textView = (TextView) getActivity().findViewById(R.id.clipViewerText);
    if (textView == null) {
        return;
    }

    if (TextUtils.isEmpty(highlightText)) {
        // make sure to reset spans
        textView.setText(mClipItem.getText());
    } else {
        final String text = mClipItem.getText();
        final Spannable spanText = Spannable.Factory.getInstance().newSpannable(text);
        final int color = ContextCompat.getColor(getContext(), R.color.accent_highlight);
        final Pattern p = Pattern.compile(highlightText, Pattern.CASE_INSENSITIVE);
        final Matcher m = p.matcher(text);
        final int length = highlightText.length();
        while (m.find()) {
            final int start = m.start();
            final int stop = start + length;
            //noinspection ObjectAllocationInLoop
            spanText.setSpan(new BackgroundColorSpan(color), start, stop, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        }

        textView.setText(spanText);
    }
}

From source file:com.ruesga.rview.tasks.AsyncTextDiffProcessor.java

private List<DiffView.AbstractModel> processUnifiedDiffs() {
    final List<DiffView.AbstractModel> model = new ArrayList<>();
    addBinaryAdviseIfNeeded(model);//from www. j  ava  2 s . c  o  m

    if (mDiffs == null) {
        return model;
    }

    int lineNumberA = 0;
    int lineNumberB = 0;

    final Spannable.Factory spannableFactory = Spannable.Factory.getInstance();
    final int noColor = ContextCompat.getColor(mContext, android.R.color.transparent);
    final int addedBgColor = ContextCompat.getColor(mContext, R.color.diffAddedBackgroundColor);
    final int addedFgColor = ContextCompat.getColor(mContext, R.color.diffAddedForegroundColor);
    final int deletedBgColor = ContextCompat.getColor(mContext, R.color.diffDeletedBackgroundColor);
    final int deletedFgColor = ContextCompat.getColor(mContext, R.color.diffDeletedForegroundColor);

    boolean noDiffs = mDiffs.length == 1 && mDiffs[0].a == null && mDiffs[0].b == null;
    int j = 0;
    for (DiffContentInfo diff : mDiffs) {
        if (diff.ab != null) {
            // Unchanged lines
            int[] p = processUnchangedLines(diff, model, j, lineNumberA, lineNumberB, noColor, noDiffs);
            lineNumberA = p[0];
            lineNumberB = p[1];
        } else {
            if (diff.a != null) {
                int pos = 0;
                for (String line : diff.a) {
                    DiffInfoModel m = new DiffInfoModel();
                    m.a = ++lineNumberA;
                    m.lineNumberA = String.valueOf(m.a);
                    if (diff.editA != null) {
                        Spannable span = spannableFactory.newSpannable(prepareTabs(line));
                        if (mHighlightIntralineDiffs) {
                            int s2 = 0;
                            for (ArrayList<Integer> intra : diff.editA) {
                                int s1 = s2 + intra.get(0);
                                s2 = s1 + intra.get(1);
                                int l = pos + line.length();
                                if ((s1 >= pos && s1 <= l) || (s2 >= pos && s2 <= l)
                                        || (s1 <= pos && s2 >= l)) {
                                    span.setSpan(new BackgroundColorSpan(deletedFgColor),
                                            Math.max(pos, s1) - pos, Math.min(l, s2) - pos,
                                            Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
                                }
                            }
                        }
                        m.lineA = span;
                    } else {
                        // No intraline data, but it still could differ at start or at end
                        processNoIntralineDataA(diff, m, line, deletedFgColor);
                    }
                    m.colorA = deletedBgColor;
                    m.colorB = noColor;
                    processHighlights(m);
                    model.add(m);
                    pos += line.length() + 1;
                }
            }
            if (diff.b != null) {
                int pos = 0;
                for (String line : diff.b) {
                    DiffInfoModel m = new DiffInfoModel();
                    m.b = ++lineNumberB;
                    m.lineNumberB = String.valueOf(m.b);
                    if (diff.editB != null) {
                        Spannable span = spannableFactory.newSpannable(prepareTabs(line));
                        if (mHighlightIntralineDiffs) {
                            int s2 = 0;
                            for (ArrayList<Integer> intra : diff.editB) {
                                int s1 = s2 + intra.get(0);
                                s2 = s1 + intra.get(1);
                                int l = pos + line.length();
                                if ((s1 >= pos && s1 <= l) || (s2 >= pos && s2 <= l)
                                        || (s1 <= pos && s2 >= l)) {
                                    span.setSpan(new BackgroundColorSpan(addedFgColor), Math.max(pos, s1) - pos,
                                            Math.min(l, s2) - pos, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
                                }
                            }
                        }
                        m.lineB = span;
                    } else {
                        // No intraline data, but it still could differ at start or at end
                        processNoIntralineDataB(diff, m, line, addedFgColor);
                    }
                    m.colorA = addedBgColor;
                    m.colorB = noColor;
                    processHighlights(m);
                    model.add(m);
                    pos += line.length() + 1;
                }
            }
        }
        j++;
    }
    return model;
}

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

private static synchronized void getItemViewResources(Context context) {
    if (sConfigurationChangedReceiver == null) {
        sConfigurationChangedReceiver = new BroadcastReceiver() {
            @Override/*w  w  w  . j  ava  2s . 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.ruesga.rview.tasks.AsyncTextDiffProcessor.java

private void processNoIntralineDataA(DiffContentInfo diff, DiffInfoModel m, String line, int color) {
    final Spannable.Factory spannableFactory = Spannable.Factory.getInstance();
    if (diff.a != null && diff.b != null && diff.a.length == 1 && diff.b.length == 1) {
        Spannable span = spannableFactory.newSpannable(prepareTabs(line));
        int z = diff.a[0].indexOf(diff.b[0]);
        if (z != -1) {
            if (z > 0) {
                span.setSpan(new BackgroundColorSpan(color), 0, z, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
            }//from   ww w.j  av  a 2 s. c  o  m
            if (z + diff.b[0].length() < diff.a[0].length()) {
                z = z + diff.b[0].length();
                span.setSpan(new BackgroundColorSpan(color), z, diff.a[0].length(),
                        Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
            }
        }
        m.lineA = span;
    } else {
        m.lineA = prepareTabs(line);
    }
}

From source file:com.ruesga.rview.tasks.AsyncTextDiffProcessor.java

private void processNoIntralineDataB(DiffContentInfo diff, DiffInfoModel m, String line, int color) {
    final Spannable.Factory spannableFactory = Spannable.Factory.getInstance();
    if (diff.a != null && diff.b != null && diff.a.length == 1 && diff.b.length == 1) {
        Spannable span = spannableFactory.newSpannable(prepareTabs(line));
        int z = diff.b[0].indexOf(diff.a[0]);
        if (z != -1) {
            if (z > 0) {
                span.setSpan(new BackgroundColorSpan(color), 0, z, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
            }//  ww  w.j a va2s  . c o  m
            if (z + diff.a[0].length() < diff.b[0].length()) {
                z = z + diff.a[0].length();
                span.setSpan(new BackgroundColorSpan(color), z, diff.b[0].length(),
                        Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
            }
        }
        m.lineB = span;
    } else {
        m.lineB = prepareTabs(line);
    }
}