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:cn.figo.mydemo.ui.activity.VideoActivity.java

private SpannableStringBuilder createSpannable(Drawable drawable) {
    String text = "bitmap";
    SpannableStringBuilder spannableStringBuilder = new SpannableStringBuilder(text);
    ImageSpan span = new ImageSpan(drawable);//ImageSpan.ALIGN_BOTTOM);
    spannableStringBuilder.setSpan(span, 0, text.length(), Spannable.SPAN_INCLUSIVE_EXCLUSIVE);
    spannableStringBuilder.append("");
    spannableStringBuilder.setSpan(new BackgroundColorSpan(Color.parseColor("#8A2233B1")), 0,
            spannableStringBuilder.length(), Spannable.SPAN_INCLUSIVE_INCLUSIVE);
    return spannableStringBuilder;
}

From source file:com.filemanager.free.activities.TextReader.java

@Override
public void onClick(View v) {
    switch (v.getId()) {
    case R.id.prev:
        // upButton
        if (mCurrent > 0) {

            // setting older span back before setting new one
            Map.Entry keyValueOld = (Map.Entry) nodes.get(mCurrent).getKey();
            mInput.getText().setSpan(/*  w  ww  .j ava  2  s  .  co  m*/
                    theme1 == 0 ? new BackgroundColorSpan(Color.YELLOW) : new BackgroundColorSpan(Color.LTGRAY),
                    (Integer) keyValueOld.getKey(), (Integer) keyValueOld.getValue(),
                    Spanned.SPAN_INCLUSIVE_INCLUSIVE);

            // highlighting previous element in list
            Map.Entry keyValueNew = (Map.Entry) nodes.get(--mCurrent).getKey();
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
                mInput.getText().setSpan(
                        new BackgroundColorSpan(
                                getResources().getColor(R.color.search_text_highlight, getTheme())),
                        (Integer) keyValueNew.getKey(), (Integer) keyValueNew.getValue(),
                        Spanned.SPAN_INCLUSIVE_INCLUSIVE);
            } else {
                mInput.getText().setSpan(
                        new BackgroundColorSpan(ContextCompat.getColor(c, R.color.search_text_highlight)),
                        (Integer) keyValueNew.getKey(), (Integer) keyValueNew.getValue(),
                        Spanned.SPAN_INCLUSIVE_INCLUSIVE);
            }
        }
        break;
    case R.id.next:
        // downButton
        if (mCurrent < nodes.size() - 1) {

            // setting older span back before setting new one
            if (mCurrent != -1) {

                Map.Entry keyValueOld = (Map.Entry) nodes.get(mCurrent).getKey();
                mInput.getText().setSpan(
                        theme1 == 0 ? new BackgroundColorSpan(Color.YELLOW)
                                : new BackgroundColorSpan(Color.LTGRAY),
                        (Integer) keyValueOld.getKey(), (Integer) keyValueOld.getValue(),
                        Spanned.SPAN_INCLUSIVE_INCLUSIVE);
            }

            Map.Entry keyValueNew = (Map.Entry) nodes.get(++mCurrent).getKey();
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
                mInput.getText().setSpan(
                        new BackgroundColorSpan(
                                getResources().getColor(R.color.search_text_highlight, getTheme())),
                        (Integer) keyValueNew.getKey(), (Integer) keyValueNew.getValue(),
                        Spanned.SPAN_INCLUSIVE_INCLUSIVE);
            } else {
                mInput.getText().setSpan(
                        new BackgroundColorSpan(ContextCompat.getColor(c, R.color.search_text_highlight)),
                        (Integer) keyValueNew.getKey(), (Integer) keyValueNew.getValue(),
                        Spanned.SPAN_INCLUSIVE_INCLUSIVE);
            }

            // scrolling to the highlighted element
            DisplayMetrics displayMetrics = new DisplayMetrics();
            getWindowManager().getDefaultDisplay().getMetrics(displayMetrics);
            scrollView.scrollTo(0, (Integer) keyValueNew.getValue() + mInput.getLineHeight()
                    - displayMetrics.heightPixels / 2);
        }
        break;
    case R.id.close:
        onDestroyActionMode();
        // closeButton
        findViewById(R.id.searchview).setVisibility(View.GONE);
        break;
    default:
        return;
    }
}

From source file:com.todoroo.astrid.adapter.TaskAdapter.java

private Function<TagData, SpannableString> tagToString(final float maxLength) {
    return tagData -> {
        String tagName = tagData.getName();
        tagName = tagName.substring(0, Math.min(tagName.length(), (int) maxLength));
        SpannableString string = new SpannableString(SPACE + tagName + SPACE);
        int themeIndex = tagData.getColor();
        ThemeColor color = themeIndex >= 0 ? themeCache.getThemeColor(themeIndex)
                : themeCache.getUntaggedColor();
        string.setSpan(new BackgroundColorSpan(color.getPrimaryColor()), 0, string.length(),
                Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
        string.setSpan(new ForegroundColorSpan(color.getActionBarTint()), 0, string.length(),
                Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
        return string;
    };//from w  w w.  j  a v a 2  s.c om
}

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

private CharSequence processHighlightTrailingSpaces(CharSequence text) {
    if (!mHighlightTrailingWhitespaces) {
        return text;
    }//ww w.j ava2s.c  om

    int color = ContextCompat.getColor(mContext, R.color.diffHighlightColor);
    final Spannable.Factory spannableFactory = Spannable.Factory.getInstance();
    String line = text.toString();
    final Matcher matcher = HIGHLIGHT_TRAIL_SPACES_PATTERN.matcher(line);
    if (matcher.find()) {
        int start = matcher.start();
        int end = matcher.end();
        Spannable span = spannableFactory.newSpannable(text);
        span.setSpan(new BackgroundColorSpan(color), start, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        return span;
    }
    return text;
}

From source file:com.nttec.everychan.ui.presentation.HtmlParser.java

private static void endAibspoiler(SpannableStringBuilder text, ThemeColors colors, boolean openSpoilers) {
    int len = text.length();
    Object obj = getLast(text, Aibspoiler.class);
    int where = text.getSpanStart(obj);
    text.removeSpan(obj);/*from  w w w.j  a  v  a 2 s . c o  m*/

    if (where != len && colors != null) {
        if (openSpoilers) {
            text.setSpan(new ForegroundColorSpan(colors.spoilerForeground), where, len,
                    Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
            text.setSpan(new BackgroundColorSpan(colors.spoilerBackground), where, len,
                    Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        } else {
            text.setSpan(new SpoilerSpan(colors.spoilerForeground, colors.spoilerBackground), where, len,
                    Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        }
    }
}

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

private static synchronized void getItemViewResources(Context context) {
    if (sConfigurationChangedReceiver == null) {
        sConfigurationChangedReceiver = new BroadcastReceiver() {
            @Override/*w w  w  .ja va 2 s.c  om*/
            public void onReceive(Context context, Intent intent) {
                STAR_OFF = null;
                //[BUGFIX]-Mod-BEGIN by TCTNB.caixia.chen,01/07/2015,PR 893304
                getItemViewResources(context.getApplicationContext());
                //[BUGFIX]-Mod-END by TCTNB.caixia.chen
            }
        };
        context.registerReceiver(sConfigurationChangedReceiver,
                new IntentFilter(Intent.ACTION_CONFIGURATION_CHANGED));
    }
    if (STAR_OFF == null) {
        final Resources res = context.getResources();
        // Initialize static bitmaps.
        //TS: junwei-xu 2015-09-02 EMAIL BUGFIX-546917 MOD-S
        // star off will not show in list item.
        //STAR_OFF = BitmapFactory.decodeResource(res, R.drawable.ic_star_outline_20dp);
        STAR_OFF = BitmapFactory.decodeResource(res, R.drawable.ic_importance_normal);
        //TS: junwei-xu 2015-09-02 EMAIL BUGFIX-546917 MOD-S
        STAR_ON = BitmapFactory.decodeResource(res, R.drawable.ic_star_20dp);
        ATTACHMENT = BitmapFactory.decodeResource(res, R.drawable.ic_attach_file_20dp);
        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);
        VISIBLE_CONVERSATION_HIGHLIGHT = res.getDrawable(R.drawable.visible_conversation_highlight);
        RIGHT_EDGE_TABLET = res.getDrawable(R.drawable.list_edge_tablet);
        //[FEATURE]-Add-BEGIN by TSCD.chao zhang,04/17/2014,FR 631895(porting from FR514398)
        sHighPriorityIcon = BitmapFactory.decodeResource(res, R.drawable.ic_high_priority);
        sLowPriorityIcon = BitmapFactory.decodeResource(res, R.drawable.ic_low_priority);
        sNormalPriorityIcon = BitmapFactory.decodeResource(res, R.drawable.ic_importance_normal);
        //[FEATURE]-Add-END by TSCD.chao zhang

        // 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);
        sFoldersStartPadding = res.getDimensionPixelOffset(R.dimen.folders_start_padding);
        sFoldersInnerPadding = res.getDimensionPixelOffset(R.dimen.folder_cell_content_padding);
        sFoldersMaxCount = res.getInteger(R.integer.conversation_list_max_folder_count);
        sFoldersOverflowGradientPadding = res.getDimensionPixelOffset(R.dimen.folders_gradient_padding);
        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);
        sFolderRoundedCornerRadius = res.getDimensionPixelOffset(R.dimen.folder_rounded_corner_radius);
        sDividerColor = res.getColor(R.color.conversation_list_divider_color);
        sDividerInset = res.getDimensionPixelSize(R.dimen.conv_list_divider_inset);
        sDividerHeight = res.getDimensionPixelSize(R.dimen.divider_height);
    }
}

From source file:com.juick.android.JuickMessagesAdapter.java

public static ParsedMessage formatMessageText(final Context ctx, final JuickMessage jmsg, boolean condensed) {
    if (jmsg.parsedText != null) {
        return (ParsedMessage) jmsg.parsedText; // was parsed before
    }/*from   ww  w .  j a  va 2s  .  com*/
    getColorTheme(ctx);
    SpannableStringBuilder ssb = new SpannableStringBuilder();
    int spanOffset = 0;
    final boolean isMainMessage = jmsg.getRID() == 0;
    final boolean doCompactComment = !isMainMessage && compactComments;
    if (jmsg.continuationInformation != null) {
        ssb.append(jmsg.continuationInformation + "\n");
        ssb.setSpan(new StyleSpan(Typeface.ITALIC), spanOffset, ssb.length() - 1,
                Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
    }
    //
    // NAME
    //
    spanOffset = ssb.length();
    String name = '@' + jmsg.User.UName;
    int userNameStart = ssb.length();
    ssb.append(name);
    int userNameEnd = ssb.length();
    StyleSpan userNameBoldSpan;
    ForegroundColorSpan userNameColorSpan;
    ssb.setSpan(userNameBoldSpan = new StyleSpan(Typeface.BOLD), spanOffset, ssb.length(),
            Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
    ssb.setSpan(
            userNameColorSpan = new ForegroundColorSpan(
                    colorTheme.getColor(ColorsTheme.ColorKey.USERNAME, 0xFFC8934E)),
            spanOffset, ssb.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);

    if (helvNueFonts) {
        ssb.setSpan(new CustomTypefaceSpan("", JuickAdvancedApplication.helvNueBold), spanOffset, ssb.length(),
                Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
    }
    ssb.append(' ');
    spanOffset = ssb.length();

    if (!condensed) {
        //
        // TAGS
        //
        String tags = jmsg.getTags();
        if (feedlyFonts)
            tags = tags.toUpperCase();
        ssb.append(tags + "\n");
        if (tags.length() > 0) {
            ssb.setSpan(new ForegroundColorSpan(colorTheme.getColor(ColorsTheme.ColorKey.TAGS, 0xFF0000CC)),
                    spanOffset, ssb.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
            if (feedlyFonts) {
                ssb.setSpan(new CustomTypefaceSpan("", JuickAdvancedApplication.dinWebPro), spanOffset,
                        ssb.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
            } else if (helvNueFonts) {
                ssb.setSpan(new CustomTypefaceSpan("", JuickAdvancedApplication.helvNue), spanOffset,
                        ssb.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
            }

        }
        spanOffset = ssb.length();
    }
    if (jmsg.translated) {
        //
        // 'translated'
        //
        ssb.append("translated: ");
        ssb.setSpan(
                new ForegroundColorSpan(colorTheme.getColor(ColorsTheme.ColorKey.TRANSLATED_LABEL, 0xFF4ec856)),
                spanOffset, ssb.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        ssb.setSpan(new StyleSpan(android.graphics.Typeface.BOLD), spanOffset, ssb.length(),
                Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        spanOffset = ssb.length();
    }
    int bodyOffset = ssb.length();
    int messageNumberStart = -1, messageNumberEnd = -1;
    if (showNumbers(ctx) && !condensed) {
        //
        // numbers
        //
        if (isMainMessage) {
            messageNumberStart = ssb.length();
            ssb.append(jmsg.getDisplayMessageNo());
            messageNumberEnd = ssb.length();
        } else {
            ssb.append("/" + jmsg.getRID());
            if (jmsg.getReplyTo() != 0) {
                ssb.append("->" + jmsg.getReplyTo());
            }
        }
        ssb.append(" ");
        ssb.setSpan(new ForegroundColorSpan(colorTheme.getColor(ColorsTheme.ColorKey.MESSAGE_ID, 0xFFa0a5bd)),
                spanOffset, ssb.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        spanOffset = ssb.length();
    }
    //
    // MESSAGE BODY
    //
    String txt = Censor.getCensoredText(jmsg.Text);
    if (!condensed) {
        if (jmsg.Photo != null) {
            txt = jmsg.Photo + "\n" + txt;
        }
        if (jmsg.Video != null) {
            txt = jmsg.Video + "\n" + txt;
        }
    }
    ssb.append(txt);
    boolean ssbChanged = false; // allocation optimization
    // Highlight links http://example.com/
    ArrayList<ExtractURLFromMessage.FoundURL> foundURLs = ExtractURLFromMessage.extractUrls(txt, jmsg.getMID());
    ArrayList<String> urls = new ArrayList<String>();
    for (ExtractURLFromMessage.FoundURL foundURL : foundURLs) {
        setSSBSpan(ssb, new ForegroundColorSpan(colorTheme.getColor(ColorsTheme.ColorKey.URLS, 0xFF0000CC)),
                spanOffset + foundURL.start, spanOffset + foundURL.end, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        urls.add(foundURL.url);
        if (foundURL.title != null) {
            ssb.replace(spanOffset + foundURL.title.start - 1, spanOffset + foundURL.title.start, " ");
            ssb.replace(spanOffset + foundURL.title.end, spanOffset + foundURL.title.end + 1, " ");
            ssb.replace(spanOffset + foundURL.start - 1, spanOffset + foundURL.start, "(");
            ssb.replace(spanOffset + foundURL.end, spanOffset + foundURL.end + 1, ")");
            ssb.setSpan(new StyleSpan(Typeface.BOLD), spanOffset + foundURL.title.start,
                    spanOffset + foundURL.title.end, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        }
        ssbChanged = true;
    }
    // bold italic underline
    if (jmsg.Text.indexOf("*") != -1) {
        setStyleSpans(ssb, spanOffset, Typeface.BOLD, "*");
        ssbChanged = true;
    }
    if (jmsg.Text.indexOf("/") != 0) {
        setStyleSpans(ssb, spanOffset, Typeface.ITALIC, "/");
        ssbChanged = true;
    }
    if (jmsg.Text.indexOf("_") != 0) {
        setStyleSpans(ssb, spanOffset, UnderlineSpan.class, "_");
        ssbChanged = true;
    }
    if (ssbChanged) {
        txt = ssb.subSequence(spanOffset, ssb.length()).toString(); // ssb was modified in between
    }

    // Highlight nick
    String accountName = XMPPService.getMyAccountName(jmsg.getMID(), ctx);
    if (accountName != null) {
        int scan = spanOffset;
        String nickScanArea = (ssb + " ").toUpperCase();
        while (true) {
            int myNick = nickScanArea.indexOf("@" + accountName.toUpperCase(), scan);
            if (myNick != -1) {
                if (!isNickPart(nickScanArea.charAt(myNick + accountName.length() + 1))) {
                    setSSBSpan(ssb,
                            new BackgroundColorSpan(
                                    colorTheme.getColor(ColorsTheme.ColorKey.USERNAME_ME, 0xFF938e00)),
                            myNick - 1, myNick + accountName.length() + 2, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
                }
                scan = myNick + 1;
            } else {
                break;
            }
        }
    }

    // Highlight messages #1234
    int pos = 0;
    Matcher m = getCrossReferenceMsgPattern(jmsg.getMID()).matcher(txt);
    while (m.find(pos)) {
        ssb.setSpan(new ForegroundColorSpan(colorTheme.getColor(ColorsTheme.ColorKey.URLS, 0xFF0000CC)),
                spanOffset + m.start(), spanOffset + m.end(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        pos = m.end();
    }

    SpannableStringBuilder compactDt = null;
    if (!condensed) {

        // found messages count (search results)
        if (jmsg.myFoundCount != 0 || jmsg.hisFoundCount != 0) {
            ssb.append("\n");
            int where = ssb.length();
            if (jmsg.myFoundCount != 0) {
                ssb.append(ctx.getString(R.string.MyReplies_) + jmsg.myFoundCount + "  ");
            }
            if (jmsg.hisFoundCount != 0) {
                ssb.append(ctx.getString(R.string.UserReplies_) + jmsg.hisFoundCount);
            }
            ssb.setSpan(
                    new ForegroundColorSpan(
                            colorTheme.getColor(ColorsTheme.ColorKey.TRANSLATED_LABEL, 0xFF4ec856)),
                    where, ssb.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        }

        int rightPartOffset = spanOffset = ssb.length();

        if (!doCompactComment) {
            //
            // TIME (bottom of message)
            //

            try {
                DateFormat df = new SimpleDateFormat("HH:mm dd/MMM/yy");
                String date = jmsg.Timestamp != null ? df.format(jmsg.Timestamp) : "[bad date]";
                if (date.endsWith("/76"))
                    date = date.substring(0, date.length() - 3); // special case for no year in datasource
                ssb.append("\n" + date + " ");
            } catch (Exception e) {
                ssb.append("\n[fmt err] ");
            }

            ssb.setSpan(new ForegroundColorSpan(colorTheme.getColor(ColorsTheme.ColorKey.DATE, 0xFFAAAAAA)),
                    spanOffset, ssb.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        } else {
            compactDt = new SpannableStringBuilder();
            try {
                if (true || jmsg.deltaTime != Long.MIN_VALUE) {
                    compactDt.append(com.juickadvanced.Utils.toRelaviteDate(jmsg.Timestamp.getTime(), russian));
                } else {
                    DateFormat df = new SimpleDateFormat("HH:mm dd/MMM/yy");
                    String date = jmsg.Timestamp != null ? df.format(jmsg.Timestamp) : "[bad date]";
                    if (date.endsWith("/76"))
                        date = date.substring(0, date.length() - 3); // special case for no year in datasource
                    compactDt.append(date);
                }
            } catch (Exception e) {
                compactDt.append("\n[fmt err] ");
            }
            compactDt.setSpan(
                    new ForegroundColorSpan(colorTheme.getColor(ColorsTheme.ColorKey.DATE, 0xFFAAAAAA)), 0,
                    compactDt.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);

        }

        spanOffset = ssb.length();

        //
        // Number of REPLIES
        //
        if (jmsg.replies > 0) {
            String replies = Replies + jmsg.replies;
            ssb.append(" " + replies);
            ssb.setSpan(
                    new ForegroundColorSpan(
                            colorTheme.getColor(ColorsTheme.ColorKey.NUMBER_OF_COMMENTS, 0xFFC8934E)),
                    spanOffset, ssb.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
            ssb.setSpan(new WrapTogetherSpan() {
            }, spanOffset, ssb.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        }
        if (!doCompactComment) {
            // right align
            ssb.setSpan(new AlignmentSpan.Standard(Alignment.ALIGN_OPPOSITE), rightPartOffset, ssb.length(),
                    Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        }
    }

    if (helvNueFonts) {
        ssb.setSpan(new CustomTypefaceSpan("", JuickAdvancedApplication.helvNue), bodyOffset, ssb.length(),
                Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
    }

    LeadingMarginSpan.LeadingMarginSpan2 userpicSpan = null;
    if (showUserpics(ctx) && !condensed) {
        userpicSpan = new LeadingMarginSpan.LeadingMarginSpan2() {
            @Override
            public int getLeadingMarginLineCount() {
                if (_wrapUserpics) {
                    return 2;
                } else {
                    return 22222;
                }
            }

            @Override
            public int getLeadingMargin(boolean first) {
                if (first) {
                    return (int) (2 * getLineHeight(ctx, (double) textScale));
                } else {
                    return 0;
                }
            }

            @Override
            public void drawLeadingMargin(Canvas c, Paint p, int x, int dir, int top, int baseline, int bottom,
                    CharSequence text, int start, int end, boolean first, Layout layout) {
            }
        };
        ssb.setSpan(userpicSpan, 0, ssb.length(), 0);
    }
    ParsedMessage parsedMessage = new ParsedMessage(ssb, urls);
    parsedMessage.userpicSpan = userpicSpan;
    parsedMessage.userNameBoldSpan = userNameBoldSpan;
    parsedMessage.userNameColorSpan = userNameColorSpan;
    parsedMessage.userNameStart = userNameStart;
    parsedMessage.userNameEnd = userNameEnd;
    parsedMessage.messageNumberStart = messageNumberStart;
    parsedMessage.messageNumberEnd = messageNumberEnd;
    parsedMessage.compactDate = compactDt;
    return parsedMessage;
}

From source file:com.nttec.everychan.ui.presentation.HtmlParser.java

private static void endSpan(SpannableStringBuilder text, ThemeColors colors, boolean openSpoilers) {
    int len = text.length();
    Object obj = getLast(text, Span.class);
    int where = text.getSpanStart(obj);
    text.removeSpan(obj);/*from ww  w  .ja v a 2s .  c  o m*/

    if (where != len) {
        Span s = (Span) obj;

        if (s.mStyle != null) {
            List<Object> styleSpans = parseStyleAttributes(s.mStyle);
            for (Object span : styleSpans) {
                text.setSpan(span, where, len, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
            }
        }

        if (colors != null && s.mIsAibquote) {
            text.setSpan(new ForegroundColorSpan(colors.quoteForeground), where, len,
                    Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        }

        if (colors != null && s.mIsAibspoiler) {
            if (openSpoilers) {
                text.setSpan(new ForegroundColorSpan(colors.spoilerForeground), where, len,
                        Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
                text.setSpan(new BackgroundColorSpan(colors.spoilerBackground), where, len,
                        Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
            } else {
                text.setSpan(new SpoilerSpan(colors.spoilerForeground, colors.spoilerBackground), where, len,
                        Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
            }
        }

        if (s.mIsUnderline) {
            text.setSpan(new UnderlineSpan(), where, len, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        }

        if (s.mIsStrike) {
            text.setSpan(new StrikethroughSpan(), where, len, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        }

    }
}

From source file:com.nttec.everychan.ui.presentation.HtmlParser.java

private static List<Object> parseStyleAttributes(String style) {
    if (TextUtils.isEmpty(style))
        return Collections.emptyList();
    int foregroundColor = 0, backgroundColor = 0;
    String[] cssStyle = style.split("[;]");
    for (String s : cssStyle) {
        int color = parseColor(s);
        if (color != 0) {
            if (s.toLowerCase(Locale.US).indexOf("background") != -1)
                backgroundColor = color;
            else//www.  j  a  v  a2s.  co m
                foregroundColor = color;
        }
    }
    if (foregroundColor == 0 && backgroundColor == 0) {
        return Collections.emptyList();
    } else if (backgroundColor == 0) {
        return Collections.singletonList((Object) new ForegroundColorSpan(foregroundColor));
    } else if (foregroundColor == 0) {
        return Collections.singletonList((Object) new BackgroundColorSpan(backgroundColor));
    } else {
        List<Object> spans = new ArrayList<Object>(2);
        spans.add(new ForegroundColorSpan(foregroundColor));
        spans.add(new BackgroundColorSpan(backgroundColor));
        return spans;
    }
}

From source file:com.songcode.materialnotes.ui.NoteEditActivity.java

private Spannable getHighlightQueryResult(String fullText, String userQuery) {
    SpannableString spannable = new SpannableString(fullText == null ? "" : fullText);
    if (!TextUtils.isEmpty(userQuery)) {
        mPattern = Pattern.compile(userQuery);
        Matcher m = mPattern.matcher(fullText);
        int start = 0;
        while (m.find(start)) {
            spannable.setSpan(// w  ww  .java  2 s.  com
                    new BackgroundColorSpan(this.getResources().getColor(R.color.user_query_highlight)),
                    m.start(), m.end(), Spannable.SPAN_INCLUSIVE_EXCLUSIVE);
            start = m.end();
        }
    }
    return spannable;
}