Skip to content

Commit 8136807

Browse files
committed
Use correct alpha value when a color is not set on a GradientDrawable.
A previous fix ensured that color filters would have a default (black) color to interact with if no color was set on the GradientDrawable object. However, that fix assumed an opaque alpha value, which is not always the case. Specifically, calling setImageAlpha() on an ImageView with a shape drawable source (as in the bug here) caused the alpha to be set to a translucent value, which was then ignored in the fix above. The fix is to account for the current alpha value of the GradientDrawable object when setting the color used by the paint object. Issue #7592193 ImageView.setImageAlpha() broken when colorFilter is in use Change-Id: Ie622ffca776fdd8731ced78ce1f683ca6a51dec8
1 parent 3f64ede commit 8136807

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

graphics/java/android/graphics/drawable/GradientDrawable.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -479,7 +479,7 @@ of the fill (if any) without worrying about blending artifacts.
479479
mFillPaint.setDither(mDither);
480480
mFillPaint.setColorFilter(mColorFilter);
481481
if (mColorFilter != null && !mGradientState.mHasSolidColor) {
482-
mFillPaint.setColor(0xff000000);
482+
mFillPaint.setColor(mAlpha << 24);
483483
}
484484
if (haveStroke) {
485485
mStrokePaint.setAlpha(currStrokeAlpha);
@@ -743,7 +743,7 @@ private boolean ensureValidRect() {
743743
mFillPaint.setShader(new LinearGradient(x0, y0, x1, y1,
744744
colors, st.mPositions, Shader.TileMode.CLAMP));
745745
if (!mGradientState.mHasSolidColor) {
746-
mFillPaint.setColor(0xff000000);
746+
mFillPaint.setColor(mAlpha << 24);
747747
}
748748
} else if (st.mGradient == RADIAL_GRADIENT) {
749749
x0 = r.left + (r.right - r.left) * st.mCenterX;
@@ -755,7 +755,7 @@ private boolean ensureValidRect() {
755755
level * st.mGradientRadius, colors, null,
756756
Shader.TileMode.CLAMP));
757757
if (!mGradientState.mHasSolidColor) {
758-
mFillPaint.setColor(0xff000000);
758+
mFillPaint.setColor(mAlpha << 24);
759759
}
760760
} else if (st.mGradient == SWEEP_GRADIENT) {
761761
x0 = r.left + (r.right - r.left) * st.mCenterX;
@@ -788,7 +788,7 @@ private boolean ensureValidRect() {
788788
}
789789
mFillPaint.setShader(new SweepGradient(x0, y0, tempColors, tempPositions));
790790
if (!mGradientState.mHasSolidColor) {
791-
mFillPaint.setColor(0xff000000);
791+
mFillPaint.setColor(mAlpha << 24);
792792
}
793793
}
794794
}

0 commit comments

Comments
 (0)