package com.google.android.material.resources;

import android.content.Context;
import android.content.res.ColorStateList;
import android.content.res.TypedArray;
import android.graphics.drawable.Drawable;
import android.util.TypedValue;
import com.google.android.material.R;
import defpackage.aa9;
import defpackage.fp9;
import defpackage.gp;
import defpackage.m38;
import defpackage.rq6;
import defpackage.sf1;
import defpackage.vo6;
import defpackage.y99;

/* JADX INFO: loaded from: classes2.dex */
@m38
public class MaterialResources {
    private static final float FONT_SCALE_1_3 = 1.3f;
    private static final float FONT_SCALE_2_0 = 2.0f;

    private MaterialResources() {
    }

    @rq6
    public static ColorStateList getColorStateList(@vo6 Context context, @vo6 TypedArray typedArray, @aa9 int i) {
        int resourceId;
        ColorStateList colorStateList;
        return (!typedArray.hasValue(i) || (resourceId = typedArray.getResourceId(i, 0)) == 0 || (colorStateList = sf1.getColorStateList(context, resourceId)) == null) ? typedArray.getColorStateList(i) : colorStateList;
    }

    private static int getComplexUnit(TypedValue typedValue) {
        return typedValue.getComplexUnit();
    }

    public static int getDimensionPixelSize(@vo6 Context context, @vo6 TypedArray typedArray, @aa9 int i, int i2) {
        TypedValue typedValue = new TypedValue();
        if (!typedArray.getValue(i, typedValue) || typedValue.type != 2) {
            return typedArray.getDimensionPixelSize(i, i2);
        }
        TypedArray typedArrayObtainStyledAttributes = context.getTheme().obtainStyledAttributes(new int[]{typedValue.data});
        int dimensionPixelSize = typedArrayObtainStyledAttributes.getDimensionPixelSize(0, i2);
        typedArrayObtainStyledAttributes.recycle();
        return dimensionPixelSize;
    }

    @rq6
    public static Drawable getDrawable(@vo6 Context context, @vo6 TypedArray typedArray, @aa9 int i) {
        int resourceId;
        Drawable drawableA;
        return (!typedArray.hasValue(i) || (resourceId = typedArray.getResourceId(i, 0)) == 0 || (drawableA = gp.a(context, resourceId)) == null) ? typedArray.getDrawable(i) : drawableA;
    }

    public static float getFontScale(@vo6 Context context) {
        return context.getResources().getConfiguration().fontScale;
    }

    @aa9
    public static int getIndexWithValue(@vo6 TypedArray typedArray, @aa9 int i, @aa9 int i2) {
        return typedArray.hasValue(i) ? i : i2;
    }

    @rq6
    public static TextAppearance getTextAppearance(@vo6 Context context, @vo6 TypedArray typedArray, @aa9 int i) {
        int resourceId;
        if (!typedArray.hasValue(i) || (resourceId = typedArray.getResourceId(i, 0)) == 0) {
            return null;
        }
        return new TextAppearance(context, resourceId);
    }

    public static int getUnscaledTextSize(@vo6 Context context, @y99 int i, int i2) {
        if (i != 0) {
            TypedArray typedArrayObtainStyledAttributes = context.obtainStyledAttributes(i, R.styleable.TextAppearance);
            TypedValue typedValue = new TypedValue();
            boolean value = typedArrayObtainStyledAttributes.getValue(R.styleable.TextAppearance_android_textSize, typedValue);
            typedArrayObtainStyledAttributes.recycle();
            if (value) {
                return getComplexUnit(typedValue) == 2 ? Math.round(TypedValue.complexToFloat(typedValue.data) * context.getResources().getDisplayMetrics().density) : TypedValue.complexToDimensionPixelSize(typedValue.data, context.getResources().getDisplayMetrics());
            }
        }
        return i2;
    }

    public static boolean isFontScaleAtLeast1_3(@vo6 Context context) {
        return context.getResources().getConfiguration().fontScale >= FONT_SCALE_1_3;
    }

    public static boolean isFontScaleAtLeast2_0(@vo6 Context context) {
        return context.getResources().getConfiguration().fontScale >= 2.0f;
    }

    @rq6
    public static ColorStateList getColorStateList(@vo6 Context context, @vo6 fp9 fp9Var, @aa9 int i) {
        int resourceId;
        ColorStateList colorStateList;
        return (!fp9Var.b.hasValue(i) || (resourceId = fp9Var.b.getResourceId(i, 0)) == 0 || (colorStateList = sf1.getColorStateList(context, resourceId)) == null) ? fp9Var.a(i) : colorStateList;
    }
}
