FileDocCategorySizeDatePackage
DynamicDrawableSpan.javaAPI DocAndroid 5.1 API3570Thu Mar 12 22:22:10 GMT 2015android.text.style

DynamicDrawableSpan

public abstract class DynamicDrawableSpan extends ReplacementSpan

Fields Summary
private static final String
TAG
public static final int
ALIGN_BOTTOM
A constant indicating that the bottom of this span should be aligned with the bottom of the surrounding text, i.e., at the same level as the lowest descender in the text.
public static final int
ALIGN_BASELINE
A constant indicating that the bottom of this span should be aligned with the baseline of the surrounding text.
protected final int
mVerticalAlignment
private WeakReference
mDrawableRef
Constructors Summary
public DynamicDrawableSpan()

    
      
        mVerticalAlignment = ALIGN_BOTTOM;
    
protected DynamicDrawableSpan(int verticalAlignment)

param
verticalAlignment one of {@link #ALIGN_BOTTOM} or {@link #ALIGN_BASELINE}.

        mVerticalAlignment = verticalAlignment;
    
Methods Summary
public voiddraw(android.graphics.Canvas canvas, java.lang.CharSequence text, int start, int end, float x, int top, int y, int bottom, android.graphics.Paint paint)

        Drawable b = getCachedDrawable();
        canvas.save();
        
        int transY = bottom - b.getBounds().bottom;
        if (mVerticalAlignment == ALIGN_BASELINE) {
            transY -= paint.getFontMetricsInt().descent;
        }

        canvas.translate(x, transY);
        b.draw(canvas);
        canvas.restore();
    
private android.graphics.drawable.DrawablegetCachedDrawable()

        WeakReference<Drawable> wr = mDrawableRef;
        Drawable d = null;

        if (wr != null)
            d = wr.get();

        if (d == null) {
            d = getDrawable();
            mDrawableRef = new WeakReference<Drawable>(d);
        }

        return d;
    
public abstract android.graphics.drawable.DrawablegetDrawable()
Your subclass must implement this method to provide the bitmap to be drawn. The dimensions of the bitmap must be the same from each call to the next.

public intgetSize(android.graphics.Paint paint, java.lang.CharSequence text, int start, int end, Paint.FontMetricsInt fm)

        Drawable d = getCachedDrawable();
        Rect rect = d.getBounds();

        if (fm != null) {
            fm.ascent = -rect.bottom; 
            fm.descent = 0; 

            fm.top = fm.ascent;
            fm.bottom = 0;
        }

        return rect.right;
    
public intgetVerticalAlignment()
Returns the vertical alignment of this span, one of {@link #ALIGN_BOTTOM} or {@link #ALIGN_BASELINE}.

        return mVerticalAlignment;