package androidx.appcompat.view.menu; import android.content.ComponentName; import android.content.Context; import android.content.Intent; import android.content.pm.ActivityInfo; import android.content.pm.PackageManager; import android.content.pm.ResolveInfo; import android.content.res.Resources; import android.graphics.drawable.Drawable; import android.os.Bundle; import android.os.Parcelable; import android.util.SparseArray; import android.view.ContextMenu; import android.view.KeyCharacterMap; import android.view.KeyEvent; import android.view.MenuItem; import android.view.SubMenu; import android.view.View; import java.lang.ref.WeakReference; import java.util.ArrayList; import java.util.Iterator; import java.util.List; import java.util.concurrent.CopyOnWriteArrayList; /* loaded from: classes.dex */ public class e implements s.a { private static final int[] A = {1, 4, 5, 3, 2, 0}; /* renamed from: a, reason: collision with root package name */ private final Context f606a; /* renamed from: b, reason: collision with root package name */ private final Resources f607b; /* renamed from: c, reason: collision with root package name */ private boolean f608c; /* renamed from: d, reason: collision with root package name */ private boolean f609d; /* renamed from: e, reason: collision with root package name */ private a f610e; /* renamed from: m, reason: collision with root package name */ private ContextMenu.ContextMenuInfo f618m; /* renamed from: n, reason: collision with root package name */ CharSequence f619n; /* renamed from: o, reason: collision with root package name */ Drawable f620o; /* renamed from: p, reason: collision with root package name */ View f621p; /* renamed from: x, reason: collision with root package name */ private g f629x; /* renamed from: z, reason: collision with root package name */ private boolean f631z; /* renamed from: l, reason: collision with root package name */ private int f617l = 0; /* renamed from: q, reason: collision with root package name */ private boolean f622q = false; /* renamed from: r, reason: collision with root package name */ private boolean f623r = false; /* renamed from: s, reason: collision with root package name */ private boolean f624s = false; /* renamed from: t, reason: collision with root package name */ private boolean f625t = false; /* renamed from: u, reason: collision with root package name */ private boolean f626u = false; /* renamed from: v, reason: collision with root package name */ private ArrayList f627v = new ArrayList(); /* renamed from: w, reason: collision with root package name */ private CopyOnWriteArrayList f628w = new CopyOnWriteArrayList(); /* renamed from: y, reason: collision with root package name */ private boolean f630y = false; /* renamed from: f, reason: collision with root package name */ private ArrayList f611f = new ArrayList(); /* renamed from: g, reason: collision with root package name */ private ArrayList f612g = new ArrayList(); /* renamed from: h, reason: collision with root package name */ private boolean f613h = true; /* renamed from: i, reason: collision with root package name */ private ArrayList f614i = new ArrayList(); /* renamed from: j, reason: collision with root package name */ private ArrayList f615j = new ArrayList(); /* renamed from: k, reason: collision with root package name */ private boolean f616k = true; public interface a { boolean a(e eVar, MenuItem menuItem); void b(e eVar); } public interface b { boolean a(g gVar); } public e(Context context) { this.f606a = context; this.f607b = context.getResources(); b0(true); } private static int B(int i10) { int i11 = ((-65536) & i10) >> 16; if (i11 >= 0) { int[] iArr = A; if (i11 < iArr.length) { return (i10 & 65535) | (iArr[i11] << 16); } } throw new IllegalArgumentException("order does not contain a valid category."); } private void N(int i10, boolean z10) { if (i10 < 0 || i10 >= this.f611f.size()) { return; } this.f611f.remove(i10); if (z10) { K(true); } } private void W(int i10, CharSequence charSequence, int i11, Drawable drawable, View view) { Resources C = C(); if (view != null) { this.f621p = view; this.f619n = null; this.f620o = null; } else { if (i10 > 0) { this.f619n = C.getText(i10); } else if (charSequence != null) { this.f619n = charSequence; } if (i11 > 0) { this.f620o = androidx.core.content.a.getDrawable(u(), i11); } else if (drawable != null) { this.f620o = drawable; } this.f621p = null; } K(false); } /* JADX WARN: Code restructure failed: missing block: B:5:0x0019, code lost: if (androidx.core.view.t0.e(android.view.ViewConfiguration.get(r2.f606a), r2.f606a) != false) goto L9; */ /* Code decompiled incorrectly, please refer to instructions dump. To view partially-correct code enable 'Show inconsistent code' option in preferences */ private void b0(boolean r3) { /* r2 = this; if (r3 == 0) goto L1c android.content.res.Resources r3 = r2.f607b android.content.res.Configuration r3 = r3.getConfiguration() int r3 = r3.keyboard r0 = 1 if (r3 == r0) goto L1c android.content.Context r3 = r2.f606a android.view.ViewConfiguration r3 = android.view.ViewConfiguration.get(r3) android.content.Context r1 = r2.f606a boolean r3 = androidx.core.view.t0.e(r3, r1) if (r3 == 0) goto L1c goto L1d L1c: r0 = 0 L1d: r2.f609d = r0 return */ throw new UnsupportedOperationException("Method not decompiled: androidx.appcompat.view.menu.e.b0(boolean):void"); } private g g(int i10, int i11, int i12, int i13, CharSequence charSequence, int i14) { return new g(this, i10, i11, i12, i13, charSequence, i14); } private void i(boolean z10) { if (this.f628w.isEmpty()) { return; } d0(); Iterator it = this.f628w.iterator(); while (it.hasNext()) { WeakReference weakReference = (WeakReference) it.next(); j jVar = (j) weakReference.get(); if (jVar == null) { this.f628w.remove(weakReference); } else { jVar.c(z10); } } c0(); } private boolean j(m mVar, j jVar) { if (this.f628w.isEmpty()) { return false; } boolean k10 = jVar != null ? jVar.k(mVar) : false; Iterator it = this.f628w.iterator(); while (it.hasNext()) { WeakReference weakReference = (WeakReference) it.next(); j jVar2 = (j) weakReference.get(); if (jVar2 == null) { this.f628w.remove(weakReference); } else if (!k10) { k10 = jVar2.k(mVar); } } return k10; } private static int n(ArrayList arrayList, int i10) { for (int size = arrayList.size() - 1; size >= 0; size--) { if (((g) arrayList.get(size)).f() <= i10) { return size + 1; } } return 0; } boolean A() { return this.f625t; } Resources C() { return this.f607b; } public e D() { return this; } public ArrayList E() { if (!this.f613h) { return this.f612g; } this.f612g.clear(); int size = this.f611f.size(); for (int i10 = 0; i10 < size; i10++) { g gVar = (g) this.f611f.get(i10); if (gVar.isVisible()) { this.f612g.add(gVar); } } this.f613h = false; this.f616k = true; return this.f612g; } public boolean F() { return this.f630y; } boolean G() { return this.f608c; } public boolean H() { return this.f609d; } void I(g gVar) { this.f616k = true; K(true); } void J(g gVar) { this.f613h = true; K(true); } public void K(boolean z10) { if (this.f622q) { this.f623r = true; if (z10) { this.f624s = true; return; } return; } if (z10) { this.f613h = true; this.f616k = true; } i(z10); } public boolean L(MenuItem menuItem, int i10) { return M(menuItem, null, i10); } public boolean M(MenuItem menuItem, j jVar, int i10) { g gVar = (g) menuItem; if (gVar == null || !gVar.isEnabled()) { return false; } boolean k10 = gVar.k(); androidx.core.view.b b10 = gVar.b(); boolean z10 = b10 != null && b10.a(); if (gVar.j()) { k10 |= gVar.expandActionView(); if (k10) { e(true); } } else if (gVar.hasSubMenu() || z10) { if ((i10 & 4) == 0) { e(false); } if (!gVar.hasSubMenu()) { gVar.x(new m(u(), this, gVar)); } m mVar = (m) gVar.getSubMenu(); if (z10) { b10.e(mVar); } k10 |= j(mVar, jVar); if (!k10) { e(true); } } else if ((i10 & 1) == 0) { e(true); } return k10; } public void O(j jVar) { Iterator it = this.f628w.iterator(); while (it.hasNext()) { WeakReference weakReference = (WeakReference) it.next(); j jVar2 = (j) weakReference.get(); if (jVar2 == null || jVar2 == jVar) { this.f628w.remove(weakReference); } } } public void P(Bundle bundle) { MenuItem findItem; if (bundle == null) { return; } SparseArray sparseParcelableArray = bundle.getSparseParcelableArray(t()); int size = size(); for (int i10 = 0; i10 < size; i10++) { MenuItem item = getItem(i10); View actionView = item.getActionView(); if (actionView != null && actionView.getId() != -1) { actionView.restoreHierarchyState(sparseParcelableArray); } if (item.hasSubMenu()) { ((m) item.getSubMenu()).P(bundle); } } int i11 = bundle.getInt("android:menu:expandedactionview"); if (i11 <= 0 || (findItem = findItem(i11)) == null) { return; } findItem.expandActionView(); } public void Q(Bundle bundle) { int size = size(); SparseArray sparseArray = null; for (int i10 = 0; i10 < size; i10++) { MenuItem item = getItem(i10); View actionView = item.getActionView(); if (actionView != null && actionView.getId() != -1) { if (sparseArray == null) { sparseArray = new SparseArray<>(); } actionView.saveHierarchyState(sparseArray); if (item.isActionViewExpanded()) { bundle.putInt("android:menu:expandedactionview", item.getItemId()); } } if (item.hasSubMenu()) { ((m) item.getSubMenu()).Q(bundle); } } if (sparseArray != null) { bundle.putSparseParcelableArray(t(), sparseArray); } } public void R(a aVar) { this.f610e = aVar; } public e S(int i10) { this.f617l = i10; return this; } void T(MenuItem menuItem) { int groupId = menuItem.getGroupId(); int size = this.f611f.size(); d0(); for (int i10 = 0; i10 < size; i10++) { g gVar = (g) this.f611f.get(i10); if (gVar.getGroupId() == groupId && gVar.m() && gVar.isCheckable()) { gVar.s(gVar == menuItem); } } c0(); } protected e U(int i10) { W(0, null, i10, null, null); return this; } protected e V(Drawable drawable) { W(0, null, 0, drawable, null); return this; } protected e X(int i10) { W(i10, null, 0, null, null); return this; } protected e Y(CharSequence charSequence) { W(0, charSequence, 0, null, null); return this; } protected e Z(View view) { W(0, null, 0, null, view); return this; } protected MenuItem a(int i10, int i11, int i12, CharSequence charSequence) { int B = B(i12); g g10 = g(i10, i11, i12, B, charSequence, this.f617l); ContextMenu.ContextMenuInfo contextMenuInfo = this.f618m; if (contextMenuInfo != null) { g10.v(contextMenuInfo); } ArrayList arrayList = this.f611f; arrayList.add(n(arrayList, B), g10); K(true); return g10; } public void a0(boolean z10) { this.f631z = z10; } @Override // android.view.Menu public MenuItem add(CharSequence charSequence) { return a(0, 0, 0, charSequence); } @Override // android.view.Menu public int addIntentOptions(int i10, int i11, int i12, ComponentName componentName, Intent[] intentArr, Intent intent, int i13, MenuItem[] menuItemArr) { int i14; PackageManager packageManager = this.f606a.getPackageManager(); List queryIntentActivityOptions = packageManager.queryIntentActivityOptions(componentName, intentArr, intent, 0); int size = queryIntentActivityOptions != null ? queryIntentActivityOptions.size() : 0; if ((i13 & 1) == 0) { removeGroup(i10); } for (int i15 = 0; i15 < size; i15++) { ResolveInfo resolveInfo = queryIntentActivityOptions.get(i15); int i16 = resolveInfo.specificIndex; Intent intent2 = new Intent(i16 < 0 ? intent : intentArr[i16]); ActivityInfo activityInfo = resolveInfo.activityInfo; intent2.setComponent(new ComponentName(activityInfo.applicationInfo.packageName, activityInfo.name)); MenuItem intent3 = add(i10, i11, i12, resolveInfo.loadLabel(packageManager)).setIcon(resolveInfo.loadIcon(packageManager)).setIntent(intent2); if (menuItemArr != null && (i14 = resolveInfo.specificIndex) >= 0) { menuItemArr[i14] = intent3; } } return size; } @Override // android.view.Menu public SubMenu addSubMenu(CharSequence charSequence) { return addSubMenu(0, 0, 0, charSequence); } public void b(j jVar) { c(jVar, this.f606a); } public void c(j jVar, Context context) { this.f628w.add(new WeakReference(jVar)); jVar.i(context, this); this.f616k = true; } public void c0() { this.f622q = false; if (this.f623r) { this.f623r = false; K(this.f624s); } } @Override // android.view.Menu public void clear() { g gVar = this.f629x; if (gVar != null) { f(gVar); } this.f611f.clear(); K(true); } public void clearHeader() { this.f620o = null; this.f619n = null; this.f621p = null; K(false); } @Override // android.view.Menu public void close() { e(true); } public void d() { a aVar = this.f610e; if (aVar != null) { aVar.b(this); } } public void d0() { if (this.f622q) { return; } this.f622q = true; this.f623r = false; this.f624s = false; } public final void e(boolean z10) { if (this.f626u) { return; } this.f626u = true; Iterator it = this.f628w.iterator(); while (it.hasNext()) { WeakReference weakReference = (WeakReference) it.next(); j jVar = (j) weakReference.get(); if (jVar == null) { this.f628w.remove(weakReference); } else { jVar.b(this, z10); } } this.f626u = false; } public boolean f(g gVar) { boolean z10 = false; if (!this.f628w.isEmpty() && this.f629x == gVar) { d0(); Iterator it = this.f628w.iterator(); while (it.hasNext()) { WeakReference weakReference = (WeakReference) it.next(); j jVar = (j) weakReference.get(); if (jVar == null) { this.f628w.remove(weakReference); } else { z10 = jVar.e(this, gVar); if (z10) { break; } } } c0(); if (z10) { this.f629x = null; } } return z10; } @Override // android.view.Menu public MenuItem findItem(int i10) { MenuItem findItem; int size = size(); for (int i11 = 0; i11 < size; i11++) { g gVar = (g) this.f611f.get(i11); if (gVar.getItemId() == i10) { return gVar; } if (gVar.hasSubMenu() && (findItem = gVar.getSubMenu().findItem(i10)) != null) { return findItem; } } return null; } @Override // android.view.Menu public MenuItem getItem(int i10) { return (MenuItem) this.f611f.get(i10); } boolean h(e eVar, MenuItem menuItem) { a aVar = this.f610e; return aVar != null && aVar.a(eVar, menuItem); } @Override // android.view.Menu public boolean hasVisibleItems() { if (this.f631z) { return true; } int size = size(); for (int i10 = 0; i10 < size; i10++) { if (((g) this.f611f.get(i10)).isVisible()) { return true; } } return false; } @Override // android.view.Menu public boolean isShortcutKey(int i10, KeyEvent keyEvent) { return p(i10, keyEvent) != null; } public boolean k(g gVar) { boolean z10 = false; if (this.f628w.isEmpty()) { return false; } d0(); Iterator it = this.f628w.iterator(); while (it.hasNext()) { WeakReference weakReference = (WeakReference) it.next(); j jVar = (j) weakReference.get(); if (jVar == null) { this.f628w.remove(weakReference); } else { z10 = jVar.f(this, gVar); if (z10) { break; } } } c0(); if (z10) { this.f629x = gVar; } return z10; } public int l(int i10) { return m(i10, 0); } public int m(int i10, int i11) { int size = size(); if (i11 < 0) { i11 = 0; } while (i11 < size) { if (((g) this.f611f.get(i11)).getGroupId() == i10) { return i11; } i11++; } return -1; } public int o(int i10) { int size = size(); for (int i11 = 0; i11 < size; i11++) { if (((g) this.f611f.get(i11)).getItemId() == i10) { return i11; } } return -1; } g p(int i10, KeyEvent keyEvent) { ArrayList arrayList = this.f627v; arrayList.clear(); q(arrayList, i10, keyEvent); if (arrayList.isEmpty()) { return null; } int metaState = keyEvent.getMetaState(); KeyCharacterMap.KeyData keyData = new KeyCharacterMap.KeyData(); keyEvent.getKeyData(keyData); int size = arrayList.size(); if (size == 1) { return (g) arrayList.get(0); } boolean G = G(); for (int i11 = 0; i11 < size; i11++) { g gVar = (g) arrayList.get(i11); char alphabeticShortcut = G ? gVar.getAlphabeticShortcut() : gVar.getNumericShortcut(); char[] cArr = keyData.meta; if ((alphabeticShortcut == cArr[0] && (metaState & 2) == 0) || ((alphabeticShortcut == cArr[2] && (metaState & 2) != 0) || (G && alphabeticShortcut == '\b' && i10 == 67))) { return gVar; } } return null; } @Override // android.view.Menu public boolean performIdentifierAction(int i10, int i11) { return L(findItem(i10), i11); } @Override // android.view.Menu public boolean performShortcut(int i10, KeyEvent keyEvent, int i11) { g p10 = p(i10, keyEvent); boolean L = p10 != null ? L(p10, i11) : false; if ((i11 & 2) != 0) { e(true); } return L; } void q(List list, int i10, KeyEvent keyEvent) { boolean G = G(); int modifiers = keyEvent.getModifiers(); KeyCharacterMap.KeyData keyData = new KeyCharacterMap.KeyData(); if (keyEvent.getKeyData(keyData) || i10 == 67) { int size = this.f611f.size(); for (int i11 = 0; i11 < size; i11++) { g gVar = (g) this.f611f.get(i11); if (gVar.hasSubMenu()) { ((e) gVar.getSubMenu()).q(list, i10, keyEvent); } char alphabeticShortcut = G ? gVar.getAlphabeticShortcut() : gVar.getNumericShortcut(); if (((modifiers & 69647) == ((G ? gVar.getAlphabeticModifiers() : gVar.getNumericModifiers()) & 69647)) && alphabeticShortcut != 0) { char[] cArr = keyData.meta; if ((alphabeticShortcut == cArr[0] || alphabeticShortcut == cArr[2] || (G && alphabeticShortcut == '\b' && i10 == 67)) && gVar.isEnabled()) { list.add(gVar); } } } } } public void r() { ArrayList E = E(); if (this.f616k) { Iterator it = this.f628w.iterator(); boolean z10 = false; while (it.hasNext()) { WeakReference weakReference = (WeakReference) it.next(); j jVar = (j) weakReference.get(); if (jVar == null) { this.f628w.remove(weakReference); } else { z10 |= jVar.d(); } } if (z10) { this.f614i.clear(); this.f615j.clear(); int size = E.size(); for (int i10 = 0; i10 < size; i10++) { g gVar = (g) E.get(i10); if (gVar.l()) { this.f614i.add(gVar); } else { this.f615j.add(gVar); } } } else { this.f614i.clear(); this.f615j.clear(); this.f615j.addAll(E()); } this.f616k = false; } } @Override // android.view.Menu public void removeGroup(int i10) { int l10 = l(i10); if (l10 >= 0) { int size = this.f611f.size() - l10; int i11 = 0; while (true) { int i12 = i11 + 1; if (i11 >= size || ((g) this.f611f.get(l10)).getGroupId() != i10) { break; } N(l10, false); i11 = i12; } K(true); } } @Override // android.view.Menu public void removeItem(int i10) { N(o(i10), true); } public ArrayList s() { r(); return this.f614i; } @Override // android.view.Menu public void setGroupCheckable(int i10, boolean z10, boolean z11) { int size = this.f611f.size(); for (int i11 = 0; i11 < size; i11++) { g gVar = (g) this.f611f.get(i11); if (gVar.getGroupId() == i10) { gVar.t(z11); gVar.setCheckable(z10); } } } @Override // android.view.Menu public void setGroupDividerEnabled(boolean z10) { this.f630y = z10; } @Override // android.view.Menu public void setGroupEnabled(int i10, boolean z10) { int size = this.f611f.size(); for (int i11 = 0; i11 < size; i11++) { g gVar = (g) this.f611f.get(i11); if (gVar.getGroupId() == i10) { gVar.setEnabled(z10); } } } @Override // android.view.Menu public void setGroupVisible(int i10, boolean z10) { int size = this.f611f.size(); boolean z11 = false; for (int i11 = 0; i11 < size; i11++) { g gVar = (g) this.f611f.get(i11); if (gVar.getGroupId() == i10 && gVar.y(z10)) { z11 = true; } } if (z11) { K(true); } } @Override // android.view.Menu public void setQwertyMode(boolean z10) { this.f608c = z10; K(false); } @Override // android.view.Menu public int size() { return this.f611f.size(); } protected String t() { return "android:menu:actionviewstates"; } public Context u() { return this.f606a; } public g v() { return this.f629x; } public Drawable w() { return this.f620o; } public CharSequence x() { return this.f619n; } public View y() { return this.f621p; } public ArrayList z() { r(); return this.f615j; } @Override // android.view.Menu public MenuItem add(int i10) { return a(0, 0, 0, this.f607b.getString(i10)); } @Override // android.view.Menu public SubMenu addSubMenu(int i10) { return addSubMenu(0, 0, 0, this.f607b.getString(i10)); } @Override // android.view.Menu public MenuItem add(int i10, int i11, int i12, CharSequence charSequence) { return a(i10, i11, i12, charSequence); } @Override // android.view.Menu public SubMenu addSubMenu(int i10, int i11, int i12, CharSequence charSequence) { g gVar = (g) a(i10, i11, i12, charSequence); m mVar = new m(this.f606a, this, gVar); gVar.x(mVar); return mVar; } @Override // android.view.Menu public MenuItem add(int i10, int i11, int i12, int i13) { return a(i10, i11, i12, this.f607b.getString(i13)); } @Override // android.view.Menu public SubMenu addSubMenu(int i10, int i11, int i12, int i13) { return addSubMenu(i10, i11, i12, this.f607b.getString(i13)); } }