package androidx.appcompat.view.menu; import android.content.Context; import android.content.res.Configuration; import android.content.res.Resources; import android.content.res.TypedArray; import android.graphics.drawable.Drawable; import android.os.Parcelable; import android.text.TextUtils; import android.util.AttributeSet; import android.view.MotionEvent; import android.view.View; import androidx.appcompat.view.menu.e; import androidx.appcompat.view.menu.k; import androidx.appcompat.widget.ActionMenuView; import androidx.appcompat.widget.l2; import androidx.appcompat.widget.m1; import androidx.appcompat.widget.r0; /* loaded from: classes.dex */ public class ActionMenuItemView extends r0 implements k.a, View.OnClickListener, ActionMenuView.a { /* renamed from: f, reason: collision with root package name */ g f512f; /* renamed from: g, reason: collision with root package name */ private CharSequence f513g; /* renamed from: h, reason: collision with root package name */ private Drawable f514h; /* renamed from: i, reason: collision with root package name */ e.b f515i; /* renamed from: j, reason: collision with root package name */ private m1 f516j; /* renamed from: k, reason: collision with root package name */ b f517k; /* renamed from: l, reason: collision with root package name */ private boolean f518l; /* renamed from: m, reason: collision with root package name */ private boolean f519m; /* renamed from: n, reason: collision with root package name */ private int f520n; /* renamed from: o, reason: collision with root package name */ private int f521o; /* renamed from: p, reason: collision with root package name */ private int f522p; private class a extends m1 { public a() { super(ActionMenuItemView.this); } @Override // androidx.appcompat.widget.m1 public i.e b() { b bVar = ActionMenuItemView.this.f517k; if (bVar != null) { return bVar.a(); } return null; } @Override // androidx.appcompat.widget.m1 protected boolean c() { i.e b10; ActionMenuItemView actionMenuItemView = ActionMenuItemView.this; e.b bVar = actionMenuItemView.f515i; return bVar != null && bVar.a(actionMenuItemView.f512f) && (b10 = b()) != null && b10.a(); } } public static abstract class b { public abstract i.e a(); } public ActionMenuItemView(Context context, AttributeSet attributeSet) { this(context, attributeSet, 0); } private boolean g() { Configuration configuration = getContext().getResources().getConfiguration(); int i10 = configuration.screenWidthDp; return i10 >= 480 || (i10 >= 640 && configuration.screenHeightDp >= 480) || configuration.orientation == 2; } private void h() { boolean z10 = true; boolean z11 = !TextUtils.isEmpty(this.f513g); if (this.f514h != null && (!this.f512f.B() || (!this.f518l && !this.f519m))) { z10 = false; } boolean z12 = z11 & z10; setText(z12 ? this.f513g : null); CharSequence contentDescription = this.f512f.getContentDescription(); if (TextUtils.isEmpty(contentDescription)) { setContentDescription(z12 ? null : this.f512f.getTitle()); } else { setContentDescription(contentDescription); } CharSequence tooltipText = this.f512f.getTooltipText(); if (TextUtils.isEmpty(tooltipText)) { l2.a(this, z12 ? null : this.f512f.getTitle()); } else { l2.a(this, tooltipText); } } @Override // androidx.appcompat.widget.ActionMenuView.a public boolean a() { return f(); } @Override // androidx.appcompat.widget.ActionMenuView.a public boolean b() { return f() && this.f512f.getIcon() == null; } @Override // androidx.appcompat.view.menu.k.a public boolean d() { return true; } @Override // androidx.appcompat.view.menu.k.a public void e(g gVar, int i10) { this.f512f = gVar; setIcon(gVar.getIcon()); setTitle(gVar.i(this)); setId(gVar.getItemId()); setVisibility(gVar.isVisible() ? 0 : 8); setEnabled(gVar.isEnabled()); if (gVar.hasSubMenu() && this.f516j == null) { this.f516j = new a(); } } public boolean f() { return !TextUtils.isEmpty(getText()); } @Override // androidx.appcompat.view.menu.k.a public g getItemData() { return this.f512f; } @Override // android.view.View.OnClickListener public void onClick(View view) { e.b bVar = this.f515i; if (bVar != null) { bVar.a(this.f512f); } } @Override // android.widget.TextView, android.view.View public void onConfigurationChanged(Configuration configuration) { super.onConfigurationChanged(configuration); this.f518l = g(); h(); } @Override // androidx.appcompat.widget.r0, android.widget.TextView, android.view.View protected void onMeasure(int i10, int i11) { int i12; boolean f10 = f(); if (f10 && (i12 = this.f521o) >= 0) { super.setPadding(i12, getPaddingTop(), getPaddingRight(), getPaddingBottom()); } super.onMeasure(i10, i11); int mode = View.MeasureSpec.getMode(i10); int size = View.MeasureSpec.getSize(i10); int measuredWidth = getMeasuredWidth(); int min = mode == Integer.MIN_VALUE ? Math.min(size, this.f520n) : this.f520n; if (mode != 1073741824 && this.f520n > 0 && measuredWidth < min) { super.onMeasure(View.MeasureSpec.makeMeasureSpec(min, 1073741824), i11); } if (f10 || this.f514h == null) { return; } super.setPadding((getMeasuredWidth() - this.f514h.getBounds().width()) / 2, getPaddingTop(), getPaddingRight(), getPaddingBottom()); } @Override // android.widget.TextView, android.view.View public void onRestoreInstanceState(Parcelable parcelable) { super.onRestoreInstanceState(null); } @Override // android.widget.TextView, android.view.View public boolean onTouchEvent(MotionEvent motionEvent) { m1 m1Var; if (this.f512f.hasSubMenu() && (m1Var = this.f516j) != null && m1Var.onTouch(this, motionEvent)) { return true; } return super.onTouchEvent(motionEvent); } public void setCheckable(boolean z10) { } public void setChecked(boolean z10) { } public void setExpandedFormat(boolean z10) { if (this.f519m != z10) { this.f519m = z10; g gVar = this.f512f; if (gVar != null) { gVar.c(); } } } public void setIcon(Drawable drawable) { this.f514h = drawable; if (drawable != null) { int intrinsicWidth = drawable.getIntrinsicWidth(); int intrinsicHeight = drawable.getIntrinsicHeight(); int i10 = this.f522p; if (intrinsicWidth > i10) { intrinsicHeight = (int) (intrinsicHeight * (i10 / intrinsicWidth)); intrinsicWidth = i10; } if (intrinsicHeight > i10) { intrinsicWidth = (int) (intrinsicWidth * (i10 / intrinsicHeight)); } else { i10 = intrinsicHeight; } drawable.setBounds(0, 0, intrinsicWidth, i10); } setCompoundDrawables(drawable, null, null, null); h(); } public void setItemInvoker(e.b bVar) { this.f515i = bVar; } @Override // android.widget.TextView, android.view.View public void setPadding(int i10, int i11, int i12, int i13) { this.f521o = i10; super.setPadding(i10, i11, i12, i13); } public void setPopupCallback(b bVar) { this.f517k = bVar; } public void setTitle(CharSequence charSequence) { this.f513g = charSequence; h(); } public ActionMenuItemView(Context context, AttributeSet attributeSet, int i10) { super(context, attributeSet, i10); Resources resources = context.getResources(); this.f518l = g(); TypedArray obtainStyledAttributes = context.obtainStyledAttributes(attributeSet, d.j.f8919v, i10, 0); this.f520n = obtainStyledAttributes.getDimensionPixelSize(d.j.f8924w, 0); obtainStyledAttributes.recycle(); this.f522p = (int) ((resources.getDisplayMetrics().density * 32.0f) + 0.5f); setOnClickListener(this); this.f521o = -1; setSaveEnabled(false); } }