22
33import java .util .Locale ;
44
5- public class LocaleCompat {
5+ /**
6+ * This class contains a simple implementation of {@link Locale#forLanguageTag(String)} for Android
7+ * API levels below 21 (Lollipop). This is needed as core library desugaring does not backport that
8+ * method as of this writing.
9+ *
10+ * Relevant issue: https://issuetracker.google.com/issues/171182330
11+ */
12+ public final class LocaleCompat {
613 private LocaleCompat () {
714 }
815
9- // Source: LocaleListCompat's private forLanguageTagCompat() method.
10- // Use Locale.forLanguageTag() on API level >= 21 instead.
16+ // Source: The AndroidX LocaleListCompat class 's private forLanguageTagCompat() method.
17+ // Use Locale.forLanguageTag() on Android API level >= 21 / Java instead.
1118 public static Locale forLanguageTag (final String str ) {
1219 if (str .contains ("-" )) {
13- String [] args = str .split ("-" , -1 );
20+ final String [] args = str .split ("-" , -1 );
1421 if (args .length > 2 ) {
1522 return new Locale (args [0 ], args [1 ], args [2 ]);
1623 } else if (args .length > 1 ) {
@@ -19,7 +26,7 @@ public static Locale forLanguageTag(final String str) {
1926 return new Locale (args [0 ]);
2027 }
2128 } else if (str .contains ("_" )) {
22- String [] args = str .split ("_" , -1 );
29+ final String [] args = str .split ("_" , -1 );
2330 if (args .length > 2 ) {
2431 return new Locale (args [0 ], args [1 ], args [2 ]);
2532 } else if (args .length > 1 ) {
0 commit comments