Android SpannedString - 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 SpannedString class.

This code example shows how to use the following methods:getSpanStart, getSpans, length
		assertEquals("https://github.com/Uncodin/bypass", spans[0].getURL());
	} 
	 
	public void testHeaderOrder() { 
		SpannedString spannable = (SpannedString) bypass.markdownToSpannable("Header!!\n--------\nText goes here or something\n*One* **Two** ***Three***\n");
		RelativeSizeSpan[] sizeSpan = spannable.getSpans(0, spannable.length(), RelativeSizeSpan.class);
		assertEquals(1, sizeSpan.length);
		assertEquals(0, spannable.getSpanStart(sizeSpan[0]));
	} 
 
	public void testCodeSpan() { 
		Spannable spannable = (Spannable) bypass.markdownToSpannable("`code`");
		TypefaceSpan[] spans = spannable.getSpans(0, spannable.length(), TypefaceSpan.class);
		assertEquals(1, spans.length);
		assertEquals(0, spannable.getSpanStart(spans[0]));
	} 
} 
8
CodeRank
This code example shows how to use the following methods:
 
        // First test with a SpannableStringBuilder, as opposed to SpannedString 
        checkPostProcess(HtmlUtils.postprocess(getContext(), builder));
 
        // Then pass a SpannedString, which is immutable, but the method should still work. 
        checkPostProcess(HtmlUtils.postprocess(getContext(), new SpannedString(builder)));
    } 
 
    /** 
     * Same as {@link #testPostProcess_with_newlines}, but text has no newlines. 
     * (The internal code path is slightly different.) 
     */ 
    public void testPostProcess_no_newlines() { 
        final SpannableStringBuilder builder = new SpannableStringBuilder("01234");
 
        setSpans(builder);
 
        // First test with a SpannableStringBuilder, as opposed to SpannedString 
        checkPostProcess(HtmlUtils.postprocess(getContext(), builder));
 
7
CodeRank
This code example shows how to use the following methods:
 
        // First test with a SpannableStringBuilder, as opposed to SpannedString 
        checkPostProcess(HtmlUtils.postprocess(getContext(), builder));
 
        // Then pass a SpannedString, which is immutable, but the method should still work. 
        checkPostProcess(HtmlUtils.postprocess(getContext(), new SpannedString(builder)));
    } 
 
    /** 
     * Same as {@link #testPostProcess_with_newlines}, but text has no newlines. 
     * (The internal code path is slightly different.) 
     */ 
    public void testPostProcess_no_newlines() { 
        final SpannableStringBuilder builder = new SpannableStringBuilder("01234");
 
        setSpans(builder);
 
        // First test with a SpannableStringBuilder, as opposed to SpannedString 
        checkPostProcess(HtmlUtils.postprocess(getContext(), builder));
 
6
CodeRank
This code example shows how to use the following methods:
        mTextView.myDraw(mCanvas);
    } 
 
    @SmallTest 
    public void testSpan() throws Exception { 
        CharSequence charSeq = new SpannedString(mString);
        mTextView.setText(charSeq);
 
        mTextView.myDraw(mCanvas);
        mTextView.myDraw(mCanvas);
        mTextView.myDraw(mCanvas);
        mTextView.myDraw(mCanvas);
        mTextView.myDraw(mCanvas);
        mTextView.myDraw(mCanvas);
        mTextView.myDraw(mCanvas);
        mTextView.myDraw(mCanvas);
        mTextView.myDraw(mCanvas);
        mTextView.myDraw(mCanvas);
    } 
 
5
CodeRank
This code example shows how to use the following methods:toHtml
		settings.setDisplayZoomControls(false);
//		settings.setDefaultZoom(WebSettings.ZoomDensity.CLOSE); 
		settings.enableSmoothTransition();
		settings.setDefaultFontSize(14);
		 
		SpannedString s = new SpannedString(TablatureHolder.getInstance().getSelectedTab().getDetails());
		webview.loadData(Html.toHtml(s), "text/html", null);
		return webview;
	} 
 
	private View getLinkView() {
		// url 
		TextView textView2 = new TextView(getActivity());
		textView2.setGravity(Gravity.CENTER);
		textView2.setText(TablatureHolder.getInstance().getSelectedTab().getUrl());
		Linkify.addLinks(textView2, Linkify.ALL);
		return textView2;
	} 
} 
4
CodeRank
This code example shows how to use the following methods:
        mTextView.myDraw(mCanvas);
    } 
 
    @SmallTest 
    public void testSpan() throws Exception { 
        CharSequence charSeq = new SpannedString(mString);
        mTextView.setText(charSeq);
 
        mTextView.myDraw(mCanvas);
        mTextView.myDraw(mCanvas);
        mTextView.myDraw(mCanvas);
        mTextView.myDraw(mCanvas);
        mTextView.myDraw(mCanvas);
        mTextView.myDraw(mCanvas);
        mTextView.myDraw(mCanvas);
        mTextView.myDraw(mCanvas);
        mTextView.myDraw(mCanvas);
        mTextView.myDraw(mCanvas);
    } 
 
4
CodeRank
This code example shows how to use the following methods:
		 
		updatePosition(); 
	} 
	 
	public void clearText() { 
		this.text = new SpannedString("");		
	}	 
	 
	public void clearStoredPosition() { 
		//No-op		 
	} 
	 
	public void reset() { 
		this.storedPosition = 0;
		this.text = new SpannedString("");
	} 
	 
	public void updatePosition() {	 
		 
		if ( this.text.length() == 0 ) {
3
CodeRank
This code example shows how to use the following methods:
     * 
     * @param source the string to be transformed 
     * @return spanned text 
     */ 
    public static Spanned fromHtml(String source) {
        if (source == null || TextUtils.isEmpty(source)) return new SpannedString("");
 
        source = source.replace(System.getProperty("line.separator"), "<br/>");
 
        try { 
            return Html.fromHtml(source);
        } catch (RuntimeException e) {
            if (e.getCause() instanceof IOException) {
                // Pushback buffer full, retry with smaller input 
                return fromHtml(source.substring(0, source.length() / 2));
            } else { 
                throw e;
            } 
        } 
    } 
4
CodeRank

Related Android SpannedString Questions & Answers:

See Code Examples for Android SpannedString Methods: