package androidx.core.view;

import android.R;
import android.os.Build;
import android.view.View;
import android.view.WindowInsets;
import android.view.WindowInsetsController;
import android.view.inputmethod.InputMethodManager;
import androidx.core.view.n0;
import java.util.concurrent.atomic.AtomicBoolean;

/* loaded from: classes.dex */
public final class n0 {

    /* renamed from: a, reason: collision with root package name */
    private final c f3883a;

    /* loaded from: classes.dex */
    private static class a extends c {

        /* renamed from: a, reason: collision with root package name */
        private final View f3884a;

        a(View view) {
            this.f3884a = view;
        }

        /* JADX INFO: Access modifiers changed from: private */
        public static /* synthetic */ void d(View view) {
            ((InputMethodManager) view.getContext().getSystemService("input_method")).showSoftInput(view, 0);
        }

        @Override // androidx.core.view.n0.c
        void a() {
            View view = this.f3884a;
            if (view != null) {
                ((InputMethodManager) view.getContext().getSystemService("input_method")).hideSoftInputFromWindow(this.f3884a.getWindowToken(), 0);
            }
        }

        @Override // androidx.core.view.n0.c
        void b() {
            final View view = this.f3884a;
            if (view == null) {
                return;
            }
            if (view.isInEditMode() || view.onCheckIsTextEditor()) {
                view.requestFocus();
            } else {
                view = view.getRootView().findFocus();
            }
            if (view == null) {
                view = this.f3884a.getRootView().findViewById(R.id.content);
            }
            if (view == null || !view.hasWindowFocus()) {
                return;
            }
            view.post(new Runnable() { // from class: androidx.core.view.m0
                @Override // java.lang.Runnable
                public final void run() {
                    n0.a.d(view);
                }
            });
        }
    }

    /* loaded from: classes.dex */
    private static class b extends a {

        /* renamed from: b, reason: collision with root package name */
        private View f3885b;

        /* renamed from: c, reason: collision with root package name */
        private WindowInsetsController f3886c;

        b(View view) {
            super(view);
            this.f3885b = view;
        }

        /* JADX INFO: Access modifiers changed from: private */
        public static /* synthetic */ void f(AtomicBoolean atomicBoolean, WindowInsetsController windowInsetsController, int i10) {
            atomicBoolean.set((i10 & 8) != 0);
        }

        @Override // androidx.core.view.n0.a, androidx.core.view.n0.c
        void a() {
            View view;
            WindowInsetsController windowInsetsController = this.f3886c;
            if (windowInsetsController == null) {
                View view2 = this.f3885b;
                windowInsetsController = view2 != null ? view2.getWindowInsetsController() : null;
            }
            if (windowInsetsController == null) {
                super.a();
                return;
            }
            final AtomicBoolean atomicBoolean = new AtomicBoolean(false);
            WindowInsetsController.OnControllableInsetsChangedListener onControllableInsetsChangedListener = new WindowInsetsController.OnControllableInsetsChangedListener() { // from class: androidx.core.view.o0
                @Override // android.view.WindowInsetsController.OnControllableInsetsChangedListener
                public final void onControllableInsetsChanged(WindowInsetsController windowInsetsController2, int i10) {
                    n0.b.f(atomicBoolean, windowInsetsController2, i10);
                }
            };
            windowInsetsController.addOnControllableInsetsChangedListener(onControllableInsetsChangedListener);
            if (!atomicBoolean.get() && (view = this.f3885b) != null) {
                ((InputMethodManager) view.getContext().getSystemService("input_method")).hideSoftInputFromWindow(this.f3885b.getWindowToken(), 0);
            }
            windowInsetsController.removeOnControllableInsetsChangedListener(onControllableInsetsChangedListener);
            windowInsetsController.hide(WindowInsets.Type.ime());
        }

        @Override // androidx.core.view.n0.a, androidx.core.view.n0.c
        void b() {
            View view = this.f3885b;
            if (view != null && Build.VERSION.SDK_INT < 33) {
                ((InputMethodManager) view.getContext().getSystemService("input_method")).isActive();
            }
            WindowInsetsController windowInsetsController = this.f3886c;
            if (windowInsetsController == null) {
                View view2 = this.f3885b;
                windowInsetsController = view2 != null ? view2.getWindowInsetsController() : null;
            }
            if (windowInsetsController != null) {
                windowInsetsController.show(WindowInsets.Type.ime());
            }
            super.b();
        }
    }

    /* loaded from: classes.dex */
    private static class c {
        c() {
        }

        abstract void a();

        abstract void b();
    }

    public n0(View view) {
        this.f3883a = new b(view);
    }

    public void a() {
        this.f3883a.a();
    }

    public void b() {
        this.f3883a.b();
    }
}
