jimu-decompiled/sources/androidx/appcompat/content/res/AppCompatResources.java
2025-05-13 19:24:51 +02:00

109 lines
3.7 KiB
Java

package androidx.appcompat.content.res;
import android.content.Context;
import android.content.res.ColorStateList;
import android.content.res.Configuration;
import android.content.res.Resources;
import android.graphics.drawable.Drawable;
import android.os.Build;
import android.util.Log;
import android.util.SparseArray;
import android.util.TypedValue;
import androidx.appcompat.widget.AppCompatDrawableManager;
import androidx.core.content.ContextCompat;
import androidx.core.content.res.ColorStateListInflaterCompat;
import java.util.WeakHashMap;
/* loaded from: classes.dex */
public final class AppCompatResources {
private static final ThreadLocal<TypedValue> a = new ThreadLocal<>();
private static final WeakHashMap<Context, SparseArray<ColorStateListCacheEntry>> b = new WeakHashMap<>(0);
private static final Object c = new Object();
private static class ColorStateListCacheEntry {
final ColorStateList a;
final Configuration b;
ColorStateListCacheEntry(ColorStateList colorStateList, Configuration configuration) {
this.a = colorStateList;
this.b = configuration;
}
}
private static ColorStateList a(Context context, int i) {
ColorStateListCacheEntry colorStateListCacheEntry;
synchronized (c) {
SparseArray<ColorStateListCacheEntry> sparseArray = b.get(context);
if (sparseArray != null && sparseArray.size() > 0 && (colorStateListCacheEntry = sparseArray.get(i)) != null) {
if (colorStateListCacheEntry.b.equals(context.getResources().getConfiguration())) {
return colorStateListCacheEntry.a;
}
sparseArray.remove(i);
}
return null;
}
}
public static ColorStateList b(Context context, int i) {
if (Build.VERSION.SDK_INT >= 23) {
return context.getColorStateList(i);
}
ColorStateList a2 = a(context, i);
if (a2 != null) {
return a2;
}
ColorStateList d = d(context, i);
if (d == null) {
return ContextCompat.b(context, i);
}
a(context, i, d);
return d;
}
public static Drawable c(Context context, int i) {
return AppCompatDrawableManager.a().a(context, i);
}
private static ColorStateList d(Context context, int i) {
if (e(context, i)) {
return null;
}
Resources resources = context.getResources();
try {
return ColorStateListInflaterCompat.a(resources, resources.getXml(i), context.getTheme());
} catch (Exception e) {
Log.e("AppCompatResources", "Failed to inflate ColorStateList, leaving it to the framework", e);
return null;
}
}
private static boolean e(Context context, int i) {
Resources resources = context.getResources();
TypedValue a2 = a();
resources.getValue(i, a2, true);
int i2 = a2.type;
return i2 >= 28 && i2 <= 31;
}
private static void a(Context context, int i, ColorStateList colorStateList) {
synchronized (c) {
SparseArray<ColorStateListCacheEntry> sparseArray = b.get(context);
if (sparseArray == null) {
sparseArray = new SparseArray<>();
b.put(context, sparseArray);
}
sparseArray.append(i, new ColorStateListCacheEntry(colorStateList, context.getResources().getConfiguration()));
}
}
private static TypedValue a() {
TypedValue typedValue = a.get();
if (typedValue != null) {
return typedValue;
}
TypedValue typedValue2 = new TypedValue();
a.set(typedValue2);
return typedValue2;
}
}