From e70b375c4b9d73d1165a21a421cfd73170cd06cc Mon Sep 17 00:00:00 2001 From: Joe Onorato Date: Wed, 17 Nov 2010 20:42:00 -0800 Subject: Add an opacity attribute to LayerDrawable that lets you control the opacity directly instead of collecting the values from the children-- a task that is much harder to get right than we want to spend startup time on. Change-Id: Idf5b1d612472c6accfdc935c6a6fadb1eb239a73 --- .../android/graphics/drawable/LayerDrawable.java | 30 +++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) (limited to 'graphics') diff --git a/graphics/java/android/graphics/drawable/LayerDrawable.java b/graphics/java/android/graphics/drawable/LayerDrawable.java index b6cce7e..09c041f 100644 --- a/graphics/java/android/graphics/drawable/LayerDrawable.java +++ b/graphics/java/android/graphics/drawable/LayerDrawable.java @@ -26,6 +26,7 @@ import android.graphics.ColorFilter; import android.graphics.PixelFormat; import android.graphics.Rect; import android.util.AttributeSet; +import android.util.Slog; import android.view.View; import java.io.IOException; @@ -49,6 +50,7 @@ import java.io.IOException; public class LayerDrawable extends Drawable implements Drawable.Callback { LayerState mLayerState; + private int mOpacityOverride = PixelFormat.UNKNOWN; private int[] mPaddingL; private int[] mPaddingT; private int[] mPaddingR; @@ -113,6 +115,13 @@ public class LayerDrawable extends Drawable implements Drawable.Callback { int type; + TypedArray a = r.obtainAttributes(attrs, com.android.internal.R.styleable.LayerDrawable); + + mOpacityOverride = a.getInt(com.android.internal.R.styleable.LayerDrawable_opacity, + PixelFormat.UNKNOWN); + + a.recycle(); + final int innerDepth = parser.getDepth() + 1; int depth; while ((type = parser.next()) != XmlPullParser.END_DOCUMENT @@ -125,7 +134,7 @@ public class LayerDrawable extends Drawable implements Drawable.Callback { continue; } - TypedArray a = r.obtainAttributes(attrs, + a = r.obtainAttributes(attrs, com.android.internal.R.styleable.LayerDrawableItem); int left = a.getDimensionPixelOffset( @@ -391,9 +400,28 @@ public class LayerDrawable extends Drawable implements Drawable.Callback { array[i].mDrawable.setColorFilter(cf); } } + + /** + * Sets the opacity of this drawable directly, instead of collecting the states from + * the layers + * + * @param opacity The opacity to use, or {@link PixelFormat#UNKNOWN PixelFormat.UNKNOWN} + * for the default behavior + * + * @see PixelFormat#UNKNOWN + * @see PixelFormat#TRANSLUCENT + * @see PixelFormat#TRANSPARENT + * @see PixelFormat#OPAQUE + */ + public void setOpacity(int opacity) { + mOpacityOverride = opacity; + } @Override public int getOpacity() { + if (mOpacityOverride != PixelFormat.UNKNOWN) { + return mOpacityOverride; + } return mLayerState.getOpacity(); } -- cgit v1.1