Java 类android.text.SpannableStringBuilder 实例源码

项目:SciChart.Android.Examples    文件:CustomTooltipsWithModifiersFragment.java   
@Override
protected void internalUpdate(XySeriesInfo seriesInfo) {
    final SpannableStringBuilder sb = new SpannableStringBuilder();

    sb.append("X: ").append(seriesInfo.getFormattedXValue()).append(StringUtil.NEW_LINE);
    sb.append("Y: ").append(seriesInfo.getFormattedYValue()).append(StringUtil.NEW_LINE);

    if (seriesInfo.seriesName != null) {
        final int start = sb.length();

        sb.append(seriesInfo.seriesName);
        sb.setSpan(new ForegroundColorSpan(ColorUtil.White), start, sb.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        sb.append(StringUtil.NEW_LINE);
    }
    sb.append(modifierName);
    setText(sb);

    // stroke 0xff4d81dd
    setSeriesColor(0xff6495ed);
}
项目:q-mail    文件:NotificationContentCreator.java   
private CharSequence getMessagePreview(LocalMessage message) {
    String subject = message.getSubject();
    String snippet = getPreview(message);

    boolean isSubjectEmpty = TextUtils.isEmpty(subject);
    boolean isSnippetPresent = snippet != null;
    if (isSubjectEmpty && isSnippetPresent) {
        return snippet;
    }

    String displaySubject = getMessageSubject(message);

    SpannableStringBuilder preview = new SpannableStringBuilder();
    preview.append(displaySubject);
    if (isSnippetPresent) {
        preview.append('\n');
        preview.append(snippet);
    }

    return preview;
}
项目:mongol-library    文件:MongolTextView.java   
public MongolTextView(Context context, AttributeSet attrs, int defStyleAttr) {
    super(context, attrs, defStyleAttr);

    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.MongolTextView, defStyleAttr, 0);

    boolean isEditText = getDefaultEditable();
    String text = a.getString(R.styleable.MongolTextView_text);
    if (text == null) text = "";
    if (isEditText) {
        SpannableStringBuilder ssb = new SpannableStringBuilder(text);
        mTextStorage = new MongolTextStorage(ssb);
    } else {
        mTextStorage = new MongolTextStorage(text);
    }
    mTextSizePx = a.getDimensionPixelSize(R.styleable.MongolTextView_textSize, 0);
    mTextColor = a.getColor(R.styleable.MongolTextView_textColor, Color.BLACK);
    mGravity = a.getInteger(R.styleable.MongolTextView_gravity, Gravity.TOP);
    a.recycle();

    mContext = context;
    init();
}
项目:Cable-Android    文件:SingleRecipientNotificationBuilder.java   
public void setPrimaryMessageBody(@NonNull  Recipients threadRecipients,
                                  @NonNull  Recipient individualRecipient,
                                  @NonNull  CharSequence message,
                                  @Nullable SlideDeck slideDeck)
{
  SpannableStringBuilder stringBuilder = new SpannableStringBuilder();

  if (privacy.isDisplayContact() && (threadRecipients.isGroupRecipient() || !threadRecipients.isSingleRecipient())) {
    stringBuilder.append(Util.getBoldedString(individualRecipient.toShortString() + ": "));
  }

  if (privacy.isDisplayMessage()) {
    setContentText(stringBuilder.append(message));
    this.slideDeck = slideDeck;
  } else {
    setContentText(stringBuilder.append(context.getString(R.string.SingleRecipientNotificationBuilder_new_message)));
  }
}
项目:SDHtmlTextView    文件:ImageHandler.java   
@Override
public void handleTagNode(TagNode node, SpannableStringBuilder builder,
        int start, int end, SpanStack stack) {
    String src = node.getAttributeByName("src");

    builder.append("\uFFFC");

    Bitmap bitmap = loadBitmap(src);

    if (bitmap != null) {
        Drawable drawable = new BitmapDrawable(bitmap);
        drawable.setBounds(0, 0, bitmap.getWidth() - 1,
                bitmap.getHeight() - 1);

           stack.pushSpan( new ImageSpan(drawable), start, builder.length() );
    }
}
项目:LiveGiftLayout    文件:ExpressionUtil.java   
public void setView(Context mContext, final View view, String content) {
    if (view != null && view instanceof ImageView) {//图片不显示GIF
        Bitmap bitmap = null;
        try {
            bitmap = BitmapFactory.decodeStream(mContext.getAssets().open(content));
        } catch (IOException e1) {
            e1.printStackTrace();
        }
        ((ImageView) view).setImageBitmap(bitmap);
    } else if (view != null && view instanceof TextView) {//文字可显示GIF
        TextView gifTextView = (TextView) view;
        String tempText = "[" + content + "]";
        SpannableStringBuilder sb = prase(mContext, gifTextView, tempText);
        gifTextView.setText(sb);
    }

}
项目:Nird2    文件:UiUtils.java   
public static SpannableStringBuilder getTeaser(Context ctx, Spanned body) {
    if (body.length() < TEASER_LENGTH)
        throw new IllegalArgumentException(
                "String is shorter than TEASER_LENGTH");

    SpannableStringBuilder builder =
            new SpannableStringBuilder(body.subSequence(0, TEASER_LENGTH));
    String ellipsis = ctx.getString(R.string.ellipsis);
    builder.append(ellipsis).append(" ");

    Spannable readMore = new SpannableString(
            ctx.getString(R.string.read_more) + ellipsis);
    ForegroundColorSpan fg = new ForegroundColorSpan(
            ContextCompat.getColor(ctx, R.color.briar_text_link));
    readMore.setSpan(fg, 0, readMore.length(),
            Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
    builder.append(readMore);

    return builder;
}
项目:RLibrary    文件:RExTextView.java   
/**
 * 匹配 电话号码
 */
protected void patternPhone(SpannableStringBuilder builder, CharSequence input) {
    Matcher matcher = patternPhone.matcher(input);

    while (matcher.find()) {
        int start = matcher.start();
        int end = matcher.end();

        if (!isInOtherSpan(builder, input.length(), start, end)) {
            builder.setSpan(new ImageTextSpan(getContext(), ImageTextSpan.initDrawable(getTextSize()),
                            matcher.group(), matcher.group())
                            .setOnImageSpanClick(mOnImageSpanClick)
                            .setTextColor(mImageSpanTextColor),
                    start, end, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        }
    }
}
项目:PSNine    文件:JellyBeanSpanFixTextView.java   
/**
 * Add spaces around spans until the text is fixed, and then removes the unneeded spaces
 */
private void fixSpannedWithSpaces(SpannableStringBuilder builder, int widthMeasureSpec,
                                  int heightMeasureSpec) {
    long startFix = System.currentTimeMillis();

    FixingResult result = addSpacesAroundSpansUntilFixed(builder, widthMeasureSpec,
            heightMeasureSpec);

    if (result.fixed) {
        removeUnneededSpaces(widthMeasureSpec, heightMeasureSpec, builder, result);
    } else {
        fallbackToString(widthMeasureSpec, heightMeasureSpec);
    }

    if (HtmlTextView.DEBUG) {
        long fixDuration = System.currentTimeMillis() - startFix;
        Log.d(HtmlTextView.TAG, "fixSpannedWithSpaces() duration in ms: " + fixDuration);
    }
}
项目:RLibrary    文件:RExTextView.java   
@Override
public void setText(CharSequence text, BufferType type) {
    if (isInEditMode()) {
        super.setText(text, type);
        return;
    }
    if (TextUtils.isEmpty(text)) {
        super.setText(text, type);
    } else {
        SpannableStringBuilder spanBuilder = new SpannableStringBuilder(text);
        if (needPatternUrl) {
            patternUrl(spanBuilder, text);//优先匹配
        }
        if (needPatternMention) {
            patternMention(spanBuilder, text);
        }
        if (needPatternPhone) {
            patternPhone(spanBuilder, text);
        }
        afterPattern(spanBuilder, text);
        super.setText(spanBuilder, type);
    }
}
项目:FastTextView    文件:EllipseFragment.java   
@Override
  public View onCreateView(LayoutInflater inflater, ViewGroup container,
                           Bundle savedInstanceState) {
    if (mRootView != null) {
      return mRootView;
    }
    mRootView = inflater.inflate(R.layout.ellipse_demo, container, false);
    SpannableStringBuilder spannableStringBuilder = getSpannable();
    FastTextView fastTextView = (FastTextView) mRootView.findViewById(R.id.fast_tv2);
    fastTextView.setText(spannableStringBuilder);
//    fastTextView.setCustomEllipsisSpan(new ImageSpan(drawable));

    TextView tv = (TextView) mRootView.findViewById(R.id.system_tv);
    tv.setText(spannableStringBuilder);
//    tv.setMovementMethod(LinkMovementMethod.getInstance());


    return mRootView;
  }
项目:okwallet    文件:RequestCoinsFragment.java   
private void updateView() {
    if (!isResumed())
        return;

    final String bitcoinRequest = determineBitcoinRequestStr(true);
    final byte[] paymentRequest = determinePaymentRequest(true);

    // update qr-code
    qrCodeBitmap = new BitmapDrawable(getResources(), Qr.bitmap(bitcoinRequest));
    qrCodeBitmap.setFilterBitmap(false);
    qrView.setImageDrawable(qrCodeBitmap);

    // update initiate request message
    final SpannableStringBuilder initiateText = new SpannableStringBuilder(
            getString(R.string.request_coins_fragment_initiate_request_qr));
    if (nfcAdapter != null && nfcAdapter.isEnabled())
        initiateText.append(' ').append(getString(R.string.request_coins_fragment_initiate_request_nfc));
    initiateRequestView.setText(initiateText);

    // focus linking
    final int activeAmountViewId = amountCalculatorLink.activeTextView().getId();
    acceptBluetoothPaymentView.setNextFocusUpId(activeAmountViewId);

    paymentRequestRef.set(paymentRequest);
}
项目:ShangHanLun    文件:ATableViewAdapter.java   
@Override
public void configurePinnedHeader(View headerView, int position, int alpaha) {
    // TODO Auto-generated method stub
    TextView label = (TextView) headerView.findViewById(R.id.textLabel);
    NSIndexPath ip = getIndexPath(position);
    curSection = ip.getSection();
    String t = mTableView.getDataSource().titleForHeaderInSection(
            mTableView, curSection);
    if (t != null) {
        label.setText(t);
    } else {
        SpannableStringBuilder buider = mTableView.getDataSource()
                .spannerbleTitleForHeaderInSection(mTableView, curSection);
        label.setText(buider);
    }
    // huanghai
    label.setTextColor(Color.BLACK);
    label.setGravity(Gravity.CENTER_VERTICAL);
}
项目:sealtalk-android-master    文件:CharacterParser.java   
public SpannableStringBuilder getColoredChattingRecord(String filterStr, MessageContent messageContent) {
    SpannableStringBuilder messageText = new SpannableStringBuilder();
    if (messageContent instanceof TextMessage) {
        TextMessage textMessage = (TextMessage) messageContent;
        String textMessageContent = textMessage.getContent();
        messageText = getOmitColored(filterStr, textMessageContent, 0);
    }
    if (messageContent instanceof RichContentMessage) {
        RichContentMessage richContentMessage = (RichContentMessage) messageContent;
        String messageTitle = richContentMessage.getTitle();
        messageText = getOmitColored(filterStr, messageTitle, 1);
        if (messageText.length() == 0) {
            SpannableStringBuilder spannableStringBuilder = new SpannableStringBuilder("[链接] ");
            spannableStringBuilder.append(messageTitle);
            messageText = spannableStringBuilder;
        }
    }
    if (messageContent instanceof FileMessage) {
        FileMessage fileMessage = (FileMessage) messageContent;
        String fileName = fileMessage.getName();
        messageText = getOmitColored(filterStr, fileName, 2);
    }
    return messageText;
}
项目:SciChart.Android.Examples    文件:CustomTooltipsWithModifiersFragment.java   
@Override
protected void internalUpdate(XySeriesInfo seriesInfo) {
    final SpannableStringBuilder sb = new SpannableStringBuilder();
    sb.append(modifierName).append(StringUtil.NEW_LINE);

    if (seriesInfo.seriesName != null) {
        sb.append(seriesInfo.seriesName);
        sb.setSpan(new ForegroundColorSpan(ColorUtil.Black), 0, sb.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        sb.append(StringUtil.NEW_LINE);
    }

    sb.append("X: ").append(seriesInfo.getFormattedXValue());
    sb.append(" Y: ").append(seriesInfo.getFormattedYValue());

    setText(sb);

    // stroke 0xffff4500
    setSeriesColor(0xffe2460c);
}
项目:lex    文件:LexList.java   
@NonNull
private CharSequence makeThreeOrMoreItems() {
    if (separator == null) {
        throw new LexNoSeparatorException();
    }

    SpannableStringBuilder sb = new SpannableStringBuilder(getWrappedItem(0));
    for (int i = 1; i < items.length; i++) {
        if (i == items.length - 1 && lastItemSeparator != null) {
            sb.append(lastItemSeparator);
        } else {
            sb.append(separator);
        }
        sb.append(getWrappedItem(i));
    }
    return sb;
}
项目:Phoenix-for-VK    文件:PreferencesFragment.java   
private void disableOnlyFullAppPrefs() {
    String fullOnly = " FULL ONLY ";
    int color = Utils.adjustAlpha(CurrentTheme.getColorAccent(getActivity()), 100);

    for (String name : AppPrefs.ONLY_FULL_APP_PREFS) {
        Preference preference = findPreference(name);
        if (preference != null) {
            preference.setEnabled(false);

            CharSequence summary = TextUtils.isEmpty(preference.getTitle()) ? "" : preference.getTitle();
            summary = fullOnly + " " + summary;

            Spannable spannable = SpannableStringBuilder.valueOf(summary);

            BackgroundColorSpan span = new BackgroundColorSpan(color);
            ForegroundColorSpan span1 = new ForegroundColorSpan(Color.WHITE);

            spannable.setSpan(span, 0, fullOnly.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
            spannable.setSpan(span1, 0, fullOnly.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
            preference.setTitle(spannable);
        }
    }
}
项目:PeSanKita-android    文件:SingleRecipientNotificationBuilder.java   
public void setPrimaryMessageBody(@NonNull  Recipients threadRecipients,
                                  @NonNull  Recipient individualRecipient,
                                  @NonNull  CharSequence message,
                                  @Nullable SlideDeck slideDeck)
{
  SpannableStringBuilder stringBuilder = new SpannableStringBuilder();

  if (privacy.isDisplayContact() && (threadRecipients.isGroupRecipient() || !threadRecipients.isSingleRecipient())) {
    stringBuilder.append(Util.getBoldedString(individualRecipient.toShortString() + ": "));
  }

  if (privacy.isDisplayMessage()) {
    setContentText(stringBuilder.append(message));
    this.slideDeck = slideDeck;
  } else {
    setContentText(stringBuilder.append(context.getString(R.string.SingleRecipientNotificationBuilder_new_message)));
  }
}
项目:PeSanKita-android    文件:SingleRecipientNotificationBuilder.java   
public void addMessageBody(@NonNull Recipients threadRecipients,
                           @NonNull Recipient individualRecipient,
                           @Nullable CharSequence messageBody)
{
  SpannableStringBuilder stringBuilder = new SpannableStringBuilder();

  if (privacy.isDisplayContact() && (threadRecipients.isGroupRecipient() || !threadRecipients.isSingleRecipient())) {
    stringBuilder.append(Util.getBoldedString(individualRecipient.toShortString() + ": "));
  }

  if (privacy.isDisplayMessage()) {
    messageBodies.add(stringBuilder.append(messageBody == null ? "" : messageBody));
  } else {
    messageBodies.add(stringBuilder.append(context.getString(R.string.SingleRecipientNotificationBuilder_new_message)));
  }
}
项目:PeSanKita-android    文件:ComposeText.java   
public void setHint(@NonNull String hint, @Nullable CharSequence subHint) {
  this.hint = new SpannableString(hint);
  this.hint.setSpan(new RelativeSizeSpan(0.8f), 0, hint.length(), Spannable.SPAN_INCLUSIVE_INCLUSIVE);

  if (subHint != null) {
    this.subHint = new SpannableString(subHint);
    this.subHint.setSpan(new RelativeSizeSpan(0.8f), 0, subHint.length(), Spannable.SPAN_INCLUSIVE_INCLUSIVE);
  } else {
    this.subHint = null;
  }

  if (this.subHint != null) {
    super.setHint(new SpannableStringBuilder().append(ellipsizeToWidth(this.hint))
                                              .append("\n")
                                              .append(ellipsizeToWidth(this.subHint)));
  } else {
    super.setHint(ellipsizeToWidth(this.hint));
  }
}
项目:PeSanKita-android    文件:FromTextView.java   
public void setText(Recipients recipients, boolean read) {
  int        attributes[] = new int[]{R.attr.conversation_list_item_count_color};
  TypedArray colors       = getContext().obtainStyledAttributes(attributes);
  String     fromString   = recipients.toShortString();

  int typeface;

  if (!read) {
    typeface = Typeface.BOLD;
  } else {
    typeface = Typeface.NORMAL;
  }

  SpannableStringBuilder builder = new SpannableStringBuilder(fromString);
  builder.setSpan(new StyleSpan(typeface), 0, builder.length(),
                  Spannable.SPAN_INCLUSIVE_EXCLUSIVE);

  colors.recycle();

  setText(builder);

  if      (recipients.isBlocked()) setCompoundDrawablesWithIntrinsicBounds(R.drawable.ic_block_grey600_18dp, 0, 0, 0);
  else if (recipients.isMuted())   setCompoundDrawablesWithIntrinsicBounds(R.drawable.ic_volume_off_grey600_18dp, 0, 0, 0);
  else                             setCompoundDrawablesWithIntrinsicBounds(0, 0, 0, 0);
}
项目:Aequorea    文件:RichText.java   
/**
 * 生成富文本
 *
 * @return Spanned
 */
private CharSequence generateRichText() {
    TextView textView = textViewSoftReference.get();
    if (textView == null) {
        return null;
    }
    if (config.richType != RichType.MARKDOWN) {
        analyzeImages(config.source);
    } else {
        imageHolderMap = new HashMap<>();
    }
    SpannableStringBuilder spannableStringBuilder = null;
    if (config.cacheType > CacheType.NONE) {
        spannableStringBuilder = RichTextPool.getPool().loadCache(config.source);
    }
    if (spannableStringBuilder == null) {
        spannableStringBuilder = parseRichText();
    }
    richText = new SoftReference<>(spannableStringBuilder);
    config.imageGetter.registerImageLoadNotify(this);
    cachedSpannedParser.setAccentColor(getAccentColor(textView.getContext()));
    count = cachedSpannedParser.parse(spannableStringBuilder, this, config);
    return spannableStringBuilder;
}
项目:Cable-Android    文件:FromTextView.java   
public void setText(Recipients recipients, boolean read) {
  int        attributes[] = new int[]{R.attr.conversation_list_item_count_color};
  TypedArray colors       = getContext().obtainStyledAttributes(attributes);
  String     fromString   = recipients.toShortString();

  int typeface;

  if (!read) {
    typeface = Typeface.BOLD;
  } else {
    typeface = Typeface.NORMAL;
  }

  SpannableStringBuilder builder = new SpannableStringBuilder(fromString);
  builder.setSpan(new StyleSpan(typeface), 0, builder.length(),
                  Spannable.SPAN_INCLUSIVE_EXCLUSIVE);

  colors.recycle();

  setText(builder);

  if      (recipients.isBlocked()) setCompoundDrawablesWithIntrinsicBounds(R.drawable.ic_block_grey600_18dp, 0, 0, 0);
  else if (recipients.isMuted())   setCompoundDrawablesWithIntrinsicBounds(R.drawable.ic_volume_off_grey600_18dp, 0, 0, 0);
  else                             setCompoundDrawablesWithIntrinsicBounds(0, 0, 0, 0);
}
项目:browser    文件:CCPActivityBase.java   
/**
 *
 */
protected SpannableString buildActionTitle() {
    int dimensionPixelSize = mActionBarActivity.getResources().getDimensionPixelSize(R.dimen.BigTextSize);

    int mutIndex = 0;
    String format = "%s";
    if(isMute) {
        format = format + " #";
        mutIndex += 2;
    }

    SpannableString spannableString = new SpannableString(mTitleText);
    //EmoticonUtil.getTextFormat(mActionBarActivity, String.format(format, new Object[]{mTitleText}), dimensionPixelSize);
    if(isMute) {
        if(mMuteIcon == null) {
            mMuteIcon = getTitleIconTips(dimensionPixelSize, R.drawable.chat_mute_notify_title_icon);
        }
        int length = spannableString.length() - mutIndex + 1;
        spannableString.setSpan(mMuteIcon, length, length + 1, SpannableStringBuilder.SPAN_POINT_MARK);
    }
    return spannableString;
}
项目:LucaHome-AndroidApplication    文件:ShoppingListEditActivity.java   
/**
 * Build a custom error text
 */
private SpannableStringBuilder createErrorText(@NonNull String errorString) {
    ForegroundColorSpan foregroundColorSpan = new ForegroundColorSpan(Color.RED);
    SpannableStringBuilder spannableStringBuilder = new SpannableStringBuilder(errorString);
    spannableStringBuilder.setSpan(foregroundColorSpan, 0, errorString.length(), 0);
    return spannableStringBuilder;
}
项目:xifan    文件:PatternUtils.java   
private static SpannableStringBuilder getUrlTextSpannableString(Context context, String source,
        int size) {
    SpannableStringBuilder builder = new SpannableStringBuilder(source);
    String prefix = " ";
    builder.replace(0, prefix.length(), prefix);
    Drawable drawable = context.getResources().getDrawable(R.mipmap.ic_status_link);
    drawable.setBounds(0, 0, size, size);
    builder.setSpan(new VerticalImageSpan(drawable), prefix.length(), source.length(),
            Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
    builder.append(App.getInstance().getString(R.string.text_url_link));
    return builder;
}
项目:mongol-library    文件:MongolTextStorage.java   
@Override
public void removeSpan(Object what) {
    if (!(mUnicodeText instanceof Spanned)) {
        return;
    }
    if (!(mUnicodeText instanceof SpannableStringBuilder)) {
        return;
    }
    ((SpannableStringBuilder) mUnicodeText).removeSpan(what);
    ((SpannableStringBuilder) mGlyphText).removeSpan(what);

    final int length = mUnicodeText.length();
    if (mChangelistener != null)
        mChangelistener.onSpanChanged((Spanned) mUnicodeText, what, 0, 0, length, length);
}
项目:BookLoadingView    文件:JumpingBeans.java   
private JumpingBeansSpan[] getJumpingBeansSpans(SpannableStringBuilder sbb) {
    JumpingBeansSpan[] spans;
    if (waveCharDelay == -1) {
        waveCharDelay = loopDuration / (3 * (endPos - startPos));
    }

    spans = new JumpingBeansSpan[endPos - startPos];
    for (int pos = startPos; pos < endPos; pos++) {
        JumpingBeansSpan jumpingBean =
                new JumpingBeansSpan(textView, loopDuration, pos - startPos, waveCharDelay, animRange);
        sbb.setSpan(jumpingBean, pos, pos + 1, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        spans[pos - startPos] = jumpingBean;
    }
    return spans;
}
项目:LucaHome-AndroidApplication    文件:WirelessSwitchEditActivity.java   
/**
 * Build a custom error text
 */
private SpannableStringBuilder createErrorText(@NonNull String errorString) {
    ForegroundColorSpan foregroundColorSpan = new ForegroundColorSpan(Color.RED);
    SpannableStringBuilder spannableStringBuilder = new SpannableStringBuilder(errorString);
    spannableStringBuilder.setSpan(foregroundColorSpan, 0, errorString.length(), 0);
    return spannableStringBuilder;
}
项目:Android-Spans    文件:Span.java   
android.text.Spannable build(SpannableStringBuilder builder) {
    if (nodes != null) {
        for (Object child : nodes) {
            if (child instanceof Span) {
                ((Span) child).build(builder);
            } else {
                builder.append(child.toString());
            }
        }
    }
    return builder;
}
项目:Slide-RSS    文件:SpoilerRobotoTextView.java   
private static SpannableStringBuilder removeNewlines(SpannableStringBuilder s) {
    int start = 0;
    int end = s.length();
    while (start < end && Character.isWhitespace(s.charAt(start))) {
        start++;
    }

    while (end > start && Character.isWhitespace(s.charAt(end - 1))) {
        end--;
    }

    return (SpannableStringBuilder) s.subSequence(start, end);
}
项目:QMUI_Android    文件:QMUISpanHelper.java   
/**
 * 在text左边或者右边添加icon,
 * 默认TextView添加leftDrawable或rightDrawable不能适应TextView match_parent的情况
 *
 * @param left true 则在文字左边添加 icon,false 则在文字右边添加 icon
 * @param text 文字内容
 * @param icon 需要被添加的 icon
 * @return 返回带有 icon 的文字
 */
public static CharSequence generateSideIconText(boolean left, int iconPadding, CharSequence text, Drawable icon) {
    if (icon == null) {
        return text;
    }

    icon.setBounds(0, 0, icon.getIntrinsicWidth(), icon.getIntrinsicHeight());
    String iconTag = "[icon]";
    SpannableStringBuilder builder = new SpannableStringBuilder();
    int start, end;
    if (left) {
        start = 0;
        builder.append(iconTag);
        end = builder.length();
        builder.append(text);
    } else {
        builder.append(text);
        start = builder.length();
        builder.append(iconTag);
        end = builder.length();
    }

    QMUIMarginImageSpan imageSpan;

    if (left) {
        imageSpan = new QMUIMarginImageSpan(icon, QMUIAlignMiddleImageSpan.ALIGN_MIDDLE, 0, iconPadding);
    } else {
        imageSpan = new QMUIMarginImageSpan(icon, QMUIAlignMiddleImageSpan.ALIGN_MIDDLE, iconPadding, 0);
    }

    builder.setSpan(imageSpan, start, end, Spannable.SPAN_INCLUSIVE_EXCLUSIVE);
    imageSpan.setAvoidSuperChangeFontMetrics(true);
    return builder;
}
项目:mongol-library    文件:MongolTextStorage.java   
@Override
public void setFilters(InputFilter[] filters) {
    if (!(mUnicodeText instanceof SpannableStringBuilder)) {
        return;
    }
    // TODO: this is untested!
    int oldLength = mUnicodeText.length();
    ((SpannableStringBuilder) mUnicodeText).setFilters(filters);
    ((SpannableStringBuilder) mGlyphText).setFilters(filters);
    if (mChangelistener != null)
        mChangelistener.onTextChanged(mUnicodeText, 0, oldLength, mUnicodeText.length());
}
项目:SciChart.Android.Examples    文件:CustomizationRolloverModifierTooltipsFragment.java   
@Override
protected boolean updateInternal(AxisInfo axisInfo) {
    final SpannableStringBuilder sb = new SpannableStringBuilder();
    sb.append("Axis ID: ").append(axisInfo.axisId).append(StringUtil.NEW_LINE);
    sb.append("Value: ").append(axisInfo.axisFormattedDataValue);

    setText(sb);

    return true;
}
项目:orgzly-android    文件:UserTimeFormatter.java   
public CharSequence formatAll(OrgRange time) {
    SpannableStringBuilder s = new SpannableStringBuilder();

    s.append(formatAll(time.getStartTime()));

    if (time.getEndTime() != null) {
        s.append(" — ");
        s.append(formatAll(time.getEndTime()));
    }

    return s;
}
项目:RNLearn_Project1    文件:RCTVirtualText.java   
@Override
protected void performApplySpans(SpannableStringBuilder builder, int begin, int end, boolean isEditable) {
  mFontStylingSpan.freeze();

  // All spans will automatically extend to the right of the text, but not the left - except
  // for spans that start at the beginning of the text.
  final int flag;
  if (isEditable) {
    flag = Spannable.SPAN_EXCLUSIVE_EXCLUSIVE;
  } else {
    flag = begin == 0 ?
        Spannable.SPAN_INCLUSIVE_INCLUSIVE :
        Spannable.SPAN_EXCLUSIVE_INCLUSIVE;
  }

  builder.setSpan(
      mFontStylingSpan,
      begin,
      end,
      flag);

  if (mShadowStyleSpan.getColor() != 0 && mShadowStyleSpan.getRadius() != 0) {
    mShadowStyleSpan.freeze();

    builder.setSpan(
        mShadowStyleSpan,
        begin,
        end,
        flag);
  }

  for (int i = 0, childCount = getChildCount(); i < childCount; ++i) {
    FlatTextShadowNode child = (FlatTextShadowNode) getChildAt(i);
    child.applySpans(builder, isEditable);
  }
}
项目:anitrend-app    文件:MarkDown.java   
private static SpannableStringBuilder fromMD(String content) {
    if(content == null)
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N)
            return (SpannableStringBuilder) Html.fromHtml("<b>No content available</b>", Html.FROM_HTML_MODE_COMPACT | Html.FROM_HTML_OPTION_USE_CSS_COLORS | Html.FROM_HTML_SEPARATOR_LINE_BREAK_LIST);
        else return (SpannableStringBuilder) Html.fromHtml("<b>No content available</b>");
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N)
        return (SpannableStringBuilder) Html.fromHtml(Processor.process(content), Html.FROM_HTML_MODE_COMPACT | Html.FROM_HTML_OPTION_USE_CSS_COLORS | Html.FROM_HTML_SEPARATOR_LINE_BREAK_LIST);
    else return (SpannableStringBuilder) Html.fromHtml(Processor.process(content));
}
项目: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);
}
项目:Espresso    文件:CompanyDetailFragment.java   
@Override
public void setCompanyName(String name) {
    String companyName = getString(R.string.company_name) + "\n" + name;
    Spannable spannable = new SpannableStringBuilder(companyName);
    spannable.setSpan(new StyleSpan(Typeface.BOLD), 0, companyName.length() - name.length() - 1, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
    spannable.setSpan(new StyleSpan(Typeface.NORMAL), companyName.length() - name.length(), companyName.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
    textViewCompanyName.setText(spannable);
}
项目:Espresso    文件:CompanyDetailFragment.java   
@Override
public void setCompanyWebsite(String website) {
    this.website = website;
    String ws = getString(R.string.official_website) + "\n" + website;
    Spannable spannable = new SpannableStringBuilder(ws);
    spannable.setSpan(new StyleSpan(Typeface.BOLD), 0, ws.length() - website.length() - 1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
    spannable.setSpan(new URLSpan(website), ws.length() - website.length(), ws.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
    textViewWebsite.setText(spannable);
}