Merge "Add tileModeX/Y attrs to BitmapDrawable, tint to ShapeDrawable"
This commit is contained in:
committed by
Android (Google) Code Review
commit
24c492d3bb
@@ -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
|
||||
|
||||
@@ -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>
|
||||
|
||||
<!-- ========================== -->
|
||||
|
||||
@@ -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" />
|
||||
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user