|
16 | 16 |
|
17 | 17 | package com.google.android.material.drawable;
|
18 | 18 |
|
| 19 | +import com.google.android.material.R; |
| 20 | + |
19 | 21 | import static java.lang.Math.max;
|
20 | 22 |
|
21 | 23 | import android.annotation.SuppressLint;
|
|
41 | 43 | import android.util.Xml;
|
42 | 44 | import android.view.Gravity;
|
43 | 45 | import androidx.annotation.ColorInt;
|
| 46 | +import androidx.annotation.DoNotInline; |
44 | 47 | import androidx.annotation.NonNull;
|
45 | 48 | import androidx.annotation.Nullable;
|
46 | 49 | import androidx.annotation.Px;
|
| 50 | +import androidx.annotation.RequiresApi; |
47 | 51 | import androidx.annotation.RestrictTo;
|
48 | 52 | import androidx.annotation.RestrictTo.Scope;
|
49 | 53 | import androidx.annotation.XmlRes;
|
@@ -359,18 +363,18 @@ public static int[] getUncheckedState(@NonNull int[] state) {
|
359 | 363 | /** Sets the Outline to a {@link android.graphics.Path path}, if possible. */
|
360 | 364 | public static void setOutlineToPath(@NonNull final Outline outline, @NonNull final Path path) {
|
361 | 365 | if (VERSION.SDK_INT >= VERSION_CODES.R) {
|
362 |
| - outline.setPath(path); |
| 366 | + OutlineCompatR.setPath(outline, path); |
363 | 367 | } else if (VERSION.SDK_INT >= VERSION_CODES.Q) {
|
364 | 368 | try {
|
365 | 369 | // As of Android Q, the restriction that the path must be convex is removed, but the API is
|
366 | 370 | // misnamed until the introduction of setPath() in R, so we have to use setConvexPath for Q.
|
367 |
| - outline.setConvexPath(path); |
| 371 | + OutlineCompatL.setConvexPath(outline, path); |
368 | 372 | } catch (IllegalArgumentException ignored) {
|
369 | 373 | // The change to support concave paths was done late in the release cycle. People
|
370 | 374 | // using pre-releases of Q would experience a crash here.
|
371 | 375 | }
|
372 | 376 | } else if (VERSION.SDK_INT >= VERSION_CODES.LOLLIPOP && path.isConvex()) {
|
373 |
| - outline.setConvexPath(path); |
| 377 | + OutlineCompatL.setConvexPath(outline, path); |
374 | 378 | }
|
375 | 379 | }
|
376 | 380 |
|
@@ -401,4 +405,22 @@ public static ColorStateList getColorStateListOrNull(@Nullable final Drawable dr
|
401 | 405 |
|
402 | 406 | return null;
|
403 | 407 | }
|
| 408 | + |
| 409 | + @RequiresApi(VERSION_CODES.R) |
| 410 | + private static class OutlineCompatR { |
| 411 | + // Avoid class verification failures on older Android versions. |
| 412 | + @DoNotInline |
| 413 | + static void setPath(@NonNull Outline outline, @NonNull Path path) { |
| 414 | + outline.setPath(path); |
| 415 | + } |
| 416 | + } |
| 417 | + |
| 418 | + @RequiresApi(VERSION_CODES.LOLLIPOP) |
| 419 | + private static class OutlineCompatL { |
| 420 | + // Avoid class verification failures on older Android versions. |
| 421 | + @DoNotInline |
| 422 | + static void setConvexPath(@NonNull Outline outline, @NonNull Path path) { |
| 423 | + outline.setConvexPath(path); |
| 424 | + } |
| 425 | + } |
404 | 426 | }
|
0 commit comments