FileDocCategorySizeDatePackage
ReplacementDrawableSpan.javaAPI DocAndroid 5.1 API2030Thu Mar 12 22:22:50 GMT 2015com.android.ex.chips.recipientchip

ReplacementDrawableSpan

public class ReplacementDrawableSpan extends android.text.style.ReplacementSpan
ReplacementSpan that properly draws the drawable that is centered around the text without changing the default text size or layout.

Fields Summary
protected android.graphics.drawable.Drawable
mDrawable
private final android.graphics.Paint
mWorkPaint
private float
mExtraMargin
Constructors Summary
public ReplacementDrawableSpan(android.graphics.drawable.Drawable drawable)


       
        super();
        mDrawable = drawable;
    
Methods Summary
public voiddraw(android.graphics.Canvas canvas, java.lang.CharSequence charSequence, int start, int end, float x, int top, int y, int bottom, android.graphics.Paint paint)

        canvas.save();
        int transY = (bottom - mDrawable.getBounds().bottom + top) / 2;
        canvas.translate(x, transY);
        mDrawable.draw(canvas);
        canvas.restore();
    
protected android.graphics.RectgetBounds()

        return mDrawable.getBounds();
    
public intgetSize(android.graphics.Paint paint, java.lang.CharSequence text, int i, int i2, Paint.FontMetricsInt fm)

        setupFontMetrics(fm, paint);
        return getBounds().right;
    
public voidsetExtraMargin(float margin)

        mExtraMargin = margin;
    
private voidsetupFontMetrics(Paint.FontMetricsInt fm, android.graphics.Paint paint)

        mWorkPaint.set(paint);
        if (fm != null) {
            mWorkPaint.getFontMetricsInt(fm);

            final Rect bounds = getBounds();
            final int textHeight = fm.descent - fm.ascent;
            final int halfMargin = (int) mExtraMargin / 2;
            fm.ascent = Math.min(fm.top, fm.top + (textHeight - bounds.bottom) / 2) - halfMargin;
            fm.descent = Math.max(fm.bottom, fm.bottom + (bounds.bottom - textHeight) / 2)
                    + halfMargin;
            fm.top = fm.ascent;
            fm.bottom = fm.descent;
        }