package i0;

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 android.util.Xml;
import androidx.annotation.ColorInt;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import java.io.IOException;
import java.util.ArrayList;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;

/* JADX INFO: loaded from: classes.dex */
public abstract class k {
    private static j checkColors(@Nullable j jVar, @ColorInt int i10, @ColorInt int i11, boolean z10, @ColorInt int i12) {
        return jVar != null ? jVar : z10 ? new j(i10, i12, i11) : new j(i10, i11);
    }

    public static Shader createFromXml(@NonNull Resources resources, @NonNull XmlPullParser xmlPullParser, @Nullable Resources.Theme theme) throws XmlPullParserException, IOException {
        int next;
        AttributeSet attributeSetAsAttributeSet = Xml.asAttributeSet(xmlPullParser);
        do {
            next = xmlPullParser.next();
            if (next == 2) {
                break;
            }
        } while (next != 1);
        if (next == 2) {
            return createFromXmlInner(resources, xmlPullParser, attributeSetAsAttributeSet, theme);
        }
        throw new XmlPullParserException("No start tag found");
    }

    public static Shader createFromXmlInner(@NonNull Resources resources, @NonNull XmlPullParser xmlPullParser, @NonNull AttributeSet attributeSet, @Nullable Resources.Theme theme) throws XmlPullParserException, IOException {
        String name = xmlPullParser.getName();
        if (!name.equals("gradient")) {
            throw new XmlPullParserException(xmlPullParser.getPositionDescription() + ": invalid gradient color tag " + name);
        }
        TypedArray typedArrayObtainAttributes = s.obtainAttributes(resources, theme, attributeSet, e0.h.GradientColor);
        float f10 = !s.c(xmlPullParser, "startX") ? 0.0f : typedArrayObtainAttributes.getFloat(e0.h.GradientColor_android_startX, 0.0f);
        float f11 = !s.c(xmlPullParser, "startY") ? 0.0f : typedArrayObtainAttributes.getFloat(e0.h.GradientColor_android_startY, 0.0f);
        float f12 = !s.c(xmlPullParser, "endX") ? 0.0f : typedArrayObtainAttributes.getFloat(e0.h.GradientColor_android_endX, 0.0f);
        float f13 = !s.c(xmlPullParser, "endY") ? 0.0f : typedArrayObtainAttributes.getFloat(e0.h.GradientColor_android_endY, 0.0f);
        float f14 = !s.c(xmlPullParser, "centerX") ? 0.0f : typedArrayObtainAttributes.getFloat(e0.h.GradientColor_android_centerX, 0.0f);
        float f15 = !s.c(xmlPullParser, "centerY") ? 0.0f : typedArrayObtainAttributes.getFloat(e0.h.GradientColor_android_centerY, 0.0f);
        int i10 = !s.c(xmlPullParser, "type") ? 0 : typedArrayObtainAttributes.getInt(e0.h.GradientColor_android_type, 0);
        int color = !s.c(xmlPullParser, "startColor") ? 0 : typedArrayObtainAttributes.getColor(e0.h.GradientColor_android_startColor, 0);
        boolean zC = s.c(xmlPullParser, "centerColor");
        int color2 = !s.c(xmlPullParser, "centerColor") ? 0 : typedArrayObtainAttributes.getColor(e0.h.GradientColor_android_centerColor, 0);
        int color3 = !s.c(xmlPullParser, "endColor") ? 0 : typedArrayObtainAttributes.getColor(e0.h.GradientColor_android_endColor, 0);
        int i11 = !s.c(xmlPullParser, "tileMode") ? 0 : typedArrayObtainAttributes.getInt(e0.h.GradientColor_android_tileMode, 0);
        float f16 = !s.c(xmlPullParser, "gradientRadius") ? 0.0f : typedArrayObtainAttributes.getFloat(e0.h.GradientColor_android_gradientRadius, 0.0f);
        typedArrayObtainAttributes.recycle();
        j jVarCheckColors = checkColors(inflateChildElements(resources, xmlPullParser, attributeSet, theme), color, color3, zC, color2);
        if (i10 != 1) {
            if (i10 != 2) {
                return new LinearGradient(f10, f11, f12, f13, jVarCheckColors.f26500a, jVarCheckColors.f26501b, i11 != 1 ? i11 != 2 ? Shader.TileMode.CLAMP : Shader.TileMode.MIRROR : Shader.TileMode.REPEAT);
            }
            return new SweepGradient(f14, f15, jVarCheckColors.f26500a, jVarCheckColors.f26501b);
        }
        if (f16 > 0.0f) {
            return new RadialGradient(f14, f15, f16, jVarCheckColors.f26500a, jVarCheckColors.f26501b, i11 != 1 ? i11 != 2 ? Shader.TileMode.CLAMP : Shader.TileMode.MIRROR : Shader.TileMode.REPEAT);
        }
        throw new XmlPullParserException("<gradient> tag requires 'gradientRadius' attribute with radial type");
    }

    /* JADX WARN: Code restructure failed: missing block: B:23:0x0085, code lost:
    
        if (r4.size() <= 0) goto L26;
     */
    /* JADX WARN: Code restructure failed: missing block: B:25:0x008c, code lost:
    
        return new i0.j(r4, r2);
     */
    /* JADX WARN: Code restructure failed: missing block: B:26:0x008d, code lost:
    
        return null;
     */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    private static j inflateChildElements(@NonNull Resources resources, @NonNull XmlPullParser xmlPullParser, @NonNull AttributeSet attributeSet, @Nullable Resources.Theme theme) throws XmlPullParserException, IOException {
        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;
            }
            if (next == 2 && depth <= depth2 && xmlPullParser.getName().equals("item")) {
                TypedArray typedArrayObtainAttributes = s.obtainAttributes(resources, theme, attributeSet, e0.h.GradientColorItem);
                int i10 = e0.h.GradientColorItem_android_color;
                boolean zHasValue = typedArrayObtainAttributes.hasValue(i10);
                int i11 = e0.h.GradientColorItem_android_offset;
                boolean zHasValue2 = typedArrayObtainAttributes.hasValue(i11);
                if (!zHasValue || !zHasValue2) {
                    break;
                }
                int color = typedArrayObtainAttributes.getColor(i10, 0);
                float f10 = typedArrayObtainAttributes.getFloat(i11, 0.0f);
                typedArrayObtainAttributes.recycle();
                arrayList2.add(Integer.valueOf(color));
                arrayList.add(Float.valueOf(f10));
            }
        }
        throw new XmlPullParserException(xmlPullParser.getPositionDescription() + ": <item> tag requires a 'color' attribute and a 'offset' attribute!");
    }
}
