當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。