package androidx.compose.ui.platform;

import android.content.Context;
import android.os.IBinder;
import android.util.AttributeSet;
import android.view.KeyEvent;
import android.view.View;
import android.view.ViewGroup;
import java.lang.ref.WeakReference;
import y0.n2;

/* loaded from: classes.dex */
public abstract class a extends ViewGroup {

    /* renamed from: p, reason: collision with root package name */
    private WeakReference f2310p;

    /* renamed from: q, reason: collision with root package name */
    private IBinder f2311q;

    /* renamed from: r, reason: collision with root package name */
    private y0.q f2312r;

    /* renamed from: s, reason: collision with root package name */
    private y0.r f2313s;

    /* renamed from: t, reason: collision with root package name */
    private dn.a f2314t;

    /* renamed from: u, reason: collision with root package name */
    private boolean f2315u;

    /* renamed from: v, reason: collision with root package name */
    private boolean f2316v;

    /* renamed from: w, reason: collision with root package name */
    private boolean f2317w;

    /* JADX INFO: Access modifiers changed from: package-private */
    /* renamed from: androidx.compose.ui.platform.a$a, reason: collision with other inner class name */
    /* loaded from: classes.dex */
    public static final class C0063a extends kotlin.jvm.internal.v implements dn.p {
        C0063a() {
            super(2);
        }

        public final void a(y0.m mVar, int i10) {
            if ((i10 & 3) == 2 && mVar.v()) {
                mVar.A();
                return;
            }
            if (y0.p.H()) {
                y0.p.Q(-656146368, i10, -1, "androidx.compose.ui.platform.AbstractComposeView.ensureCompositionCreated.<anonymous> (ComposeView.android.kt:258)");
            }
            a.this.a(mVar, 0);
            if (y0.p.H()) {
                y0.p.P();
            }
        }

        @Override // dn.p
        public /* bridge */ /* synthetic */ Object invoke(Object obj, Object obj2) {
            a((y0.m) obj, ((Number) obj2).intValue());
            return rm.n0.f34904a;
        }
    }

    public /* synthetic */ a(Context context, AttributeSet attributeSet, int i10, int i11, kotlin.jvm.internal.k kVar) {
        this(context, (i11 & 2) != 0 ? null : attributeSet, (i11 & 4) != 0 ? 0 : i10);
    }

    private final y0.r b(y0.r rVar) {
        y0.r rVar2 = i(rVar) ? rVar : null;
        if (rVar2 != null) {
            this.f2310p = new WeakReference(rVar2);
        }
        return rVar;
    }

    private final void c() {
        if (this.f2316v) {
            return;
        }
        throw new UnsupportedOperationException("Cannot add views to " + getClass().getSimpleName() + "; only Compose content is supported");
    }

    private final void f() {
        if (this.f2312r == null) {
            try {
                this.f2316v = true;
                this.f2312r = p3.c(this, j(), g1.c.c(-656146368, true, new C0063a()));
            } finally {
                this.f2316v = false;
            }
        }
    }

    private static /* synthetic */ void getDisposeViewCompositionStrategy$annotations() {
    }

    public static /* synthetic */ void getShowLayoutBounds$annotations() {
    }

    private final boolean i(y0.r rVar) {
        return !(rVar instanceof y0.n2) || ((n2.d) ((y0.n2) rVar).d0().getValue()).compareTo(n2.d.ShuttingDown) > 0;
    }

    private final y0.r j() {
        y0.r rVar;
        y0.r rVar2 = this.f2313s;
        if (rVar2 != null) {
            return rVar2;
        }
        y0.r d10 = m3.d(this);
        y0.r rVar3 = null;
        y0.r b10 = d10 != null ? b(d10) : null;
        if (b10 != null) {
            return b10;
        }
        WeakReference weakReference = this.f2310p;
        if (weakReference != null && (rVar = (y0.r) weakReference.get()) != null && i(rVar)) {
            rVar3 = rVar;
        }
        y0.r rVar4 = rVar3;
        return rVar4 == null ? b(m3.h(this)) : rVar4;
    }

    private final void setParentContext(y0.r rVar) {
        if (this.f2313s != rVar) {
            this.f2313s = rVar;
            if (rVar != null) {
                this.f2310p = null;
            }
            y0.q qVar = this.f2312r;
            if (qVar != null) {
                qVar.a();
                this.f2312r = null;
                if (isAttachedToWindow()) {
                    f();
                }
            }
        }
    }

    private final void setPreviousAttachedWindowToken(IBinder iBinder) {
        if (this.f2311q != iBinder) {
            this.f2311q = iBinder;
            this.f2310p = null;
        }
    }

    public abstract void a(y0.m mVar, int i10);

    @Override // android.view.ViewGroup
    public void addView(View view) {
        c();
        super.addView(view);
    }

    @Override // android.view.ViewGroup
    protected boolean addViewInLayout(View view, int i10, ViewGroup.LayoutParams layoutParams) {
        c();
        return super.addViewInLayout(view, i10, layoutParams);
    }

    public final void d() {
        if (!(this.f2313s != null || isAttachedToWindow())) {
            throw new IllegalStateException("createComposition requires either a parent reference or the View to be attachedto a window. Attach the View or call setParentCompositionReference.".toString());
        }
        f();
    }

    public final void e() {
        y0.q qVar = this.f2312r;
        if (qVar != null) {
            qVar.a();
        }
        this.f2312r = null;
        requestLayout();
    }

    public void g(boolean z10, int i10, int i11, int i12, int i13) {
        View childAt = getChildAt(0);
        if (childAt != null) {
            childAt.layout(getPaddingLeft(), getPaddingTop(), (i12 - i10) - getPaddingRight(), (i13 - i11) - getPaddingBottom());
        }
    }

    public final boolean getHasComposition() {
        return this.f2312r != null;
    }

    protected boolean getShouldCreateCompositionOnAttachedToWindow() {
        return true;
    }

    public final boolean getShowLayoutBounds() {
        return this.f2315u;
    }

    public void h(int i10, int i11) {
        View childAt = getChildAt(0);
        if (childAt == null) {
            super.onMeasure(i10, i11);
            return;
        }
        childAt.measure(View.MeasureSpec.makeMeasureSpec(Math.max(0, (View.MeasureSpec.getSize(i10) - getPaddingLeft()) - getPaddingRight()), View.MeasureSpec.getMode(i10)), View.MeasureSpec.makeMeasureSpec(Math.max(0, (View.MeasureSpec.getSize(i11) - getPaddingTop()) - getPaddingBottom()), View.MeasureSpec.getMode(i11)));
        setMeasuredDimension(childAt.getMeasuredWidth() + getPaddingLeft() + getPaddingRight(), childAt.getMeasuredHeight() + getPaddingTop() + getPaddingBottom());
    }

    @Override // android.view.ViewGroup
    public boolean isTransitionGroup() {
        return !this.f2317w || super.isTransitionGroup();
    }

    /* JADX INFO: Access modifiers changed from: protected */
    @Override // android.view.ViewGroup, android.view.View
    public void onAttachedToWindow() {
        super.onAttachedToWindow();
        setPreviousAttachedWindowToken(getWindowToken());
        if (getShouldCreateCompositionOnAttachedToWindow()) {
            f();
        }
    }

    @Override // android.view.ViewGroup, android.view.View
    protected final void onLayout(boolean z10, int i10, int i11, int i12, int i13) {
        g(z10, i10, i11, i12, i13);
    }

    @Override // android.view.View
    protected final void onMeasure(int i10, int i11) {
        f();
        h(i10, i11);
    }

    @Override // android.view.View
    public void onRtlPropertiesChanged(int i10) {
        View childAt = getChildAt(0);
        if (childAt == null) {
            return;
        }
        childAt.setLayoutDirection(i10);
    }

    public final void setParentCompositionContext(y0.r rVar) {
        setParentContext(rVar);
    }

    public final void setShowLayoutBounds(boolean z10) {
        this.f2315u = z10;
        KeyEvent.Callback childAt = getChildAt(0);
        if (childAt != null) {
            ((j2.j1) childAt).setShowLayoutBounds(z10);
        }
    }

    @Override // android.view.ViewGroup
    public void setTransitionGroup(boolean z10) {
        super.setTransitionGroup(z10);
        this.f2317w = true;
    }

    public final void setViewCompositionStrategy(u2 u2Var) {
        dn.a aVar = this.f2314t;
        if (aVar != null) {
            aVar.invoke();
        }
        this.f2314t = u2Var.a(this);
    }

    @Override // android.view.ViewGroup
    public boolean shouldDelayChildPressedState() {
        return false;
    }

    public a(Context context, AttributeSet attributeSet, int i10) {
        super(context, attributeSet, i10);
        setClipChildren(false);
        setClipToPadding(false);
        this.f2314t = u2.f2705a.a().a(this);
    }

    @Override // android.view.ViewGroup
    public void addView(View view, int i10) {
        c();
        super.addView(view, i10);
    }

    @Override // android.view.ViewGroup
    protected boolean addViewInLayout(View view, int i10, ViewGroup.LayoutParams layoutParams, boolean z10) {
        c();
        return super.addViewInLayout(view, i10, layoutParams, z10);
    }

    @Override // android.view.ViewGroup
    public void addView(View view, int i10, int i11) {
        c();
        super.addView(view, i10, i11);
    }

    @Override // android.view.ViewGroup, android.view.ViewManager
    public void addView(View view, ViewGroup.LayoutParams layoutParams) {
        c();
        super.addView(view, layoutParams);
    }

    @Override // android.view.ViewGroup
    public void addView(View view, int i10, ViewGroup.LayoutParams layoutParams) {
        c();
        super.addView(view, i10, layoutParams);
    }
}
