package ῲ.ῲ.ῲ.K;

import android.annotation.SuppressLint;
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 java.util.WeakHashMap;
import ῲ.ᨨ.ῲ.C1806;
import ῲ.ῲ.㴹.C2012;
import K.K.K.ʬ.C2369;

@SuppressLint({"RestrictedAPI"})
/* renamed from: ῲ.ῲ.ῲ.K.K  reason: contains not printable characters */
/* compiled from: AppCompatResources */
public final class C1940 {

    /* renamed from: ʬ  reason: contains not printable characters */
    public static final Object f6627 = new Object();

    /* renamed from: ῲ  reason: contains not printable characters */
    public static final WeakHashMap<Context, SparseArray<C1941>> f6628 = new WeakHashMap<>(0);

    /* renamed from: K  reason: contains not printable characters */
    public static final ThreadLocal<TypedValue> f6629 = new ThreadLocal<>();

    /* renamed from: ῲ.ῲ.ῲ.K.K$K  reason: contains not printable characters */
    /* compiled from: AppCompatResources */
    public static class C1941 {

        /* renamed from: ῲ  reason: contains not printable characters */
        public final Configuration f6630;

        /* renamed from: K  reason: contains not printable characters */
        public final ColorStateList f6631;

        public C1941(ColorStateList colorStateList, Configuration configuration) {
            this.f6631 = colorStateList;
            this.f6630 = configuration;
        }
    }

    /* renamed from: ʬ  reason: contains not printable characters */
    public static Drawable m5017(Context context, int i) {
        return C2012.m5203().m5206(context, i);
    }

    /* renamed from: ῲ  reason: contains not printable characters */
    public static ColorStateList m5018(Context context, int i) {
        if (Build.VERSION.SDK_INT >= 23) {
            return context.getColorStateList(i);
        }
        ColorStateList r0 = m5019(context, i);
        if (r0 != null) {
            return r0;
        }
        Resources resources = context.getResources();
        TypedValue typedValue = f6629.get();
        if (typedValue == null) {
            typedValue = new TypedValue();
            f6629.set(typedValue);
        }
        boolean z = true;
        resources.getValue(i, typedValue, true);
        int i2 = typedValue.type;
        if (i2 < 28 || i2 > 31) {
            z = false;
        }
        ColorStateList colorStateList = null;
        if (!z) {
            Resources resources2 = context.getResources();
            try {
                colorStateList = C2369.m6303(resources2, resources2.getXml(i), context.getTheme());
            } catch (Exception e) {
                Log.e("AppCompatResources", "Failed to inflate ColorStateList, leaving it to the framework", e);
            }
        }
        if (colorStateList == null) {
            return C1806.m4684(context, i);
        }
        m5020(context, i, colorStateList);
        return colorStateList;
    }

    /* renamed from: K  reason: contains not printable characters */
    public static ColorStateList m5019(Context context, int i) {
        C1941 k;
        synchronized (f6627) {
            SparseArray<C1941> sparseArray = f6628.get(context);
            if (!(sparseArray == null || sparseArray.size() <= 0 || (k = sparseArray.get(i)) == null)) {
                if (k.f6630.equals(context.getResources().getConfiguration())) {
                    return k.f6631;
                }
                sparseArray.remove(i);
            }
            return null;
        }
    }

    /* renamed from: K  reason: contains not printable characters */
    public static void m5020(Context context, int i, ColorStateList colorStateList) {
        synchronized (f6627) {
            SparseArray<C1941> sparseArray = f6628.get(context);
            if (sparseArray == null) {
                sparseArray = new SparseArray<>();
                f6628.put(context, sparseArray);
            }
            sparseArray.append(i, new C1941(colorStateList, context.getResources().getConfiguration()));
        }
    }
}
