discord-jadx/app/src/main/java/androidx/core/content/res/ResourcesCompat.java

283 lines
12 KiB
Java

package androidx.core.content.res;
import android.content.Context;
import android.content.res.ColorStateList;
import android.content.res.Resources;
import android.graphics.Typeface;
import android.graphics.drawable.Drawable;
import android.os.Build;
import android.os.Handler;
import android.os.Looper;
import android.util.Log;
import android.util.TypedValue;
import androidx.annotation.AnyRes;
import androidx.annotation.ColorInt;
import androidx.annotation.ColorRes;
import androidx.annotation.DimenRes;
import androidx.annotation.DrawableRes;
import androidx.annotation.FontRes;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.RequiresApi;
import androidx.annotation.RestrictTo;
import androidx.core.content.res.FontResourcesParserCompat;
import androidx.core.graphics.TypefaceCompat;
import androidx.core.util.Preconditions;
import c.d.b.a.a;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import org.xmlpull.v1.XmlPullParserException;
public final class ResourcesCompat {
@AnyRes
public static final int ID_NULL = 0;
private static final String TAG = "ResourcesCompat";
public static abstract class FontCallback {
/* renamed from: androidx.core.content.res.ResourcesCompat$FontCallback$1 reason: invalid class name */
public class AnonymousClass1 implements Runnable {
public final /* synthetic */ Typeface val$typeface;
public AnonymousClass1(Typeface typeface) {
this.val$typeface = typeface;
}
@Override // java.lang.Runnable
public void run() {
FontCallback.this.onFontRetrieved(this.val$typeface);
}
}
/* renamed from: androidx.core.content.res.ResourcesCompat$FontCallback$2 reason: invalid class name */
public class AnonymousClass2 implements Runnable {
public final /* synthetic */ int val$reason;
public AnonymousClass2(int i) {
this.val$reason = i;
}
@Override // java.lang.Runnable
public void run() {
FontCallback.this.onFontRetrievalFailed(this.val$reason);
}
}
@RestrictTo({RestrictTo.Scope.LIBRARY_GROUP_PREFIX})
public final void callbackFailAsync(int i, @Nullable Handler handler) {
if (handler == null) {
handler = new Handler(Looper.getMainLooper());
}
handler.post(new AnonymousClass2(i));
}
@RestrictTo({RestrictTo.Scope.LIBRARY_GROUP_PREFIX})
public final void callbackSuccessAsync(Typeface typeface, @Nullable Handler handler) {
if (handler == null) {
handler = new Handler(Looper.getMainLooper());
}
handler.post(new AnonymousClass1(typeface));
}
public abstract void onFontRetrievalFailed(int i);
public abstract void onFontRetrieved(@NonNull Typeface typeface);
}
public static final class ThemeCompat {
@RequiresApi(23)
public static class ImplApi23 {
private static Method sRebaseMethod;
private static boolean sRebaseMethodFetched;
private static final Object sRebaseMethodLock = new Object();
private ImplApi23() {
}
public static void rebase(@NonNull Resources.Theme theme) {
synchronized (sRebaseMethodLock) {
if (!sRebaseMethodFetched) {
try {
Method declaredMethod = Resources.Theme.class.getDeclaredMethod("rebase", new Class[0]);
sRebaseMethod = declaredMethod;
declaredMethod.setAccessible(true);
} catch (NoSuchMethodException e) {
Log.i(ResourcesCompat.TAG, "Failed to retrieve rebase() method", e);
}
sRebaseMethodFetched = true;
}
Method method = sRebaseMethod;
if (method != null) {
try {
method.invoke(theme, new Object[0]);
} catch (IllegalAccessException | InvocationTargetException e2) {
Log.i(ResourcesCompat.TAG, "Failed to invoke rebase() method via reflection", e2);
sRebaseMethod = null;
}
}
}
}
}
@RequiresApi(29)
public static class ImplApi29 {
private ImplApi29() {
}
public static void rebase(@NonNull Resources.Theme theme) {
theme.rebase();
}
}
private ThemeCompat() {
}
public static void rebase(@NonNull Resources.Theme theme) {
int i = Build.VERSION.SDK_INT;
if (i >= 29) {
ImplApi29.rebase(theme);
} else if (i >= 23) {
ImplApi23.rebase(theme);
}
}
}
private ResourcesCompat() {
}
@ColorInt
public static int getColor(@NonNull Resources resources, @ColorRes int i, @Nullable Resources.Theme theme) throws Resources.NotFoundException {
return Build.VERSION.SDK_INT >= 23 ? resources.getColor(i, theme) : resources.getColor(i);
}
@Nullable
public static ColorStateList getColorStateList(@NonNull Resources resources, @ColorRes int i, @Nullable Resources.Theme theme) throws Resources.NotFoundException {
return Build.VERSION.SDK_INT >= 23 ? resources.getColorStateList(i, theme) : resources.getColorStateList(i);
}
@Nullable
public static Drawable getDrawable(@NonNull Resources resources, @DrawableRes int i, @Nullable Resources.Theme theme) throws Resources.NotFoundException {
return resources.getDrawable(i, theme);
}
@Nullable
public static Drawable getDrawableForDensity(@NonNull Resources resources, @DrawableRes int i, int i2, @Nullable Resources.Theme theme) throws Resources.NotFoundException {
return resources.getDrawableForDensity(i, i2, theme);
}
public static float getFloat(@NonNull Resources resources, @DimenRes int i) {
TypedValue typedValue = new TypedValue();
resources.getValue(i, typedValue, true);
if (typedValue.type == 4) {
return typedValue.getFloat();
}
StringBuilder L = a.L("Resource ID #0x");
L.append(Integer.toHexString(i));
L.append(" type #0x");
L.append(Integer.toHexString(typedValue.type));
L.append(" is not valid");
throw new Resources.NotFoundException(L.toString());
}
@Nullable
public static Typeface getFont(@NonNull Context context, @FontRes int i) throws Resources.NotFoundException {
if (context.isRestricted()) {
return null;
}
return loadFont(context, i, new TypedValue(), 0, null, null, false);
}
@RestrictTo({RestrictTo.Scope.LIBRARY_GROUP_PREFIX})
public static Typeface getFont(@NonNull Context context, @FontRes int i, TypedValue typedValue, int i2, @Nullable FontCallback fontCallback) throws Resources.NotFoundException {
if (context.isRestricted()) {
return null;
}
return loadFont(context, i, typedValue, i2, fontCallback, null, true);
}
public static void getFont(@NonNull Context context, @FontRes int i, @NonNull FontCallback fontCallback, @Nullable Handler handler) throws Resources.NotFoundException {
Preconditions.checkNotNull(fontCallback);
if (context.isRestricted()) {
fontCallback.callbackFailAsync(-4, handler);
} else {
loadFont(context, i, new TypedValue(), 0, fontCallback, handler, false);
}
}
private static Typeface loadFont(@NonNull Context context, int i, TypedValue typedValue, int i2, @Nullable FontCallback fontCallback, @Nullable Handler handler, boolean z2) {
Resources resources = context.getResources();
resources.getValue(i, typedValue, true);
Typeface loadFont = loadFont(context, resources, typedValue, i, i2, fontCallback, handler, z2);
if (loadFont != null || fontCallback != null) {
return loadFont;
}
StringBuilder L = a.L("Font resource ID #0x");
L.append(Integer.toHexString(i));
L.append(" could not be retrieved.");
throw new Resources.NotFoundException(L.toString());
}
/* JADX WARNING: Removed duplicated region for block: B:34:0x00a4 */
private static Typeface loadFont(@NonNull Context context, Resources resources, TypedValue typedValue, int i, int i2, @Nullable FontCallback fontCallback, @Nullable Handler handler, boolean z2) {
CharSequence charSequence = typedValue.string;
if (charSequence != null) {
String charSequence2 = charSequence.toString();
if (!charSequence2.startsWith("res/")) {
if (fontCallback != null) {
fontCallback.callbackFailAsync(-3, handler);
}
return null;
}
Typeface findFromCache = TypefaceCompat.findFromCache(resources, i, i2);
if (findFromCache != null) {
if (fontCallback != null) {
fontCallback.callbackSuccessAsync(findFromCache, handler);
}
return findFromCache;
}
try {
if (charSequence2.toLowerCase().endsWith(".xml")) {
FontResourcesParserCompat.FamilyResourceEntry parse = FontResourcesParserCompat.parse(resources.getXml(i), resources);
if (parse != null) {
return TypefaceCompat.createFromResourcesFamilyXml(context, parse, resources, i, i2, fontCallback, handler, z2);
}
Log.e(TAG, "Failed to find font-family tag");
if (fontCallback != null) {
fontCallback.callbackFailAsync(-3, handler);
}
return null;
}
Typeface createFromResourcesFontFile = TypefaceCompat.createFromResourcesFontFile(context, resources, i, charSequence2, i2);
if (fontCallback != null) {
if (createFromResourcesFontFile != null) {
fontCallback.callbackSuccessAsync(createFromResourcesFontFile, handler);
} else {
fontCallback.callbackFailAsync(-3, handler);
}
}
return createFromResourcesFontFile;
} catch (XmlPullParserException e) {
Log.e(TAG, "Failed to parse xml resource " + charSequence2, e);
if (fontCallback != null) {
fontCallback.callbackFailAsync(-3, handler);
}
return null;
} catch (IOException e2) {
Log.e(TAG, "Failed to read xml resource " + charSequence2, e2);
if (fontCallback != null) {
}
return null;
}
} else {
StringBuilder L = a.L("Resource \"");
L.append(resources.getResourceName(i));
L.append("\" (");
L.append(Integer.toHexString(i));
L.append(") is not a Font: ");
L.append(typedValue);
throw new Resources.NotFoundException(L.toString());
}
}
}