package d.b.f.i;

import android.content.DialogInterface;
import android.view.KeyEvent;
import android.view.View;
import android.view.Window;
import d.b.f.i.e;
import d.b.f.i.m;

/* JADX INFO: loaded from: classes.dex */
public class h implements DialogInterface.OnKeyListener, DialogInterface.OnClickListener, DialogInterface.OnDismissListener, m.a {

    /* JADX INFO: renamed from: f, reason: collision with root package name */
    public g f1811f;

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

    /* JADX INFO: renamed from: n, reason: collision with root package name */
    public e f1813n;

    public h(g gVar) {
        this.f1811f = gVar;
    }

    @Override // d.b.f.i.m.a
    public void b(g gVar, boolean z2) {
        d.b.c.e eVar;
        if ((z2 || gVar == this.f1811f) && (eVar = this.f1812m) != null) {
            eVar.dismiss();
        }
    }

    @Override // d.b.f.i.m.a
    public boolean c(g gVar) {
        return false;
    }

    @Override // android.content.DialogInterface.OnClickListener
    public void onClick(DialogInterface dialogInterface, int i2) {
        this.f1811f.r(((e.a) this.f1813n.a()).getItem(i2), 0);
    }

    @Override // android.content.DialogInterface.OnDismissListener
    public void onDismiss(DialogInterface dialogInterface) {
        e eVar = this.f1813n;
        g gVar = this.f1811f;
        m.a aVar = eVar.f1777p;
        if (aVar != null) {
            aVar.b(gVar, true);
        }
    }

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