public boolean performItemAction(MenuItem item, int flags) {
    MenuItemImpl itemImpl = (MenuItemImpl) item;

    if (itemImpl == null || !itemImpl.isEnabled()) {
      return false;
    }

    boolean invoked = itemImpl.invoke();

    // if (itemImpl.hasCollapsibleActionView()) {
    //    invoked |= itemImpl.expandActionView();
    //    if (invoked) close(true);
    // } else
    if (item.hasSubMenu()) {
      close(false);

      final SubMenuBuilder subMenu = (SubMenuBuilder) item.getSubMenu();
      final ActionProvider provider = item.getActionProvider();
      if (provider != null && provider.hasSubMenu()) {
        provider.onPrepareSubMenu(subMenu);
      }
      invoked |= dispatchSubMenuSelected(subMenu);
      if (!invoked) close(true);
    } else {
      if ((flags & FLAG_PERFORM_NO_CLOSE) == 0) {
        close(true);
      }
    }

    return invoked;
  }
  /**
   * Invokes the item by calling various listeners or callbacks.
   *
   * @return true if the invocation was handled, false otherwise
   */
  public boolean invoke() {
    if (mClickListener != null && mClickListener.onMenuItemClick(this)) {
      return true;
    }

    if (mMenu.dispatchMenuItemSelected(mMenu.getRootMenu(), this)) {
      return true;
    }

    if (mItemCallback != null) {
      mItemCallback.run();
      return true;
    }

    if (mIntent != null) {
      try {
        mMenu.getContext().startActivity(mIntent);
        return true;
      } catch (ActivityNotFoundException e) {
        Log.e(TAG, "Can't find activity to handle intent; ignoring", e);
      }
    }

    if (mActionProvider != null && mActionProvider.onPerformDefaultAction()) {
      return true;
    }

    return false;
  }
 public boolean hasCollapsibleActionView() {
   if ((mShowAsAction & SHOW_AS_ACTION_COLLAPSE_ACTION_VIEW) != 0) {
     if (mActionView == null && mActionProvider != null) {
       mActionView = mActionProvider.onCreateActionView(this);
     }
     return mActionView != null;
   }
   return false;
 }
 public MenuItem setActionProvider(ActionProvider actionProvider) {
   if (mActionProvider != null) {
     mActionProvider.setVisibilityListener(null);
   }
   mActionView = null;
   mActionProvider = actionProvider;
   mMenu.onItemsChanged(true); // Measurement can be changed
   if (mActionProvider != null) {
     mActionProvider.setVisibilityListener(
         new ActionProvider.VisibilityListener() {
           @Override
           public void onActionProviderVisibilityChanged(boolean isVisible) {
             mMenu.onItemVisibleChanged(MenuItemImpl.this);
           }
         });
   }
   return this;
 }
 public View getActionView() {
   if (mActionView != null) {
     return mActionView;
   } else if (mActionProvider != null) {
     mActionView = mActionProvider.onCreateActionView();
     return mActionView;
   } else {
     return null;
   }
 }
 public boolean isVisible() {
   if (mActionProvider != null && mActionProvider.overridesItemVisibility()) {
     return (mFlags & HIDDEN) == 0 && mActionProvider.isVisible();
   }
   return (mFlags & HIDDEN) == 0;
 }