package k;

import android.content.DialogInterface;
import android.view.KeyEvent;
import android.view.View;
import android.view.Window;

/* JADX INFO: loaded from: classes.dex */
public final class q implements DialogInterface.OnKeyListener, DialogInterface.OnClickListener, DialogInterface.OnDismissListener, a0 {

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    public p f28905a;

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    public e.m f28906b;

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    public l f28907c;

    @Override // k.a0
    public final boolean e(p pVar) {
        return false;
    }

    @Override // android.content.DialogInterface.OnClickListener
    public final void onClick(DialogInterface dialogInterface, int i10) {
        l lVar = this.f28907c;
        if (lVar.f28872g == null) {
            lVar.f28872g = new k(lVar);
        }
        this.f28905a.q(lVar.f28872g.getItem(i10), null, 0);
    }

    @Override // k.a0
    public final void onCloseMenu(p pVar, boolean z10) {
        e.m mVar;
        if ((z10 || pVar == this.f28905a) && (mVar = this.f28906b) != null) {
            mVar.dismiss();
        }
    }

    @Override // android.content.DialogInterface.OnDismissListener
    public final void onDismiss(DialogInterface dialogInterface) {
        this.f28907c.onCloseMenu(this.f28905a, true);
    }

    @Override // android.content.DialogInterface.OnKeyListener
    public final boolean onKey(DialogInterface dialogInterface, int i10, KeyEvent keyEvent) {
        Window window;
        View decorView;
        KeyEvent.DispatcherState keyDispatcherState;
        View decorView2;
        KeyEvent.DispatcherState keyDispatcherState2;
        p pVar = this.f28905a;
        if (i10 == 82 || i10 == 4) {
            if (keyEvent.getAction() == 0 && keyEvent.getRepeatCount() == 0) {
                Window window2 = this.f28906b.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.f28906b.getWindow()) != null && (decorView = window.getDecorView()) != null && (keyDispatcherState = decorView.getKeyDispatcherState()) != null && keyDispatcherState.isTracking(keyEvent)) {
                pVar.c(true);
                dialogInterface.dismiss();
                return true;
            }
        }
        return pVar.performShortcut(i10, keyEvent, 0);
    }
}
