本文整理汇总了Java中android.text.Spanned.length方法的典型用法代码示例。如果您正苦于以下问题:Java Spanned.length方法的具体用法?Java Spanned.length怎么用?Java Spanned.length使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.text.Spanned
的用法示例。
在下文中一共展示了Spanned.length方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: filter
import android.text.Spanned; //导入方法依赖的package包/类
@Override
public CharSequence filter(CharSequence source, int start, int end, Spanned dest, int dstart, int dend) {
try {
if (end - start == 1
&& start < source.length()
&& dstart <= dest.length()) {
char newChar = source.charAt(start);
if (newChar == '\n') {
return autoIndent(source, dest, dstart, dend);
}
}
} catch (IndexOutOfBoundsException | NullPointerException e) {
e.printStackTrace();
}
return source;
}
示例2: filter
import android.text.Spanned; //导入方法依赖的package包/类
@Override
public CharSequence filter(
CharSequence source,
int start,
int end,
Spanned dest,
int dstart,
int dend) {
if (end - start == 1 &&
start < source.length() &&
dstart <= dest.length()) {
char newChar = source.charAt(start);
if (newChar == '\n') {
return autoIndent(
source,
dest,
dstart,
dend);
}
}
return source;
}
示例3: getTeaser
import android.text.Spanned; //导入方法依赖的package包/类
public static SpannableStringBuilder getTeaser(Context ctx, Spanned body) {
if (body.length() < TEASER_LENGTH)
throw new IllegalArgumentException(
"String is shorter than TEASER_LENGTH");
SpannableStringBuilder builder =
new SpannableStringBuilder(body.subSequence(0, TEASER_LENGTH));
String ellipsis = ctx.getString(R.string.ellipsis);
builder.append(ellipsis).append(" ");
Spannable readMore = new SpannableString(
ctx.getString(R.string.read_more) + ellipsis);
ForegroundColorSpan fg = new ForegroundColorSpan(
ContextCompat.getColor(ctx, R.color.briar_text_link));
readMore.setSpan(fg, 0, readMore.length(),
Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
builder.append(readMore);
return builder;
}
示例4: getSpan
import android.text.Spanned; //导入方法依赖的package包/类
Object getSpan(Spanned spanned) {
final Object out;
final Object[] spans;
final int length = spanned != null ? spanned.length() : 0;
if (length == 0) {
spans = null;
} else {
spans = spanned.getSpans(0, length, Object.class);
}
if (spans != null
&& spans.length > 0) {
out = spans[0];
} else {
out = null;
}
return out;
}
示例5: filter
import android.text.Spanned; //导入方法依赖的package包/类
public CharSequence filter(CharSequence source, int start, int end, Spanned dest, int dstart, int dend) {
// If 8 digits have been pasted, replacing all source, trim alpha digits.
// Otherwise standard LengthFilter behavior.
final int srcLength = end - start;
final int dstSelLength = dend - dstart;
if (srcLength == PASTED_LEN && dstSelLength == dest.length()) {
// Discard alpha digits:
return source.subSequence(PASTED_LEN - MAX_LENGTH, PASTED_LEN);
}
else {
return sixDigitFilter.filter(source, start, end, dest, dstart, dend);
}
}
示例6: setEnableScrolling
import android.text.Spanned; //导入方法依赖的package包/类
public void setEnableScrolling(boolean enableScrolling) {
if (this.strategy == null
|| this.strategy.isScrolling() != enableScrolling) {
int pos = -1;
boolean wasNull = true;
Spanned text = null;
if (this.strategy != null) {
pos = this.strategy.getTopLeftPosition();
text = this.strategy.getText().unsafeGet();
this.strategy.clearText();
wasNull = false;
}
if (enableScrolling) {
this.strategy = scrollingStrategy;
} else {
this.strategy = fixedPagesStrategy;
}
strategy.setBookView(this);
if (!wasNull) {
this.strategy.setPosition(pos);
}
if (text != null && text.length() > 0) {
this.strategy.loadText(text);
}
}
}
示例7: getNumbers
import android.text.Spanned; //导入方法依赖的package包/类
public List<String> getNumbers() {
Spanned sp = mList.getText();
int len = sp.length();
List<String> list = new ArrayList<String>();
int start = 0;
int i = 0;
while (i < len + 1) {
char c;
if ((i == len) || ((c = sp.charAt(i)) == ',') || (c == ';')) {
if (i > start) {
list.add(getNumberAt(sp, start, i, mContext));
// calculate the recipients total length. This is so if the name contains
// commas or semis, we'll skip over the whole name to the next
// recipient, rather than parsing this single name into multiple
// recipients.
int spanLen = getSpanLength(sp, start, i, mContext);
if (spanLen > i) {
i = spanLen;
}
}
i++;
while ((i < len) && (sp.charAt(i) == ' ')) {
i++;
}
start = i;
} else {
i++;
}
}
return list;
}
示例8: createIndentForNextLine
import android.text.Spanned; //导入方法依赖的package包/类
private String createIndentForNextLine(Spanned dest, int dend, int istart) {
if (AppSettings.get().isTodoStartTasksWithTodaysDateEnabled()) {
if (dend == 0 || (dend == dest.length() || dend == dest.length() - 1)
|| (dest.charAt(dend) == '\n')) {
return SttCommander.DATEF_YYYY_MM_DD.format(new Date()) + " ";
}
}
return "";
}
示例9: getRecipientList
import android.text.Spanned; //导入方法依赖的package包/类
public RecipientList getRecipientList() {
Spanned sp = mList.getText();
int len = sp.length();
RecipientList rl = new RecipientList();
int start = 0;
int i = 0;
while (i < len + 1) {
if ((i == len) || (sp.charAt(i) == ',')) {
if (i > start) {
Recipient r = getRecipientAt(sp, start, i);
rl.add(r);
}
i++;
while ((i < len) && (sp.charAt(i) == ' ')) {
i++;
}
start = i;
} else {
i++;
}
}
return rl;
}
示例10: encodeTextAlignmentByDiv
import android.text.Spanned; //导入方法依赖的package包/类
private static void encodeTextAlignmentByDiv(Context context, StringBuilder out, Spanned text, int option) {
int len = text.length();
int next;
for (int i = 0; i < len; i = next) {
next = text.nextSpanTransition(i, len, ParagraphStyle.class);
ParagraphStyle[] styles = text.getSpans(i, next, ParagraphStyle.class);
String elements = " ";
boolean needDiv = false;
for (ParagraphStyle style : styles) {
if (style instanceof AlignmentSpan) {
Layout.Alignment align =
((AlignmentSpan) style).getAlignment();
needDiv = true;
if (align == Layout.Alignment.ALIGN_CENTER) {
elements = "align=\"center\" " + elements;
} else if (align == Layout.Alignment.ALIGN_OPPOSITE) {
elements = "align=\"right\" " + elements;
} else {
elements = "align=\"left\" " + elements;
}
}
}
if (needDiv) {
out.append("<div ").append(elements).append(">");
}
withinDiv(context, out, text, i, next, option);
if (needDiv) {
out.append("</div>");
}
}
}
示例11: filter
import android.text.Spanned; //导入方法依赖的package包/类
@Override
public CharSequence filter(CharSequence source, int start, int end, Spanned dest, int dstart,
int dend) {
if (this.emojiPattern.matcher(source).find() || containsEmoji(source)) {
return "";
}
if (mMax != -1) {
int keep = mMax - (dest.length() - (dend - dstart));
if (keep <= 0) {
return "";
} else if (keep >= end - start) {
return null; // keep original
} else {
keep += start;
if (Character.isHighSurrogate(source.charAt(keep - 1))) {
--keep;
if (keep == start) {
return "";
}
}
return source.subSequence(start, keep);
}
}
return source;
}
示例12: bindView
import android.text.Spanned; //导入方法依赖的package包/类
@Override
public View bindView(View view, final Object object, ThumbnailEngine.Result thumbnailResult, int positionInAdapter) {
super.bindView(view, object, thumbnailResult, positionInAdapter);
ViewHolder holder = (ViewHolder) view.getTag();
final Video video = (Video) object;
String name = video.getName();
if(video instanceof Episode){
Episode episode = (Episode) video;
name = episode.getShowName()+" S"+episode.getSeasonNumber()+"E"+episode.getEpisodeNumber()+" "+"<i>"+episode.getName()+ITALIC;
}
if (name == null) name = "";
if (name.endsWith(ITALIC)&&holder.name!=null) {
Spanned htmlName = Html.fromHtml(name);
// Display a string containing several display
// styles
// (use a SpannableStringBuilder in order to
// clear the shadow layer
// which is set when we come back from playing a
// video with subtitles)
mSpannableStringBuilder.clear();
mSpannableStringBuilder.append(htmlName);
if (htmlName.length() > 0) {
mSpannableStringBuilder
.setSpan(mTextNoShadowSpan, 0, htmlName.length() - 1,
Spanned.SPAN_INCLUSIVE_INCLUSIVE);
}
holder.name.setText(mSpannableStringBuilder);
} else if(holder.name!=null) {
holder.name.setText(name);
}
if(holder.name!=null)
holder.name.setEllipsize(TextUtils.TruncateAt.END);
int resumePosition = video.getRemoteResumeMs()>0?video.getRemoteResumeMs():video.getResumeMs();
boolean resume = resumePosition>0 || resumePosition == PlayerActivity.LAST_POSITION_END;
if (resume&&holder.resume!=null) {
int duration = video.getDurationMs();
duration = duration > 0 ? duration : resumePosition>0&&resumePosition<=100? 100 : 0;//resume can now be a percentage
boolean displayProgressSlider = !mThinPhoneInPortrait&&(duration>0 ||resumePosition == PlayerActivity.LAST_POSITION_END); // Display the progress bar if we know the duration
setResume(displayProgressSlider,duration > 0 ? duration : 100, resumePosition, holder.resume);
} else if(holder.resume!=null){
// Show disabled video icon (there is no such disabled resume slider)
holder.resume.setVisibility(View.GONE);
}
return view;
}
示例13: reactTagForTouch
import android.text.Spanned; //导入方法依赖的package包/类
@Override
public int reactTagForTouch(float touchX, float touchY) {
Spanned text = (Spanned) getText();
int target = getId();
int x = (int) touchX;
int y = (int) touchY;
Layout layout = getLayout();
if (layout == null) {
// If the layout is null, the view hasn't been properly laid out yet. Therefore, we can't find
// the exact text tag that has been touched, and the correct tag to return is the default one.
return target;
}
int line = layout.getLineForVertical(y);
int lineStartX = (int) layout.getLineLeft(line);
int lineEndX = (int) layout.getLineRight(line);
// TODO(5966918): Consider extending touchable area for text spans by some DP constant
if (x >= lineStartX && x <= lineEndX) {
int index = layout.getOffsetForHorizontal(line, x);
// We choose the most inner span (shortest) containing character at the given index
// if no such span can be found we will send the textview's react id as a touch handler
// In case when there are more than one spans with same length we choose the last one
// from the spans[] array, since it correspond to the most inner react element
ReactTagSpan[] spans = text.getSpans(index, index, ReactTagSpan.class);
if (spans != null) {
int targetSpanTextLength = text.length();
for (int i = 0; i < spans.length; i++) {
int spanStart = text.getSpanStart(spans[i]);
int spanEnd = text.getSpanEnd(spans[i]);
if (spanEnd > index && (spanEnd - spanStart) <= targetSpanTextLength) {
target = spans[i].getReactTag();
targetSpanTextLength = (spanEnd - spanStart);
}
}
}
}
return target;
}