summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authornewt <newt@chromium.org>2015-08-11 17:14:13 -0700
committerCommit bot <commit-bot@chromium.org>2015-08-12 00:14:45 +0000
commit17e96910eb69f6c05573b8a295dcb1792918e490 (patch)
tree73ac3b5c504b4e97febafd7ea5873de2857511ab
parentc0117efcdcd46d16aa8b5ad12a0a2ded7a108299 (diff)
downloadchromium_src-17e96910eb69f6c05573b8a295dcb1792918e490.zip
chromium_src-17e96910eb69f6c05573b8a295dcb1792918e490.tar.gz
chromium_src-17e96910eb69f6c05573b8a295dcb1792918e490.tar.bz2
Avoid partial rows of most visited icons on the NTP.
This limits the number of rows of most visited tiles that will be displayed on the new tab page, and hence ensures that we don't show partial rows. Previously on narrow devices, we'd show 8 tiles over three rows, which feels unbalanced. Now we show just 2 rows (which happens to be 6 tiles). In non-Google mode, we show 3 rows (up to 12 tiles). Before: X X X X X X X X After: X X X X X X BUG=504367 Review URL: https://codereview.chromium.org/1275083003 Cr-Commit-Position: refs/heads/master@{#342946}
-rw-r--r--chrome/android/java/src/org/chromium/chrome/browser/ntp/IconMostVisitedLayout.java22
-rw-r--r--chrome/android/java/src/org/chromium/chrome/browser/ntp/NewTabPageView.java16
2 files changed, 36 insertions, 2 deletions
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/ntp/IconMostVisitedLayout.java b/chrome/android/java/src/org/chromium/chrome/browser/ntp/IconMostVisitedLayout.java
index 4f3bdf9..02854ce 100644
--- a/chrome/android/java/src/org/chromium/chrome/browser/ntp/IconMostVisitedLayout.java
+++ b/chrome/android/java/src/org/chromium/chrome/browser/ntp/IconMostVisitedLayout.java
@@ -27,6 +27,7 @@ public class IconMostVisitedLayout extends FrameLayout {
private int mMinHorizontalSpacing;
private int mMaxHorizontalSpacing;
private int mMaxWidth;
+ private int mMaxRows;
/**
* @param context The view context in which this item will be shown.
@@ -44,6 +45,14 @@ public class IconMostVisitedLayout extends FrameLayout {
mMaxWidth = res.getDimensionPixelOffset(R.dimen.icon_most_visited_layout_max_width);
}
+ /**
+ * Sets the maximum number of rows to display. Any items that don't fit within these rows will
+ * be hidden.
+ */
+ public void setMaxRows(int rows) {
+ mMaxRows = rows;
+ }
+
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
int totalWidth = resolveSize(mMaxWidth, widthMeasureSpec);
@@ -80,11 +89,15 @@ public class IconMostVisitedLayout extends FrameLayout {
horizontalSpacing = (float) gridWidthMinusColumns / Math.max(1, numColumns - 1);
}
+ // Limit the number of rows to mMaxRows.
+ int visibleChildCount = Math.min(childCount, mMaxRows * numColumns);
+
// Arrange the children in a grid.
int paddingTop = getPaddingTop();
boolean isRtl = ApiCompatibilityUtils.isLayoutRtl(this);
- for (int i = 0; i < childCount; i++) {
+ for (int i = 0; i < visibleChildCount; i++) {
View child = getChildAt(i);
+ child.setVisibility(View.VISIBLE);
int row = i / numColumns;
int column = i % numColumns;
int childTop = row * (childHeight + mVerticalSpacing);
@@ -94,7 +107,12 @@ public class IconMostVisitedLayout extends FrameLayout {
child.setLayoutParams(layoutParams);
}
- int numRows = (childCount + numColumns - 1) / numColumns;
+ // Hide the last row if it's incomplete.
+ for (int i = visibleChildCount; i < childCount; i++) {
+ getChildAt(i).setVisibility(View.GONE);
+ }
+
+ int numRows = (visibleChildCount + numColumns - 1) / numColumns;
int totalHeight = paddingTop + getPaddingBottom() + numRows * childHeight
+ (numRows - 1) * mVerticalSpacing;
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 a9b0ee3..8777aaf 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
@@ -271,6 +271,7 @@ public class NewTabPageView extends FrameLayout
ViewStub mostVisitedLayoutStub = (ViewStub) findViewById(R.id.most_visited_layout_stub);
mostVisitedLayoutStub.setLayoutResource(mMostVisitedDesign.getMostVisitedLayoutId());
mMostVisitedLayout = (ViewGroup) mostVisitedLayoutStub.inflate();
+ mMostVisitedDesign.initMostVisitedLayout(mMostVisitedLayout, searchProviderHasLogo);
mSearchProviderLogoView = (LogoView) findViewById(R.id.search_provider_logo);
mSearchBoxView = findViewById(R.id.search_box);
@@ -832,6 +833,7 @@ public class NewTabPageView extends FrameLayout
int getNumberOfTiles(boolean searchProviderHasLogo);
int getMostVisitedLayoutId();
int getMostVisitedLayoutBleed();
+ void initMostVisitedLayout(ViewGroup mostVisitedLayout, boolean searchProviderHasLogo);
void setSearchProviderHasLogo(View mostVisitedLayout, boolean hasLogo);
View createMostVisitedItemView(LayoutInflater inflater, String url, String title,
String displayTitle, int index, boolean isInitialLoad);
@@ -879,6 +881,11 @@ public class NewTabPageView extends FrameLayout
}
@Override
+ public void initMostVisitedLayout(ViewGroup mostVisitedLayout,
+ boolean searchProviderHasLogo) {
+ }
+
+ @Override
public void setSearchProviderHasLogo(View mostVisitedLayout, boolean hasLogo) {}
@Override
@@ -949,6 +956,8 @@ public class NewTabPageView extends FrameLayout
private static final int NUM_TILES = 8;
private static final int NUM_TILES_NO_LOGO = 12;
+ private static final int MAX_ROWS = 2;
+ private static final int MAX_ROWS_NO_LOGO = 3;
private static final int ICON_CORNER_RADIUS_DP = 4;
private static final int ICON_TEXT_SIZE_DP = 20;
@@ -994,6 +1003,13 @@ public class NewTabPageView extends FrameLayout
}
@Override
+ public void initMostVisitedLayout(ViewGroup mostVisitedLayout,
+ boolean searchProviderHasLogo) {
+ ((IconMostVisitedLayout) mostVisitedLayout).setMaxRows(
+ searchProviderHasLogo ? MAX_ROWS : MAX_ROWS_NO_LOGO);
+ }
+
+ @Override
public void setSearchProviderHasLogo(View mostVisitedLayout, boolean hasLogo) {
int paddingTop = getResources().getDimensionPixelSize(hasLogo
? R.dimen.icon_most_visited_layout_padding_top