diff options
-rw-r--r-- | api/current.xml | 24 | ||||
-rwxr-xr-x | core/res/res/values/attrs.xml | 9 | ||||
-rw-r--r-- | core/res/res/values/public.xml | 1 | ||||
-rw-r--r-- | graphics/java/android/graphics/drawable/LayerDrawable.java | 30 |
4 files changed, 62 insertions, 2 deletions
diff --git a/api/current.xml b/api/current.xml index 13b708c..afe86fb 100644 --- a/api/current.xml +++ b/api/current.xml @@ -6697,6 +6697,17 @@ visibility="public" > </field> +<field name="opacity" + type="int" + transient="false" + volatile="false" + value="16843567" + static="true" + final="true" + deprecated="not deprecated" + visibility="public" +> +</field> <field name="order" type="int" transient="false" @@ -86062,6 +86073,19 @@ <parameter name="b" type="int"> </parameter> </method> +<method name="setOpacity" + return="void" + abstract="false" + native="false" + synchronized="false" + static="false" + final="false" + deprecated="not deprecated" + visibility="public" +> +<parameter name="opacity" type="int"> +</parameter> +</method> <method name="unscheduleDrawable" return="void" abstract="false" diff --git a/core/res/res/values/attrs.xml b/core/res/res/values/attrs.xml index af1cab9..651bfea 100755 --- a/core/res/res/values/attrs.xml +++ b/core/res/res/values/attrs.xml @@ -49,7 +49,6 @@ window is floating. --> <attr name="backgroundDimEnabled" format="boolean" /> - <!-- =========== --> <!-- Text styles --> <!-- =========== --> @@ -2943,6 +2942,14 @@ <attr name="bottom" format="dimension" /> </declare-styleable> + <declare-styleable name="LayerDrawable"> + <attr name="opacity"> + <enum name="opaque" value="-1" /> + <enum name="transparent" value="-2" /> + <enum name="translucent" value="-3" /> + </attr> + </declare-styleable> + <declare-styleable name="LayerDrawableItem"> <attr name="left" /> <attr name="top" /> diff --git a/core/res/res/values/public.xml b/core/res/res/values/public.xml index b0be7e1..e319fa0 100644 --- a/core/res/res/values/public.xml +++ b/core/res/res/values/public.xml @@ -1378,6 +1378,7 @@ <public type="attr" name="state_accelerated" /> <public type="attr" name="baseline" /> <public type="attr" name="homeLayout" /> + <public type="attr" name="opacity" /> <public type="anim" name="animator_fade_in" /> <public type="anim" name="animator_fade_out" /> 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(); } |