Spanned getSpans - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Spanned getSpans method.

This code example shows how to use the following methods:getSpans, length, toString
        builder.setSpan(new CustomSpan(), 4, builder.length(), 0);
    } 
 
    private void checkPostProcess(Spanned ret) {
        // Newlines should be trimmed. 
        assertEquals("01234", ret.toString());
 
        // First, check the image span. 
        // - Vertical alignment should be changed to ALIGN_BASELINE 
        // - Drawable shouldn't be changed. 
        ImageSpan[] imageSpans = ret.getSpans(0, ret.length(), ImageSpan.class);
        assertEquals(1, imageSpans.length);
        assertEquals(ImageSpan.ALIGN_BASELINE, imageSpans[0].getVerticalAlignment());
        assertEquals(ColorDrawable.class, imageSpans[0].getDrawable().getClass());
 
        // QuoteSpans should be replaced with StreamItemQuoteSpans. 
        QuoteSpan[] quoteSpans = ret.getSpans(0, ret.length(), QuoteSpan.class);
        assertEquals(1, quoteSpans.length);
        assertEquals(StreamItemQuoteSpan.class, quoteSpans[0].getClass());
 

8
CodeRank
This code example shows how to use the following methods:getSpans, charAt, length
		bypass.markdownToSpannable("");
	} 
 
	public void testHeaderString() { 
		Spannable spannable = (Spannable) bypass.markdownToSpannable("Header!!\n--------");
		StyleSpan[] spans = spannable.getSpans(0, spannable.length(), StyleSpan.class);
		assertEquals(1, spans.length);
		RelativeSizeSpan[] sizeSpan = spannable.getSpans(0, spannable.length(), RelativeSizeSpan.class);
		assertEquals(1, sizeSpan.length);
		assertEquals('\n', spannable.charAt(spannable.length() - 1));
	} 
	 
	public void testBoldString() { 
		Spannable spannable = (Spannable) bypass.markdownToSpannable("One **Two** Three");
		StyleSpan[] spans = spannable.getSpans(0, spannable.length(), StyleSpan.class);
		assertEquals(1, spans.length);
		assertEquals(Typeface.BOLD, spans[0].getStyle());
		assertEquals(4, spannable.getSpanStart(spans[0]));
		assertEquals(7, spannable.getSpanEnd(spans[0]));
	} 
8
CodeRank
This code example shows how to use the following methods:getSpans, length, toString
        builder.setSpan(new CustomSpan(), 4, builder.length(), 0);
    } 
 
    private void checkPostProcess(Spanned ret) {
        // Newlines should be trimmed. 
        assertEquals("01234", ret.toString());
 
        // First, check the image span. 
        // - Vertical alignment should be changed to ALIGN_BASELINE 
        // - Drawable shouldn't be changed. 
        ImageSpan[] imageSpans = ret.getSpans(0, ret.length(), ImageSpan.class);
        assertEquals(1, imageSpans.length);
        assertEquals(ImageSpan.ALIGN_BASELINE, imageSpans[0].getVerticalAlignment());
        assertEquals(ColorDrawable.class, imageSpans[0].getDrawable().getClass());
 
        // QuoteSpans should be replaced with StreamItemQuoteSpans. 
        QuoteSpan[] quoteSpans = ret.getSpans(0, ret.length(), QuoteSpan.class);
        assertEquals(1, quoteSpans.length);
        assertEquals(StreamItemQuoteSpan.class, quoteSpans[0].getClass());
 

8
CodeRank
This code example shows how to use the following methods:getSpans
        if (mTextView == null) {
            return super.commitText(text, newCursorPosition);
        } 
        if (text instanceof Spanned) {
            Spanned spanned = ((Spanned) text);
            SuggestionSpan[] spans = spanned.getSpans(0, text.length(), SuggestionSpan.class);
            mIMM.registerSuggestionSpansForNotification(spans);
        } 
 
        mTextView.resetErrorChangedFlag();
        boolean success = super.commitText(text, newCursorPosition);
        mTextView.hideErrorIfUnchanged();
 
        return success;
    } 
} 
6
CodeRank
This code example shows how to use the following methods:getSpans, length
            } 
        } 
    }; 
 
    private static Object getLast(final Spanned text, final Class<?> kind) {
        Object[] spans = text.getSpans(0, text.length(), kind);
        return spans.length > 0 ? spans[spans.length - 1] : null;
    } 
 
    private static void startSpan(Object span, Editable output) {
        int length = output.length();
        output.setSpan(span, length, length, SPAN_MARK_MARK);
    } 
 
    private static void endSpan(Class<?> type, Editable output) {
        int length = output.length();
        Object span = getLast(output, type);
        int start = output.getSpanStart(span);
        output.removeSpan(span);
        if (start != length)
7
CodeRank
This code example shows how to use the following methods:getSpans
 
			Layout layout = widget.getLayout();
			int line = layout.getLineForVertical(y);
			int off = layout.getOffsetForHorizontal(line, x);
 
			ClickableSpan[] links = buffer.getSpans(off, off,
					ClickableSpan.class);
 
			if (links.length != 0 && links[0] instanceof URLSpan) {
				HashMap args = new HashMap();
				args.put("url", ((URLSpan) links[0]).getURL());
				_proxy.fireEvent("click", args);
				return true; 
			} 
		} 
		return super.onTouchEvent(widget, buffer, event);
	} 
} 
6
CodeRank
This code example shows how to use the following methods:removeSelection, setSelection, getSpanEnd, getSpanStart, getSpans
 
            Layout layout = widget.getLayout();
            int line = layout.getLineForVertical(y);
            int off = layout.getOffsetForHorizontal(line, x);
 
            MyURLSpan[] link = buffer.getSpans(off, off, MyURLSpan.class);
 
            if (link.length != 0) {
                if (action == MotionEvent.ACTION_UP) {
                    if (!mHasPerformedLongPress) {
                        link[0].onClick(widget);
                    } 
                    pressed = false;
                    lastEvent = new float[2];
                } else if (action == MotionEvent.ACTION_DOWN) {
                    pressed = true;
                    lastEvent[0] = event.getX();
                    lastEvent[1] = event.getY();
                    checkForLongClick(link, widget);
                    Selection.setSelection(buffer,

8
CodeRank
This code example shows how to use the following methods:setSelection, getSpanEnd, getSpanStart, getSpans
 
                Layout layout = widget.getLayout();
                int line = layout.getLineForVertical(y);
                int off = layout.getOffsetForHorizontal(line, x);
 
                ClickableSpan[] link = buffer.getSpans(off, off, ClickableSpan.class);
 
                if (link.length != 0) {
                    if (action == MotionEvent.ACTION_UP) {
                        link[0].onClick(widget);
                    } else if (action == MotionEvent.ACTION_DOWN) {
                        Selection.setSelection(buffer, buffer.getSpanStart(link[0]), buffer.getSpanEnd(link[0]));
                    } 
                    linkHandled = true;
                    return true; 
                } 
            } 
        } 
        if (!linkHandled) {
            return super.onTouchEvent(event);
8
CodeRank
This code example shows how to use the following methods:removeSpan, setSpan, getSpanEnd, getSpanStart, getSpans
7
CodeRank
This code example shows how to use the following methods:setSelection, getSpanEnd, getSpanStart, getSpans
 
				Layout layout = widget.getLayout();
				int line = layout.getLineForVertical(y);
				int off = layout.getOffsetForHorizontal(line, x);
 
				ClickableSpan[] link = buffer.getSpans(off, off,
						ClickableSpan.class);
 
				if (link.length != 0) {
					if (action == MotionEvent.ACTION_UP) {
						link[0].onClick(widget);
					} 
					else if (action == MotionEvent.ACTION_DOWN) {
						Selection.setSelection(buffer,
								buffer.getSpanStart(link[0]),
								buffer.getSpanEnd(link[0]));
					} 
					return true; 
				} 
			} 
 
7
CodeRank

Related Spanned getSpans Questions & Answers:

getSpans Method Overview
Return an array of the markup objects attached to the specified slice of this CharSequence and whose type is the specified type or a subclass of it.
See Code Examples for other Android Spanned Methods: