Merge "Don't show icons in overlay popup menus." into nyc-dev

This commit is contained in:
Oren Blasberg
2016-04-14 20:34:52 +00:00
committed by Android (Google) Code Review
2 changed files with 19 additions and 7 deletions

View File

@@ -347,14 +347,21 @@ final class CascadingMenuPopup extends MenuPopup implements MenuPresenter, OnKey
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.
// Apply "force show icon" setting. There are 4 cases:
// (1) This is the top level menu. Only add spacing for icons if forced.
// (2) This is a submenu. Add spacing if any of the visible menu items has an icon.
// (3) This is a top level menu that is not an overflow menu. Add spacing if any of the
// visible menu items has an icon.
// (4) This is an overflow menu or a top level menu that doesn't have "force" set.
// Don't allow spacing.
if (!isShowing() && mForceShowIcon) {
adapter.setForceShowIcon(mForceShowIcon);
} else {
adapter.setForceShowIcon(MenuPopup.shouldPreserveIconSpacing(menu));
// Case 1
adapter.setForceShowIcon(true);
} else if (isShowing() || !isShowing() && !mForceShowIcon && !mOverflowOnly) {
// Case 2 or 3
adapter.setForceShowIcon(MenuPopup.shouldPreserveIconSpacing(menu));
}
// Case 4: Else, don't allow spacing for icons.
final int menuWidth = measureIndividualMenuWidth(adapter, null, mContext, mMenuMaxWidth);
final MenuPopupWindow popupWindow = createPopupWindow();
@@ -734,4 +741,4 @@ final class CascadingMenuPopup extends MenuPopup implements MenuPresenter, OnKey
return window.getListView();
}
}
}
}

View File

@@ -187,6 +187,11 @@ public abstract class MenuPopup implements ShowableListMenu, MenuPresenter,
/**
* Returns whether icon spacing needs to be preserved for the given menu, based on whether any
* of its items contains an icon.
*
* NOTE: This should only be used for non-overflow-only menus, because this method does not
* take into account whether the menu items are being shown as part of the popup or or being
* shown as actions in the action bar.
*
* @param menu
* @return Whether to preserve icon spacing.
*/