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
This commit is contained in:
Joe Onorato
2010-11-17 20:42:00 -08:00
parent 3f1845ffec
commit e70b375c4b
4 changed files with 62 additions and 2 deletions

View File

@@ -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"

View File

@@ -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" />

View File

@@ -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" />

View File

@@ -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();
}