From c36666cf53eee7abc2304bae0eb107622e511232 Mon Sep 17 00:00:00 2001 From: Matthew Jones Date: Wed, 13 Sep 2017 15:26:58 +0000 Subject: [PATCH] [Home] Fix occasional failure to evenly space icons in bottom nav. Instead of relying on the menu items to provide their width to us to space them apart, a dimension has been added to dimens.xml since the icons will always be the same size anyway. TBR=thildebr@chromium.org (cherry picked from commit e6b519dcb5e4d96f38101f724b1744d8017f1bc9) Bug: 763033 Change-Id: Ia34fb7a09589df10f565559da51c01fef972bfbf Reviewed-on: https://chromium-review.googlesource.com/658300 Reviewed-by: Theresa Commit-Queue: Troy Hildebrandt Cr-Original-Commit-Position: refs/heads/master@{#500837} Reviewed-on: https://chromium-review.googlesource.com/664981 Reviewed-by: Matthew Jones Cr-Commit-Position: refs/branch-heads/3202@{#201} Cr-Branched-From: fa6a5d87adff761bc16afc5498c3f5944c1daa68-refs/heads/master@{#499098} --- chrome/android/java/res/values/dimens.xml | 1 + .../widget/bottomsheet/BottomSheetContentController.java | 6 ++++-- .../bottomsheet/base/BottomNavigationMenuView.java | 9 +++------ 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/chrome/android/java/res/values/dimens.xml b/chrome/android/java/res/values/dimens.xml index 636614470906f..67c25627152a0 100644 --- a/chrome/android/java/res/values/dimens.xml +++ b/chrome/android/java/res/values/dimens.xml @@ -490,6 +490,7 @@ 10dp 40dp 96dp + 24dp diff --git a/chrome/android/java/src/org/chromium/chrome/browser/widget/bottomsheet/BottomSheetContentController.java b/chrome/android/java/src/org/chromium/chrome/browser/widget/bottomsheet/BottomSheetContentController.java index fc027ada907b8..facf9334b61a7 100644 --- a/chrome/android/java/src/org/chromium/chrome/browser/widget/bottomsheet/BottomSheetContentController.java +++ b/chrome/android/java/src/org/chromium/chrome/browser/widget/bottomsheet/BottomSheetContentController.java @@ -247,8 +247,10 @@ public void onGlobalLayout() { * menu items are spaced apart appropriately. */ private void updateMenuItemSpacing() { - getMenuView().updateMenuItemSpacingForMinWidth( - mBottomSheet.getWidth(), mBottomSheet.getHeight()); + Resources res = getContext().getResources(); + getMenuView().updateMenuItemSpacingForMinWidth(mBottomSheet.getWidth(), + mBottomSheet.getHeight(), + res.getDimensionPixelSize(R.dimen.bottom_nav_menu_item_size)); } /** diff --git a/chrome/android/third_party/widget_bottomsheet_base/java/src/org/chromium/chrome/browser/widget/bottomsheet/base/BottomNavigationMenuView.java b/chrome/android/third_party/widget_bottomsheet_base/java/src/org/chromium/chrome/browser/widget/bottomsheet/base/BottomNavigationMenuView.java index bf6c91de6b61b..e4a24f1e0deef 100644 --- a/chrome/android/third_party/widget_bottomsheet_base/java/src/org/chromium/chrome/browser/widget/bottomsheet/base/BottomNavigationMenuView.java +++ b/chrome/android/third_party/widget_bottomsheet_base/java/src/org/chromium/chrome/browser/widget/bottomsheet/base/BottomNavigationMenuView.java @@ -234,18 +234,15 @@ private BottomNavigationItemView getNewItem() { * * @param layoutWidth Width of the navigation menu's container. * @param layoutHeight Height of the navigation menu's container. + * @param iconWidth The width of the menu item icons, necessary for proper spacing. */ - public void updateMenuItemSpacingForMinWidth(int layoutWidth, int layoutHeight) { + public void updateMenuItemSpacingForMinWidth(int layoutWidth, int layoutHeight, int iconWidth) { if (mButtons.length == 0) return; int menuWidth = Math.min(layoutWidth, layoutHeight); if (menuWidth != mMenuWidth) { mMenuWidth = menuWidth; - int iconWidths = 0; - for (BottomNavigationItemView item : mButtons) { - iconWidths += item.getWidth() - (item.getPaddingLeft() + item.getPaddingRight()); - } - + int iconWidths = iconWidth * mButtons.length; int padding = (menuWidth - iconWidths) / (mButtons.length * 2); for (BottomNavigationItemView item : mButtons) { item.setPadding(padding, item.getPaddingTop(), padding, item.getPaddingBottom());