package A1;

import C3.AbstractC0055q;
import C3.b0;
import T0.AbstractC0302b;
import T0.C0307g;
import T0.InterfaceC0308h;
import android.content.Context;
import android.content.res.ColorStateList;
import android.content.res.Resources;
import android.content.res.TypedArray;
import android.content.res.XmlResourceParser;
import android.graphics.LinearGradient;
import android.graphics.RadialGradient;
import android.graphics.Shader;
import android.graphics.SweepGradient;
import android.graphics.drawable.Drawable;
import android.util.AttributeSet;
import android.util.SparseArray;
import android.util.Xml;
import android.widget.ImageView;
import d3.R0;
import d5.AbstractC0844a;
import i2.C1050a;
import java.io.EOFException;
import java.io.IOException;
import java.io.InterruptedIOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import n.C1228p;
import n.S;
import n4.u0;
import org.xmlpull.v1.XmlPullParserException;
import p2.AbstractC1420j;
import p2.C1415e;
import p2.C1426p;
import r2.C1492a;

/* JADX INFO: loaded from: classes.dex */
public final class H implements InterfaceC0308h, t2.e {

    /* JADX INFO: renamed from: q, reason: collision with root package name */
    public final /* synthetic */ int f64q;

    /* JADX INFO: renamed from: r, reason: collision with root package name */
    public int f65r;

    /* JADX INFO: renamed from: s, reason: collision with root package name */
    public Object f66s;

    /* JADX INFO: renamed from: t, reason: collision with root package name */
    public Object f67t;

    public /* synthetic */ H() {
        this.f64q = 5;
    }

    /* JADX WARN: Code restructure failed: missing block: B:100:0x01df, code lost:
    
        throw new org.xmlpull.v1.XmlPullParserException(r3.getPositionDescription() + ": <item> tag requires a 'color' attribute and a 'offset' attribute!");
     */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public static H e(Resources resources, int i, Resources.Theme theme) throws XmlPullParserException, IOException {
        int next;
        float f3;
        int i5;
        float f7;
        float f8;
        Shader radialGradient;
        XmlResourceParser xml = resources.getXml(i);
        AttributeSet attributeSetAsAttributeSet = Xml.asAttributeSet(xml);
        do {
            next = xml.next();
            if (next == 2) {
                break;
            }
        } while (next != 1);
        if (next != 2) {
            throw new XmlPullParserException("No start tag found");
        }
        String name = xml.getName();
        name.getClass();
        if (!name.equals("gradient")) {
            if (name.equals("selector")) {
                ColorStateList colorStateListB = E.c.b(resources, xml, attributeSetAsAttributeSet, theme);
                return new H((Shader) null, colorStateListB, colorStateListB.getDefaultColor());
            }
            throw new XmlPullParserException(xml.getPositionDescription() + ": unsupported complex color tag " + name);
        }
        String name2 = xml.getName();
        if (!name2.equals("gradient")) {
            throw new XmlPullParserException(xml.getPositionDescription() + ": invalid gradient color tag " + name2);
        }
        TypedArray typedArrayG = E.b.g(resources, theme, attributeSetAsAttributeSet, A.a.f3d);
        float f9 = !(xml.getAttributeValue("http://schemas.android.com/apk/res/android", "startX") != null) ? 0.0f : typedArrayG.getFloat(8, 0.0f);
        float f10 = xml.getAttributeValue("http://schemas.android.com/apk/res/android", "startY") != null ? typedArrayG.getFloat(9, 0.0f) : 0.0f;
        float f11 = xml.getAttributeValue("http://schemas.android.com/apk/res/android", "endX") != null ? typedArrayG.getFloat(10, 0.0f) : 0.0f;
        float f12 = xml.getAttributeValue("http://schemas.android.com/apk/res/android", "endY") != null ? typedArrayG.getFloat(11, 0.0f) : 0.0f;
        float f13 = !(xml.getAttributeValue("http://schemas.android.com/apk/res/android", "centerX") != null) ? 0.0f : typedArrayG.getFloat(3, 0.0f);
        float f14 = xml.getAttributeValue("http://schemas.android.com/apk/res/android", "centerY") != null ? typedArrayG.getFloat(4, 0.0f) : 0.0f;
        int i8 = !(xml.getAttributeValue("http://schemas.android.com/apk/res/android", "type") != null) ? 0 : typedArrayG.getInt(2, 0);
        int color = xml.getAttributeValue("http://schemas.android.com/apk/res/android", "startColor") != null ? typedArrayG.getColor(0, 0) : 0;
        boolean z8 = xml.getAttributeValue("http://schemas.android.com/apk/res/android", "centerColor") != null;
        int color2 = xml.getAttributeValue("http://schemas.android.com/apk/res/android", "centerColor") != null ? typedArrayG.getColor(7, 0) : 0;
        int color3 = xml.getAttributeValue("http://schemas.android.com/apk/res/android", "endColor") != null ? typedArrayG.getColor(1, 0) : 0;
        if (xml.getAttributeValue("http://schemas.android.com/apk/res/android", "tileMode") != null) {
            f3 = f9;
            i5 = typedArrayG.getInt(6, 0);
        } else {
            f3 = f9;
            i5 = 0;
        }
        float f15 = xml.getAttributeValue("http://schemas.android.com/apk/res/android", "gradientRadius") != null ? typedArrayG.getFloat(5, 0.0f) : 0.0f;
        typedArrayG.recycle();
        int depth = xml.getDepth() + 1;
        ArrayList arrayList = new ArrayList(20);
        float f16 = f15;
        ArrayList arrayList2 = new ArrayList(20);
        while (true) {
            int next2 = xml.next();
            f7 = f10;
            if (next2 == 1) {
                f8 = f11;
                break;
            }
            int depth2 = xml.getDepth();
            f8 = f11;
            if (depth2 < depth && next2 == 3) {
                break;
            }
            if (next2 == 2 && depth2 <= depth && xml.getName().equals("item")) {
                TypedArray typedArrayG2 = E.b.g(resources, theme, attributeSetAsAttributeSet, A.a.f4e);
                boolean zHasValue = typedArrayG2.hasValue(0);
                boolean zHasValue2 = typedArrayG2.hasValue(1);
                if (!zHasValue || !zHasValue2) {
                    break;
                }
                int color4 = typedArrayG2.getColor(0, 0);
                float f17 = typedArrayG2.getFloat(1, 0.0f);
                typedArrayG2.recycle();
                arrayList2.add(Integer.valueOf(color4));
                arrayList.add(Float.valueOf(f17));
            }
            f10 = f7;
            f11 = f8;
        }
        R0 r02 = arrayList2.size() > 0 ? new R0(arrayList2, arrayList) : null;
        if (r02 == null) {
            r02 = z8 ? new R0(color, color2, color3) : new R0(color, color3);
        }
        if (i8 != 1) {
            if (i8 != 2) {
                radialGradient = new LinearGradient(f3, f7, f8, f12, (int[]) r02.f11692r, (float[]) r02.f11693s, i5 != 1 ? i5 != 2 ? Shader.TileMode.CLAMP : Shader.TileMode.MIRROR : Shader.TileMode.REPEAT);
            } else {
                radialGradient = new SweepGradient(f13, f14, (int[]) r02.f11692r, (float[]) r02.f11693s);
            }
        } else {
            if (f16 <= 0.0f) {
                throw new XmlPullParserException("<gradient> tag requires 'gradientRadius' attribute with radial type");
            }
            radialGradient = new RadialGradient(f13, f14, f16, (int[]) r02.f11692r, (float[]) r02.f11693s, i5 != 1 ? i5 != 2 ? Shader.TileMode.CLAMP : Shader.TileMode.MIRROR : Shader.TileMode.REPEAT);
        }
        return new H(radialGradient, (ColorStateList) null, 0);
    }

    private final /* synthetic */ void k() {
    }

    @Override // T0.InterfaceC0308h
    public void A() {
        switch (this.f64q) {
            case u0.f15495q /* 0 */:
                byte[] bArr = x0.v.f18555c;
                x0.o oVar = (x0.o) this.f67t;
                oVar.getClass();
                oVar.D(bArr.length, bArr);
                break;
        }
    }

    @Override // t2.e
    public void a() {
        C1492a c1492a = (C1492a) this.f66s;
        Drawable drawable = c1492a.f16434r.getDrawable();
        AbstractC1420j abstractC1420j = (AbstractC1420j) this.f67t;
        boolean z8 = abstractC1420j instanceof C1426p;
        C1050a c1050a = new C1050a(drawable, abstractC1420j.a(), abstractC1420j.b().f16087w, this.f65r, (z8 && ((C1426p) abstractC1420j).f16115g) ? false : true);
        if (z8) {
            c1492a.d(c1050a);
        } else {
            if (!(abstractC1420j instanceof C1415e)) {
                throw new A6.b();
            }
            c1492a.d(c1050a);
        }
    }

    public void b() {
        k7.i iVar;
        ImageView imageView = (ImageView) this.f66s;
        Drawable drawable = imageView.getDrawable();
        if (drawable != null) {
            S.a(drawable);
        }
        if (drawable == null || (iVar = (k7.i) this.f67t) == null) {
            return;
        }
        C1228p.d(drawable, iVar, imageView.getDrawableState());
    }

    public G4.b c() {
        if (!"".isEmpty()) {
            throw new IllegalStateException("Missing required properties:".concat(""));
        }
        return new G4.b(((Long) this.f67t).longValue(), (String) this.f66s, this.f65r);
    }

    public b0 d() {
        C3.H h8 = (C3.H) this.f67t;
        if (h8 != null) {
            throw h8.a();
        }
        b0 b0VarB = b0.b(this.f65r, (Object[]) this.f66s, this);
        C3.H h9 = (C3.H) this.f67t;
        if (h9 == null) {
            return b0VarB;
        }
        throw h9.a();
    }

    public long f(T0.j jVar) throws EOFException, InterruptedIOException {
        long j8;
        L4.h hVar;
        T0.r rVar;
        long j9;
        boolean zB;
        int iL;
        while (true) {
            long jI = jVar.i();
            j8 = jVar.f6427s;
            long j10 = j8 - 6;
            hVar = (L4.h) this.f67t;
            rVar = (T0.r) this.f66s;
            if (jI >= j10) {
                j9 = 6;
                break;
            }
            long jI2 = jVar.i();
            byte[] bArr = new byte[2];
            jVar.f(bArr, 0, 2, false);
            int i = ((bArr[0] & 255) << 8) | (bArr[1] & 255);
            int i5 = this.f65r;
            if (i != i5) {
                jVar.f6430v = 0;
                jVar.h((int) (jI2 - jVar.f6428t), false);
                j9 = 6;
                zB = false;
            } else {
                j9 = 6;
                x0.o oVar = new x0.o(16);
                System.arraycopy(bArr, 0, oVar.f18539a, 0, 2);
                byte[] bArr2 = oVar.f18539a;
                int i8 = 0;
                for (int i9 = 2; i8 < 14 && (iL = jVar.l(bArr2, i9 + i8, 14 - i8)) != -1; i9 = 2) {
                    i8 += iL;
                }
                oVar.E(i8);
                jVar.f6430v = 0;
                jVar.h((int) (jI2 - jVar.f6428t), false);
                zB = AbstractC0302b.b(oVar, rVar, i5, hVar);
            }
            if (zB) {
                break;
            }
            jVar.h(1, false);
        }
        if (jVar.i() < j8 - j9) {
            return hVar.f4006a;
        }
        jVar.h((int) (j8 - jVar.i()), false);
        return rVar.f6452j;
    }

    public Object g(int i) {
        SparseArray sparseArray;
        if (this.f65r == -1) {
            this.f65r = 0;
        }
        while (true) {
            int i5 = this.f65r;
            sparseArray = (SparseArray) this.f66s;
            if (i5 <= 0 || i >= sparseArray.keyAt(i5)) {
                break;
            }
            this.f65r--;
        }
        while (this.f65r < sparseArray.size() - 1 && i >= sparseArray.keyAt(this.f65r + 1)) {
            this.f65r++;
        }
        return sparseArray.valueAt(this.f65r);
    }

    public boolean h() {
        ColorStateList colorStateList;
        return ((Shader) this.f66s) == null && (colorStateList = (ColorStateList) this.f67t) != null && colorStateList.isStateful();
    }

    /* JADX WARN: Removed duplicated region for block: B:41:0x00ea  */
    /* JADX WARN: Removed duplicated region for block: B:42:0x00f3  */
    @Override // T0.InterfaceC0308h
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public C0307g i(T0.j jVar, long j8) throws EOFException, InterruptedIOException {
        C0307g c0307g;
        switch (this.f64q) {
            case u0.f15495q /* 0 */:
                long j9 = jVar.f6428t;
                int iMin = (int) Math.min(112800, jVar.f6427s - j9);
                x0.o oVar = (x0.o) this.f67t;
                oVar.C(iMin);
                jVar.f(oVar.f18539a, 0, iMin, false);
                int i = oVar.f18541c;
                long j10 = -1;
                long j11 = -1;
                long j12 = -9223372036854775807L;
                while (oVar.a() >= 188) {
                    byte[] bArr = oVar.f18539a;
                    int i5 = oVar.f18540b;
                    while (i5 < i && bArr[i5] != 71) {
                        i5++;
                    }
                    int i8 = i5 + 188;
                    if (i8 > i) {
                        if (j12 != -9223372036854775807L) {
                            return C0307g.f6415d;
                        }
                        c0307g = new C0307g(-2, j12, j9 + j10);
                        return c0307g;
                    }
                    long jE = W2.g.E(oVar, i5, this.f65r);
                    if (jE != -9223372036854775807L) {
                        long jB = ((x0.t) this.f66s).b(jE);
                        if (jB > j8) {
                            if (j12 == -9223372036854775807L) {
                                return new C0307g(-1, jB, j9);
                            }
                            c0307g = new C0307g(0, -9223372036854775807L, j9 + j11);
                            return c0307g;
                        }
                        j12 = jB;
                        if (100000 + j12 > j8) {
                            return new C0307g(0, -9223372036854775807L, j9 + ((long) i5));
                        }
                        j11 = i5;
                    }
                    oVar.F(i8);
                    j10 = i8;
                }
                if (j12 != -9223372036854775807L) {
                }
                break;
            default:
                long j13 = jVar.f6428t;
                long jF = f(jVar);
                long jI = jVar.i();
                jVar.h(Math.max(6, ((T0.r) this.f66s).f6446c), false);
                long jF2 = f(jVar);
                return (jF > j8 || jF2 <= j8) ? jF2 <= j8 ? new C0307g(-2, jF2, jVar.i()) : new C0307g(-1, jF, j13) : new C0307g(0, -9223372036854775807L, jI);
        }
    }

    public void j(AttributeSet attributeSet, int i) {
        int resourceId;
        ImageView imageView = (ImageView) this.f66s;
        Context context = imageView.getContext();
        int[] iArr = h.a.f13009e;
        com.google.android.material.datepicker.c cVarZ = com.google.android.material.datepicker.c.z(context, attributeSet, iArr, i);
        M.J.i(imageView, imageView.getContext(), iArr, attributeSet, (TypedArray) cVarZ.f10220s, i);
        try {
            Drawable drawable = imageView.getDrawable();
            TypedArray typedArray = (TypedArray) cVarZ.f10220s;
            if (drawable == null && (resourceId = typedArray.getResourceId(1, -1)) != -1 && (drawable = android.support.v4.media.session.a.l(imageView.getContext(), resourceId)) != null) {
                imageView.setImageDrawable(drawable);
            }
            if (drawable != null) {
                S.a(drawable);
            }
            if (typedArray.hasValue(2)) {
                imageView.setImageTintList(cVarZ.t(2));
            }
            if (typedArray.hasValue(3)) {
                imageView.setImageTintMode(S.b(typedArray.getInt(3, -1), null));
            }
            cVarZ.B();
        } catch (Throwable th) {
            cVarZ.B();
            throw th;
        }
    }

    public void l(Object obj, Object obj2) {
        int i = (this.f65r + 1) * 2;
        Object[] objArr = (Object[]) this.f66s;
        if (i > objArr.length) {
            this.f66s = Arrays.copyOf(objArr, C3.A.f(objArr.length, i));
        }
        AbstractC0055q.b(obj, obj2);
        Object[] objArr2 = (Object[]) this.f66s;
        int i5 = this.f65r;
        int i8 = i5 * 2;
        objArr2[i8] = obj;
        objArr2[i8 + 1] = obj2;
        this.f65r = i5 + 1;
    }

    public void m(Collection collection) {
        if (AbstractC0844a.w(collection)) {
            int size = (collection.size() + this.f65r) * 2;
            Object[] objArr = (Object[]) this.f66s;
            if (size > objArr.length) {
                this.f66s = Arrays.copyOf(objArr, C3.A.f(objArr.length, size));
            }
        }
        Iterator it = collection.iterator();
        while (it.hasNext()) {
            Map.Entry entry = (Map.Entry) it.next();
            l(entry.getKey(), entry.getValue());
        }
    }

    public List n(CharSequence charSequence) {
        charSequence.getClass();
        K4.c cVar = (K4.c) this.f67t;
        cVar.getClass();
        B3.k kVar = new B3.k(cVar, this, charSequence);
        ArrayList arrayList = new ArrayList();
        while (kVar.hasNext()) {
            arrayList.add((String) kVar.next());
        }
        return Collections.unmodifiableList(arrayList);
    }

    public String toString() {
        switch (this.f64q) {
            case 9:
                StringBuilder sb = new StringBuilder();
                if (((k7.x) this.f66s) == k7.x.f14194r) {
                    sb.append("HTTP/1.0");
                } else {
                    sb.append("HTTP/1.1");
                }
                sb.append(' ');
                sb.append(this.f65r);
                sb.append(' ');
                sb.append((String) this.f67t);
                String string = sb.toString();
                P6.g.d(string, "StringBuilder().apply(builderAction).toString()");
                return string;
            default:
                return super.toString();
        }
    }

    public /* synthetic */ H(Object obj, int i, String str, int i5) {
        this.f64q = i5;
        this.f66s = obj;
        this.f65r = i;
        this.f67t = str;
    }

    public H(C1492a c1492a, AbstractC1420j abstractC1420j, int i) {
        this.f64q = 10;
        this.f66s = c1492a;
        this.f67t = abstractC1420j;
        this.f65r = i;
        if (i <= 0) {
            throw new IllegalArgumentException("durationMillis must be > 0.");
        }
    }

    public H(ImageView imageView) {
        this.f64q = 8;
        this.f65r = 0;
        this.f66s = imageView;
    }

    public H(I3.y yVar) {
        this.f64q = 6;
        this.f66s = new SparseArray();
        this.f67t = yVar;
        this.f65r = -1;
    }

    public H(Shader shader, ColorStateList colorStateList, int i) {
        this.f64q = 4;
        this.f66s = shader;
        this.f67t = colorStateList;
        this.f65r = i;
    }

    public H(T0.r rVar, int i) {
        this.f64q = 7;
        this.f66s = rVar;
        this.f65r = i;
        this.f67t = new L4.h();
    }

    public H(int i, x0.t tVar) {
        this.f64q = 0;
        this.f65r = i;
        this.f66s = tVar;
        this.f67t = new x0.o();
    }

    public H(K4.c cVar) {
        this.f64q = 1;
        this.f67t = cVar;
        this.f66s = B3.d.f973q;
        this.f65r = Integer.MAX_VALUE;
    }

    public H(int i) {
        this.f64q = 3;
        this.f66s = new Object[i * 2];
        this.f65r = 0;
    }
}
