jimu-decompiled/sources/androidx/core/text/ICUCompat.java
2025-05-13 19:24:51 +02:00

82 lines
2.3 KiB
Java

package androidx.core.text;
import android.os.Build;
import android.util.Log;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.Locale;
/* loaded from: classes.dex */
public final class ICUCompat {
private static Method a;
private static Method b;
static {
if (Build.VERSION.SDK_INT >= 21) {
try {
b = Class.forName("libcore.icu.ICU").getMethod("addLikelySubtags", Locale.class);
return;
} catch (Exception e) {
throw new IllegalStateException(e);
}
}
try {
Class<?> cls = Class.forName("libcore.icu.ICU");
if (cls != null) {
a = cls.getMethod("getScript", String.class);
b = cls.getMethod("addLikelySubtags", String.class);
}
} catch (Exception e2) {
a = null;
b = null;
Log.w("ICUCompat", e2);
}
}
private static String a(String str) {
try {
if (a != null) {
return (String) a.invoke(null, str);
}
} catch (IllegalAccessException e) {
Log.w("ICUCompat", e);
} catch (InvocationTargetException e2) {
Log.w("ICUCompat", e2);
}
return null;
}
public static String b(Locale locale) {
if (Build.VERSION.SDK_INT < 21) {
String a2 = a(locale);
if (a2 != null) {
return a(a2);
}
return null;
}
try {
return ((Locale) b.invoke(null, locale)).getScript();
} catch (IllegalAccessException e) {
Log.w("ICUCompat", e);
return locale.getScript();
} catch (InvocationTargetException e2) {
Log.w("ICUCompat", e2);
return locale.getScript();
}
}
private static String a(Locale locale) {
String locale2 = locale.toString();
try {
if (b != null) {
return (String) b.invoke(null, locale2);
}
} catch (IllegalAccessException e) {
Log.w("ICUCompat", e);
} catch (InvocationTargetException e2) {
Log.w("ICUCompat", e2);
}
return locale2;
}
}