Chromium Code Reviews| OLD | NEW |
|---|---|
| 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.content.Context; | 7 import android.content.Context; |
| 8 import android.content.res.Resources; | 8 import android.content.res.Resources; |
| 9 import android.support.v7.widget.RecyclerView; | |
| 9 import android.util.AttributeSet; | 10 import android.util.AttributeSet; |
| 10 import android.view.View; | 11 import android.view.View; |
| 11 import android.widget.LinearLayout; | 12 import android.widget.LinearLayout; |
| 12 | 13 |
| 13 import org.chromium.chrome.R; | 14 import org.chromium.chrome.R; |
| 14 | 15 |
| 15 /** | 16 /** |
| 16 * Layout for the new tab page. This positions the page elements in the correct vertical positions. | 17 * Layout for the new tab page. This positions the page elements in the correct vertical positions. |
| 17 * There are no separate phone and tablet UIs; this layout adapts based on the a vailable space. | 18 * There are no separate phone and tablet UIs; this layout adapts based on the a vailable space. |
| 18 */ | 19 */ |
| 19 public class NewTabPageLayout extends LinearLayout { | 20 public class NewTabPageLayout extends LinearLayout { |
| 20 | 21 |
| 21 // Space permitting, the spacers will grow from 0dp to the heights given bel ow. If there is | 22 // Space permitting, the spacers will grow from 0dp to the heights given bel ow. If there is |
| 22 // additional space, it will be distributed evenly between the top and botto m spacers. | 23 // additional space, it will be distributed evenly between the top and botto m spacers. |
| 23 private static final float TOP_SPACER_HEIGHT_DP = 44f; | 24 private static final float TOP_SPACER_HEIGHT_DP = 44f; |
| 24 private static final float MIDDLE_SPACER_HEIGHT_DP = 24f; | 25 private static final float MIDDLE_SPACER_HEIGHT_DP = 24f; |
| 25 private static final float BOTTOM_SPACER_HEIGHT_DP = 44f; | 26 private static final float BOTTOM_SPACER_HEIGHT_DP = 44f; |
| 26 private static final float TOTAL_SPACER_HEIGHT_DP = TOP_SPACER_HEIGHT_DP | 27 private static final float TOTAL_SPACER_HEIGHT_DP = TOP_SPACER_HEIGHT_DP |
| 27 + MIDDLE_SPACER_HEIGHT_DP + BOTTOM_SPACER_HEIGHT_DP; | 28 + MIDDLE_SPACER_HEIGHT_DP + BOTTOM_SPACER_HEIGHT_DP; |
| 28 | 29 |
| 29 private final int mTopSpacerHeight; | 30 private final int mTopSpacerHeight; |
| 30 private final int mMiddleSpacerHeight; | 31 private final int mMiddleSpacerHeight; |
| 31 private final int mBottomSpacerHeight; | 32 private final int mBottomSpacerHeight; |
| 32 private final int mTotalSpacerHeight; | 33 private final int mTotalSpacerHeight; |
| 33 private final int mMostVisitedLayoutBleed; | 34 private final int mMostVisitedLayoutBleed; |
| 34 | 35 |
| 35 private int mParentScrollViewportHeight; | 36 private int mParentScrollViewportHeight; |
| 36 | 37 |
| 38 private boolean mUseCardsUiEnabled; | |
|
Bernhard Bauer
2016/05/05 18:04:40
Nit: I would call this either |mUseCardsUi| or |mC
mcwilliams
2016/05/05 18:21:11
Done.
| |
| 37 private View mTopSpacer; | 39 private View mTopSpacer; |
| 38 private View mMiddleSpacer; | 40 private View mMiddleSpacer; |
| 39 private View mBottomSpacer; | 41 private View mBottomSpacer; |
| 40 private View mScrollCompensationSpacer; | 42 private View mScrollCompensationSpacer; |
| 41 | 43 |
| 42 private LogoView mSearchProviderLogoView; | 44 private LogoView mSearchProviderLogoView; |
| 43 private View mSearchBoxView; | 45 private View mSearchBoxView; |
| 44 private MostVisitedLayout mMostVisitedLayout; | 46 private MostVisitedLayout mMostVisitedLayout; |
| 45 | 47 |
| 46 /** | 48 /** |
| (...skipping 28 matching lines...) Expand all Loading... | |
| 75 * <p> | 77 * <p> |
| 76 * As this is required in onMeasure, we can not rely on the parent having th e proper | 78 * As this is required in onMeasure, we can not rely on the parent having th e proper |
| 77 * size set yet and thus must be told explicitly of this size. | 79 * size set yet and thus must be told explicitly of this size. |
| 78 * | 80 * |
| 79 * @param height The height of the scroll viewport containing this view. | 81 * @param height The height of the scroll viewport containing this view. |
| 80 */ | 82 */ |
| 81 public void setParentScrollViewportHeight(int height) { | 83 public void setParentScrollViewportHeight(int height) { |
| 82 mParentScrollViewportHeight = height; | 84 mParentScrollViewportHeight = height; |
| 83 } | 85 } |
| 84 | 86 |
| 87 /** | |
| 88 * | |
|
Bernhard Bauer
2016/05/05 18:04:40
Javadoc please.
mcwilliams
2016/05/05 18:21:11
:)
| |
| 89 */ | |
| 90 public void setUseCardsUiEnabled(boolean useCardsUi) { | |
| 91 mUseCardsUiEnabled = useCardsUi; | |
| 92 } | |
| 93 | |
| 85 @Override | 94 @Override |
| 86 protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { | 95 protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { |
| 87 mScrollCompensationSpacer.getLayoutParams().height = 0; | 96 mScrollCompensationSpacer.getLayoutParams().height = 0; |
| 88 super.onMeasure(widthMeasureSpec, heightMeasureSpec); | 97 super.onMeasure(widthMeasureSpec, heightMeasureSpec); |
| 98 | |
| 99 // Check if we are showing snippets. If Most Likely is fully rendered on the initial page | |
| 100 // load and has enough space for the peeking card, push snippets to the bottom of the page | |
| 101 // to show the peeking card. | |
| 102 if (mUseCardsUiEnabled) { | |
| 103 int peekingCardHeight = getContext().getResources().getDimensionPixe lSize( | |
| 104 R.dimen.snippets_padding_and_peeking_card_height); | |
| 105 if (mParentScrollViewportHeight >= getMeasuredHeight() + peekingCard Height) { | |
| 106 RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) g etLayoutParams(); | |
| 107 params.height = mParentScrollViewportHeight - peekingCardHeight; | |
| 108 } | |
| 109 } | |
| 110 // TODO(https://crbug.com/609487): Push snippets below the fold when mos t likely | |
| 111 // is not fully rendered. | |
| 112 | |
| 89 distributeExtraSpace(mTopSpacer.getMeasuredHeight()); | 113 distributeExtraSpace(mTopSpacer.getMeasuredHeight()); |
| 90 | 114 |
| 91 int minScrollAmountRequired = 0; | 115 int minScrollAmountRequired = 0; |
| 92 for (int i = 0; i < getChildCount(); i++) { | 116 for (int i = 0; i < getChildCount(); i++) { |
| 93 View child = getChildAt(i); | 117 View child = getChildAt(i); |
| 94 | 118 |
| 95 MarginLayoutParams layoutParams = (MarginLayoutParams) child.getLayo utParams(); | 119 MarginLayoutParams layoutParams = (MarginLayoutParams) child.getLayo utParams(); |
| 96 if (child.getVisibility() != View.GONE) { | 120 if (child.getVisibility() != View.GONE) { |
| 97 minScrollAmountRequired += layoutParams.topMargin; | 121 minScrollAmountRequired += layoutParams.topMargin; |
| 98 } | 122 } |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 162 | 186 |
| 163 int widthSpec = MeasureSpec.makeMeasureSpec(0, MeasureSpec.EXACTLY); | 187 int widthSpec = MeasureSpec.makeMeasureSpec(0, MeasureSpec.EXACTLY); |
| 164 mTopSpacer.measure(widthSpec, | 188 mTopSpacer.measure(widthSpec, |
| 165 MeasureSpec.makeMeasureSpec(topSpacerHeight, MeasureSpec.EXACTLY )); | 189 MeasureSpec.makeMeasureSpec(topSpacerHeight, MeasureSpec.EXACTLY )); |
| 166 mMiddleSpacer.measure(widthSpec, | 190 mMiddleSpacer.measure(widthSpec, |
| 167 MeasureSpec.makeMeasureSpec(middleSpacerHeight, MeasureSpec.EXAC TLY)); | 191 MeasureSpec.makeMeasureSpec(middleSpacerHeight, MeasureSpec.EXAC TLY)); |
| 168 mBottomSpacer.measure(widthSpec, | 192 mBottomSpacer.measure(widthSpec, |
| 169 MeasureSpec.makeMeasureSpec(bottomSpacerHeight, MeasureSpec.EXAC TLY)); | 193 MeasureSpec.makeMeasureSpec(bottomSpacerHeight, MeasureSpec.EXAC TLY)); |
| 170 } | 194 } |
| 171 } | 195 } |
| OLD | NEW |