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

Commit ddf6b813 authored by Oren Blasberg's avatar Oren Blasberg
Browse files

Fix icon spacing on both MenuPopup implementations.

Ensure we calculate based on the actual menu items in a particular menu
or submenu, not based on whether the parent menu had icon spacing
enabled.

Bug: 28026351
Change-Id: Ie6e56eb142f0b82de38bf39ee848ddd26df2bf1c
parent bcff1431
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);