package androidx.appcompat.view.menu;

import android.content.DialogInterface;
import android.os.IBinder;
import android.view.KeyEvent;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import androidx.appcompat.app.a;
import androidx.appcompat.view.menu.j;

/* loaded from: classes.dex */
class f implements DialogInterface.OnKeyListener, DialogInterface.OnClickListener, DialogInterface.OnDismissListener, j.a {

    /* renamed from: p, reason: collision with root package name */
    private e f734p;

    /* renamed from: q, reason: collision with root package name */
    private androidx.appcompat.app.a f735q;

    /* renamed from: r, reason: collision with root package name */
    c f736r;

    /* renamed from: s, reason: collision with root package name */
    private j.a f737s;

    public f(e eVar) {
        this.f734p = eVar;
    }

    public void a() {
        androidx.appcompat.app.a aVar = this.f735q;
        if (aVar != null) {
            aVar.dismiss();
        }
    }

    @Override // androidx.appcompat.view.menu.j.a
    public void b(e eVar, boolean z10) {
        if (z10 || eVar == this.f734p) {
            a();
        }
        j.a aVar = this.f737s;
        if (aVar != null) {
            aVar.b(eVar, z10);
        }
    }

    @Override // androidx.appcompat.view.menu.j.a
    public boolean c(e eVar) {
        j.a aVar = this.f737s;
        if (aVar != null) {
            return aVar.c(eVar);
        }
        return false;
    }

    public void d(IBinder iBinder) {
        e eVar = this.f734p;
        a.C0023a c0023a = new a.C0023a(eVar.w());
        c cVar = new c(c0023a.b(), h.g.f20252j);
        this.f736r = cVar;
        cVar.h(this);
        this.f734p.b(this.f736r);
        c0023a.c(this.f736r.a(), this);
        View A = eVar.A();
        if (A != null) {
            c0023a.e(A);
        } else {
            c0023a.f(eVar.y()).p(eVar.z());
        }
        c0023a.l(this);
        androidx.appcompat.app.a a10 = c0023a.a();
        this.f735q = a10;
        a10.setOnDismissListener(this);
        WindowManager.LayoutParams attributes = this.f735q.getWindow().getAttributes();
        attributes.type = 1003;
        if (iBinder != null) {
            attributes.token = iBinder;
        }
        attributes.flags |= 131072;
        this.f735q.show();
    }

    @Override // android.content.DialogInterface.OnClickListener
    public void onClick(DialogInterface dialogInterface, int i10) {
        this.f734p.N((g) this.f736r.a().getItem(i10), 0);
    }

    @Override // android.content.DialogInterface.OnDismissListener
    public void onDismiss(DialogInterface dialogInterface) {
        this.f736r.b(this.f734p, true);
    }

    @Override // android.content.DialogInterface.OnKeyListener
    public boolean onKey(DialogInterface dialogInterface, int i10, KeyEvent keyEvent) {
        Window window;
        View decorView;
        KeyEvent.DispatcherState keyDispatcherState;
        View decorView2;
        KeyEvent.DispatcherState keyDispatcherState2;
        if (i10 == 82 || i10 == 4) {
            if (keyEvent.getAction() == 0 && keyEvent.getRepeatCount() == 0) {
                Window window2 = this.f735q.getWindow();
                if (window2 != null && (decorView2 = window2.getDecorView()) != null && (keyDispatcherState2 = decorView2.getKeyDispatcherState()) != null) {
                    keyDispatcherState2.startTracking(keyEvent, this);
                    return true;
                }
            } else if (keyEvent.getAction() == 1 && !keyEvent.isCanceled() && (window = this.f735q.getWindow()) != null && (decorView = window.getDecorView()) != null && (keyDispatcherState = decorView.getKeyDispatcherState()) != null && keyDispatcherState.isTracking(keyEvent)) {
                this.f734p.e(true);
                dialogInterface.dismiss();
                return true;
            }
        }
        return this.f734p.performShortcut(i10, keyEvent, 0);
    }
}
