Methods Summary |
---|
public void | draw(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 float | getAlpha()
return mAlpha;
|
public int | getHeight()
return mDrawable != null ? mDrawable.getIntrinsicHeight() : 0;
|
public float | getPositionX()
return mPositionX;
|
public float | getPositionY()
return mPositionY;
|
public int | getResourceId()
return mResourceId;
|
public float | getScaleX()
return mScaleX;
|
public float | getScaleY()
return mScaleY;
|
public int | getWidth()
return mDrawable != null ? mDrawable.getIntrinsicWidth() : 0;
|
public float | getX()
return mTranslationX;
|
public float | getY()
return mTranslationY;
|
public boolean | hasState(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 boolean | isActive()Returns true if the drawable is a StateListDrawable and is in the focused state.
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 boolean | isEnabled()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 mDrawable != null && mEnabled;
|
private void | resizeDrawables()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 void | setAlpha(float alpha)
mAlpha = alpha;
|
public void | setDrawable(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 void | setEnabled(boolean enabled)
mEnabled = enabled;
|
public void | setPositionX(float x)
mPositionX = x;
|
public void | setPositionY(float y)
mPositionY = y;
|
public void | setScaleX(float x)
mScaleX = x;
|
public void | setScaleY(float y)
mScaleY = y;
|
public void | setState(int[] state)
if (mDrawable instanceof StateListDrawable) {
StateListDrawable d = (StateListDrawable) mDrawable;
d.setState(state);
}
|
public void | setX(float x)
mTranslationX = x;
|
public void | setY(float y)
mTranslationY = y;
|