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;

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

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

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

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

    /* JADX INFO: renamed from: f, reason: collision with root package name */
    private View f271f;

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

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

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

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

    /* JADX INFO: renamed from: k, reason: collision with root package name */
    private PopupWindow.OnDismissListener f276k;
    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 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(c.a.d.abc_cascading_menus_min_smallest_width) ? new e(this.a, this.f271f, this.f269d, this.f270e, this.f268c) : new t(this.a, this.f267b, this.f271f, this.f269d, this.f270e, this.f268c);
        eVar.l(this.f267b);
        eVar.u(this.l);
        eVar.p(this.f271f);
        eVar.k(this.f274i);
        eVar.r(this.f273h);
        eVar.s(this.f272g);
        return eVar;
    }

    private void l(int i2, int i3, boolean z, boolean z2) {
        m mVarC = c();
        mVarC.v(z2);
        if (z) {
            if ((c.f.l.d.b(this.f272g, c.f.l.t.u(this.f271f)) & 7) == 5) {
                i2 -= this.f271f.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.f275j.dismiss();
        }
    }

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

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

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

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

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

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

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

    public void j(o.a aVar) {
        this.f274i = aVar;
        m mVar = this.f275j;
        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.f271f == null) {
            return false;
        }
        l(0, 0, false, false);
        return true;
    }

    public boolean n(int i2, int i3) {
        if (d()) {
            return true;
        }
        if (this.f271f == 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.f272g = 8388611;
        this.l = new a();
        this.a = context;
        this.f267b = hVar;
        this.f271f = view;
        this.f268c = z;
        this.f269d = i2;
        this.f270e = i3;
    }
}
