Chromium Code Reviews| Index: chrome/android/java/src/org/chromium/chrome/browser/ntp/NewTabPageView.java |
| diff --git a/chrome/android/java/src/org/chromium/chrome/browser/ntp/NewTabPageView.java b/chrome/android/java/src/org/chromium/chrome/browser/ntp/NewTabPageView.java |
| index 53d8d2f157ed7ee18085ee81ff24fd0925a84183..8546b1c06bdcd46e61180ea880b2b30fbc48353f 100644 |
| --- a/chrome/android/java/src/org/chromium/chrome/browser/ntp/NewTabPageView.java |
| +++ b/chrome/android/java/src/org/chromium/chrome/browser/ntp/NewTabPageView.java |
| @@ -76,10 +76,16 @@ public class NewTabPageView |
| private static final String PARAM_NTP_TILE_TITLE_LINES = "ntp_tile_title_lines"; |
| /** |
| - * The maximum number of tiles to try and fit in a row. On smaller screens, there may not be |
| - * enough space to fit all of them. |
| + * Experiment parameter for whether to use the condensed tile layout on small screens. |
| */ |
| - private static final int MAX_TILE_COLUMNS = 4; |
| + private static final String PARAM_NTP_CONDENSED_TILE_LAYOUT_FOR_SMALL_SCREENS_ENABLED = |
| + "ntp_condensed_tile_layout_for_small_screens_enabled"; |
|
Alexei Svitkine (slow)
2017/02/27 15:56:27
Nit: This param name is awfully long. Can you find
Michael van Ouwerkerk
2017/02/27 16:53:57
Done. We can do without the "ntp" part if you pref
|
| + |
| + /** |
| + * Experiment parameter for whether to use the condensed tile layout on large screens. |
| + */ |
| + private static final String PARAM_NTP_CONDENSED_TILE_LAYOUT_FOR_LARGE_SCREENS_ENABLED = |
| + "ntp_condensed_tile_layout_for_large_screens_enabled"; |
| private NewTabPageRecyclerView mRecyclerView; |
| @@ -234,6 +240,7 @@ public class NewTabPageView |
| mTileGridLayout = (TileGridLayout) mNewTabPageLayout.findViewById(R.id.tile_grid_layout); |
| mTileGridLayout.setMaxRows(getMaxTileRows(searchProviderHasLogo)); |
| + mTileGridLayout.setMaxColumns(getMaxTileColumns()); |
| mTileGroup = new TileGroup(mActivity, mManager, mContextMenuManager, mTileGroupDelegate, |
| /* observer = */ this, offlinePageBridge, getTileTitleLines()); |
| @@ -248,7 +255,7 @@ public class NewTabPageView |
| mNewTabPageLayout.addOnLayoutChangeListener(this); |
| setSearchProviderHasLogo(searchProviderHasLogo); |
| - mTileGroup.startObserving(getMaxTileRows(searchProviderHasLogo) * MAX_TILE_COLUMNS); |
| + mTileGroup.startObserving(getMaxTileRows(searchProviderHasLogo) * getMaxTileColumns()); |
| // Set up snippets |
| NewTabPageAdapter newTabPageAdapter = new NewTabPageAdapter(mManager, mNewTabPageLayout, |
| @@ -805,6 +812,20 @@ public class NewTabPageView |
| ChromeFeatureList.NTP_CONDENSED_LAYOUT, PARAM_NTP_MAX_TILE_ROWS, defaultValue); |
| } |
| + /** |
| + * Determines The maximum number of tiles to try and fit in a row. On smaller screens, there |
| + * may not be enough space to fit all of them. |
| + */ |
| + private int getMaxTileColumns() { |
| + if (!mUiConfig.getCurrentDisplayStyle().isSmall() |
| + && ChromeFeatureList.getFieldTrialParamByFeatureAsBoolean( |
| + ChromeFeatureList.NTP_CONDENSED_TILE_LAYOUT, |
| + PARAM_NTP_CONDENSED_TILE_LAYOUT_FOR_LARGE_SCREENS_ENABLED, false)) { |
| + return 5; |
| + } |
| + return 4; |
| + } |
| + |
| private static int getTileTitleLines() { |
| int defaultValue = 2; |
| if (ChromeFeatureList.isEnabled(ChromeFeatureList.NTP_CONDENSED_LAYOUT)) { |
| @@ -814,6 +835,17 @@ public class NewTabPageView |
| ChromeFeatureList.NTP_CONDENSED_LAYOUT, PARAM_NTP_TILE_TITLE_LINES, defaultValue); |
| } |
| + private boolean shouldUseCondensedTileLayout() { |
| + if (mUiConfig.getCurrentDisplayStyle().isSmall()) { |
| + return ChromeFeatureList.getFieldTrialParamByFeatureAsBoolean( |
| + ChromeFeatureList.NTP_CONDENSED_TILE_LAYOUT, |
| + PARAM_NTP_CONDENSED_TILE_LAYOUT_FOR_SMALL_SCREENS_ENABLED, false); |
| + } |
| + return ChromeFeatureList.getFieldTrialParamByFeatureAsBoolean( |
| + ChromeFeatureList.NTP_CONDENSED_TILE_LAYOUT, |
| + PARAM_NTP_CONDENSED_TILE_LAYOUT_FOR_LARGE_SCREENS_ENABLED, false); |
|
Alexei Svitkine (slow)
2017/02/27 15:56:27
Nit: Maybe make a helper function in this file tha
Michael van Ouwerkerk
2017/02/27 16:53:57
I'm not sure another helper function would help mu
|
| + } |
| + |
| @Override |
| protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { |
| if (mNewTabPageLayout != null) { |
| @@ -855,7 +887,8 @@ public class NewTabPageView |
| @Override |
| public void onTileDataChanged() { |
| - mTileGroup.renderTileViews(mTileGridLayout, !mLoadHasCompleted); |
| + mTileGroup.renderTileViews( |
| + mTileGridLayout, !mLoadHasCompleted, shouldUseCondensedTileLayout()); |
| mSnapshotTileGridChanged = true; |
| // The page contents are initially hidden; otherwise they'll be drawn centered on the page |