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.m;

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

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

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

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

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

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

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

    /* JADX INFO: renamed from: g, reason: collision with root package name */
    private int f448g;
    private boolean h;
    private m.a i;
    private k 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() {
            l.this.e();
        }
    }

    public l(Context context, g gVar, View view, boolean z, int i) {
        this(context, gVar, view, z, i, 0);
    }

    private k a() {
        Display defaultDisplay = ((WindowManager) this.f442a.getSystemService("window")).getDefaultDisplay();
        Point point = new Point();
        if (Build.VERSION.SDK_INT >= 17) {
            defaultDisplay.getRealSize(point);
        } else {
            defaultDisplay.getSize(point);
        }
        k eVar = Math.min(point.x, point.y) >= this.f442a.getResources().getDimensionPixelSize(a.a.d.f16c) ? new e(this.f442a, this.f447f, this.f445d, this.f446e, this.f444c) : new r(this.f442a, this.f443b, this.f447f, this.f445d, this.f446e, this.f444c);
        eVar.m(this.f443b);
        eVar.v(this.l);
        eVar.q(this.f447f);
        eVar.g(this.i);
        eVar.s(this.h);
        eVar.t(this.f448g);
        return eVar;
    }

    private void l(int i, int i2, boolean z, boolean z2) {
        k kVarC = c();
        kVarC.w(z2);
        if (z) {
            if ((a.c.i.c.a(this.f448g, a.c.i.l.c(this.f447f)) & 7) == 5) {
                i -= this.f447f.getWidth();
            }
            kVarC.u(i);
            kVarC.x(i2);
            int i3 = (int) ((this.f442a.getResources().getDisplayMetrics().density * 48.0f) / 2.0f);
            kVarC.r(new Rect(i - i3, i2 - i3, i + i3, i2 + i3));
        }
        kVarC.h();
    }

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

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

    public boolean d() {
        k kVar = this.j;
        return kVar != null && kVar.e();
    }

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

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

    public void g(boolean z) {
        this.h = z;
        k kVar = this.j;
        if (kVar != null) {
            kVar.s(z);
        }
    }

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

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

    public void j(m.a aVar) {
        this.i = aVar;
        k kVar = this.j;
        if (kVar != null) {
            kVar.g(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.f447f == null) {
            return false;
        }
        l(0, 0, false, false);
        return true;
    }

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

    public l(Context context, g gVar, View view, boolean z, int i, int i2) {
        this.f448g = 8388611;
        this.l = new a();
        this.f442a = context;
        this.f443b = gVar;
        this.f447f = view;
        this.f444c = z;
        this.f445d = i;
        this.f446e = i2;
    }
}
