FileDocCategorySizeDatePackage
TargetDrawable.javaAPI DocAndroid 5.1 API7305Thu Mar 12 22:22:10 GMT 2015com.android.internal.widget.multiwaveview

TargetDrawable

public class TargetDrawable extends Object

Fields Summary
private static final String
TAG
private static final boolean
DEBUG
public static final int[]
STATE_ACTIVE
public static final int[]
STATE_INACTIVE
public static final int[]
STATE_FOCUSED
private float
mTranslationX
private float
mTranslationY
private float
mPositionX
private float
mPositionY
private float
mScaleX
private float
mScaleY
private float
mAlpha
private android.graphics.drawable.Drawable
mDrawable
private boolean
mEnabled
private final int
mResourceId
Constructors Summary
public TargetDrawable(android.content.res.Resources res, int resId)


         
        mResourceId = resId;
        setDrawable(res, resId);
    
public TargetDrawable(TargetDrawable other)

        mResourceId = other.mResourceId;
        // Mutate the drawable so we can animate shared drawable properties.
        mDrawable = other.mDrawable != null ? other.mDrawable.mutate() : null;
        resizeDrawables();
        setState(STATE_INACTIVE);
    
Methods Summary
public voiddraw(android.graphics.Canvas canvas)

        if (mDrawable == null || !mEnabled) {
            return;
        }
        canvas.save(Canvas.MATRIX_SAVE_FLAG);
        canvas.scale(mScaleX, mScaleY, mPositionX, mPositionY);
        canvas.translate(mTranslationX + mPositionX, mTranslationY + mPositionY);
        canvas.translate(-0.5f * getWidth(), -0.5f * getHeight());
        mDrawable.setAlpha((int) Math.round(mAlpha * 255f));
        mDrawable.draw(canvas);
        canvas.restore();
    
public floatgetAlpha()

        return mAlpha;
    
public intgetHeight()

        return mDrawable != null ? mDrawable.getIntrinsicHeight() : 0;
    
public floatgetPositionX()

        return mPositionX;
    
public floatgetPositionY()

        return mPositionY;
    
public intgetResourceId()

        return mResourceId;
    
public floatgetScaleX()

        return mScaleX;
    
public floatgetScaleY()

        return mScaleY;
    
public intgetWidth()

        return mDrawable != null ? mDrawable.getIntrinsicWidth() : 0;
    
public floatgetX()

        return mTranslationX;
    
public floatgetY()

        return mTranslationY;
    
public booleanhasState(int[] state)

        if (mDrawable instanceof StateListDrawable) {
            StateListDrawable d = (StateListDrawable) mDrawable;
            // TODO: this doesn't seem to work
            return d.getStateDrawableIndex(state) != -1;
        }
        return false;
    
public booleanisActive()
Returns true if the drawable is a StateListDrawable and is in the focused state.

return

        if (mDrawable instanceof StateListDrawable) {
            StateListDrawable d = (StateListDrawable) mDrawable;
            int[] states = d.getState();
            for (int i = 0; i < states.length; i++) {
                if (states[i] == android.R.attr.state_focused) {
                    return true;
                }
            }
        }
        return false;
    
public booleanisEnabled()
Returns true if this target is enabled. Typically an enabled target contains a valid drawable in a valid state. Currently all targets with valid drawables are valid.

return

        return mDrawable != null && mEnabled;
    
private voidresizeDrawables()
Makes drawables in a StateListDrawable all the same dimensions. If not a StateListDrawable, then justs sets the bounds to the intrinsic size of the drawable.

        if (mDrawable instanceof StateListDrawable) {
            StateListDrawable d = (StateListDrawable) mDrawable;
            int maxWidth = 0;
            int maxHeight = 0;
            for (int i = 0; i < d.getStateCount(); i++) {
                Drawable childDrawable = d.getStateDrawable(i);
                maxWidth = Math.max(maxWidth, childDrawable.getIntrinsicWidth());
                maxHeight = Math.max(maxHeight, childDrawable.getIntrinsicHeight());
            }
            if (DEBUG) Log.v(TAG, "union of childDrawable rects " + d + " to: "
                        + maxWidth + "x" + maxHeight);
            d.setBounds(0, 0, maxWidth, maxHeight);
            for (int i = 0; i < d.getStateCount(); i++) {
                Drawable childDrawable = d.getStateDrawable(i);
                if (DEBUG) Log.v(TAG, "sizing drawable " + childDrawable + " to: "
                            + maxWidth + "x" + maxHeight);
                childDrawable.setBounds(0, 0, maxWidth, maxHeight);
            }
        } else if (mDrawable != null) {
            mDrawable.setBounds(0, 0,
                    mDrawable.getIntrinsicWidth(), mDrawable.getIntrinsicHeight());
        }
    
public voidsetAlpha(float alpha)

        mAlpha = alpha;
    
public voidsetDrawable(android.content.res.Resources res, int resId)

        // Note we explicitly don't set mResourceId to resId since we allow the drawable to be
        // swapped at runtime and want to re-use the existing resource id for identification.
        Drawable drawable = resId == 0 ? null : res.getDrawable(resId);
        // Mutate the drawable so we can animate shared drawable properties.
        mDrawable = drawable != null ? drawable.mutate() : null;
        resizeDrawables();
        setState(STATE_INACTIVE);
    
public voidsetEnabled(boolean enabled)

        mEnabled  = enabled;
    
public voidsetPositionX(float x)

        mPositionX = x;
    
public voidsetPositionY(float y)

        mPositionY = y;
    
public voidsetScaleX(float x)

        mScaleX = x;
    
public voidsetScaleY(float y)

        mScaleY = y;
    
public voidsetState(int[] state)

        if (mDrawable instanceof StateListDrawable) {
            StateListDrawable d = (StateListDrawable) mDrawable;
            d.setState(state);
        }
    
public voidsetX(float x)

        mTranslationX = x;
    
public voidsetY(float y)

        mTranslationY = y;