Various API council fixes to drawables
BUG: 15089957
Change-Id: Ieaf468bbff092e68f6313d8a5ecccda8b753806d
diff --git a/api/current.txt b/api/current.txt
index b16eb2f..3092df2 100644
--- a/api/current.txt
+++ b/api/current.txt
@@ -865,6 +865,7 @@
field public static final int paddingBottom = 16842969; // 0x10100d9
field public static final int paddingEnd = 16843700; // 0x10103b4
field public static final int paddingLeft = 16842966; // 0x10100d6
+ field public static final int paddingMode = 16843866; // 0x101045a
field public static final int paddingRight = 16842968; // 0x10100d8
field public static final int paddingStart = 16843699; // 0x10103b3
field public static final int paddingTop = 16842967; // 0x10100d7
@@ -11259,16 +11260,6 @@
method public void startTransition(int);
}
- public class VectorDrawable extends android.graphics.drawable.Drawable {
- ctor public VectorDrawable();
- method public void draw(android.graphics.Canvas);
- method public int getOpacity();
- method public void setAlpha(int);
- method public void setColorFilter(android.graphics.ColorFilter);
- method public void setPadding(android.graphics.Rect);
- method public void setPadding(int, int, int, int);
- }
-
}
package android.graphics.drawable.shapes {
diff --git a/core/res/res/values/attrs.xml b/core/res/res/values/attrs.xml
index 3746780..73ffc79 100644
--- a/core/res/res/values/attrs.xml
+++ b/core/res/res/values/attrs.xml
@@ -4497,7 +4497,7 @@
RTL (right-to-left). -->
<attr name="autoMirrored" />
<!-- Indicates how layer padding should affect the bounds of subsequent layers.
- The default value is nest. -->
+ The default padding mode value is nest. -->
<attr name="paddingMode">
<!-- Nest each layer inside the padding of the previous layer. -->
<enum name="nest" value="0" />
diff --git a/core/res/res/values/public.xml b/core/res/res/values/public.xml
index 44b25f2b..3920faa 100644
--- a/core/res/res/values/public.xml
+++ b/core/res/res/values/public.xml
@@ -2177,6 +2177,7 @@
<public type="attr" name="contentInsetEnd" />
<public type="attr" name="contentInsetLeft" />
<public type="attr" name="contentInsetRight" />
+ <public type="attr" name="paddingMode" />
<public-padding type="dimen" name="l_resource_pad" end="0x01050010" />
diff --git a/graphics/java/android/graphics/drawable/Drawable.java b/graphics/java/android/graphics/drawable/Drawable.java
index b939636..002da57 100644
--- a/graphics/java/android/graphics/drawable/Drawable.java
+++ b/graphics/java/android/graphics/drawable/Drawable.java
@@ -1032,6 +1032,11 @@
return createFromXmlInnerThemed(r, parser, attrs, null);
}
+ /**
+ * Create a themed drawable from inside an XML document. Called on a parser
+ * positioned at a tag in an XML document, tries to create a Drawable from
+ * that tag. Returns null if the tag is not a valid drawable.
+ */
public static Drawable createFromXmlInnerThemed(Resources r, XmlPullParser parser,
AttributeSet attrs, Theme theme) throws XmlPullParserException, IOException {
final Drawable drawable;
diff --git a/graphics/java/android/graphics/drawable/LayerDrawable.java b/graphics/java/android/graphics/drawable/LayerDrawable.java
index 7847aad..93b9eab 100644
--- a/graphics/java/android/graphics/drawable/LayerDrawable.java
+++ b/graphics/java/android/graphics/drawable/LayerDrawable.java
@@ -38,10 +38,12 @@
* order, so the element with the largest index will be drawn on top.
* <p>
* It can be defined in an XML file with the <code><layer-list></code> element.
- * Each Drawable in the layer is defined in a nested <code><item></code>. For more
- * information, see the guide to <a
- * href="{@docRoot}guide/topics/resources/drawable-resource.html">Drawable Resources</a>.</p>
+ * Each Drawable in the layer is defined in a nested <code><item></code>.
+ * <p>
+ * For more information, see the guide to
+ * <a href="{@docRoot}guide/topics/resources/drawable-resource.html">Drawable Resources</a>.
*
+ * @attr ref android.R.styleable#LayerDrawable_paddingMode
* @attr ref android.R.styleable#LayerDrawableItem_left
* @attr ref android.R.styleable#LayerDrawableItem_top
* @attr ref android.R.styleable#LayerDrawableItem_right
@@ -53,10 +55,16 @@
/**
* Padding mode used to nest each layer inside the padding of the previous
* layer.
+ *
+ * @see #setPaddingMode(int)
*/
public static final int PADDING_MODE_NEST = 0;
- /** Padding mode used to stack each layer directly atop the previous layer. */
+ /**
+ * Padding mode used to stack each layer directly atop the previous layer.
+ *
+ * @see #setPaddingMode(int)
+ */
public static final int PADDING_MODE_STACK = 1;
LayerState mLayerState;
@@ -127,9 +135,8 @@
throws XmlPullParserException, IOException {
super.inflate(r, parser, attrs, theme);
- final TypedArray a = obtainAttributes(
- r, theme, attrs, R.styleable.LayerDrawable);
- inflateStateFromTypedArray(a);
+ final TypedArray a = obtainAttributes(r, theme, attrs, R.styleable.LayerDrawable);
+ updateStateFromTypedArray(a);
a.recycle();
inflateLayers(r, parser, attrs, theme);
@@ -141,25 +148,19 @@
/**
* Initializes the constant state from the values in the typed array.
*/
- private void inflateStateFromTypedArray(TypedArray a) {
+ private void updateStateFromTypedArray(TypedArray a) {
final LayerState state = mLayerState;
// Extract the theme attributes, if any.
final int[] themeAttrs = a.extractThemeAttrs();
state.mThemeAttrs = themeAttrs;
- if (themeAttrs == null || themeAttrs[R.styleable.LayerDrawable_opacity] == 0) {
- mOpacityOverride = a.getInt(R.styleable.LayerDrawable_opacity, PixelFormat.UNKNOWN);
- }
+ mOpacityOverride = a.getInt(R.styleable.LayerDrawable_opacity, mOpacityOverride);
- if (themeAttrs == null || themeAttrs[R.styleable.LayerDrawable_autoMirrored] == 0) {
- state.mAutoMirrored = a.getBoolean(R.styleable.LayerDrawable_autoMirrored, false);
- }
-
- if (themeAttrs == null || themeAttrs[R.styleable.LayerDrawableItem_drawable] == 0) {
- state.mPaddingMode = a.getInteger(
- R.styleable.LayerDrawableItem_drawable, PADDING_MODE_NEST);
- }
+ state.mAutoMirrored = a.getBoolean(R.styleable.LayerDrawable_autoMirrored,
+ state.mAutoMirrored);
+ state.mPaddingMode = a.getInteger(R.styleable.LayerDrawable_paddingMode,
+ state.mPaddingMode);
}
/**
@@ -181,9 +182,9 @@
continue;
}
- a = obtainAttributes(
- r, theme, attrs, R.styleable.LayerDrawableItem);
+ a = obtainAttributes(r, theme, attrs, R.styleable.LayerDrawableItem);
+ final int[] themeAttrs = a.extractThemeAttrs();
final int left = a.getDimensionPixelOffset(
R.styleable.LayerDrawableItem_left, 0);
final int top = a.getDimensionPixelOffset(
@@ -197,7 +198,6 @@
final int id = a.getResourceId(
R.styleable.LayerDrawableItem_id, View.NO_ID);
- // TODO: Cache typed array, if necessary.
a.recycle();
final Drawable dr;
@@ -214,7 +214,7 @@
dr = Drawable.createFromXmlInnerThemed(r, parser, attrs, theme);
}
- addLayer(dr, id, left, top, right, bottom);
+ addLayer(dr, themeAttrs, id, left, top, right, bottom);
}
}
@@ -224,7 +224,7 @@
final LayerState state = mLayerState;
if (state == null) {
- throw new RuntimeException("Can't apply theme to <layer-list> with no constant state");
+ return;
}
final int[] themeAttrs = state.mThemeAttrs;
@@ -239,9 +239,10 @@
final ChildDrawable[] array = mLayerState.mChildren;
final int N = mLayerState.mNum;
for (int i = 0; i < N; i++) {
- final Drawable layer = array[i].mDrawable;
- if (layer.canApplyTheme()) {
- layer.applyTheme(t);
+ final ChildDrawable layer = array[i];
+ final Drawable d = layer.mDrawable;
+ if (d.canApplyTheme()) {
+ d.applyTheme(t);
}
}
@@ -249,26 +250,6 @@
onStateChange(getState());
}
- /**
- * Updates the constant state from the values in the typed array.
- */
- private void updateStateFromTypedArray(TypedArray a) {
- final LayerState state = mLayerState;
-
- if (a.hasValue(R.styleable.LayerDrawable_opacity)) {
- mOpacityOverride = a.getInt(R.styleable.LayerDrawable_opacity, PixelFormat.UNKNOWN);
- }
-
- if (a.hasValue(R.styleable.LayerDrawable_autoMirrored)) {
- state.mAutoMirrored = a.getBoolean(R.styleable.LayerDrawable_autoMirrored, false);
- }
-
- if (a.hasValue(R.styleable.LayerDrawableItem_drawable)) {
- state.mPaddingMode = a.getInteger(
- R.styleable.LayerDrawableItem_drawable, PADDING_MODE_NEST);
- }
- }
-
@Override
public boolean canApplyTheme() {
final LayerState state = mLayerState;
@@ -283,14 +264,15 @@
final ChildDrawable[] array = state.mChildren;
final int N = state.mNum;
for (int i = 0; i < N; i++) {
- if (array[i].mDrawable.canApplyTheme()) {
+ final ChildDrawable layer = array[i];
+ if (layer.mThemeAttrs != null || layer.mDrawable.canApplyTheme()) {
return true;
}
}
return false;
}
-
+
/**
* @hide
*/
@@ -315,13 +297,15 @@
* Add a new layer to this drawable. The new layer is identified by an id.
*
* @param layer The drawable to add as a layer.
+ * @param themeAttrs Theme attributes extracted from the layer.
* @param id The id of the new layer.
* @param left The left padding of the new layer.
* @param top The top padding of the new layer.
* @param right The right padding of the new layer.
* @param bottom The bottom padding of the new layer.
*/
- private void addLayer(Drawable layer, int id, int left, int top, int right, int bottom) {
+ private void addLayer(Drawable layer, int[] themeAttrs, int id, int left, int top, int right,
+ int bottom) {
final LayerState st = mLayerState;
final int N = st.mChildren != null ? st.mChildren.length : 0;
final int i = st.mNum;
@@ -339,6 +323,7 @@
final ChildDrawable childDrawable = new ChildDrawable();
st.mChildren[i] = childDrawable;
childDrawable.mId = id;
+ childDrawable.mThemeAttrs = themeAttrs;
childDrawable.mDrawable = layer;
childDrawable.mDrawable.setAutoMirrored(isAutoMirrored());
childDrawable.mInsetL = left;
@@ -471,8 +456,14 @@
*
* @param mode padding mode, one of:
* <ul>
- * <li>{@link #PADDING_MODE_NEST} <li>{@link #PADDING_MODE_STACK}
+ * <li>{@link #PADDING_MODE_NEST} to nest each layer inside the
+ * padding of the previous layer
+ * <li>{@link #PADDING_MODE_STACK} to stack each layer directly
+ * atop the previous layer
* </ul>
+ *
+ * @see #getPaddingMode()
+ * @attr ref android.R.styleable#LayerDrawable_paddingMode
*/
public void setPaddingMode(int mode) {
if (mLayerState.mPaddingMode != mode) {
@@ -482,7 +473,9 @@
/**
* @return the current padding mode
+ *
* @see #setPaddingMode(int)
+ * @attr ref android.R.styleable#LayerDrawable_paddingMode
*/
public int getPaddingMode() {
return mLayerState.mPaddingMode;
@@ -936,7 +929,7 @@
private boolean mHaveIsStateful;
private boolean mIsStateful;
- private boolean mAutoMirrored;
+ private boolean mAutoMirrored = false;
private int mPaddingMode = PADDING_MODE_NEST;
diff --git a/graphics/java/android/graphics/drawable/RotateDrawable.java b/graphics/java/android/graphics/drawable/RotateDrawable.java
index edf1091..5f9d1cd 100644
--- a/graphics/java/android/graphics/drawable/RotateDrawable.java
+++ b/graphics/java/android/graphics/drawable/RotateDrawable.java
@@ -145,6 +145,9 @@
* Sets the start angle for rotation.
*
* @param fromDegrees Starting angle in degrees
+ *
+ * @see #getFromDegrees()
+ * @attr ref android.R.styleable#RotateDrawable_fromDegrees
*/
public void setFromDegrees(float fromDegrees) {
if (mState.mFromDegrees != fromDegrees) {
@@ -155,6 +158,9 @@
/**
* @return The starting angle for rotation in degrees
+ *
+ * @see #setFromDegrees(float)
+ * @attr ref android.R.styleable#RotateDrawable_fromDegrees
*/
public float getFromDegrees() {
return mState.mFromDegrees;
@@ -164,6 +170,9 @@
* Sets the end angle for rotation.
*
* @param toDegrees Ending angle in degrees
+ *
+ * @see #getToDegrees()
+ * @attr ref android.R.styleable#RotateDrawable_toDegrees
*/
public void setToDegrees(float toDegrees) {
if (mState.mToDegrees != toDegrees) {
@@ -174,6 +183,9 @@
/**
* @return The ending angle for rotation in degrees
+ *
+ * @see #setToDegrees(float)
+ * @attr ref android.R.styleable#RotateDrawable_toDegrees
*/
public float getToDegrees() {
return mState.mToDegrees;
@@ -186,7 +198,9 @@
* relative, the position represents a fraction of the drawable
* width. Otherwise, the position represents an absolute value in
* pixels.
+ *
* @see #setPivotXRelative(boolean)
+ * @attr ref android.R.styleable#RotateDrawable_pivotX
*/
public void setPivotX(float pivotX) {
if (mState.mPivotX == pivotX) {
@@ -197,7 +211,9 @@
/**
* @return X position around which to rotate
+ *
* @see #setPivotX(float)
+ * @attr ref android.R.styleable#RotateDrawable_pivotX
*/
public float getPivotX() {
return mState.mPivotX;
@@ -209,6 +225,8 @@
*
* @param relative True if the X pivot represents a fraction of the drawable
* width, or false if it represents an absolute value in pixels
+ *
+ * @see #isPivotXRelative()
*/
public void setPivotXRelative(boolean relative) {
if (mState.mPivotXRel == relative) {
@@ -220,6 +238,7 @@
/**
* @return True if the X pivot represents a fraction of the drawable width,
* or false if it represents an absolute value in pixels
+ *
* @see #setPivotXRelative(boolean)
*/
public boolean isPivotXRelative() {
@@ -233,7 +252,9 @@
* relative, the position represents a fraction of the drawable
* height. Otherwise, the position represents an absolute value
* in pixels.
- * @see #setPivotYRelative(boolean)
+ *
+ * @see #getPivotY()
+ * @attr ref android.R.styleable#RotateDrawable_pivotY
*/
public void setPivotY(float pivotY) {
if (mState.mPivotY == pivotY) {
@@ -244,7 +265,9 @@
/**
* @return Y position around which to rotate
+ *
* @see #setPivotY(float)
+ * @attr ref android.R.styleable#RotateDrawable_pivotY
*/
public float getPivotY() {
return mState.mPivotY;
@@ -256,6 +279,8 @@
*
* @param relative True if the Y pivot represents a fraction of the drawable
* height, or false if it represents an absolute value in pixels
+ *
+ * @see #isPivotYRelative()
*/
public void setPivotYRelative(boolean relative) {
if (mState.mPivotYRel == relative) {
@@ -267,6 +292,7 @@
/**
* @return True if the Y pivot represents a fraction of the drawable height,
* or false if it represents an absolute value in pixels
+ *
* @see #setPivotYRelative(boolean)
*/
public boolean isPivotYRelative() {