Example #1
0
        public override bool flagActionItems()
        {
            java.util.ArrayList <*****@*****.**> visibleItems = mMenu
                                                                                          .getVisibleItems();
            int itemsSize  = visibleItems.size();
            int maxActions = mMaxItems;
            int widthLimit = mActionItemWidthLimit;
            int querySpec  = android.view.View.MeasureSpec.makeMeasureSpec(0, android.view.View
                                                                           .MeasureSpec.UNSPECIFIED);

            android.view.ViewGroup parent = (android.view.ViewGroup)mMenuView;
            int  requiredItems            = 0;
            int  requestedItems           = 0;
            int  firstActionWidth         = 0;
            bool hasOverflow = false;

            {
                for (int i = 0; i < itemsSize; i++)
                {
                    [email protected] item = visibleItems.get(i);
                    if (item.requiresActionButton())
                    {
                        requiredItems++;
                    }
                    else
                    {
                        if (item.requestsActionButton())
                        {
                            requestedItems++;
                        }
                        else
                        {
                            hasOverflow = true;
                        }
                    }
                    if (mExpandedActionViewsExclusive && item.isActionViewExpanded())
                    {
                        // Overflow everything if we have an expanded action view and we're
                        // space constrained.
                        maxActions = 0;
                    }
                }
            }
            // Reserve a spot for the overflow item if needed.
            if (mReserveOverflow && (hasOverflow || requiredItems + requestedItems > maxActions
                                     ))
            {
                maxActions--;
            }
            maxActions -= requiredItems;
            android.util.SparseBooleanArray seenGroups = mActionButtonGroups;
            seenGroups.clear();
            int cellSize       = 0;
            int cellsRemaining = 0;

            if (mStrictWidthLimit)
            {
                cellsRemaining = widthLimit / mMinCellSize;
                int cellSizeRemaining = widthLimit % mMinCellSize;
                cellSize = mMinCellSize + cellSizeRemaining / cellsRemaining;
            }
            {
                // Flag as many more requested items as will fit.
                for (int i_1 = 0; i_1 < itemsSize; i_1++)
                {
                    [email protected] item = visibleItems.get(i_1);
                    if (item.requiresActionButton())
                    {
                        android.view.View v = getItemView(item, mScrapActionButtonView, parent);
                        if (mScrapActionButtonView == null)
                        {
                            mScrapActionButtonView = v;
                        }
                        if (mStrictWidthLimit)
                        {
                            cellsRemaining -= [email protected]
                                                  (v, cellSize, cellsRemaining, querySpec, 0);
                        }
                        else
                        {
                            v.measure(querySpec, querySpec);
                        }
                        int measuredWidth = v.getMeasuredWidth();
                        widthLimit -= measuredWidth;
                        if (firstActionWidth == 0)
                        {
                            firstActionWidth = measuredWidth;
                        }
                        int groupId = item.getGroupId();
                        if (groupId != 0)
                        {
                            seenGroups.put(groupId, true);
                        }
                        item.setIsActionButton(true);
                    }
                    else
                    {
                        if (item.requestsActionButton())
                        {
                            // Items in a group with other items that already have an action slot
                            // can break the max actions rule, but not the width limit.
                            int  groupId  = item.getGroupId();
                            bool inGroup  = seenGroups.get(groupId);
                            bool isAction = (maxActions > 0 || inGroup) && widthLimit > 0 && (!mStrictWidthLimit ||
                                                                                              cellsRemaining > 0);
                            if (isAction)
                            {
                                android.view.View v = getItemView(item, mScrapActionButtonView, parent);
                                if (mScrapActionButtonView == null)
                                {
                                    mScrapActionButtonView = v;
                                }
                                if (mStrictWidthLimit)
                                {
                                    int cells = [email protected](v, cellSize
                                                                                                                , cellsRemaining, querySpec, 0);
                                    cellsRemaining -= cells;
                                    if (cells == 0)
                                    {
                                        isAction = false;
                                    }
                                }
                                else
                                {
                                    v.measure(querySpec, querySpec);
                                }
                                int measuredWidth = v.getMeasuredWidth();
                                widthLimit -= measuredWidth;
                                if (firstActionWidth == 0)
                                {
                                    firstActionWidth = measuredWidth;
                                }
                                if (mStrictWidthLimit)
                                {
                                    isAction &= widthLimit >= 0;
                                }
                                else
                                {
                                    // Did this push the entire first item past the limit?
                                    isAction &= widthLimit + firstActionWidth > 0;
                                }
                            }
                            if (isAction && groupId != 0)
                            {
                                seenGroups.put(groupId, true);
                            }
                            else
                            {
                                if (inGroup)
                                {
                                    // We broke the width limit. Demote the whole group, they all overflow now.
                                    seenGroups.put(groupId, false);
                                    {
                                        for (int j = 0; j < i_1; j++)
                                        {
                                            [email protected] areYouMyGroupie = visibleItems.get(j);
                                            if (areYouMyGroupie.getGroupId() == groupId)
                                            {
                                                // Give back the action slot
                                                if (areYouMyGroupie.isActionButton())
                                                {
                                                    maxActions++;
                                                }
                                                areYouMyGroupie.setIsActionButton(false);
                                            }
                                        }
                                    }
                                }
                            }
                            if (isAction)
                            {
                                maxActions--;
                            }
                            item.setIsActionButton(isAction);
                        }
                    }
                }
            }
            return(true);
        }