Loading core/java/com/android/internal/view/menu/CascadingMenuPopup.java +9 −1 Original line number Diff line number Diff line Loading @@ -346,7 +346,15 @@ final class CascadingMenuPopup extends MenuPopup implements MenuPresenter, OnKey private void showMenu(@NonNull MenuBuilder menu) { final LayoutInflater inflater = LayoutInflater.from(mContext); final MenuAdapter adapter = new MenuAdapter(menu, inflater, mOverflowOnly); // Apply "force show icon" setting; if the menu being shown is the top level menu, apply the // setting set on this CascadingMenuPopup by its creating code. If it's a submenu, or if no // "force" setting was explicitly set, determine the setting by examining the items. if (!isShowing() && mForceShowIcon) { adapter.setForceShowIcon(mForceShowIcon); } else { adapter.setForceShowIcon(MenuPopup.shouldPreserveIconSpacing(menu)); } final int menuWidth = measureIndividualMenuWidth(adapter, null, mContext, mMenuMaxWidth); final MenuPopupWindow popupWindow = createPopupWindow(); Loading core/java/com/android/internal/view/menu/MenuPopup.java +21 −0 Original line number Diff line number Diff line Loading @@ -183,4 +183,25 @@ public abstract class MenuPopup implements ShowableListMenu, MenuPresenter, } return (MenuAdapter) adapter; } /** * Returns whether icon spacing needs to be preserved for the given menu, based on whether any * of its items contains an icon. * @param menu * @return Whether to preserve icon spacing. */ protected static boolean shouldPreserveIconSpacing(MenuBuilder menu) { boolean preserveIconSpacing = false; final int count = menu.size(); for (int i = 0; i < count; i++) { MenuItem childItem = menu.getItem(i); if (childItem.isVisible() && childItem.getIcon() != null) { preserveIconSpacing = true; break; } } return preserveIconSpacing; } } core/java/com/android/internal/view/menu/StandardMenuPopup.java +1 −1 Original line number Diff line number Diff line Loading @@ -266,7 +266,7 @@ final class StandardMenuPopup extends MenuPopup implements OnDismissListener, On final MenuPopupHelper subPopup = new MenuPopupHelper(mContext, subMenu, mShownAnchorView, mOverflowOnly, mPopupStyleAttr, mPopupStyleRes); subPopup.setPresenterCallback(mPresenterCallback); subPopup.setForceShowIcon(mAdapter.getForceShowIcon()); subPopup.setForceShowIcon(MenuPopup.shouldPreserveIconSpacing(subMenu)); // Pass responsibility for handling onDismiss to the submenu. subPopup.setOnDismissListener(mOnDismissListener); Loading Loading
core/java/com/android/internal/view/menu/CascadingMenuPopup.java +9 −1 Original line number Diff line number Diff line Loading @@ -346,7 +346,15 @@ final class CascadingMenuPopup extends MenuPopup implements MenuPresenter, OnKey private void showMenu(@NonNull MenuBuilder menu) { final LayoutInflater inflater = LayoutInflater.from(mContext); final MenuAdapter adapter = new MenuAdapter(menu, inflater, mOverflowOnly); // Apply "force show icon" setting; if the menu being shown is the top level menu, apply the // setting set on this CascadingMenuPopup by its creating code. If it's a submenu, or if no // "force" setting was explicitly set, determine the setting by examining the items. if (!isShowing() && mForceShowIcon) { adapter.setForceShowIcon(mForceShowIcon); } else { adapter.setForceShowIcon(MenuPopup.shouldPreserveIconSpacing(menu)); } final int menuWidth = measureIndividualMenuWidth(adapter, null, mContext, mMenuMaxWidth); final MenuPopupWindow popupWindow = createPopupWindow(); Loading
core/java/com/android/internal/view/menu/MenuPopup.java +21 −0 Original line number Diff line number Diff line Loading @@ -183,4 +183,25 @@ public abstract class MenuPopup implements ShowableListMenu, MenuPresenter, } return (MenuAdapter) adapter; } /** * Returns whether icon spacing needs to be preserved for the given menu, based on whether any * of its items contains an icon. * @param menu * @return Whether to preserve icon spacing. */ protected static boolean shouldPreserveIconSpacing(MenuBuilder menu) { boolean preserveIconSpacing = false; final int count = menu.size(); for (int i = 0; i < count; i++) { MenuItem childItem = menu.getItem(i); if (childItem.isVisible() && childItem.getIcon() != null) { preserveIconSpacing = true; break; } } return preserveIconSpacing; } }
core/java/com/android/internal/view/menu/StandardMenuPopup.java +1 −1 Original line number Diff line number Diff line Loading @@ -266,7 +266,7 @@ final class StandardMenuPopup extends MenuPopup implements OnDismissListener, On final MenuPopupHelper subPopup = new MenuPopupHelper(mContext, subMenu, mShownAnchorView, mOverflowOnly, mPopupStyleAttr, mPopupStyleRes); subPopup.setPresenterCallback(mPresenterCallback); subPopup.setForceShowIcon(mAdapter.getForceShowIcon()); subPopup.setForceShowIcon(MenuPopup.shouldPreserveIconSpacing(subMenu)); // Pass responsibility for handling onDismiss to the submenu. subPopup.setOnDismissListener(mOnDismissListener); Loading