summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-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