package androidx.constraintlayout.helper.widget;

import android.content.Context;
import android.content.res.TypedArray;
import android.util.AttributeSet;
import android.view.View;
import androidx.constraintlayout.widget.ConstraintLayout;
import androidx.constraintlayout.widget.VirtualLayout;
import androidx.constraintlayout.widget.c;
import androidx.constraintlayout.widget.s;
import java.util.Arrays;
import java.util.HashMap;

/* JADX INFO: loaded from: classes.dex */
public class CircularFlow extends VirtualLayout {

    /* JADX INFO: renamed from: b0, reason: collision with root package name */
    public static int f1061b0;

    /* JADX INFO: renamed from: c0, reason: collision with root package name */
    public static float f1062c0;
    public float[] Q;
    public int[] R;
    public int S;
    public int T;
    public String U;
    public String V;
    public Float W;

    /* JADX INFO: renamed from: a0, reason: collision with root package name */
    public Integer f1063a0;

    /* JADX INFO: renamed from: l, reason: collision with root package name */
    public ConstraintLayout f1064l;

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

    public CircularFlow(Context context) {
        super(context);
    }

    private void setAngles(String str) {
        if (str == null) {
            return;
        }
        int i10 = 0;
        this.T = 0;
        while (true) {
            int iIndexOf = str.indexOf(44, i10);
            if (iIndexOf == -1) {
                t(str.substring(i10).trim());
                return;
            } else {
                t(str.substring(i10, iIndexOf).trim());
                i10 = iIndexOf + 1;
            }
        }
    }

    private void setRadius(String str) {
        if (str == null) {
            return;
        }
        int i10 = 0;
        this.S = 0;
        while (true) {
            int iIndexOf = str.indexOf(44, i10);
            if (iIndexOf == -1) {
                u(str.substring(i10).trim());
                return;
            } else {
                u(str.substring(i10, iIndexOf).trim());
                i10 = iIndexOf + 1;
            }
        }
    }

    public float[] getAngles() {
        return Arrays.copyOf(this.Q, this.T);
    }

    public int[] getRadius() {
        return Arrays.copyOf(this.R, this.S);
    }

    @Override // androidx.constraintlayout.widget.VirtualLayout, androidx.constraintlayout.widget.ConstraintHelper
    public final void l(AttributeSet attributeSet) {
        super.l(attributeSet);
        if (attributeSet != null) {
            TypedArray typedArrayObtainStyledAttributes = getContext().obtainStyledAttributes(attributeSet, s.ConstraintLayout_Layout);
            int indexCount = typedArrayObtainStyledAttributes.getIndexCount();
            for (int i10 = 0; i10 < indexCount; i10++) {
                int index = typedArrayObtainStyledAttributes.getIndex(i10);
                if (index == s.ConstraintLayout_Layout_circularflow_viewCenter) {
                    this.f1065m = typedArrayObtainStyledAttributes.getResourceId(index, 0);
                } else if (index == s.ConstraintLayout_Layout_circularflow_angles) {
                    String string = typedArrayObtainStyledAttributes.getString(index);
                    this.U = string;
                    setAngles(string);
                } else if (index == s.ConstraintLayout_Layout_circularflow_radiusInDP) {
                    String string2 = typedArrayObtainStyledAttributes.getString(index);
                    this.V = string2;
                    setRadius(string2);
                } else if (index == s.ConstraintLayout_Layout_circularflow_defaultAngle) {
                    Float fValueOf = Float.valueOf(typedArrayObtainStyledAttributes.getFloat(index, f1062c0));
                    this.W = fValueOf;
                    setDefaultAngle(fValueOf.floatValue());
                } else if (index == s.ConstraintLayout_Layout_circularflow_defaultRadius) {
                    Integer numValueOf = Integer.valueOf(typedArrayObtainStyledAttributes.getDimensionPixelSize(index, f1061b0));
                    this.f1063a0 = numValueOf;
                    setDefaultRadius(numValueOf.intValue());
                }
            }
            typedArrayObtainStyledAttributes.recycle();
        }
    }

    @Override // androidx.constraintlayout.widget.VirtualLayout, androidx.constraintlayout.widget.ConstraintHelper, android.view.View
    public final void onAttachedToWindow() {
        super.onAttachedToWindow();
        String str = this.U;
        if (str != null) {
            this.Q = new float[1];
            setAngles(str);
        }
        String str2 = this.V;
        if (str2 != null) {
            this.R = new int[1];
            setRadius(str2);
        }
        Float f10 = this.W;
        if (f10 != null) {
            setDefaultAngle(f10.floatValue());
        }
        Integer num = this.f1063a0;
        if (num != null) {
            setDefaultRadius(num.intValue());
        }
        this.f1064l = (ConstraintLayout) getParent();
        for (int i10 = 0; i10 < this.f1268b; i10++) {
            View viewById = this.f1064l.getViewById(this.f1267a[i10]);
            if (viewById != null) {
                int i11 = f1061b0;
                float f11 = f1062c0;
                int[] iArr = this.R;
                HashMap map = this.f1275i;
                if (iArr == null || i10 >= iArr.length) {
                    Integer num2 = this.f1063a0;
                    if (num2 == null || num2.intValue() == -1) {
                    } else {
                        this.S++;
                        if (this.R == null) {
                            this.R = new int[1];
                        }
                        int[] radius = getRadius();
                        this.R = radius;
                        radius[this.S - 1] = i11;
                    }
                } else {
                    i11 = iArr[i10];
                }
                float[] fArr = this.Q;
                if (fArr == null || i10 >= fArr.length) {
                    Float f12 = this.W;
                    if (f12 == null || f12.floatValue() == -1.0f) {
                    } else {
                        this.T++;
                        if (this.Q == null) {
                            this.Q = new float[1];
                        }
                        float[] angles = getAngles();
                        this.Q = angles;
                        angles[this.T - 1] = f11;
                    }
                } else {
                    f11 = fArr[i10];
                }
                c cVar = (c) viewById.getLayoutParams();
                cVar.f1343r = f11;
                cVar.f1339p = this.f1065m;
                cVar.f1341q = i11;
                viewById.setLayoutParams(cVar);
            }
        }
        f();
    }

    public void setDefaultAngle(float f10) {
        f1062c0 = f10;
    }

    public void setDefaultRadius(int i10) {
        f1061b0 = i10;
    }

    public final void t(String str) {
        float[] fArr;
        if (str == null || str.length() == 0 || this.f1269c == null || (fArr = this.Q) == null) {
            return;
        }
        if (this.T + 1 > fArr.length) {
            this.Q = Arrays.copyOf(fArr, fArr.length + 1);
        }
        this.Q[this.T] = Integer.parseInt(str);
        this.T++;
    }

    public final void u(String str) {
        Context context;
        int[] iArr;
        if (str == null || str.length() == 0 || (context = this.f1269c) == null || (iArr = this.R) == null) {
            return;
        }
        if (this.S + 1 > iArr.length) {
            this.R = Arrays.copyOf(iArr, iArr.length + 1);
        }
        this.R[this.S] = (int) (Integer.parseInt(str) * context.getResources().getDisplayMetrics().density);
        this.S++;
    }

    public CircularFlow(Context context, AttributeSet attributeSet) {
        super(context, attributeSet);
    }

    public CircularFlow(Context context, AttributeSet attributeSet, int i10) {
        super(context, attributeSet, i10);
    }
}
