@@ -896,24 +896,29 @@ public Drawable getDrawable() {
896
896
@ Override
897
897
public void getOutline (@ NonNull Outline outline ) {
898
898
if (android .os .Build .VERSION .SDK_INT >= 21 ) {
899
- outlineBackgroundPath .reset ();
900
- float [] backgroundRadii = {
901
- Math .max (0 , borderTopLeftRadius ), Math .max (0 , borderTopLeftRadius ),
902
- Math .max (0 , borderTopRightRadius ), Math .max (0 , borderTopRightRadius ),
903
- Math .max (0 , borderBottomRightRadius ), Math .max (0 , borderBottomRightRadius ),
904
- Math .max (0 , borderBottomLeftRadius ), Math .max (0 , borderBottomLeftRadius )
905
- };
906
899
outlineRectF .setEmpty ();
907
900
outlineRectF .set (getBounds ());
908
- outlineBackgroundPath .addRoundRect (outlineRectF , backgroundRadii , Path .Direction .CW );
909
-
910
- if (android .os .Build .VERSION .SDK_INT >= Build .VERSION_CODES .R ) {
911
- // see setConvexPath notes
912
- outline .setPath (outlineBackgroundPath );
901
+ if (hasUniformBorderRadius ()) {
902
+ outline .setRoundRect (getBounds (), borderTopLeftRadius );
913
903
} else {
914
- outline .setConvexPath (outlineBackgroundPath );
915
- }
904
+ // cliping with path is only support on API >= 33
905
+ // before it only works for rectangle, circle, or round rect
906
+ outlineBackgroundPath .reset ();
907
+ float [] backgroundRadii = {
908
+ Math .max (0 , borderTopLeftRadius ), Math .max (0 , borderTopLeftRadius ),
909
+ Math .max (0 , borderTopRightRadius ), Math .max (0 , borderTopRightRadius ),
910
+ Math .max (0 , borderBottomRightRadius ), Math .max (0 , borderBottomRightRadius ),
911
+ Math .max (0 , borderBottomLeftRadius ), Math .max (0 , borderBottomLeftRadius )
912
+ };
913
+ outlineBackgroundPath .addRoundRect (outlineRectF , backgroundRadii , Path .Direction .CW );
916
914
915
+ if (android .os .Build .VERSION .SDK_INT >= Build .VERSION_CODES .R ) {
916
+ // see setConvexPath notes
917
+ outline .setPath (outlineBackgroundPath );
918
+ } else {
919
+ outline .setConvexPath (outlineBackgroundPath );
920
+ }
921
+ }
917
922
} else {
918
923
throw new IllegalStateException ("Method supported on API 21 or higher" );
919
924
}
0 commit comments