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.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.ViewGroup;
import android.widget.LinearLayout;
import androidx.appcompat.view.menu.k;
import androidx.core.view.b;

/* loaded from: classes.dex */
public final class g implements n3.b {
    private View A;
    private androidx.core.view.b B;
    private MenuItem.OnActionExpandListener C;
    private ContextMenu.ContextMenuInfo E;

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

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

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

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

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

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

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

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

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

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

    /* renamed from: n, reason: collision with root package name */
    e f751n;

    /* renamed from: o, reason: collision with root package name */
    private m f752o;

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    /* loaded from: classes.dex */
    class a implements b.InterfaceC0102b {
        a() {
        }

        @Override // androidx.core.view.b.InterfaceC0102b
        public void onActionProviderVisibilityChanged(boolean z10) {
            g gVar = g.this;
            gVar.f751n.L(gVar);
        }
    }

    /* JADX INFO: Access modifiers changed from: package-private */
    public g(e eVar, int i10, int i11, int i12, int i13, CharSequence charSequence, int i14) {
        this.f751n = eVar;
        this.f738a = i11;
        this.f739b = i10;
        this.f740c = i12;
        this.f741d = i13;
        this.f742e = charSequence;
        this.f763z = i14;
    }

    private static void d(StringBuilder sb2, int i10, int i11, String str) {
        if ((i10 & i11) == i11) {
            sb2.append(str);
        }
    }

    private Drawable e(Drawable drawable) {
        if (drawable != null && this.f761x && (this.f759v || this.f760w)) {
            drawable = androidx.core.graphics.drawable.a.l(drawable).mutate();
            if (this.f759v) {
                androidx.core.graphics.drawable.a.i(drawable, this.f757t);
            }
            if (this.f760w) {
                androidx.core.graphics.drawable.a.j(drawable, this.f758u);
            }
            this.f761x = false;
        }
        return drawable;
    }

    /* JADX INFO: Access modifiers changed from: package-private */
    public boolean A() {
        return this.f751n.J() && g() != 0;
    }

    public boolean B() {
        return (this.f763z & 4) == 4;
    }

    @Override // n3.b
    public n3.b a(androidx.core.view.b bVar) {
        androidx.core.view.b bVar2 = this.B;
        if (bVar2 != null) {
            bVar2.g();
        }
        this.A = null;
        this.B = bVar;
        this.f751n.M(true);
        androidx.core.view.b bVar3 = this.B;
        if (bVar3 != null) {
            bVar3.i(new a());
        }
        return this;
    }

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

    public void c() {
        this.f751n.K(this);
    }

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

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

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

    /* JADX INFO: Access modifiers changed from: package-private */
    public char g() {
        return this.f751n.I() ? this.f747j : this.f745h;
    }

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

    @Override // n3.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 c10 = bVar.c(this);
        this.A = c10;
        return c10;
    }

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

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

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

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

    @Override // android.view.MenuItem
    public Drawable getIcon() {
        Drawable drawable = this.f749l;
        if (drawable != null) {
            return e(drawable);
        }
        if (this.f750m == 0) {
            return null;
        }
        Drawable b10 = j.a.b(this.f751n.w(), this.f750m);
        this.f750m = 0;
        this.f749l = b10;
        return e(b10);
    }

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

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

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

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

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

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

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

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

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

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

    @Override // android.view.MenuItem
    public CharSequence getTitleCondensed() {
        CharSequence charSequence = this.f743f;
        return charSequence != null ? charSequence : this.f742e;
    }

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

    /* JADX INFO: Access modifiers changed from: package-private */
    public String h() {
        char g10 = g();
        if (g10 == 0) {
            return "";
        }
        Resources resources = this.f751n.w().getResources();
        StringBuilder sb2 = new StringBuilder();
        if (ViewConfiguration.get(this.f751n.w()).hasPermanentMenuKey()) {
            sb2.append(resources.getString(h.h.f20274m));
        }
        int i10 = this.f751n.I() ? this.f748k : this.f746i;
        d(sb2, i10, 65536, resources.getString(h.h.f20270i));
        d(sb2, i10, 4096, resources.getString(h.h.f20266e));
        d(sb2, i10, 2, resources.getString(h.h.f20265d));
        d(sb2, i10, 1, resources.getString(h.h.f20271j));
        d(sb2, i10, 4, resources.getString(h.h.f20273l));
        d(sb2, i10, 8, resources.getString(h.h.f20269h));
        if (g10 == '\b') {
            sb2.append(resources.getString(h.h.f20267f));
        } else if (g10 == '\n') {
            sb2.append(resources.getString(h.h.f20268g));
        } else if (g10 != ' ') {
            sb2.append(g10);
        } else {
            sb2.append(resources.getString(h.h.f20272k));
        }
        return sb2.toString();
    }

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

    /* JADX INFO: Access modifiers changed from: package-private */
    public CharSequence i(k.a aVar) {
        return (aVar == null || !aVar.d()) ? getTitle() : getTitleCondensed();
    }

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

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

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

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

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

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

    public boolean k() {
        MenuItem.OnMenuItemClickListener onMenuItemClickListener = this.f754q;
        if (onMenuItemClickListener != null && onMenuItemClickListener.onMenuItemClick(this)) {
            return true;
        }
        e eVar = this.f751n;
        if (eVar.h(eVar, this)) {
            return true;
        }
        Runnable runnable = this.f753p;
        if (runnable != null) {
            runnable.run();
            return true;
        }
        if (this.f744g != null) {
            try {
                this.f751n.w().startActivity(this.f744g);
                return true;
            } catch (ActivityNotFoundException e10) {
                Log.e("MenuItemImpl", "Can't find activity to handle intent; ignoring", e10);
            }
        }
        androidx.core.view.b bVar = this.B;
        return bVar != null && bVar.d();
    }

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

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

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

    public boolean o() {
        return (this.f763z & 2) == 2;
    }

    @Override // n3.b, android.view.MenuItem
    /* renamed from: p, reason: merged with bridge method [inline-methods] */
    public n3.b setActionView(int i10) {
        Context w10 = this.f751n.w();
        setActionView(LayoutInflater.from(w10).inflate(i10, (ViewGroup) new LinearLayout(w10), false));
        return this;
    }

    @Override // n3.b, android.view.MenuItem
    /* renamed from: q, reason: merged with bridge method [inline-methods] */
    public n3.b setActionView(View view) {
        int i10;
        this.A = view;
        this.B = null;
        if (view != null && view.getId() == -1 && (i10 = this.f738a) > 0) {
            view.setId(i10);
        }
        this.f751n.K(this);
        return this;
    }

    public void r(boolean z10) {
        this.D = z10;
        this.f751n.M(false);
    }

    /* JADX INFO: Access modifiers changed from: package-private */
    public void s(boolean z10) {
        int i10 = this.f762y;
        int i11 = (z10 ? 2 : 0) | (i10 & (-3));
        this.f762y = i11;
        if (i10 != i11) {
            this.f751n.M(false);
        }
    }

    @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 c10) {
        if (this.f747j == c10) {
            return this;
        }
        this.f747j = Character.toLowerCase(c10);
        this.f751n.M(false);
        return this;
    }

    @Override // android.view.MenuItem
    public MenuItem setCheckable(boolean z10) {
        int i10 = this.f762y;
        int i11 = (z10 ? 1 : 0) | (i10 & (-2));
        this.f762y = i11;
        if (i10 != i11) {
            this.f751n.M(false);
        }
        return this;
    }

    @Override // android.view.MenuItem
    public MenuItem setChecked(boolean z10) {
        if ((this.f762y & 4) != 0) {
            this.f751n.X(this);
        } else {
            s(z10);
        }
        return this;
    }

    @Override // android.view.MenuItem
    public MenuItem setEnabled(boolean z10) {
        if (z10) {
            this.f762y |= 16;
        } else {
            this.f762y &= -17;
        }
        this.f751n.M(false);
        return this;
    }

    @Override // android.view.MenuItem
    public MenuItem setIcon(Drawable drawable) {
        this.f750m = 0;
        this.f749l = drawable;
        this.f761x = true;
        this.f751n.M(false);
        return this;
    }

    @Override // n3.b, android.view.MenuItem
    public MenuItem setIconTintList(ColorStateList colorStateList) {
        this.f757t = colorStateList;
        this.f759v = true;
        this.f761x = true;
        this.f751n.M(false);
        return this;
    }

    @Override // n3.b, android.view.MenuItem
    public MenuItem setIconTintMode(PorterDuff.Mode mode) {
        this.f758u = mode;
        this.f760w = true;
        this.f761x = true;
        this.f751n.M(false);
        return this;
    }

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

    @Override // android.view.MenuItem
    public MenuItem setNumericShortcut(char c10) {
        if (this.f745h == c10) {
            return this;
        }
        this.f745h = c10;
        this.f751n.M(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.f754q = onMenuItemClickListener;
        return this;
    }

    @Override // android.view.MenuItem
    public MenuItem setShortcut(char c10, char c11) {
        this.f745h = c10;
        this.f747j = Character.toLowerCase(c11);
        this.f751n.M(false);
        return this;
    }

    @Override // n3.b, android.view.MenuItem
    public void setShowAsAction(int i10) {
        int i11 = i10 & 3;
        if (i11 != 0 && i11 != 1 && i11 != 2) {
            throw new IllegalArgumentException("SHOW_AS_ACTION_ALWAYS, SHOW_AS_ACTION_IF_ROOM, and SHOW_AS_ACTION_NEVER are mutually exclusive.");
        }
        this.f763z = i10;
        this.f751n.K(this);
    }

    @Override // android.view.MenuItem
    public MenuItem setTitle(CharSequence charSequence) {
        this.f742e = charSequence;
        this.f751n.M(false);
        m mVar = this.f752o;
        if (mVar != null) {
            mVar.setHeaderTitle(charSequence);
        }
        return this;
    }

    @Override // android.view.MenuItem
    public MenuItem setTitleCondensed(CharSequence charSequence) {
        this.f743f = charSequence;
        this.f751n.M(false);
        return this;
    }

    @Override // android.view.MenuItem
    public MenuItem setVisible(boolean z10) {
        if (y(z10)) {
            this.f751n.L(this);
        }
        return this;
    }

    public void t(boolean z10) {
        this.f762y = (z10 ? 4 : 0) | (this.f762y & (-5));
    }

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

    public void u(boolean z10) {
        if (z10) {
            this.f762y |= 32;
        } else {
            this.f762y &= -33;
        }
    }

    /* JADX INFO: Access modifiers changed from: package-private */
    public void v(ContextMenu.ContextMenuInfo contextMenuInfo) {
        this.E = contextMenuInfo;
    }

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

    public void x(m mVar) {
        this.f752o = mVar;
        mVar.setHeaderTitle(getTitle());
    }

    /* JADX INFO: Access modifiers changed from: package-private */
    public boolean y(boolean z10) {
        int i10 = this.f762y;
        int i11 = (z10 ? 0 : 8) | (i10 & (-9));
        this.f762y = i11;
        return i10 != i11;
    }

    public boolean z() {
        return this.f751n.C();
    }

    @Override // android.view.MenuItem
    public n3.b setContentDescription(CharSequence charSequence) {
        this.f755r = charSequence;
        this.f751n.M(false);
        return this;
    }

    @Override // android.view.MenuItem
    public n3.b setTooltipText(CharSequence charSequence) {
        this.f756s = charSequence;
        this.f751n.M(false);
        return this;
    }

    @Override // n3.b, android.view.MenuItem
    public MenuItem setAlphabeticShortcut(char c10, int i10) {
        if (this.f747j == c10 && this.f748k == i10) {
            return this;
        }
        this.f747j = Character.toLowerCase(c10);
        this.f748k = KeyEvent.normalizeMetaState(i10);
        this.f751n.M(false);
        return this;
    }

    @Override // n3.b, android.view.MenuItem
    public MenuItem setNumericShortcut(char c10, int i10) {
        if (this.f745h == c10 && this.f746i == i10) {
            return this;
        }
        this.f745h = c10;
        this.f746i = KeyEvent.normalizeMetaState(i10);
        this.f751n.M(false);
        return this;
    }

    @Override // n3.b, android.view.MenuItem
    public MenuItem setShortcut(char c10, char c11, int i10, int i11) {
        this.f745h = c10;
        this.f746i = KeyEvent.normalizeMetaState(i10);
        this.f747j = Character.toLowerCase(c11);
        this.f748k = KeyEvent.normalizeMetaState(i11);
        this.f751n.M(false);
        return this;
    }

    @Override // android.view.MenuItem
    public MenuItem setIcon(int i10) {
        this.f749l = null;
        this.f750m = i10;
        this.f761x = true;
        this.f751n.M(false);
        return this;
    }

    @Override // android.view.MenuItem
    public MenuItem setTitle(int i10) {
        return setTitle(this.f751n.w().getString(i10));
    }
}
