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 android.widget.Button;
import androidx.appcompat.view.menu.C0103e;
import androidx.appcompat.view.menu.InterfaceC0114j;
import androidx.appcompat.widget.ActionMenuView;
import p007c.C0494j;
import p025i.InterfaceC1015g;
import p028j.AbstractView$OnTouchListenerC1140l2;
import p028j.C1134k3;
import p028j.C1165o1;

/* loaded from: classes.dex */
public class ActionMenuItemView extends C1165o1 implements InterfaceC0114j.InterfaceC0115a, View.OnClickListener, ActionMenuView.InterfaceC0127a {

    /* renamed from: k */
    public C0107g f211k;

    /* renamed from: l */
    public CharSequence f212l;

    /* renamed from: m */
    public Drawable f213m;

    /* renamed from: n */
    public C0103e.InterfaceC0105b f214n;

    /* renamed from: o */
    public AbstractView$OnTouchListenerC1140l2 f215o;

    /* renamed from: p */
    public AbstractC0092b f216p;

    /* renamed from: q */
    public boolean f217q;

    /* renamed from: r */
    public boolean f218r;

    /* renamed from: s */
    public int f219s;

    /* renamed from: t */
    public int f220t;

    /* renamed from: u */
    public int f221u;

    /* renamed from: androidx.appcompat.view.menu.ActionMenuItemView$a */
    /* loaded from: classes.dex */
    public class C0091a extends AbstractView$OnTouchListenerC1140l2 {
        public C0091a() {
            super(ActionMenuItemView.this);
        }

        @Override // p028j.AbstractView$OnTouchListenerC1140l2
        /* renamed from: b */
        public InterfaceC1015g mo1889b() {
            AbstractC0092b abstractC0092b = ActionMenuItemView.this.f216p;
            if (abstractC0092b != null) {
                return abstractC0092b.mo4631a();
            }
            return null;
        }

        @Override // p028j.AbstractView$OnTouchListenerC1140l2
        /* renamed from: c */
        public boolean mo1888c() {
            InterfaceC1015g mo1889b;
            ActionMenuItemView actionMenuItemView = ActionMenuItemView.this;
            C0103e.InterfaceC0105b interfaceC0105b = actionMenuItemView.f214n;
            return interfaceC0105b != null && interfaceC0105b.mo4775a(actionMenuItemView.f211k) && (mo1889b = mo1889b()) != null && mo1889b.mo2024b();
        }
    }

    /* renamed from: androidx.appcompat.view.menu.ActionMenuItemView$b */
    /* loaded from: classes.dex */
    public static abstract class AbstractC0092b {
        /* renamed from: a */
        public abstract InterfaceC1015g mo4631a();
    }

    public ActionMenuItemView(Context context, AttributeSet attributeSet) {
        this(context, attributeSet, 0);
    }

    public ActionMenuItemView(Context context, AttributeSet attributeSet, int i) {
        super(context, attributeSet, i);
        Resources resources = context.getResources();
        this.f217q = m4940s();
        TypedArray obtainStyledAttributes = context.obtainStyledAttributes(attributeSet, C0494j.f1906v, i, 0);
        this.f219s = obtainStyledAttributes.getDimensionPixelSize(C0494j.f1911w, 0);
        obtainStyledAttributes.recycle();
        this.f221u = (int) ((resources.getDisplayMetrics().density * 32.0f) + 0.5f);
        setOnClickListener(this);
        this.f220t = -1;
        setSaveEnabled(false);
    }

    @Override // androidx.appcompat.widget.ActionMenuView.InterfaceC0127a
    /* renamed from: a */
    public boolean mo4630a() {
        return m4941r();
    }

    @Override // androidx.appcompat.widget.ActionMenuView.InterfaceC0127a
    /* renamed from: b */
    public boolean mo4629b() {
        return m4941r() && this.f211k.getIcon() == null;
    }

    @Override // androidx.appcompat.view.menu.InterfaceC0114j.InterfaceC0115a
    /* renamed from: c */
    public boolean mo4823c() {
        return true;
    }

    @Override // androidx.appcompat.view.menu.InterfaceC0114j.InterfaceC0115a
    /* renamed from: d */
    public void mo4822d(C0107g c0107g, int i) {
        this.f211k = c0107g;
        setIcon(c0107g.getIcon());
        setTitle(c0107g.m4855i(this));
        setId(c0107g.getItemId());
        setVisibility(c0107g.isVisible() ? 0 : 8);
        setEnabled(c0107g.isEnabled());
        if (c0107g.hasSubMenu() && this.f215o == null) {
            this.f215o = new C0091a();
        }
    }

    @Override // android.widget.TextView, android.view.View
    public CharSequence getAccessibilityClassName() {
        return Button.class.getName();
    }

    @Override // androidx.appcompat.view.menu.InterfaceC0114j.InterfaceC0115a
    public C0107g getItemData() {
        return this.f211k;
    }

    @Override // android.view.View.OnClickListener
    public void onClick(View view) {
        C0103e.InterfaceC0105b interfaceC0105b = this.f214n;
        if (interfaceC0105b != null) {
            interfaceC0105b.mo4775a(this.f211k);
        }
    }

    @Override // android.widget.TextView, android.view.View
    public void onConfigurationChanged(Configuration configuration) {
        super.onConfigurationChanged(configuration);
        this.f217q = m4940s();
        m4939t();
    }

    @Override // p028j.C1165o1, android.widget.TextView, android.view.View
    public void onMeasure(int i, int i2) {
        int i3;
        boolean m4941r = m4941r();
        if (m4941r && (i3 = this.f220t) >= 0) {
            super.setPadding(i3, getPaddingTop(), getPaddingRight(), getPaddingBottom());
        }
        super.onMeasure(i, i2);
        int mode = View.MeasureSpec.getMode(i);
        int size = View.MeasureSpec.getSize(i);
        int measuredWidth = getMeasuredWidth();
        int min = mode == Integer.MIN_VALUE ? Math.min(size, this.f219s) : this.f219s;
        if (mode != 1073741824 && this.f219s > 0 && measuredWidth < min) {
            super.onMeasure(View.MeasureSpec.makeMeasureSpec(min, 1073741824), i2);
        }
        if (m4941r || this.f213m == null) {
            return;
        }
        super.setPadding((getMeasuredWidth() - this.f213m.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) {
        AbstractView$OnTouchListenerC1140l2 abstractView$OnTouchListenerC1140l2;
        if (this.f211k.hasSubMenu() && (abstractView$OnTouchListenerC1140l2 = this.f215o) != null && abstractView$OnTouchListenerC1140l2.onTouch(this, motionEvent)) {
            return true;
        }
        return super.onTouchEvent(motionEvent);
    }

    /* renamed from: r */
    public boolean m4941r() {
        return !TextUtils.isEmpty(getText());
    }

    /* renamed from: s */
    public final boolean m4940s() {
        Configuration configuration = getContext().getResources().getConfiguration();
        int i = configuration.screenWidthDp;
        return i >= 480 || (i >= 640 && configuration.screenHeightDp >= 480) || configuration.orientation == 2;
    }

    public void setCheckable(boolean z) {
    }

    public void setChecked(boolean z) {
    }

    public void setExpandedFormat(boolean z) {
        if (this.f218r != z) {
            this.f218r = z;
            C0107g c0107g = this.f211k;
            if (c0107g != null) {
                c0107g.m4861c();
            }
        }
    }

    public void setIcon(Drawable drawable) {
        this.f213m = drawable;
        if (drawable != null) {
            int intrinsicWidth = drawable.getIntrinsicWidth();
            int intrinsicHeight = drawable.getIntrinsicHeight();
            int i = this.f221u;
            if (intrinsicWidth > i) {
                intrinsicHeight = (int) (intrinsicHeight * (i / intrinsicWidth));
                intrinsicWidth = i;
            }
            if (intrinsicHeight > i) {
                intrinsicWidth = (int) (intrinsicWidth * (i / intrinsicHeight));
            } else {
                i = intrinsicHeight;
            }
            drawable.setBounds(0, 0, intrinsicWidth, i);
        }
        setCompoundDrawables(drawable, null, null, null);
        m4939t();
    }

    public void setItemInvoker(C0103e.InterfaceC0105b interfaceC0105b) {
        this.f214n = interfaceC0105b;
    }

    @Override // android.widget.TextView, android.view.View
    public void setPadding(int i, int i2, int i3, int i4) {
        this.f220t = i;
        super.setPadding(i, i2, i3, i4);
    }

    public void setPopupCallback(AbstractC0092b abstractC0092b) {
        this.f216p = abstractC0092b;
    }

    public void setTitle(CharSequence charSequence) {
        this.f212l = charSequence;
        m4939t();
    }

    /* renamed from: t */
    public final void m4939t() {
        boolean z = true;
        boolean z2 = !TextUtils.isEmpty(this.f212l);
        if (this.f213m != null && (!this.f211k.m4862B() || (!this.f217q && !this.f218r))) {
            z = false;
        }
        boolean z3 = z2 & z;
        setText(z3 ? this.f212l : null);
        CharSequence contentDescription = this.f211k.getContentDescription();
        if (TextUtils.isEmpty(contentDescription)) {
            contentDescription = z3 ? null : this.f211k.getTitle();
        }
        setContentDescription(contentDescription);
        CharSequence tooltipText = this.f211k.getTooltipText();
        if (TextUtils.isEmpty(tooltipText)) {
            C1134k3.m2064a(this, z3 ? null : this.f211k.getTitle());
        } else {
            C1134k3.m2064a(this, tooltipText);
        }
    }
}