Skip to content

Commit 7bc26e5

Browse files
pubiqqdrchen
authored andcommittedApr 12, 2023
[Carousel] Fix item masking for API 21
Resolves #3330 GIT_ORIGIN_REV_ID=1c46e2882b074e35ab1f19af0af00f88dee84f4c PiperOrigin-RevId: 523119333
1 parent 176ce5e commit 7bc26e5

File tree

2 files changed

+17
-16
lines changed

2 files changed

+17
-16
lines changed
 

‎lib/java/com/google/android/material/carousel/MaskableFrameLayout.java

+9-8
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,8 @@ public MaskableFrameLayout(
7474
private MaskableDelegate createMaskableDelegate() {
7575
if (VERSION.SDK_INT >= VERSION_CODES.TIRAMISU) {
7676
return new MaskableDelegateV33(this);
77-
} else if (VERSION.SDK_INT >= VERSION_CODES.LOLLIPOP) {
78-
return new MaskableDelegateV21(this);
77+
} else if (VERSION.SDK_INT >= VERSION_CODES.LOLLIPOP_MR1) {
78+
return new MaskableDelegateV22(this);
7979
} else {
8080
return new MaskableDelegateV14();
8181
}
@@ -302,7 +302,7 @@ void maybeClip(Canvas canvas, CanvasOperation op) {
302302
}
303303

304304
/**
305-
* A {@link MaskableDelegate} implementation for API 14-20 that always clips using canvas
305+
* A {@link MaskableDelegate} implementation for API 14-21 that always clips using canvas
306306
* clipping.
307307
*/
308308
private static class MaskableDelegateV14 extends MaskableDelegate {
@@ -325,19 +325,20 @@ void invalidateClippingMethod(View view) {
325325
}
326326

327327
/**
328-
* A {@link MaskableDelegate} for API 21-32 that uses {@link ViewOutlineProvider} to clip when the
328+
* A {@link MaskableDelegate} for API 22-32 that uses {@link ViewOutlineProvider} to clip when the
329329
* shape being clipped is a round rect with symmetrical corners and canvas clipping for all other
330-
* shapes.
330+
* shapes. This way is not used for API 21 because outline invalidation is incorrectly implemented
331+
* in this version.
331332
*
332333
* <p>{@link Outline#setRoundRect(Rect, float)} is only able to clip to a rectangle with a single
333334
* corner radius for all four corners.
334335
*/
335-
@RequiresApi(VERSION_CODES.LOLLIPOP)
336-
private static class MaskableDelegateV21 extends MaskableDelegate {
336+
@RequiresApi(VERSION_CODES.LOLLIPOP_MR1)
337+
private static class MaskableDelegateV22 extends MaskableDelegate {
337338

338339
private boolean isShapeRoundRect = false;
339340

340-
MaskableDelegateV21(View view) {
341+
MaskableDelegateV22(View view) {
341342
initMaskOutlineProvider(view);
342343
}
343344

‎lib/javatests/com/google/android/material/carousel/MaskableFrameLayoutTest.java

+8-8
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,8 @@ public void testShapeAppearanceWithAbsoluteCornerSizes_shouldBeClamped() {
7474
assertThat(topRightCornerSize.getCornerSize(maskableFrameLayout.getMaskRectF())).isEqualTo(25F);
7575
}
7676

77-
@RequiresApi(api = VERSION_CODES.LOLLIPOP)
78-
@Config(sdk = VERSION_CODES.LOLLIPOP)
77+
@RequiresApi(api = VERSION_CODES.LOLLIPOP_MR1)
78+
@Config(sdk = VERSION_CODES.LOLLIPOP_MR1)
7979
@Test
8080
public void testForceCompatClipping_shouldNotUseViewOutlineProvider() {
8181
MaskableFrameLayout maskableFrameLayout = createMaskableFrameLayoutWithSize(50, 50);
@@ -87,21 +87,21 @@ public void testForceCompatClipping_shouldNotUseViewOutlineProvider() {
8787
assertThat(maskableFrameLayout.getClipToOutline()).isFalse();
8888
}
8989

90-
@RequiresApi(api = VERSION_CODES.LOLLIPOP)
91-
@Config(sdk = VERSION_CODES.LOLLIPOP)
90+
@RequiresApi(api = VERSION_CODES.LOLLIPOP_MR1)
91+
@Config(sdk = VERSION_CODES.LOLLIPOP_MR1)
9292
@Test
93-
public void testRoundedCornersApi21_usesViewOutlineProvider() {
93+
public void testRoundedCornersApi22_usesViewOutlineProvider() {
9494
MaskableFrameLayout maskableFrameLayout = createMaskableFrameLayoutWithSize(50, 50);
9595
ShapeAppearanceModel model = new ShapeAppearanceModel.Builder().setAllCornerSizes(10F).build();
9696
maskableFrameLayout.setShapeAppearanceModel(model);
9797

9898
assertThat(maskableFrameLayout.getClipToOutline()).isTrue();
9999
}
100100

101-
@RequiresApi(api = VERSION_CODES.LOLLIPOP)
102-
@Config(sdk = VERSION_CODES.LOLLIPOP)
101+
@RequiresApi(api = VERSION_CODES.LOLLIPOP_MR1)
102+
@Config(sdk = VERSION_CODES.LOLLIPOP_MR1)
103103
@Test
104-
public void testCutCornersApi21_doesNotUseViewOutlineProvider() {
104+
public void testCutCornersApi22_doesNotUseViewOutlineProvider() {
105105
MaskableFrameLayout maskableFrameLayout = createMaskableFrameLayoutWithSize(50, 50);
106106
ShapeAppearanceModel model =
107107
new ShapeAppearanceModel.Builder()

0 commit comments

Comments
 (0)
Please sign in to comment.