Search in sources :

Example 66 with SpannableString

use of android.text.SpannableString in project k-9 by k9mail.

the class MessageHeader method populateAdditionalHeadersView.

/**
     * Set up the additional headers text view with the supplied header data.
     *
     * @param additionalHeaders List of header entries. Each entry consists of a header
     *                          name and a header value. Header names may appear multiple
     *                          times.
     *                          <p/>
     *                          This method is always called from within the UI thread by
     *                          {@link #showAdditionalHeaders()}.
     */
private void populateAdditionalHeadersView(final List<HeaderEntry> additionalHeaders) {
    SpannableStringBuilder sb = new SpannableStringBuilder();
    boolean first = true;
    for (HeaderEntry additionalHeader : additionalHeaders) {
        if (!first) {
            sb.append("\n");
        } else {
            first = false;
        }
        StyleSpan boldSpan = new StyleSpan(Typeface.BOLD);
        SpannableString label = new SpannableString(additionalHeader.label + ": ");
        label.setSpan(boldSpan, 0, label.length(), 0);
        sb.append(label);
        sb.append(MimeUtility.unfoldAndDecode(additionalHeader.value));
    }
    mAdditionalHeadersView.setText(sb);
}
Also used : SpannableString(android.text.SpannableString) StyleSpan(android.text.style.StyleSpan) SpannableStringBuilder(android.text.SpannableStringBuilder)

Example 67 with SpannableString

use of android.text.SpannableString in project k-9 by k9mail.

the class MessageListRemoteViewFactory method bold.

private CharSequence bold(String text) {
    SpannableString spannableString = new SpannableString(text);
    spannableString.setSpan(new StyleSpan(Typeface.BOLD), 0, text.length(), 0);
    return spannableString;
}
Also used : SpannableString(android.text.SpannableString) StyleSpan(android.text.style.StyleSpan)

Example 68 with SpannableString

use of android.text.SpannableString in project Android-Developers-Samples by johnjohndoe.

the class MainActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.sample_main);
    // BEGIN_INCLUDE(text_auto_linkify)
    /*
         *  text_auto_linkify shows the android:autoLink property, which
         *  automatically linkifies things like URLs and phone numbers
         *  found in the text. No java code is needed to make this
         *  work.
         *  This can also be enabled programmatically by calling
         *  .setAutoLinkMask(Linkify.ALL) before the text is set on the TextView.
         *
         *  See android.text.util.Linkify for other options, for example only
         *  auto-linking email addresses or phone numbers
         */
    // END_INCLUDE(text_auto_linkify)
    // BEGIN_INCLUDE(text_html_resource)
    /*
         * text_html_resource has links specified by putting anchor tags (<a>) in the string
         * resource. By default these links will appear but not
         * respond to user input. To make them active, you need to
         * call setMovementMethod() on the TextView object.
         */
    TextView textViewResource = (TextView) findViewById(R.id.text_html_resource);
    textViewResource.setText(Html.fromHtml(getResources().getString(R.string.link_text_manual)));
    textViewResource.setMovementMethod(LinkMovementMethod.getInstance());
    // END_INCLUDE(text_html_resource)
    // BEGIN_INCLUDE(text_html_program)
    /*
         * text_html_program shows creating text with links from HTML in the Java
         * code, rather than from a string resource. Note that for a
         * fixed string, using a (localizable) resource as shown above
         * is usually a better way to go; this example is intended to
         * illustrate how you might display text that came from a
         * dynamic source (eg, the network).
         */
    TextView textViewHtml = (TextView) findViewById(R.id.text_html_program);
    textViewHtml.setText(Html.fromHtml("<b>text_html_program: Constructed from HTML programmatically.</b>" + "  Text with a <a href=\"http://www.google.com\">link</a> " + "created in the Java source code using HTML."));
    textViewHtml.setMovementMethod(LinkMovementMethod.getInstance());
    // END_INCLUDE(text_html_program)
    // BEGIN_INCLUDE(text_spannable)
    /*
         * text_spannable illustrates constructing a styled string containing a
         * link without using HTML at all. Again, for a fixed string
         * you should probably be using a string resource, not a
         * hardcoded value.
         */
    SpannableString ss = new SpannableString("text_spannable: Manually created spans. Click here to dial the phone.");
    /*
         * Make the first 38 characters bold by applying a StyleSpan with bold typeface.
         *
         * Characters 45 to 49 (the word "here") is made clickable by applying a URLSpan
         * pointing to a telephone number. Clicking it opens the "tel:" URL that starts the dialer.
         *
         * The SPAN_EXCLUSIVE_EXCLUSIVE flag defines this span as exclusive, which means
         * that it will not expand to include text inserted on either side of this span.
         */
    ss.setSpan(new StyleSpan(Typeface.BOLD), 0, 39, Spanned.SPAN_INCLUSIVE_INCLUSIVE);
    ss.setSpan(new URLSpan("tel:4155551212"), 40 + 6, 40 + 10, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
    TextView textViewSpan = (TextView) findViewById(R.id.text_spannable);
    textViewSpan.setText(ss);
    /*
         * Set the movement method to move between links in this TextView.
         * This means that the user traverses through links in this TextView, automatically
         * handling appropriate scrolling and key commands.
         */
    textViewSpan.setMovementMethod(LinkMovementMethod.getInstance());
// END_INCLUDE(text_spannable)
}
Also used : SpannableString(android.text.SpannableString) StyleSpan(android.text.style.StyleSpan) TextView(android.widget.TextView) URLSpan(android.text.style.URLSpan)

Example 69 with SpannableString

use of android.text.SpannableString in project NoHttp by yanzhenjie.

the class ResCompat method getColorText.

public static SpannableString getColorText(CharSequence content, int start, int end, int color) {
    SpannableString stringSpan = new SpannableString(content);
    stringSpan.setSpan(new ForegroundColorSpan(color), start, end, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
    return stringSpan;
}
Also used : SpannableString(android.text.SpannableString) ForegroundColorSpan(android.text.style.ForegroundColorSpan)

Example 70 with SpannableString

use of android.text.SpannableString in project NoHttp by yanzhenjie.

the class ResCompat method getImageSpanText.

public static SpannableString getImageSpanText(CharSequence content, Drawable drawable, int start, int end) {
    SpannableString stringSpan = new SpannableString(content);
    setDrawableBounds(drawable);
    ImageSpan imageSpan = new ImageSpan(drawable, ImageSpan.ALIGN_BASELINE);
    stringSpan.setSpan(imageSpan, start, end, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
    return stringSpan;
}
Also used : SpannableString(android.text.SpannableString) ImageSpan(android.text.style.ImageSpan)

Aggregations

SpannableString (android.text.SpannableString)325 TextView (android.widget.TextView)61 Spannable (android.text.Spannable)60 View (android.view.View)57 StyleSpan (android.text.style.StyleSpan)53 ForegroundColorSpan (android.text.style.ForegroundColorSpan)47 TextPaint (android.text.TextPaint)25 Spanned (android.text.Spanned)24 TextAppearanceSpan (android.text.style.TextAppearanceSpan)21 Paint (android.graphics.Paint)20 RelativeSizeSpan (android.text.style.RelativeSizeSpan)19 ImageView (android.widget.ImageView)19 Bundle (android.os.Bundle)17 TypedValue (android.util.TypedValue)17 SmallTest (android.test.suitebuilder.annotation.SmallTest)16 Intent (android.content.Intent)15 SpannableStringBuilder (android.text.SpannableStringBuilder)15 ClickableSpan (android.text.style.ClickableSpan)14 URLSpan (android.text.style.URLSpan)13 LayoutInflater (android.view.LayoutInflater)13