package androidx.appcompat.view.menu;

import android.content.ActivityNotFoundException;
import android.content.Context;
import android.content.Intent;
import android.content.res.ColorStateList;
import android.content.res.Resources;
import android.graphics.PorterDuff;
import android.graphics.drawable.Drawable;
import android.os.Build;
import android.util.Log;
import android.view.ActionProvider;
import android.view.ContextMenu;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.MenuItem;
import android.view.SubMenu;
import android.view.View;
import android.view.ViewConfiguration;
import android.view.ViewDebug;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import androidx.appcompat.view.menu.n;
import androidx.core.view.b;

/* JADX INFO: compiled from: MenuItemImpl.java */
/* JADX INFO: loaded from: classes.dex */
public final class i implements s.b {
    private View A;
    private androidx.core.view.b B;
    private MenuItem.OnActionExpandListener C;
    private ContextMenu.ContextMenuInfo E;

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    private final int f523a;

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    private final int f524b;

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    private final int f525c;

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    private final int f526d;

    /* JADX INFO: renamed from: e, reason: collision with root package name */
    private CharSequence f527e;

    /* JADX INFO: renamed from: f, reason: collision with root package name */
    private CharSequence f528f;

    /* JADX INFO: renamed from: g, reason: collision with root package name */
    private Intent f529g;

    /* JADX INFO: renamed from: h, reason: collision with root package name */
    private char f530h;

    /* JADX INFO: renamed from: j, reason: collision with root package name */
    private char f532j;

    /* JADX INFO: renamed from: l, reason: collision with root package name */
    private Drawable f534l;

    /* JADX INFO: renamed from: n, reason: collision with root package name */
    g f536n;

    /* JADX INFO: renamed from: o, reason: collision with root package name */
    private r f537o;

    /* JADX INFO: renamed from: p, reason: collision with root package name */
    private Runnable f538p;

    /* JADX INFO: renamed from: q, reason: collision with root package name */
    private MenuItem.OnMenuItemClickListener f539q;

    /* JADX INFO: renamed from: r, reason: collision with root package name */
    private CharSequence f540r;

    /* JADX INFO: renamed from: s, reason: collision with root package name */
    private CharSequence f541s;

    /* JADX INFO: renamed from: z, reason: collision with root package name */
    private int f548z;

    /* JADX INFO: renamed from: i, reason: collision with root package name */
    private int f531i = 4096;

    /* JADX INFO: renamed from: k, reason: collision with root package name */
    private int f533k = 4096;

    /* JADX INFO: renamed from: m, reason: collision with root package name */
    private int f535m = 0;

    /* JADX INFO: renamed from: t, reason: collision with root package name */
    private ColorStateList f542t = null;

    /* JADX INFO: renamed from: u, reason: collision with root package name */
    private PorterDuff.Mode f543u = null;

    /* JADX INFO: renamed from: v, reason: collision with root package name */
    private boolean f544v = false;

    /* JADX INFO: renamed from: w, reason: collision with root package name */
    private boolean f545w = false;

    /* JADX INFO: renamed from: x, reason: collision with root package name */
    private boolean f546x = false;

    /* JADX INFO: renamed from: y, reason: collision with root package name */
    private int f547y = 16;
    private boolean D = false;

    /* JADX INFO: compiled from: MenuItemImpl.java */
    class a implements b.InterfaceC0023b {
        a() {
        }

        @Override // androidx.core.view.b.InterfaceC0023b
        public void onActionProviderVisibilityChanged(boolean z2) {
            i iVar = i.this;
            iVar.f536n.J(iVar);
        }
    }

    i(g gVar, int i3, int i4, int i5, int i6, CharSequence charSequence, int i7) {
        this.f548z = 0;
        this.f536n = gVar;
        this.f523a = i4;
        this.f524b = i3;
        this.f525c = i5;
        this.f526d = i6;
        this.f527e = charSequence;
        this.f548z = i7;
    }

    private static void d(StringBuilder sb, int i3, int i4, String str) {
        if ((i3 & i4) == i4) {
            sb.append(str);
        }
    }

    private Drawable e(Drawable drawable) {
        if (drawable != null && this.f546x && (this.f544v || this.f545w)) {
            drawable = androidx.core.graphics.drawable.a.r(drawable).mutate();
            if (this.f544v) {
                androidx.core.graphics.drawable.a.o(drawable, this.f542t);
            }
            if (this.f545w) {
                androidx.core.graphics.drawable.a.p(drawable, this.f543u);
            }
            this.f546x = false;
        }
        return drawable;
    }

    public boolean A() {
        return (this.f548z & 4) == 4;
    }

    @Override // s.b
    public s.b a(androidx.core.view.b bVar) {
        androidx.core.view.b bVar2 = this.B;
        if (bVar2 != null) {
            bVar2.h();
        }
        this.A = null;
        this.B = bVar;
        this.f536n.K(true);
        androidx.core.view.b bVar3 = this.B;
        if (bVar3 != null) {
            bVar3.j(new a());
        }
        return this;
    }

    @Override // s.b
    public androidx.core.view.b b() {
        return this.B;
    }

    public void c() {
        this.f536n.I(this);
    }

    @Override // s.b, android.view.MenuItem
    public boolean collapseActionView() {
        if ((this.f548z & 8) == 0) {
            return false;
        }
        if (this.A == null) {
            return true;
        }
        MenuItem.OnActionExpandListener onActionExpandListener = this.C;
        if (onActionExpandListener == null || onActionExpandListener.onMenuItemActionCollapse(this)) {
            return this.f536n.f(this);
        }
        return false;
    }

    @Override // s.b, android.view.MenuItem
    public boolean expandActionView() {
        if (!j()) {
            return false;
        }
        MenuItem.OnActionExpandListener onActionExpandListener = this.C;
        if (onActionExpandListener == null || onActionExpandListener.onMenuItemActionExpand(this)) {
            return this.f536n.k(this);
        }
        return false;
    }

    public int f() {
        return this.f526d;
    }

    char g() {
        return this.f536n.G() ? this.f532j : this.f530h;
    }

    @Override // android.view.MenuItem
    public ActionProvider getActionProvider() {
        throw new UnsupportedOperationException("This is not supported, use MenuItemCompat.getActionProvider()");
    }

    @Override // s.b, android.view.MenuItem
    public View getActionView() {
        View view = this.A;
        if (view != null) {
            return view;
        }
        androidx.core.view.b bVar = this.B;
        if (bVar == null) {
            return null;
        }
        View viewD = bVar.d(this);
        this.A = viewD;
        return viewD;
    }

    @Override // s.b, android.view.MenuItem
    public int getAlphabeticModifiers() {
        return this.f533k;
    }

    @Override // android.view.MenuItem
    public char getAlphabeticShortcut() {
        return this.f532j;
    }

    @Override // s.b, android.view.MenuItem
    public CharSequence getContentDescription() {
        return this.f540r;
    }

    @Override // android.view.MenuItem
    public int getGroupId() {
        return this.f524b;
    }

    @Override // android.view.MenuItem
    public Drawable getIcon() {
        Drawable drawable = this.f534l;
        if (drawable != null) {
            return e(drawable);
        }
        if (this.f535m == 0) {
            return null;
        }
        Drawable drawableB = d.a.b(this.f536n.u(), this.f535m);
        this.f535m = 0;
        this.f534l = drawableB;
        return e(drawableB);
    }

    @Override // s.b, android.view.MenuItem
    public ColorStateList getIconTintList() {
        return this.f542t;
    }

    @Override // s.b, android.view.MenuItem
    public PorterDuff.Mode getIconTintMode() {
        return this.f543u;
    }

    @Override // android.view.MenuItem
    public Intent getIntent() {
        return this.f529g;
    }

    @Override // android.view.MenuItem
    @ViewDebug.CapturedViewProperty
    public int getItemId() {
        return this.f523a;
    }

    @Override // android.view.MenuItem
    public ContextMenu.ContextMenuInfo getMenuInfo() {
        return this.E;
    }

    @Override // s.b, android.view.MenuItem
    public int getNumericModifiers() {
        return this.f531i;
    }

    @Override // android.view.MenuItem
    public char getNumericShortcut() {
        return this.f530h;
    }

    @Override // android.view.MenuItem
    public int getOrder() {
        return this.f525c;
    }

    @Override // android.view.MenuItem
    public SubMenu getSubMenu() {
        return this.f537o;
    }

    @Override // android.view.MenuItem
    @ViewDebug.CapturedViewProperty
    public CharSequence getTitle() {
        return this.f527e;
    }

    @Override // android.view.MenuItem
    public CharSequence getTitleCondensed() {
        CharSequence charSequence = this.f528f;
        if (charSequence == null) {
            charSequence = this.f527e;
        }
        return (Build.VERSION.SDK_INT >= 18 || charSequence == null || (charSequence instanceof String)) ? charSequence : charSequence.toString();
    }

    @Override // s.b, android.view.MenuItem
    public CharSequence getTooltipText() {
        return this.f541s;
    }

    String h() {
        char cG = g();
        if (cG == 0) {
            return "";
        }
        Resources resources = this.f536n.u().getResources();
        StringBuilder sb = new StringBuilder();
        if (ViewConfiguration.get(this.f536n.u()).hasPermanentMenuKey()) {
            sb.append(resources.getString(c.h.f3282k));
        }
        int i3 = this.f536n.G() ? this.f533k : this.f531i;
        d(sb, i3, 65536, resources.getString(c.h.f3278g));
        d(sb, i3, 4096, resources.getString(c.h.f3274c));
        d(sb, i3, 2, resources.getString(c.h.f3273b));
        d(sb, i3, 1, resources.getString(c.h.f3279h));
        d(sb, i3, 4, resources.getString(c.h.f3281j));
        d(sb, i3, 8, resources.getString(c.h.f3277f));
        if (cG == '\b') {
            sb.append(resources.getString(c.h.f3275d));
        } else if (cG == '\n') {
            sb.append(resources.getString(c.h.f3276e));
        } else if (cG != ' ') {
            sb.append(cG);
        } else {
            sb.append(resources.getString(c.h.f3280i));
        }
        return sb.toString();
    }

    @Override // android.view.MenuItem
    public boolean hasSubMenu() {
        return this.f537o != null;
    }

    CharSequence i(n.a aVar) {
        return (aVar == null || !aVar.d()) ? getTitle() : getTitleCondensed();
    }

    @Override // s.b, android.view.MenuItem
    public boolean isActionViewExpanded() {
        return this.D;
    }

    @Override // android.view.MenuItem
    public boolean isCheckable() {
        return (this.f547y & 1) == 1;
    }

    @Override // android.view.MenuItem
    public boolean isChecked() {
        return (this.f547y & 2) == 2;
    }

    @Override // android.view.MenuItem
    public boolean isEnabled() {
        return (this.f547y & 16) != 0;
    }

    @Override // android.view.MenuItem
    public boolean isVisible() {
        androidx.core.view.b bVar = this.B;
        return (bVar == null || !bVar.g()) ? (this.f547y & 8) == 0 : (this.f547y & 8) == 0 && this.B.b();
    }

    public boolean j() {
        androidx.core.view.b bVar;
        if ((this.f548z & 8) == 0) {
            return false;
        }
        if (this.A == null && (bVar = this.B) != null) {
            this.A = bVar.d(this);
        }
        return this.A != null;
    }

    public boolean k() {
        MenuItem.OnMenuItemClickListener onMenuItemClickListener = this.f539q;
        if (onMenuItemClickListener != null && onMenuItemClickListener.onMenuItemClick(this)) {
            return true;
        }
        g gVar = this.f536n;
        if (gVar.h(gVar, this)) {
            return true;
        }
        Runnable runnable = this.f538p;
        if (runnable != null) {
            runnable.run();
            return true;
        }
        if (this.f529g != null) {
            try {
                this.f536n.u().startActivity(this.f529g);
                return true;
            } catch (ActivityNotFoundException e3) {
                Log.e("MenuItemImpl", "Can't find activity to handle intent; ignoring", e3);
            }
        }
        androidx.core.view.b bVar = this.B;
        return bVar != null && bVar.e();
    }

    public boolean l() {
        return (this.f547y & 32) == 32;
    }

    public boolean m() {
        return (this.f547y & 4) != 0;
    }

    public boolean n() {
        return (this.f548z & 1) == 1;
    }

    @Override // s.b, android.view.MenuItem
    /* JADX INFO: renamed from: o, reason: merged with bridge method [inline-methods] */
    public s.b setActionView(int i3) {
        Context contextU = this.f536n.u();
        setActionView(LayoutInflater.from(contextU).inflate(i3, (ViewGroup) new LinearLayout(contextU), false));
        return this;
    }

    @Override // s.b, android.view.MenuItem
    /* JADX INFO: renamed from: p, reason: merged with bridge method [inline-methods] */
    public s.b setActionView(View view) {
        int i3;
        this.A = view;
        this.B = null;
        if (view != null && view.getId() == -1 && (i3 = this.f523a) > 0) {
            view.setId(i3);
        }
        this.f536n.I(this);
        return this;
    }

    public void q(boolean z2) {
        this.D = z2;
        this.f536n.K(false);
    }

    void r(boolean z2) {
        int i3 = this.f547y;
        int i4 = (z2 ? 2 : 0) | (i3 & (-3));
        this.f547y = i4;
        if (i3 != i4) {
            this.f536n.K(false);
        }
    }

    public boolean requiresActionButton() {
        return (this.f548z & 2) == 2;
    }

    public boolean requiresOverflow() {
        return (requiresActionButton() || n()) ? false : true;
    }

    public void s(boolean z2) {
        this.f547y = (z2 ? 4 : 0) | (this.f547y & (-5));
    }

    @Override // android.view.MenuItem
    public MenuItem setActionProvider(ActionProvider actionProvider) {
        throw new UnsupportedOperationException("This is not supported, use MenuItemCompat.setActionProvider()");
    }

    @Override // android.view.MenuItem
    public MenuItem setAlphabeticShortcut(char c3) {
        if (this.f532j == c3) {
            return this;
        }
        this.f532j = Character.toLowerCase(c3);
        this.f536n.K(false);
        return this;
    }

    @Override // android.view.MenuItem
    public MenuItem setCheckable(boolean z2) {
        int i3 = this.f547y;
        int i4 = (z2 ? 1 : 0) | (i3 & (-2));
        this.f547y = i4;
        if (i3 != i4) {
            this.f536n.K(false);
        }
        return this;
    }

    @Override // android.view.MenuItem
    public MenuItem setChecked(boolean z2) {
        if ((this.f547y & 4) != 0) {
            this.f536n.T(this);
        } else {
            r(z2);
        }
        return this;
    }

    @Override // android.view.MenuItem
    public MenuItem setEnabled(boolean z2) {
        if (z2) {
            this.f547y |= 16;
        } else {
            this.f547y &= -17;
        }
        this.f536n.K(false);
        return this;
    }

    @Override // android.view.MenuItem
    public MenuItem setIcon(Drawable drawable) {
        this.f535m = 0;
        this.f534l = drawable;
        this.f546x = true;
        this.f536n.K(false);
        return this;
    }

    @Override // s.b, android.view.MenuItem
    public MenuItem setIconTintList(ColorStateList colorStateList) {
        this.f542t = colorStateList;
        this.f544v = true;
        this.f546x = true;
        this.f536n.K(false);
        return this;
    }

    @Override // s.b, android.view.MenuItem
    public MenuItem setIconTintMode(PorterDuff.Mode mode) {
        this.f543u = mode;
        this.f545w = true;
        this.f546x = true;
        this.f536n.K(false);
        return this;
    }

    @Override // android.view.MenuItem
    public MenuItem setIntent(Intent intent) {
        this.f529g = intent;
        return this;
    }

    @Override // android.view.MenuItem
    public MenuItem setNumericShortcut(char c3) {
        if (this.f530h == c3) {
            return this;
        }
        this.f530h = c3;
        this.f536n.K(false);
        return this;
    }

    @Override // android.view.MenuItem
    public MenuItem setOnActionExpandListener(MenuItem.OnActionExpandListener onActionExpandListener) {
        this.C = onActionExpandListener;
        return this;
    }

    @Override // android.view.MenuItem
    public MenuItem setOnMenuItemClickListener(MenuItem.OnMenuItemClickListener onMenuItemClickListener) {
        this.f539q = onMenuItemClickListener;
        return this;
    }

    @Override // android.view.MenuItem
    public MenuItem setShortcut(char c3, char c4) {
        this.f530h = c3;
        this.f532j = Character.toLowerCase(c4);
        this.f536n.K(false);
        return this;
    }

    @Override // s.b, android.view.MenuItem
    public void setShowAsAction(int i3) {
        int i4 = i3 & 3;
        if (i4 != 0 && i4 != 1 && i4 != 2) {
            throw new IllegalArgumentException("SHOW_AS_ACTION_ALWAYS, SHOW_AS_ACTION_IF_ROOM, and SHOW_AS_ACTION_NEVER are mutually exclusive.");
        }
        this.f548z = i3;
        this.f536n.I(this);
    }

    @Override // android.view.MenuItem
    public MenuItem setTitle(CharSequence charSequence) {
        this.f527e = charSequence;
        this.f536n.K(false);
        r rVar = this.f537o;
        if (rVar != null) {
            rVar.setHeaderTitle(charSequence);
        }
        return this;
    }

    @Override // android.view.MenuItem
    public MenuItem setTitleCondensed(CharSequence charSequence) {
        this.f528f = charSequence;
        this.f536n.K(false);
        return this;
    }

    @Override // android.view.MenuItem
    public MenuItem setVisible(boolean z2) {
        if (x(z2)) {
            this.f536n.J(this);
        }
        return this;
    }

    public void t(boolean z2) {
        if (z2) {
            this.f547y |= 32;
        } else {
            this.f547y &= -33;
        }
    }

    public String toString() {
        CharSequence charSequence = this.f527e;
        if (charSequence != null) {
            return charSequence.toString();
        }
        return null;
    }

    void u(ContextMenu.ContextMenuInfo contextMenuInfo) {
        this.E = contextMenuInfo;
    }

    @Override // s.b, android.view.MenuItem
    /* JADX INFO: renamed from: v, reason: merged with bridge method [inline-methods] */
    public s.b setShowAsActionFlags(int i3) {
        setShowAsAction(i3);
        return this;
    }

    public void w(r rVar) {
        this.f537o = rVar;
        rVar.setHeaderTitle(getTitle());
    }

    boolean x(boolean z2) {
        int i3 = this.f547y;
        int i4 = (z2 ? 0 : 8) | (i3 & (-9));
        this.f547y = i4;
        return i3 != i4;
    }

    public boolean y() {
        return this.f536n.A();
    }

    boolean z() {
        return this.f536n.H() && g() != 0;
    }

    @Override // android.view.MenuItem
    public s.b setContentDescription(CharSequence charSequence) {
        this.f540r = charSequence;
        this.f536n.K(false);
        return this;
    }

    @Override // android.view.MenuItem
    public s.b setTooltipText(CharSequence charSequence) {
        this.f541s = charSequence;
        this.f536n.K(false);
        return this;
    }

    @Override // s.b, android.view.MenuItem
    public MenuItem setAlphabeticShortcut(char c3, int i3) {
        if (this.f532j == c3 && this.f533k == i3) {
            return this;
        }
        this.f532j = Character.toLowerCase(c3);
        this.f533k = KeyEvent.normalizeMetaState(i3);
        this.f536n.K(false);
        return this;
    }

    @Override // s.b, android.view.MenuItem
    public MenuItem setNumericShortcut(char c3, int i3) {
        if (this.f530h == c3 && this.f531i == i3) {
            return this;
        }
        this.f530h = c3;
        this.f531i = KeyEvent.normalizeMetaState(i3);
        this.f536n.K(false);
        return this;
    }

    @Override // s.b, android.view.MenuItem
    public MenuItem setShortcut(char c3, char c4, int i3, int i4) {
        this.f530h = c3;
        this.f531i = KeyEvent.normalizeMetaState(i3);
        this.f532j = Character.toLowerCase(c4);
        this.f533k = KeyEvent.normalizeMetaState(i4);
        this.f536n.K(false);
        return this;
    }

    @Override // android.view.MenuItem
    public MenuItem setIcon(int i3) {
        this.f534l = null;
        this.f535m = i3;
        this.f546x = true;
        this.f536n.K(false);
        return this;
    }

    @Override // android.view.MenuItem
    public MenuItem setTitle(int i3) {
        return setTitle(this.f536n.u().getString(i3));
    }
}
