package androidx.appcompat.widget; import android.content.Context; import android.content.res.Resources; import android.graphics.drawable.Drawable; import android.os.Parcel; import android.os.Parcelable; import android.util.SparseBooleanArray; import android.view.MenuItem; import android.view.View; import android.view.ViewGroup; import androidx.appcompat.view.menu.ActionMenuItemView; import androidx.appcompat.view.menu.MenuItemImpl; import androidx.appcompat.widget.ActionMenuView; import java.util.ArrayList; import o.AZJ; import o.AuZ; import o.C16108lLe; import o.C6286cOZ; import o.FzA; import o.InterfaceC15933jjG; import o.NoP; import o.SYO; import o.SubMenuC16744qqn; import o.Sya; import o.Tlu; import o.WpL; import o.hbU; import o.nHL; /* loaded from: classes.dex */ public class ActionMenuPresenter extends FzA implements hbU.LWm { private boolean D; boolean f; boolean h; int i; public HBt j; boolean k; RVV l; Drawable m; OverflowMenuButton n; /* renamed from: o, reason: collision with root package name */ int f6373o; boolean p; private final SparseBooleanArray q; boolean r; public Sts s; final IeS t; private LWm u; private int v; private int w; private boolean x; private int y; public ActionMenuPresenter(Context context) { super(context, SYO.ojQ.abc_action_menu_layout, SYO.ojQ.abc_action_menu_item_layout); this.q = new SparseBooleanArray(); this.t = new IeS(this); } @Override // o.FzA, o.InterfaceC15933jjG public final void a(Context context, NoP noP) { super.a(context, noP); Resources resources = context.getResources(); AuZ auZ = new AuZ(context); if (!this.p) { this.r = true; } this.v = auZ.c.getResources().getDisplayMetrics().widthPixels / 2; this.i = auZ.d(); int i = this.v; if (this.r) { if (this.n == null) { OverflowMenuButton overflowMenuButton = new OverflowMenuButton(this, this.g); this.n = overflowMenuButton; if (this.k) { overflowMenuButton.setImageDrawable(this.m); this.m = null; this.k = false; } int makeMeasureSpec = View.MeasureSpec.makeMeasureSpec(0, 0); this.n.measure(makeMeasureSpec, makeMeasureSpec); } i -= this.n.getMeasuredWidth(); } else { this.n = null; } this.y = i; this.w = (int) (resources.getDisplayMetrics().density * 56.0f); } @Override // o.FzA public final Sya fj_(ViewGroup viewGroup) { Sya sya = this.b; Sya fj_ = super.fj_(viewGroup); if (sya != fj_) { ((ActionMenuView) fj_).setPresenter(this); } return fj_; } @Override // o.FzA public final View fi_(MenuItemImpl menuItemImpl, View view, ViewGroup viewGroup) { View actionView = menuItemImpl.getActionView(); if (actionView == null || menuItemImpl.b()) { actionView = super.fi_(menuItemImpl, view, viewGroup); } actionView.setVisibility(menuItemImpl.isActionViewExpanded() ? 8 : 0); ViewGroup.LayoutParams layoutParams = actionView.getLayoutParams(); if (!((ActionMenuView) viewGroup).checkLayoutParams(layoutParams)) { actionView.setLayoutParams(ActionMenuView.fm_(layoutParams)); } return actionView; } @Override // o.FzA public final void a(MenuItemImpl menuItemImpl, Sya.HBt hBt) { hBt.c(menuItemImpl); ActionMenuItemView actionMenuItemView = (ActionMenuItemView) hBt; actionMenuItemView.setItemInvoker((ActionMenuView) this.b); if (this.u == null) { this.u = new LWm(this); } actionMenuItemView.setPopupCallback(this.u); } @Override // o.FzA, o.InterfaceC15933jjG public final void a(boolean z) { ArrayList arrayList; int size; super.a(z); ((View) this.b).requestLayout(); if (this.d != null) { NoP noP = this.d; noP.a(); ArrayList arrayList2 = noP.e; int size2 = arrayList2.size(); for (int i = 0; i < size2; i++) { hbU hbu = arrayList2.get(i).d; if (hbu != null) { hbu.c(this); } } } if (this.d != null) { NoP noP2 = this.d; noP2.a(); arrayList = noP2.m; } else { arrayList = null; } if (this.r && arrayList != null && ((size = arrayList.size()) != 1 ? size > 0 : (!arrayList.get(0).isActionViewExpanded()))) { if (this.n == null) { this.n = new OverflowMenuButton(this, this.g); } ViewGroup viewGroup = (ViewGroup) this.n.getParent(); if (viewGroup != this.b) { if (viewGroup != null) { viewGroup.removeView(this.n); } ((ActionMenuView) this.b).addView(this.n, ActionMenuView.c()); } } else { OverflowMenuButton overflowMenuButton = this.n; if (overflowMenuButton != null && overflowMenuButton.getParent() == this.b) { ((ViewGroup) this.b).removeView(this.n); } } ((ActionMenuView) this.b).setOverflowReserved(this.r); } @Override // o.FzA public final boolean fh_(ViewGroup viewGroup, int i) { if (viewGroup.getChildAt(i) == this.n) { return false; } return super.fh_(viewGroup, i); } /* JADX WARN: Multi-variable type inference failed */ @Override // o.FzA, o.InterfaceC15933jjG public final boolean d(SubMenuC16744qqn subMenuC16744qqn) { View view; boolean z = false; if (!subMenuC16744qqn.hasVisibleItems()) { return false; } SubMenuC16744qqn subMenuC16744qqn2 = subMenuC16744qqn; while (subMenuC16744qqn2.q != this.d) { subMenuC16744qqn2 = (SubMenuC16744qqn) subMenuC16744qqn2.q; } MenuItem item = subMenuC16744qqn2.getItem(); ViewGroup viewGroup = (ViewGroup) this.b; if (viewGroup != null) { int childCount = viewGroup.getChildCount(); for (int i = 0; i < childCount; i++) { view = viewGroup.getChildAt(i); if ((view instanceof Sya.HBt) && ((Sya.HBt) view).a() == item) { break; } } } view = 0; if (view == 0) { return false; } this.f6373o = subMenuC16744qqn.getItem().getItemId(); int size = subMenuC16744qqn.size(); int i2 = 0; while (true) { if (i2 >= size) { break; } MenuItem item2 = subMenuC16744qqn.getItem(i2); if (item2.isVisible() && item2.getIcon() != null) { z = true; break; } i2++; } HBt hBt = new HBt(this, this.c, subMenuC16744qqn, view); this.j = hBt; hBt.d = z; WpL wpL = hBt.e; if (wpL != null) { wpL.c(z); } this.j.e(); super.d(subMenuC16744qqn); return true; } public final boolean b() { if (!this.r || d() || this.d == null || this.b == null || this.s != null) { return false; } NoP noP = this.d; noP.a(); if (noP.m.isEmpty()) { return false; } this.s = new Sts(this, new RVV(this, this.c, this.d, this.n)); ((View) this.b).post(this.s); return true; } public final boolean c() { if (this.s != null && this.b != null) { ((View) this.b).removeCallbacks(this.s); this.s = null; return true; } RVV rvv = this.l; if (rvv == null) { return false; } rvv.a(); return true; } public final boolean d() { WpL wpL; RVV rvv = this.l; return (rvv == null || (wpL = rvv.e) == null || !wpL.j()) ? false : true; } /* JADX WARN: Multi-variable type inference failed */ @Override // o.FzA, o.InterfaceC15933jjG public final boolean e() { ArrayList arrayList; int i; int i2; boolean z; View view = null; if (this.d != null) { arrayList = this.d.d(); i = arrayList.size(); } else { arrayList = null; i = 0; } int i3 = this.i; int i4 = this.y; int makeMeasureSpec = View.MeasureSpec.makeMeasureSpec(0, 0); ViewGroup viewGroup = (ViewGroup) this.b; int i5 = 0; boolean z2 = false; int i6 = 0; int i7 = 0; while (true) { i2 = 2; z = 1; if (i5 >= i) { break; } MenuItemImpl menuItemImpl = arrayList.get(i5); if ((menuItemImpl.i & 2) == 2) { i7++; } else if ((menuItemImpl.i & 1) != 1) { z2 = true; } else { i6++; } if (this.f && menuItemImpl.isActionViewExpanded()) { i3 = 0; } i5++; } if (this.r && (z2 || i6 + i7 > i3)) { i3--; } int i8 = i3 - i7; SparseBooleanArray sparseBooleanArray = this.q; sparseBooleanArray.clear(); int i9 = 0; int i10 = 0; while (i9 < i) { MenuItemImpl menuItemImpl2 = arrayList.get(i9); if ((menuItemImpl2.i & i2) == i2) { View fi_ = fi_(menuItemImpl2, view, viewGroup); fi_.measure(makeMeasureSpec, makeMeasureSpec); int measuredWidth = fi_.getMeasuredWidth(); i4 -= measuredWidth; if (i10 == 0) { i10 = measuredWidth; } int groupId = menuItemImpl2.getGroupId(); if (groupId != 0) { sparseBooleanArray.put(groupId, z); } menuItemImpl2.a |= 32; } else if ((menuItemImpl2.i & z) == z) { int groupId2 = menuItemImpl2.getGroupId(); boolean z3 = sparseBooleanArray.get(groupId2); boolean z4 = ((i8 > 0 || z3) && i4 > 0) ? z : false; if (z4) { View fi_2 = fi_(menuItemImpl2, view, viewGroup); fi_2.measure(makeMeasureSpec, makeMeasureSpec); int measuredWidth2 = fi_2.getMeasuredWidth(); i4 -= measuredWidth2; if (i10 == 0) { i10 = measuredWidth2; } z4 &= i4 + i10 > 0 ? z : false; } if (z4 && groupId2 != 0) { sparseBooleanArray.put(groupId2, z); } else if (z3) { sparseBooleanArray.put(groupId2, false); for (int i11 = 0; i11 < i9; i11++) { MenuItemImpl menuItemImpl3 = arrayList.get(i11); if (menuItemImpl3.getGroupId() == groupId2) { if ((menuItemImpl3.a & 32) == 32) { i8++; } menuItemImpl3.a &= -33; } } } if (z4) { i8--; } int i12 = menuItemImpl2.a; menuItemImpl2.a = z4 ? i12 | 32 : i12 & (-33); } else { menuItemImpl2.a &= -33; } i9++; view = null; i2 = 2; z = 1; } return z; } @Override // o.InterfaceC15933jjG public final Parcelable Kn_() { ZqN zqN = new ZqN(); zqN.e = this.f6373o; return zqN; } @Override // o.InterfaceC15933jjG public final void Km_(Parcelable parcelable) { MenuItem findItem; if (parcelable instanceof ZqN) { ZqN zqN = (ZqN) parcelable; if (zqN.e <= 0 || (findItem = this.d.findItem(zqN.e)) == null) { return; } d((SubMenuC16744qqn) findItem.getSubMenu()); } } @Override // o.hbU.LWm public final void c(boolean z) { if (z) { super.d((SubMenuC16744qqn) null); } else if (this.d != null) { this.d.b(false); } } /* loaded from: classes.dex */ static class ZqN implements Parcelable { public static final Parcelable.Creator CREATOR = new Parcelable.Creator() { // from class: androidx.appcompat.widget.ActionMenuPresenter.ZqN.1 @Override // android.os.Parcelable.Creator public final /* synthetic */ ZqN createFromParcel(Parcel parcel) { return new ZqN(parcel); } @Override // android.os.Parcelable.Creator public final /* bridge */ /* synthetic */ ZqN[] newArray(int i) { return new ZqN[i]; } }; public int e; @Override // android.os.Parcelable public final int describeContents() { return 0; } ZqN() { } ZqN(Parcel parcel) { this.e = parcel.readInt(); } @Override // android.os.Parcelable public final void writeToParcel(Parcel parcel, int i) { parcel.writeInt(this.e); } } /* JADX INFO: Access modifiers changed from: package-private */ /* loaded from: classes.dex */ public class OverflowMenuButton extends AppCompatImageView implements ActionMenuView.HBt { final ActionMenuPresenter c; @Override // androidx.appcompat.widget.ActionMenuView.HBt public final boolean c() { return false; } @Override // androidx.appcompat.widget.ActionMenuView.HBt public final boolean d() { return false; } /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */ public OverflowMenuButton(ActionMenuPresenter actionMenuPresenter, Context context) { super(context, null, SYO.IeS.actionOverflowButtonStyle); this.c = actionMenuPresenter; setClickable(true); setFocusable(true); setVisibility(0); setEnabled(true); C6286cOZ.e(this, getContentDescription()); setOnTouchListener(new nHL(this, this, actionMenuPresenter) { // from class: androidx.appcompat.widget.ActionMenuPresenter.OverflowMenuButton.3 final OverflowMenuButton b; final ActionMenuPresenter e; { this.b = this; this.e = actionMenuPresenter; } @Override // o.nHL public final AZJ e() { if (this.b.c.l == null) { return null; } RVV rvv = this.b.c.l; if (rvv.e == null) { rvv.e = rvv.c(); } return rvv.e; } @Override // o.nHL public final boolean c() { this.b.c.b(); return true; } @Override // o.nHL public final boolean a() { if (this.b.c.s != null) { return false; } this.b.c.c(); return true; } }); } @Override // android.view.View public boolean performClick() { if (super.performClick()) { return true; } playSoundEffect(0); this.c.b(); return true; } @Override // android.widget.ImageView protected boolean setFrame(int i, int i2, int i3, int i4) { boolean frame = super.setFrame(i, i2, i3, i4); Drawable drawable = getDrawable(); Drawable background = getBackground(); if (drawable != null && background != null) { int width = getWidth(); int height = getHeight(); int max = Math.max(width, height) / 2; int paddingLeft = (width + (getPaddingLeft() - getPaddingRight())) / 2; int paddingTop = (height + (getPaddingTop() - getPaddingBottom())) / 2; Tlu.pC_(background, paddingLeft - max, paddingTop - max, paddingLeft + max, paddingTop + max); } return frame; } } /* JADX INFO: Access modifiers changed from: package-private */ /* loaded from: classes.dex */ public class RVV extends C16108lLe { final ActionMenuPresenter i; /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */ public RVV(ActionMenuPresenter actionMenuPresenter, Context context, NoP noP, View view) { super(context, noP, view, true, SYO.IeS.actionOverflowMenuStyle); this.i = actionMenuPresenter; this.a = 8388613; IeS ieS = actionMenuPresenter.t; this.h = ieS; WpL wpL = this.e; if (wpL != null) { wpL.c(ieS); } } @Override // o.C16108lLe public final void d() { if (this.i.d != null) { this.i.d.close(); } this.i.l = null; super.d(); } } /* JADX INFO: Access modifiers changed from: package-private */ /* loaded from: classes.dex */ public class HBt extends C16108lLe { final ActionMenuPresenter f; /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */ public HBt(ActionMenuPresenter actionMenuPresenter, Context context, SubMenuC16744qqn subMenuC16744qqn, View view) { super(context, subMenuC16744qqn, view, false, SYO.IeS.actionOverflowMenuStyle); this.f = actionMenuPresenter; if ((((MenuItemImpl) subMenuC16744qqn.getItem()).a & 32) != 32) { this.b = actionMenuPresenter.n == null ? (View) actionMenuPresenter.b : actionMenuPresenter.n; } IeS ieS = actionMenuPresenter.t; this.h = ieS; WpL wpL = this.e; if (wpL != null) { wpL.c(ieS); } } @Override // o.C16108lLe public final void d() { this.f.j = null; this.f.f6373o = 0; super.d(); } } /* loaded from: classes.dex */ class IeS implements InterfaceC15933jjG.Sts { final ActionMenuPresenter d; IeS(ActionMenuPresenter actionMenuPresenter) { this.d = actionMenuPresenter; } @Override // o.InterfaceC15933jjG.Sts public final boolean d(NoP noP) { if (noP == this.d.d) { return false; } this.d.f6373o = ((SubMenuC16744qqn) noP).getItem().getItemId(); InterfaceC15933jjG.Sts sts = this.d.a; if (sts != null) { return sts.d(noP); } return false; } @Override // o.InterfaceC15933jjG.Sts public final void e(NoP noP, boolean z) { if (noP instanceof SubMenuC16744qqn) { noP.b().b(false); } InterfaceC15933jjG.Sts sts = this.d.a; if (sts != null) { sts.e(noP, z); } } } /* JADX INFO: Access modifiers changed from: package-private */ /* loaded from: classes.dex */ public class Sts implements Runnable { final ActionMenuPresenter b; private RVV d; public Sts(ActionMenuPresenter actionMenuPresenter, RVV rvv) { this.b = actionMenuPresenter; this.d = rvv; } @Override // java.lang.Runnable public final void run() { NoP noP; NoP.Sts sts; if (this.b.d != null && (sts = (noP = this.b.d).c) != null) { sts.b(noP); } View view = (View) this.b.b; if (view != null && view.getWindowToken() != null) { RVV rvv = this.d; WpL wpL = rvv.e; if (wpL == null || !wpL.j()) { if (rvv.b != null) { rvv.a(0, 0, false, false); } } this.b.l = this.d; } this.b.s = null; } } /* loaded from: classes.dex */ class LWm extends ActionMenuItemView.LWm { final ActionMenuPresenter a; LWm(ActionMenuPresenter actionMenuPresenter) { this.a = actionMenuPresenter; } @Override // androidx.appcompat.view.menu.ActionMenuItemView.LWm public final AZJ e() { if (this.a.j == null) { return null; } HBt hBt = this.a.j; if (hBt.e == null) { hBt.e = hBt.c(); } return hBt.e; } } @Override // o.FzA, o.InterfaceC15933jjG public final void b(NoP noP, boolean z) { c(); HBt hBt = this.j; if (hBt != null) { hBt.a(); } super.b(noP, z); } @Override // o.FzA public final boolean e(MenuItemImpl menuItemImpl) { return (menuItemImpl.a & 32) == 32; } }