Methods Summary |
---|
void | addLayer(android.graphics.drawable.LayerDrawable$ChildDrawable layer)
final LayerState st = mLayerState;
final int N = st.mChildren != null ? st.mChildren.length : 0;
final int i = st.mNum;
if (i >= N) {
final ChildDrawable[] nu = new ChildDrawable[N + 10];
if (i > 0) {
System.arraycopy(st.mChildren, 0, nu, 0, i);
}
st.mChildren = nu;
}
st.mChildren[i] = layer;
st.mNum++;
st.invalidateCache();
|
android.graphics.drawable.LayerDrawable$ChildDrawable | addLayer(Drawable layer, int[] themeAttrs, 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 ChildDrawable childDrawable = new ChildDrawable();
childDrawable.mId = id;
childDrawable.mThemeAttrs = themeAttrs;
childDrawable.mDrawable = layer;
childDrawable.mDrawable.setAutoMirrored(isAutoMirrored());
childDrawable.mInsetL = left;
childDrawable.mInsetT = top;
childDrawable.mInsetR = right;
childDrawable.mInsetB = bottom;
addLayer(childDrawable);
mLayerState.mChildrenChangingConfigurations |= layer.getChangingConfigurations();
layer.setCallback(this);
return childDrawable;
|
public void | applyTheme(android.content.res.Resources.Theme t)
super.applyTheme(t);
final LayerState state = mLayerState;
if (state == null) {
return;
}
if (state.mThemeAttrs != null) {
final TypedArray a = t.resolveAttributes(state.mThemeAttrs, R.styleable.LayerDrawable);
updateStateFromTypedArray(a);
a.recycle();
}
final ChildDrawable[] array = state.mChildren;
final int N = state.mNum;
for (int i = 0; i < N; i++) {
final ChildDrawable layer = array[i];
if (layer.mThemeAttrs != null) {
final TypedArray a = t.resolveAttributes(layer.mThemeAttrs,
R.styleable.LayerDrawableItem);
updateLayerFromTypedArray(layer, a);
a.recycle();
}
final Drawable d = layer.mDrawable;
if (d.canApplyTheme()) {
d.applyTheme(t);
}
}
ensurePadding();
onStateChange(getState());
|
public boolean | canApplyTheme()
return (mLayerState != null && mLayerState.canApplyTheme()) || super.canApplyTheme();
|
public void | clearMutated()
super.clearMutated();
final ChildDrawable[] array = mLayerState.mChildren;
final int N = mLayerState.mNum;
for (int i = 0; i < N; i++) {
array[i].mDrawable.clearMutated();
}
mMutated = false;
|
private void | computeNestedPadding(android.graphics.Rect padding)
padding.left = 0;
padding.top = 0;
padding.right = 0;
padding.bottom = 0;
// Add all the padding.
final ChildDrawable[] array = mLayerState.mChildren;
final int N = mLayerState.mNum;
for (int i = 0; i < N; i++) {
refreshChildPadding(i, array[i]);
padding.left += mPaddingL[i];
padding.top += mPaddingT[i];
padding.right += mPaddingR[i];
padding.bottom += mPaddingB[i];
}
|
private void | computeStackedPadding(android.graphics.Rect padding)
padding.left = 0;
padding.top = 0;
padding.right = 0;
padding.bottom = 0;
// Take the max padding.
final ChildDrawable[] array = mLayerState.mChildren;
final int N = mLayerState.mNum;
for (int i = 0; i < N; i++) {
refreshChildPadding(i, array[i]);
padding.left = Math.max(padding.left, mPaddingL[i]);
padding.top = Math.max(padding.top, mPaddingT[i]);
padding.right = Math.max(padding.right, mPaddingR[i]);
padding.bottom = Math.max(padding.bottom, mPaddingB[i]);
}
|
android.graphics.drawable.LayerDrawable$LayerState | createConstantState(android.graphics.drawable.LayerDrawable$LayerState state, android.content.res.Resources res)
return new LayerState(state, this, res);
|
public void | draw(android.graphics.Canvas canvas)
final ChildDrawable[] array = mLayerState.mChildren;
final int N = mLayerState.mNum;
for (int i = 0; i < N; i++) {
array[i].mDrawable.draw(canvas);
}
|
void | ensurePadding()Ensures the child padding caches are large enough.
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)Looks for a layer with the given ID and returns its {@link Drawable}.
If multiple layers are found for the given ID, returns the
{@link Drawable} for the matching layer at the highest index.
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 | getAlpha()
final ChildDrawable[] array = mLayerState.mChildren;
if (mLayerState.mNum > 0) {
// All layers should have the same alpha set on them - just return
// the first one
return array[0].mDrawable.getAlpha();
} else {
return super.getAlpha();
}
|
public int | getChangingConfigurations()
return super.getChangingConfigurations()
| mLayerState.mChangingConfigurations
| mLayerState.mChildrenChangingConfigurations;
|
public ConstantState | getConstantState()
if (mLayerState.canConstantState()) {
mLayerState.mChangingConfigurations = getChangingConfigurations();
return mLayerState;
}
return null;
|
public Drawable | getDrawable(int index)Returns the drawable at the specified layer index.
return mLayerState.mChildren[index].mDrawable;
|
public void | getHotspotBounds(android.graphics.Rect outRect)
if (mHotspotBounds != null) {
outRect.set(mHotspotBounds);
} else {
super.getHotspotBounds(outRect);
}
|
public int | getId(int index)Returns the id of the specified layer.
return mLayerState.mChildren[index].mId;
|
public int | getIntrinsicHeight()
int height = -1;
int padT = 0;
int padB = 0;
final boolean nest = mLayerState.mPaddingMode == PADDING_MODE_NEST;
final ChildDrawable[] array = mLayerState.mChildren;
final int N = mLayerState.mNum;
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;
}
if (nest) {
padT += mPaddingT[i];
padB += mPaddingB[i];
}
}
return height;
|
public int | getIntrinsicWidth()
int width = -1;
int padL = 0;
int padR = 0;
final boolean nest = mLayerState.mPaddingMode == PADDING_MODE_NEST;
final ChildDrawable[] array = mLayerState.mChildren;
final int N = mLayerState.mNum;
for (int i = 0; i < N; i++) {
final ChildDrawable r = array[i];
final int w = r.mDrawable.getIntrinsicWidth() + r.mInsetL + r.mInsetR + padL + padR;
if (w > width) {
width = w;
}
if (nest) {
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()
if (mOpacityOverride != PixelFormat.UNKNOWN) {
return mOpacityOverride;
}
return mLayerState.getOpacity();
|
public void | getOutline(android.graphics.Outline outline)Populates outline with the first available (non-empty) layer outline.
final LayerState state = mLayerState;
final ChildDrawable[] children = state.mChildren;
final int N = state.mNum;
for (int i = 0; i < N; i++) {
children[i].mDrawable.getOutline(outline);
if (!outline.isEmpty()) {
return;
}
}
|
public boolean | getPadding(android.graphics.Rect padding)
if (mLayerState.mPaddingMode == PADDING_MODE_NEST) {
computeNestedPadding(padding);
} else {
computeStackedPadding(padding);
}
return padding.left != 0 || padding.top != 0 || padding.right != 0 || padding.bottom != 0;
|
public int | getPaddingMode()
return mLayerState.mPaddingMode;
|
public void | inflate(android.content.res.Resources r, org.xmlpull.v1.XmlPullParser parser, android.util.AttributeSet attrs, android.content.res.Resources.Theme theme)
super.inflate(r, parser, attrs, theme);
final TypedArray a = obtainAttributes(r, theme, attrs, R.styleable.LayerDrawable);
updateStateFromTypedArray(a);
a.recycle();
inflateLayers(r, parser, attrs, theme);
ensurePadding();
onStateChange(getState());
|
private void | inflateLayers(android.content.res.Resources r, org.xmlpull.v1.XmlPullParser parser, android.util.AttributeSet attrs, android.content.res.Resources.Theme theme)Inflates child layers using the specified parser.
final LayerState state = mLayerState;
final int innerDepth = parser.getDepth() + 1;
int type;
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;
}
final ChildDrawable layer = new ChildDrawable();
final TypedArray a = obtainAttributes(r, theme, attrs, R.styleable.LayerDrawableItem);
updateLayerFromTypedArray(layer, a);
a.recycle();
if (layer.mDrawable == null) {
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");
}
layer.mDrawable = Drawable.createFromXmlInner(r, parser, attrs, theme);
}
if (layer.mDrawable != null) {
state.mChildrenChangingConfigurations |=
layer.mDrawable.getChangingConfigurations();
layer.mDrawable.setCallback(this);
}
addLayer(layer);
}
|
public void | invalidateDrawable(Drawable who)
invalidateSelf();
|
public boolean | isAutoMirrored()
return mLayerState.mAutoMirrored;
|
public boolean | isProjected()
if (super.isProjected()) {
return true;
}
final ChildDrawable[] layers = mLayerState.mChildren;
final int N = mLayerState.mNum;
for (int i = 0; i < N; i++) {
if (layers[i].mDrawable.isProjected()) {
return true;
}
}
return false;
|
public boolean | isStateful()
return mLayerState.isStateful();
|
public Drawable | mutate()
if (!mMutated && super.mutate() == this) {
mLayerState = createConstantState(mLayerState, null);
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(android.graphics.Rect bounds)
int padL = 0;
int padT = 0;
int padR = 0;
int padB = 0;
final boolean nest = mLayerState.mPaddingMode == PADDING_MODE_NEST;
final ChildDrawable[] array = mLayerState.mChildren;
final int N = mLayerState.mNum;
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);
if (nest) {
padL += mPaddingL[i];
padR += mPaddingR[i];
padT += mPaddingT[i];
padB += mPaddingB[i];
}
}
|
protected boolean | onLevelChange(int level)
boolean paddingChanged = false;
boolean changed = false;
final ChildDrawable[] array = mLayerState.mChildren;
final int N = mLayerState.mNum;
for (int i = 0; i < N; i++) {
final ChildDrawable r = array[i];
if (r.mDrawable.setLevel(level)) {
changed = true;
}
if (refreshChildPadding(i, r)) {
paddingChanged = true;
}
}
if (paddingChanged) {
onBoundsChange(getBounds());
}
return changed;
|
protected boolean | onStateChange(int[] state)
boolean paddingChanged = false;
boolean changed = false;
final ChildDrawable[] array = mLayerState.mChildren;
final int N = mLayerState.mNum;
for (int i = 0; i < N; i++) {
final ChildDrawable r = array[i];
if (r.mDrawable.isStateful() && r.mDrawable.setState(state)) {
changed = true;
}
if (refreshChildPadding(i, r)) {
paddingChanged = true;
}
}
if (paddingChanged) {
onBoundsChange(getBounds());
}
return changed;
|
private boolean | refreshChildPadding(int i, android.graphics.drawable.LayerDrawable$ChildDrawable r)Refreshes the cached padding values for the specified child.
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)
scheduleSelf(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 | setAutoMirrored(boolean mirrored)
mLayerState.mAutoMirrored = mirrored;
final ChildDrawable[] array = mLayerState.mChildren;
final int N = mLayerState.mNum;
for (int i = 0; i < N; i++) {
array[i].mDrawable.setAutoMirrored(mirrored);
}
|
public void | setColorFilter(android.graphics.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;
final int N = mLayerState.mNum;
for (int i = 0; i < N; i++) {
final ChildDrawable childDrawable = layers[i];
if (childDrawable.mId == id) {
if (childDrawable.mDrawable != null) {
if (drawable != null) {
final Rect bounds = childDrawable.mDrawable.getBounds();
drawable.setBounds(bounds);
}
childDrawable.mDrawable.setCallback(null);
}
if (drawable != null) {
drawable.setCallback(this);
}
childDrawable.mDrawable = drawable;
mLayerState.invalidateCache();
return true;
}
}
return false;
|
public void | setHotspot(float x, float y)
final ChildDrawable[] array = mLayerState.mChildren;
final int N = mLayerState.mNum;
for (int i = 0; i < N; i++) {
array[i].mDrawable.setHotspot(x, y);
}
|
public void | setHotspotBounds(int left, int top, int right, int bottom)
final ChildDrawable[] array = mLayerState.mChildren;
final int N = mLayerState.mNum;
for (int i = 0; i < N; i++) {
array[i].mDrawable.setHotspotBounds(left, top, right, bottom);
}
if (mHotspotBounds == null) {
mHotspotBounds = new Rect(left, top, right, bottom);
} else {
mHotspotBounds.set(left, top, right, bottom);
}
|
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)Specifies the insets in pixels for the drawable at the specified index.
final ChildDrawable childDrawable = mLayerState.mChildren[index];
childDrawable.mInsetL = l;
childDrawable.mInsetT = t;
childDrawable.mInsetR = r;
childDrawable.mInsetB = b;
|
public void | setLayoutDirection(int layoutDirection)
final ChildDrawable[] array = mLayerState.mChildren;
final int N = mLayerState.mNum;
for (int i = 0; i < N; i++) {
array[i].mDrawable.setLayoutDirection(layoutDirection);
}
super.setLayoutDirection(layoutDirection);
|
public void | setOpacity(int opacity)Sets the opacity of this drawable directly, instead of collecting the
states from the layers
mOpacityOverride = opacity;
|
public void | setPaddingMode(int mode)Specifies how layer padding should affect the bounds of subsequent
layers. The default value is {@link #PADDING_MODE_NEST}.
if (mLayerState.mPaddingMode != mode) {
mLayerState.mPaddingMode = mode;
}
|
public void | setTintList(android.content.res.ColorStateList tint)
final ChildDrawable[] array = mLayerState.mChildren;
final int N = mLayerState.mNum;
for (int i = 0; i < N; i++) {
array[i].mDrawable.setTintList(tint);
}
|
public void | setTintMode(android.graphics.PorterDuff.Mode tintMode)
final ChildDrawable[] array = mLayerState.mChildren;
final int N = mLayerState.mNum;
for (int i = 0; i < N; i++) {
array[i].mDrawable.setTintMode(tintMode);
}
|
public boolean | setVisible(boolean visible, boolean restart)
final 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)
unscheduleSelf(what);
|
private void | updateLayerFromTypedArray(android.graphics.drawable.LayerDrawable$ChildDrawable layer, android.content.res.TypedArray a)
final LayerState state = mLayerState;
// Account for any configuration changes.
state.mChildrenChangingConfigurations |= a.getChangingConfigurations();
// Extract the theme attributes, if any.
layer.mThemeAttrs = a.extractThemeAttrs();
layer.mInsetL = a.getDimensionPixelOffset(
R.styleable.LayerDrawableItem_left, layer.mInsetL);
layer.mInsetT = a.getDimensionPixelOffset(
R.styleable.LayerDrawableItem_top, layer.mInsetT);
layer.mInsetR = a.getDimensionPixelOffset(
R.styleable.LayerDrawableItem_right, layer.mInsetR);
layer.mInsetB = a.getDimensionPixelOffset(
R.styleable.LayerDrawableItem_bottom, layer.mInsetB);
layer.mId = a.getResourceId(R.styleable.LayerDrawableItem_id, layer.mId);
final Drawable dr = a.getDrawable(R.styleable.LayerDrawableItem_drawable);
if (dr != null) {
layer.mDrawable = dr;
}
|
private void | updateStateFromTypedArray(android.content.res.TypedArray a)Initializes the constant state from the values in the typed array.
final LayerState state = mLayerState;
// Account for any configuration changes.
state.mChangingConfigurations |= a.getChangingConfigurations();
// Extract the theme attributes, if any.
state.mThemeAttrs = a.extractThemeAttrs();
mOpacityOverride = a.getInt(R.styleable.LayerDrawable_opacity, mOpacityOverride);
state.mAutoMirrored = a.getBoolean(R.styleable.LayerDrawable_autoMirrored,
state.mAutoMirrored);
state.mPaddingMode = a.getInteger(R.styleable.LayerDrawable_paddingMode,
state.mPaddingMode);
|