package androidx.appcompat.widget;

import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Canvas;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewParent;
import java.lang.ref.WeakReference;
import p007c.C0494j;

/* loaded from: classes.dex */
public final class ViewStubCompat extends View {

    /* renamed from: d */
    public int f628d;

    /* renamed from: e */
    public int f629e;

    /* renamed from: f */
    public WeakReference<View> f630f;

    /* renamed from: g */
    public LayoutInflater f631g;

    /* renamed from: androidx.appcompat.widget.ViewStubCompat$a */
    /* loaded from: classes.dex */
    public interface InterfaceC0162a {
    }

    public ViewStubCompat(Context context, AttributeSet attributeSet) {
        this(context, attributeSet, 0);
    }

    public ViewStubCompat(Context context, AttributeSet attributeSet, int i) {
        super(context, attributeSet, i);
        this.f628d = 0;
        TypedArray obtainStyledAttributes = context.obtainStyledAttributes(attributeSet, C0494j.f1705C3, i, 0);
        this.f629e = obtainStyledAttributes.getResourceId(C0494j.f1720F3, -1);
        this.f628d = obtainStyledAttributes.getResourceId(C0494j.f1715E3, 0);
        setId(obtainStyledAttributes.getResourceId(C0494j.f1710D3, -1));
        obtainStyledAttributes.recycle();
        setVisibility(8);
        setWillNotDraw(true);
    }

    /* renamed from: a */
    public View m4661a() {
        ViewParent parent = getParent();
        if (parent instanceof ViewGroup) {
            if (this.f628d != 0) {
                ViewGroup viewGroup = (ViewGroup) parent;
                LayoutInflater layoutInflater = this.f631g;
                if (layoutInflater == null) {
                    layoutInflater = LayoutInflater.from(getContext());
                }
                View inflate = layoutInflater.inflate(this.f628d, viewGroup, false);
                int i = this.f629e;
                if (i != -1) {
                    inflate.setId(i);
                }
                int indexOfChild = viewGroup.indexOfChild(this);
                viewGroup.removeViewInLayout(this);
                ViewGroup.LayoutParams layoutParams = getLayoutParams();
                if (layoutParams != null) {
                    viewGroup.addView(inflate, indexOfChild, layoutParams);
                } else {
                    viewGroup.addView(inflate, indexOfChild);
                }
                this.f630f = new WeakReference<>(inflate);
                return inflate;
            }
            throw new IllegalArgumentException("ViewStub must have a valid layoutResource");
        }
        throw new IllegalStateException("ViewStub must have a non-null ViewGroup viewParent");
    }

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

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

    public int getInflatedId() {
        return this.f629e;
    }

    public LayoutInflater getLayoutInflater() {
        return this.f631g;
    }

    public int getLayoutResource() {
        return this.f628d;
    }

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

    public void setInflatedId(int i) {
        this.f629e = i;
    }

    public void setLayoutInflater(LayoutInflater layoutInflater) {
        this.f631g = layoutInflater;
    }

    public void setLayoutResource(int i) {
        this.f628d = i;
    }

    public void setOnInflateListener(InterfaceC0162a interfaceC0162a) {
    }

    @Override // android.view.View
    public void setVisibility(int i) {
        WeakReference<View> weakReference = this.f630f;
        if (weakReference != null) {
            View view = weakReference.get();
            if (view == null) {
                throw new IllegalStateException("setVisibility called on un-referenced view");
            }
            view.setVisibility(i);
            return;
        }
        super.setVisibility(i);
        if (i == 0 || i == 4) {
            m4661a();
        }
    }
}