Skip to content

Commit d51ae67

Browse files
ymarianhunterstich
authored andcommitted
[MaterialShapeDrawable] Fixed exception with int division
Resolves #937 PiperOrigin-RevId: 319778531 (cherry picked from commit 26fc10c)
1 parent b9d70d3 commit d51ae67

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

lib/java/com/google/android/material/shadow/ShadowRenderer.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -149,16 +149,21 @@ public void drawCornerShadow(
149149
cornerColors[3] = shadowEndColor;
150150
}
151151

152-
float startRatio = 1f - (elevation / (bounds.width() / 2f));
152+
float radius = bounds.width() / 2f;
153+
// The shadow is not big enough to draw.
154+
if (radius <= 0) {
155+
return;
156+
}
157+
158+
float startRatio = 1f - (elevation / radius);
153159
float midRatio = startRatio + ((1f - startRatio) / 2f);
154160
cornerPositions[1] = startRatio;
155161
cornerPositions[2] = midRatio;
156-
157162
cornerShadowPaint.setShader(
158163
new RadialGradient(
159164
bounds.centerX(),
160165
bounds.centerY(),
161-
bounds.width() / 2,
166+
radius,
162167
cornerColors,
163168
cornerPositions,
164169
Shader.TileMode.CLAMP));

0 commit comments

Comments
 (0)