Search in sources :

Example 11 with MenuItemImpl

use of com.android.internal.view.menu.MenuItemImpl in project platform_frameworks_base by android.

the class RenderSessionImpl method getViewKey.

/* (non-Javadoc)
     * The cookie for menu items are stored in menu item and not in the map from View stored in
     * BridgeContext.
     */
@Nullable
private Object getViewKey(View view) {
    BridgeContext context = getContext();
    if (!(view instanceof MenuView.ItemView)) {
        return context.getViewKey(view);
    }
    MenuItemImpl menuItem;
    if (view instanceof ActionMenuItemView) {
        menuItem = ((ActionMenuItemView) view).getItemData();
    } else if (view instanceof ListMenuItemView) {
        menuItem = ((ListMenuItemView) view).getItemData();
    } else if (view instanceof IconMenuItemView) {
        menuItem = ((IconMenuItemView) view).getItemData();
    } else {
        menuItem = null;
    }
    if (menuItem instanceof BridgeMenuItemImpl) {
        return ((BridgeMenuItemImpl) menuItem).getViewCookie();
    }
    return null;
}
Also used : BridgeMenuItemImpl(com.android.internal.view.menu.BridgeMenuItemImpl) MenuItemImpl(com.android.internal.view.menu.MenuItemImpl) BridgeMenuItemImpl(com.android.internal.view.menu.BridgeMenuItemImpl) ActionMenuItemView(com.android.internal.view.menu.ActionMenuItemView) IconMenuItemView(com.android.internal.view.menu.IconMenuItemView) ListMenuItemView(com.android.internal.view.menu.ListMenuItemView) IconMenuItemView(com.android.internal.view.menu.IconMenuItemView) ListMenuItemView(com.android.internal.view.menu.ListMenuItemView) BridgeContext(com.android.layoutlib.bridge.android.BridgeContext) ActionMenuItemView(com.android.internal.view.menu.ActionMenuItemView) Nullable(android.annotation.Nullable)

Example 12 with MenuItemImpl

use of com.android.internal.view.menu.MenuItemImpl in project platform_frameworks_base by android.

the class FrameworkActionBar method isOverflowPopupNeeded.

private boolean isOverflowPopupNeeded() {
    boolean needed = mActionBar.isOverflowPopupNeeded();
    if (!needed) {
        return false;
    }
    // Copied from android.widget.ActionMenuPresenter.updateMenuView()
    ArrayList<MenuItemImpl> menus = mActionBar.getMenuBuilder().getNonActionItems();
    ActionMenuPresenter presenter = mActionBar.getActionMenuPresenter();
    if (presenter == null) {
        throw new RuntimeException("Failed to create a Presenter for Action Bar Menus.");
    }
    if (presenter.isOverflowReserved() && menus != null) {
        final int count = menus.size();
        if (count == 1) {
            needed = !menus.get(0).isActionViewExpanded();
        } else {
            needed = count > 0;
        }
    }
    return needed;
}
Also used : MenuItemImpl(com.android.internal.view.menu.MenuItemImpl) ActionMenuPresenter(android.widget.ActionMenuPresenter)

Example 13 with MenuItemImpl

use of com.android.internal.view.menu.MenuItemImpl in project platform_frameworks_base by android.

the class ActionMenuPresenter method updateMenuView.

@Override
public void updateMenuView(boolean cleared) {
    final ViewGroup menuViewParent = (ViewGroup) ((View) mMenuView).getParent();
    if (menuViewParent != null && ACTIONBAR_ANIMATIONS_ENABLED) {
        setupItemAnimations();
    }
    super.updateMenuView(cleared);
    ((View) mMenuView).requestLayout();
    if (mMenu != null) {
        final ArrayList<MenuItemImpl> actionItems = mMenu.getActionItems();
        final int count = actionItems.size();
        for (int i = 0; i < count; i++) {
            final ActionProvider provider = actionItems.get(i).getActionProvider();
            if (provider != null) {
                provider.setSubUiVisibilityListener(this);
            }
        }
    }
    final ArrayList<MenuItemImpl> nonActionItems = mMenu != null ? mMenu.getNonActionItems() : null;
    boolean hasOverflow = false;
    if (mReserveOverflow && nonActionItems != null) {
        final int count = nonActionItems.size();
        if (count == 1) {
            hasOverflow = !nonActionItems.get(0).isActionViewExpanded();
        } else {
            hasOverflow = count > 0;
        }
    }
    if (hasOverflow) {
        if (mOverflowButton == null) {
            mOverflowButton = new OverflowMenuButton(mSystemContext);
        }
        ViewGroup parent = (ViewGroup) mOverflowButton.getParent();
        if (parent != mMenuView) {
            if (parent != null) {
                parent.removeView(mOverflowButton);
            }
            ActionMenuView menuView = (ActionMenuView) mMenuView;
            menuView.addView(mOverflowButton, menuView.generateOverflowButtonLayoutParams());
        }
    } else if (mOverflowButton != null && mOverflowButton.getParent() == mMenuView) {
        ((ViewGroup) mMenuView).removeView(mOverflowButton);
    }
    ((ActionMenuView) mMenuView).setOverflowReserved(mReserveOverflow);
}
Also used : MenuItemImpl(com.android.internal.view.menu.MenuItemImpl) ActionProvider(android.view.ActionProvider) ViewGroup(android.view.ViewGroup) MenuView(com.android.internal.view.menu.MenuView) View(android.view.View) ActionMenuItemView(com.android.internal.view.menu.ActionMenuItemView)

Example 14 with MenuItemImpl

use of com.android.internal.view.menu.MenuItemImpl in project android_frameworks_base by AOSPA.

the class ActionMenuPresenter method flagActionItems.

public boolean flagActionItems() {
    final ArrayList<MenuItemImpl> visibleItems;
    final int itemsSize;
    if (mMenu != null) {
        visibleItems = mMenu.getVisibleItems();
        itemsSize = visibleItems.size();
    } else {
        visibleItems = null;
        itemsSize = 0;
    }
    int maxActions = mMaxItems;
    int widthLimit = mActionItemWidthLimit;
    final int querySpec = MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED);
    final ViewGroup parent = (ViewGroup) mMenuView;
    int requiredItems = 0;
    int requestedItems = 0;
    int firstActionWidth = 0;
    boolean hasOverflow = false;
    for (int i = 0; i < itemsSize; i++) {
        MenuItemImpl 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;
    final SparseBooleanArray seenGroups = mActionButtonGroups;
    seenGroups.clear();
    int cellSize = 0;
    int cellsRemaining = 0;
    if (mStrictWidthLimit) {
        cellsRemaining = widthLimit / mMinCellSize;
        final int cellSizeRemaining = widthLimit % mMinCellSize;
        cellSize = mMinCellSize + cellSizeRemaining / cellsRemaining;
    }
    // Flag as many more requested items as will fit.
    for (int i = 0; i < itemsSize; i++) {
        MenuItemImpl item = visibleItems.get(i);
        if (item.requiresActionButton()) {
            View v = getItemView(item, null, parent);
            if (mStrictWidthLimit) {
                cellsRemaining -= ActionMenuView.measureChildForCells(v, cellSize, cellsRemaining, querySpec, 0);
            } else {
                v.measure(querySpec, querySpec);
            }
            final int measuredWidth = v.getMeasuredWidth();
            widthLimit -= measuredWidth;
            if (firstActionWidth == 0) {
                firstActionWidth = measuredWidth;
            }
            final 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.
            final int groupId = item.getGroupId();
            final boolean inGroup = seenGroups.get(groupId);
            boolean isAction = (maxActions > 0 || inGroup) && widthLimit > 0 && (!mStrictWidthLimit || cellsRemaining > 0);
            if (isAction) {
                View v = getItemView(item, null, parent);
                if (mStrictWidthLimit) {
                    final int cells = ActionMenuView.measureChildForCells(v, cellSize, cellsRemaining, querySpec, 0);
                    cellsRemaining -= cells;
                    if (cells == 0) {
                        isAction = false;
                    }
                } else {
                    v.measure(querySpec, querySpec);
                }
                final 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; j++) {
                    MenuItemImpl 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);
        } else {
            // Neither requires nor requests an action button.
            item.setIsActionButton(false);
        }
    }
    return true;
}
Also used : MenuItemImpl(com.android.internal.view.menu.MenuItemImpl) ViewGroup(android.view.ViewGroup) SparseBooleanArray(android.util.SparseBooleanArray) MenuView(com.android.internal.view.menu.MenuView) View(android.view.View) ActionMenuItemView(com.android.internal.view.menu.ActionMenuItemView)

Example 15 with MenuItemImpl

use of com.android.internal.view.menu.MenuItemImpl in project android_frameworks_base by AOSPA.

the class RenderSessionImpl method getViewKey.

/* (non-Javadoc)
     * The cookie for menu items are stored in menu item and not in the map from View stored in
     * BridgeContext.
     */
@Nullable
private Object getViewKey(View view) {
    BridgeContext context = getContext();
    if (!(view instanceof MenuView.ItemView)) {
        return context.getViewKey(view);
    }
    MenuItemImpl menuItem;
    if (view instanceof ActionMenuItemView) {
        menuItem = ((ActionMenuItemView) view).getItemData();
    } else if (view instanceof ListMenuItemView) {
        menuItem = ((ListMenuItemView) view).getItemData();
    } else if (view instanceof IconMenuItemView) {
        menuItem = ((IconMenuItemView) view).getItemData();
    } else {
        menuItem = null;
    }
    if (menuItem instanceof BridgeMenuItemImpl) {
        return ((BridgeMenuItemImpl) menuItem).getViewCookie();
    }
    return null;
}
Also used : BridgeMenuItemImpl(com.android.internal.view.menu.BridgeMenuItemImpl) MenuItemImpl(com.android.internal.view.menu.MenuItemImpl) BridgeMenuItemImpl(com.android.internal.view.menu.BridgeMenuItemImpl) ActionMenuItemView(com.android.internal.view.menu.ActionMenuItemView) IconMenuItemView(com.android.internal.view.menu.IconMenuItemView) ListMenuItemView(com.android.internal.view.menu.ListMenuItemView) IconMenuItemView(com.android.internal.view.menu.IconMenuItemView) ListMenuItemView(com.android.internal.view.menu.ListMenuItemView) BridgeContext(com.android.layoutlib.bridge.android.BridgeContext) ActionMenuItemView(com.android.internal.view.menu.ActionMenuItemView) Nullable(android.annotation.Nullable)

Aggregations

MenuItemImpl (com.android.internal.view.menu.MenuItemImpl)25 ActionMenuItemView (com.android.internal.view.menu.ActionMenuItemView)15 View (android.view.View)10 ViewGroup (android.view.ViewGroup)10 MenuView (com.android.internal.view.menu.MenuView)10 Nullable (android.annotation.Nullable)5 SparseBooleanArray (android.util.SparseBooleanArray)5 ActionProvider (android.view.ActionProvider)5 ActionMenuPresenter (android.widget.ActionMenuPresenter)5 BridgeMenuItemImpl (com.android.internal.view.menu.BridgeMenuItemImpl)5 IconMenuItemView (com.android.internal.view.menu.IconMenuItemView)5 ListMenuItemView (com.android.internal.view.menu.ListMenuItemView)5 BridgeContext (com.android.layoutlib.bridge.android.BridgeContext)5