Methods Summary |
---|
private void | addLayer(Drawable layer, int id, int left, int top, int right, int bottom)Add a new layer to this drawable. The new layer is identified by an id.
final LayerState st = mLayerState;
int N = st.mChildren != null ? st.mChildren.length : 0;
int i = st.mNum;
if (i >= N) {
ChildDrawable[] nu = new ChildDrawable[N + 10];
if (i > 0) {
System.arraycopy(st.mChildren, 0, nu, 0, i);
}
st.mChildren = nu;
}
mLayerState.mChildrenChangingConfigurations |= layer.getChangingConfigurations();
ChildDrawable childDrawable = new ChildDrawable();
st.mChildren[i] = childDrawable;
childDrawable.mId = id;
childDrawable.mDrawable = layer;
childDrawable.mInsetL = left;
childDrawable.mInsetT = top;
childDrawable.mInsetR = right;
childDrawable.mInsetB = bottom;
st.mNum++;
layer.setCallback(this);
|
android.graphics.drawable.LayerDrawable$LayerState | createConstantState(android.graphics.drawable.LayerDrawable$LayerState state)
return new LayerState(state, this);
|
public void | draw(Canvas canvas)
final ChildDrawable[] array = mLayerState.mChildren;
final int N = mLayerState.mNum;
for (int i=0; i<N; i++) {
array[i].mDrawable.draw(canvas);
}
|
private void | ensurePadding()
final int N = mLayerState.mNum;
if (mPaddingL != null && mPaddingL.length >= N) {
return;
}
mPaddingL = new int[N];
mPaddingT = new int[N];
mPaddingR = new int[N];
mPaddingB = new int[N];
|
public Drawable | findDrawableByLayerId(int id)Look for a layer with the given id, and returns its {@link Drawable}.
final ChildDrawable[] layers = mLayerState.mChildren;
for (int i = mLayerState.mNum - 1; i >= 0; i--) {
if (layers[i].mId == id) {
return layers[i].mDrawable;
}
}
return null;
|
public int | getChangingConfigurations()
return super.getChangingConfigurations()
| mLayerState.mChangingConfigurations
| mLayerState.mChildrenChangingConfigurations;
|
public ConstantState | getConstantState()
if (mLayerState.canConstantState()) {
mLayerState.mChangingConfigurations = super.getChangingConfigurations();
return mLayerState;
}
return null;
|
public Drawable | getDrawable(int index)Returns the drawable at the specified layer index.
return mLayerState.mChildren[index].mDrawable;
|
public int | getId(int index)Returns the id of the specified layer.
return mLayerState.mChildren[index].mId;
|
public int | getIntrinsicHeight()
int height = -1;
final ChildDrawable[] array = mLayerState.mChildren;
final int N = mLayerState.mNum;
int padT=0, padB=0;
for (int i=0; i<N; i++) {
final ChildDrawable r = array[i];
int h = r.mDrawable.getIntrinsicHeight() + r.mInsetT + r.mInsetB + + padT + padB;
if (h > height) {
height = h;
}
padT += mPaddingT[i];
padB += mPaddingB[i];
}
return height;
|
public int | getIntrinsicWidth()
int width = -1;
final ChildDrawable[] array = mLayerState.mChildren;
final int N = mLayerState.mNum;
int padL=0, padR=0;
for (int i=0; i<N; i++) {
final ChildDrawable r = array[i];
int w = r.mDrawable.getIntrinsicWidth()
+ r.mInsetL + r.mInsetR + padL + padR;
if (w > width) {
width = w;
}
padL += mPaddingL[i];
padR += mPaddingR[i];
}
return width;
|
public int | getNumberOfLayers()Returns the number of layers contained within this.
return mLayerState.mNum;
|
public int | getOpacity()
return mLayerState.getOpacity();
|
public boolean | getPadding(Rect padding)
// Arbitrarily get the padding from the first image.
// Technically we should maybe do something more intelligent,
// like take the max padding of all the images.
padding.left = 0;
padding.top = 0;
padding.right = 0;
padding.bottom = 0;
final ChildDrawable[] array = mLayerState.mChildren;
final int N = mLayerState.mNum;
for (int i=0; i<N; i++) {
reapplyPadding(i, array[i]);
padding.left += mPaddingL[i];
padding.top += mPaddingT[i];
padding.right += mPaddingR[i];
padding.bottom += mPaddingB[i];
}
return true;
|
public void | inflate(android.content.res.Resources r, org.xmlpull.v1.XmlPullParser parser, android.util.AttributeSet attrs)
super.inflate(r, parser, attrs);
int type;
final int innerDepth = parser.getDepth() + 1;
int depth;
while ((type = parser.next()) != XmlPullParser.END_DOCUMENT
&& ((depth = parser.getDepth()) >= innerDepth || type != XmlPullParser.END_TAG)) {
if (type != XmlPullParser.START_TAG) {
continue;
}
if (depth > innerDepth || !parser.getName().equals("item")) {
continue;
}
TypedArray a = r.obtainAttributes(attrs,
com.android.internal.R.styleable.LayerDrawableItem);
int left = a.getDimensionPixelOffset(
com.android.internal.R.styleable.LayerDrawableItem_left, 0);
int top = a.getDimensionPixelOffset(
com.android.internal.R.styleable.LayerDrawableItem_top, 0);
int right = a.getDimensionPixelOffset(
com.android.internal.R.styleable.LayerDrawableItem_right, 0);
int bottom = a.getDimensionPixelOffset(
com.android.internal.R.styleable.LayerDrawableItem_bottom, 0);
int drawableRes = a.getResourceId(
com.android.internal.R.styleable.LayerDrawableItem_drawable, 0);
int id = a.getResourceId(com.android.internal.R.styleable.LayerDrawableItem_id,
View.NO_ID);
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()
+ ": <item> tag requires a 'drawable' attribute or "
+ "child tag defining a drawable");
}
dr = Drawable.createFromXmlInner(r, parser, attrs);
}
addLayer(dr, id, left, top, right, bottom);
}
ensurePadding();
onStateChange(getState());
|
public void | invalidateDrawable(Drawable who)
if (mCallback != null) {
mCallback.invalidateDrawable(this);
}
|
public boolean | isStateful()
return mLayerState.isStateful();
|
public Drawable | mutate()
if (!mMutated && super.mutate() == this) {
final ChildDrawable[] array = mLayerState.mChildren;
final int N = mLayerState.mNum;
for (int i = 0; i < N; i++) {
array[i].mDrawable.mutate();
}
mMutated = true;
}
return this;
|
protected void | onBoundsChange(Rect bounds)
final ChildDrawable[] array = mLayerState.mChildren;
final int N = mLayerState.mNum;
int padL=0, padT=0, padR=0, padB=0;
for (int i=0; i<N; i++) {
final ChildDrawable r = array[i];
r.mDrawable.setBounds(bounds.left + r.mInsetL + padL,
bounds.top + r.mInsetT + padT,
bounds.right - r.mInsetR - padR,
bounds.bottom - r.mInsetB - padB);
padL += mPaddingL[i];
padR += mPaddingR[i];
padT += mPaddingT[i];
padB += mPaddingB[i];
}
|
protected boolean | onLevelChange(int level)
final ChildDrawable[] array = mLayerState.mChildren;
final int N = mLayerState.mNum;
boolean paddingChanged = false;
boolean changed = false;
for (int i=0; i<N; i++) {
final ChildDrawable r = array[i];
if (r.mDrawable.setLevel(level)) {
changed = true;
}
if (reapplyPadding(i, r)) {
paddingChanged = true;
}
}
if (paddingChanged) {
onBoundsChange(getBounds());
}
return changed;
|
protected boolean | onStateChange(int[] state)
final ChildDrawable[] array = mLayerState.mChildren;
final int N = mLayerState.mNum;
boolean paddingChanged = false;
boolean changed = false;
for (int i=0; i<N; i++) {
final ChildDrawable r = array[i];
if (r.mDrawable.setState(state)) {
changed = true;
}
if (reapplyPadding(i, r)) {
paddingChanged = true;
}
}
if (paddingChanged) {
onBoundsChange(getBounds());
}
return changed;
|
private boolean | reapplyPadding(int i, android.graphics.drawable.LayerDrawable$ChildDrawable r)
final Rect rect = mTmpRect;
r.mDrawable.getPadding(rect);
if (rect.left != mPaddingL[i] || rect.top != mPaddingT[i] ||
rect.right != mPaddingR[i] || rect.bottom != mPaddingB[i]) {
mPaddingL[i] = rect.left;
mPaddingT[i] = rect.top;
mPaddingR[i] = rect.right;
mPaddingB[i] = rect.bottom;
return true;
}
return false;
|
public void | scheduleDrawable(Drawable who, java.lang.Runnable what, long when)
if (mCallback != null) {
mCallback.scheduleDrawable(this, what, when);
}
|
public void | setAlpha(int alpha)
final ChildDrawable[] array = mLayerState.mChildren;
final int N = mLayerState.mNum;
for (int i=0; i<N; i++) {
array[i].mDrawable.setAlpha(alpha);
}
|
public void | setColorFilter(ColorFilter cf)
final ChildDrawable[] array = mLayerState.mChildren;
final int N = mLayerState.mNum;
for (int i=0; i<N; i++) {
array[i].mDrawable.setColorFilter(cf);
}
|
public void | setDither(boolean dither)
final ChildDrawable[] array = mLayerState.mChildren;
final int N = mLayerState.mNum;
for (int i=0; i<N; i++) {
array[i].mDrawable.setDither(dither);
}
|
public boolean | setDrawableByLayerId(int id, Drawable drawable)Sets (or replaces) the {@link Drawable} for the layer with the given id.
final ChildDrawable[] layers = mLayerState.mChildren;
for (int i = mLayerState.mNum - 1; i >= 0; i--) {
if (layers[i].mId == id) {
layers[i].mDrawable = drawable;
return true;
}
}
return false;
|
public void | setId(int index, int id)Sets the ID of a layer.
mLayerState.mChildren[index].mId = id;
|
public void | setLayerInset(int index, int l, int t, int r, int b)Specify modifiers to the bounds for the drawable[index].
left += l
top += t;
right -= r;
bottom -= b;
ChildDrawable childDrawable = mLayerState.mChildren[index];
childDrawable.mInsetL = l;
childDrawable.mInsetT = t;
childDrawable.mInsetR = r;
childDrawable.mInsetB = b;
|
public boolean | setVisible(boolean visible, boolean restart)
boolean changed = super.setVisible(visible, restart);
final ChildDrawable[] array = mLayerState.mChildren;
final int N = mLayerState.mNum;
for (int i=0; i<N; i++) {
array[i].mDrawable.setVisible(visible, restart);
}
return changed;
|
public void | unscheduleDrawable(Drawable who, java.lang.Runnable what)
if (mCallback != null) {
mCallback.unscheduleDrawable(this, what);
}
|