package io.flutter.plugin.platform;

import android.app.Presentation;
import android.content.Context;
import android.content.MutableContextWrapper;
import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;
import android.view.Display;
import android.view.View;
import android.view.WindowManager;
import android.widget.FrameLayout;
import androidx.annotation.Keep;
import androidx.annotation.Nullable;

/* JADX INFO: Access modifiers changed from: package-private */
/* JADX INFO: loaded from: classes.dex */
@Keep
public class SingleViewPresentation extends Presentation {
    private static final String TAG = "PlatformViewsController";
    private final a accessibilityEventsDelegate;
    private FrameLayout container;
    private final View.OnFocusChangeListener focusChangeListener;
    private final Context outerContext;
    private t rootView;
    private boolean startFocused;
    private final w state;
    private int viewId;

    public SingleViewPresentation(Context context, Display display, i iVar, a aVar, int i10, View.OnFocusChangeListener onFocusChangeListener) {
        super(new u(context), display);
        this.startFocused = false;
        this.accessibilityEventsDelegate = aVar;
        this.viewId = i10;
        this.focusChangeListener = onFocusChangeListener;
        this.outerContext = context;
        w wVar = new w();
        this.state = wVar;
        wVar.f28259a = iVar;
        getWindow().setFlags(8, 8);
        getWindow().setType(2030);
    }

    public w detachState() {
        FrameLayout frameLayout = this.container;
        if (frameLayout != null) {
            frameLayout.removeAllViews();
        }
        t tVar = this.rootView;
        if (tVar != null) {
            tVar.removeAllViews();
        }
        return this.state;
    }

    @Nullable
    public i getView() {
        return this.state.f28259a;
    }

    @Override // android.app.Dialog
    public void onCreate(Bundle bundle) {
        super.onCreate(bundle);
        getWindow().setBackgroundDrawable(new ColorDrawable(0));
        w wVar = this.state;
        if (wVar.f28261c == null) {
            wVar.f28261c = new s(getContext());
        }
        if (this.state.f28260b == null) {
            WindowManager windowManager = (WindowManager) getContext().getSystemService("window");
            w wVar2 = this.state;
            wVar2.f28260b = new d0(windowManager, wVar2.f28261c);
        }
        this.container = new FrameLayout(getContext());
        v vVar = new v(getContext(), this.state.f28260b, this.outerContext);
        View view = this.state.f28259a.getView();
        if (view.getContext() instanceof MutableContextWrapper) {
            ((MutableContextWrapper) view.getContext()).setBaseContext(vVar);
        }
        this.container.addView(view);
        t tVar = new t(getContext(), this.accessibilityEventsDelegate, view);
        this.rootView = tVar;
        tVar.addView(this.container);
        this.rootView.addView(this.state.f28261c);
        view.setOnFocusChangeListener(this.focusChangeListener);
        this.rootView.setFocusableInTouchMode(true);
        if (this.startFocused) {
            view.requestFocus();
        } else {
            this.rootView.requestFocus();
        }
        setContentView(this.rootView);
    }

    public SingleViewPresentation(Context context, Display display, a aVar, w wVar, View.OnFocusChangeListener onFocusChangeListener, boolean z10) {
        super(new u(context), display);
        this.startFocused = false;
        this.accessibilityEventsDelegate = aVar;
        this.state = wVar;
        this.focusChangeListener = onFocusChangeListener;
        this.outerContext = context;
        getWindow().setFlags(8, 8);
        this.startFocused = z10;
    }
}
