diff --git a/chrome/android/features/start_surface/javatests/src/org/chromium/chrome/features/start_surface/StartSurfaceOnTabletTest.java b/chrome/android/features/start_surface/javatests/src/org/chromium/chrome/features/start_surface/StartSurfaceOnTabletTest.java index 314ef0e236c88..1f4ec59eb213c 100644 --- a/chrome/android/features/start_surface/javatests/src/org/chromium/chrome/features/start_surface/StartSurfaceOnTabletTest.java +++ b/chrome/android/features/start_surface/javatests/src/org/chromium/chrome/features/start_surface/StartSurfaceOnTabletTest.java @@ -19,7 +19,6 @@ import org.hamcrest.Matchers; import org.junit.Assert; -import org.junit.Assume; import org.junit.Rule; import org.junit.Test; import org.junit.runner.RunWith; @@ -457,20 +456,18 @@ public void test1RowMvtMarginWithMultiColumnFeedsOnNtpHomePage() throws IOExcept int expectedContainerTwoSideMarginLandscape = res.getDimensionPixelSize(org.chromium.chrome.R.dimen.ntp_search_box_start_margin) * 2 - + res.getDimensionPixelSize( - org.chromium.chrome.R.dimen - .mvt_container_to_ntp_right_extra_margin_two_feed_tablet) + res.getDimensionPixelSize(org.chromium.chrome.R.dimen.tile_grid_layout_bleed) / 2 * 2; int expectedContainerTwoSideMarginPortrait = res.getDimensionPixelSize(org.chromium.chrome.R.dimen.tile_grid_layout_bleed) / 2 - * 2 - + res.getDimensionPixelSize( - org.chromium.chrome.R.dimen - .mvt_container_to_ntp_right_extra_margin_two_feed_tablet); + * 2; + int expectedContainerRightExtraMargin = res.getDimensionPixelSize( + org.chromium.chrome.R.dimen + .mvt_container_to_ntp_right_extra_margin_two_feed_tablet); // Verifies the margins of the module most visited tiles and its inner view are correct. verifyMostVisitedTileMargin(expectedContainerTwoSideMarginLandscape, - expectedContainerTwoSideMarginPortrait, 0, 0, /*isScrollable=*/true, ntp); + expectedContainerTwoSideMarginPortrait, expectedContainerRightExtraMargin, 0, 0, + /*isScrollable=*/true, ntp); int expectedMvtBottomMargin = res.getDimensionPixelSize( org.chromium.chrome.R.dimen.mvt_container_bottom_margin_tablet); @@ -541,7 +538,7 @@ public void test2RowMvtMarginWithMultiColumnFeedsOnNtpHomePage() throws IOExcept org.chromium.chrome.R.dimen.tile_grid_layout_portrait_edge_margin_tablet); // Verifies the margins of the module most visited tiles and its inner view are correct. verifyMostVisitedTileMargin(expectedContainerTwoSideMargin, expectedContainerTwoSideMargin, - expectedLandScapeEdgeMargin, expectedPortraitEdgeMargin, /*isScrollable=*/false, + 0, expectedLandScapeEdgeMargin, expectedPortraitEdgeMargin, /*isScrollable=*/false, ntp); int expectedMvtBottomMargin = res.getDimensionPixelSize( @@ -596,6 +593,9 @@ public void testClickSingleTabCardCloseNtpHomeSurface() throws IOException { * most visited tiles container when the tablet is in landscape. * @param expectedContainerTwoSideMarginPortrait The expected sum of two side margins of the * most visited tiles container when the tablet is in portrait. + * @param expectedContainerRightExtraMargin The extra value might be added to the right margin + * of the most visited tiles container when there is a half-tile element at the end of + * the scrollable most visited tiles. * @param expectedEdgeMarginLandScape The expected edge margin of the most visited tiles element * to the MV tiles layout when the tablet is in landscape. * @param expectedEdgeMarginPortrait The expected edge margin of the most visited tiles element @@ -604,10 +604,10 @@ public void testClickSingleTabCardCloseNtpHomeSurface() throws IOException { * @param ntp The current {@link NewTabPage}. */ private void verifyMostVisitedTileMargin(int expectedContainerTwoSideMarginLandScape, - int expectedContainerTwoSideMarginPortrait, int expectedEdgeMarginLandScape, - int expectedEdgeMarginPortrait, boolean isScrollable, NewTabPage ntp) { + int expectedContainerTwoSideMarginPortrait, int expectedContainerRightExtraMargin, + int expectedEdgeMarginLandScape, int expectedEdgeMarginPortrait, boolean isScrollable, + NewTabPage ntp) { NewTabPageLayout ntpLayout = ntp.getNewTabPageLayout(); - Assume.assumeTrue(ntpLayout.getChildCount() >= 4); View mvTilesContainer = ntpLayout.findViewById(org.chromium.chrome.test.R.id.mv_tiles_container); View mvTilesLayout = ntpLayout.findViewById(org.chromium.chrome.test.R.id.mv_tiles_layout); @@ -621,8 +621,9 @@ private void verifyMostVisitedTileMargin(int expectedContainerTwoSideMarginLandS waitForScreenOrientation("\"landscape\""); // Verifies the margins added for the most visited tiles are correct. verifyMostVisitedTileMarginImpl(ntpLayout, mvTilesContainer, mvTilesLayout, mvTileItem1, - mvTileItem2, expectedContainerTwoSideMarginLandScape, expectedEdgeMarginLandScape, - mvTilesItemWidth, isScrollable); + mvTileItem2, expectedContainerTwoSideMarginLandScape, + expectedContainerRightExtraMargin, expectedEdgeMarginLandScape, mvTilesItemWidth, + isScrollable); // Start off in portrait screen orientation. mActivityTestRule.getActivity().setRequestedOrientation( @@ -630,8 +631,9 @@ private void verifyMostVisitedTileMargin(int expectedContainerTwoSideMarginLandS waitForScreenOrientation("\"portrait\""); // Verifies the margins added for the most visited tiles are correct. verifyMostVisitedTileMarginImpl(ntpLayout, mvTilesContainer, mvTilesLayout, mvTileItem1, - mvTileItem2, expectedContainerTwoSideMarginPortrait, expectedEdgeMarginPortrait, - mvTilesItemWidth, isScrollable); + mvTileItem2, expectedContainerTwoSideMarginPortrait, + expectedContainerRightExtraMargin, expectedEdgeMarginPortrait, mvTilesItemWidth, + isScrollable); } /** @@ -644,6 +646,10 @@ private void verifyMostVisitedTileMargin(int expectedContainerTwoSideMarginLandS * @param mvTileItem2 The second element of the most visited tile. * @param expectedContainerTwoSideMargin The expected sum of two side margins of the * most visited tiles container. + * @param expectedContainerRightExtraMargin The extra value might be added to the right margin + * of the most visited tiles container when there is + * a half-tile element at the end of the scrollable + * most visited tiles. * @param expectedEdgeMargin The expected edge margin of the most visited tiles element * to the MV tiles layout. * @param mvTilesItemWidth The width of the elements in the most visited tile. @@ -651,28 +657,53 @@ private void verifyMostVisitedTileMargin(int expectedContainerTwoSideMarginLandS */ private void verifyMostVisitedTileMarginImpl(View ntpLayout, View mvTilesContainer, View mvTilesLayout, View mvTileItem1, View mvTileItem2, - int expectedContainerTwoSideMargin, int expectedEdgeMargin, int mvTilesItemWidth, - boolean isScrollable) { + int expectedContainerTwoSideMargin, int expectedContainerRightExtraMargin, + int expectedEdgeMargin, int mvTilesItemWidth, boolean isScrollable) { int mvtContainerWidth = mvTilesContainer.getWidth(); int mvTilesLayoutWidth = mvTilesLayout.getWidth(); int mvt1LeftMargin = ((MarginLayoutParams) mvTileItem1.getLayoutParams()).leftMargin; int mvt2LeftMargin = ((MarginLayoutParams) mvTileItem2.getLayoutParams()).leftMargin; - Assert.assertEquals("The container's margin with respect to the layout of the new tab " - + "page is incorrect.", - expectedContainerTwoSideMargin, ntpLayout.getWidth() - mvtContainerWidth, 3); - if (isScrollable) { Assert.assertTrue("The width of the most visited tiles layout is wrong.", - mvtContainerWidth < mvTilesLayoutWidth); - int mvtWithPadding = mvTilesItemWidth + mvt2LeftMargin; - int visibleMvtNum = mvtContainerWidth / mvtWithPadding; - Assert.assertEquals("It fails to meet the requirement that half of " - + "the most visited tiles element should be at the end of the MV tiles " - + "when the new tab page is initially loaded.", - mvtContainerWidth - visibleMvtNum * mvtWithPadding, mvTilesItemWidth / 2, - mvTilesItemWidth / 20); + mvtContainerWidth <= mvTilesLayoutWidth); + int tileNum = + ((ViewGroup) ntpLayout.findViewById(org.chromium.chrome.R.id.mv_tiles_layout)) + .getChildCount(); + int minIntervalMargin = ntpLayout.getResources().getDimensionPixelOffset( + org.chromium.chrome.R.dimen.tile_carousel_layout_min_interval_margin_tablet); + boolean isHalfMvt = tileNum * mvTilesItemWidth + (tileNum - 1) * minIntervalMargin + > mvtContainerWidth; + if (isHalfMvt) { + Assert.assertEquals( + "The container's margin with respect to the layout of the new tab " + + "page is incorrect.", + expectedContainerTwoSideMargin + expectedContainerRightExtraMargin, + ntpLayout.getWidth() - mvtContainerWidth, 3); + int mvtWithPadding = mvTilesItemWidth + mvt2LeftMargin; + int visibleMvtNum = mvtContainerWidth / mvtWithPadding; + Assert.assertEquals("It fails to meet the requirement that half of " + + "the most visited tiles element should be at the end of the MV " + + "tiles when the new tab page is initially loaded with too many " + + "tile elements.", + mvtContainerWidth - visibleMvtNum * mvtWithPadding, mvTilesItemWidth / 2, + mvTilesItemWidth / 20); + } else { + Assert.assertTrue( + "The container's margin with respect to the layout of the new tab " + + "page is incorrect.", + expectedContainerTwoSideMargin <= ntpLayout.getWidth() - mvtContainerWidth); + Assert.assertEquals("It fails to meet the requirement that all of " + + "the most visited tiles element should be fitted in the MV tiles " + + "when the new tab page is initially loaded without too many tile " + + "elements.", + mvtContainerWidth, + tileNum * mvTilesItemWidth + (tileNum - 1) * mvt2LeftMargin); + } } else { + Assert.assertEquals("The container's margin with respect to the " + + "layout of the new tab page is incorrect.", + expectedContainerTwoSideMargin, ntpLayout.getWidth() - mvtContainerWidth, 3); Assert.assertTrue("The width of the most visited tiles layout is wrong.", mvtContainerWidth == mvTilesLayoutWidth); int minHorizontalSpacing = ((MostVisitedTilesGridLayout) mvTilesLayout) @@ -685,7 +716,7 @@ private void verifyMostVisitedTileMarginImpl(View ntpLayout, View mvTilesContain int expectedIntervalPadding = Math.round((float) (mvTilesLayoutWidth - mvTilesItemWidth * numColumns - expectedEdgeMargin * 2) - / (numColumns - 1)); + / Math.max(1, numColumns - 1)); if (expectedIntervalPadding >= minHorizontalSpacing && expectedIntervalPadding <= maxHorizontalSpacing) { Assert.assertEquals("The edge margin of the most visited tiles element to " diff --git a/chrome/android/java/res/values/dimens.xml b/chrome/android/java/res/values/dimens.xml index 8c784bb4a3ab4..4a158681547cc 100644 --- a/chrome/android/java/res/values/dimens.xml +++ b/chrome/android/java/res/values/dimens.xml @@ -165,7 +165,8 @@ found in the LICENSE file. 48dp 100dp 84dp - 64dp + 48dp + 16dp 48dp 40dp 6dp diff --git a/chrome/android/java/src/org/chromium/chrome/browser/ntp/NewTabPageLayout.java b/chrome/android/java/src/org/chromium/chrome/browser/ntp/NewTabPageLayout.java index 18aa1196ebf89..05b0d0a062596 100644 --- a/chrome/android/java/src/org/chromium/chrome/browser/ntp/NewTabPageLayout.java +++ b/chrome/android/java/src/org/chromium/chrome/browser/ntp/NewTabPageLayout.java @@ -82,9 +82,8 @@ public class NewTabPageLayout extends LinearLayout { private final Context mContext; private int mSearchBoxEndPadding = UNSET_RESOURCE_FLAG; - private final int mMvtLandscapeLeftMarginTablet; - private final int mMvtLandscapeRightMarginTablet; - private final int mMvtPortraitRightMarginTablet; + private final int mMvtLandscapeLateralMarginTablet; + private final int mMvtExtraRightMarginTablet; private View mMiddleSpacer; // Spacer between toolbar and Most Likely. @@ -142,6 +141,12 @@ public class NewTabPageLayout extends LinearLayout { private NewTabPageUma mNewTabPageUma; + private int mTileViewWidth; + private int mTileViewMinIntervalPaddingTablet; + private Integer mInitialTileNum; + private Boolean mIsHalfMvtLandscape; + private Boolean mIsHalfMvtPortrait; + /** * Constructor for inflating from XML. */ @@ -150,12 +155,14 @@ public NewTabPageLayout(Context context, AttributeSet attrs) { mContext = context; Resources res = getResources(); mTileGridLayoutBleed = res.getDimensionPixelSize(R.dimen.tile_grid_layout_bleed); - mMvtLandscapeLeftMarginTablet = + mMvtLandscapeLateralMarginTablet = res.getDimensionPixelSize(R.dimen.ntp_search_box_start_margin); - mMvtPortraitRightMarginTablet = res.getDimensionPixelSize( + mMvtExtraRightMarginTablet = res.getDimensionPixelSize( R.dimen.mvt_container_to_ntp_right_extra_margin_two_feed_tablet); - mMvtLandscapeRightMarginTablet = - mMvtLandscapeLeftMarginTablet + mMvtPortraitRightMarginTablet; + mTileViewWidth = + getResources().getDimensionPixelOffset(org.chromium.chrome.R.dimen.tile_view_width); + mTileViewMinIntervalPaddingTablet = getResources().getDimensionPixelOffset( + org.chromium.chrome.R.dimen.tile_carousel_layout_min_interval_margin_tablet); } @Override @@ -451,10 +458,45 @@ public View getSearchBoxView() { @Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { + if (mIsNtpAsHomeSurfaceEnabled && mIsMultiColumnFeedEnabled && isScrollableMvtEnabled()) { + calculateTabletMvtMargin(MeasureSpec.getSize(widthMeasureSpec)); + } super.onMeasure(widthMeasureSpec, heightMeasureSpec); unifyElementWidths(); } + /** + * Update the right margin for the MV tiles container if needed to have half tile element + * in the end of the MV tiles when used in NTP on the tablet. + */ + private void calculateTabletMvtMargin(int widthMeasureSpec) { + if (mMvTilesContainerLayout.getVisibility() == GONE) return; + + if (mInitialTileNum == null) { + mInitialTileNum = ((ViewGroup) findViewById(R.id.mv_tiles_layout)).getChildCount(); + } + + int currentOrientation = getResources().getConfiguration().orientation; + if ((currentOrientation == Configuration.ORIENTATION_LANDSCAPE + && mIsHalfMvtLandscape == null) + || (currentOrientation == Configuration.ORIENTATION_PORTRAIT + && mIsHalfMvtPortrait == null)) { + MarginLayoutParams marginLayoutParams = + (MarginLayoutParams) mMvTilesContainerLayout.getLayoutParams(); + int mvtContainerWidth = widthMeasureSpec - marginLayoutParams.leftMargin + - marginLayoutParams.rightMargin; + boolean isHalfMvt = mInitialTileNum * mTileViewWidth + + (mInitialTileNum - 1) * mTileViewMinIntervalPaddingTablet + > mvtContainerWidth; + if (currentOrientation == Configuration.ORIENTATION_LANDSCAPE) { + mIsHalfMvtLandscape = isHalfMvt; + } else { + mIsHalfMvtPortrait = isHalfMvt; + } + updateTilesLayoutLeftAndRightMarginsOnTablet(marginLayoutParams); + } + } + public void onSwitchToForeground() { if (mMostVisitedTilesCoordinator != null) { mMostVisitedTilesCoordinator.onSwitchToForeground(); @@ -524,7 +566,6 @@ private void updateTilesLayoutMargins() { // Let mMvTilesContainerLayout attached to the edge of the screen. setClipToPadding(false); if (mIsNtpAsHomeSurfaceEnabled && mIsMultiColumnFeedEnabled) { - ((LayoutParams) marginLayoutParams).gravity = Gravity.START; updateTilesLayoutLeftAndRightMarginsOnTablet(marginLayoutParams); } else { int lateralPaddingsForNTP = -getResources().getDimensionPixelSize( @@ -955,13 +996,19 @@ public void onConfigurationChanged(Configuration newConfig) { */ private void updateTilesLayoutLeftAndRightMarginsOnTablet( MarginLayoutParams marginLayoutParams) { + ((LayoutParams) marginLayoutParams).gravity = Gravity.CENTER_HORIZONTAL; int leftMarginForNtp = mTileGridLayoutBleed / 2; int rightMarginForNtp = leftMarginForNtp; if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) { - leftMarginForNtp = leftMarginForNtp + mMvtLandscapeLeftMarginTablet; - rightMarginForNtp = rightMarginForNtp + mMvtLandscapeRightMarginTablet; - } else { - rightMarginForNtp = rightMarginForNtp + mMvtPortraitRightMarginTablet; + leftMarginForNtp = leftMarginForNtp + mMvtLandscapeLateralMarginTablet; + rightMarginForNtp = rightMarginForNtp + mMvtLandscapeLateralMarginTablet; + if (mIsHalfMvtLandscape != null && mIsHalfMvtLandscape) { + ((LayoutParams) marginLayoutParams).gravity = Gravity.START; + rightMarginForNtp = rightMarginForNtp + mMvtExtraRightMarginTablet; + } + } else if (mIsHalfMvtPortrait != null && mIsHalfMvtPortrait) { + ((LayoutParams) marginLayoutParams).gravity = Gravity.START; + rightMarginForNtp = rightMarginForNtp + mMvtExtraRightMarginTablet; } marginLayoutParams.leftMargin = leftMarginForNtp; marginLayoutParams.rightMargin = rightMarginForNtp; diff --git a/chrome/android/java/src/org/chromium/chrome/browser/suggestions/tile/MostVisitedTilesCarouselLayout.java b/chrome/android/java/src/org/chromium/chrome/browser/suggestions/tile/MostVisitedTilesCarouselLayout.java index e4d89e6472f10..d2967260985eb 100644 --- a/chrome/android/java/src/org/chromium/chrome/browser/suggestions/tile/MostVisitedTilesCarouselLayout.java +++ b/chrome/android/java/src/org/chromium/chrome/browser/suggestions/tile/MostVisitedTilesCarouselLayout.java @@ -40,7 +40,7 @@ public MostVisitedTilesCarouselLayout(Context context, AttributeSet attrs) { mTileViewWidth = getResources().getDimensionPixelOffset(org.chromium.chrome.R.dimen.tile_view_width); mTileViewMinIntervalPaddingTablet = getResources().getDimensionPixelOffset( - org.chromium.chrome.R.dimen.tile_view_padding); + org.chromium.chrome.R.dimen.tile_carousel_layout_min_interval_margin_tablet); mTileViewMaxIntervalPaddingTablet = getResources().getDimensionPixelOffset( org.chromium.chrome.R.dimen.tile_carousel_layout_max_interval_margin_tablet); } @@ -113,27 +113,29 @@ void updateIntervalPaddingsTablet(boolean isOrientationLandscape) { /** * Computes the distance between each MV tiles element based on certain parameters. - * @param totalWidth The total width of the most recent tile, - * excluding the half MV tiles element at the end. + * @param totalWidth The total width of the MV tiles. + * @param isHalfMvt Whether there should be half MV tiles element at the end. * @return The median value of the appropriate distances calculated as the distance between * each MV tiles element. */ @VisibleForTesting - public int calculateTabletIntervalPadding(int totalWidth) { - int tileWidthWithMinInternalPadding = mTileViewWidth - mTileViewMinIntervalPaddingTablet; - int tileWidthWithMaxInternalPadding = mTileViewWidth + mTileViewMaxIntervalPaddingTablet; - int maxElements = totalWidth / tileWidthWithMinInternalPadding; - int minElements = (int) Math.ceil((double) totalWidth / tileWidthWithMaxInternalPadding); - int preferElements = (minElements + Math.min(maxElements, mInitialTileNum - 1)) / 2; - return (totalWidth - preferElements * mTileViewWidth) / preferElements; + public int calculateTabletIntervalPadding(int totalWidth, boolean isHalfMvt) { + if (isHalfMvt) { + int preferElements = (totalWidth - mTileViewWidth / 2) + / (mTileViewWidth + mTileViewMinIntervalPaddingTablet); + return (totalWidth - mTileViewWidth / 2 - preferElements * mTileViewWidth) + / Math.max(1, preferElements); + } + return Math.min((totalWidth - mInitialTileNum * mTileViewWidth) + / Math.max(1, (mInitialTileNum - 1)), + mTileViewMaxIntervalPaddingTablet); } @Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { if (mIsMultiColumnFeedOnTabletEnabled) { if (mInitialTileNum == null) { - mInitialTileNum = Math.min(Math.max(getChildCount(), MIN_RESULTS), - MostVisitedTilesMediator.MAX_RESULTS); + mInitialTileNum = getChildCount(); } int currentOrientation = getResources().getConfiguration().orientation; @@ -141,9 +143,10 @@ protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { && mIntervalPaddingsLandscapeTablet == null) || (currentOrientation == Configuration.ORIENTATION_PORTRAIT && mIntervalPaddingsPortraitTablet == null)) { - int totalWidth = Math.min(MeasureSpec.getSize(widthMeasureSpec), Integer.MAX_VALUE) - - mTileViewWidth / 2; - int tileViewIntervalPadding = calculateTabletIntervalPadding(totalWidth); + int totalWidth = Math.min(MeasureSpec.getSize(widthMeasureSpec), Integer.MAX_VALUE); + boolean isHalfMvt = totalWidth < mInitialTileNum * mTileViewWidth + + (mInitialTileNum - 1) * mTileViewMinIntervalPaddingTablet; + int tileViewIntervalPadding = calculateTabletIntervalPadding(totalWidth, isHalfMvt); if (currentOrientation == Configuration.ORIENTATION_LANDSCAPE) { mIntervalPaddingsLandscapeTablet = tileViewIntervalPadding; } else { diff --git a/chrome/android/javatests/src/org/chromium/chrome/browser/suggestions/tile/MostVisitedTilesLayoutUnitTest.java b/chrome/android/javatests/src/org/chromium/chrome/browser/suggestions/tile/MostVisitedTilesLayoutUnitTest.java index 9fa5e1b9d8e11..1da9cb35a0ea3 100644 --- a/chrome/android/javatests/src/org/chromium/chrome/browser/suggestions/tile/MostVisitedTilesLayoutUnitTest.java +++ b/chrome/android/javatests/src/org/chromium/chrome/browser/suggestions/tile/MostVisitedTilesLayoutUnitTest.java @@ -34,48 +34,63 @@ public void setUpTest() throws Exception { @UiThreadTest @SmallTest public void testCalculateTabletIntervalPadding() { - int tileNum = 8; - mMvTilesLayout.setInitialTileNumForTesting(tileNum); - int tileViewWidth = 160; mMvTilesLayout.setTileViewWidthForTesting(tileViewWidth); - int tileViewMinIntervalPaddingTablet = 8; + int tileViewMinIntervalPaddingTablet = 32; mMvTilesLayout.setTileViewMinIntervalPaddingTabletForTesting( tileViewMinIntervalPaddingTablet); - int tileViewMaxIntervalPaddingTablet = 128; + int tileViewMaxIntervalPaddingTablet = 96; mMvTilesLayout.setTileViewMaxIntervalPaddingTabletForTesting( tileViewMaxIntervalPaddingTablet); - int totalWidth = 1392; - int expectedIntervalPadding = 72; - int intervalPadding = mMvTilesLayout.calculateTabletIntervalPadding(totalWidth); + int tileNum = 8; + mMvTilesLayout.setInitialTileNumForTesting(tileNum); + + int totalWidth = 1504; + int expectedIntervalPadding = 32; + int intervalPadding = + mMvTilesLayout.calculateTabletIntervalPadding(totalWidth, /*isHalfMvt=*/false); Assert.assertEquals("The result of function CalculateTabletIntervalPadding is wrong", expectedIntervalPadding, intervalPadding); - totalWidth = 1416; - expectedIntervalPadding = 76; - intervalPadding = mMvTilesLayout.calculateTabletIntervalPadding(totalWidth); + totalWidth = 1528; + expectedIntervalPadding = 35; + intervalPadding = + mMvTilesLayout.calculateTabletIntervalPadding(totalWidth, /*isHalfMvt=*/false); Assert.assertEquals("The result of function CalculateTabletIntervalPadding is wrong", expectedIntervalPadding, intervalPadding); - tileViewWidth = 100; - mMvTilesLayout.setTileViewWidthForTesting(tileViewWidth); - tileViewMinIntervalPaddingTablet = 5; - mMvTilesLayout.setTileViewMinIntervalPaddingTabletForTesting( - tileViewMinIntervalPaddingTablet); - tileViewMaxIntervalPaddingTablet = 80; - mMvTilesLayout.setTileViewMaxIntervalPaddingTabletForTesting( - tileViewMaxIntervalPaddingTablet); + tileNum = 12; + mMvTilesLayout.setInitialTileNumForTesting(tileNum); + + totalWidth = 1472; + expectedIntervalPadding = 38; + intervalPadding = + mMvTilesLayout.calculateTabletIntervalPadding(totalWidth, /*isHalfMvt=*/true); + Assert.assertEquals("The result of function CalculateTabletIntervalPadding is wrong", + expectedIntervalPadding, intervalPadding); + + totalWidth = 1496; + expectedIntervalPadding = 42; + intervalPadding = + mMvTilesLayout.calculateTabletIntervalPadding(totalWidth, /*isHalfMvt=*/true); + Assert.assertEquals("The result of function CalculateTabletIntervalPadding is wrong", + expectedIntervalPadding, intervalPadding); + + tileNum = 3; + mMvTilesLayout.setInitialTileNumForTesting(tileNum); - totalWidth = 930; - expectedIntervalPadding = 55; - intervalPadding = mMvTilesLayout.calculateTabletIntervalPadding(totalWidth); + totalWidth = 1504; + expectedIntervalPadding = 96; + intervalPadding = + mMvTilesLayout.calculateTabletIntervalPadding(totalWidth, /*isHalfMvt=*/false); Assert.assertEquals("The result of function CalculateTabletIntervalPadding is wrong", expectedIntervalPadding, intervalPadding); - totalWidth = 1270; - expectedIntervalPadding = 81; - intervalPadding = mMvTilesLayout.calculateTabletIntervalPadding(totalWidth); + totalWidth = 1528; + expectedIntervalPadding = 96; + intervalPadding = + mMvTilesLayout.calculateTabletIntervalPadding(totalWidth, /*isHalfMvt=*/false); Assert.assertEquals("The result of function CalculateTabletIntervalPadding is wrong", expectedIntervalPadding, intervalPadding); }