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


Java Spanned.subSequence方法代码示例

本文整理汇总了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;
}
 
开发者ID:rafjordao,项目名称:Nird2,代码行数:21,代码来源:UiUtils.java

示例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 "";
}
 
开发者ID:sdrausty,项目名称:buildAPKsApps,代码行数:19,代码来源:NumberPicker.java

示例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 "";
    }
}
 
开发者ID:CMPUT301W17T17,项目名称:MoodSwings,代码行数:21,代码来源:TextInputFilter.java

示例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);
                }
            }
    };
}
 
开发者ID:mvescovo,项目名称:item-reaper,代码行数:16,代码来源:EditItemFragment.java

示例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);
}
 
开发者ID:Commit451,项目名称:InternalLinkMovementMethod,代码行数:38,代码来源:InternalLinkMovementMethod.java

示例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();
}
 
开发者ID:yanweiqiang,项目名称:MyWidgetSample,代码行数:65,代码来源:NumberFilter.java

示例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);
}
 
开发者ID:yanweiqiang,项目名称:MyWidgetSample,代码行数:6,代码来源:NumberFilter.java


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