当前位置: 首页>>代码示例>>Java>>正文


Java StyleSpan类代码示例

本文整理汇总了Java中android.text.style.StyleSpan的典型用法代码示例。如果您正苦于以下问题:Java StyleSpan类的具体用法?Java StyleSpan怎么用?Java StyleSpan使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


StyleSpan类属于android.text.style包,在下文中一共展示了StyleSpan类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: populateAdditionalHeadersView

import android.text.style.StyleSpan; //导入依赖的package包/类
/**
 * 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);
}
 
开发者ID:philipwhiuk,项目名称:q-mail,代码行数:28,代码来源:MessageHeader.java

示例2: highlightText

import android.text.style.StyleSpan; //导入依赖的package包/类
/**
 * 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);
	}
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:28,代码来源:Utils.java

示例3: appendPushNotificationState

import android.text.style.StyleSpan; //导入依赖的package包/类
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();
  }
}
 
开发者ID:XecureIT,项目名称:PeSanKita-android,代码行数:27,代码来源:MessageNotifier.java

示例4: setText

import android.text.style.StyleSpan; //导入依赖的package包/类
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);
}
 
开发者ID:XecureIT,项目名称:PeSanKita-android,代码行数:26,代码来源:FromTextView.java

示例5: applySpansForTag

import android.text.style.StyleSpan; //导入依赖的package包/类
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;
  }
}
 
开发者ID:MLNO,项目名称:airgram,代码行数:19,代码来源:WebvttCueParser.java

示例6: buildTickerMessage

import android.text.style.StyleSpan; //导入依赖的package包/类
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;
}
 
开发者ID:treasure-lau,项目名称:CSipSimple,代码行数:19,代码来源:SipNotifications.java

示例7: createValueString

import android.text.style.StyleSpan; //导入依赖的package包/类
/**
 * 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;
}
 
开发者ID:rkshuai,项目名称:chromium-for-android-56-debug-video,代码行数:24,代码来源:PaymentRequestSection.java

示例8: applyHighlightToMatchRegions

import android.text.style.StyleSpan; //导入依赖的package包/类
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;
}
 
开发者ID:rkshuai,项目名称:chromium-for-android-56-debug-video,代码行数:26,代码来源:SuggestionView.java

示例9: drawFollowNum

import android.text.style.StyleSpan; //导入依赖的package包/类
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);
}
 
开发者ID:JackChan1999,项目名称:letv,代码行数:21,代码来源:StarActivity.java

示例10: setText

import android.text.style.StyleSpan; //导入依赖的package包/类
@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);
}
 
开发者ID:dreaminglion,项目名称:iosched-reader,代码行数:23,代码来源:SearchSnippet.java

示例11: buildStyledSnippet

import android.text.style.StyleSpan; //导入依赖的package包/类
/**
 * 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;
}
 
开发者ID:dreaminglion,项目名称:iosched-reader,代码行数:28,代码来源:UIUtils.java

示例12: setBold

import android.text.style.StyleSpan; //导入依赖的package包/类
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);
        }
    }
}
 
开发者ID:hsj-xiaokang,项目名称:OSchina_resources_android,代码行数:23,代码来源:RichEditText.java

示例13: setItalic

import android.text.style.StyleSpan; //导入依赖的package包/类
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);
        }
    }
}
 
开发者ID:hsj-xiaokang,项目名称:OSchina_resources_android,代码行数:23,代码来源:RichEditText.java

示例14: onLoadFinished

import android.text.style.StyleSpan; //导入依赖的package包/类
@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);
    }
}
 
开发者ID:guodroid,项目名称:okwallet,代码行数:22,代码来源:WalletTransactionsFragment.java

示例15: buildActionPresetMessageFormat

import android.text.style.StyleSpan; //导入依赖的package包/类
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;
}
 
开发者ID:MCMrARM,项目名称:revolution-irc,代码行数:22,代码来源:MessageFormatSettingsActivity.java


注:本文中的android.text.style.StyleSpan类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。