Java 类android.text.Spannable 实例源码

项目:Rotatable-Scalable-Font    文件:WidgetTextContent.java   
private SpannableString applyLetterSpacing(String text) {
    StringBuilder builder = new StringBuilder();
    for (int i = 0; i < text.length(); i++) {
        builder.append(text.charAt(i));
        if (i + 1 < text.length() && !isEmojiCharacter(text.charAt(i))) {//avoid adding the blank code between the emoji code
            builder.append("\u00A0");
        }
    }
    SpannableString finalText = new SpannableString(builder.toString());
    if (builder.toString().length() > 1) {
        for (int i = 1; i < builder.toString().length(); i += 2) {
            if (builder.toString().toCharArray()[i] == 160) {//avoid breaking emoji code, u00A0 is text space
                finalText.setSpan(new ScaleXSpan((mLetterSpace + 1) / 10), i, i + 1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
            }
        }
    }
    return finalText;
}
项目:OSchina_resources_android    文件:TweetQueueAdapter.java   
@SuppressWarnings("unused")
public void bind(int position, TweetPublishModel model, RequestManager loader) {
    itemView.setTag(model);

    Context context = itemView.getContext();

    Spannable spannable = TweetParser.getInstance().parse(context, model.getContent());
    mTitle.setText(spannable);
    mTitle.setMovementMethod(LinkMovementMethod.getInstance());
    mTitle.setFocusable(false);
    mTitle.setDispatchToParent(true);
    mTitle.setLongClickable(false);

    mLog.setText(String.format("Error:%s.",
            model.getErrorString() == null ? "null" : model.getErrorString()));
    mDate.setText(FORMAT.format(new Date(model.getDate())));
}
项目:RLibrary    文件:RExTextView.java   
/**
 * 检查当前位置是否命中在spannable上, 如果是, 返回spannable的start position
 */
private int findStartPosition(Spannable spannable, int startWidthPosition) {
    CharacterStyle[] oldSpans = spannable.getSpans(startWidthPosition, spannable.length(), CharacterStyle.class);
    int position = startWidthPosition;
    for (CharacterStyle oldSpan : oldSpans) {
        int spanStart = spannable.getSpanStart(oldSpan);
        int spanEnd = spannable.getSpanEnd(oldSpan);

        if (spanStart <= startWidthPosition && spanEnd > startWidthPosition) {
            position = spanStart;
        }

        if (spanStart >= startWidthPosition) {
            spannable.removeSpan(oldSpan);
        }
    }
    //L.e("call: findStartPosition([spannable, startWidthPosition]) " + startWidthPosition + " -> " + position);
    return position;
}
项目:QMUI_Android    文件:QMUILinkTouchDecorHelper.java   
public ITouchableSpan getPressedSpan(TextView textView, Spannable spannable, MotionEvent event) {
    int x = (int) event.getX();
    int y = (int) event.getY();

    x -= textView.getTotalPaddingLeft();
    y -= textView.getTotalPaddingTop();

    x += textView.getScrollX();
    y += textView.getScrollY();

    Layout layout = textView.getLayout();
    int line = layout.getLineForVertical(y);
    int off = layout.getOffsetForHorizontal(line, x);
    if (x < layout.getLineLeft(line) || x > layout.getLineRight(line)) {
        // 实际上没点到任何内容
        off = -1;
    }

    ITouchableSpan[] link = spannable.getSpans(off, off, ITouchableSpan.class);
    ITouchableSpan touchedSpan = null;
    if (link.length > 0) {
        touchedSpan = link[0];
    }
    return touchedSpan;
}
项目:qmui    文件:QMUILinkTouchDecorHelper.java   
public ITouchableSpan getPressedSpan(TextView textView, Spannable spannable, MotionEvent event) {
    int x = (int) event.getX();
    int y = (int) event.getY();

    x -= textView.getTotalPaddingLeft();
    y -= textView.getTotalPaddingTop();

    x += textView.getScrollX();
    y += textView.getScrollY();

    Layout layout = textView.getLayout();
    int line = layout.getLineForVertical(y);
    int off = layout.getOffsetForHorizontal(line, x);
    if (x < layout.getLineLeft(line) || x > layout.getLineRight(line)) {
        // 实际上没点到任何内容
        off = -1;
    }

    ITouchableSpan[] link = spannable.getSpans(off, off, ITouchableSpan.class);
    ITouchableSpan touchedSpan = null;
    if (link.length > 0) {
        touchedSpan = link[0];
    }
    return touchedSpan;
}
项目:GitHub    文件:MyURLSpan.java   
/**
 * @param context
 * @param spannable
 * @param title
 * @return
 */
public static SpannableStringBuilder getText(Activity context, Spannable spannable, String title) {
    if (spannable == null || spannable.length() <= 0) {
        Log.e(TAG, "getText  spannable == null || spannable.length() <= 0 >> return new SpannableStringBuilder();");
        return new SpannableStringBuilder();
    }

    SpannableStringBuilder builder = new SpannableStringBuilder(spannable);
    builder.clearSpans();// should clear old spans
    URLSpan[] urls = spannable.getSpans(0, spannable.length(), URLSpan.class);
    if (urls != null) {
        for (URLSpan urlSpan : urls) {
            if (urlSpan != null) {
                MyURLSpan myURLSpan = new MyURLSpan(context, urlSpan.getURL(), title);
                builder.setSpan(myURLSpan, spannable.getSpanStart(urlSpan), spannable
                        .getSpanEnd(urlSpan), Spannable.SPAN_EXCLUSIVE_INCLUSIVE);
            }
        }
    }

    return builder;
}
项目:GitHub    文件:BookMarkAdapter.java   
@Override
public void convert(EasyLVHolder holder, int position, BookMark item) {
    TextView tv = holder.getView(R.id.tvMarkItem);

    SpannableString spanText = new SpannableString((position + 1) + ". " + item.title + ": ");
    spanText.setSpan(new ForegroundColorSpan(ContextCompat.getColor(mContext, R.color.light_coffee)),
            0, spanText.length(), Spannable.SPAN_INCLUSIVE_EXCLUSIVE);

    tv.setText(spanText);

    if (item.desc != null) {
        tv.append(item.desc
                .replaceAll(" ", "")
                .replaceAll(" ", "")
                .replaceAll("\n", ""));
    }

}
项目:okwallet    文件:WalletUtils.java   
public static Editable formatHash(@Nullable final String prefix, final String address, final int groupSize,
        final int lineSize, final char groupSeparator) {
    final SpannableStringBuilder builder = prefix != null ? new SpannableStringBuilder(prefix)
            : new SpannableStringBuilder();

    final int len = address.length();
    for (int i = 0; i < len; i += groupSize) {
        final int end = i + groupSize;
        final String part = address.substring(i, end < len ? end : len);

        builder.append(part);
        builder.setSpan(new TypefaceSpan("monospace"), builder.length() - part.length(), builder.length(),
                Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        if (end < len) {
            final boolean endOfLine = lineSize > 0 && end % lineSize == 0;
            builder.append(endOfLine ? '\n' : groupSeparator);
        }
    }

    return builder;
}
项目:boohee_v5.6    文件:LinkUtils.java   
public boolean onTouchEvent(TextView widget, Spannable buffer, MotionEvent event) {
    if (event.getAction() == 1) {
        this.mLinkClicked = false;
        this.mClickedLink = null;
        int x = (((int) event.getX()) - widget.getTotalPaddingLeft()) + widget.getScrollX();
        int y = (((int) event.getY()) - widget.getTotalPaddingTop()) + widget.getScrollY();
        Layout layout = widget.getLayout();
        int off = layout.getOffsetForHorizontal(layout.getLineForVertical(y), (float) x);
        ClickableSpan[] link = (ClickableSpan[]) buffer.getSpans(off, off, ClickableSpan
                .class);
        if (link.length != 0) {
            SensibleUrlSpan span = link[0];
            this.mLinkClicked = span.onClickSpan(widget);
            this.mClickedLink = span.getURL();
            return this.mLinkClicked;
        }
    }
    super.onTouchEvent(widget, buffer, event);
    return false;
}
项目:Slide-RSS    文件:SpoilerRobotoTextView.java   
/**
 * Replaces the blue line produced by <blockquote>s with something more visible
 *
 * @param spannable parsed comment text #fromHtml
 */
private void replaceQuoteSpans(Spannable spannable) {
    QuoteSpan[] quoteSpans = spannable.getSpans(0, spannable.length(), QuoteSpan.class);

    for (QuoteSpan quoteSpan : quoteSpans) {
        final int start = spannable.getSpanStart(quoteSpan);
        final int end = spannable.getSpanEnd(quoteSpan);
        final int flags = spannable.getSpanFlags(quoteSpan);

        spannable.removeSpan(quoteSpan);

        //If the theme is Light or Sepia, use a darker blue; otherwise, use a lighter blue
        final int barColor =
                (SettingValues.currentTheme == 1 || SettingValues.currentTheme == 5)
                        ? ContextCompat.getColor(getContext(), R.color.md_blue_600)
                        : ContextCompat.getColor(getContext(), R.color.md_blue_400);

        final int BAR_WIDTH = 4;
        final int GAP = 5;

        spannable.setSpan(new CustomQuoteSpan(Color.TRANSPARENT, //background color
                        barColor, //bar color
                        BAR_WIDTH, //bar width
                        GAP), //bar + text gap
                start, end, flags);
    }
}
项目:EmoticonGIFKeyboard    文件:EmoticonUtils.java   
/**
 * Replace the system emoticons with the provided custom emoticons drawable. This will find the
 * unicodes with supported emoticons in the provided text and  will replace the emoticons with
 * appropriate images.
 *
 * @param context          instance of caller.
 * @param text             Text to replace
 * @param emoticonProvider {@link EmoticonProvider} for emoticons images
 * @param emoticonSize     Size of the emoticons in dp
 * @return Modified text.
 */
public static void replaceWithImages(@NonNull final Context context,
                                     @NonNull final Spannable text,
                                     @NonNull final EmoticonProvider emoticonProvider,
                                     final int emoticonSize) {

    final EmoticonSpan[] existingSpans = text.getSpans(0, text.length(), EmoticonSpan.class);
    final ArrayList<Integer> existingSpanPositions = new ArrayList<>(existingSpans.length);
    for (EmoticonSpan existingSpan : existingSpans) {
        existingSpanPositions.add(text.getSpanStart(existingSpan));
    }

    //Get location and unicode of all emoticons.
    final List<EmoticonRange> findAllEmojis = findAllEmoticons(context, text, emoticonProvider);

    //Replace all the emoticons with their relatives.
    for (int i = 0; i < findAllEmojis.size(); i++) {
        final EmoticonRange location = findAllEmojis.get(i);
        if (!existingSpanPositions.contains(location.mStartPos)) {
            text.setSpan(new EmoticonSpan(context, location.mEmoticon.getIcon(), emoticonSize),
                    location.mStartPos,
                    location.mEndPos,
                    Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        }
    }
}
项目:IslamicLibraryAndroid    文件:SearchResult.java   
public CharSequence getformatedSearchSnippet() {
    //TODO implement improved snippet function
    String CleanedSearchString = " " + ArabicUtilities.cleanTextForSearchingWthStingBuilder(searchString) + " ";
    StringBuilder cleanedUnformattedPage = new StringBuilder(ArabicUtilities.cleanTextForSearchingWthStingBuilder(unformatedPage));
    int firstMatchStart = cleanedUnformattedPage.indexOf(CleanedSearchString);
    cleanedUnformattedPage.delete(0, Math.max(firstMatchStart - 100, 0));
    cleanedUnformattedPage.delete(
            Math.min(firstMatchStart + CleanedSearchString.length() + 100, cleanedUnformattedPage.length())
            , cleanedUnformattedPage.length());
    cleanedUnformattedPage.insert(0, "...");
    cleanedUnformattedPage.append("...");

    Spannable snippet = SpannableString.
            valueOf(cleanedUnformattedPage.toString());
    int index = TextUtils.indexOf(snippet, CleanedSearchString);
    while (index >= 0) {

        snippet.setSpan(new BackgroundColorSpan(0xFF8B008B), index, index
                + CleanedSearchString.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        index = TextUtils.indexOf(snippet, CleanedSearchString, index + CleanedSearchString.length());
    }

    return snippet;
}
项目:ultrasonic    文件:SelectPlaylistActivity.java   
private void displayPlaylistInfo(final Playlist playlist)
{
    final TextView textView = new TextView(this);
    textView.setPadding(5, 5, 5, 5);

    final Spannable message = new SpannableString("Owner: " + playlist.getOwner() + "\nComments: " +
            ((playlist.getComment() == null) ? "" : playlist.getComment()) +
            "\nSong Count: " + playlist.getSongCount() +
            ((playlist.getPublic() == null) ? "" : ("\nPublic: " + playlist.getPublic()) + ((playlist.getCreated() == null) ? "" : ("\nCreation Date: " + playlist.getCreated().replace('T', ' ')))));

    Linkify.addLinks(message, Linkify.WEB_URLS);
    textView.setText(message);
    textView.setMovementMethod(LinkMovementMethod.getInstance());

    new AlertDialog.Builder(this).setTitle(playlist.getName()).setCancelable(true).setIcon(android.R.drawable.ic_dialog_info).setView(textView).show();
}
项目:markor    文件:Highlighter.java   
/**
 * Create Span for matches in paragraph's. Note that this will highlight the full matched pattern
 * (including optionals) if no group parameters are given.
 *
 * @param editable      Text editable
 * @param pattern       The pattern to match
 * @param creator       A ParcelableSpanCreator for ParcelableSpan
 * @param groupsToMatch (optional) groups to be matched, indexes start at 1.
 */
protected void createSpanForMatchesP(final Editable editable, final Pattern pattern, final ParagraphStyleCreator creator, int... groupsToMatch) {
    if (groupsToMatch == null || groupsToMatch.length < 1) {
        groupsToMatch = new int[]{0};
    }
    int i = 0;
    for (Matcher m = pattern.matcher(editable); m.find(); i++) {
        ParagraphStyle span = creator.create(m, i);
        if (span != null) {
            for (int g : groupsToMatch) {
                if (g == 0 || g <= m.groupCount()) {
                    editable.setSpan(span, m.start(g), m.end(g), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
                }
            }
        }
    }
}
项目:revolution-irc    文件:SpannableStringHelper.java   
public static void setAndMergeSpans(Spannable text, Object what, int start, int end, int flags) {
    Object[] spans = text.getSpans(Math.max(start - 1, 0), Math.min(end + 1, 0), what.getClass());
    for (Object span : spans) {
        if (!areSpansEqual(span, what))
            continue;
        int sFlags = text.getSpanFlags(span);
        if ((sFlags & Spanned.SPAN_COMPOSING) != 0)
            continue;

        int sStart = text.getSpanStart(span);
        int sEnd = text.getSpanEnd(span);
        if (sEnd < start || sStart > end)
            continue;
        text.removeSpan(span);
        if (sStart < start)
            start = sStart;
        if (sEnd > end)
            end = sEnd;
    }
    text.setSpan(what, start, end, flags);
}
项目:qmui    文件:QMUILinkify.java   
private static void gatherPhoneLinks(ArrayList<LinkSpec> links,
                                     Spannable s, Pattern pattern, Pattern[] excepts, String[] schemes,
                                     MatchFilter matchFilter, TransformFilter transformFilter) {
    Matcher m = pattern.matcher(s);

    while (m.find()) {
        if (isInExcepts(m.group(), excepts)) {
            continue;
        }

        int start = m.start();
        int end = m.end();

        if (matchFilter == null || matchFilter.acceptMatch(s, start, end)) {
            LinkSpec spec = new LinkSpec();
            String url = makeUrl(m.group(0), schemes, m, transformFilter);

            spec.url = url;
            spec.start = start;
            spec.end = end;

            links.add(spec);
        }
    }
}
项目:GifEmoticon    文件:EmoticonUtils.java   
static void replaceWithImages(@NonNull final Context context,
                              @NonNull final Spannable text,
                              @NonNull final EmoticonProvider emoticonProvider,
                              final int emoticonSize) {

    final EmoticonSpan[] existingSpans = text.getSpans(0, text.length(), EmoticonSpan.class);
    final ArrayList<Integer> existingSpanPositions = new ArrayList<>(existingSpans.length);
    for (EmoticonSpan existingSpan : existingSpans) {
        existingSpanPositions.add(text.getSpanStart(existingSpan));
    }

    final List<EmoticonRange> findAllEmojis = findAllEmoticons(text, emoticonProvider);

    for (int i = 0; i < findAllEmojis.size(); i++) {
        final EmoticonRange location = findAllEmojis.get(i);
        if (!existingSpanPositions.contains(location.mStartPos)) {
            text.setSpan(EmoticonSpan.create(context, location.mEmoticon.getIcon(), emoticonSize),
                    location.mStartPos,
                    location.mEndPos,
                    Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        }
    }
}
项目:ShangHanLun    文件:ShowFragment.java   
public SpannableStringBuilder spannerbleTitleForHeaderInSection(
        ATableView tableView, int section) {
    HH2SectionData sd = data.get(section);
    String text = sd.getHeader();
    SpannableStringBuilder builder = new SpannableStringBuilder(text);
    builder.setSpan(new ForegroundColorSpan(Color.BLUE), 0,
            text.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
    if (text.contains("$")) {
        int index = text.indexOf("$") + 1;
        builder.setSpan(new ForegroundColorSpan(Color.RED), index,
                text.length(),
                SpannableStringBuilder.SPAN_EXCLUSIVE_EXCLUSIVE);
        builder.setSpan(new RelativeSizeSpan(0.55f), index,
                text.length(),
                SpannableStringBuilder.SPAN_EXCLUSIVE_EXCLUSIVE);
        builder.replace(index - 1, index, "\n");
    }

    return builder;
}
项目:Sega    文件:SearchAdapter.java   
@Override
public void onBindViewHolder(ResultViewHolder viewHolder, int position) {
    SearchItem item = mResultList.get(position);

    viewHolder.icon_left.setImageResource(item.get_icon());
    viewHolder.icon_left.setColorFilter(SearchView.getIconColor(), PorterDuff.Mode.SRC_IN);
    viewHolder.text.setTypeface((Typeface.create(SearchView.getTextFont(), SearchView.getTextStyle())));
    viewHolder.text.setTextColor(SearchView.getTextColor());

    String itemText = item.get_text().toString();
    String itemTextLower = itemText.toLowerCase(Locale.getDefault());

    if (itemTextLower.contains(key) && !key.isEmpty()) {
        SpannableString s = new SpannableString(itemText);
        s.setSpan(new ForegroundColorSpan(SearchView.getTextHighlightColor()), itemTextLower.indexOf(key), itemTextLower.indexOf(key) + key.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        viewHolder.text.setText(s, TextView.BufferType.SPANNABLE);
    } else {
        viewHolder.text.setText(item.get_text());
    }
}
项目:MultiContactPicker    文件:MultiContactPickerAdapter.java   
private void highlightTerm(TextView tv, String query, String originalString){
    if (query != null && !query.isEmpty()) {
        int startPos = originalString.toLowerCase().indexOf(query.toLowerCase());
        int endPos = startPos + query.length();
        if (startPos != -1) {
            Spannable spannable = new SpannableString(originalString);
            ColorStateList blackColor = new ColorStateList(new int[][]{new int[]{}}, new int[]{Color.BLACK});
            TextAppearanceSpan highlightSpan = new TextAppearanceSpan(null, Typeface.BOLD, -1, blackColor, null);
            spannable.setSpan(highlightSpan, startPos, endPos, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
            tv.setText(spannable);
        } else {
            tv.setText(originalString);
        }
    } else {
        tv.setText(originalString);
    }
}
项目:xwallet    文件:WalletUtils.java   
public static Editable formatHash(@Nullable final String prefix, final String address, final int groupSize,
                                  final int lineSize, final char groupSeparator) {
    final SpannableStringBuilder builder = prefix != null ? new SpannableStringBuilder(prefix)
            : new SpannableStringBuilder();

    final int len = address.length();
    for (int i = 0; i < len; i += groupSize) {
        final int end = i + groupSize;
        final String part = address.substring(i, end < len ? end : len);

        builder.append(part);
        builder.setSpan(new TypefaceSpan("monospace"), builder.length() - part.length(), builder.length(),
                Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        if (end < len) {
            final boolean endOfLine = lineSize > 0 && end % lineSize == 0;
            builder.append(endOfLine ? '\n' : groupSeparator);
        }
    }

    return builder;
}
项目:Demos    文件:TouchLinkMovementMethod.java   
@Override
public boolean onTouchEvent(TextView widget, Spannable buffer, MotionEvent event) {
    int action = event.getAction();

    if (action == MotionEvent.ACTION_DOWN) {
        int x = (int) event.getX();
        int y = (int) event.getY();

        x -= widget.getTotalPaddingLeft();
        y -= widget.getTotalPaddingTop();
        x += widget.getScrollX();
        y += widget.getScrollY();

        Layout layout = widget.getLayout();
        int line = layout.getLineForVertical(y);
        int off = layout.getOffsetForHorizontal(line, x);

        ClickableSpan[] link = buffer.getSpans(off, off, ClickableSpan.class);
        if (link.length != 0) {
            link[0].onClick(widget);
            return true;
        } else {
            Selection.removeSelection(buffer);
        }
    }

    return super.onTouchEvent(widget, buffer, event);
}
项目:minion-android    文件:IniSyntaxHighlighter.java   
private void applySpan(Spannable spannable, @ColorInt int color, int start, int end) {
    spannable.setSpan(
            new ForegroundColorSpan(color),
            start,
            end,
            Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
}
项目:sealtalk-android-master    文件:TestMessageProvider.java   
@Override
public Spannable getContentSummary(TestMessage data) {
    if (data == null)
        return null;

    String content = data.getContent();
    if (content != null) {
        if (content.length() > 100) {
            content = content.substring(0, 100);
        }
        return new SpannableString(AndroidEmoji.ensure(content));
    }
    return null;
}
项目:SimpleDialogFragments    文件:AdvancedAdapter.java   
/**
 * Highlights everything that matched the current filter (if any) in text
 *
 * @param text the text to highlight
 * @param context a context to get the default highlight color from
 * @return a spannable string
 */
protected Spannable highlight(String text, Context context) {
    if (mDefaultHighlightColor == null){
        TypedArray array = context.obtainStyledAttributes(new int[]{
                android.R.attr.textColorHighlight});
        mDefaultHighlightColor = array.getColor(0, 0x6633B5E5);
        array.recycle();
    }
    return highlight(text, mDefaultHighlightColor);
}
项目:KingTV    文件:ChatFragment.java   
@Override
public void initUI() {


    SpannableStringBuilder ssb = new SpannableStringBuilder();
    //系统通知图片
    ImageSpan imageSpan = new ImageSpan(context,R.drawable.img_dm_xttz);
    SpannableString spannableString = new SpannableString("tips");
    spannableString.setSpan(imageSpan,0,spannableString.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
    ssb.append(spannableString);
    //系统通知内容
    ssb.append(getText(R.string.tips_notice_desc));
    tvTips.setText(ssb);
}
项目:q-mail    文件:ICalendarHelper.java   
@VisibleForTesting
static CharSequence toFriendly(Organizer organizer, Contacts contacts,
                               boolean showCorrespondentNames,
                               boolean changeContactNameColor,
                               int contactNameColor) {
    if (organizer == null) {
        return null;
    }
    if (!showCorrespondentNames) {
        return organizer.getEmail();
    } else if (contacts != null) {
        final String name = contacts.getNameForAddress(organizer.getEmail());
        // TODO: The results should probably be cached for performance reasons.
        if (name != null) {
            if (changeContactNameColor) {
                final SpannableString coloredName = new SpannableString(name);
                coloredName.setSpan(new ForegroundColorSpan(contactNameColor),
                        0,
                        coloredName.length(),
                        Spannable.SPAN_EXCLUSIVE_EXCLUSIVE
                );
                return coloredName;
            } else {
                return name;
            }
        }
    }

    return (!TextUtils.isEmpty(organizer.getCommonName())) ? organizer.getCommonName() : organizer.getEmail();
}
项目:GCSApp    文件:EaseSmileUtils.java   
/**
 * replace existing spannable with smiles
 * @param context
 * @param spannable
 * @return
 */
public static boolean addSmiles(Context context, Spannable spannable) {
    boolean hasChanges = false;
    for (Entry<Pattern, Object> entry : emoticons.entrySet()) {
        Matcher matcher = entry.getKey().matcher(spannable);
        while (matcher.find()) {
            boolean set = true;
            for (ImageSpan span : spannable.getSpans(matcher.start(),
                    matcher.end(), ImageSpan.class))
                if (spannable.getSpanStart(span) >= matcher.start()
                        && spannable.getSpanEnd(span) <= matcher.end())
                    spannable.removeSpan(span);
                else {
                    set = false;
                    break;
                }
            if (set) {
                hasChanges = true;
                Object value = entry.getValue();
                if(value instanceof String && !((String) value).startsWith("http")){
                    File file = new File((String) value);
                    if(!file.exists() || file.isDirectory()){
                        return false;
                    }
                    spannable.setSpan(new ImageSpan(context, Uri.fromFile(file)),
                            matcher.start(), matcher.end(),
                            Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
                }else{
                    spannable.setSpan(new ImageSpan(context, (Integer)value),
                            matcher.start(), matcher.end(),
                            Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
                }
            }
        }
    }

    return hasChanges;
}
项目:UltimateRecyclerView    文件:StickyAdapter.java   
private void setData(SuperViewHolder holder, StockEntity.StockInfo item) {
    final String stockNameAndCode = item.stock_name + "\n" + item.stock_code;
    SpannableStringBuilder ssb = new SpannableStringBuilder(stockNameAndCode);
    ssb.setSpan(new ForegroundColorSpan(Color.parseColor("#a4a4a7")), item.stock_name.length(), stockNameAndCode.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
    ssb.setSpan(new AbsoluteSizeSpan(dip2px(holder.itemView.getContext(), 13)), item.stock_name.length(), stockNameAndCode.length(),
            Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);

    ((TextView) holder.getView(R.id.tv_stock_name_code)).setText(ssb);
    ((TextView) holder.getView(R.id.tv_current_price)).setText(item.current_price);
    ((TextView) holder.getView(R.id.tv_rate)).setText(item.rate < 0 ? String.format("%.2f", item.rate) : ("+" + String.format("%.2f", item.rate)) + "%");
}
项目:chromium-for-android-56-debug-video    文件:AnswerTextBuilder.java   
/**
 * Append the styled text in textField to the supplied builder.
 *
 * @param builder The builder to append the text to.
 * @param textField The text field (with text and type) to append.
 * @param maxTextHeightSp The height in SP of the largest text field in the entire line. Used to
 *                        top-align text when specified.
 * @param metrics Font metrics which will be used to properly size and layout images and top-
 *                aligned text.
 * @param density Screen density which will be used to properly size and layout images and top-
 *                aligned text.
*/
private static void appendAndStyleText(
        SpannableStringBuilder builder, SuggestionAnswer.TextField textField,
        int maxTextHeightSp, Paint.FontMetrics metrics, float density) {
    String text = textField.getText();
    int type = textField.getType();

    // Unescape HTML entities (e.g. "&quot;", "&gt;").
    text = Html.fromHtml(text).toString();

    // Append as HTML (answer responses contain simple markup).
    int start = builder.length();
    builder.append(Html.fromHtml(text));
    int end = builder.length();

    // Apply styles according to the type.
    AbsoluteSizeSpan sizeSpan = new AbsoluteSizeSpan(getAnswerTextSizeSp(type), true);
    builder.setSpan(sizeSpan, start, end, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);

    ForegroundColorSpan colorSpan = new ForegroundColorSpan(getAnswerTextColor(type));
    builder.setSpan(colorSpan, start, end, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);

    if (type == ANSWERS_TOP_ALIGNED_TEXT_TYPE) {
        TopAlignedSpan topAlignedSpan =
                new TopAlignedSpan(
                        ANSWERS_TOP_ALIGNED_TEXT_SIZE_SP, maxTextHeightSp, metrics, density);
        builder.setSpan(topAlignedSpan, start, end, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
    }
}
项目:ShangHanLun    文件:FangFragment.java   
public SpannableStringBuilder spannerbleTitleForHeaderInSection(
        ATableView tableView, int section) {
    SpannableStringBuilder builder = super
            .spannerbleTitleForHeaderInSection(tableView, section);
    SpannableString append = new SpannableString(String.format(
            "   凡%d方", data.get(section).getData().size()));
    append.setSpan(new ForegroundColorSpan(Color.BLUE), 0,
            append.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
    builder.append(append);
    return builder;
}
项目:GCSApp    文件:EaseChatRowRecSendMoney.java   
@Override
public void onSetUpView() {
    EMTextMessageBody txtBody = (EMTextMessageBody) message.getBody();
    Spannable span = EaseSmileUtils.getSmiledText(context, txtBody.getMessage());
    String money = message.getStringAttribute("transferMoney ", "");
    // 设置内容
    if (StringUtils.isNotEmpty(money)) {
        contentView.setText(money);
    } else {
        contentView.setText("0.0");
    }

    handleTextMessage();
}
项目:Veggietizer    文件:Utility.java   
/**
 * Sets the action bar title using the specified font.
 *
 * @param font The font to use.
 * @param title The title to set.
 */
@SuppressWarnings("SameParameterValue")
public static void styleActionBar(ActionBar actionBar, FontManager.Font font, String title) {
    SpannableString actionBarTitle = new SpannableString(title);

    // ActionBar font
    actionBarTitle.setSpan(new TypefaceSpan(font),
            0, actionBarTitle.length(),
            Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
    actionBar.setTitle(actionBarTitle);
}
项目:ShangHanLun    文件:Helper.java   
public static void renderItemNumber(SpannableStringBuilder builder) {
    String string = builder.toString();
    if (!string.contains("、")
            || !isNumeric(string.substring(0, string.indexOf("、")))) {
        return;
    }
    ForegroundColorSpan numSpan = new ForegroundColorSpan(Color.BLUE);
    builder.setSpan(numSpan, 0, string.indexOf("、"),
            Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
}
项目:AndroidSnooper    文件:HttpCallFragment.java   
@Override
public void removeOldHighlightedSpans() {
  Spannable spannableString = (Spannable) payloadTextView.getText();
  BackgroundColorSpan[] backgroundSpans = spannableString.getSpans(0, spannableString.length(), BackgroundColorSpan.class);
  for (BackgroundColorSpan span : backgroundSpans) {
    spannableString.removeSpan(span);
  }
}
项目:QMark    文件:EditSourceListAdapter.java   
@Override
public void bind(int position, EditSourceListBean data) {
    mFB.display(mImgBg, data.imgBgUrl);
    mFB.display(mImgCatgy, data.ImgCatgyUrl);
    mTextLeft.setText(data.textLeft);
    Resources resources = getView().getResources();
    SpannableStringBuilder spans = new SpannableStringBuilder(resources.getString(R.string.i_m_category_text_sign_count, data.textSignSize));
    spans.setSpan(new ForegroundColorSpan(resources.getColor(R.color.text_title_orange)), 0, 2, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
    spans.setSpan(new ForegroundColorSpan(resources.getColor(R.color.text_title_orange)), spans.length() - 3, spans.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
    mTextSignSize.setText(spans);
}
项目:Phoenix-for-VK    文件:FeedbackViewBinder.java   
/**
 * Настройка отображения уведомления типа "reply_topic"
 *
 * @param notification уведомление
 * @param holder       контейнер в елементами интерфейса
 */
public void configReplyTopicFeedback(ReplyCommentFeedback notification, FeedbackAdapter.CommentHolder holder) {
    Topic topic = (Topic) notification.getCommentsOf();

    Comment feedback = notification.getFeedbackComment();

    Spannable feedBackText = OwnerLinkSpanFactory.withSpans(feedback.getText(), true, true, mLinkActionAdapter);

    holder.cOwnerText.setText(feedBackText);
    holder.cOwnerText.setVisibility(TextUtils.isEmpty(feedBackText) ? View.GONE : View.VISIBLE);
    AttachmentsHolder containers = AttachmentsHolder.forFeedback(holder.vAttachmentsRoot);
    attachmentsViewBinder.displayAttachments(feedback.getAttachments(), containers, true);

    String action = getDateFromUnixTime(feedback.getDate());
    action = action + SPACE + context.getString(R.string.in_reply_to_your_message_in_topic);

    Link parentLink = Link.startOf(action.length());
    action = action + SPACE + topic.getTitle();
    parentLink.end(action.length());

    Spannable spannable = Spannable.Factory.getInstance().newSpannable(action);
    showAsLink(spannable, parentLink);

    holder.cOwnerName.setText(feedback.getFullAuthorName());
    holder.cOwnerTime.setText(spannable, TextView.BufferType.SPANNABLE);

    holder.cChangable.setVisibility(View.GONE);
    PicassoInstance.with()
            .load(feedback.getMaxAuthorAvaUrl())
            .tag(Constants.PICASSO_TAG)
            .transform(transformation)
            .into(holder.cOwnerAvatar);

    holder.ivRightAttachment.setVisibility(View.GONE);
    solveOwnerOpenByAvatar(holder.cOwnerAvatar, feedback.getFromId());

    configReply(notification.getReply(), holder);
}
项目:Phoenix-for-VK    文件:FeedbackViewBinder.java   
/**
 * Настройка отображения уведомления типа "reply_comment_photo"
 *
 * @param notification уведомление
 * @param holder       контейнер в елементами интерфейса
 */
public void configReplyCommentPhotoFeedback(ReplyCommentFeedback notification, FeedbackAdapter.CommentHolder holder) {
    Comment parent = notification.getOwnComment();
    Comment feedback = notification.getFeedbackComment();

    setupAttachmentViewWithPhoto((Photo) notification.getCommentsOf(), holder.ivRightAttachment);

    String feedBackText = OwnerLinkSpanFactory.getTextWithCollapseOwnerLinks(feedback.getText());

    String action = getDateFromUnixTime(feedback.getDate());
    action = action + SPACE + context.getString(R.string.in_reply_to_your_comment);

    String parentText;
    if (TextUtils.isEmpty(parent.getText())) {
        parentText = context.getString(R.string.from_date, getDateFromUnixTime(parent.getDate()));
    } else {
        parentText = reduce(OwnerLinkSpanFactory.getTextWithCollapseOwnerLinks(parent.getText()));
    }

    Link parentLink = Link.startOf(action.length());
    action = action + SPACE + parentText;
    parentLink.end(action.length());

    Spannable spannable = Spannable.Factory.getInstance().newSpannable(action);
    showAsLink(spannable, parentLink);

    holder.cOwnerName.setText(feedback.getFullAuthorName());
    holder.cOwnerText.setText(feedBackText);
    holder.cOwnerText.setVisibility(TextUtils.isEmpty(feedBackText) ? View.GONE : View.VISIBLE);
    holder.cOwnerTime.setText(spannable, TextView.BufferType.SPANNABLE);
    holder.cChangable.setVisibility(View.GONE);
    AttachmentsHolder containers = AttachmentsHolder.forFeedback(holder.vAttachmentsRoot);
    attachmentsViewBinder.displayAttachments(feedback.getAttachments(), containers, true);

    showUserAvatarOnImageView(feedback.getMaxAuthorAvaUrl(), holder.cOwnerAvatar);
    solveOwnerOpenByAvatar(holder.cOwnerAvatar, feedback.getFromId());

    configReply(notification.getReply(), holder);
}
项目:javaide    文件:XmlCommentHighlighter.java   
@Override
public void highlight(@NonNull Editable allText, @NonNull CharSequence textToHighlight, int start) {
    mCommentRegion.clear();
    for (Matcher m = XML_COMMENTS.matcher(textToHighlight); m.find(); ) {
        allText.setSpan(new ForegroundColorSpan(codeTheme.getCommentColor()),
                start + m.start(),
                start + m.end(),
                Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        mCommentRegion.add(new Pair<>(start + m.start(), start + m.end()));
    }
}
项目:Espresso    文件:CompanyDetailFragment.java   
@Override
public void setCompanyTel(String tel) {
    this.tel = tel;
    String companyTel = getString(R.string.phone_number) + "\n" + tel;
    Spannable spannable = new SpannableStringBuilder(companyTel);
    spannable.setSpan(new StyleSpan(Typeface.BOLD), 0, companyTel.length() - tel.length() - 1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
    spannable.setSpan(new URLSpan(tel), companyTel.length() - tel.length(), companyTel.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
    textViewTel.setText(spannable);
}