diff options
author | Alan Viverette <alanv@google.com> | 2014-05-20 17:45:52 +0000 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2014-05-20 17:45:52 +0000 |
commit | f31512eb17b6327c5f81bfb8a69c3a6119a0dd66 (patch) | |
tree | f943aef163183fb7727f3864fb8ba67a05d35634 /graphics | |
parent | b5eb843e4b7c56259e2609e2e668bf5a4cd51f42 (diff) | |
parent | e5b082d6eb0489e7dbe3159338f8c94c0af61dee (diff) | |
download | frameworks_base-f31512eb17b6327c5f81bfb8a69c3a6119a0dd66.zip frameworks_base-f31512eb17b6327c5f81bfb8a69c3a6119a0dd66.tar.gz frameworks_base-f31512eb17b6327c5f81bfb8a69c3a6119a0dd66.tar.bz2 |
Merge "Various API council fixes to drawables"
Diffstat (limited to 'graphics')
3 files changed, 77 insertions, 53 deletions
diff --git a/graphics/java/android/graphics/drawable/Drawable.java b/graphics/java/android/graphics/drawable/Drawable.java index c78096a..3eabc3a 100644 --- a/graphics/java/android/graphics/drawable/Drawable.java +++ b/graphics/java/android/graphics/drawable/Drawable.java @@ -1005,6 +1005,11 @@ public abstract class Drawable { 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 373d894..f446000 100644 --- a/graphics/java/android/graphics/drawable/LayerDrawable.java +++ b/graphics/java/android/graphics/drawable/LayerDrawable.java @@ -38,10 +38,12 @@ import java.io.IOException; * 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 @@ public class LayerDrawable extends Drawable implements Drawable.Callback { /** * 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 @@ public class LayerDrawable extends Drawable implements Drawable.Callback { 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 @@ public class LayerDrawable extends Drawable implements Drawable.Callback { /** * 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); - } - - if (themeAttrs == null || themeAttrs[R.styleable.LayerDrawable_autoMirrored] == 0) { - state.mAutoMirrored = a.getBoolean(R.styleable.LayerDrawable_autoMirrored, false); - } + mOpacityOverride = a.getInt(R.styleable.LayerDrawable_opacity, mOpacityOverride); - 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 @@ public class LayerDrawable extends Drawable implements Drawable.Callback { 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 @@ public class LayerDrawable extends Drawable implements Drawable.Callback { 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 @@ public class LayerDrawable extends Drawable implements Drawable.Callback { 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 @@ public class LayerDrawable extends Drawable implements Drawable.Callback { 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 @@ public class LayerDrawable extends Drawable implements Drawable.Callback { 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 @@ public class LayerDrawable extends Drawable implements Drawable.Callback { 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 @@ public class LayerDrawable extends Drawable implements Drawable.Callback { 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 @@ public class LayerDrawable extends Drawable implements Drawable.Callback { * 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 @@ public class LayerDrawable extends Drawable implements Drawable.Callback { 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 @@ public class LayerDrawable extends Drawable implements Drawable.Callback { * * @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 @@ public class LayerDrawable extends Drawable implements Drawable.Callback { /** * @return the current padding mode + * * @see #setPaddingMode(int) + * @attr ref android.R.styleable#LayerDrawable_paddingMode */ public int getPaddingMode() { return mLayerState.mPaddingMode; @@ -905,7 +898,7 @@ public class LayerDrawable extends Drawable implements Drawable.Callback { 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 @@ public class RotateDrawable extends Drawable implements Drawable.Callback { * 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 @@ public class RotateDrawable extends Drawable implements Drawable.Callback { /** * @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 @@ public class RotateDrawable extends Drawable implements Drawable.Callback { * 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 @@ public class RotateDrawable extends Drawable implements Drawable.Callback { /** * @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 @@ public class RotateDrawable extends Drawable implements Drawable.Callback { * 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 @@ public class RotateDrawable extends Drawable implements Drawable.Callback { /** * @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 @@ public class RotateDrawable extends Drawable implements Drawable.Callback { * * @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 @@ public class RotateDrawable extends Drawable implements Drawable.Callback { /** * @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 @@ public class RotateDrawable extends Drawable implements Drawable.Callback { * 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 @@ public class RotateDrawable extends Drawable implements Drawable.Callback { /** * @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 @@ public class RotateDrawable extends Drawable implements Drawable.Callback { * * @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 @@ public class RotateDrawable extends Drawable implements Drawable.Callback { /** * @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() { |