Example usage for android.text.style DynamicDrawableSpan ALIGN_BASELINE

List of usage examples for android.text.style DynamicDrawableSpan ALIGN_BASELINE

Introduction

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

Prototype

int ALIGN_BASELINE

To view the source code for android.text.style DynamicDrawableSpan ALIGN_BASELINE.

Click Source Link

Document

A constant indicating that the bottom of this span should be aligned with the baseline of the surrounding text.

Usage

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

public void setFolders(ConversationViewHeaderCallbacks callbacks, Account account, Conversation conv) {
    mVisibleFolders = true;//from   w  w  w.  j a v  a2s  .com
    final BidiFormatter bidiFormatter = getBidiFormatter();
    if (TextUtils.isEmpty(mSubject)) {
        mSubject = conv.subject;
    }
    final SpannableStringBuilder sb = new SpannableStringBuilder(bidiFormatter.unicodeWrap(mSubject));
    sb.append('\u0020');
    final Settings settings = account.settings;
    final int start = sb.length();
    if (settings.importanceMarkersEnabled && conv.isImportant()) {
        sb.append(".\u0020");
        sb.setSpan(new DynamicDrawableSpan(DynamicDrawableSpan.ALIGN_BASELINE) {
            @Override
            public Drawable getDrawable() {
                Drawable d = getContext().getResources()
                        .getDrawable(R.drawable.ic_email_caret_none_important_unread);
                d.setBounds(0, 0, d.getIntrinsicWidth(), d.getIntrinsicHeight());
                return d;
            }
        }, start, start + 1, Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
    }

    //TS: yanhua.chen 2015-12-22 EMAIL BUGFIX_1178365 MOD_S
    //        mFolderDisplayer.loadConversationFolders(conv, null /* ignoreFolder */, -1 /* ignoreFolderType */);
    //        mFolderDisplayer.appendFolderSpans(sb, bidiFormatter);

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

    setText(sb);
    //TS: yanhua.chen 2015-11-4 EMAIL BUGFIX_851207 MOD_S
    //        if(isNeedMove()){
    //            setMovementMethod(LinkMovementMethod.getInstance());
    //        }
    //TS: yanhua.chen 2015-11-4 EMAIL BUGFIX_851207 MOD_E
    //TS: yanhua.chen 2015-12-22 EMAIL BUGFIX_1178365 MOD_E
}

From source file:com.vuze.android.remote.spanbubbles.SpanTags.java

public void setTagBubbles(final SpannableStringBuilder ss, String text, String token) {
    if (ss.length() > 0) {
        // hack to ensure descent is always added by TextView
        ss.append("\u200B");
    }/*from w w w .ja  v  a2 s  .  c  o m*/

    if (tvTags == null) {
        Log.e(TAG, "no tvTags");
        return;
    }

    TextPaint p = tvTags.getPaint();

    // Start and end refer to the points where the span will apply
    int tokenLen = token.length();
    int base = 0;

    if (showIcon && tagDrawables == null) {
        createDrawTagables();
    }

    while (true) {
        int start = text.indexOf(token, base);
        int end = text.indexOf(token, start + tokenLen);

        if (start < 0 || end < 0) {
            break;
        }

        base = end + tokenLen;

        final int fSpanStart = start;
        final int fSpanEnd = end + tokenLen;

        String id = text.substring(start + tokenLen, end);

        Map mapTag = null;
        try {
            long tagUID = Long.parseLong(id);
            mapTag = sessionInfo.getTag(tagUID);
        } catch (Throwable ignore) {
        }

        final String word = MapUtils.getMapString(mapTag, "name", "" + id);
        final Map fMapTag = mapTag;

        final DrawableTag imgDrawable = new DrawableTag(context, p, word, showIcon ? tagDrawables : null,
                mapTag, drawCount) {

            @Override
            public boolean isTagPressed() {
                if (!AndroidUtils.usesNavigationControl()) {
                    return false;
                }
                int selectionEnd = tvTags.getSelectionEnd();
                if (selectionEnd < 0) {
                    return false;
                }
                int selectionStart = tvTags.getSelectionStart();
                return selectionStart == fSpanStart && selectionEnd == fSpanEnd;
            }

            @Override
            public int getTagState() {
                if (listener == null) {
                    return TAG_STATE_SELECTED;
                }
                return listener.getTagState(fMapTag, word);
            }
        };

        if (countFontRatio > 0) {
            imgDrawable.setCountFontRatio(countFontRatio);
        }

        imgDrawable.setBounds(0, 0, imgDrawable.getIntrinsicWidth(), imgDrawable.getIntrinsicHeight());
        //         Log.d(TAG, "State=" + Arrays.toString(imgDrawable.getState()));

        if (listener != null && showIcon) {
            int tagState = listener.getTagState(mapTag, word);
            int[] state = makeState(tagState, mapTag == null, false);
            imgDrawable.setState(state);
        }

        ImageSpan imageSpan = new ImageSpan(imgDrawable, DynamicDrawableSpan.ALIGN_BASELINE) {

            @Override
            public int getSize(Paint paint, CharSequence text, int start, int end, Paint.FontMetricsInt fm) {
                int size = super.getSize(paint, text, start, end, fm);
                int width = -1;
                if (tvTags.getLayoutParams().width == ViewGroup.LayoutParams.WRAP_CONTENT) {
                    if (tvTags.getParent() instanceof ViewGroup) {
                        width = ((ViewGroup) tvTags.getParent()).getWidth();
                    }
                } else {
                    width = tvTags.getWidth();
                }
                if (width <= 0) {
                    return size;
                }
                return Math.min(size, width);
            }
        };

        ss.setSpan(imageSpan, start, end + tokenLen, 0);

        if (listener != null) {
            ClickableSpan clickSpan = new ClickableSpan() {

                @Override
                public void onClick(View widget) {
                    listener.tagClicked(fMapTag, word);

                    if (AndroidUtils.hasTouchScreen()) {
                        Selection.removeSelection((Spannable) tvTags.getText());
                    }
                    widget.invalidate();
                }
            };

            ss.setSpan(clickSpan, start, end + tokenLen, 0);
        }

    }
}