package o; import android.content.Context; import android.content.res.Resources; import android.os.Parcelable; import android.view.Gravity; import android.view.KeyEvent; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.view.ViewTreeObserver; import android.widget.AdapterView; import android.widget.FrameLayout; import android.widget.ListView; import android.widget.PopupWindow; import android.widget.TextView; import androidx.appcompat.widget.MenuPopupWindow; import androidx.core.view.ViewCompat; import java.lang.ref.WeakReference; import o.InterfaceC15933jjG; import o.SYO; /* loaded from: classes.dex */ final class ZeI extends WpL implements PopupWindow.OnDismissListener, AdapterView.OnItemClickListener, View.OnKeyListener { private static final int d = SYO.ojQ.abc_popup_menu_item_layout; final MenuPopupWindow a; View c; ViewTreeObserver e; private View g; private int i; private final C5263bpj j; private PopupWindow.OnDismissListener k; private final Context m; private boolean n; /* renamed from: o, reason: collision with root package name */ private final NoP f8484o; private final int p; private InterfaceC15933jjG.Sts q; private final int r; private final boolean s; private final int t; private boolean v; private boolean w; final ViewTreeObserver.OnGlobalLayoutListener b = new ViewTreeObserver.OnGlobalLayoutListener(this) { // from class: o.ZeI.3 final ZeI a; { this.a = this; } @Override // android.view.ViewTreeObserver.OnGlobalLayoutListener public final void onGlobalLayout() { if (!this.a.j() || this.a.a.t()) { return; } View view = this.a.c; if (view == null || !view.isShown()) { this.a.b(); } else { this.a.a.h(); } } }; private final View.OnAttachStateChangeListener f = new View.OnAttachStateChangeListener(this) { // from class: o.ZeI.1 final ZeI d; @Override // android.view.View.OnAttachStateChangeListener public final void onViewAttachedToWindow(View view) { } { this.d = this; } @Override // android.view.View.OnAttachStateChangeListener public final void onViewDetachedFromWindow(View view) { if (this.d.e != null) { if (!this.d.e.isAlive()) { this.d.e = view.getViewTreeObserver(); } this.d.e.removeGlobalOnLayoutListener(this.d.b); } view.removeOnAttachStateChangeListener(this); } }; private int l = 0; @Override // o.InterfaceC15933jjG public final void Km_(Parcelable parcelable) { } @Override // o.InterfaceC15933jjG public final Parcelable Kn_() { return null; } @Override // o.WpL public final void b(NoP noP) { } @Override // o.InterfaceC15933jjG public final boolean e() { return false; } public ZeI(Context context, NoP noP, View view, int i, int i2, boolean z) { this.m = context; this.f8484o = noP; this.s = z; this.j = new C5263bpj(noP, LayoutInflater.from(context), z, d); this.p = i; this.t = i2; Resources resources = context.getResources(); this.r = Math.max(resources.getDisplayMetrics().widthPixels / 2, resources.getDimensionPixelSize(SYO.Sts.abc_config_prefDialogWidth)); this.g = view; this.a = new MenuPopupWindow(context, i, i2); noP.r.add(new WeakReference<>(this)); a(context, noP); noP.f = true; } @Override // o.AZJ public final void b() { if (j()) { this.a.b(); } } @Override // o.AZJ public final boolean j() { return !this.w && this.a.j(); } @Override // android.widget.PopupWindow.OnDismissListener public final void onDismiss() { this.w = true; this.f8484o.close(); ViewTreeObserver viewTreeObserver = this.e; if (viewTreeObserver != null) { if (!viewTreeObserver.isAlive()) { this.e = this.c.getViewTreeObserver(); } this.e.removeGlobalOnLayoutListener(this.b); this.e = null; } this.c.removeOnAttachStateChangeListener(this.f); PopupWindow.OnDismissListener onDismissListener = this.k; if (onDismissListener != null) { onDismissListener.onDismiss(); } } @Override // o.InterfaceC15933jjG public final void a(boolean z) { this.n = false; C5263bpj c5263bpj = this.j; if (c5263bpj != null) { c5263bpj.notifyDataSetChanged(); } } @Override // o.InterfaceC15933jjG public final boolean d(SubMenuC16744qqn subMenuC16744qqn) { if (subMenuC16744qqn.hasVisibleItems()) { C16108lLe c16108lLe = new C16108lLe(this.m, subMenuC16744qqn, this.c, this.s, this.p, this.t); InterfaceC15933jjG.Sts sts = this.q; c16108lLe.h = sts; WpL wpL = c16108lLe.e; if (wpL != null) { wpL.c(sts); } boolean e = WpL.e(subMenuC16744qqn); c16108lLe.d = e; WpL wpL2 = c16108lLe.e; if (wpL2 != null) { wpL2.c(e); } c16108lLe.c = this.k; this.k = null; this.f8484o.b(false); int d2 = this.a.d(); int e2 = this.a.e(); if ((Gravity.getAbsoluteGravity(this.l, ViewCompat.m(this.g)) & 7) == 5) { d2 += this.g.getWidth(); } WpL wpL3 = c16108lLe.e; if (wpL3 == null || !wpL3.j()) { if (c16108lLe.b != null) { c16108lLe.a(d2, e2, true, true); } } InterfaceC15933jjG.Sts sts2 = this.q; if (sts2 != null) { sts2.d(subMenuC16744qqn); } return true; } return false; } @Override // o.InterfaceC15933jjG public final void b(NoP noP, boolean z) { if (noP != this.f8484o) { return; } b(); InterfaceC15933jjG.Sts sts = this.q; if (sts != null) { sts.e(noP, z); } } @Override // android.view.View.OnKeyListener public final boolean onKey(View view, int i, KeyEvent keyEvent) { if (keyEvent.getAction() != 1 || i != 82) { return false; } b(); return true; } @Override // o.AZJ public final ListView it_() { return this.a.it_(); } @Override // o.WpL public final void e(int i) { this.a.e(i); } @Override // o.WpL public final void c(int i) { this.a.c(i); } @Override // o.WpL public final void c(boolean z) { this.j.c = z; } @Override // o.AZJ public final void h() { View view; if (j()) { return; } if (this.w || (view = this.g) == null) { throw new IllegalStateException("StandardMenuPopup cannot be used without an anchor"); } this.c = view; this.a.ix_(this); this.a.iy_(this); this.a.c(true); View view2 = this.c; boolean z = this.e == null; ViewTreeObserver viewTreeObserver = view2.getViewTreeObserver(); this.e = viewTreeObserver; if (z) { viewTreeObserver.addOnGlobalLayoutListener(this.b); } view2.addOnAttachStateChangeListener(this.f); this.a.e(view2); this.a.h(this.l); if (!this.n) { this.i = eU_(this.j, this.m, this.r); this.n = true; } this.a.a(this.i); this.a.i(2); this.a.iw_(this.h); this.a.h(); ListView it_ = this.a.it_(); it_.setOnKeyListener(this); if (this.v && this.f8484o.j != null) { FrameLayout frameLayout = (FrameLayout) LayoutInflater.from(this.m).inflate(SYO.ojQ.abc_popup_menu_header_item_layout, (ViewGroup) it_, false); TextView textView = (TextView) frameLayout.findViewById(android.R.id.title); if (textView != null) { textView.setText(this.f8484o.j); } frameLayout.setEnabled(false); it_.addHeaderView(frameLayout, null, false); } this.a.iu_(this.j); this.a.h(); } @Override // o.WpL public final void e(boolean z) { this.v = z; } @Override // o.WpL public final void fd_(PopupWindow.OnDismissListener onDismissListener) { this.k = onDismissListener; } @Override // o.WpL public final void b(int i) { this.l = i; } @Override // o.InterfaceC15933jjG public final void c(InterfaceC15933jjG.Sts sts) { this.q = sts; } @Override // o.WpL public final void a(View view) { this.g = view; } }