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


Java SpannableStringBuilder.charAt方法代码示例

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


在下文中一共展示了SpannableStringBuilder.charAt方法的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: trimText

import android.text.SpannableStringBuilder; //导入方法依赖的package包/类
/**
 * Trims the specified text by removing white spaces at its start and also at its end.
 *
 * @param text The text to be trimmed.
 * @return Trimmed text.
 */
@NonNull
public static CharSequence trimText(@NonNull CharSequence text) {
	int length = text.length();
	final int trimmedLength = TextUtils.getTrimmedLength(text);
	if (length > trimmedLength) {
		final SpannableStringBuilder builder = new SpannableStringBuilder(text);

		// Remove white spaces from the start.
		int start = 0;
		while (start < length && builder.charAt(start) <= ' ') {
			start++;
		}
		builder.delete(0, start);
		length -= start;

		// Remove white spaces from the end.
		int end = length;
		while (end >= 0 && builder.charAt(end - 1) <= ' ') {
			end--;
		}
		builder.delete(end, length);
		return builder;
	}
	return text;
}
 
开发者ID:universum-studios,项目名称:android_ui,代码行数:32,代码来源:EmptyView.java

示例3: generateStaticLayout

import android.text.SpannableStringBuilder; //导入方法依赖的package包/类
public static StaticLayout generateStaticLayout(CharSequence text, TextPaint paint, int maxWidth, int smallWidth, int linesCount, int maxLines) {
    SpannableStringBuilder stringBuilder = new SpannableStringBuilder(text);
    int addedChars = 0;
    StaticLayout layout = new StaticLayout(text, paint, smallWidth, Layout.Alignment.ALIGN_NORMAL, 1.0f, 0.0f, false);
    for (int a = 0; a < linesCount; a++) {
        Layout.Directions directions = layout.getLineDirections(a);
        if (layout.getLineLeft(a) != 0 || layout.isRtlCharAt(layout.getLineStart(a)) || layout.isRtlCharAt(layout.getLineEnd(a))) {
            maxWidth = smallWidth;
        }
        int pos = layout.getLineEnd(a);
        if (pos == text.length()) {
            break;
        }
        pos--;
        if (stringBuilder.charAt(pos + addedChars) == ' ') {
            stringBuilder.replace(pos + addedChars, pos + addedChars + 1, "\n");
        } else if (stringBuilder.charAt(pos + addedChars) != '\n') {
            stringBuilder.insert(pos + addedChars, "\n");
            addedChars++;
        }
        if (a == layout.getLineCount() - 1 || a == maxLines - 1) {
            break;
        }
    }
    return StaticLayoutEx.createStaticLayout(stringBuilder, paint, maxWidth, Layout.Alignment.ALIGN_NORMAL, 1.0f, dp(1), false, TextUtils.TruncateAt.END, maxWidth, maxLines);
}
 
开发者ID:MLNO,项目名称:airgram,代码行数:27,代码来源:ChatMessageCell.java

示例4: 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

示例5: setHighlight

import android.text.SpannableStringBuilder; //导入方法依赖的package包/类
private void setHighlight(SpannableStringBuilder builder, String subreddit) {
    final int offset = "[[h[".length(); // == "]h]]".length()

    int start = -1;
    int end;
    for (int i = 0; i < builder.length() - 4; i++) {
        if (builder.charAt(i) == '['
                && builder.charAt(i + 1) == '['
                && builder.charAt(i + 2) == 'h'
                && builder.charAt(i + 3) == '[') {
            start = i + offset;
        } else if (builder.charAt(i) == ']'
                && builder.charAt(i + 1) == 'h'
                && builder.charAt(i + 2) == ']'
                && builder.charAt(i + 3) == ']') {
            end = i;
            builder.setSpan(new BackgroundColorSpan(Palette.getColor(subreddit)), 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,代码行数:25,代码来源:SpoilerRobotoTextView.java

示例6: 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

示例7: isInFangContext

import android.text.SpannableStringBuilder; //导入方法依赖的package包/类
public boolean isInFangContext() {
    SpannableStringBuilder builder = attributedString;
    ClickableSpan[] spans = builder.getSpans(0,
            builder.length(), ClickableSpan.class);
    Map<String, String> dict = SingletonData.getInstance().getFangAliasDict();
    if (spans.length > 0) {
        ClickableSpan span = spans[0];
        int start = builder.getSpanStart(span);
        int end = builder.getSpanEnd(span);
        String unit = builder.subSequence(start, end)
                .toString();
        String left = dict.get(unit);
        if (left == null) {
            left = unit;
        }
        if (SingletonData.getInstance().getAllFang().contains(left)
                && start > 0
                && builder.toString().substring(start - 1, start).equals("、")
                && builder.charAt(0) != '*') {
            return true;
        }
    }

    return false;
}
 
开发者ID:hh-in-zhuzhou,项目名称:ShangHanLun,代码行数:26,代码来源:LittleTableViewWindow.java

示例8: while

import android.text.SpannableStringBuilder; //导入方法依赖的package包/类
/**
 * Invoked when the end of a paragraph is encountered. Adds a newline if there are one or more
 * non-space characters since the previous newline.
 *
 * @param builder The builder.
 */
/* package */ static void endParagraph(SpannableStringBuilder builder) {
  int position = builder.length() - 1;
  while (position >= 0 && builder.charAt(position) == ' ') {
    position--;
  }
  if (position >= 0 && builder.charAt(position) != '\n') {
    builder.append('\n');
  }
}
 
开发者ID:MLNO,项目名称:airgram,代码行数:16,代码来源:TtmlRenderUtil.java

示例9: convert

import android.text.SpannableStringBuilder; //导入方法依赖的package包/类
public static Spanned convert(String input) {
    SpannableStringBuilder spanned = fromMD(PatternMatcher.findUserTags(input));

    try {
        if(input != null && !input.isEmpty()) {
            while (spanned.charAt(spanned.length() - 1) == '\n') {
                spanned = spanned.delete(spanned.length() - 1, spanned.length());
            }
        }
    } catch (Exception e){
        e.printStackTrace();
    }

    return spanned;
}
 
开发者ID:wax911,项目名称:anitrend-app,代码行数:16,代码来源:MarkDown.java

示例10: 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

示例11: beforeChildren

import android.text.SpannableStringBuilder; //导入方法依赖的package包/类
@Override
public void beforeChildren(TagNode node, SpannableStringBuilder builder, SpanStack spanStack) {

    Style useStyle = spanStack.getStyle( node, getStyle() );

    if (builder.length() > 0 &&  useStyle.getDisplayStyle() == Style.DisplayStyle.BLOCK ) {

        if ( builder.charAt(builder.length() -1) != '\n' ) {
            builder.append('\n');
        }
    }

    //If we have a top margin, we insert an extra newline. We'll manipulate the line height
    //of this newline to create the margin.
    if ( useStyle.getMarginTop() != null ) {

        StyleValue styleValue = useStyle.getMarginTop();

        if ( styleValue.getUnit() == StyleValue.Unit.PX ) {
            if ( styleValue.getIntValue() > 0 ) {
                if ( appendNewLine(builder) ) {
                    spanStack.pushSpan( new VerticalMarginSpan( styleValue.getIntValue() ),
                        builder.length() -1, builder.length() );
                }
            }
        } else {
            if ( styleValue.getFloatValue() > 0f ) {
                if ( appendNewLine(builder) ) {
                    spanStack.pushSpan( new VerticalMarginSpan( styleValue.getFloatValue() ),
                        builder.length() -1, builder.length() );
                }
            }
        }

    }


}
 
开发者ID:SysdataSpA,项目名称:SDHtmlTextView,代码行数:39,代码来源:StyledTextHandler.java

示例12: 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

示例13: while

import android.text.SpannableStringBuilder; //导入方法依赖的package包/类
/**
 * Called when the end of a paragraph is encountered. Adds a newline if there are one or more
 * non-space characters since the previous newline.
 *
 * @param builder The builder.
 */
/* package */ static void endParagraph(SpannableStringBuilder builder) {
  int position = builder.length() - 1;
  while (position >= 0 && builder.charAt(position) == ' ') {
    position--;
  }
  if (position >= 0 && builder.charAt(position) != '\n') {
    builder.append('\n');
  }
}
 
开发者ID:sanjaysingh1990,项目名称:Exoplayer2Radio,代码行数:16,代码来源:TtmlRenderUtil.java

示例14: cleanUpText

import android.text.SpannableStringBuilder; //导入方法依赖的package包/类
private SpannableStringBuilder cleanUpText(SpannableStringBuilder builder) {
  // Having joined the text elements, we need to do some final cleanup on the result.
  // 1. Collapse multiple consecutive spaces into a single space.
  int builderLength = builder.length();
  for (int i = 0; i < builderLength; i++) {
    if (builder.charAt(i) == ' ') {
      int j = i + 1;
      while (j < builder.length() && builder.charAt(j) == ' ') {
        j++;
      }
      int spacesToDelete = j - (i + 1);
      if (spacesToDelete > 0) {
        builder.delete(i, i + spacesToDelete);
        builderLength -= spacesToDelete;
      }
    }
  }
  // 2. Remove any spaces from the start of each line.
  if (builderLength > 0 && builder.charAt(0) == ' ') {
    builder.delete(0, 1);
    builderLength--;
  }
  for (int i = 0; i < builderLength - 1; i++) {
    if (builder.charAt(i) == '\n' && builder.charAt(i + 1) == ' ') {
      builder.delete(i + 1, i + 2);
      builderLength--;
    }
  }
  // 3. Remove any spaces from the end of each line.
  if (builderLength > 0 && builder.charAt(builderLength - 1) == ' ') {
    builder.delete(builderLength - 1, builderLength);
    builderLength--;
  }
  for (int i = 0; i < builderLength - 1; i++) {
    if (builder.charAt(i) == ' ' && builder.charAt(i + 1) == '\n') {
      builder.delete(i, i + 1);
      builderLength--;
    }
  }
  // 4. Trim a trailing newline, if there is one.
  if (builderLength > 0 && builder.charAt(builderLength - 1) == '\n') {
    builder.delete(builderLength - 1, builderLength);
    /*builderLength--;*/
  }
  return builder;
}
 
开发者ID:MLNO,项目名称:airgram,代码行数:47,代码来源:TtmlNode.java

示例15: beforeChildren

import android.text.SpannableStringBuilder; //导入方法依赖的package包/类
public void beforeChildren(TagNode node, SpannableStringBuilder builder) {
    if (builder.length() > 0 && builder.charAt(builder.length() - 1) != 10) { //'10 = \n'
        this.appendNewLine(builder);
    }
}
 
开发者ID:duyp,项目名称:mvvm-template,代码行数:6,代码来源:MarginHandler.java


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