package o;

import android.view.ActionMode;
import android.view.KeyEvent;
import android.view.Menu;
import android.view.MenuItem;
import android.view.MotionEvent;
import android.view.SearchEvent;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.view.accessibility.AccessibilityEvent;
import java.lang.reflect.InvocationTargetException;
import java.util.List;

/* compiled from: r8-map-id-3b7cc9102578c509342fa2f0fabed2bfc72239cd258d579fc679bfcbc198b048 */
/* loaded from: classes.dex */
public final class N7 implements Window.Callback {
    public final Window.Callback l;
    public Sf0 m;
    public boolean n;

    /* renamed from: o, reason: collision with root package name */
    public boolean f251o;
    public boolean p;
    public final /* synthetic */ S7 q;

    public N7(S7 s7, Window.Callback callback) {
        this.q = s7;
        if (callback == null) {
            throw new IllegalArgumentException("Window callback may not be null");
        }
        this.l = callback;
    }

    public final void a(Window.Callback callback) {
        try {
            this.n = true;
            callback.onContentChanged();
        } finally {
            this.n = false;
        }
    }

    public final boolean b(int i, Menu menu) {
        return this.l.onMenuOpened(i, menu);
    }

    public final void c(int i, Menu menu) {
        this.l.onPanelClosed(i, menu);
    }

    public final void d(List list, Menu menu, int i) {
        AbstractC1127el0.a(this.l, list, menu, i);
    }

    @Override // android.view.Window.Callback
    public final boolean dispatchGenericMotionEvent(MotionEvent motionEvent) {
        return this.l.dispatchGenericMotionEvent(motionEvent);
    }

    @Override // android.view.Window.Callback
    public final boolean dispatchKeyEvent(KeyEvent keyEvent) {
        boolean z = this.f251o;
        Window.Callback callback = this.l;
        return z ? callback.dispatchKeyEvent(keyEvent) : this.q.u(keyEvent) || callback.dispatchKeyEvent(keyEvent);
    }

    @Override // android.view.Window.Callback
    public final boolean dispatchKeyShortcutEvent(KeyEvent keyEvent) throws IllegalAccessException, NoSuchMethodException, SecurityException, IllegalArgumentException, InvocationTargetException {
        if (!this.l.dispatchKeyShortcutEvent(keyEvent)) {
            int keyCode = keyEvent.getKeyCode();
            S7 s7 = this.q;
            s7.A();
            T0 t0 = s7.z;
            if (t0 == null || !t0.i(keyCode, keyEvent)) {
                R7 r7 = s7.X;
                if (r7 == null || !s7.F(r7, keyEvent.getKeyCode(), keyEvent)) {
                    if (s7.X == null) {
                        R7 r7Z = s7.z(0);
                        s7.G(r7Z, keyEvent);
                        boolean zF = s7.F(r7Z, keyEvent.getKeyCode(), keyEvent);
                        r7Z.k = false;
                        if (zF) {
                        }
                    }
                    return false;
                }
                R7 r72 = s7.X;
                if (r72 != null) {
                    r72.l = true;
                    return true;
                }
            }
        }
        return true;
    }

    @Override // android.view.Window.Callback
    public final boolean dispatchPopulateAccessibilityEvent(AccessibilityEvent accessibilityEvent) {
        return this.l.dispatchPopulateAccessibilityEvent(accessibilityEvent);
    }

    @Override // android.view.Window.Callback
    public final boolean dispatchTouchEvent(MotionEvent motionEvent) {
        return this.l.dispatchTouchEvent(motionEvent);
    }

    @Override // android.view.Window.Callback
    public final boolean dispatchTrackballEvent(MotionEvent motionEvent) {
        return this.l.dispatchTrackballEvent(motionEvent);
    }

    @Override // android.view.Window.Callback
    public final void onActionModeFinished(ActionMode actionMode) {
        this.l.onActionModeFinished(actionMode);
    }

    @Override // android.view.Window.Callback
    public final void onActionModeStarted(ActionMode actionMode) {
        this.l.onActionModeStarted(actionMode);
    }

    @Override // android.view.Window.Callback
    public final void onAttachedToWindow() {
        this.l.onAttachedToWindow();
    }

    @Override // android.view.Window.Callback
    public final void onContentChanged() {
        if (this.n) {
            this.l.onContentChanged();
        }
    }

    @Override // android.view.Window.Callback
    public final boolean onCreatePanelMenu(int i, Menu menu) {
        if (i != 0 || (menu instanceof CO)) {
            return this.l.onCreatePanelMenu(i, menu);
        }
        return false;
    }

    @Override // android.view.Window.Callback
    public final View onCreatePanelView(int i) {
        Sf0 sf0 = this.m;
        if (sf0 != null) {
            View view = i == 0 ? new View(sf0.l.a.a.getContext()) : null;
            if (view != null) {
                return view;
            }
        }
        return this.l.onCreatePanelView(i);
    }

    @Override // android.view.Window.Callback
    public final void onDetachedFromWindow() {
        this.l.onDetachedFromWindow();
    }

    @Override // android.view.Window.Callback
    public final boolean onMenuItemSelected(int i, MenuItem menuItem) {
        return this.l.onMenuItemSelected(i, menuItem);
    }

    @Override // android.view.Window.Callback
    public final boolean onMenuOpened(int i, Menu menu) throws IllegalAccessException, NoSuchMethodException, SecurityException, IllegalArgumentException, InvocationTargetException {
        b(i, menu);
        S7 s7 = this.q;
        if (i == 108) {
            s7.A();
            T0 t0 = s7.z;
            if (t0 != null) {
                t0.c(true);
            }
        } else {
            s7.getClass();
        }
        return true;
    }

    @Override // android.view.Window.Callback
    public final void onPanelClosed(int i, Menu menu) throws IllegalAccessException, NoSuchMethodException, SecurityException, IllegalArgumentException, InvocationTargetException {
        if (this.p) {
            this.l.onPanelClosed(i, menu);
            return;
        }
        c(i, menu);
        S7 s7 = this.q;
        if (i == 108) {
            s7.A();
            T0 t0 = s7.z;
            if (t0 != null) {
                t0.c(false);
                return;
            }
            return;
        }
        if (i == 0) {
            R7 r7Z = s7.z(i);
            if (r7Z.m) {
                s7.r(r7Z, false);
            }
        }
    }

    @Override // android.view.Window.Callback
    public final void onPointerCaptureChanged(boolean z) {
        AbstractC1223fl0.a(this.l, z);
    }

    @Override // android.view.Window.Callback
    public final boolean onPreparePanel(int i, View view, Menu menu) {
        CO co = menu instanceof CO ? (CO) menu : null;
        if (i == 0 && co == null) {
            return false;
        }
        if (co != null) {
            co.x = true;
        }
        Sf0 sf0 = this.m;
        if (sf0 != null && i == 0) {
            Tf0 tf0 = sf0.l;
            if (!tf0.d) {
                tf0.a.l = true;
                tf0.d = true;
            }
        }
        boolean zOnPreparePanel = this.l.onPreparePanel(i, view, menu);
        if (co != null) {
            co.x = false;
        }
        return zOnPreparePanel;
    }

    @Override // android.view.Window.Callback
    public final void onProvideKeyboardShortcuts(List list, Menu menu, int i) {
        CO co = this.q.z(0).h;
        if (co != null) {
            d(list, co, i);
        } else {
            d(list, menu, i);
        }
    }

    @Override // android.view.Window.Callback
    public final boolean onSearchRequested(SearchEvent searchEvent) {
        return AbstractC1032dl0.a(this.l, searchEvent);
    }

    @Override // android.view.Window.Callback
    public final void onWindowAttributesChanged(WindowManager.LayoutParams layoutParams) {
        this.l.onWindowAttributesChanged(layoutParams);
    }

    @Override // android.view.Window.Callback
    public final void onWindowFocusChanged(boolean z) {
        this.l.onWindowFocusChanged(z);
    }

    @Override // android.view.Window.Callback
    public final ActionMode onWindowStartingActionMode(ActionMode.Callback callback, int i) throws IllegalAccessException, NoSuchMethodException, SecurityException, IllegalArgumentException, InvocationTargetException {
        if (i != 0) {
            return AbstractC1032dl0.b(this.l, callback, i);
        }
        S7 s7 = this.q;
        S60 s60 = new S60(s7.v, callback);
        AbstractC1918n1 abstractC1918n1K = s7.k(s60);
        if (abstractC1918n1K != null) {
            return s60.f(abstractC1918n1K);
        }
        return null;
    }

    @Override // android.view.Window.Callback
    public final boolean onSearchRequested() {
        return this.l.onSearchRequested();
    }

    @Override // android.view.Window.Callback
    public final ActionMode onWindowStartingActionMode(ActionMode.Callback callback) {
        return null;
    }
}
