package android.support.v7.view.menu;

import android.content.DialogInterface;
import android.os.IBinder;
import android.support.v7.app.b;
import android.support.v7.view.menu.o;
import android.view.KeyEvent;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;

/* JADX INFO: compiled from: MenuDialogHelper.java */
/* JADX INFO: loaded from: classes.dex */
class i implements DialogInterface.OnKeyListener, DialogInterface.OnClickListener, DialogInterface.OnDismissListener, o.a {

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    private h f889b;

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    private android.support.v7.app.b f890c;

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    f f891d;

    /* JADX INFO: renamed from: e, reason: collision with root package name */
    private o.a f892e;

    public i(h hVar) {
        this.f889b = hVar;
    }

    @Override // android.support.v7.view.menu.o.a
    public void a(h hVar, boolean z) {
        if (z || hVar == this.f889b) {
            c();
        }
        o.a aVar = this.f892e;
        if (aVar != null) {
            aVar.a(hVar, z);
        }
    }

    @Override // android.support.v7.view.menu.o.a
    public boolean b(h hVar) {
        o.a aVar = this.f892e;
        if (aVar != null) {
            return aVar.b(hVar);
        }
        return false;
    }

    public void c() {
        android.support.v7.app.b bVar = this.f890c;
        if (bVar != null) {
            bVar.dismiss();
        }
    }

    public void d(IBinder iBinder) {
        h hVar = this.f889b;
        b.a aVar = new b.a(hVar.u());
        f fVar = new f(aVar.b(), a.b.d.a.g.abc_list_menu_item_layout);
        this.f891d = fVar;
        fVar.f(this);
        this.f889b.b(this.f891d);
        aVar.c(this.f891d.c(), this);
        View viewY = hVar.y();
        if (viewY != null) {
            aVar.d(viewY);
        } else {
            aVar.e(hVar.w());
            aVar.g(hVar.x());
        }
        aVar.f(this);
        android.support.v7.app.b bVarA = aVar.a();
        this.f890c = bVarA;
        bVarA.setOnDismissListener(this);
        WindowManager.LayoutParams attributes = this.f890c.getWindow().getAttributes();
        attributes.type = 1003;
        if (iBinder != null) {
            attributes.token = iBinder;
        }
        attributes.flags |= 131072;
        this.f890c.show();
    }

    @Override // android.content.DialogInterface.OnClickListener
    public void onClick(DialogInterface dialogInterface, int i) {
        this.f889b.L((j) this.f891d.c().getItem(i), 0);
    }

    @Override // android.content.DialogInterface.OnDismissListener
    public void onDismiss(DialogInterface dialogInterface) {
        this.f891d.a(this.f889b, true);
    }

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