package androidx.core.content.res;

import android.content.res.Resources;
import android.content.res.TypedArray;
import android.os.Build;
import android.util.Base64;
import android.util.TypedValue;
import android.util.Xml;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;

/* JADX INFO: compiled from: FontResourcesParserCompat.java */
/* JADX INFO: loaded from: classes.dex */
public class e {

    /* JADX INFO: compiled from: FontResourcesParserCompat.java */
    static class a {
        static int a(TypedArray typedArray, int i3) {
            return typedArray.getType(i3);
        }
    }

    /* JADX INFO: compiled from: FontResourcesParserCompat.java */
    public interface b {
    }

    /* JADX INFO: compiled from: FontResourcesParserCompat.java */
    public static final class c implements b {

        /* JADX INFO: renamed from: a, reason: collision with root package name */
        private final d[] f1644a;

        public c(d[] dVarArr) {
            this.f1644a = dVarArr;
        }

        public d[] a() {
            return this.f1644a;
        }
    }

    /* JADX INFO: compiled from: FontResourcesParserCompat.java */
    public static final class d {

        /* JADX INFO: renamed from: a, reason: collision with root package name */
        private final String f1645a;

        /* JADX INFO: renamed from: b, reason: collision with root package name */
        private final int f1646b;

        /* JADX INFO: renamed from: c, reason: collision with root package name */
        private final boolean f1647c;

        /* JADX INFO: renamed from: d, reason: collision with root package name */
        private final String f1648d;

        /* JADX INFO: renamed from: e, reason: collision with root package name */
        private final int f1649e;

        /* JADX INFO: renamed from: f, reason: collision with root package name */
        private final int f1650f;

        public d(String str, int i3, boolean z2, String str2, int i4, int i5) {
            this.f1645a = str;
            this.f1646b = i3;
            this.f1647c = z2;
            this.f1648d = str2;
            this.f1649e = i4;
            this.f1650f = i5;
        }

        public String a() {
            return this.f1645a;
        }

        public int b() {
            return this.f1650f;
        }

        public int c() {
            return this.f1649e;
        }

        public String d() {
            return this.f1648d;
        }

        public int e() {
            return this.f1646b;
        }

        public boolean f() {
            return this.f1647c;
        }
    }

    /* JADX INFO: renamed from: androidx.core.content.res.e$e, reason: collision with other inner class name */
    /* JADX INFO: compiled from: FontResourcesParserCompat.java */
    public static final class C0012e implements b {

        /* JADX INFO: renamed from: a, reason: collision with root package name */
        private final androidx.core.provider.e f1651a;

        /* JADX INFO: renamed from: b, reason: collision with root package name */
        private final int f1652b;

        /* JADX INFO: renamed from: c, reason: collision with root package name */
        private final int f1653c;

        /* JADX INFO: renamed from: d, reason: collision with root package name */
        private final String f1654d;

        public C0012e(androidx.core.provider.e eVar, int i3, int i4, String str) {
            this.f1651a = eVar;
            this.f1653c = i3;
            this.f1652b = i4;
            this.f1654d = str;
        }

        public int a() {
            return this.f1653c;
        }

        public androidx.core.provider.e b() {
            return this.f1651a;
        }

        public String c() {
            return this.f1654d;
        }

        public int d() {
            return this.f1652b;
        }
    }

    private static int a(TypedArray typedArray, int i3) {
        if (Build.VERSION.SDK_INT >= 21) {
            return a.a(typedArray, i3);
        }
        TypedValue typedValue = new TypedValue();
        typedArray.getValue(i3, typedValue);
        return typedValue.type;
    }

    public static b b(XmlPullParser xmlPullParser, Resources resources) throws XmlPullParserException, IOException {
        int next;
        do {
            next = xmlPullParser.next();
            if (next == 2) {
                break;
            }
        } while (next != 1);
        if (next == 2) {
            return d(xmlPullParser, resources);
        }
        throw new XmlPullParserException("No start tag found");
    }

    public static List<List<byte[]>> c(Resources resources, int i3) {
        if (i3 == 0) {
            return Collections.emptyList();
        }
        TypedArray typedArrayObtainTypedArray = resources.obtainTypedArray(i3);
        try {
            if (typedArrayObtainTypedArray.length() == 0) {
                return Collections.emptyList();
            }
            ArrayList arrayList = new ArrayList();
            if (a(typedArrayObtainTypedArray, 0) == 1) {
                for (int i4 = 0; i4 < typedArrayObtainTypedArray.length(); i4++) {
                    int resourceId = typedArrayObtainTypedArray.getResourceId(i4, 0);
                    if (resourceId != 0) {
                        arrayList.add(h(resources.getStringArray(resourceId)));
                    }
                }
            } else {
                arrayList.add(h(resources.getStringArray(i3)));
            }
            return arrayList;
        } finally {
            typedArrayObtainTypedArray.recycle();
        }
    }

    private static b d(XmlPullParser xmlPullParser, Resources resources) throws XmlPullParserException, IOException {
        xmlPullParser.require(2, null, "font-family");
        if (xmlPullParser.getName().equals("font-family")) {
            return e(xmlPullParser, resources);
        }
        g(xmlPullParser);
        return null;
    }

    private static b e(XmlPullParser xmlPullParser, Resources resources) throws XmlPullParserException, IOException {
        TypedArray typedArrayObtainAttributes = resources.obtainAttributes(Xml.asAttributeSet(xmlPullParser), r.c.f5822g);
        String string = typedArrayObtainAttributes.getString(r.c.f5823h);
        String string2 = typedArrayObtainAttributes.getString(r.c.f5827l);
        String string3 = typedArrayObtainAttributes.getString(r.c.f5828m);
        int resourceId = typedArrayObtainAttributes.getResourceId(r.c.f5824i, 0);
        int integer = typedArrayObtainAttributes.getInteger(r.c.f5825j, 1);
        int integer2 = typedArrayObtainAttributes.getInteger(r.c.f5826k, 500);
        String string4 = typedArrayObtainAttributes.getString(r.c.f5829n);
        typedArrayObtainAttributes.recycle();
        if (string != null && string2 != null && string3 != null) {
            while (xmlPullParser.next() != 3) {
                g(xmlPullParser);
            }
            return new C0012e(new androidx.core.provider.e(string, string2, string3, c(resources, resourceId)), integer, integer2, string4);
        }
        ArrayList arrayList = new ArrayList();
        while (xmlPullParser.next() != 3) {
            if (xmlPullParser.getEventType() == 2) {
                if (xmlPullParser.getName().equals("font")) {
                    arrayList.add(f(xmlPullParser, resources));
                } else {
                    g(xmlPullParser);
                }
            }
        }
        if (arrayList.isEmpty()) {
            return null;
        }
        return new c((d[]) arrayList.toArray(new d[0]));
    }

    private static d f(XmlPullParser xmlPullParser, Resources resources) throws XmlPullParserException, IOException {
        TypedArray typedArrayObtainAttributes = resources.obtainAttributes(Xml.asAttributeSet(xmlPullParser), r.c.f5830o);
        int i3 = r.c.f5839x;
        if (!typedArrayObtainAttributes.hasValue(i3)) {
            i3 = r.c.f5832q;
        }
        int i4 = typedArrayObtainAttributes.getInt(i3, 400);
        int i5 = r.c.f5837v;
        if (!typedArrayObtainAttributes.hasValue(i5)) {
            i5 = r.c.f5833r;
        }
        boolean z2 = 1 == typedArrayObtainAttributes.getInt(i5, 0);
        int i6 = r.c.f5840y;
        if (!typedArrayObtainAttributes.hasValue(i6)) {
            i6 = r.c.f5834s;
        }
        int i7 = r.c.f5838w;
        if (!typedArrayObtainAttributes.hasValue(i7)) {
            i7 = r.c.f5835t;
        }
        String string = typedArrayObtainAttributes.getString(i7);
        int i8 = typedArrayObtainAttributes.getInt(i6, 0);
        int i9 = r.c.f5836u;
        if (!typedArrayObtainAttributes.hasValue(i9)) {
            i9 = r.c.f5831p;
        }
        int resourceId = typedArrayObtainAttributes.getResourceId(i9, 0);
        String string2 = typedArrayObtainAttributes.getString(i9);
        typedArrayObtainAttributes.recycle();
        while (xmlPullParser.next() != 3) {
            g(xmlPullParser);
        }
        return new d(string2, i4, z2, string, i8, resourceId);
    }

    private static void g(XmlPullParser xmlPullParser) throws XmlPullParserException, IOException {
        int i3 = 1;
        while (i3 > 0) {
            int next = xmlPullParser.next();
            if (next == 2) {
                i3++;
            } else if (next == 3) {
                i3--;
            }
        }
    }

    private static List<byte[]> h(String[] strArr) {
        ArrayList arrayList = new ArrayList();
        for (String str : strArr) {
            arrayList.add(Base64.decode(str, 0));
        }
        return arrayList;
    }
}
