package android.support.v7.view.menu;

import android.content.Context;
import android.graphics.Point;
import android.graphics.Rect;
import android.os.Build;
import android.support.v7.view.menu.o;
import android.view.Display;
import android.view.View;
import android.view.WindowManager;
import android.widget.PopupWindow;

/* JADX INFO: compiled from: MenuPopupHelper.java */
/* JADX INFO: loaded from: classes.dex */
public class n {

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    private final Context f908a;

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

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    private final boolean f910c;

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    private final int f911d;

    /* JADX INFO: renamed from: e, reason: collision with root package name */
    private final int f912e;

    /* JADX INFO: renamed from: f, reason: collision with root package name */
    private View f913f;
    private int g;
    private boolean h;
    private o.a i;
    private m j;
    private PopupWindow.OnDismissListener k;
    private final PopupWindow.OnDismissListener l;

    /* JADX INFO: compiled from: MenuPopupHelper.java */
    class a implements PopupWindow.OnDismissListener {
        a() {
        }

        @Override // android.widget.PopupWindow.OnDismissListener
        public void onDismiss() {
            n.this.e();
        }
    }

    public n(Context context, h hVar, View view, boolean z, int i) {
        this(context, hVar, view, z, i, 0);
    }

    private m a() {
        Display defaultDisplay = ((WindowManager) this.f908a.getSystemService("window")).getDefaultDisplay();
        Point point = new Point();
        if (Build.VERSION.SDK_INT >= 17) {
            defaultDisplay.getRealSize(point);
        } else {
            defaultDisplay.getSize(point);
        }
        m eVar = Math.min(point.x, point.y) >= this.f908a.getResources().getDimensionPixelSize(a.b.d.a.d.abc_cascading_menus_min_smallest_width) ? new e(this.f908a, this.f913f, this.f911d, this.f912e, this.f910c) : new t(this.f908a, this.f909b, this.f913f, this.f911d, this.f912e, this.f910c);
        eVar.l(this.f909b);
        eVar.u(this.l);
        eVar.p(this.f913f);
        eVar.f(this.i);
        eVar.r(this.h);
        eVar.s(this.g);
        return eVar;
    }

    private void l(int i, int i2, boolean z, boolean z2) {
        m mVarC = c();
        mVarC.v(z2);
        if (z) {
            if ((a.b.c.g.d.a(this.g, a.b.c.g.p.f(this.f913f)) & 7) == 5) {
                i -= this.f913f.getWidth();
            }
            mVarC.t(i);
            mVarC.w(i2);
            int i3 = (int) ((this.f908a.getResources().getDisplayMetrics().density * 48.0f) / 2.0f);
            mVarC.q(new Rect(i - i3, i2 - i3, i + i3, i2 + i3));
        }
        mVarC.c();
    }

    public void b() {
        if (d()) {
            this.j.dismiss();
        }
    }

    public m c() {
        if (this.j == null) {
            this.j = a();
        }
        return this.j;
    }

    public boolean d() {
        m mVar = this.j;
        return mVar != null && mVar.h();
    }

    protected void e() {
        this.j = null;
        PopupWindow.OnDismissListener onDismissListener = this.k;
        if (onDismissListener != null) {
            onDismissListener.onDismiss();
        }
    }

    public void f(View view) {
        this.f913f = view;
    }

    public void g(boolean z) {
        this.h = z;
        m mVar = this.j;
        if (mVar != null) {
            mVar.r(z);
        }
    }

    public void h(int i) {
        this.g = i;
    }

    public void i(PopupWindow.OnDismissListener onDismissListener) {
        this.k = onDismissListener;
    }

    public void j(o.a aVar) {
        this.i = aVar;
        m mVar = this.j;
        if (mVar != null) {
            mVar.f(aVar);
        }
    }

    public void k() {
        if (!m()) {
            throw new IllegalStateException("MenuPopupHelper cannot be used without an anchor");
        }
    }

    public boolean m() {
        if (d()) {
            return true;
        }
        if (this.f913f == null) {
            return false;
        }
        l(0, 0, false, false);
        return true;
    }

    public boolean n(int i, int i2) {
        if (d()) {
            return true;
        }
        if (this.f913f == null) {
            return false;
        }
        l(i, i2, true, true);
        return true;
    }

    public n(Context context, h hVar, View view, boolean z, int i, int i2) {
        this.g = 8388611;
        this.l = new a();
        this.f908a = context;
        this.f909b = hVar;
        this.f913f = view;
        this.f910c = z;
        this.f911d = i;
        this.f912e = i2;
    }
}
