Search in sources :

Example 21 with SpannableStringBuilder

use of android.text.SpannableStringBuilder in project android_frameworks_base by ParanoidAndroid.

the class SmileyParser method getSpannableString.

/**
     * Retrieves the parsed text as a spannable string object.
     * @param context the context for fetching smiley resources.
     * @return the spannable string as CharSequence.
     */
public CharSequence getSpannableString(Context context) {
    SpannableStringBuilder builder = new SpannableStringBuilder();
    if (getPartCount() == 0) {
        return "";
    }
    // should have only one part since we parse smiley only
    Part part = getPart(0);
    ArrayList<Token> tokens = part.getTokens();
    int len = tokens.size();
    for (int i = 0; i < len; i++) {
        Token token = tokens.get(i);
        int start = builder.length();
        builder.append(token.getRawText());
        if (token.getType() == AbstractMessageParser.Token.Type.SMILEY) {
            int resid = mRes.getSmileyRes(token.getRawText());
            if (resid != -1) {
                builder.setSpan(new ImageSpan(context, resid), start, builder.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
            }
        }
    }
    return builder;
}
Also used : SpannableStringBuilder(android.text.SpannableStringBuilder) ImageSpan(android.text.style.ImageSpan)

Example 22 with SpannableStringBuilder

use of android.text.SpannableStringBuilder in project plaid by nickbutcher.

the class ImageSpanTarget method onResourceReady.

@Override
public void onResourceReady(Bitmap bitmap, GlideAnimation<? super Bitmap> glideAnimation) {
    TextView tv = textView.get();
    if (tv != null) {
        BitmapDrawable bitmapDrawable = new BitmapDrawable(tv.getResources(), bitmap);
        // image span doesn't handle scaling so we manually set bounds
        if (bitmap.getWidth() > tv.getWidth()) {
            float aspectRatio = (float) bitmap.getHeight() / (float) bitmap.getWidth();
            bitmapDrawable.setBounds(0, 0, tv.getWidth(), (int) (aspectRatio * tv.getWidth()));
        } else {
            bitmapDrawable.setBounds(0, 0, bitmap.getWidth(), bitmap.getHeight());
        }
        ImageSpan span = new ImageSpan(bitmapDrawable);
        // add the image span and remove our marker
        SpannableStringBuilder ssb = new SpannableStringBuilder(tv.getText());
        int start = ssb.getSpanStart(loadingSpan);
        int end = ssb.getSpanEnd(loadingSpan);
        if (start >= 0 && end >= 0) {
            ssb.setSpan(span, start, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        }
        ssb.removeSpan(loadingSpan);
        // animate the change
        TransitionManager.beginDelayedTransition((ViewGroup) tv.getParent());
        tv.setText(ssb);
    }
}
Also used : TextView(android.widget.TextView) BitmapDrawable(android.graphics.drawable.BitmapDrawable) SpannableStringBuilder(android.text.SpannableStringBuilder) ImageSpan(android.text.style.ImageSpan)

Example 23 with SpannableStringBuilder

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

the class NotificationContentCreator method buildMessageSummary.

private CharSequence buildMessageSummary(String sender, String subject) {
    if (sender == null) {
        return subject;
    }
    SpannableStringBuilder summary = new SpannableStringBuilder();
    summary.append(sender);
    summary.append(" ");
    summary.append(subject);
    summary.setSpan(getEmphasizedSpan(), 0, sender.length(), 0);
    return summary;
}
Also used : SpannableStringBuilder(android.text.SpannableStringBuilder)

Example 24 with SpannableStringBuilder

use of android.text.SpannableStringBuilder 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 25 with SpannableStringBuilder

use of android.text.SpannableStringBuilder in project plaid by nickbutcher.

the class HomeActivity method setNoFiltersEmptyTextVisibility.

private void setNoFiltersEmptyTextVisibility(int visibility) {
    if (visibility == View.VISIBLE) {
        if (noFiltersEmptyText == null) {
            // create the no filters empty text
            ViewStub stub = (ViewStub) findViewById(R.id.stub_no_filters);
            noFiltersEmptyText = (TextView) stub.inflate();
            String emptyText = getString(R.string.no_filters_selected);
            int filterPlaceholderStart = emptyText.indexOf('ࢴ');
            int altMethodStart = filterPlaceholderStart + 3;
            SpannableStringBuilder ssb = new SpannableStringBuilder(emptyText);
            // show an image of the filter icon
            ssb.setSpan(new ImageSpan(this, R.drawable.ic_filter_small, ImageSpan.ALIGN_BASELINE), filterPlaceholderStart, filterPlaceholderStart + 1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
            // make the alt method (swipe from right) less prominent and italic
            ssb.setSpan(new ForegroundColorSpan(ContextCompat.getColor(this, R.color.text_secondary_light)), altMethodStart, emptyText.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
            ssb.setSpan(new StyleSpan(Typeface.ITALIC), altMethodStart, emptyText.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
            noFiltersEmptyText.setText(ssb);
            noFiltersEmptyText.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View v) {
                    drawer.openDrawer(GravityCompat.END);
                }
            });
        }
        noFiltersEmptyText.setVisibility(visibility);
    } else if (noFiltersEmptyText != null) {
        noFiltersEmptyText.setVisibility(visibility);
    }
}
Also used : ViewStub(android.view.ViewStub) ForegroundColorSpan(android.text.style.ForegroundColorSpan) StyleSpan(android.text.style.StyleSpan) ImageView(android.widget.ImageView) BindView(butterknife.BindView) View(android.view.View) TextView(android.widget.TextView) RecyclerView(android.support.v7.widget.RecyclerView) SpannableStringBuilder(android.text.SpannableStringBuilder) ImageSpan(android.text.style.ImageSpan)

Aggregations

SpannableStringBuilder (android.text.SpannableStringBuilder)705 TextView (android.widget.TextView)114 ForegroundColorSpan (android.text.style.ForegroundColorSpan)112 View (android.view.View)100 StyleSpan (android.text.style.StyleSpan)85 ImageSpan (android.text.style.ImageSpan)77 Test (org.junit.Test)65 SpannableString (android.text.SpannableString)55 Drawable (android.graphics.drawable.Drawable)44 TextPaint (android.text.TextPaint)43 Intent (android.content.Intent)42 Spanned (android.text.Spanned)38 RelativeSizeSpan (android.text.style.RelativeSizeSpan)38 Paint (android.graphics.Paint)34 Spannable (android.text.Spannable)33 ImageView (android.widget.ImageView)31 ArrayList (java.util.ArrayList)28 Typeface (android.graphics.Typeface)26 Context (android.content.Context)25 SuppressLint (android.annotation.SuppressLint)24