diff options
author | Joe Onorato <joeo@google.com> | 2010-11-17 20:42:00 -0800 |
---|---|---|
committer | Joe Onorato <joeo@google.com> | 2010-11-17 21:20:08 -0800 |
commit | e70b375c4b9d73d1165a21a421cfd73170cd06cc (patch) | |
tree | f4b2dd62b9bc712d1c3fd72c26148acf5459863d /graphics | |
parent | 3f1845ffec469cac9d897b504fee29c173890024 (diff) | |
download | frameworks_base-e70b375c4b9d73d1165a21a421cfd73170cd06cc.zip frameworks_base-e70b375c4b9d73d1165a21a421cfd73170cd06cc.tar.gz frameworks_base-e70b375c4b9d73d1165a21a421cfd73170cd06cc.tar.bz2 |
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
Diffstat (limited to 'graphics')
-rw-r--r-- | graphics/java/android/graphics/drawable/LayerDrawable.java | 30 |
1 files changed, 29 insertions, 1 deletions
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(); } |