package android.support.constraint;

import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Canvas;
import android.support.constraint.ConstraintLayout;
import android.support.constraint.i.j.j;
import android.util.AttributeSet;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import java.util.Arrays;

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

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

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

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

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

    /* JADX INFO: renamed from: f, reason: collision with root package name */
    protected boolean f394f;
    private String g;

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

    private void a(String str) {
        int iIntValue;
        Object objC;
        if (str == null || this.f392d == null) {
            return;
        }
        String strTrim = str.trim();
        try {
            iIntValue = g.class.getField(strTrim).getInt(null);
        } catch (Exception unused) {
            iIntValue = 0;
        }
        if (iIntValue == 0) {
            iIntValue = this.f392d.getResources().getIdentifier(strTrim, "id", this.f392d.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 i = 0;
        while (true) {
            int iIndexOf = str.indexOf(44, i);
            if (iIndexOf == -1) {
                a(str.substring(i));
                return;
            } else {
                a(str.substring(i, iIndexOf));
                i = iIndexOf + 1;
            }
        }
    }

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

    public void c(ConstraintLayout constraintLayout) {
    }

    public void d(ConstraintLayout constraintLayout) {
    }

    public void e(ConstraintLayout constraintLayout) {
        if (isInEditMode()) {
            setIds(this.g);
        }
        j jVar = this.f393e;
        if (jVar == null) {
            return;
        }
        jVar.J0();
        for (int i = 0; i < this.f391c; i++) {
            View viewE = constraintLayout.e(this.f390b[i]);
            if (viewE != null) {
                this.f393e.I0(constraintLayout.f(viewE));
            }
        }
    }

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

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

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

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

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

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