package androidx.appcompat.view.menu;

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

/* JADX INFO: compiled from: MenuPopupHelper.java */
/* JADX INFO: loaded from: classes.dex */
public class n {
    private final Context a;
    private final h b;
    private final boolean c;
    private final int d;
    private final int e;
    private View f;

    /* JADX INFO: renamed from: g, reason: collision with root package name */
    private int f96g;

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

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

    /* JADX INFO: renamed from: j, reason: collision with root package name */
    private m f99j;

    /* JADX INFO: renamed from: k, reason: collision with root package name */
    private PopupWindow.OnDismissListener f100k;

    /* JADX INFO: renamed from: l, reason: collision with root package name */
    private final PopupWindow.OnDismissListener f101l;

    /* 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 i2) {
        this(context, hVar, view, z, i2, 0);
    }

    private m a() {
        Display defaultDisplay = ((WindowManager) this.a.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.a.getResources().getDimensionPixelSize(g.a.d.abc_cascading_menus_min_smallest_width) ? new e(this.a, this.f, this.d, this.e, this.c) : new t(this.a, this.b, this.f, this.d, this.e, this.c);
        eVar.l(this.b);
        eVar.u(this.f101l);
        eVar.p(this.f);
        eVar.k(this.f98i);
        eVar.r(this.f97h);
        eVar.s(this.f96g);
        return eVar;
    }

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

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

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

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

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

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

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

    public void h(int i2) {
        this.f96g = i2;
    }

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

    public void j(o.a aVar) {
        this.f98i = aVar;
        m mVar = this.f99j;
        if (mVar != null) {
            mVar.k(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.f == null) {
            return false;
        }
        l(0, 0, false, false);
        return true;
    }

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

    public n(Context context, h hVar, View view, boolean z, int i2, int i3) {
        this.f96g = 8388611;
        this.f101l = new a();
        this.a = context;
        this.b = hVar;
        this.f = view;
        this.c = z;
        this.d = i2;
        this.e = i3;
    }
}
