package androidx.constraintlayout.widget;

import android.content.Context;
import android.content.res.Resources;
import android.content.res.TypedArray;
import android.graphics.Canvas;
import android.os.Build;
import android.util.AttributeSet;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewParent;
import androidx.constraintlayout.widget.ConstraintLayout;
import java.util.Arrays;
import java.util.HashMap;

/* JADX INFO: compiled from: ConstraintHelper.java */
/* JADX INFO: loaded from: classes.dex */
public abstract class b extends View {

    /* JADX INFO: renamed from: e, reason: collision with root package name */
    protected int[] f1319e;

    /* JADX INFO: renamed from: f, reason: collision with root package name */
    protected int f1320f;

    /* JADX INFO: renamed from: g, reason: collision with root package name */
    protected Context f1321g;

    /* JADX INFO: renamed from: h, reason: collision with root package name */
    protected n.h f1322h;

    /* JADX INFO: renamed from: i, reason: collision with root package name */
    protected boolean f1323i;

    /* JADX INFO: renamed from: j, reason: collision with root package name */
    protected String f1324j;

    /* JADX INFO: renamed from: k, reason: collision with root package name */
    protected String f1325k;

    /* JADX INFO: renamed from: l, reason: collision with root package name */
    private View[] f1326l;

    /* JADX INFO: renamed from: m, reason: collision with root package name */
    protected HashMap<Integer, String> f1327m;

    public b(Context context) {
        super(context);
        this.f1319e = new int[32];
        this.f1323i = false;
        this.f1326l = null;
        this.f1327m = new HashMap<>();
        this.f1321g = context;
        m(null);
    }

    private void d(String str) {
        if (str == null || str.length() == 0 || this.f1321g == null) {
            return;
        }
        String strTrim = str.trim();
        if (getParent() instanceof ConstraintLayout) {
        }
        int iK = k(strTrim);
        if (iK != 0) {
            this.f1327m.put(Integer.valueOf(iK), strTrim);
            e(iK);
            return;
        }
        Log.w("ConstraintHelper", "Could not find id of \"" + strTrim + "\"");
    }

    private void e(int i3) {
        if (i3 == getId()) {
            return;
        }
        int i4 = this.f1320f + 1;
        int[] iArr = this.f1319e;
        if (i4 > iArr.length) {
            this.f1319e = Arrays.copyOf(iArr, iArr.length * 2);
        }
        int[] iArr2 = this.f1319e;
        int i5 = this.f1320f;
        iArr2[i5] = i3;
        this.f1320f = i5 + 1;
    }

    private void f(String str) {
        if (str == null || str.length() == 0 || this.f1321g == null) {
            return;
        }
        String strTrim = str.trim();
        ConstraintLayout constraintLayout = getParent() instanceof ConstraintLayout ? (ConstraintLayout) getParent() : null;
        if (constraintLayout == null) {
            Log.w("ConstraintHelper", "Parent not a ConstraintLayout");
            return;
        }
        int childCount = constraintLayout.getChildCount();
        for (int i3 = 0; i3 < childCount; i3++) {
            View childAt = constraintLayout.getChildAt(i3);
            ViewGroup.LayoutParams layoutParams = childAt.getLayoutParams();
            if ((layoutParams instanceof ConstraintLayout.b) && strTrim.equals(((ConstraintLayout.b) layoutParams).Y)) {
                if (childAt.getId() == -1) {
                    Log.w("ConstraintHelper", "to use ConstraintTag view " + childAt.getClass().getSimpleName() + " must have an ID");
                } else {
                    e(childAt.getId());
                }
            }
        }
    }

    private int j(ConstraintLayout constraintLayout, String str) {
        Resources resources;
        if (str == null || constraintLayout == null || (resources = this.f1321g.getResources()) == null) {
            return 0;
        }
        int childCount = constraintLayout.getChildCount();
        for (int i3 = 0; i3 < childCount; i3++) {
            View childAt = constraintLayout.getChildAt(i3);
            if (childAt.getId() != -1) {
                String resourceEntryName = null;
                try {
                    resourceEntryName = resources.getResourceEntryName(childAt.getId());
                } catch (Resources.NotFoundException unused) {
                }
                if (str.equals(resourceEntryName)) {
                    return childAt.getId();
                }
            }
        }
        return 0;
    }

    private int k(String str) {
        ConstraintLayout constraintLayout = getParent() instanceof ConstraintLayout ? (ConstraintLayout) getParent() : null;
        int iJ = 0;
        if (isInEditMode() && constraintLayout != null) {
            Object objH = constraintLayout.h(0, str);
            if (objH instanceof Integer) {
                iJ = ((Integer) objH).intValue();
            }
        }
        if (iJ == 0 && constraintLayout != null) {
            iJ = j(constraintLayout, str);
        }
        if (iJ == 0) {
            try {
                iJ = h.class.getField(str).getInt(null);
            } catch (Exception unused) {
            }
        }
        return iJ == 0 ? this.f1321g.getResources().getIdentifier(str, "id", this.f1321g.getPackageName()) : iJ;
    }

    protected void g() {
        ViewParent parent = getParent();
        if (parent == null || !(parent instanceof ConstraintLayout)) {
            return;
        }
        h((ConstraintLayout) parent);
    }

    public int[] getReferencedIds() {
        return Arrays.copyOf(this.f1319e, this.f1320f);
    }

    protected void h(ConstraintLayout constraintLayout) {
        int visibility = getVisibility();
        float elevation = Build.VERSION.SDK_INT >= 21 ? getElevation() : 0.0f;
        for (int i3 = 0; i3 < this.f1320f; i3++) {
            View viewL = constraintLayout.l(this.f1319e[i3]);
            if (viewL != null) {
                viewL.setVisibility(visibility);
                if (elevation > 0.0f && Build.VERSION.SDK_INT >= 21) {
                    viewL.setTranslationZ(viewL.getTranslationZ() + elevation);
                }
            }
        }
    }

    protected void i(ConstraintLayout constraintLayout) {
    }

    protected View[] l(ConstraintLayout constraintLayout) {
        View[] viewArr = this.f1326l;
        if (viewArr == null || viewArr.length != this.f1320f) {
            this.f1326l = new View[this.f1320f];
        }
        for (int i3 = 0; i3 < this.f1320f; i3++) {
            this.f1326l[i3] = constraintLayout.l(this.f1319e[i3]);
        }
        return this.f1326l;
    }

    protected void m(AttributeSet attributeSet) {
        if (attributeSet != null) {
            TypedArray typedArrayObtainStyledAttributes = getContext().obtainStyledAttributes(attributeSet, i.U0);
            int indexCount = typedArrayObtainStyledAttributes.getIndexCount();
            for (int i3 = 0; i3 < indexCount; i3++) {
                int index = typedArrayObtainStyledAttributes.getIndex(i3);
                if (index == i.f1485g1) {
                    String string = typedArrayObtainStyledAttributes.getString(index);
                    this.f1324j = string;
                    setIds(string);
                } else if (index == i.f1489h1) {
                    String string2 = typedArrayObtainStyledAttributes.getString(index);
                    this.f1325k = string2;
                    setReferenceTags(string2);
                }
            }
            typedArrayObtainStyledAttributes.recycle();
        }
    }

    public void n(n.e eVar, boolean z2) {
    }

    public void o(ConstraintLayout constraintLayout) {
    }

    @Override // android.view.View
    protected void onAttachedToWindow() {
        super.onAttachedToWindow();
        String str = this.f1324j;
        if (str != null) {
            setIds(str);
        }
        String str2 = this.f1325k;
        if (str2 != null) {
            setReferenceTags(str2);
        }
    }

    @Override // android.view.View
    public void onDraw(Canvas canvas) {
    }

    @Override // android.view.View
    protected void onMeasure(int i3, int i4) {
        if (this.f1323i) {
            super.onMeasure(i3, i4);
        } else {
            setMeasuredDimension(0, 0);
        }
    }

    public void p(ConstraintLayout constraintLayout) {
    }

    public void q(ConstraintLayout constraintLayout) {
    }

    public void r(ConstraintLayout constraintLayout) {
        String str;
        int iJ;
        if (isInEditMode()) {
            setIds(this.f1324j);
        }
        n.h hVar = this.f1322h;
        if (hVar == null) {
            return;
        }
        hVar.c();
        for (int i3 = 0; i3 < this.f1320f; i3++) {
            int i4 = this.f1319e[i3];
            View viewL = constraintLayout.l(i4);
            if (viewL == null && (iJ = j(constraintLayout, (str = this.f1327m.get(Integer.valueOf(i4))))) != 0) {
                this.f1319e[i3] = iJ;
                this.f1327m.put(Integer.valueOf(iJ), str);
                viewL = constraintLayout.l(iJ);
            }
            if (viewL != null) {
                this.f1322h.a(constraintLayout.p(viewL));
            }
        }
        this.f1322h.b(constraintLayout.f1238g);
    }

    public void s() {
        if (this.f1322h == null) {
            return;
        }
        ViewGroup.LayoutParams layoutParams = getLayoutParams();
        if (layoutParams instanceof ConstraintLayout.b) {
            ((ConstraintLayout.b) layoutParams).f1291r0 = (n.e) this.f1322h;
        }
    }

    protected void setIds(String str) {
        this.f1324j = str;
        if (str == null) {
            return;
        }
        int i3 = 0;
        this.f1320f = 0;
        while (true) {
            int iIndexOf = str.indexOf(44, i3);
            if (iIndexOf == -1) {
                d(str.substring(i3));
                return;
            } else {
                d(str.substring(i3, iIndexOf));
                i3 = iIndexOf + 1;
            }
        }
    }

    protected void setReferenceTags(String str) {
        this.f1325k = str;
        if (str == null) {
            return;
        }
        int i3 = 0;
        this.f1320f = 0;
        while (true) {
            int iIndexOf = str.indexOf(44, i3);
            if (iIndexOf == -1) {
                f(str.substring(i3));
                return;
            } else {
                f(str.substring(i3, iIndexOf));
                i3 = iIndexOf + 1;
            }
        }
    }

    public void setReferencedIds(int[] iArr) {
        this.f1324j = null;
        this.f1320f = 0;
        for (int i3 : iArr) {
            e(i3);
        }
    }

    @Override // android.view.View
    public void setTag(int i3, Object obj) {
        super.setTag(i3, obj);
        if (obj == null && this.f1324j == null) {
            e(i3);
        }
    }

    public b(Context context, AttributeSet attributeSet) {
        super(context, attributeSet);
        this.f1319e = new int[32];
        this.f1323i = false;
        this.f1326l = null;
        this.f1327m = new HashMap<>();
        this.f1321g = context;
        m(attributeSet);
    }
}
