package androidx.constraintlayout.widget;

import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Canvas;
import android.util.AttributeSet;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import androidx.constraintlayout.widget.ConstraintLayout;
import g.d.a.j.j;
import java.util.Arrays;

/* JADX INFO: compiled from: ConstraintHelper.java */
/* JADX INFO: loaded from: classes.dex */
public abstract class b extends View {
    protected int[] b;
    protected int d;
    protected Context e;
    protected j f;

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

    /* JADX INFO: renamed from: h, reason: collision with root package name */
    private String f249h;

    public b(Context context) {
        super(context);
        this.b = new int[32];
        this.f248g = false;
        this.e = context;
        b(null);
    }

    private void a(String str) {
        int iIntValue;
        Object objC;
        if (str == null || this.e == null) {
            return;
        }
        String strTrim = str.trim();
        try {
            iIntValue = g.class.getField(strTrim).getInt(null);
        } catch (Exception unused) {
            iIntValue = 0;
        }
        if (iIntValue == 0) {
            iIntValue = this.e.getResources().getIdentifier(strTrim, "id", this.e.getPackageName());
        }
        if (iIntValue == 0 && isInEditMode() && (getParent() instanceof ConstraintLayout) && (objC = ((ConstraintLayout) getParent()).c(0, strTrim)) != null && (objC instanceof Integer)) {
            iIntValue = ((Integer) objC).intValue();
        }
        if (iIntValue != 0) {
            setTag(iIntValue, null);
            return;
        }
        Log.w("ConstraintHelper", "Could not find id of \"" + strTrim + "\"");
    }

    private void setIds(String str) {
        if (str == null) {
            return;
        }
        int i2 = 0;
        while (true) {
            int iIndexOf = str.indexOf(44, i2);
            if (iIndexOf == -1) {
                a(str.substring(i2));
                return;
            } else {
                a(str.substring(i2, iIndexOf));
                i2 = iIndexOf + 1;
            }
        }
    }

    protected void b(AttributeSet attributeSet) {
        if (attributeSet != null) {
            TypedArray typedArrayObtainStyledAttributes = getContext().obtainStyledAttributes(attributeSet, h.ConstraintLayout_Layout);
            int indexCount = typedArrayObtainStyledAttributes.getIndexCount();
            for (int i2 = 0; i2 < indexCount; i2++) {
                int index = typedArrayObtainStyledAttributes.getIndex(i2);
                if (index == h.ConstraintLayout_Layout_constraint_referenced_ids) {
                    String string = typedArrayObtainStyledAttributes.getString(index);
                    this.f249h = string;
                    setIds(string);
                }
            }
        }
    }

    public void c(ConstraintLayout constraintLayout) {
    }

    public void d(ConstraintLayout constraintLayout) {
    }

    public void e(ConstraintLayout constraintLayout) {
        if (isInEditMode()) {
            setIds(this.f249h);
        }
        j jVar = this.f;
        if (jVar == null) {
            return;
        }
        jVar.J0();
        for (int i2 = 0; i2 < this.d; i2++) {
            View viewE = constraintLayout.e(this.b[i2]);
            if (viewE != null) {
                this.f.I0(constraintLayout.f(viewE));
            }
        }
    }

    public void f() {
        if (this.f == null) {
            return;
        }
        ViewGroup.LayoutParams layoutParams = getLayoutParams();
        if (layoutParams instanceof ConstraintLayout.a) {
            ((ConstraintLayout.a) layoutParams).k0 = this.f;
        }
    }

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

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

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

    public void setReferencedIds(int[] iArr) {
        this.d = 0;
        for (int i2 : iArr) {
            setTag(i2, null);
        }
    }

    @Override // android.view.View
    public void setTag(int i2, Object obj) {
        int i3 = this.d + 1;
        int[] iArr = this.b;
        if (i3 > iArr.length) {
            this.b = Arrays.copyOf(iArr, iArr.length * 2);
        }
        int[] iArr2 = this.b;
        int i4 = this.d;
        iArr2[i4] = i2;
        this.d = i4 + 1;
    }
}
