本文整理汇总了Java中android.text.Spanned.subSequence方法的典型用法代码示例。如果您正苦于以下问题:Java Spanned.subSequence方法的具体用法?Java Spanned.subSequence怎么用?Java Spanned.subSequence使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.text.Spanned
的用法示例。
在下文中一共展示了Spanned.subSequence方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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;
}
示例2: filter
import android.text.Spanned; //导入方法依赖的package包/类
public CharSequence filter(CharSequence source, int start, int end,
Spanned dest, int dstart, int dend) {
if (mDisplayedValues == null) {
return mNumberInputFilter.filter(source, start, end, dest, dstart, dend);
}
CharSequence filtered = String.valueOf(source.subSequence(start, end));
String result = String.valueOf(dest.subSequence(0, dstart))
+ filtered
+ dest.subSequence(dend, dest.length());
String str = String.valueOf(result).toLowerCase();
for (String val : mDisplayedValues) {
val = val.toLowerCase();
if (val.startsWith(str)) {
return filtered;
}
}
return "";
}
示例3: filter
import android.text.Spanned; //导入方法依赖的package包/类
@Override
public CharSequence filter(CharSequence source, int start, int end, Spanned dest, int dstart, int dend) {
String replacement = source.subSequence(start, end).toString();
String newVal = dest.subSequence(0, dstart).toString() + replacement
+ dest.subSequence(dend, dest.length()).toString();
Matcher matcher = mPattern.matcher(newVal);
if (matcher.matches())
return null;
if (TextUtils.isEmpty(source))
return dest.subSequence(dstart, dend);
else {
Toast.makeText(
context
, "Reason is at most three words, and must be shorter than 20 characters"
, Toast.LENGTH_SHORT)
.show();
return "";
}
}
示例4: createCurrencyFilter
import android.text.Spanned; //导入方法依赖的package包/类
private InputFilter[] createCurrencyFilter() {
final Pattern pattern = Pattern.compile("(0|[1-9][0-9]{0,8})?(\\.[0-9]{0,2})?");
return new InputFilter[]{
new InputFilter() {
@Override
public CharSequence filter(CharSequence source, int start, int end,
Spanned dest, int dstart, int dend) {
String result = dest.subSequence(0, dstart) + source.toString()
+ dest.subSequence(dend, dest.length());
Matcher matcher = pattern.matcher(result);
return matcher.matches() ? null : dest.subSequence(dstart, dend);
}
}
};
}
示例5: onTouchEvent
import android.text.Spanned; //导入方法依赖的package包/类
@Override
public boolean onTouchEvent(TextView widget, Spannable buffer, MotionEvent event) {
//http://stackoverflow.com/questions/1697084/handle-textview-link-click-in-my-android-app
int action = event.getAction();
if (action == MotionEvent.ACTION_UP) {
int x = (int) event.getX();
int y = (int) event.getY();
x -= widget.getTotalPaddingLeft();
y -= widget.getTotalPaddingTop();
x += widget.getScrollX();
y += widget.getScrollY();
Layout layout = widget.getLayout();
int line = layout.getLineForVertical(y);
int off = layout.getOffsetForHorizontal(line, x);
URLSpan[] link = buffer.getSpans(off, off, URLSpan.class);
if (link.length > 0) {
URLSpan span = link[0];
String url = span.getURL();
Spanned s = (Spanned) widget.getText();
int start = s.getSpanStart(span);
int end = s.getSpanEnd(span);
//http://stackoverflow.com/a/19750721/895797
String title = null;
if (start != -1 && end != -1) {
CharSequence wordThatWasClicked = s.subSequence(start, end);
title = wordThatWasClicked.toString();
}
onLinkClicked(widget, url, title);
return true;
}
}
return super.onTouchEvent(widget, buffer, event);
}
示例6: filter
import android.text.Spanned; //导入方法依赖的package包/类
/**
* source 新输入的字符串
* start 新输入的字符串起始下标,一般为0
* end 新输入的字符串终点下标,一般为source长度-1
* dest 输入之前文本框内容
* dstart 原内容起始坐标,一般为0
* dend 原内容终点坐标,一般为dest长度-1
*/
@Override
public CharSequence filter(CharSequence src, int start, int end, Spanned dest, int dstart, int dend) {
String ret = getString(src, start, end, dest, dstart, dend);
//Log.i(tag, src + "," + start + "," + end + "||" + dest + "," + dstart + "," + dend);
//Log.i(tag, ret);
//验证删除等按键
if ("".equals(src.toString())) {
if (ret.length() > 0) {
if (!legalNumber.matcher(ret).matches()) {
return dest.subSequence(dstart, dend);
}
if (Double.parseDouble(ret) > maxValue) {
return dest.subSequence(dstart, dend);
}
}
return null;
}
//验证小数点
if (".".equals(src.toString())) {
if (!legalNumber.matcher(ret).matches()) {
return dest.subSequence(dstart, dend);
}
return src.toString();
}
//验证数字
if (!oneNumber.matcher(src).matches()) {
return "";
}
if (!legalNumber.matcher(ret).matches()) {
return dest.subSequence(dstart, dend);
}
double number = Double.parseDouble(ret);
//Log.i(tag, "number:" + number);
//验证数字大小
if (number > maxValue) {
return dest.subSequence(dstart, dend);
}
//验证小数位精度是否正确
if (ret.contains(".")) {
int index = ret.indexOf(".");
int len = ret.length() - index - 1;
if (len > pointLen) {
return "";
}
}
return src.toString();
}
示例7: getString
import android.text.Spanned; //导入方法依赖的package包/类
private String getString(CharSequence src, int start, int end, Spanned dest, int dstart, int dend) {
CharSequence sectionA = dest.subSequence(0, dstart);
CharSequence sectionB = dest.subSequence(dend, dest.length());
return MessageFormat.format("{0}{1}{2}", sectionA, src, sectionB);
}