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


Java SpannableStringBuilder.removeSpan方法代碼示例

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


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

示例1: setHtmlWithLinkClickHandler

import android.text.SpannableStringBuilder; //導入方法依賴的package包/類
public static void setHtmlWithLinkClickHandler(TextView tv, String html,
                                        Action1<String> linkClickHandler) {
    CharSequence sequence = Html.fromHtml(html);
    SpannableStringBuilder strBuilder = new SpannableStringBuilder(sequence);
    URLSpan[] urls = strBuilder.getSpans(0, sequence.length(), URLSpan.class);
    for (URLSpan span : urls) {
        int start = strBuilder.getSpanStart(span);
        int end = strBuilder.getSpanEnd(span);
        int flags = strBuilder.getSpanFlags(span);
        ClickableSpan clickable = new ClickableSpan() {
            public void onClick(View view) {
                linkClickHandler.call(span.getURL());
            }
        };
        strBuilder.setSpan(clickable, start, end, flags);
        strBuilder.removeSpan(span);
    }
    tv.setText(strBuilder);
    tv.setMovementMethod(LinkMovementMethod.getInstance());
}
 
開發者ID:TryGhost,項目名稱:Ghost-Android,代碼行數:21,代碼來源:AppUtils.java

示例2: makeLinksClickable

import android.text.SpannableStringBuilder; //導入方法依賴的package包/類
public static void makeLinksClickable(TextView v) {
	SpannableStringBuilder ssb = new SpannableStringBuilder(v.getText());
	URLSpan[] spans = ssb.getSpans(0, ssb.length(), URLSpan.class);
	for (URLSpan span : spans) {
		int start = ssb.getSpanStart(span);
		int end = ssb.getSpanEnd(span);
		final String url = span.getURL();
		ssb.removeSpan(span);
		ClickableSpan cSpan = new ClickableSpan() {
			@Override
			public void onClick(View v2) {
				LinkDialogFragment f = LinkDialogFragment.newInstance(url);
				FragmentManager fm = ((AppCompatActivity) v2.getContext())
						.getSupportFragmentManager();
				f.show(fm, f.getUniqueTag());
			}
		};
		ssb.setSpan(cSpan, start, end, 0);
	}
	v.setText(ssb);
	v.setMovementMethod(ArticleMovementMethod.getInstance());
}
 
開發者ID:rafjordao,項目名稱:Nird2,代碼行數:23,代碼來源:UiUtils.java

示例3: resetLinkSpan

import android.text.SpannableStringBuilder; //導入方法依賴的package包/類
private void resetLinkSpan(SpannableStringBuilder ssb, RichTextConfig config, URLSpan urlSpan) {
    int start = ssb.getSpanStart(urlSpan);
    int end = ssb.getSpanEnd(urlSpan);
    ssb.removeSpan(urlSpan);
    LinkHolder linkHolder = new LinkHolder(urlSpan.getURL(), accentColor);
    if (config.linkFixCallback != null) {
        config.linkFixCallback.fix(linkHolder);
    }
    LongClickableURLSpan longClickableURLSpan = new LongClickableURLSpan(linkHolder, config.onUrlClickListener, config.onUrlLongClickListener);
    ssb.setSpan(longClickableURLSpan, start, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
}
 
開發者ID:nichbar,項目名稱:Aequorea,代碼行數:12,代碼來源:CachedSpannedParser.java

示例4: clearCachedMark

import android.text.SpannableStringBuilder; //導入方法依賴的package包/類
private void clearCachedMark(SpannableStringBuilder ssb) {
    Cached[] cs = ssb.getSpans(0, ssb.length(), Cached.class);
    if (cs != null && cs.length > 0) {
        for (Cached c : cs) {
            ssb.removeSpan(c);
        }
    }
}
 
開發者ID:nichbar,項目名稱:Aequorea,代碼行數:9,代碼來源:CachedSpannedParser.java

示例5: getTextWithPasswords

import android.text.SpannableStringBuilder; //導入方法依賴的package包/類
private static String getTextWithPasswords(CharSequence seq) {
    SpannableStringBuilder lstr = new SpannableStringBuilder(seq);
    for (PasswordSpan span : lstr.getSpans(0, lstr.length(), PasswordSpan.class)) {
        lstr.replace(lstr.getSpanStart(span), lstr.getSpanEnd(span), span.mPassword);
        lstr.removeSpan(span);
    }
    return lstr.toString();
}
 
開發者ID:MCMrARM,項目名稱:revolution-irc,代碼行數:9,代碼來源:AutoRunCommandListEditText.java

示例6: addEmojis

import android.text.SpannableStringBuilder; //導入方法依賴的package包/類
/**
   * Convert emoji characters of the given Spannable to the according emojicon.
   *
   * @param context
   * @param text
   * @param emojiSize
   * @param index
   * @param length
   * @param useSystemDefault
   */
  public static SpannableStringBuilder addEmojis(Context context, SpannableStringBuilder text, int emojiSize, int textSize, int index, int length, boolean useSystemDefault) {
      if (useSystemDefault) {
          return text;
      }

      int textLengthToProcess = calculateLegalTextLength(text, index, length);

      // remove spans throughout all text
      EmojiconSpan[] oldSpans = text.getSpans(0, text.length(), EmojiconSpan.class);
      for (int i = 0; i < oldSpans.length; i++) {
          text.removeSpan(oldSpans[i]);
      }

      int[] results = new int[3];
      String textStr = text.toString();

      int processIdx = index;
      while (processIdx < textLengthToProcess) {

          boolean isEmoji = findEmoji(textStr, processIdx, textLengthToProcess, results);
          int skip = results[1];
          if (isEmoji) {
              int icon = results[0];
              boolean isQQFace = results[2] > 0;
          	EmojiconSpan span = new EmojiconSpan(context, icon, (int)(emojiSize * EMOJIICON_SCALE),
                      (int)(emojiSize * EMOJIICON_SCALE));
              span.setTranslateY(isQQFace ? QQFACE_TRANSLATE_Y : EMOJIICON_TRANSLATE_Y);
          	if (span.getCachedDrawable() == null) {
          		text.replace(processIdx, processIdx + skip,  "..");
          		//重新計算字符串的合法長度
          		textLengthToProcess = calculateLegalTextLength(text, index, length);
		} else {
			text.setSpan(span, processIdx, processIdx + skip, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
		}
          }
          
          processIdx += skip;
}
      return (SpannableStringBuilder) text.subSequence(index, processIdx);
  }
 
開發者ID:coopese,項目名稱:qmui,代碼行數:51,代碼來源:EmojiconHandler.java

示例7: setEmoteSpans

import android.text.SpannableStringBuilder; //導入方法依賴的package包/類
private void setEmoteSpans(SpannableStringBuilder builder) {
    for (URLSpan span : builder.getSpans(0, builder.length(), URLSpan.class)) {
            setLargeLinks(builder, span);
        File emoteDir = new File(Environment.getExternalStorageDirectory(), "RedditEmotes");
        File emoteFile = new File(emoteDir, span.getURL().replace("/", "").replaceAll("-.*", "")
                + ".png"); //BPM uses "-" to add dynamics for emotes in browser. Fall back to original here if exists.
        boolean startsWithSlash = span.getURL().startsWith("/");
        boolean hasOnlyOneSlash = StringUtils.countMatches(span.getURL(), "/") == 1;

        if (emoteDir.exists() && startsWithSlash && hasOnlyOneSlash && emoteFile.exists()) {
            //We've got an emote match
            int start = builder.getSpanStart(span);
            int end = builder.getSpanEnd(span);
            CharSequence textCovers = builder.subSequence(start, end);

            //Make sure bitmap loaded works well with screen density.
            BitmapFactory.Options options = new BitmapFactory.Options();
            DisplayMetrics metrics = new DisplayMetrics();
            ((WindowManager) getContext().getSystemService(
                    Context.WINDOW_SERVICE)).getDefaultDisplay().getMetrics(metrics);
            options.inDensity = 240;
            options.inScreenDensity = metrics.densityDpi;
            options.inScaled = true;

            //Since emotes are not directly attached to included text, add extra character to attach image to.
            builder.removeSpan(span);
            if (builder.subSequence(start, end).charAt(0) != '.') {
                builder.insert(start, ".");
            }
            Bitmap emoteBitmap = BitmapFactory.decodeFile(emoteFile.getAbsolutePath(), options);
            builder.setSpan(new ImageSpan(getContext(), emoteBitmap), start, start + 1,
                    Spanned.SPAN_INCLUSIVE_INCLUSIVE);
            //Check if url span has length. If it does, it's a spoiler/caption
            if (textCovers.length() > 1) {
                builder.setSpan(new URLSpan("/sp"), start + 1, end + 1,
                        Spanned.SPAN_INCLUSIVE_INCLUSIVE);
                builder.setSpan(new StyleSpan(Typeface.ITALIC), start + 1, end + 1,
                        Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
            }
            builder.append("\n"); //Newline to fix text wrapping issues
        }
    }
}
 
開發者ID:ccrama,項目名稱:Slide-RSS,代碼行數:44,代碼來源:SpoilerRobotoTextView.java

示例8: addEmojis

import android.text.SpannableStringBuilder; //導入方法依賴的package包/類
/**
 * Convert emoji characters of the given Spannable to the according emojicon.
 *
 * @param context
 * @param text
 * @param emojiSize
 * @param index
 * @param length
 * @param useSystemDefault
 */
public static SpannableStringBuilder addEmojis(Context context, SpannableStringBuilder text, int emojiSize, int textSize, int index, int length, boolean useSystemDefault) {
    if (useSystemDefault) {
        return text;
    }

    int textLengthToProcess = calculateLegalTextLength(text, index, length);

    // remove spans throughout all text
    EmojiconSpan[] oldSpans = text.getSpans(0, text.length(), EmojiconSpan.class);
    for (EmojiconSpan oldSpan : oldSpans) {
        text.removeSpan(oldSpan);
    }

    int[] results = new int[3];
    String textStr = text.toString();

    int processIdx = index;
    while (processIdx < textLengthToProcess) {

        boolean isEmoji = findEmoji(textStr, processIdx, textLengthToProcess, results);
        int skip = results[1];
        if (isEmoji) {
            int icon = results[0];
            boolean isQQFace = results[2] > 0;
            EmojiconSpan span = new EmojiconSpan(context, icon, (int) (emojiSize * EMOJIICON_SCALE),
                    (int) (emojiSize * EMOJIICON_SCALE));
            span.setTranslateY(isQQFace ? QQFACE_TRANSLATE_Y : EMOJIICON_TRANSLATE_Y);
            if (span.getCachedDrawable() == null) {
                text.replace(processIdx, processIdx + skip, "..");
                //重新計算字符串的合法長度
                textLengthToProcess = calculateLegalTextLength(text, index, length);
            } else {
                text.setSpan(span, processIdx, processIdx + skip, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
            }
        }

        processIdx += skip;
    }
    return (SpannableStringBuilder) text.subSequence(index, processIdx);
}
 
開發者ID:QMUI,項目名稱:QMUI_Android,代碼行數:51,代碼來源:EmojiconHandler.java


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