Java 类android.text.style.StyleSpan 实例源码

项目:q-mail    文件:MessageHeader.java   
/**
 * Set up the additional headers text view with the supplied header data.
 *
 * @param additionalHeaders List of header entries. Each entry consists of a header
 *                          name and a header value. Header names may appear multiple
 *                          times.
 *                          <p/>
 *                          This method is always called from within the UI thread by
 *                          {@link #showAdditionalHeaders()}.
 */
private void populateAdditionalHeadersView(final List<HeaderEntry> additionalHeaders) {
    SpannableStringBuilder sb = new SpannableStringBuilder();
    boolean first = true;
    for (HeaderEntry additionalHeader : additionalHeaders) {
        if (!first) {
            sb.append("\n");
        } else {
            first = false;
        }
        StyleSpan boldSpan = new StyleSpan(Typeface.BOLD);
        SpannableString label = new SpannableString(additionalHeader.label + ": ");
        label.setSpan(boldSpan, 0, label.length(), 0);
        sb.append(label);
        sb.append(MimeUtility.unfoldAndDecode(additionalHeader.value));
    }
    mAdditionalHeadersView.setText(sb);
}
项目:GitHub    文件:Utils.java   
/**
 * Sets a spannable text with any highlight color into the provided TextView.
 *
 * @param textView     the TextView to transform
 * @param originalText the original text which the transformation is applied to
 * @param constraint   the text to highlight
 * @param color        the highlight color
 * @see #fetchAccentColor(Context, int)
 * @see #highlightText(TextView, String, String)
 * @since 5.0.0-rc1
 */
public static void highlightText(@NonNull TextView textView, @Nullable String originalText,
                                 @Nullable String constraint, @ColorInt int color) {
    if (originalText == null) originalText = "";
    if (constraint == null) constraint = "";
    int i = originalText.toLowerCase(Locale.getDefault()).indexOf(constraint.toLowerCase(Locale.getDefault()));
    if (i != -1) {
        Spannable spanText = Spannable.Factory.getInstance().newSpannable(originalText);
        spanText.setSpan(new ForegroundColorSpan(color), i,
                i + constraint.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        spanText.setSpan(new StyleSpan(Typeface.BOLD), i,
                i + constraint.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        textView.setText(spanText, TextView.BufferType.SPANNABLE);
    } else {
        textView.setText(originalText, TextView.BufferType.NORMAL);
    }
}
项目:PeSanKita-android    文件:MessageNotifier.java   
private static void appendPushNotificationState(@NonNull Context context,
                                                @NonNull NotificationState notificationState,
                                                @NonNull Cursor cursor)
{
  PushDatabase.Reader reader = null;
  SignalServiceEnvelope envelope;

  try {
    reader = DatabaseFactory.getPushDatabase(context).readerFor(cursor);

    while ((envelope = reader.getNext()) != null) {
      Recipients      recipients = RecipientFactory.getRecipientsFromString(context, envelope.getSource(), false);
      Recipient       recipient  = recipients.getPrimaryRecipient();
      long            threadId   = DatabaseFactory.getThreadDatabase(context).getThreadIdFor(recipients);
      SpannableString body       = new SpannableString(context.getString(R.string.MessageNotifier_locked_message));
      body.setSpan(new StyleSpan(android.graphics.Typeface.ITALIC), 0, body.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);

      if (!recipients.isMuted()) {
        notificationState.addNotification(new NotificationItem(recipient, recipients, null, threadId, body, 0, null));
      }
    }
  } finally {
    if (reader != null)
      reader.close();
  }
}
项目: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);
}
项目:airgram    文件:WebvttCueParser.java   
private static void applySpansForTag(StartTag startTag, SpannableStringBuilder spannedText) {
  switch(startTag.name) {
    case TAG_BOLD:
      spannedText.setSpan(new StyleSpan(STYLE_BOLD), startTag.position,
          spannedText.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
      return;
    case TAG_ITALIC:
      spannedText.setSpan(new StyleSpan(STYLE_ITALIC), startTag.position,
          spannedText.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
      return;
    case TAG_UNDERLINE:
      spannedText.setSpan(new UnderlineSpan(), startTag.position,
          spannedText.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
      return;
    default:
      break;
  }
}
项目:CSipSimple    文件:SipNotifications.java   
protected static CharSequence buildTickerMessage(Context context, String address, String body) {
    String displayAddress = address;

    StringBuilder buf = new StringBuilder(displayAddress == null ? "" : displayAddress.replace('\n', ' ').replace('\r', ' '));
    buf.append(':').append(' ');

    int offset = buf.length();

    if (!TextUtils.isEmpty(body)) {
        body = body.replace('\n', ' ').replace('\r', ' ');
        buf.append(body);
    }

    SpannableString spanText = new SpannableString(buf.toString());
    spanText.setSpan(new StyleSpan(Typeface.BOLD), 0, offset, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);

    return spanText;
}
项目: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);
}
项目:chromium-for-android-56-debug-video    文件:PaymentRequestSection.java   
/**
 * Builds a CharSequence that displays a value in a particular currency.
 *
 * @param currency    Currency of the value being displayed.
 * @param value       Value to display.
 * @param isValueBold Whether or not to bold the item.
 * @return CharSequence that represents the whole value.
 */
private CharSequence createValueString(String currency, String value, boolean isValueBold) {
    SpannableStringBuilder valueBuilder = new SpannableStringBuilder();
    valueBuilder.append(currency);
    valueBuilder.append(" ");

    int boldStartIndex = valueBuilder.length();
    valueBuilder.append(value);

    if (isValueBold) {
        valueBuilder.setSpan(new StyleSpan(android.graphics.Typeface.BOLD), boldStartIndex,
                boldStartIndex + value.length(), 0);
    }

    return valueBuilder;
}
项目:chromium-for-android-56-debug-video    文件:SuggestionView.java   
private boolean applyHighlightToMatchRegions(
        Spannable str, List<MatchClassification> classifications) {
    boolean hasMatch = false;
    for (int i = 0; i < classifications.size(); i++) {
        MatchClassification classification = classifications.get(i);
        if ((classification.style & MatchClassificationStyle.MATCH)
                == MatchClassificationStyle.MATCH) {
            int matchStartIndex = classification.offset;
            int matchEndIndex;
            if (i == classifications.size() - 1) {
                matchEndIndex = str.length();
            } else {
                matchEndIndex = classifications.get(i + 1).offset;
            }
            matchStartIndex = Math.min(matchStartIndex, str.length());
            matchEndIndex = Math.min(matchEndIndex, str.length());

            hasMatch = true;
            // Bold the part of the URL that matches the user query.
            str.setSpan(new StyleSpan(android.graphics.Typeface.BOLD),
                    matchStartIndex, matchEndIndex, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        }
    }
    return hasMatch;
}
项目:letv    文件:StarActivity.java   
private void drawFollowNum(long num) {
    LogInfo.log("clf", "drawFollowNum....num=" + num);
    String followNum = StringUtils.getPlayCountsToStr(num);
    if (TextUtils.isEmpty(followNum)) {
        this.mFollowNum.setText("0");
        return;
    }
    String unit = "";
    String lastChar = followNum.substring(followNum.length() - 1);
    if (!StringUtils.isInt(lastChar)) {
        unit = " " + lastChar;
        followNum = followNum.substring(0, followNum.length() - 1) + unit;
    }
    int start = followNum.length() - unit.length();
    int end = followNum.length();
    SpannableStringBuilder sb = new SpannableStringBuilder(followNum);
    sb.setSpan(new StyleSpan(1), 0, start, 33);
    sb.setSpan(new AbsoluteSizeSpan(getResources().getDimensionPixelSize(2131165476)), start, end, 33);
    this.mFollowNum.setText(sb);
}
项目:iosched-reader    文件:SearchSnippet.java   
@Override
public void setText(CharSequence text, BufferType type) {
    if (!TextUtils.isEmpty(text)) {
        Matcher matcher = PATTERN_SEARCH_TERM.matcher(text);
        SpannableStringBuilder ssb = new SpannableStringBuilder(text);
        List<String> hits = new ArrayList<>();
        while (matcher.find()) {
            hits.add(matcher.group(1));
        }

        for (String hit : hits) {
            int start = ssb.toString().indexOf(hit);
            int end = start + hit.length();
            ssb.setSpan(new StyleSpan(Typeface.BOLD), start, end, 0);
            // delete the markup tokens
            ssb.delete(end - 1, end);
            ssb.delete(start, start + 1);
        }
        text = ssb;
    }
    super.setText(text, type);
}
项目:iosched-reader    文件:UIUtils.java   
/**
 * Given a snippet string with matching segments surrounded by curly
 * braces, turn those areas into bold spans, removing the curly braces.
 */
public static Spannable buildStyledSnippet(String snippet) {
    final SpannableStringBuilder builder = new SpannableStringBuilder(snippet);

    // Walk through string, inserting bold snippet spans
    int startIndex, endIndex = -1, delta = 0;
    while ((startIndex = snippet.indexOf('{', endIndex)) != -1) {
        endIndex = snippet.indexOf('}', startIndex);

        // Remove braces from both sides
        builder.delete(startIndex - delta, startIndex - delta + 1);
        builder.delete(endIndex - delta - 1, endIndex - delta);

        // Insert bold style
        builder.setSpan(new StyleSpan(Typeface.BOLD),
                startIndex - delta, endIndex - delta - 1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        //builder.setSpan(new ForegroundColorSpan(0xff111111),
        //        startIndex - delta, endIndex - delta - 1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);

        delta += 2;
    }

    return builder;
}
项目:OSchina_resources_android    文件:RichEditText.java   
void setBold(boolean isBold) {
    int index = getSelectionIndex();
    if (index >= 0 && index < mSections.size()) {
        mSections.get(index).setBold(isBold);
    }
    Editable edit = getEditableText();
    int star = getSectionStart();
    int end = getSectionEnd();
    if (isBold) {
        edit.setSpan(new StyleSpan(Typeface.BOLD),
                star,
                end,
                Typeface.BOLD);
    } else {
        StyleSpan[] styleSpans = edit.getSpans(star,
                end, StyleSpan.class);
        for (CharacterStyle span : styleSpans) {
            if (span instanceof StyleSpan && ((StyleSpan) span).getStyle() == Typeface.BOLD)
                edit.removeSpan(span);
        }
    }
}
项目:OSchina_resources_android    文件:RichEditText.java   
void setItalic(boolean isItalic) {
    int index = getSelectionIndex();
    if (index >= 0 && index < mSections.size()) {
        mSections.get(index).setItalic(isItalic);
    }
    Editable edit = getEditableText();
    int star = getSectionStart();
    int end = getSectionEnd();
    if (isItalic) {
        edit.setSpan(new StyleSpan(Typeface.ITALIC),
                star,
                end,
                Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
    } else {
        StyleSpan[] styleSpans = edit.getSpans(star,
                end, StyleSpan.class);
        for (CharacterStyle span : styleSpans) {
            if (span instanceof StyleSpan && ((StyleSpan) span).getStyle() == Typeface.ITALIC)
                edit.removeSpan(span);
        }
    }
}
项目:OSchina_resources_android    文件:RichEditText.java   
void setItalic(boolean isItalic, int index) {
    if (index >= 0 && index < mSections.size()) {
        mSections.get(index).setItalic(isItalic);
    }
    Editable edit = getEditableText();
    int star = getSectionStart();
    int end = getSectionEnd();
    if (isItalic) {
        edit.setSpan(new StyleSpan(Typeface.ITALIC),
                star,
                end,
                Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
    } else {
        StyleSpan[] styleSpans = edit.getSpans(star,
                end, StyleSpan.class);
        for (CharacterStyle span : styleSpans) {
            if (span instanceof StyleSpan && ((StyleSpan) span).getStyle() == Typeface.ITALIC)
                edit.removeSpan(span);
        }
    }
}
项目:OSchina_resources_android    文件:RichEditText.java   
void setBold(boolean isBold, int index) {
    if (index >= 0 && index < mSections.size()) {
        mSections.get(index).setBold(isBold);
    }
    Editable edit = getEditableText();
    int star = getSectionStart(index);
    int end = getSectionEnd(index);
    if (star >= end)
        return;
    if (isBold) {
        edit.setSpan(new StyleSpan(Typeface.BOLD),
                star,
                end,
                Typeface.BOLD);
    } else {
        StyleSpan[] styleSpans = edit.getSpans(star,
                end, StyleSpan.class);
        for (CharacterStyle span : styleSpans) {
            if (span instanceof StyleSpan && ((StyleSpan) span).getStyle() == Typeface.BOLD)
                edit.removeSpan(span);
        }
    }
}
项目:PlusGram    文件:WebvttCueParser.java   
private static void applySpansForTag(StartTag startTag, SpannableStringBuilder spannedText) {
  switch(startTag.name) {
    case TAG_BOLD:
      spannedText.setSpan(new StyleSpan(STYLE_BOLD), startTag.position,
          spannedText.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
      return;
    case TAG_ITALIC:
      spannedText.setSpan(new StyleSpan(STYLE_ITALIC), startTag.position,
          spannedText.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
      return;
    case TAG_UNDERLINE:
      spannedText.setSpan(new UnderlineSpan(), startTag.position,
          spannedText.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
      return;
    default:
      break;
  }
}
项目:okwallet    文件:WalletTransactionsFragment.java   
@Override
public void onLoadFinished(final Loader<List<Transaction>> loader, final List<Transaction> transactions) {
    final Direction direction = ((TransactionsLoader) loader).getDirection();

    adapter.replace(transactions);

    if (transactions.isEmpty()) {
        viewGroup.setDisplayedChild(1);

        final SpannableStringBuilder emptyText = new SpannableStringBuilder(
                getString(direction == Direction.SENT ? R.string.wallet_transactions_fragment_empty_text_sent
                        : R.string.wallet_transactions_fragment_empty_text_received));
        emptyText.setSpan(new StyleSpan(Typeface.BOLD), 0, emptyText.length(),
                SpannableStringBuilder.SPAN_POINT_MARK);
        if (direction != Direction.SENT)
            emptyText.append("\n\n").append(getString(R.string.wallet_transactions_fragment_empty_text_howto));
        emptyView.setText(emptyText);
    } else {
        viewGroup.setDisplayedChild(2);
    }
}
项目:revolution-irc    文件:MessageFormatSettingsActivity.java   
public static SpannableString buildActionPresetMessageFormat(Context context, int preset, boolean mention) {
    if (preset == 0 || preset == 1) {
        SpannableString spannable = new SpannableString("  |*    ");
        spannable.setSpan(new MessageBuilder.MetaForegroundColorSpan(context, MessageBuilder.MetaForegroundColorSpan.COLOR_TIMESTAMP), 0, 1, MessageBuilder.FORMAT_SPAN_FLAGS);
        if (preset == 0)
            spannable.setSpan(new StyleSpan(Typeface.ITALIC), 3, 8, Spanned.SPAN_INCLUSIVE_INCLUSIVE);
        spannable.setSpan(new MessageBuilder.MetaChipSpan(context, MessageBuilder.MetaChipSpan.TYPE_TIME), 0, 1, MessageBuilder.FORMAT_SPAN_FLAGS);
        spannable.setSpan(new MessageBuilder.MetaChipSpan(context, MessageBuilder.MetaChipSpan.TYPE_SENDER), 5, 6, MessageBuilder.FORMAT_SPAN_FLAGS);
        spannable.setSpan(new MessageBuilder.MetaChipSpan(context, MessageBuilder.MetaChipSpan.TYPE_MESSAGE),  7, 8, MessageBuilder.FORMAT_SPAN_FLAGS);
        spannable.setSpan(new MessageBuilder.MetaChipSpan(context, MessageBuilder.MetaChipSpan.TYPE_WRAP_ANCHOR), 2, 3, MessageBuilder.FORMAT_SPAN_FLAGS);
        if (mention) {
            spannable.setSpan(new StyleSpan(Typeface.BOLD), 5, 6, MessageBuilder.FORMAT_SPAN_FLAGS);
            spannable.setSpan(new MessageBuilder.MetaForegroundColorSpan(context, MessageBuilder.MetaForegroundColorSpan.COLOR_SENDER),  3, 8, MessageBuilder.FORMAT_SPAN_FLAGS);
        } else {
            spannable.setSpan(new MessageBuilder.MetaForegroundColorSpan(context, MessageBuilder.MetaForegroundColorSpan.COLOR_STATUS), 3, 4, MessageBuilder.FORMAT_SPAN_FLAGS);
            spannable.setSpan(new MessageBuilder.MetaForegroundColorSpan(context, MessageBuilder.MetaForegroundColorSpan.COLOR_SENDER), 5, 6, MessageBuilder.FORMAT_SPAN_FLAGS);
        }
        return spannable;
    }
    return null;
}
项目:revolution-irc    文件:SpannableStringHelper.java   
public static JsonObject spanToJson(Object span) {
    JsonObject ret = new JsonObject();
    if (span instanceof ForegroundColorSpan) {
        ret.addProperty("type", SPAN_TYPE_FOREGROUND);
        ret.addProperty("color", ((ForegroundColorSpan) span).getForegroundColor());
    } else if (span instanceof BackgroundColorSpan) {
        ret.addProperty("type", SPAN_TYPE_BACKGROUND);
        ret.addProperty("color", ((BackgroundColorSpan) span).getBackgroundColor());
    } else if (span instanceof StyleSpan) {
        ret.addProperty("type", SPAN_TYPE_STYLE);
        ret.addProperty("style", ((StyleSpan) span).getStyle());
    } else {
        return null;
    }
    return ret;
}
项目:GitHub    文件:PiePolylineChartActivity.java   
private SpannableString generateCenterSpannableText() {

        SpannableString s = new SpannableString("MPAndroidChart\ndeveloped by Philipp Jahoda");
        s.setSpan(new RelativeSizeSpan(1.5f), 0, 14, 0);
        s.setSpan(new StyleSpan(Typeface.NORMAL), 14, s.length() - 15, 0);
        s.setSpan(new ForegroundColorSpan(Color.GRAY), 14, s.length() - 15, 0);
        s.setSpan(new RelativeSizeSpan(.65f), 14, s.length() - 15, 0);
        s.setSpan(new StyleSpan(Typeface.ITALIC), s.length() - 14, s.length(), 0);
        s.setSpan(new ForegroundColorSpan(ColorTemplate.getHoloBlue()), s.length() - 14, s.length(), 0);
        return s;
    }
项目:GitHub    文件:HalfPieChartActivity.java   
private SpannableString generateCenterSpannableText() {

        SpannableString s = new SpannableString("MPAndroidChart\ndeveloped by Philipp Jahoda");
        s.setSpan(new RelativeSizeSpan(1.7f), 0, 14, 0);
        s.setSpan(new StyleSpan(Typeface.NORMAL), 14, s.length() - 15, 0);
        s.setSpan(new ForegroundColorSpan(Color.GRAY), 14, s.length() - 15, 0);
        s.setSpan(new RelativeSizeSpan(.8f), 14, s.length() - 15, 0);
        s.setSpan(new StyleSpan(Typeface.ITALIC), s.length() - 14, s.length(), 0);
        s.setSpan(new ForegroundColorSpan(ColorTemplate.getHoloBlue()), s.length() - 14, s.length(), 0);
        return s;
    }
项目:GitHub    文件:RealmDatabaseActivityPie.java   
private SpannableString generateCenterSpannableText() {

        SpannableString s = new SpannableString("Realm.io\nmobile database");
        s.setSpan(new ForegroundColorSpan(Color.rgb(240, 115, 126)), 0, 8, 0);
        s.setSpan(new RelativeSizeSpan(2.2f), 0, 8, 0);
        s.setSpan(new StyleSpan(Typeface.ITALIC), 9, s.length(), 0);
        s.setSpan(new ForegroundColorSpan(ColorTemplate.getHoloBlue()), 9, s.length(), 0);
        s.setSpan(new RelativeSizeSpan(0.85f), 9, s.length(), 0);
        return s;
    }
项目:GitHub    文件:PieChartActivity.java   
private SpannableString generateCenterSpannableText() {

        SpannableString s = new SpannableString("MPAndroidChart\ndeveloped by Philipp Jahoda");
        s.setSpan(new RelativeSizeSpan(1.7f), 0, 14, 0);
        s.setSpan(new StyleSpan(Typeface.NORMAL), 14, s.length() - 15, 0);
        s.setSpan(new ForegroundColorSpan(Color.GRAY), 14, s.length() - 15, 0);
        s.setSpan(new RelativeSizeSpan(.8f), 14, s.length() - 15, 0);
        s.setSpan(new StyleSpan(Typeface.ITALIC), s.length() - 14, s.length(), 0);
        s.setSpan(new ForegroundColorSpan(ColorTemplate.getHoloBlue()), s.length() - 14, s.length(), 0);
        return s;
    }
项目: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 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);
}
项目: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);
}
项目:mapbox-navigation-android    文件:TimeUtils.java   
public static SpannableStringBuilder formatTimeRemaining(double routeDuration) {
  long seconds = (long) routeDuration;

  if (seconds < 0) {
    throw new IllegalArgumentException("Duration must be greater than zero.");
  }

  long days = TimeUnit.SECONDS.toDays(seconds);
  seconds -= TimeUnit.DAYS.toSeconds(days);
  long hours = TimeUnit.SECONDS.toHours(seconds);
  seconds -= TimeUnit.HOURS.toSeconds(hours);
  long minutes = TimeUnit.SECONDS.toMinutes(seconds);
  seconds -= TimeUnit.MINUTES.toSeconds(minutes);

  if (seconds >= 30) {
    minutes = minutes + 1;
  }

  List<SpanItem> spanItems = new ArrayList<>();
  if (days != 0) {
    String dayFormat = days > 1 ? DAYS : DAY;
    spanItems.add(new SpanItem(new StyleSpan(Typeface.BOLD), String.valueOf(days)));
    spanItems.add(new SpanItem(new RelativeSizeSpan(1f), dayFormat));
  }
  if (hours != 0) {
    spanItems.add(new SpanItem(new StyleSpan(Typeface.BOLD), String.valueOf(hours)));
    spanItems.add(new SpanItem(new RelativeSizeSpan(1f), HOUR));
  }
  if (minutes != 0) {
    spanItems.add(new SpanItem(new StyleSpan(Typeface.BOLD), String.valueOf(minutes)));
    spanItems.add(new SpanItem(new RelativeSizeSpan(1f), MINUTE));
  }
  if (days == 0 && hours == 0 && minutes == 0) {
    spanItems.add(new SpanItem(new StyleSpan(Typeface.BOLD), String.valueOf(1)));
    spanItems.add(new SpanItem(new RelativeSizeSpan(1f), MINUTE));
  }

  return SpanUtils.combineSpans(spanItems);
}
项目:keepass2android    文件:SearchBookContentsListItem.java   
public void set(SearchBookContentsResult result) {
  pageNumberView.setText(result.getPageNumber());
  String snippet = result.getSnippet();
  if (snippet.isEmpty()) {
    snippetView.setText("");
  } else {
    if (result.getValidSnippet()) {
      String lowerQuery = SearchBookContentsResult.getQuery().toLowerCase(Locale.getDefault());
      String lowerSnippet = snippet.toLowerCase(Locale.getDefault());
      Spannable styledSnippet = new SpannableString(snippet);
      StyleSpan boldSpan = new StyleSpan(Typeface.BOLD);
      int queryLength = lowerQuery.length();
      int offset = 0;
      while (true) {
        int pos = lowerSnippet.indexOf(lowerQuery, offset);
        if (pos < 0) {
          break;
        }
        styledSnippet.setSpan(boldSpan, pos, pos + queryLength, 0);
        offset = pos + queryLength;
      }
      snippetView.setText(styledSnippet);
    } else {
      // This may be an error message, so don't try to bold the query terms within it
      snippetView.setText(snippet);
    }
  }
}
项目:Cable-Android    文件:Util.java   
public static CharSequence getBoldedString(String value) {
  SpannableString spanned = new SpannableString(value);
  spanned.setSpan(new StyleSpan(Typeface.BOLD), 0,
                  spanned.length(),
                  Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);

  return spanned;
}
项目:instamaterial    文件:FeedAdapter.java   
private Spannable getStylizedText(String username, String description) {
  Spannable descriptionSpan = new SpannableString(username + " " + description);

  descriptionSpan.setSpan(new ForegroundColorSpan(Color.parseColor("#21425D")), 0,
      username.length(),
      Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
  descriptionSpan.setSpan(new StyleSpan(android.graphics.Typeface.BOLD), 0,
      username.length(),
      Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);

  return descriptionSpan;
}
项目:PeSanKita-android    文件:MessageRecord.java   
protected SpannableString emphasisAdded(String sequence) {
  SpannableString spannable = new SpannableString(sequence);
  spannable.setSpan(new RelativeSizeSpan(0.9f), 0, sequence.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
  spannable.setSpan(new StyleSpan(android.graphics.Typeface.ITALIC), 0, sequence.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);

  return spannable;
}
项目:PeSanKita-android    文件:Util.java   
public static CharSequence getBoldedString(String value) {
  SpannableString spanned = new SpannableString(value);
  spanned.setSpan(new StyleSpan(Typeface.BOLD), 0,
                  spanned.length(),
                  Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);

  return spanned;
}
项目:markor    文件:Highlighter.java   
protected void clearSpans(Editable editable) {
    clearCharacterSpanType(editable, TextAppearanceSpan.class);
    clearCharacterSpanType(editable, ForegroundColorSpan.class);
    clearCharacterSpanType(editable, BackgroundColorSpan.class);
    clearCharacterSpanType(editable, StrikethroughSpan.class);
    clearCharacterSpanType(editable, RelativeSizeSpan.class);
    clearCharacterSpanType(editable, StyleSpan.class);
    clearCharacterSpanType(editable, ColorUnderlineSpan.class);
    clearParagraphSpanType(editable, LineBackgroundSpan.class);
    clearParagraphSpanType(editable, LineHeightSpan.class);
}
项目:Exoplayer2Radio    文件:Cea708Decoder.java   
public SpannableString buildSpannableString() {
  SpannableStringBuilder spannableStringBuilder =
      new SpannableStringBuilder(captionStringBuilder);
  int length = spannableStringBuilder.length();

  if (length > 0) {
    if (italicsStartPosition != C.POSITION_UNSET) {
      spannableStringBuilder.setSpan(new StyleSpan(Typeface.ITALIC), italicsStartPosition,
          length, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
    }

    if (underlineStartPosition != C.POSITION_UNSET) {
      spannableStringBuilder.setSpan(new UnderlineSpan(), underlineStartPosition,
          length, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
    }

    if (foregroundColorStartPosition != C.POSITION_UNSET) {
      spannableStringBuilder.setSpan(new ForegroundColorSpan(foregroundColor),
          foregroundColorStartPosition, length, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
    }

    if (backgroundColorStartPosition != C.POSITION_UNSET) {
      spannableStringBuilder.setSpan(new BackgroundColorSpan(backgroundColor),
          backgroundColorStartPosition, length, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
    }
  }

  return new SpannableString(spannableStringBuilder);
}
项目:Exoplayer2Radio    文件:WebvttCueParser.java   
private static void applySpansForTag(String cueId, StartTag startTag, SpannableStringBuilder text,
    List<WebvttCssStyle> styles, List<StyleMatch> scratchStyleMatches) {
  int start = startTag.position;
  int end = text.length();
  switch(startTag.name) {
    case TAG_BOLD:
      text.setSpan(new StyleSpan(STYLE_BOLD), start, end,
          Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
      break;
    case TAG_ITALIC:
      text.setSpan(new StyleSpan(STYLE_ITALIC), start, end,
          Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
      break;
    case TAG_UNDERLINE:
      text.setSpan(new UnderlineSpan(), start, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
      break;
    case TAG_CLASS:
    case TAG_LANG:
    case TAG_VOICE:
    case "": // Case of the "whole cue" virtual tag.
      break;
    default:
      return;
  }
  scratchStyleMatches.clear();
  getApplicableStyles(styles, cueId, startTag, scratchStyleMatches);
  int styleMatchesCount = scratchStyleMatches.size();
  for (int i = 0; i < styleMatchesCount; i++) {
    applyStyleToText(text, scratchStyleMatches.get(i).style, start, end);
  }
}
项目:lex    文件:MyListItemView.java   
public void bind(BookList item) {
    Lex.say(R.string.name_template)
            .with(LexKey.FIRST_NAME, item.firstName)
            .with(LexKey.LAST_NAME, item.lastName)
            .into(title);

    Lex.list(item.titles)
            .wrappedIn(new StyleSpan(android.graphics.Typeface.BOLD_ITALIC))
            .wrappedIn(new ForegroundColorSpan(Color.WHITE))
            .separator(R.string.comma_separator)
            .twoItemSeparator(R.string.and_separator)
            .lastItemSeparator(R.string.comma_and_separator)
            .into(description);

    Lex.say(R.string.item_count_template)
            .withNumber(LexKey.COUNT, item.titles.length)
            .wrappedIn(new AbsoluteSizeSpan(24, true))
            .wrappedIn(new ForegroundColorSpan(Color.WHITE))
            .withPlural(LexKey.ITEM, item.titles.length, R.plurals.book)
            .wrappedIn(new ForegroundColorSpan(Color.YELLOW))
            .into(bookCount);

    Lex.say(R.string.gpa_template)
            .withNumber(LexKey.NUMBER, item.gpa, GPA_FORMAT)
            .wrappedIn(new AbsoluteSizeSpan(24, true))
            .into(gpa);
}
项目:SpanEZ    文件:SpanEZTest.java   
@Test
public void bold_should_add_only_one_span() {
    spanBuilder.style(range, EZ.BOLD)
               .apply();

    verify((SpanEZ) spanBuilder, times(1))
            .addSpan(isA(TargetRange.class), isA(StyleSpan.class));
}
项目:MyBP    文件:Span.java   
public static void span(String text, String subText, Switch switchView) {
    SpannableString spanText = new SpannableString(text);
    spanText.setSpan(new ForegroundColorSpan(Color.GRAY), 0, text.length(), 0);
    spanText.setSpan(new StyleSpan(Typeface.BOLD), 0, text.length(), 0);

    SpannableString spanSubText = new SpannableString(subText);
    spanSubText.setSpan(new RelativeSizeSpan(0.75f), 0, subText.length(), 0);
    spanSubText.setSpan(new ForegroundColorSpan(Color.GRAY), 0, subText.length(), 0);
    switchView.setText("");
    switchView.append(spanText);
    switchView.append("\n");
    switchView.append(spanSubText);
}
项目:MyBP    文件:Span.java   
public static void span(String text, String subText, TextView textView) {
    SpannableString spanText = new SpannableString(text);
    spanText.setSpan(new ForegroundColorSpan(Color.GRAY), 0, text.length(), 0);
    spanText.setSpan(new StyleSpan(Typeface.BOLD), 0, text.length(), 0);

    SpannableString spanSubText = new SpannableString(subText);
    spanSubText.setSpan(new RelativeSizeSpan(0.75f), 0, subText.length(), 0);
    spanSubText.setSpan(new ForegroundColorSpan(Color.GRAY), 0, subText.length(), 0);
    textView.setText("");
    textView.append(spanText);
    textView.append("\n");
    textView.append(spanSubText);
}