Example usage for android.text.style ReplacementSpan ReplacementSpan

List of usage examples for android.text.style ReplacementSpan ReplacementSpan

Introduction

In this page you can find the example usage for android.text.style ReplacementSpan ReplacementSpan.

Prototype

ReplacementSpan

Source Link

Usage

From source file:com.android.mail.browse.SubjectAndFolderView.java

public void setFolders(ConversationViewHeaderCallbacks callbacks, Account account, Conversation conv) {
    mVisibleFolders = true;/*  ww w  . j a v  a  2 s.c  o  m*/
    final BidiFormatter bidiFormatter = getBidiFormatter();
    final String wrappedSubject = mSubject == null ? "" : bidiFormatter.unicodeWrap(mSubject);
    final SpannableStringBuilder sb = new SpannableStringBuilder(wrappedSubject);
    sb.append('\u0020');
    final Settings settings = account.settings;
    final int start = sb.length();
    if (settings.importanceMarkersEnabled && conv.isImportant()) {
        sb.append(".\u0020");
        sb.setSpan(new ReplacementSpan() {
            @Override
            public int getSize(Paint paint, CharSequence text, int start, int end, Paint.FontMetricsInt fm) {
                return mImportanceMarkerDrawable.getIntrinsicWidth();
            }

            @Override
            public void draw(Canvas canvas, CharSequence text, int start, int end, float x, int top,
                    int baseline, int bottom, Paint paint) {
                canvas.save();
                final int transY = baseline + mChipVerticalOffset
                        - mImportanceMarkerDrawable.getIntrinsicHeight();
                canvas.translate(x, transY);
                mImportanceMarkerDrawable.draw(canvas);
                canvas.restore();
            }
        }, start, start + 1, Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
    }

    mFolderDisplayer.loadConversationFolders(conv, null /* ignoreFolder */, -1 /* ignoreFolderType */);
    mFolderDisplayer.constructFolderChips(sb);

    final int end = sb.length();
    sb.setSpan(new ChangeLabelsSpan(callbacks), start, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);

    setText(sb);
    setMovementMethod(LinkMovementMethod.getInstance());
}