當前位置: 首頁>>代碼示例>>Java>>正文


Java SpannableStringBuilder.setSpan方法代碼示例

本文整理匯總了Java中android.text.SpannableStringBuilder.setSpan方法的典型用法代碼示例。如果您正苦於以下問題:Java SpannableStringBuilder.setSpan方法的具體用法?Java SpannableStringBuilder.setSpan怎麽用?Java SpannableStringBuilder.setSpan使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在android.text.SpannableStringBuilder的用法示例。


在下文中一共展示了SpannableStringBuilder.setSpan方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: handleEmoticonText

import android.text.SpannableStringBuilder; //導入方法依賴的package包/類
/**
 * 處理帶表情的文本(顯示表情符號)
 *
 * @param editText
 * @param content
 * @param context
 */
public static void handleEmoticonText(EditText editText, String content, Context context) {
    SpannableStringBuilder sb = new SpannableStringBuilder(content);
    String regex = "\\[(\\S+?)\\]";
    Pattern p = Pattern.compile(regex);
    Matcher m = p.matcher(content);
    Iterator<Emoticon> iterator;
    Emoticon emoticon = null;
    while (m.find()) {
        iterator = emoticonList.iterator();
        String tempText = m.group();
        while (iterator.hasNext()) {
            emoticon = iterator.next();
            if (tempText.equals(emoticon.getContent())) {
                //轉換為Span並設置Span的大小
                sb.setSpan(new VerticalImageSpan(context,
                                decodeSampledBitmapFromResource(context.getResources(),
                                        emoticon.getImageUri(), dip2px(context, 16), dip2px(context, 16))),
                        m.start(), m.end(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
                break;
            }
        }
    }
    editText.setText(sb);
    editText.setSelection(sb.length());
}
 
開發者ID:liying2008,項目名稱:Simpler,代碼行數:33,代碼來源:EmoticonUtils.java

示例2: onUploadSuccess

import android.text.SpannableStringBuilder; //導入方法依賴的package包/類
private void onUploadSuccess(final QueuedMedia item, Attachment media) {
    item.id = media.id;
    item.preview.setProgress(-1);
    item.readyStage = QueuedMedia.ReadyStage.UPLOADED;

    /* Add the upload URL to the text field. Also, keep a reference to the span so if the user
     * chooses to remove the media, the URL is also automatically removed. */
    item.uploadUrl = new URLSpan(media.textUrl);
    int end = 1 + media.textUrl.length();
    SpannableStringBuilder builder = new SpannableStringBuilder();
    builder.append(' ');
    builder.append(media.textUrl);
    builder.setSpan(item.uploadUrl, 1, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
    int cursorStart = textEditor.getSelectionStart();
    int cursorEnd = textEditor.getSelectionEnd();
    textEditor.append(builder);
    textEditor.setSelection(cursorStart, cursorEnd);

    waitForMediaLatch.countDown();
}
 
開發者ID:Vavassor,項目名稱:Tusky,代碼行數:21,代碼來源:ComposeActivity.java

示例3: emojify

import android.text.SpannableStringBuilder; //導入方法依賴的package包/類
@Nullable
@UiThread
Spannable emojify(@Nullable CharSequence text, TextView tv) {
	if (text == null) return null;
	Matcher matches = EMOJI_RANGE.matcher(text);
	SpannableStringBuilder builder = new SpannableStringBuilder(text);

	while (matches.find()) {
		int codePoint = matches.group().codePointAt(0);
		Drawable drawable = getEmojiDrawable(codePoint);
		if (drawable != null) {
			builder.setSpan(new EmojiSpan(drawable, tv), matches.start(),
					matches.end(), SPAN_EXCLUSIVE_EXCLUSIVE);
		}
	}
	return builder;
}
 
開發者ID:rafjordao,項目名稱:Nird2,代碼行數:18,代碼來源:EmojiProvider.java

示例4: internalUpdate

import android.text.SpannableStringBuilder; //導入方法依賴的package包/類
@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);
}
 
開發者ID:ABTSoftware,項目名稱:SciChart.Android.Examples,代碼行數:21,代碼來源:CustomTooltipsWithModifiersFragment.java

示例5: createAndPutChipForUser

import android.text.SpannableStringBuilder; //導入方法依賴的package包/類
private ChipSpan createAndPutChipForUser(TLRPC.User user) {
    LayoutInflater lf = (LayoutInflater) ApplicationLoader.applicationContext.getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
    View textView = lf.inflate(R.layout.group_create_bubble, null);
    TextView text = (TextView)textView.findViewById(R.id.bubble_text_view);
    String name = UserObject.getUserName(user);
    if (name.length() == 0 && user.phone != null && user.phone.length() != 0) {
        name = PhoneFormat.getInstance().format("+" + user.phone);
    }
    text.setText(name + ", ");

    int spec = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED);
    textView.measure(spec, spec);
    textView.layout(0, 0, textView.getMeasuredWidth(), textView.getMeasuredHeight());
    Bitmap b = Bitmap.createBitmap(textView.getWidth(), textView.getHeight(), Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(b);
    canvas.translate(-textView.getScrollX(), -textView.getScrollY());
    textView.draw(canvas);
    textView.setDrawingCacheEnabled(true);
    Bitmap cacheBmp = textView.getDrawingCache();
    Bitmap viewBmp = cacheBmp.copy(Bitmap.Config.ARGB_8888, true);
    textView.destroyDrawingCache();

    final BitmapDrawable bmpDrawable = new BitmapDrawable(b);
    bmpDrawable.setBounds(0, 0, b.getWidth(), b.getHeight());

    SpannableStringBuilder ssb = new SpannableStringBuilder("");
    ChipSpan span = new ChipSpan(bmpDrawable, ImageSpan.ALIGN_BASELINE);
    allSpans.add(span);
    selectedContacts.put(user.id, span);
    for (ImageSpan sp : allSpans) {
        ssb.append("<<");
        ssb.setSpan(sp, ssb.length() - 2, ssb.length(), SpannableStringBuilder.SPAN_EXCLUSIVE_EXCLUSIVE);
    }
    userSelectEditText.setText(ssb);
    userSelectEditText.setSelection(ssb.length());
    return span;
}
 
開發者ID:MLNO,項目名稱:airgram,代碼行數:38,代碼來源:GroupCreateActivity.java

示例6: setColorText

import android.text.SpannableStringBuilder; //導入方法依賴的package包/類
/**
 * 設置彩色文本
 *
 * @param tv        textview
 * @param formatStr 格式化字符串
 * @param params    需要變色的字符
 * @param colors    需要變換的顏色
 */
public static void setColorText(TextView tv, String formatStr, Object[] params, int[] colors) {
    if (StringUtil.isEmpty(formatStr) || params.length != colors.length)
        return;
    String text = String.format(formatStr, params);
    SpannableStringBuilder spannable = new SpannableStringBuilder(text);
    Pattern p = Pattern.compile("%[abcdefghosx]");
    Matcher m = p.matcher(formatStr);
    int i = 0;
    int begin = 0;
    int end = 0;
    while (m.find()) {
        begin += m.start() - end;
        spannable.setSpan(new ForegroundColorSpan(colors[i]), begin, begin + params[i].toString().length(), Spanned.SPAN_EXCLUSIVE_INCLUSIVE);
        begin = begin + params[i].toString().length();
        end = m.end();
        i++;
    }
    tv.setText(spannable);
}
 
開發者ID:f-evil,項目名稱:EVideoRecorder,代碼行數:28,代碼來源:StringUtil.java

示例7: applySpansForTag

import android.text.SpannableStringBuilder; //導入方法依賴的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

示例8: emojifyText

import android.text.SpannableStringBuilder; //導入方法依賴的package包/類
/**
 * replaces emoji shortcodes in a text with EmojiSpans
 * @param text the text containing custom emojis
 * @param emojis a list of the custom emojis
 * @param textView a reference to the textView the emojis will be shown in
 * @return the text with the shortcodes replaced by EmojiSpans
 */
public static Spanned emojifyText(Spanned text, List<Status.Emoji> emojis, final TextView textView) {

    if (!emojis.isEmpty()) {

        SpannableStringBuilder builder = new SpannableStringBuilder(text);
        for (Status.Emoji emoji : emojis) {
            CharSequence pattern = new StringBuilder(":").append(emoji.getShortcode()).append(':');
            Matcher matcher = Pattern.compile(pattern.toString()).matcher(text);
            while (matcher.find()) {
                // We keep a span as a Picasso target, because Picasso keeps weak reference to
                // the target so an anonymous class would likely be garbage collected.
                EmojiSpan span = new EmojiSpan(textView);
                builder.setSpan(span, matcher.start(), matcher.end(), 0);
                Picasso.with(textView.getContext())
                        .load(emoji.getUrl())
                        .into(span);
            }
        }

        return builder;
    }

    return text;
}
 
開發者ID:Vavassor,項目名稱:Tusky,代碼行數:32,代碼來源:CustomEmojiHelper.java

示例9: formatMessage

import android.text.SpannableStringBuilder; //導入方法依賴的package包/類
private CharSequence formatMessage(Cursor cursor) {
    SpannableStringBuilder buf = new SpannableStringBuilder();
    /*
    String remoteContact = cursor.getString(cursor.getColumnIndex(SipMessage.FIELD_FROM));
    if (remoteContact.equals("SELF")) {
        remoteContact = cursor.getString(cursor.getColumnIndex(SipMessage.FIELD_TO));
        buf.append("To: ");
    }
    */
    String remoteContactFull = cursor.getString(cursor.getColumnIndex(SipMessage.FIELD_FROM_FULL));
    CallerInfo callerInfo = CallerInfo.getCallerInfoFromSipUri(mContext, remoteContactFull);
    if (callerInfo != null && callerInfo.contactExists) {
    	buf.append(callerInfo.name);
    	buf.append(" / ");
        buf.append(SipUri.getDisplayedSimpleContact(remoteContactFull));
    } else {
        buf.append(SipUri.getDisplayedSimpleContact(remoteContactFull));
    }
    
    int counter = cursor.getInt(cursor.getColumnIndex("counter"));
    if (counter > 1) {
        buf.append(" (" + counter + ") ");
    }
   

    int read = cursor.getInt(cursor.getColumnIndex(SipMessage.FIELD_READ));
    // Unread messages are shown in bold
    if (read == 0) {
        buf.setSpan(STYLE_BOLD, 0, buf.length(),
                Spannable.SPAN_INCLUSIVE_EXCLUSIVE);
    }
    return buf;
}
 
開發者ID:treasure-lau,項目名稱:CSipSimple,代碼行數:34,代碼來源:ConversationsAdapter.java

示例10: buildCounterSpannable

import android.text.SpannableStringBuilder; //導入方法依賴的package包/類
private Spannable buildCounterSpannable(String label, int value) {
    SpannableStringBuilder contentString = new SpannableStringBuilder();
    contentString.append(String.valueOf(value));
    contentString.append("\n");
    int start = contentString.length();
    contentString.append(label);
    contentString.setSpan(new TextAppearanceSpan(this, R.style.TextAppearance_Second_Light), start, contentString.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
    return contentString;
}
 
開發者ID:rozdoum,項目名稱:social-app-android,代碼行數:10,代碼來源:ProfileActivity.java

示例11: createAndPutChipForUser

import android.text.SpannableStringBuilder; //導入方法依賴的package包/類
private ChipSpan createAndPutChipForUser(TLRPC.User user) {
    LayoutInflater lf = (LayoutInflater) ApplicationLoader.applicationContext.getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
    View textView = lf.inflate(R.layout.group_create_bubble, null);
    TextView text = (TextView) textView.findViewById(R.id.bubble_text_view);
    String name = UserObject.getUserName(user);
    if (name.length() == 0 && user.phone != null && user.phone.length() != 0) {
        name = PhoneFormat.getInstance().format("+" + user.phone);
    }
    text.setText(name + ", ");

    int spec = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED);
    textView.measure(spec, spec);
    textView.layout(0, 0, textView.getMeasuredWidth(), textView.getMeasuredHeight());
    Bitmap b = Bitmap.createBitmap(textView.getWidth(), textView.getHeight(), Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(b);
    canvas.translate(-textView.getScrollX(), -textView.getScrollY());
    textView.draw(canvas);
    textView.setDrawingCacheEnabled(true);
    Bitmap cacheBmp = textView.getDrawingCache();
    Bitmap viewBmp = cacheBmp.copy(Bitmap.Config.ARGB_8888, true);
    textView.destroyDrawingCache();

    final BitmapDrawable bmpDrawable = new BitmapDrawable(b);
    bmpDrawable.setBounds(0, 0, b.getWidth(), b.getHeight());

    SpannableStringBuilder ssb = new SpannableStringBuilder("");
    ChipSpan span = new ChipSpan(bmpDrawable, ImageSpan.ALIGN_BASELINE);
    allSpans.add(span);
    selectedContacts.put(user.id, span);
    for (ImageSpan sp : allSpans) {
        ssb.append("<<");
        ssb.setSpan(sp, ssb.length() - 2, ssb.length(), SpannableStringBuilder.SPAN_EXCLUSIVE_EXCLUSIVE);
    }
    userSelectEditText.setText(ssb);
    userSelectEditText.setSelection(ssb.length());
    return span;
}
 
開發者ID:pooyafaroka,項目名稱:PlusGram,代碼行數:38,代碼來源:DeleteBySelectContacts.java

示例12: attachFontFamily

import android.text.SpannableStringBuilder; //導入方法依賴的package包/類
@SuppressWarnings("ReferenceEquality")
private static void attachFontFamily(SpannableStringBuilder cueText, String fontFamily,
    String defaultFontFamily, int start, int end, int spanPriority) {
  if (fontFamily != defaultFontFamily) {
    cueText.setSpan(new TypefaceSpan(fontFamily), start, end,
        Spanned.SPAN_EXCLUSIVE_EXCLUSIVE | spanPriority);
  }
}
 
開發者ID:sanjaysingh1990,項目名稱:Exoplayer2Radio,代碼行數:9,代碼來源:Tx3gDecoder.java

示例13: getUrlTextSpannableString

import android.text.SpannableStringBuilder; //導入方法依賴的package包/類
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;
}
 
開發者ID:betroy,項目名稱:xifan,代碼行數:13,代碼來源:PatternUtils.java

示例14: performApplySpans

import android.text.SpannableStringBuilder; //導入方法依賴的package包/類
@Override
protected void performApplySpans(
    SpannableStringBuilder builder,
    int begin,
    int end,
    boolean isEditable) {
  mInlineImageSpan.freeze();
  builder.setSpan(
      mInlineImageSpan,
      begin,
      end,
      Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
}
 
開發者ID:qq565999484,項目名稱:RNLearn_Project1,代碼行數:14,代碼來源:RCTTextInlineImage.java

示例15: setAmountTextWithTwoAmounts

import android.text.SpannableStringBuilder; //導入方法依賴的package包/類
private void setAmountTextWithTwoAmounts(TextView textView, Currency c, long amount1, long amount2) {
    SpannableStringBuilder sb = new SpannableStringBuilder();
    sb.append(Utils.amountToString(c, amount1, false));
    int x = sb.length();
    sb.setSpan(getAmountSpan(context, amount1), 0, x, Spannable.SPAN_INCLUSIVE_EXCLUSIVE);
    sb.append(" | ");
    sb.append(Utils.amountToString(c, amount2, false));
    sb.setSpan(getAmountSpan(context, amount2), x+3, sb.length(), Spannable.SPAN_INCLUSIVE_EXCLUSIVE);
    textView.setText(sb, TextView.BufferType.NORMAL);
}
 
開發者ID:tiberiusteng,項目名稱:financisto1-holo,代碼行數:11,代碼來源:Utils.java


注:本文中的android.text.SpannableStringBuilder.setSpan方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。