Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(94)

Side by Side Diff: chrome/android/java/src/org/chromium/chrome/browser/ntp/NewTabPageView.java

Issue 2714723002: Add feature for condensed NTP tiles. (Closed)
Patch Set: Cleanups. Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 package org.chromium.chrome.browser.ntp; 5 package org.chromium.chrome.browser.ntp;
6 6
7 import android.annotation.SuppressLint; 7 import android.annotation.SuppressLint;
8 import android.content.Context; 8 import android.content.Context;
9 import android.content.res.Configuration; 9 import android.content.res.Configuration;
10 import android.graphics.Canvas; 10 import android.graphics.Canvas;
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
69 * Experiment parameter for the maximum number of tile suggestion rows to sh ow. 69 * Experiment parameter for the maximum number of tile suggestion rows to sh ow.
70 */ 70 */
71 private static final String PARAM_NTP_MAX_TILE_ROWS = "ntp_max_tile_rows"; 71 private static final String PARAM_NTP_MAX_TILE_ROWS = "ntp_max_tile_rows";
72 72
73 /** 73 /**
74 * Experiment parameter for the number of tile title lines to show. 74 * Experiment parameter for the number of tile title lines to show.
75 */ 75 */
76 private static final String PARAM_NTP_TILE_TITLE_LINES = "ntp_tile_title_lin es"; 76 private static final String PARAM_NTP_TILE_TITLE_LINES = "ntp_tile_title_lin es";
77 77
78 /** 78 /**
79 * The maximum number of tiles to try and fit in a row. On smaller screens, there may not be 79 * Experiment parameter for whether to use the condensed tile layout on smal l screens.
80 * enough space to fit all of them.
81 */ 80 */
82 private static final int MAX_TILE_COLUMNS = 4; 81 private static final String PARAM_CONDENSED_TILE_LAYOUT_FOR_SMALL_SCREENS_EN ABLED =
82 "condensed_tile_layout_for_small_screens_enabled";
83
84 /**
85 * Experiment parameter for whether to use the condensed tile layout on larg e screens.
86 */
87 private static final String PARAM_CONDENSED_TILE_LAYOUT_FOR_LARGE_SCREENS_EN ABLED =
88 "condensed_tile_layout_for_large_screens_enabled";
83 89
84 private NewTabPageRecyclerView mRecyclerView; 90 private NewTabPageRecyclerView mRecyclerView;
85 91
86 private NewTabPageLayout mNewTabPageLayout; 92 private NewTabPageLayout mNewTabPageLayout;
87 private LogoView mSearchProviderLogoView; 93 private LogoView mSearchProviderLogoView;
88 private View mSearchBoxView; 94 private View mSearchBoxView;
89 private ImageView mVoiceSearchButton; 95 private ImageView mVoiceSearchButton;
90 private TileGridLayout mTileGridLayout; 96 private TileGridLayout mTileGridLayout;
91 private View mTileGridPlaceholder; 97 private View mTileGridPlaceholder;
92 private View mNoSearchLogoSpacer; 98 private View mNoSearchLogoSpacer;
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
227 public void onDestroy() { 233 public void onDestroy() {
228 mActivity.getWindowAndroid().removeContextMenuCloseListener(mCon textMenuManager); 234 mActivity.getWindowAndroid().removeContextMenuCloseListener(mCon textMenuManager);
229 } 235 }
230 }); 236 });
231 237
232 OfflinePageBridge offlinePageBridge = 238 OfflinePageBridge offlinePageBridge =
233 OfflinePageBridge.getForProfile(Profile.getLastUsedProfile()); 239 OfflinePageBridge.getForProfile(Profile.getLastUsedProfile());
234 240
235 mTileGridLayout = (TileGridLayout) mNewTabPageLayout.findViewById(R.id.t ile_grid_layout); 241 mTileGridLayout = (TileGridLayout) mNewTabPageLayout.findViewById(R.id.t ile_grid_layout);
236 mTileGridLayout.setMaxRows(getMaxTileRows(searchProviderHasLogo)); 242 mTileGridLayout.setMaxRows(getMaxTileRows(searchProviderHasLogo));
243 mTileGridLayout.setMaxColumns(getMaxTileColumns());
237 mTileGroup = new TileGroup(mActivity, mManager, mContextMenuManager, mTi leGroupDelegate, 244 mTileGroup = new TileGroup(mActivity, mManager, mContextMenuManager, mTi leGroupDelegate,
238 /* observer = */ this, offlinePageBridge, getTileTitleLines()); 245 /* observer = */ this, offlinePageBridge, getTileTitleLines());
239 246
240 mSearchProviderLogoView = 247 mSearchProviderLogoView =
241 (LogoView) mNewTabPageLayout.findViewById(R.id.search_provider_l ogo); 248 (LogoView) mNewTabPageLayout.findViewById(R.id.search_provider_l ogo);
242 mSearchBoxView = mNewTabPageLayout.findViewById(R.id.search_box); 249 mSearchBoxView = mNewTabPageLayout.findViewById(R.id.search_box);
243 mNoSearchLogoSpacer = mNewTabPageLayout.findViewById(R.id.no_search_logo _spacer); 250 mNoSearchLogoSpacer = mNewTabPageLayout.findViewById(R.id.no_search_logo _spacer);
244 251
245 initializeSearchBoxTextView(); 252 initializeSearchBoxTextView();
246 initializeVoiceSearchButton(); 253 initializeVoiceSearchButton();
247 254
248 mNewTabPageLayout.addOnLayoutChangeListener(this); 255 mNewTabPageLayout.addOnLayoutChangeListener(this);
249 setSearchProviderHasLogo(searchProviderHasLogo); 256 setSearchProviderHasLogo(searchProviderHasLogo);
250 257
251 mTileGroup.startObserving(getMaxTileRows(searchProviderHasLogo) * MAX_TI LE_COLUMNS); 258 mTileGroup.startObserving(getMaxTileRows(searchProviderHasLogo) * getMax TileColumns());
252 259
253 // Set up snippets 260 // Set up snippets
254 NewTabPageAdapter newTabPageAdapter = new NewTabPageAdapter(mManager, mN ewTabPageLayout, 261 NewTabPageAdapter newTabPageAdapter = new NewTabPageAdapter(mManager, mN ewTabPageLayout,
255 mUiConfig, offlinePageBridge, mContextMenuManager, /* tileGroupD elegate = */ null); 262 mUiConfig, offlinePageBridge, mContextMenuManager, /* tileGroupD elegate = */ null);
256 mRecyclerView.setAdapter(newTabPageAdapter); 263 mRecyclerView.setAdapter(newTabPageAdapter);
257 264
258 int scrollOffset; 265 int scrollOffset;
259 if (CardsVariationParameters.isScrollBelowTheFoldEnabled()) { 266 if (CardsVariationParameters.isScrollBelowTheFoldEnabled()) {
260 scrollPosition = newTabPageAdapter.getFirstHeaderPosition(); 267 scrollPosition = newTabPageAdapter.getFirstHeaderPosition();
261 scrollOffset = getResources().getDimensionPixelSize(R.dimen.ntp_sear ch_box_height); 268 scrollOffset = getResources().getDimensionPixelSize(R.dimen.ntp_sear ch_box_height);
(...skipping 536 matching lines...) Expand 10 before | Expand all | Expand 10 after
798 private static int getMaxTileRows(boolean searchProviderHasLogo) { 805 private static int getMaxTileRows(boolean searchProviderHasLogo) {
799 int defaultValue = 2; 806 int defaultValue = 2;
800 if (!ChromeFeatureList.isEnabled(ChromeFeatureList.NTP_CONDENSED_LAYOUT) 807 if (!ChromeFeatureList.isEnabled(ChromeFeatureList.NTP_CONDENSED_LAYOUT)
801 && !searchProviderHasLogo) { 808 && !searchProviderHasLogo) {
802 defaultValue = 3; 809 defaultValue = 3;
803 } 810 }
804 return ChromeFeatureList.getFieldTrialParamByFeatureAsInt( 811 return ChromeFeatureList.getFieldTrialParamByFeatureAsInt(
805 ChromeFeatureList.NTP_CONDENSED_LAYOUT, PARAM_NTP_MAX_TILE_ROWS, defaultValue); 812 ChromeFeatureList.NTP_CONDENSED_LAYOUT, PARAM_NTP_MAX_TILE_ROWS, defaultValue);
806 } 813 }
807 814
815 /**
816 * Determines The maximum number of tiles to try and fit in a row. On smalle r screens, there
817 * may not be enough space to fit all of them.
818 */
819 private int getMaxTileColumns() {
820 if (!mUiConfig.getCurrentDisplayStyle().isSmall()
821 && ChromeFeatureList.getFieldTrialParamByFeatureAsBoolean(
822 ChromeFeatureList.NTP_CONDENSED_TILE_LAYOUT,
823 PARAM_CONDENSED_TILE_LAYOUT_FOR_LARGE_SCREENS_ENABLED , false)) {
824 return 5;
825 }
826 return 4;
827 }
828
808 private static int getTileTitleLines() { 829 private static int getTileTitleLines() {
809 int defaultValue = 2; 830 int defaultValue = 2;
810 if (ChromeFeatureList.isEnabled(ChromeFeatureList.NTP_CONDENSED_LAYOUT)) { 831 if (ChromeFeatureList.isEnabled(ChromeFeatureList.NTP_CONDENSED_LAYOUT)) {
811 defaultValue = 1; 832 defaultValue = 1;
812 } 833 }
813 return ChromeFeatureList.getFieldTrialParamByFeatureAsInt( 834 return ChromeFeatureList.getFieldTrialParamByFeatureAsInt(
814 ChromeFeatureList.NTP_CONDENSED_LAYOUT, PARAM_NTP_TILE_TITLE_LIN ES, defaultValue); 835 ChromeFeatureList.NTP_CONDENSED_LAYOUT, PARAM_NTP_TILE_TITLE_LIN ES, defaultValue);
815 } 836 }
816 837
838 private boolean shouldUseCondensedTileLayout() {
839 if (mUiConfig.getCurrentDisplayStyle().isSmall()) {
840 return ChromeFeatureList.getFieldTrialParamByFeatureAsBoolean(
841 ChromeFeatureList.NTP_CONDENSED_TILE_LAYOUT,
842 PARAM_CONDENSED_TILE_LAYOUT_FOR_SMALL_SCREENS_ENABLED, false );
843 }
844 return ChromeFeatureList.getFieldTrialParamByFeatureAsBoolean(
845 ChromeFeatureList.NTP_CONDENSED_TILE_LAYOUT,
846 PARAM_CONDENSED_TILE_LAYOUT_FOR_LARGE_SCREENS_ENABLED, false);
847 }
848
817 @Override 849 @Override
818 protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { 850 protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
819 if (mNewTabPageLayout != null) { 851 if (mNewTabPageLayout != null) {
820 mNewTabPageLayout.setParentViewportHeight(MeasureSpec.getSize(height MeasureSpec)); 852 mNewTabPageLayout.setParentViewportHeight(MeasureSpec.getSize(height MeasureSpec));
821 } 853 }
822 super.onMeasure(widthMeasureSpec, heightMeasureSpec); 854 super.onMeasure(widthMeasureSpec, heightMeasureSpec);
823 855
824 mRecyclerView.updatePeekingCardAndHeader(); 856 mRecyclerView.updatePeekingCardAndHeader();
825 } 857 }
826 858
(...skipping 21 matching lines...) Expand all
848 880
849 /** @return the context menu manager. */ 881 /** @return the context menu manager. */
850 public ContextMenuManager getContextMenuManager() { 882 public ContextMenuManager getContextMenuManager() {
851 return mContextMenuManager; 883 return mContextMenuManager;
852 } 884 }
853 885
854 // TileGroup.Observer interface. 886 // TileGroup.Observer interface.
855 887
856 @Override 888 @Override
857 public void onTileDataChanged() { 889 public void onTileDataChanged() {
858 mTileGroup.renderTileViews(mTileGridLayout, !mLoadHasCompleted); 890 mTileGroup.renderTileViews(
891 mTileGridLayout, !mLoadHasCompleted, shouldUseCondensedTileLayou t());
859 mSnapshotTileGridChanged = true; 892 mSnapshotTileGridChanged = true;
860 893
861 // The page contents are initially hidden; otherwise they'll be drawn ce ntered on the page 894 // The page contents are initially hidden; otherwise they'll be drawn ce ntered on the page
862 // before the tiles are available and then jump upwards to make space on ce the tiles are 895 // before the tiles are available and then jump upwards to make space on ce the tiles are
863 // available. 896 // available.
864 if (mNewTabPageLayout.getVisibility() != View.VISIBLE) { 897 if (mNewTabPageLayout.getVisibility() != View.VISIBLE) {
865 mNewTabPageLayout.setVisibility(View.VISIBLE); 898 mNewTabPageLayout.setVisibility(View.VISIBLE);
866 } 899 }
867 } 900 }
868 901
(...skipping 20 matching lines...) Expand all
889 @Override 922 @Override
890 public void onLoadTaskAdded() { 923 public void onLoadTaskAdded() {
891 mPendingLoadTasks++; 924 mPendingLoadTasks++;
892 } 925 }
893 926
894 @Override 927 @Override
895 public void onLoadTaskCompleted() { 928 public void onLoadTaskCompleted() {
896 loadTaskCompleted(); 929 loadTaskCompleted();
897 } 930 }
898 } 931 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698