Android Spannable - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Android Spannable class.

This code example shows how to use the following methods: removeSpan, setSpan, getSpanEnd, getSpanStart, getSpans
7
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods: removeSpan, setSpan, getSpanStart, length
        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)
            output.setSpan(span, start, length, SPAN_EXCLUSIVE_EXCLUSIVE);
    } 
 
    /** 
     * Encode HTML 
     * 
     * @param html 
     * @return html 
     */ 
    public static CharSequence encode(final String html) {
Full Snippet Info
8
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
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]));
	} 
Full Snippet Info
8
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
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
Connect your IDE to all the code out there  Get Codota for Java
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);
Full Snippet Info
8
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods: setSpan
     * @param result The result to highlight 
     * @return CharSequence The non highlighted name string 
     */ 
    public static CharSequence getNonHighlightedName(SearchResult result) {
        String name = result.getFso().getName();
        Spannable span = new SpannableString(name);
        span.setSpan(new StyleSpan(Typeface.BOLD), 0, name.length(), 0);
        return span;
    } 
 
    /** 
     * Method that converts the list of file system object to a search result. 
     * 
     * @param files The files to convert 
     * @param queries The terms of the search 
     * @return List<SearchResult> The files converted 
     */ 
    public static List<SearchResult> convertToResults(List<FileSystemObject> files, Query queries) {
        //Converts the list of files in a list of search results 
        List<SearchResult> results = new ArrayList<SearchResult>(files.size());
Full Snippet Info
6
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
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; 
				} 
			} 
 
Full Snippet Info
7
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
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);
	} 
} 
Full Snippet Info
6
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods: append, insert, setSpan, length, toString
            handleListTag(output);
    } 
 
    private void handleListTag(Editable output) {
        if (mListParents.lastElement().equals("ul")) {
            output.append("\n");
            String[] split = output.toString().split("\n");
 
            int lastIndex = split.length - 1;
            int start = output.length() - split[lastIndex].length() - 1;
            output.setSpan(new BulletSpan(15 * mListParents.size()), start,
                    output.length(), 0);
        } else if (mListParents.lastElement().equals("ol")) {
            mListItemCount++;
 
            output.append("\n");
            String[] split = output.toString().split("\n");
 
            int lastIndex = split.length - 1;
            int start = output.length() - split[lastIndex].length() - 1;

7
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods: setSpan, length
        header = serverName.toUpperCase();
        setText(header);
    } 
 
    public void setDisconnected() { 
        Spannable wordToSpan = new SpannableString(header + " (DISCONNECTED)");
        wordToSpan.setSpan(new ForegroundColorSpan(0xFFFF4444), header.length(), wordToSpan.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        setText(wordToSpan);
    } 
 
    public void setConnected() { 
        setText(header);
    } 
} 
Full Snippet Info
6
CodeRank
Connect your IDE to all the code out there  Get Codota for Java

Related Android Spannable Questions & Answers:

See Code Examples for Android Spannable Methods: