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

This code example shows how to use the following methods:setSpan, length
                       .replace(",", " ");  // Make sure we leave a space between parts of names.
        } 
 
        String nameAndNumber = RecipientsFormatter.formatNameAndNumber(name, number);
 
        SpannableString out = new SpannableString(nameAndNumber);
        int len = out.length();
 
        if (!TextUtils.isEmpty(name)) {
            out.setSpan(new Annotation("name", name), 0, len,
                        Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        } else { 
            out.setSpan(new Annotation("name", number), 0, len,
                        Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        } 
 
        String person_id = cursor.getString(RecipientsAdapter.CONTACT_ID_INDEX);
        out.setSpan(new Annotation("person_id", person_id), 0, len,
                    Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        out.setSpan(new Annotation("label", displayLabel.toString()), 0, len,

8
CodeRank
This code example shows how to use the following methods:setSpan, length, toString
        //    body = body.substring(0, LengthBody); 
 
        body = body.replaceAll("<img[^>]*>", "");
        body = body.replaceAll("<video[^>]*>", "");        
 
        SpannableString bodyStringSpannable = new SpannableString(Html.fromHtml(body));
        bodyStringSpannable.setSpan(bodyForegroundColor, 0, bodyStringSpannable.length(), Spannable.SPAN_INCLUSIVE_INCLUSIVE);
 
        String bodyString = bodyStringSpannable.toString().trim();
         
        if(bodyString.length() > LengthBody)
            bodyString = bodyString.substring(0, LengthBody);
 
        return bodyString;
    } 
 
	@Override 
	public View newView(Context cont, Cursor cursor, ViewGroup parent) {
		// when the view will be created for first time, 
        // we need to tell the adapters, how each item will look 
7
CodeRank
This code example shows how to use the following methods:toHtml, setSpan, length
 
    @SmallTest 
    public void testBlockquote() throws Exception { 
        SpannableString s;
 
        s = new SpannableString("Hello world");
        s.setSpan(new QuoteSpan(), 0, s.length(), Spannable.SPAN_PARAGRAPH);
        assertEquals(Html.toHtml(s), "<blockquote><p>Hello world</p>\n</blockquote>\n");
 
        s = new SpannableString("Hello\n\nworld");
        s.setSpan(new QuoteSpan(), 0, 7, Spannable.SPAN_PARAGRAPH);
        assertEquals(Html.toHtml(s), "<blockquote><p>Hello</p>\n</blockquote>\n<p>world</p>\n");
    } 
 
    @SmallTest 
    public void testEntities() throws Exception { 
        SpannableString s;
 
        s = new SpannableString("Hello <&> world");
        assertEquals(Html.toHtml(s), "<p>Hello &lt;&amp;&gt; world</p>\n");
7
CodeRank
This code example shows how to use the following methods:setSpan, length
	 *         input string will be displayed using the Roboto Condensed font (if the OS has this) 
	 */ 
	public static SpannableString buildCondensedFontString(String string) {
		if (string == null)
			return null; 
		SpannableString s = new SpannableString(string);
		s.setSpan(new TypefaceSpan("sans-serif-condensed"), 0, s.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
		return s;
	} 
 
} 
7
CodeRank
This code example shows how to use the following methods:addLinks, setMessage
    public static SpannableString getLinkifiedText(Context context, int textId) {
        return getLinkifiedText(context.getText(textId));
    } 
 
    public static SpannableString getLinkifiedText(CharSequence text) {
        final SpannableString msg = new SpannableString(text);
        Linkify.addLinks(msg, Linkify.ALL);
        return msg;
    } 
 
    /* 
     * confirmation dialogs 
     */ 
 
    public static AlertDialog.Builder buildConfirmationDialog(Context context, int titleId, int msgId) {
        return new AlertDialog.Builder(context)
            .setTitle(titleId)
            .setMessage(getLinkifiedText(context, msgId));
    } 
 

6
CodeRank
This code example shows how to use the following methods:setSpan, setText, length
    super.onCreate(paramBundle);
    requestWindowFeature(1);
    setContentView(2130903073);
    ((TextView)findViewById(2131230727)).setText(getString(2131428743));
    ((TextView)findViewById(2131230728)).setVisibility(8);
    SpannableString localSpannableString = new SpannableString(getString(2131428770));
    localSpannableString.setSpan(new a(this), localSpannableString.length() - 44, localSpannableString.length(), 17);
    localSpannableString.setSpan(new ForegroundColorSpan(getResources().getColor(2131296283)), localSpannableString.length() - 44, localSpannableString.length(), 34);
    ((TextView)findViewById(2131230932)).setText(localSpannableString);
    ((TextView)findViewById(2131230932)).setMovementMethod(LinkMovementMethod.getInstance());
  } 
} 
 
/* Location:           C:\Users\sandrocheng.21KUNPENG\Desktop\classes_dex2jar\ 
 * Qualified Name:     com.ijinshan.bootmanager.activity.AutoBootHelpActivity 
 * JD-Core Version:    0.6.2 
 */ 
6
CodeRank
This code example shows how to use the following methods:setSpan
		default: 
			fontSpan = new TypefaceSpan("sans-serif");
			break; 
		} 
 
		SpannableString ss = new SpannableString(text);
		if (titleEnd > 0) {
			ss.setSpan(new StyleSpan(face), 0, titleEnd,
					Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
			ss.setSpan(new RelativeSizeSpan(titleRelSize), 0, titleEnd,
					Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
			ss.setSpan(fontSpan, 0, titleEnd,
					Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
		} 
 
		return ss;
	} 
 
	@Override 
	public boolean onTouchEvent(MotionEvent event) {
6
CodeRank
This code example shows how to use the following methods:setSpan, length
 
        if (forceUpdate || changed || (mSubject == null && mSnippet == null) /* first time */) {
            SpannableStringBuilder ssb = new SpannableStringBuilder();
            boolean hasSubject = false;
            if (!TextUtils.isEmpty(mSubject)) {
                SpannableString ss = new SpannableString(mSubject);
                ss.setSpan(new StyleSpan(mRead ? Typeface.NORMAL : Typeface.BOLD), 0, ss.length(),
                        Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
                ssb.append(ss);
                hasSubject = true;
            } 
            if (!TextUtils.isEmpty(mSnippet)) {
                if (hasSubject) {
                    ssb.append(sSubjectSnippetDivider);
                } 
                ssb.append(mSnippet);
            } 
            mText = ssb;
            requestLayout();
        } 
7
CodeRank
This code example shows how to use the following methods:setSpan
        super(context, attrs);
    } 
 
    @Override 
    public void setText(CharSequence text, BufferType type) {
        SpannableString content = new SpannableString(text + " \u00BB");
        content.setSpan(new UnderlineSpan(), 0, text.length(), 0);
 
        super.setText(content, BufferType.SPANNABLE);
    } 
} 
6
CodeRank
This code example shows how to use the following methods:setSpan, length
                       .replace(",", " ");  // Make sure we leave a space between parts of names.
        } 
 
        String nameAndNumber = Contact.formatNameAndNumber(name, number);
 
        SpannableString out = new SpannableString(nameAndNumber);
        int len = out.length();
 
        if (!TextUtils.isEmpty(name)) {
            out.setSpan(new Annotation("name", name), 0, len,
                        Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        } else { 
            out.setSpan(new Annotation("name", number), 0, len,
                        Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        } 
 
        String person_id = cursor.getString(RecipientsAdapter.CONTACT_ID_INDEX);
        out.setSpan(new Annotation("person_id", person_id), 0, len,
                    Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        out.setSpan(new Annotation("label", displayLabel.toString()), 0, len,

6
CodeRank

Related Android SpannableString Questions & Answers:

See Code Examples for Android SpannableString Methods: