diff options
| author | 2014-06-20 16:18:58 -0700 | |
|---|---|---|
| committer | 2014-06-23 12:47:43 -0700 | |
| commit | 22594f097242d9de0a538a9b8142f77da9df7ebd (patch) | |
| tree | 78cdb13c8d1eff5c0c36123133bfad13d2818d10 | |
| parent | a559f2af166a25b724040961f4e8402053170c71 (diff) | |
Add tileModeX/Y attrs to BitmapDrawable, tint to ShapeDrawable
Change-Id: I1c9efe39bfd5286230cee8354822db81f05186e4
| -rw-r--r-- | api/current.txt | 2 | ||||
| -rw-r--r-- | core/res/res/values/attrs.xml | 32 | ||||
| -rw-r--r-- | core/res/res/values/public.xml | 2 | ||||
| -rw-r--r-- | graphics/java/android/graphics/drawable/BitmapDrawable.java | 33 | ||||
| -rw-r--r-- | graphics/java/android/graphics/drawable/ShapeDrawable.java | 31 |
5 files changed, 87 insertions, 13 deletions
diff --git a/api/current.txt b/api/current.txt index c8b3b3b570ed..6a8b2be9d8ad 100644 --- a/api/current.txt +++ b/api/current.txt @@ -1239,6 +1239,8 @@ package android { field public static final int thumbTintMode = 16843892; // 0x1010474 field public static final int thumbnail = 16843429; // 0x10102a5 field public static final int tileMode = 16843265; // 0x1010201 + field public static final int tileModeX = 16843897; // 0x1010479 + field public static final int tileModeY = 16843898; // 0x101047a field public static final int timeZone = 16843724; // 0x10103cc field public static final int tint = 16843041; // 0x1010121 field public static final int tintMode = 16843797; // 0x1010415 diff --git a/core/res/res/values/attrs.xml b/core/res/res/values/attrs.xml index 02a8863803a8..a8a4d7a78ef3 100644 --- a/core/res/res/values/attrs.xml +++ b/core/res/res/values/attrs.xml @@ -4813,6 +4813,32 @@ mirror images so that adjacent images always seam. --> <enum name="mirror" value="2" /> </attr> + <!-- Defines the horizontal tile mode. When the tile mode is enabled, the bitmap is repeated. + Gravity is ignored when the tile mode is enabled. Default value is "disabled". --> + <attr name="tileModeX"> + <!-- Do not tile the bitmap. This is the default value. --> + <enum name="disabled" value="-1" /> + <!-- Replicates the edge color. --> + <enum name="clamp" value="0" /> + <!-- Repeats the bitmap in both direction. --> + <enum name="repeat" value="1" /> + <!-- Repeats the shader's image horizontally and vertically, alternating + mirror images so that adjacent images always seam. --> + <enum name="mirror" value="2" /> + </attr> + <!-- Defines the vertical tile mode. When the tile mode is enabled, the bitmap is repeated. + Gravity is ignored when the tile mode is enabled. Default value is "disabled". --> + <attr name="tileModeY"> + <!-- Do not tile the bitmap. This is the default value. --> + <enum name="disabled" value="-1" /> + <!-- Replicates the edge color. --> + <enum name="clamp" value="0" /> + <!-- Repeats the bitmap in both direction. --> + <enum name="repeat" value="1" /> + <!-- Repeats the shader's image horizontally and vertically, alternating + mirror images so that adjacent images always seam. --> + <enum name="mirror" value="2" /> + </attr> <!-- Enables or disables the mipmap hint. See {@link android.graphics.Bitmap#setHasMipMap(boolean)} for more information. Default value is false. --> @@ -4971,6 +4997,12 @@ <attr name="height" /> <!-- Enables or disables dithering. --> <attr name="dither" /> + <!-- If set, specifies the color to apply to the drawable as a tint. By default, + no tint is applied. May be a color state list. --> + <attr name="tint" /> + <!-- When a tint color is set, specifies its Porter-Duff blending mode. The + default value is src_in, which treats the drawable as an alpha mask. --> + <attr name="tintMode" /> </declare-styleable> <!-- ========================== --> diff --git a/core/res/res/values/public.xml b/core/res/res/values/public.xml index 6e9dc93c4188..28e66d5e3aa2 100644 --- a/core/res/res/values/public.xml +++ b/core/res/res/values/public.xml @@ -2210,6 +2210,8 @@ <public type="attr" name="propertyXName" /> <public type="attr" name="propertyYName" /> <public type="attr" name="relinquishTaskIdentity" /> + <public type="attr" name="tileModeX" /> + <public type="attr" name="tileModeY" /> <public-padding type="dimen" name="l_resource_pad" end="0x01050010" /> diff --git a/graphics/java/android/graphics/drawable/BitmapDrawable.java b/graphics/java/android/graphics/drawable/BitmapDrawable.java index 0a394d56d322..e08037599650 100644 --- a/graphics/java/android/graphics/drawable/BitmapDrawable.java +++ b/graphics/java/android/graphics/drawable/BitmapDrawable.java @@ -757,7 +757,18 @@ public class BitmapDrawable extends Drawable { final int tileMode = a.getInt(R.styleable.BitmapDrawable_tileMode, TILE_MODE_UNDEFINED); if (tileMode != TILE_MODE_UNDEFINED) { - setTileModeInternal(tileMode); + final Shader.TileMode mode = parseTileMode(tileMode); + setTileModeXY(mode, mode); + } + + final int tileModeX = a.getInt(R.styleable.BitmapDrawable_tileModeX, TILE_MODE_UNDEFINED); + if (tileModeX != TILE_MODE_UNDEFINED) { + setTileModeX(parseTileMode(tileModeX)); + } + + final int tileModeY = a.getInt(R.styleable.BitmapDrawable_tileModeY, TILE_MODE_UNDEFINED); + if (tileModeY != TILE_MODE_UNDEFINED) { + setTileModeY(parseTileMode(tileModeY)); } // Update local properties. @@ -783,20 +794,16 @@ public class BitmapDrawable extends Drawable { } } - private void setTileModeInternal(final int tileMode) { + private static Shader.TileMode parseTileMode(int tileMode) { switch (tileMode) { - case TILE_MODE_DISABLED: - setTileModeXY(null, null); - break; case TILE_MODE_CLAMP: - setTileModeXY(Shader.TileMode.CLAMP, Shader.TileMode.CLAMP); - break; + return Shader.TileMode.CLAMP; case TILE_MODE_REPEAT: - setTileModeXY(Shader.TileMode.REPEAT, Shader.TileMode.REPEAT); - break; + return Shader.TileMode.REPEAT; case TILE_MODE_MIRROR: - setTileModeXY(Shader.TileMode.MIRROR, Shader.TileMode.MIRROR); - break; + return Shader.TileMode.MIRROR; + default: + return null; } } @@ -919,7 +926,9 @@ public class BitmapDrawable extends Drawable { } /** - * Initializes local dynamic properties from state. + * Initializes local dynamic properties from state. This should be called + * after significant state changes, e.g. from the One True Constructor and + * after inflating or applying a theme. */ private void initializeWithState(BitmapState state, Resources res) { if (res != null) { diff --git a/graphics/java/android/graphics/drawable/ShapeDrawable.java b/graphics/java/android/graphics/drawable/ShapeDrawable.java index 369bb591803d..86765dd4d20f 100644 --- a/graphics/java/android/graphics/drawable/ShapeDrawable.java +++ b/graphics/java/android/graphics/drawable/ShapeDrawable.java @@ -396,6 +396,9 @@ public class ShapeDrawable extends Drawable { " for ShapeDrawable " + this); } } + + // Update local properties. + initializeWithState(mShapeState, r); } @Override @@ -410,6 +413,9 @@ public class ShapeDrawable extends Drawable { final TypedArray a = t.resolveAttributes(state.mThemeAttrs, R.styleable.ShapeDrawable); updateStateFromTypedArray(a); a.recycle(); + + // Update local properties. + initializeWithState(state, t.getResources()); } private void updateStateFromTypedArray(TypedArray a) { @@ -431,6 +437,16 @@ public class ShapeDrawable extends Drawable { R.styleable.ShapeDrawable_width, state.mIntrinsicWidth)); setIntrinsicHeight((int) a.getDimension( R.styleable.ShapeDrawable_height, state.mIntrinsicHeight)); + + final int tintMode = a.getInt(R.styleable.ShapeDrawable_tintMode, -1); + if (tintMode != -1) { + state.mTintMode = Drawable.parseTintMode(tintMode, Mode.SRC_IN); + } + + final ColorStateList tint = a.getColorStateList(R.styleable.ShapeDrawable_tint); + if (tint != null) { + state.mTint = tint; + } } private void updateShape() { @@ -545,6 +561,10 @@ public class ShapeDrawable extends Drawable { } } + /** + * The one constructor to rule them all. This is called by all public + * constructors to set the state and initialize local properties. + */ private ShapeDrawable(ShapeState state, Resources res, Theme theme) { if (theme != null && state.canApplyTheme()) { mShapeState = new ShapeState(state); @@ -553,7 +573,16 @@ public class ShapeDrawable extends Drawable { mShapeState = state; } - mTintFilter = updateTintFilter(mTintFilter, mShapeState.mTint, mShapeState.mTintMode); + initializeWithState(state, res); + } + + /** + * Initializes local dynamic properties from state. This should be called + * after significant state changes, e.g. from the One True Constructor and + * after inflating or applying a theme. + */ + private void initializeWithState(ShapeState state, Resources res) { + mTintFilter = updateTintFilter(mTintFilter, state.mTint, state.mTintMode); } /** |