Simplify GradientDrawable's use of ColorStateList
BUG: 12816352
Change-Id: Icff432ee5d460ca733866185b8bf61fd50248cfc
diff --git a/graphics/java/android/graphics/drawable/GradientDrawable.java b/graphics/java/android/graphics/drawable/GradientDrawable.java
index 6a9454c..6b0f7ba 100644
--- a/graphics/java/android/graphics/drawable/GradientDrawable.java
+++ b/graphics/java/android/graphics/drawable/GradientDrawable.java
@@ -266,7 +266,7 @@
* @see #setStroke(int, int)
*/
public void setStroke(int width, int color, float dashWidth, float dashGap) {
- mGradientState.setStroke(width, color, dashWidth, dashGap);
+ mGradientState.setStroke(width, ColorStateList.valueOf(color), dashWidth, dashGap);
setStrokeInternal(width, color, dashWidth, dashGap);
}
@@ -288,15 +288,15 @@
*/
public void setStroke(
int width, ColorStateList colorStateList, float dashWidth, float dashGap) {
+ mGradientState.setStroke(width, colorStateList, dashWidth, dashGap);
+ final int color;
if (colorStateList == null) {
- setStroke(width, Color.TRANSPARENT, dashWidth, dashGap);
+ color = Color.TRANSPARENT;
} else {
- mGradientState.setStroke(width, colorStateList, dashWidth, dashGap);
-
final int[] stateSet = getState();
- final int color = colorStateList.getColorForState(stateSet, 0);
- setStrokeInternal(width, color, dashWidth, dashGap);
+ color = colorStateList.getColorForState(stateSet, 0);
}
+ setStrokeInternal(width, color, dashWidth, dashGap);
}
private void setStrokeInternal(int width, int color, float dashWidth, float dashGap) {
@@ -529,8 +529,7 @@
mFillPaint.setAlpha(currFillAlpha);
mFillPaint.setDither(mDither);
mFillPaint.setColorFilter(mColorFilter);
- if (mColorFilter != null && !mGradientState.mHasSolidColor
- && mGradientState.mColorStateList == null) {
+ if (mColorFilter != null && mGradientState.mColorStateList == null) {
mFillPaint.setColor(mAlpha << 24);
}
if (haveStroke) {
@@ -672,7 +671,7 @@
* @see #setColors(int[])
*/
public void setColor(int argb) {
- mGradientState.setSolidColor(argb);
+ mGradientState.setColorStateList(ColorStateList.valueOf(argb));
mFillPaint.setColor(argb);
invalidateSelf();
}
@@ -691,14 +690,16 @@
* @see #mutate()
*/
public void setColor(ColorStateList colorStateList) {
+ mGradientState.setColorStateList(colorStateList);
+ final int color;
if (colorStateList == null) {
- setColor(Color.TRANSPARENT);
+ color = Color.TRANSPARENT;
} else {
- final int color = colorStateList.getColorForState(getState(), 0);
- mGradientState.setColorStateList(colorStateList);
- mFillPaint.setColor(color);
- invalidateSelf();
+ final int[] stateSet = getState();
+ color = colorStateList.getColorForState(stateSet, 0);
}
+ mFillPaint.setColor(color);
+ invalidateSelf();
}
@Override
@@ -910,7 +911,7 @@
// If we don't have a solid color, the alpha channel must be
// maxed out so that alpha modulation works correctly.
- if (!st.mHasSolidColor && st.mColorStateList == null) {
+ if (st.mColorStateList == null) {
mFillPaint.setColor(Color.BLACK);
}
}
@@ -1202,10 +1203,7 @@
public int[] mTempColors; // no need to copy
public float[] mTempPositions; // no need to copy
public float[] mPositions;
- public boolean mHasSolidColor;
- public int mSolidColor;
public int mStrokeWidth = -1; // if >= 0 use stroking.
- public int mStrokeColor;
public float mStrokeDashWidth;
public float mStrokeDashGap;
public float mRadius; // use this if mRadiusArray is null
@@ -1241,10 +1239,8 @@
if (state.mPositions != null) {
mPositions = state.mPositions.clone();
}
- mHasSolidColor = state.mHasSolidColor;
- mSolidColor = state.mSolidColor;
+ mStrokeColorStateList = state.mStrokeColorStateList;
mStrokeWidth = state.mStrokeWidth;
- mStrokeColor = state.mStrokeColor;
mStrokeDashWidth = state.mStrokeDashWidth;
mStrokeDashGap = state.mStrokeDashGap;
mRadius = state.mRadius;
@@ -1298,22 +1294,12 @@
}
public void setColors(int[] colors) {
- mHasSolidColor = false;
mColors = colors;
mColorStateList = null;
computeOpacity();
}
-
- public void setSolidColor(int argb) {
- mHasSolidColor = argb != Color.TRANSPARENT;
- mSolidColor = argb;
- mColors = null;
- mColorStateList = null;
- computeOpacity();
- }
public void setColorStateList(ColorStateList colorStateList) {
- mHasSolidColor = false;
mColors = null;
mColorStateList = colorStateList;
computeOpacity();
@@ -1336,9 +1322,6 @@
mOpaque = false;
return;
}
- } else if (!isOpaque(mStrokeColor)) {
- mOpaque = false;
- return;
}
}
@@ -1347,11 +1330,6 @@
return;
}
- if (mHasSolidColor) {
- mOpaque = isOpaque(mSolidColor);
- return;
- }
-
if (mColors != null) {
for (int i = 0; i < mColors.length; i++) {
if (!isOpaque(mColors[i])) {
@@ -1368,22 +1346,6 @@
return ((color >> 24) & 0xff) == 0xff;
}
- public void setStroke(int width, int color) {
- mStrokeWidth = width;
- mStrokeColor = color;
- mStrokeColorStateList = null;
- computeOpacity();
- }
-
- public void setStroke(int width, int color, float dashWidth, float dashGap) {
- mStrokeWidth = width;
- mStrokeColor = color;
- mStrokeColorStateList = null;
- mStrokeDashWidth = dashWidth;
- mStrokeDashGap = dashGap;
- computeOpacity();
- }
-
public void setStroke(
int width, ColorStateList colorStateList, float dashWidth, float dashGap) {
mStrokeWidth = width;
@@ -1426,9 +1388,7 @@
}
private void initializeWithState(GradientState state) {
- if (state.mHasSolidColor) {
- mFillPaint.setColor(state.mSolidColor);
- } else if (state.mColorStateList != null) {
+ if (state.mColorStateList != null) {
final int[] currentState = getState();
final int stateColor = state.mColorStateList.getColorForState(currentState, 0);
mFillPaint.setColor(stateColor);
@@ -1451,8 +1411,6 @@
final int strokeStateColor = state.mStrokeColorStateList.getColorForState(
currentState, 0);
mStrokePaint.setColor(strokeStateColor);
- } else {
- mStrokePaint.setColor(state.mStrokeColor);
}
if (state.mStrokeDashWidth != 0.0f) {