FileDocCategorySizeDatePackage
InsetDrawable.javaAPI DocAndroid 1.5 API9405Wed May 06 22:42:00 BST 2009android.graphics.drawable

InsetDrawable

public class InsetDrawable extends Drawable implements Drawable.Callback
A Drawable that insets another Drawable by a specified distance. This is used when a View needs a background that is smaller than the View's actual bounds.

It can be defined in an XML file with the <inset> element.

attr
ref android.R.styleable#InsetDrawable_visible
attr
ref android.R.styleable#InsetDrawable_drawable
attr
ref android.R.styleable#InsetDrawable_insetLeft
attr
ref android.R.styleable#InsetDrawable_insetRight
attr
ref android.R.styleable#InsetDrawable_insetTop
attr
ref android.R.styleable#InsetDrawable_insetBottom

Fields Summary
private InsetState
mInsetState
private final Rect
mTmpRect
private boolean
mMutated
Constructors Summary
InsetDrawable()


    /*package*/  
        this(null);
    
public InsetDrawable(Drawable drawable, int inset)

        this(drawable, inset, inset, inset, inset);
    
private InsetDrawable(InsetState state)

        mInsetState = new InsetState(state, this);
    
public InsetDrawable(Drawable drawable, int insetLeft, int insetTop, int insetRight, int insetBottom)

        this(null);
        
        mInsetState.mDrawable = drawable;
        mInsetState.mInsetLeft = insetLeft;
        mInsetState.mInsetTop = insetTop;
        mInsetState.mInsetRight = insetRight;
        mInsetState.mInsetBottom = insetBottom;
        
        if (drawable != null) {
            drawable.setCallback(this);
        }
    
Methods Summary
public voiddraw(Canvas canvas)

        mInsetState.mDrawable.draw(canvas);
    
public intgetChangingConfigurations()

        return super.getChangingConfigurations()
                | mInsetState.mChangingConfigurations
                | mInsetState.mDrawable.getChangingConfigurations();
    
public ConstantStategetConstantState()

        if (mInsetState.canConstantState()) {
            mInsetState.mChangingConfigurations = super.getChangingConfigurations();
            return mInsetState;
        }
        return null;
    
public intgetIntrinsicHeight()

        return mInsetState.mDrawable.getIntrinsicHeight();
    
public intgetIntrinsicWidth()

        return mInsetState.mDrawable.getIntrinsicWidth();
    
public intgetOpacity()

        return mInsetState.mDrawable.getOpacity();
    
public booleangetPadding(Rect padding)

        boolean pad = mInsetState.mDrawable.getPadding(padding);

        padding.left += mInsetState.mInsetLeft;
        padding.right += mInsetState.mInsetRight;
        padding.top += mInsetState.mInsetTop;
        padding.bottom += mInsetState.mInsetBottom;

        if (pad || (mInsetState.mInsetLeft | mInsetState.mInsetRight | 
                    mInsetState.mInsetTop | mInsetState.mInsetBottom) != 0) {
            return true;
        } else {
            return false;
        }
    
public voidinflate(android.content.res.Resources r, org.xmlpull.v1.XmlPullParser parser, android.util.AttributeSet attrs)

        int type;
        
        TypedArray a = r.obtainAttributes(attrs,
                com.android.internal.R.styleable.InsetDrawable);

        super.inflateWithAttributes(r, parser, a,
                com.android.internal.R.styleable.InsetDrawable_visible);

        int drawableRes = a.getResourceId(com.android.internal.R.styleable.
                                    InsetDrawable_drawable, 0);

        int inLeft = a.getDimensionPixelOffset(com.android.internal.R.styleable.
                                    InsetDrawable_insetLeft, 0);
        int inTop = a.getDimensionPixelOffset(com.android.internal.R.styleable.
                                    InsetDrawable_insetTop, 0);
        int inRight = a.getDimensionPixelOffset(com.android.internal.R.styleable.
                                    InsetDrawable_insetRight, 0);
        int inBottom = a.getDimensionPixelOffset(com.android.internal.R.styleable.
                                    InsetDrawable_insetBottom, 0);

        a.recycle();

        Drawable dr;
        if (drawableRes != 0) {
            dr = r.getDrawable(drawableRes);
        } else {
            while ((type=parser.next()) == XmlPullParser.TEXT) {
            }
            if (type != XmlPullParser.START_TAG) {
                throw new XmlPullParserException(
                        parser.getPositionDescription()
                        + ": <inset> tag requires a 'drawable' attribute or "
                        + "child tag defining a drawable");
            }
            dr = Drawable.createFromXmlInner(r, parser, attrs);
        }

        if (dr == null) {
            Log.w("drawable", "No drawable specified for <inset>");
        }

        mInsetState.mDrawable = dr;
        mInsetState.mInsetLeft = inLeft;
        mInsetState.mInsetRight = inRight;
        mInsetState.mInsetTop = inTop;
        mInsetState.mInsetBottom = inBottom;

        if (dr != null) {
            dr.setCallback(this);
        }
    
public voidinvalidateDrawable(Drawable who)

        if (mCallback != null) {
            mCallback.invalidateDrawable(this);
        }
    
public booleanisStateful()

        return mInsetState.mDrawable.isStateful();
    
public Drawablemutate()

        if (!mMutated && super.mutate() == this) {
            mInsetState.mDrawable.mutate();
            mMutated = true;
        }
        return this;
    
protected voidonBoundsChange(Rect bounds)

        final Rect r = mTmpRect;
        r.set(bounds);

        r.left += mInsetState.mInsetLeft;
        r.top += mInsetState.mInsetTop;
        r.right -= mInsetState.mInsetRight;
        r.bottom -= mInsetState.mInsetBottom;

        mInsetState.mDrawable.setBounds(r.left, r.top, r.right, r.bottom);
    
protected booleanonStateChange(int[] state)

        boolean changed = mInsetState.mDrawable.setState(state);
        onBoundsChange(getBounds());
        return changed;
    
public voidscheduleDrawable(Drawable who, java.lang.Runnable what, long when)

        if (mCallback != null) {
            mCallback.scheduleDrawable(this, what, when);
        }
    
public voidsetAlpha(int alpha)

        mInsetState.mDrawable.setAlpha(alpha);
    
public voidsetColorFilter(ColorFilter cf)

        mInsetState.mDrawable.setColorFilter(cf);
    
public booleansetVisible(boolean visible, boolean restart)

        mInsetState.mDrawable.setVisible(visible, restart);
        return super.setVisible(visible, restart);
    
public voidunscheduleDrawable(Drawable who, java.lang.Runnable what)

        if (mCallback != null) {
            mCallback.unscheduleDrawable(this, what);
        }