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


Java SpannableStringBuilder.length方法代碼示例

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


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

示例1: appendNewLine

import android.text.SpannableStringBuilder; //導入方法依賴的package包/類
/**
 * Utility method to append newlines while making sure that there are never
 * more than 2 consecutive newlines in the text (if whitespace stripping was
 * enabled).
 * 
 * @param builder
    * @return true if a newline was added
 */
protected boolean appendNewLine(SpannableStringBuilder builder) {

	int len = builder.length();

	if (this.spanner.isStripExtraWhiteSpace()) {
		// Should never have more than 2 \n characters in a row.
		if (len > 2 && builder.charAt(len - 1) == '\n'
				&& builder.charAt(len - 2) == '\n') {
			return false;
		}
	}

	builder.append("\n");

       return true;
}
 
開發者ID:SysdataSpA,項目名稱:SDHtmlTextView,代碼行數:25,代碼來源:TagNodeHandler.java

示例2: getColoredChattingRecord

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

示例3: replaceWithLink

import android.text.SpannableStringBuilder; //導入方法依賴的package包/類
public CharSequence replaceWithLink(CharSequence source, String param, ArrayList<Integer> uids, AbstractMap<Integer, TLRPC.User> usersDict) {
    int start = TextUtils.indexOf(source, param);
    if (start >= 0) {
        SpannableStringBuilder names = new SpannableStringBuilder("");
        for (int a = 0; a < uids.size(); a++) {
            TLRPC.User user = null;
            if (usersDict != null) {
                user = usersDict.get(uids.get(a));
            }
            if (user == null) {
                user = MessagesController.getInstance().getUser(uids.get(a));
            }
            if (user != null) {
                String name = UserObject.getUserName(user);
                start = names.length();
                if (names.length() != 0) {
                    names.append(", ");
                }
                names.append(name);
                names.setSpan(new URLSpanNoUnderlineBold("" + user.id), start, start + name.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
            }
        }
        return TextUtils.replace(source, new String[]{param}, new CharSequence[]{names});
    }
    return source;
}
 
開發者ID:MLNO,項目名稱:airgram,代碼行數:27,代碼來源:MessageObject.java

示例4: format

import android.text.SpannableStringBuilder; //導入方法依賴的package包/類
public static CharSequence format(CharSequence seq, Object... args) {
    int argI = 0;
    SpannableStringBuilder builder = new SpannableStringBuilder(seq);
    for (int i = 0; i < builder.length() - 1; i++) {
        if (builder.charAt(i) == '%') {
            int c = builder.charAt(++i);
            CharSequence replacement = null;
            switch (c) {
                case 's':
                    replacement = (CharSequence) args[argI++];
                    break;
                case '%':
                    replacement = "%";
                    break;
            }
            if (replacement != null) {
                builder.replace(i - 1, i + 1, replacement);
                i += replacement.length() - 2;
            }
        }
    }
    return builder;
}
 
開發者ID:MCMrARM,項目名稱:revolution-irc,代碼行數:24,代碼來源:SpannableStringHelper.java

示例5: setStrikethrough

import android.text.SpannableStringBuilder; //導入方法依賴的package包/類
private void setStrikethrough(SpannableStringBuilder builder) {
    final int offset = "[[d[".length(); // == "]d]]".length()

    int start = -1;
    int end;

    for (int i = 0; i < builder.length() - 3; i++) {
        if (builder.charAt(i) == '['
                && builder.charAt(i + 1) == '['
                && builder.charAt(i + 2) == 'd'
                && builder.charAt(i + 3) == '[') {
            start = i + offset;
        } else if (builder.charAt(i) == ']'
                && builder.charAt(i + 1) == 'd'
                && builder.charAt(i + 2) == ']'
                && builder.charAt(i + 3) == ']') {
            end = i;
            builder.setSpan(new StrikethroughSpan(), start, end,
                    Spanned.SPAN_INCLUSIVE_INCLUSIVE);
            builder.delete(end, end + offset);
            builder.delete(start - offset, start);
            i -= offset + (end - start); // length of text
        }
    }
}
 
開發者ID:ccrama,項目名稱:Slide-RSS,代碼行數:26,代碼來源:SpoilerRobotoTextView.java

示例6: prepareMainMessageString

import android.text.SpannableStringBuilder; //導入方法依賴的package包/類
/**
 * Prepares text to be displayed as the infobar's main message, including setting up a
 * clickable link if the infobar requires it.
 */
private CharSequence prepareMainMessageString() {
    SpannableStringBuilder fullString = new SpannableStringBuilder();

    if (mMessageMainText != null) fullString.append(mMessageMainText);

    // Concatenate the text to display for the link and make it clickable.
    if (!TextUtils.isEmpty(mMessageLinkText)) {
        if (fullString.length() > 0) fullString.append(" ");
        int spanStart = fullString.length();

        fullString.append(mMessageLinkText);
        fullString.setSpan(new ClickableSpan() {
            @Override
            public void onClick(View view) {
                mInfoBarView.onLinkClicked();
            }
        }, spanStart, fullString.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
    }

    return fullString;
}
 
開發者ID:rkshuai,項目名稱:chromium-for-android-56-debug-video,代碼行數:26,代碼來源:InfoBarLayout.java

示例7: generateSideIconText

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

示例8: removeNewlines

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

示例9: sameTextForSpan

import android.text.SpannableStringBuilder; //導入方法依賴的package包/類
private static boolean sameTextForSpan(
    final Editable oldText,
    final SpannableStringBuilder newText,
    final int start,
    final int end) {
  if (start > newText.length() || end > newText.length()) {
    return false;
  }
  for (int charIdx = start; charIdx < end; charIdx++) {
    if (oldText.charAt(charIdx) != newText.charAt(charIdx)) {
      return false;
    }
  }
  return true;
}
 
開發者ID:qq565999484,項目名稱:RNLearn_Project1,代碼行數:16,代碼來源:ReactEditText.java

示例10: getFormattedTweet

import android.text.SpannableStringBuilder; //導入方法依賴的package包/類
private SpannableStringBuilder getFormattedTweet(String tweet, boolean hasMedia) {
    if (hasMedia) {
        int excluir = tweet.indexOf("https://t.co/");
        while (tweet.indexOf("https://t.co/", excluir + 1) != excluir) {
            int excluir_novo = tweet.indexOf("https://t.co/", excluir + 1);
            if (excluir_novo == -1) {
                break;
            } else {
                excluir = excluir_novo;
            }
        }
        tweet = tweet.replace(tweet.substring(excluir, tweet.length()), "");
    }
    SpannableStringBuilder str = new SpannableStringBuilder(tweet);
    ArrayList<int[]> indexes = new ArrayList<>();
    int start = -1;
    while (true) { // É TÃO DIVERTIDO BRINCAR COM FOGO.
        int current = tweet.indexOf("#", start + 1);
        if (current == -1) {
            break;
        }
        indexes.add(new int[]{current, tweet.indexOf(" ", current)});
        start = current;
    }
    for (int[] arr : indexes) {
        int inicio = arr[0];
        int fim = arr[1];
        if (fim < 0) {
            fim = str.length();
        }
        str.setSpan(new android.text.style.StyleSpan(Typeface.BOLD), inicio, fim, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
    }
    return str;
}
 
開發者ID:secompufscar,項目名稱:app_secompufscar,代碼行數:35,代碼來源:ListHashtagAdapter.java

示例11: applySpan

import android.text.SpannableStringBuilder; //導入方法依賴的package包/類
private void applySpan(SpannableStringBuilder builder, TagNode node, SpanStack stack,
                       CancellationCallback cancellationCallback) {

    checkForCancellation(cancellationCallback);

    TagNodeHandler handler = this.handlers.get(node.getName());

    if ( handler == null ) {
        handler = new StyledTextHandler();
        handler.setSpanner(this);
    }

    int lengthBefore = builder.length();

    handler.beforeChildren(node, builder, stack);

    if ( !handler.rendersContent() ) {

        for (Object childNode : node.getAllChildren()) {

            if ( childNode instanceof ContentNode ) {
                handleContent( builder, childNode, stack, cancellationCallback );
            } else if ( childNode instanceof TagNode ) {
                applySpan( builder, (TagNode) childNode, stack, cancellationCallback );
            }
        }
    }

    int lengthAfter = builder.length();
    handler.handleTagNode(node, builder, lengthBefore, lengthAfter, stack);
}
 
開發者ID:SysdataSpA,項目名稱:SDHtmlTextView,代碼行數:32,代碼來源:HtmlSpanner.java

示例12: buildSpannableString

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

示例13: populate

import android.text.SpannableStringBuilder; //導入方法依賴的package包/類
public void populate(RecipientList list) {
    SpannableStringBuilder sb = new SpannableStringBuilder();

    Iterator<Recipient> iter = list.iterator();
    while (iter.hasNext()) {
        if (sb.length() != 0) {
            sb.append(", ");
        }

        Recipient r = iter.next();
        sb.append(r.toToken());
    }

    setText(sb);
}
 
開發者ID:sdrausty,項目名稱:buildAPKsApps,代碼行數:16,代碼來源:RecipientsEditor.java

示例14: autoClose

import android.text.SpannableStringBuilder; //導入方法依賴的package包/類
@SuppressWarnings("StatementWithEmptyBody")
protected void autoClose(Editable e, int count) {
    SpannableStringBuilder selectedStr = new SpannableStringBuilder(getText());
    Integer startSelection = getSelectionStart();
    Integer endSelection = getSelectionEnd();
    if (startSelection.equals(endSelection) && selectedStr.length() == startSelection) {}
    if (count > 0 && selectedStr.length() > 0 && startSelection > 0 && startSelection.equals(endSelection)) {
        char c = selectedStr.charAt(startSelection - 1);
        char nextC = 'x';
        char prevC = 'x';
        if (selectedStr.length() > startSelection) {
            nextC = selectedStr.charAt(startSelection);
        }
        if (startSelection > 1) {
            prevC = selectedStr.charAt(startSelection - 2);
        }
        if (!(c != '(' || nextC == ')' || prevC == '(')) {
            e.insert(startSelection, ")");
            setSelection(startSelection);
        } else if (!(c != '{' || nextC == '}' || prevC == '{')) {
            e.insert(startSelection, "}");
            setSelection(startSelection);
        } else if (!(c != '[' || nextC == ']' || prevC == '[')) {
            e.insert(startSelection, "]");
            setSelection(startSelection);
        }
    }
}
 
開發者ID:Light-Team,項目名稱:ModPE-IDE-Source,代碼行數:29,代碼來源:LModEditor.java

示例15: appendAndStyleText

import android.text.SpannableStringBuilder; //導入方法依賴的package包/類
/**
 * Append the styled text in textField to the supplied builder.
 *
 * @param builder The builder to append the text to.
 * @param textField The text field (with text and type) to append.
 * @param maxTextHeightSp The height in SP of the largest text field in the entire line. Used to
 *                        top-align text when specified.
 * @param metrics Font metrics which will be used to properly size and layout images and top-
 *                aligned text.
 * @param density Screen density which will be used to properly size and layout images and top-
 *                aligned text.
*/
private static void appendAndStyleText(
        SpannableStringBuilder builder, SuggestionAnswer.TextField textField,
        int maxTextHeightSp, Paint.FontMetrics metrics, float density) {
    String text = textField.getText();
    int type = textField.getType();

    // Unescape HTML entities (e.g. "&quot;", "&gt;").
    text = Html.fromHtml(text).toString();

    // Append as HTML (answer responses contain simple markup).
    int start = builder.length();
    builder.append(Html.fromHtml(text));
    int end = builder.length();

    // Apply styles according to the type.
    AbsoluteSizeSpan sizeSpan = new AbsoluteSizeSpan(getAnswerTextSizeSp(type), true);
    builder.setSpan(sizeSpan, start, end, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);

    ForegroundColorSpan colorSpan = new ForegroundColorSpan(getAnswerTextColor(type));
    builder.setSpan(colorSpan, start, end, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);

    if (type == ANSWERS_TOP_ALIGNED_TEXT_TYPE) {
        TopAlignedSpan topAlignedSpan =
                new TopAlignedSpan(
                        ANSWERS_TOP_ALIGNED_TEXT_SIZE_SP, maxTextHeightSp, metrics, density);
        builder.setSpan(topAlignedSpan, start, end, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
    }
}
 
開發者ID:rkshuai,項目名稱:chromium-for-android-56-debug-video,代碼行數:41,代碼來源:AnswerTextBuilder.java


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