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.ConstraintHelper;
import androidx.constraintlayout.widget.ConstraintLayout;
import androidx.constraintlayout.widget.c;
import androidx.constraintlayout.widget.s;
import w.d;

/* JADX INFO: loaded from: classes.dex */
public class Layer extends ConstraintHelper {
    public float Q;
    public float R;
    public float S;
    public float T;
    public float U;
    public float V;
    public float W;

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

    /* JADX INFO: renamed from: b0, reason: collision with root package name */
    public final boolean f1078b0;

    /* JADX INFO: renamed from: c0, reason: collision with root package name */
    public View[] f1079c0;

    /* JADX INFO: renamed from: d0, reason: collision with root package name */
    public float f1080d0;

    /* JADX INFO: renamed from: e0, reason: collision with root package name */
    public float f1081e0;

    /* JADX INFO: renamed from: f0, reason: collision with root package name */
    public boolean f1082f0;

    /* JADX INFO: renamed from: g0, reason: collision with root package name */
    public boolean f1083g0;

    /* JADX INFO: renamed from: j, reason: collision with root package name */
    public float f1084j;

    /* JADX INFO: renamed from: k, reason: collision with root package name */
    public float f1085k;

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

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

    public Layer(Context context) {
        super(context);
        this.f1084j = Float.NaN;
        this.f1085k = Float.NaN;
        this.f1086l = Float.NaN;
        this.Q = 1.0f;
        this.R = 1.0f;
        this.S = Float.NaN;
        this.T = Float.NaN;
        this.U = Float.NaN;
        this.V = Float.NaN;
        this.W = Float.NaN;
        this.f1077a0 = Float.NaN;
        this.f1078b0 = true;
        this.f1079c0 = null;
        this.f1080d0 = 0.0f;
        this.f1081e0 = 0.0f;
    }

    @Override // androidx.constraintlayout.widget.ConstraintHelper
    public final void h(ConstraintLayout constraintLayout) {
        g(constraintLayout);
    }

    @Override // androidx.constraintlayout.widget.ConstraintHelper
    public final void l(AttributeSet attributeSet) {
        super.l(attributeSet);
        this.f1271e = false;
        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_android_visibility) {
                    this.f1082f0 = true;
                } else if (index == s.ConstraintLayout_Layout_android_elevation) {
                    this.f1083g0 = true;
                }
            }
            typedArrayObtainStyledAttributes.recycle();
        }
    }

    @Override // androidx.constraintlayout.widget.ConstraintHelper
    public final void o() {
        t();
        this.S = Float.NaN;
        this.T = Float.NaN;
        d dVar = ((c) getLayoutParams()).f1342q0;
        dVar.Q(0);
        dVar.N(0);
        s();
        layout(((int) this.W) - getPaddingLeft(), ((int) this.f1077a0) - getPaddingTop(), getPaddingRight() + ((int) this.U), getPaddingBottom() + ((int) this.V));
        u();
    }

    @Override // androidx.constraintlayout.widget.ConstraintHelper, android.view.View
    public final void onAttachedToWindow() {
        super.onAttachedToWindow();
        this.f1087m = (ConstraintLayout) getParent();
        if (this.f1082f0 || this.f1083g0) {
            int visibility = getVisibility();
            float elevation = getElevation();
            for (int i10 = 0; i10 < this.f1268b; i10++) {
                View viewById = this.f1087m.getViewById(this.f1267a[i10]);
                if (viewById != null) {
                    if (this.f1082f0) {
                        viewById.setVisibility(visibility);
                    }
                    if (this.f1083g0 && elevation > 0.0f) {
                        viewById.setTranslationZ(viewById.getTranslationZ() + elevation);
                    }
                }
            }
        }
    }

    @Override // androidx.constraintlayout.widget.ConstraintHelper
    public final void p(ConstraintLayout constraintLayout) {
        this.f1087m = constraintLayout;
        float rotation = getRotation();
        if (rotation != 0.0f) {
            this.f1086l = rotation;
        } else {
            if (Float.isNaN(this.f1086l)) {
                return;
            }
            this.f1086l = rotation;
        }
    }

    public final void s() {
        if (this.f1087m == null) {
            return;
        }
        if (this.f1078b0 || Float.isNaN(this.S) || Float.isNaN(this.T)) {
            if (!Float.isNaN(this.f1084j) && !Float.isNaN(this.f1085k)) {
                this.T = this.f1085k;
                this.S = this.f1084j;
                return;
            }
            View[] viewArrK = k(this.f1087m);
            int left = viewArrK[0].getLeft();
            int top = viewArrK[0].getTop();
            int right = viewArrK[0].getRight();
            int bottom = viewArrK[0].getBottom();
            for (int i10 = 0; i10 < this.f1268b; i10++) {
                View view = viewArrK[i10];
                left = Math.min(left, view.getLeft());
                top = Math.min(top, view.getTop());
                right = Math.max(right, view.getRight());
                bottom = Math.max(bottom, view.getBottom());
            }
            this.U = right;
            this.V = bottom;
            this.W = left;
            this.f1077a0 = top;
            if (Float.isNaN(this.f1084j)) {
                this.S = (left + right) / 2;
            } else {
                this.S = this.f1084j;
            }
            if (Float.isNaN(this.f1085k)) {
                this.T = (top + bottom) / 2;
            } else {
                this.T = this.f1085k;
            }
        }
    }

    @Override // android.view.View
    public void setElevation(float f10) {
        super.setElevation(f10);
        f();
    }

    @Override // android.view.View
    public void setPivotX(float f10) {
        this.f1084j = f10;
        u();
    }

    @Override // android.view.View
    public void setPivotY(float f10) {
        this.f1085k = f10;
        u();
    }

    @Override // android.view.View
    public void setRotation(float f10) {
        this.f1086l = f10;
        u();
    }

    @Override // android.view.View
    public void setScaleX(float f10) {
        this.Q = f10;
        u();
    }

    @Override // android.view.View
    public void setScaleY(float f10) {
        this.R = f10;
        u();
    }

    @Override // android.view.View
    public void setTranslationX(float f10) {
        this.f1080d0 = f10;
        u();
    }

    @Override // android.view.View
    public void setTranslationY(float f10) {
        this.f1081e0 = f10;
        u();
    }

    @Override // android.view.View
    public void setVisibility(int i10) {
        super.setVisibility(i10);
        f();
    }

    public final void t() {
        int i10;
        if (this.f1087m == null || (i10 = this.f1268b) == 0) {
            return;
        }
        View[] viewArr = this.f1079c0;
        if (viewArr == null || viewArr.length != i10) {
            this.f1079c0 = new View[i10];
        }
        for (int i11 = 0; i11 < this.f1268b; i11++) {
            this.f1079c0[i11] = this.f1087m.getViewById(this.f1267a[i11]);
        }
    }

    public final void u() {
        if (this.f1087m == null) {
            return;
        }
        if (this.f1079c0 == null) {
            t();
        }
        s();
        double radians = Float.isNaN(this.f1086l) ? 0.0d : Math.toRadians(this.f1086l);
        float fSin = (float) Math.sin(radians);
        float fCos = (float) Math.cos(radians);
        float f10 = this.Q;
        float f11 = f10 * fCos;
        float f12 = this.R;
        float f13 = (-f12) * fSin;
        float f14 = f10 * fSin;
        float f15 = f12 * fCos;
        for (int i10 = 0; i10 < this.f1268b; i10++) {
            View view = this.f1079c0[i10];
            int right = (view.getRight() + view.getLeft()) / 2;
            int bottom = (view.getBottom() + view.getTop()) / 2;
            float f16 = right - this.S;
            float f17 = bottom - this.T;
            float f18 = (((f13 * f17) + (f11 * f16)) - f16) + this.f1080d0;
            float f19 = (((f15 * f17) + (f16 * f14)) - f17) + this.f1081e0;
            view.setTranslationX(f18);
            view.setTranslationY(f19);
            view.setScaleY(this.R);
            view.setScaleX(this.Q);
            if (!Float.isNaN(this.f1086l)) {
                view.setRotation(this.f1086l);
            }
        }
    }

    public Layer(Context context, AttributeSet attributeSet) {
        super(context, attributeSet);
        this.f1084j = Float.NaN;
        this.f1085k = Float.NaN;
        this.f1086l = Float.NaN;
        this.Q = 1.0f;
        this.R = 1.0f;
        this.S = Float.NaN;
        this.T = Float.NaN;
        this.U = Float.NaN;
        this.V = Float.NaN;
        this.W = Float.NaN;
        this.f1077a0 = Float.NaN;
        this.f1078b0 = true;
        this.f1079c0 = null;
        this.f1080d0 = 0.0f;
        this.f1081e0 = 0.0f;
    }

    public Layer(Context context, AttributeSet attributeSet, int i10) {
        super(context, attributeSet, i10);
        this.f1084j = Float.NaN;
        this.f1085k = Float.NaN;
        this.f1086l = Float.NaN;
        this.Q = 1.0f;
        this.R = 1.0f;
        this.S = Float.NaN;
        this.T = Float.NaN;
        this.U = Float.NaN;
        this.V = Float.NaN;
        this.W = Float.NaN;
        this.f1077a0 = Float.NaN;
        this.f1078b0 = true;
        this.f1079c0 = null;
        this.f1080d0 = 0.0f;
        this.f1081e0 = 0.0f;
    }
}
