public void flagActionItems(){
  if (!mIsActionItemsStale) {
    return;
  }
  boolean flagged=false;
  for (  WeakReference<MenuPresenter> ref : mPresenters) {
    final MenuPresenter presenter=ref.get();
    if (presenter == null) {
      mPresenters.remove(ref);
    }
 else {
      flagged|=presenter.flagActionItems();
    }
  }
  if (flagged) {
    mActionItems.clear();
    mNonActionItems.clear();
    ArrayList<MenuItemImpl> visibleItems=getVisibleItems();
    final int itemsSize=visibleItems.size();
    for (int i=0; i < itemsSize; i++) {
      MenuItemImpl item=visibleItems.get(i);
      if (item.isActionButton()) {
        mActionItems.add(item);
      }
 else {
        mNonActionItems.add(item);
      }
    }
  }
 else {
    mActionItems.clear();
    mNonActionItems.clear();
    mNonActionItems.addAll(getVisibleItems());
  }
  mIsActionItemsStale=false;
}

public void flagActionItems ( ) { if ( ! mIsActionItemsStale ) { return ; } boolean flagged = false ; for ( WeakReference < MenuPresenter > ref : mPresenters ) { final MenuPresenter presenter = ref . get ( ) ; if ( presenter == null ) { mPresenters . remove ( ref ) ; } else { flagged |= presenter . flagActionItems ( ) ; } } if ( flagged ) { mActionItems . clear ( ) ; mNonActionItems . clear ( ) ; ArrayList < MenuItemImpl > visibleItems = getVisibleItems ( ) ; final int itemsSize = visibleItems . size ( ) ; for ( int i = 0 ; i < itemsSize ; i ++ ) { MenuItemImpl item = visibleItems . get ( i ) ; if ( item . isActionButton ( ) ) { mActionItems . add ( item ) ; } else { mNonActionItems . add ( item ) ; } } } else { mActionItems . clear ( ) ; mNonActionItems . clear ( ) ; mNonActionItems . addAll ( getVisibleItems ( ) ) ; } mIsActionItemsStale = false ; }
this method determines which menu items get to be ' action items ' that will appear in an action bar and which items should be ' overflow items ' in a secondary menu . the rules are as follows : < p > items are considered for inclusion in the order specified within the menu . there is a limit of mmaxactionitems as a total count , optionally including the overflow menu button itself . this is a soft limit ; if an item shares a group id with an item previously included as an action item , the new item will stay with its group and become an action item itself even if it breaks the max item count limit . this is done to limit the conceptual complexity of the items presented within an action bar . only a few unrelated concepts should be presented to the user in this space , and groups are treated as a single concept . < p > there is also a hard limit of consumed measurable space : mactionwidthlimit . this limit may be broken by a single item that exceeds the remaining space , but no further items may be added . if an item that is part of a group cannot fit within the remaining measured width , the entire group will be demoted to overflow . this is done to ensure room for navigation and other affordances in the action bar as well as reduce general ui clutter . < p > the space freed by demoting a full group cannot be consumed by future menu items . once items begin to overflow , all future items become overflow items as well . this is to avoid inadvertent reordering that may break the app ' s intended design .
