package b.e.c;

import android.content.Context;
import android.content.res.Resources;
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 java.util.Arrays;
import java.util.HashMap;

/* JADX INFO: loaded from: classes.dex */
public abstract class c extends View {

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    public int[] f822a;

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

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    public Context f824c;

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    public b.e.a.j.g f825d;

    /* JADX INFO: renamed from: e, reason: collision with root package name */
    public String f826e;

    /* JADX INFO: renamed from: f, reason: collision with root package name */
    public String f827f;
    public View[] g;
    public HashMap<Integer, String> h;

    public c(Context context) {
        super(context);
        this.f822a = new int[32];
        this.g = null;
        this.h = new HashMap<>();
        this.f824c = context;
        i(null);
    }

    public final void c(String str) {
        if (str == null || str.length() == 0 || this.f824c == null) {
            return;
        }
        String strTrim = str.trim();
        if (getParent() instanceof ConstraintLayout) {
        }
        ConstraintLayout constraintLayout = getParent() instanceof ConstraintLayout ? (ConstraintLayout) getParent() : null;
        int identifier = 0;
        if (isInEditMode() && constraintLayout != null) {
            Object objB = constraintLayout.b(0, strTrim);
            if (objB instanceof Integer) {
                identifier = ((Integer) objB).intValue();
            }
        }
        if (identifier == 0 && constraintLayout != null) {
            identifier = h(constraintLayout, strTrim);
        }
        if (identifier == 0) {
            try {
                identifier = j.class.getField(strTrim).getInt(null);
            } catch (Exception unused) {
            }
        }
        if (identifier == 0) {
            identifier = this.f824c.getResources().getIdentifier(strTrim, "id", this.f824c.getPackageName());
        }
        if (identifier != 0) {
            this.h.put(Integer.valueOf(identifier), strTrim);
            d(identifier);
            return;
        }
        Log.w("ConstraintHelper", "Could not find id of \"" + strTrim + "\"");
    }

    public final void d(int i) {
        if (i == getId()) {
            return;
        }
        int i2 = this.f823b + 1;
        int[] iArr = this.f822a;
        if (i2 > iArr.length) {
            this.f822a = Arrays.copyOf(iArr, iArr.length * 2);
        }
        int[] iArr2 = this.f822a;
        int i3 = this.f823b;
        iArr2[i3] = i;
        this.f823b = i3 + 1;
    }

    public final void e(String str) {
        if (str == null || str.length() == 0 || this.f824c == 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 i = 0; i < childCount; i++) {
            View childAt = constraintLayout.getChildAt(i);
            ViewGroup.LayoutParams layoutParams = childAt.getLayoutParams();
            if ((layoutParams instanceof ConstraintLayout.a) && strTrim.equals(((ConstraintLayout.a) layoutParams).Y)) {
                if (childAt.getId() == -1) {
                    StringBuilder sbD = c.a.a.a.a.d("to use ConstraintTag view ");
                    sbD.append(childAt.getClass().getSimpleName());
                    sbD.append(" must have an ID");
                    Log.w("ConstraintHelper", sbD.toString());
                } else {
                    d(childAt.getId());
                }
            }
        }
    }

    public void f(ConstraintLayout constraintLayout) {
        int visibility = getVisibility();
        float elevation = getElevation();
        for (int i = 0; i < this.f823b; i++) {
            View viewC = constraintLayout.c(this.f822a[i]);
            if (viewC != null) {
                viewC.setVisibility(visibility);
                if (elevation > 0.0f) {
                    viewC.setTranslationZ(viewC.getTranslationZ() + elevation);
                }
            }
        }
    }

    public void g(ConstraintLayout constraintLayout) {
    }

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

    public final int h(ConstraintLayout constraintLayout, String str) {
        Resources resources;
        if (str == null || (resources = this.f824c.getResources()) == null) {
            return 0;
        }
        int childCount = constraintLayout.getChildCount();
        for (int i = 0; i < childCount; i++) {
            View childAt = constraintLayout.getChildAt(i);
            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;
    }

    public void i(AttributeSet attributeSet) {
        if (attributeSet != null) {
            TypedArray typedArrayObtainStyledAttributes = getContext().obtainStyledAttributes(attributeSet, k.f890b);
            int indexCount = typedArrayObtainStyledAttributes.getIndexCount();
            for (int i = 0; i < indexCount; i++) {
                int index = typedArrayObtainStyledAttributes.getIndex(i);
                if (index == 35) {
                    String string = typedArrayObtainStyledAttributes.getString(index);
                    this.f826e = string;
                    setIds(string);
                } else if (index == 36) {
                    String string2 = typedArrayObtainStyledAttributes.getString(index);
                    this.f827f = string2;
                    setReferenceTags(string2);
                }
            }
            typedArrayObtainStyledAttributes.recycle();
        }
    }

    public void j(b.e.a.j.d dVar, boolean z) {
    }

    public void k() {
        if (this.f825d == null) {
            return;
        }
        ViewGroup.LayoutParams layoutParams = getLayoutParams();
        if (layoutParams instanceof ConstraintLayout.a) {
            ((ConstraintLayout.a) layoutParams).q0 = (b.e.a.j.d) this.f825d;
        }
    }

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

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

    @Override // android.view.View
    public void onMeasure(int i, int i2) {
        setMeasuredDimension(0, 0);
    }

    public void setIds(String str) {
        this.f826e = str;
        if (str == null) {
            return;
        }
        int i = 0;
        this.f823b = 0;
        while (true) {
            int iIndexOf = str.indexOf(44, i);
            if (iIndexOf == -1) {
                c(str.substring(i));
                return;
            } else {
                c(str.substring(i, iIndexOf));
                i = iIndexOf + 1;
            }
        }
    }

    public void setReferenceTags(String str) {
        this.f827f = str;
        if (str == null) {
            return;
        }
        int i = 0;
        this.f823b = 0;
        while (true) {
            int iIndexOf = str.indexOf(44, i);
            if (iIndexOf == -1) {
                e(str.substring(i));
                return;
            } else {
                e(str.substring(i, iIndexOf));
                i = iIndexOf + 1;
            }
        }
    }

    public void setReferencedIds(int[] iArr) {
        this.f826e = null;
        this.f823b = 0;
        for (int i : iArr) {
            d(i);
        }
    }

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