package p071y;

import android.content.res.Resources;
import android.content.res.TypedArray;
import android.graphics.LinearGradient;
import android.graphics.RadialGradient;
import android.graphics.Shader;
import android.graphics.SweepGradient;
import android.util.AttributeSet;
import java.util.ArrayList;
import java.util.List;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
import p064v.C1752c;

/* renamed from: y.g */
/* loaded from: classes.dex */
public final class C1818g {

    /* renamed from: y.g$a */
    /* loaded from: classes.dex */
    public static final class C1819a {

        /* renamed from: a */
        public final int[] f4551a;

        /* renamed from: b */
        public final float[] f4552b;

        public C1819a(int i, int i2) {
            this.f4551a = new int[]{i, i2};
            this.f4552b = new float[]{0.0f, 1.0f};
        }

        public C1819a(int i, int i2, int i3) {
            this.f4551a = new int[]{i, i2, i3};
            this.f4552b = new float[]{0.0f, 0.5f, 1.0f};
        }

        public C1819a(List<Integer> list, List<Float> list2) {
            int size = list.size();
            this.f4551a = new int[size];
            this.f4552b = new float[size];
            for (int i = 0; i < size; i++) {
                this.f4551a[i] = list.get(i).intValue();
                this.f4552b[i] = list2.get(i).floatValue();
            }
        }
    }

    /* renamed from: a */
    public static C1819a m298a(C1819a c1819a, int i, int i2, boolean z, int i3) {
        return c1819a != null ? c1819a : z ? new C1819a(i, i3, i2) : new C1819a(i, i2);
    }

    /* renamed from: b */
    public static Shader m297b(Resources resources, XmlPullParser xmlPullParser, AttributeSet attributeSet, Resources.Theme theme) {
        String name = xmlPullParser.getName();
        if (!name.equals("gradient")) {
            throw new XmlPullParserException(xmlPullParser.getPositionDescription() + ": invalid gradient color tag " + name);
        }
        TypedArray m248k = C1838q.m248k(resources, theme, attributeSet, C1752c.f4427A);
        float m253f = C1838q.m253f(m248k, xmlPullParser, "startX", C1752c.f4436J, 0.0f);
        float m253f2 = C1838q.m253f(m248k, xmlPullParser, "startY", C1752c.f4437K, 0.0f);
        float m253f3 = C1838q.m253f(m248k, xmlPullParser, "endX", C1752c.f4438L, 0.0f);
        float m253f4 = C1838q.m253f(m248k, xmlPullParser, "endY", C1752c.f4439M, 0.0f);
        float m253f5 = C1838q.m253f(m248k, xmlPullParser, "centerX", C1752c.f4431E, 0.0f);
        float m253f6 = C1838q.m253f(m248k, xmlPullParser, "centerY", C1752c.f4432F, 0.0f);
        int m252g = C1838q.m252g(m248k, xmlPullParser, "type", C1752c.f4430D, 0);
        int m257b = C1838q.m257b(m248k, xmlPullParser, "startColor", C1752c.f4428B, 0);
        boolean m249j = C1838q.m249j(xmlPullParser, "centerColor");
        int m257b2 = C1838q.m257b(m248k, xmlPullParser, "centerColor", C1752c.f4435I, 0);
        int m257b3 = C1838q.m257b(m248k, xmlPullParser, "endColor", C1752c.f4429C, 0);
        int m252g2 = C1838q.m252g(m248k, xmlPullParser, "tileMode", C1752c.f4434H, 0);
        float m253f7 = C1838q.m253f(m248k, xmlPullParser, "gradientRadius", C1752c.f4433G, 0.0f);
        m248k.recycle();
        C1819a m298a = m298a(m296c(resources, xmlPullParser, attributeSet, theme), m257b, m257b3, m249j, m257b2);
        if (m252g != 1) {
            return m252g != 2 ? new LinearGradient(m253f, m253f2, m253f3, m253f4, m298a.f4551a, m298a.f4552b, m295d(m252g2)) : new SweepGradient(m253f5, m253f6, m298a.f4551a, m298a.f4552b);
        } else if (m253f7 > 0.0f) {
            return new RadialGradient(m253f5, m253f6, m253f7, m298a.f4551a, m298a.f4552b, m295d(m252g2));
        } else {
            throw new XmlPullParserException("<gradient> tag requires 'gradientRadius' attribute with radial type");
        }
    }

    /* JADX WARN: Code restructure failed: missing block: B:21:0x0080, code lost:
        throw new org.xmlpull.v1.XmlPullParserException(r10.getPositionDescription() + ": <item> tag requires a 'color' attribute and a 'offset' attribute!");
     */
    /* renamed from: c */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public static C1819a m296c(Resources resources, XmlPullParser xmlPullParser, AttributeSet attributeSet, Resources.Theme theme) {
        int depth;
        int depth2 = xmlPullParser.getDepth() + 1;
        ArrayList arrayList = new ArrayList(20);
        ArrayList arrayList2 = new ArrayList(20);
        while (true) {
            int next = xmlPullParser.next();
            if (next == 1 || ((depth = xmlPullParser.getDepth()) < depth2 && next == 3)) {
                break;
            } else if (next == 2 && depth <= depth2 && xmlPullParser.getName().equals("item")) {
                TypedArray m248k = C1838q.m248k(resources, theme, attributeSet, C1752c.f4440N);
                int i = C1752c.f4441O;
                boolean hasValue = m248k.hasValue(i);
                int i2 = C1752c.f4442P;
                boolean hasValue2 = m248k.hasValue(i2);
                if (!hasValue || !hasValue2) {
                    break;
                }
                int color = m248k.getColor(i, 0);
                float f = m248k.getFloat(i2, 0.0f);
                m248k.recycle();
                arrayList2.add(Integer.valueOf(color));
                arrayList.add(Float.valueOf(f));
            }
        }
        if (arrayList2.size() > 0) {
            return new C1819a(arrayList2, arrayList);
        }
        return null;
    }

    /* renamed from: d */
    public static Shader.TileMode m295d(int i) {
        return i != 1 ? i != 2 ? Shader.TileMode.CLAMP : Shader.TileMode.MIRROR : Shader.TileMode.REPEAT;
    }
}