package ῲ.ᨨ.ῲ.ῲ;

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.util.AttributeSet;
import android.util.Xml;
import androidx.core.R$styleable;
import java.io.IOException;
import java.util.ArrayList;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
import K.K.K.ʬ.C2369;

/* renamed from: ῲ.ᨨ.ῲ.ῲ.K  reason: contains not printable characters */
/* compiled from: ComplexColorCompat */
public final class C1802 {

    /* renamed from: ʬ  reason: contains not printable characters */
    public int f6154;

    /* renamed from: ῲ  reason: contains not printable characters */
    public final ColorStateList f6155;

    /* renamed from: K  reason: contains not printable characters */
    public final Shader f6156;

    public C1802(Shader shader, ColorStateList colorStateList, int i) {
        this.f6156 = shader;
        this.f6155 = colorStateList;
        this.f6154 = i;
    }

    /* renamed from: ʬ  reason: contains not printable characters */
    public boolean m4677() {
        ColorStateList colorStateList;
        return this.f6156 == null && (colorStateList = this.f6155) != null && colorStateList.isStateful();
    }

    /* renamed from: ῲ  reason: contains not printable characters */
    public boolean m4678() {
        return this.f6156 != null;
    }

    /* renamed from: K  reason: contains not printable characters */
    public Shader m4679() {
        return this.f6156;
    }

    /* renamed from: 㸾  reason: contains not printable characters */
    public boolean m4681() {
        return m4678() || this.f6154 != 0;
    }

    /* renamed from: K  reason: contains not printable characters */
    public boolean m4680(int[] iArr) {
        if (m4677()) {
            ColorStateList colorStateList = this.f6155;
            int colorForState = colorStateList.getColorForState(iArr, colorStateList.getDefaultColor());
            if (colorForState != this.f6154) {
                this.f6154 = colorForState;
                return true;
            }
        }
        return false;
    }

    /* JADX WARNING: Code restructure failed: missing block: B:36:0x014f, code lost:
        throw new org.xmlpull.v1.XmlPullParserException(r2.getPositionDescription() + ": <item> tag requires a 'color' attribute and a 'offset' attribute!");
     */
    /* renamed from: K  reason: contains not printable characters */
    public static C1802 m4676(Resources resources, int i, Resources.Theme theme) throws IOException, XmlPullParserException {
        int next;
        float f;
        Shader shader;
        XmlResourceParser xml = resources.getXml(i);
        AttributeSet asAttributeSet = Xml.asAttributeSet(xml);
        do {
            next = xml.next();
            if (next == 2) {
                break;
            }
        } while (next != 1);
        if (next == 2) {
            String name = xml.getName();
            char c = 65535;
            int hashCode = name.hashCode();
            if (hashCode != 89650992) {
                if (hashCode == 1191572447 && name.equals("selector")) {
                    c = 0;
                }
            } else if (name.equals("gradient")) {
                c = 1;
            }
            if (c == 0) {
                ColorStateList r0 = C2369.m6304(resources, xml, asAttributeSet, theme);
                return new C1802(null, r0, r0.getDefaultColor());
            } else if (c == 1) {
                String name2 = xml.getName();
                if (name2.equals("gradient")) {
                    TypedArray r4 = C2369.m6305(resources, theme, asAttributeSet, R$styleable.GradientColor);
                    float r13 = C2369.m6290(r4, (XmlPullParser) xml, "startX", R$styleable.GradientColor_android_startX, 0.0f);
                    float r14 = C2369.m6290(r4, (XmlPullParser) xml, "startY", R$styleable.GradientColor_android_startY, 0.0f);
                    float r15 = C2369.m6290(r4, (XmlPullParser) xml, "endX", R$styleable.GradientColor_android_endX, 0.0f);
                    float r16 = C2369.m6290(r4, (XmlPullParser) xml, "endY", R$styleable.GradientColor_android_endY, 0.0f);
                    float r7 = C2369.m6290(r4, (XmlPullParser) xml, "centerX", R$styleable.GradientColor_android_centerX, 0.0f);
                    float r10 = C2369.m6290(r4, (XmlPullParser) xml, "centerY", R$styleable.GradientColor_android_centerY, 0.0f);
                    int r8 = C2369.m6277(r4, xml, "type", R$styleable.GradientColor_android_type, 0);
                    int r5 = C2369.m6298(r4, (XmlPullParser) xml, "startColor", R$styleable.GradientColor_android_startColor, 0);
                    boolean r18 = C2369.m6346((XmlPullParser) xml, "centerColor");
                    int r6 = C2369.m6298(r4, (XmlPullParser) xml, "centerColor", R$styleable.GradientColor_android_centerColor, 0);
                    int r9 = C2369.m6298(r4, (XmlPullParser) xml, "endColor", R$styleable.GradientColor_android_endColor, 0);
                    int r02 = C2369.m6277(r4, xml, "tileMode", R$styleable.GradientColor_android_tileMode, 0);
                    float r11 = C2369.m6290(r4, (XmlPullParser) xml, "gradientRadius", R$styleable.GradientColor_android_gradientRadius, 0.0f);
                    r4.recycle();
                    int depth = xml.getDepth() + 1;
                    ArrayList arrayList = new ArrayList(20);
                    ArrayList arrayList2 = new ArrayList(20);
                    Resources resources2 = resources;
                    while (true) {
                        int next2 = xml.next();
                        if (next2 == 1) {
                            f = r14;
                            break;
                        }
                        int depth2 = xml.getDepth();
                        f = r14;
                        if (depth2 < depth && next2 == 3) {
                            break;
                        }
                        if (next2 == 2) {
                            if (depth2 <= depth) {
                                if (!xml.getName().equals("item")) {
                                    continue;
                                } else {
                                    TypedArray r72 = C2369.m6305(resources2, theme, asAttributeSet, R$styleable.GradientColorItem);
                                    boolean hasValue = r72.hasValue(R$styleable.GradientColorItem_android_color);
                                    boolean hasValue2 = r72.hasValue(R$styleable.GradientColorItem_android_offset);
                                    if (!hasValue || !hasValue2) {
                                    } else {
                                        int color = r72.getColor(R$styleable.GradientColorItem_android_color, 0);
                                        float f2 = r72.getFloat(R$styleable.GradientColorItem_android_offset, 0.0f);
                                        r72.recycle();
                                        arrayList2.add(Integer.valueOf(color));
                                        arrayList.add(Float.valueOf(f2));
                                    }
                                }
                            }
                            resources2 = resources;
                        }
                        r15 = r15;
                        r14 = f;
                    }
                    C1803 r1 = arrayList2.size() > 0 ? new C1803(arrayList2, arrayList) : null;
                    if (r1 == null) {
                        if (r18) {
                            r1 = new C1803(r5, r6, r9);
                        } else {
                            r1 = new C1803(r5, r9);
                        }
                    }
                    if (r8 != 1) {
                        if (r8 != 2) {
                            shader = new LinearGradient(r13, f, r15, r16, r1.f6158, r1.f6157, C2369.m6350(r02));
                        } else {
                            shader = new SweepGradient(r7, r10, r1.f6158, r1.f6157);
                        }
                    } else if (r11 > 0.0f) {
                        shader = new RadialGradient(r7, r10, r11, r1.f6158, r1.f6157, C2369.m6350(r02));
                    } else {
                        throw new XmlPullParserException("<gradient> tag requires 'gradientRadius' attribute with radial type");
                    }
                    return new C1802(shader, null, 0);
                }
                throw new XmlPullParserException(xml.getPositionDescription() + ": invalid gradient color tag " + name2);
            } else {
                throw new XmlPullParserException(xml.getPositionDescription() + ": unsupported complex color tag " + name);
            }
        } else {
            throw new XmlPullParserException("No start tag found");
        }
    }
}
