Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 1b65b01f authored by Oren Blasberg's avatar Oren Blasberg Committed by Android (Google) Code Review
Browse files

Merge "Fix icon spacing on both MenuPopup implementations." into nyc-dev

parents d408b995 ddf6b813
Loading
Loading
Loading
Loading
+9 −1
Original line number Diff line number Diff line
@@ -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();
+21 −0
Original line number Diff line number Diff line
@@ -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;
    }
}
+1 −1
Original line number Diff line number Diff line
@@ -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);