content: 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.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.widget.LinearLayout;
  import androidx.appcompat.R;
  import androidx.appcompat.content.res.AppCompatResources;
  import androidx.appcompat.view.menu.MenuView;
  import androidx.core.graphics.drawable.DrawableCompat;
  import androidx.core.internal.view.SupportMenuItem;
  import androidx.core.view.ActionProvider;
  import okhttp3.HttpUrl;
  
  public final class MenuItemImpl implements SupportMenuItem {
      private static final int CHECKABLE = 1;
      private static final int CHECKED = 2;
      private static final int ENABLED = 16;
      private static final int EXCLUSIVE = 4;
      private static final int HIDDEN = 8;
      private static final int IS_ACTION = 32;
      static final int NO_ICON = 0;
      private static final int SHOW_AS_ACTION_MASK = 3;
      private static final String TAG = "MenuItemImpl";
      private ActionProvider mActionProvider;
      private View mActionView;
      private final int mCategoryOrder;
      private MenuItem.OnMenuItemClickListener mClickListener;
      private CharSequence mContentDescription;
      private int mFlags = 16;
      private final int mGroup;
      private boolean mHasIconTint = false;
      private boolean mHasIconTintMode = false;
      private Drawable mIconDrawable;
      private int mIconResId = 0;
      private ColorStateList mIconTintList = null;
      private PorterDuff.Mode mIconTintMode = null;
      private final int mId;
      private Intent mIntent;
      private boolean mIsActionViewExpanded = false;
      private Runnable mItemCallback;
      MenuBuilder mMenu;
      private ContextMenu.ContextMenuInfo mMenuInfo;
      private boolean mNeedToApplyIconTint = false;
      private MenuItem.OnActionExpandListener mOnActionExpandListener;
      private final int mOrdering;
      private char mShortcutAlphabeticChar;
      private int mShortcutAlphabeticModifiers = 4096;
      private char mShortcutNumericChar;
      private int mShortcutNumericModifiers = 4096;
      private int mShowAsAction = 0;
      private SubMenuBuilder mSubMenu;
      private CharSequence mTitle;
      private CharSequence mTitleCondensed;
      private CharSequence mTooltipText;
  
      MenuItemImpl(MenuBuilder menu, int group, int id, int categoryOrder, int ordering, CharSequence title, int showAsAction) {
          this.mMenu = menu;
          this.mId = id;
          this.mGroup = group;
          this.mCategoryOrder = categoryOrder;
          this.mOrdering = ordering;
          this.mTitle = title;
          this.mShowAsAction = showAsAction;
      }
  
      private static void appendModifier(StringBuilder sb, int modifiers, int flag, String label) {
          if ((modifiers & flag) == flag) {
              sb.append(label);
          }
      }
  
      private Drawable applyIconTintIfNecessary(Drawable icon) {
          if (icon != null && this.mNeedToApplyIconTint && (this.mHasIconTint || this.mHasIconTintMode)) {
              icon = DrawableCompat.wrap(icon).mutate();
              if (this.mHasIconTint) {
                  DrawableCompat.setTintList(icon, this.mIconTintList);
              }
              if (this.mHasIconTintMode) {
                  DrawableCompat.setTintMode(icon, this.mIconTintMode);
              }
              this.mNeedToApplyIconTint = false;
          }
          return icon;
      }
  
      public void actionFormatChanged() {
          this.mMenu.onItemActionRequestChanged(this);
      }
  
      public boolean collapseActionView() {
          if ((this.mShowAsAction & 8) == 0) {
              return false;
          }
          if (this.mActionView == null) {
              return true;
          }
          MenuItem.OnActionExpandListener onActionExpandListener = this.mOnActionExpandListener;
          if (onActionExpandListener == null || onActionExpandListener.onMenuItemActionCollapse(this)) {
              return this.mMenu.collapseItemActionView(this);
          }
          return false;
      }
  
      public boolean expandActionView() {
          if (!hasCollapsibleActionView()) {
              return false;
          }
          MenuItem.OnActionExpandListener onActionExpandListener = this.mOnActionExpandListener;
          if (onActionExpandListener == null || onActionExpandListener.onMenuItemActionExpand(this)) {
              return this.mMenu.expandItemActionView(this);
          }
          return false;
      }
  
      public android.view.ActionProvider getActionProvider() {
          throw new UnsupportedOperationException("This is not supported, use MenuItemCompat.getActionProvider()");
      }
  
      public View getActionView() {
          View view = this.mActionView;
          if (view != null) {
              return view;
          }
          ActionProvider actionProvider = this.mActionProvider;
          if (actionProvider == null) {
              return null;
          }
          View onCreateActionView = actionProvider.onCreateActionView(this);
          this.mActionView = onCreateActionView;
          return onCreateActionView;
      }
  
      public int getAlphabeticModifiers() {
          return this.mShortcutAlphabeticModifiers;
      }
  
      public char getAlphabeticShortcut() {
          return this.mShortcutAlphabeticChar;
      }
  
      /* access modifiers changed from: package-private */
      public Runnable getCallback() {
          return this.mItemCallback;
      }
  
      public CharSequence getContentDescription() {
          return this.mContentDescription;
      }
  
      public int getGroupId() {
          return this.mGroup;
      }
  
      public Drawable getIcon() {
          Drawable drawable = this.mIconDrawable;
          if (drawable != null) {
              return applyIconTintIfNecessary(drawable);
          }
          if (this.mIconResId == 0) {
              return null;
          }
          Drawable drawable2 = AppCompatResources.getDrawable(this.mMenu.getContext(), this.mIconResId);
          this.mIconResId = 0;
          this.mIconDrawable = drawable2;
          return applyIconTintIfNecessary(drawable2);
      }
  
      public ColorStateList getIconTintList() {
          return this.mIconTintList;
      }
  
      public PorterDuff.Mode getIconTintMode() {
          return this.mIconTintMode;
      }
  
      public Intent getIntent() {
          return this.mIntent;
      }
  
      @ViewDebug.CapturedViewProperty
      public int getItemId() {
          return this.mId;
      }
  
      public ContextMenu.ContextMenuInfo getMenuInfo() {
          return this.mMenuInfo;
      }
  
      public int getNumericModifiers() {
          return this.mShortcutNumericModifiers;
      }
  
      public char getNumericShortcut() {
          return this.mShortcutNumericChar;
      }
  
      public int getOrder() {
          return this.mCategoryOrder;
      }
  
      public int getOrdering() {
          return this.mOrdering;
      }
  
      /* access modifiers changed from: package-private */
      public char getShortcut() {
          return this.mMenu.isQwertyMode() ? this.mShortcutAlphabeticChar : this.mShortcutNumericChar;
      }
  
      /* access modifiers changed from: package-private */
      public String getShortcutLabel() {
          char shortcut = getShortcut();
          if (shortcut == 0) {
              return HttpUrl.FRAGMENT_ENCODE_SET;
          }
          Resources resources = this.mMenu.getContext().getResources();
          StringBuilder sb = new StringBuilder();
          if (ViewConfiguration.get(this.mMenu.getContext()).hasPermanentMenuKey()) {
              sb.append(resources.getString(R.string.abc_prepend_shortcut_label));
          }
          int i = this.mMenu.isQwertyMode() ? this.mShortcutAlphabeticModifiers : this.mShortcutNumericModifiers;
          appendModifier(sb, i, 65536, resources.getString(R.string.abc_menu_meta_shortcut_label));
          appendModifier(sb, i, 4096, resources.getString(R.string.abc_menu_ctrl_shortcut_label));
          appendModifier(sb, i, 2, resources.getString(R.string.abc_menu_alt_shortcut_label));
          appendModifier(sb, i, 1, resources.getString(R.string.abc_menu_shift_shortcut_label));
          appendModifier(sb, i, 4, resources.getString(R.string.abc_menu_sym_shortcut_label));
          appendModifier(sb, i, 8, resources.getString(R.string.abc_menu_function_shortcut_label));
          switch (shortcut) {
              case 8:
                  sb.append(resources.getString(R.string.abc_menu_delete_shortcut_label));
                  break;
              case 10:
                  sb.append(resources.getString(R.string.abc_menu_enter_shortcut_label));
                  break;
              case ' ':
                  sb.append(resources.getString(R.string.abc_menu_space_shortcut_label));
                  break;
              default:
                  sb.append(shortcut);
                  break;
          }
          return sb.toString();
      }
  
      public SubMenu getSubMenu() {
          return this.mSubMenu;
      }
  
      public ActionProvider getSupportActionProvider() {
          return this.mActionProvider;
      }
  
      @ViewDebug.CapturedViewProperty
      public CharSequence getTitle() {
          return this.mTitle;
      }
  
      public CharSequence getTitleCondensed() {
          CharSequence charSequence = this.mTitleCondensed;
          if (charSequence == null) {
              charSequence = this.mTitle;
          }
          return (Build.VERSION.SDK_INT >= 18 || charSequence == null || (charSequence instanceof String)) ? charSequence : charSequence.toString();
      }
  
      /* access modifiers changed from: package-private */
      public CharSequence getTitleForItemView(MenuView.ItemView itemView) {
          return (itemView == null || !itemView.prefersCondensedTitle()) ? getTitle() : getTitleCondensed();
      }
  
      public CharSequence getTooltipText() {
          return this.mTooltipText;
      }
  
      public boolean hasCollapsibleActionView() {
          ActionProvider actionProvider;
          if ((this.mShowAsAction & 8) == 0) {
              return false;
          }
          if (this.mActionView == null && (actionProvider = this.mActionProvider) != null) {
              this.mActionView = actionProvider.onCreateActionView(this);
          }
          return this.mActionView != null;
      }
  
      public boolean hasSubMenu() {
          return this.mSubMenu != null;
      }
  
      public boolean invoke() {
          MenuItem.OnMenuItemClickListener onMenuItemClickListener = this.mClickListener;
          if (onMenuItemClickListener != null && onMenuItemClickListener.onMenuItemClick(this)) {
              return true;
          }
          MenuBuilder menuBuilder = this.mMenu;
          if (menuBuilder.dispatchMenuItemSelected(menuBuilder, this)) {
              return true;
          }
          Runnable runnable = this.mItemCallback;
          if (runnable != null) {
              runnable.run();
              return true;
          }
          if (this.mIntent != null) {
              try {
                  this.mMenu.getContext().startActivity(this.mIntent);
                  return true;
              } catch (ActivityNotFoundException e) {
                  Log.e(TAG, "Can't find activity to handle intent; ignoring", e);
              }
          }
          ActionProvider actionProvider = this.mActionProvider;
          return actionProvider != null && actionProvider.onPerformDefaultAction();
      }
  
      public boolean isActionButton() {
          return (this.mFlags & 32) == 32;
      }
  
      public boolean isActionViewExpanded() {
          return this.mIsActionViewExpanded;
      }
  
      public boolean isCheckable() {
          return (this.mFlags & 1) == 1;
      }
  
      public boolean isChecked() {
          return (this.mFlags & 2) == 2;
      }
  
      public boolean isEnabled() {
          return (this.mFlags & 16) != 0;
      }
  
      public boolean isExclusiveCheckable() {
          return (this.mFlags & 4) != 0;
      }
  
      public boolean isVisible() {
          ActionProvider actionProvider = this.mActionProvider;
          return (actionProvider == null || !actionProvider.overridesItemVisibility()) ? (this.mFlags & 8) == 0 : (this.mFlags & 8) == 0 && this.mActionProvider.isVisible();
      }
  
      public boolean requestsActionButton() {
          return (this.mShowAsAction & 1) == 1;
      }
  
      public boolean requiresActionButton() {
          return (this.mShowAsAction & 2) == 2;
      }
  
      public boolean requiresOverflow() {
          return !requiresActionButton() && !requestsActionButton();
      }
  
      public MenuItem setActionProvider(android.view.ActionProvider actionProvider) {
          throw new UnsupportedOperationException("This is not supported, use MenuItemCompat.setActionProvider()");
      }
  
      public SupportMenuItem setActionView(int resId) {
          Context context = this.mMenu.getContext();
          setActionView(LayoutInflater.from(context).inflate(resId, new LinearLayout(context), false));
          return this;
      }
  
      public SupportMenuItem setActionView(View view) {
          int i;
          this.mActionView = view;
          this.mActionProvider = null;
          if (view != null && view.getId() == -1 && (i = this.mId) > 0) {
              view.setId(i);
          }
          this.mMenu.onItemActionRequestChanged(this);
          return this;
      }
  
      public void setActionViewExpanded(boolean isExpanded) {
          this.mIsActionViewExpanded = isExpanded;
          this.mMenu.onItemsChanged(false);
      }
  
      public MenuItem setAlphabeticShortcut(char alphaChar) {
          if (this.mShortcutAlphabeticChar == alphaChar) {
              return this;
          }
          this.mShortcutAlphabeticChar = Character.toLowerCase(alphaChar);
          this.mMenu.onItemsChanged(false);
          return this;
      }
  
      public MenuItem setAlphabeticShortcut(char alphaChar, int alphaModifiers) {
          if (this.mShortcutAlphabeticChar == alphaChar && this.mShortcutAlphabeticModifiers == alphaModifiers) {
              return this;
          }
          this.mShortcutAlphabeticChar = Character.toLowerCase(alphaChar);
          this.mShortcutAlphabeticModifiers = KeyEvent.normalizeMetaState(alphaModifiers);
          this.mMenu.onItemsChanged(false);
          return this;
      }
  
      public MenuItem setCallback(Runnable callback) {
          this.mItemCallback = callback;
          return this;
      }
  
      public MenuItem setCheckable(boolean checkable) {
          int i = this.mFlags;
          boolean z = (this.mFlags & true) | checkable;
          this.mFlags = z ? 1 : 0;
          if (i != z) {
              this.mMenu.onItemsChanged(false);
          }
          return this;
      }
  
      public MenuItem setChecked(boolean checked) {
          if ((this.mFlags & 4) != 0) {
              this.mMenu.setExclusiveItemChecked(this);
          } else {
              setCheckedInt(checked);
          }
          return this;
      }
  
      /* access modifiers changed from: package-private */
      public void setCheckedInt(boolean checked) {
          int i = this.mFlags;
          int i2 = (this.mFlags & -3) | (checked ? 2 : 0);
          this.mFlags = i2;
          if (i != i2) {
              this.mMenu.onItemsChanged(false);
          }
      }
  
      public SupportMenuItem setContentDescription(CharSequence contentDescription) {
          this.mContentDescription = contentDescription;
          this.mMenu.onItemsChanged(false);
          return this;
      }
  
      public MenuItem setEnabled(boolean enabled) {
          if (enabled) {
              this.mFlags |= 16;
          } else {
              this.mFlags &= -17;
          }
          this.mMenu.onItemsChanged(false);
          return this;
      }
  
      public void setExclusiveCheckable(boolean exclusive) {
          this.mFlags = (this.mFlags & -5) | (exclusive ? 4 : 0);
      }
  
      public MenuItem setIcon(int iconResId) {
          this.mIconDrawable = null;
          this.mIconResId = iconResId;
          this.mNeedToApplyIconTint = true;
          this.mMenu.onItemsChanged(false);
          return this;
      }
  
      public MenuItem setIcon(Drawable icon) {
          this.mIconResId = 0;
          this.mIconDrawable = icon;
          this.mNeedToApplyIconTint = true;
          this.mMenu.onItemsChanged(false);
          return this;
      }
  
      public MenuItem setIconTintList(ColorStateList iconTintList) {
          this.mIconTintList = iconTintList;
          this.mHasIconTint = true;
          this.mNeedToApplyIconTint = true;
          this.mMenu.onItemsChanged(false);
          return this;
      }
  
      public MenuItem setIconTintMode(PorterDuff.Mode iconTintMode) {
          this.mIconTintMode = iconTintMode;
          this.mHasIconTintMode = true;
          this.mNeedToApplyIconTint = true;
          this.mMenu.onItemsChanged(false);
          return this;
      }
  
      public MenuItem setIntent(Intent intent) {
          this.mIntent = intent;
          return this;
      }
  
      public void setIsActionButton(boolean isActionButton) {
          if (isActionButton) {
              this.mFlags |= 32;
          } else {
              this.mFlags &= -33;
          }
      }
  
      /* access modifiers changed from: package-private */
      public void setMenuInfo(ContextMenu.ContextMenuInfo menuInfo) {
          this.mMenuInfo = menuInfo;
      }
  
      public MenuItem setNumericShortcut(char numericChar) {
          if (this.mShortcutNumericChar == numericChar) {
              return this;
          }
          this.mShortcutNumericChar = numericChar;
          this.mMenu.onItemsChanged(false);
          return this;
      }
  
      public MenuItem setNumericShortcut(char numericChar, int numericModifiers) {
          if (this.mShortcutNumericChar == numericChar && this.mShortcutNumericModifiers == numericModifiers) {
              return this;
          }
          this.mShortcutNumericChar = numericChar;
          this.mShortcutNumericModifiers = KeyEvent.normalizeMetaState(numericModifiers);
          this.mMenu.onItemsChanged(false);
          return this;
      }
  
      public MenuItem setOnActionExpandListener(MenuItem.OnActionExpandListener listener) {
          this.mOnActionExpandListener = listener;
          return this;
      }
  
      public MenuItem setOnMenuItemClickListener(MenuItem.OnMenuItemClickListener clickListener) {
          this.mClickListener = clickListener;
          return this;
      }
  
      public MenuItem setShortcut(char numericChar, char alphaChar) {
          this.mShortcutNumericChar = numericChar;
          this.mShortcutAlphabeticChar = Character.toLowerCase(alphaChar);
          this.mMenu.onItemsChanged(false);
          return this;
      }
  
      public MenuItem setShortcut(char numericChar, char alphaChar, int numericModifiers, int alphaModifiers) {
          this.mShortcutNumericChar = numericChar;
          this.mShortcutNumericModifiers = KeyEvent.normalizeMetaState(numericModifiers);
          this.mShortcutAlphabeticChar = Character.toLowerCase(alphaChar);
          this.mShortcutAlphabeticModifiers = KeyEvent.normalizeMetaState(alphaModifiers);
          this.mMenu.onItemsChanged(false);
          return this;
      }
  
      public void setShowAsAction(int actionEnum) {
          switch (actionEnum & 3) {
              case 0:
              case 1:
              case 2:
                  this.mShowAsAction = actionEnum;
                  this.mMenu.onItemActionRequestChanged(this);
                  return;
              default:
                  throw new IllegalArgumentException("SHOW_AS_ACTION_ALWAYS, SHOW_AS_ACTION_IF_ROOM, and SHOW_AS_ACTION_NEVER are mutually exclusive.");
          }
      }
  
      public SupportMenuItem setShowAsActionFlags(int actionEnum) {
          setShowAsAction(actionEnum);
          return this;
      }
  
      public void setSubMenu(SubMenuBuilder subMenu) {
          this.mSubMenu = subMenu;
          subMenu.setHeaderTitle(getTitle());
      }
  
      public SupportMenuItem setSupportActionProvider(ActionProvider actionProvider) {
          ActionProvider actionProvider2 = this.mActionProvider;
          if (actionProvider2 != null) {
              actionProvider2.reset();
          }
          this.mActionView = null;
          this.mActionProvider = actionProvider;
          this.mMenu.onItemsChanged(true);
          ActionProvider actionProvider3 = this.mActionProvider;
          if (actionProvider3 != null) {
              actionProvider3.setVisibilityListener(new ActionProvider.VisibilityListener() {
                  public void onActionProviderVisibilityChanged(boolean isVisible) {
                      MenuItemImpl.this.mMenu.onItemVisibleChanged(MenuItemImpl.this);
                  }
              });
          }
          return this;
      }
  
      public MenuItem setTitle(int title) {
          return setTitle((CharSequence) this.mMenu.getContext().getString(title));
      }
  
      public MenuItem setTitle(CharSequence title) {
          this.mTitle = title;
          this.mMenu.onItemsChanged(false);
          SubMenuBuilder subMenuBuilder = this.mSubMenu;
          if (subMenuBuilder != null) {
              subMenuBuilder.setHeaderTitle(title);
          }
          return this;
      }
  
      public MenuItem setTitleCondensed(CharSequence title) {
          this.mTitleCondensed = title;
          if (title == null) {
              CharSequence title2 = this.mTitle;
          }
          this.mMenu.onItemsChanged(false);
          return this;
      }
  
      public SupportMenuItem setTooltipText(CharSequence tooltipText) {
          this.mTooltipText = tooltipText;
          this.mMenu.onItemsChanged(false);
          return this;
      }
  
      public MenuItem setVisible(boolean shown) {
          if (setVisibleInt(shown)) {
              this.mMenu.onItemVisibleChanged(this);
          }
          return this;
      }
  
      /* access modifiers changed from: package-private */
      public boolean setVisibleInt(boolean shown) {
          int i = this.mFlags;
          int i2 = (this.mFlags & -9) | (shown ? 0 : 8);
          this.mFlags = i2;
          return i != i2;
      }
  
      public boolean shouldShowIcon() {
          return this.mMenu.getOptionalIconsVisible();
      }
  
      /* access modifiers changed from: package-private */
      public boolean shouldShowShortcut() {
          return this.mMenu.isShortcutsVisible() && getShortcut() != 0;
      }
  
      public boolean showsTextAsAction() {
          return (this.mShowAsAction & 4) == 4;
      }
  
      public String toString() {
          CharSequence charSequence = this.mTitle;
          if (charSequence != null) {
              return charSequence.toString();
          }
          return null;
      }
  }
  