package d.f.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 b extends View {

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

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

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

    /* JADX INFO: renamed from: o, reason: collision with root package name */
    public d.f.a.j.g f2442o;

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

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

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

    /* JADX INFO: renamed from: s, reason: collision with root package name */
    public HashMap<Integer, String> f2446s;

    public b(Context context) {
        super(context);
        this.f2439f = new int[32];
        this.f2445r = null;
        this.f2446s = new HashMap<>();
        this.f2441n = context;
        i(null);
    }

    public b(Context context, AttributeSet attributeSet) {
        super(context, attributeSet);
        this.f2439f = new int[32];
        this.f2445r = null;
        this.f2446s = new HashMap<>();
        this.f2441n = context;
        i(attributeSet);
    }

    public final void c(String str) {
        if (str == null || str.length() == 0 || this.f2441n == 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 objC = constraintLayout.c(0, strTrim);
            if (objC instanceof Integer) {
                identifier = ((Integer) objC).intValue();
            }
        }
        if (identifier == 0 && constraintLayout != null) {
            identifier = h(constraintLayout, strTrim);
        }
        if (identifier == 0) {
            try {
                identifier = h.class.getField(strTrim).getInt(null);
            } catch (Exception unused) {
            }
        }
        if (identifier == 0) {
            identifier = this.f2441n.getResources().getIdentifier(strTrim, "id", this.f2441n.getPackageName());
        }
        if (identifier != 0) {
            this.f2446s.put(Integer.valueOf(identifier), strTrim);
            d(identifier);
            return;
        }
        Log.w("ConstraintHelper", "Could not find id of \"" + strTrim + "\"");
    }

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

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

    public void f(ConstraintLayout constraintLayout) {
        int visibility = getVisibility();
        float elevation = getElevation();
        for (int i2 = 0; i2 < this.f2440m; i2++) {
            View viewD = constraintLayout.d(this.f2439f[i2]);
            if (viewD != null) {
                viewD.setVisibility(visibility);
                if (elevation > 0.0f) {
                    viewD.setTranslationZ(viewD.getTranslationZ() + elevation);
                }
            }
        }
    }

    public void g(ConstraintLayout constraintLayout) {
    }

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

    public final int h(ConstraintLayout constraintLayout, String str) {
        Resources resources;
        if (str == null || (resources = this.f2441n.getResources()) == null) {
            return 0;
        }
        int childCount = constraintLayout.getChildCount();
        for (int i2 = 0; i2 < childCount; i2++) {
            View childAt = constraintLayout.getChildAt(i2);
            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, i.f2546b);
            int indexCount = typedArrayObtainStyledAttributes.getIndexCount();
            for (int i2 = 0; i2 < indexCount; i2++) {
                int index = typedArrayObtainStyledAttributes.getIndex(i2);
                if (index == 35) {
                    String string = typedArrayObtainStyledAttributes.getString(index);
                    this.f2443p = string;
                    setIds(string);
                } else if (index == 36) {
                    String string2 = typedArrayObtainStyledAttributes.getString(index);
                    this.f2444q = string2;
                    setReferenceTags(string2);
                }
            }
            typedArrayObtainStyledAttributes.recycle();
        }
    }

    public void j(d.f.a.j.d dVar, boolean z2) {
    }

    public void k() {
    }

    public void l() {
    }

    public void m() {
    }

    public void n() {
        if (this.f2442o == null) {
            return;
        }
        ViewGroup.LayoutParams layoutParams = getLayoutParams();
        if (layoutParams instanceof ConstraintLayout.a) {
            ((ConstraintLayout.a) layoutParams).p0 = (d.f.a.j.d) this.f2442o;
        }
    }

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

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

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

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

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

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

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