use of org.chromium.chrome.browser.ntp.NewTabPageUma.NTPLayoutResult in project AndroidChromium by JackyAndroid.
the class NewTabPageLayout method measureWithCardsUiEnabled.
/**
* Performs layout measurements for when the cards ui is enabled.
*/
private void measureWithCardsUiEnabled(int widthMeasureSpec, int heightMeasureSpec) {
assert mCardsUiEnabled;
mLogoSpacer.setVisibility(View.GONE);
mSearchBoxSpacer.setVisibility(View.GONE);
// Remove the extra spacing before measuring because it might not be needed anymore.
mMostVisitedLayout.setExtraVerticalSpacing(0);
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
boolean hasSpaceForPeekingCard = false;
int spaceToFill = mParentViewportHeight - mPeekingCardHeight - mTabStripHeight;
@NTPLayoutResult int layoutResult;
// We need to make sure we have just enough space to show the peeking card.
if (getMeasuredHeight() > spaceToFill) {
layoutResult = NewTabPageUma.NTP_LAYOUT_DOES_NOT_FIT;
// and let MostVisited get cut to make it clear that the page is scrollable.
if (mMostVisitedLayout.getChildCount() > 0) {
// Add some extra space if needed (the 'bleed' is the amount of the layout that
// will be cut off by the bottom of the screen).
int currentBleed = getMeasuredHeight() - mParentViewportHeight - mTabStripHeight;
int minimumBleed = (int) (mMostVisitedLayout.getChildAt(0).getMeasuredHeight() * 0.44);
if (currentBleed < minimumBleed) {
int extraBleed = minimumBleed - currentBleed;
mLogoSpacer.getLayoutParams().height = (int) (extraBleed * 0.25);
mLogoSpacer.setVisibility(View.INVISIBLE);
mSearchBoxSpacer.getLayoutParams().height = (int) (extraBleed * 0.25);
mSearchBoxSpacer.setVisibility(View.INVISIBLE);
mMostVisitedLayout.setExtraVerticalSpacing((int) (extraBleed * 0.5));
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
layoutResult = NewTabPageUma.NTP_LAYOUT_DOES_NOT_FIT_PUSH_MOST_LIKELY;
}
}
} else {
hasSpaceForPeekingCard = true;
// If there is enough space, reduce the space we are going to fill.
if (mFieldTrialLayoutAdjustment != 0f) {
if (getMeasuredHeight() < spaceToFill - mFieldTrialLayoutAdjustment) {
spaceToFill -= mFieldTrialLayoutAdjustment;
layoutResult = NewTabPageUma.NTP_LAYOUT_FITS_WITH_FIELD_TRIAL;
} else {
layoutResult = NewTabPageUma.NTP_LAYOUT_FITS_WITHOUT_FIELD_TRIAL;
}
} else {
layoutResult = NewTabPageUma.NTP_LAYOUT_FITS_NO_FIELD_TRIAL;
}
// Call super.onMeasure with mode EXACTLY and the target height to allow the top
// spacer (which has a weight of 1) to grow and take up the remaining space.
heightMeasureSpec = MeasureSpec.makeMeasureSpec(spaceToFill, MeasureSpec.EXACTLY);
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
distributeExtraSpace(mTopSpacer.getMeasuredHeight());
}
assert getParent() instanceof NewTabPageRecyclerView;
NewTabPageRecyclerView recyclerView = (NewTabPageRecyclerView) getParent();
recyclerView.setHasSpaceForPeekingCard(hasSpaceForPeekingCard);
// contents. We want to record what the user sees when the layout has stabilized.
if (mMostVisitedLayout.getChildCount() > 0 && !mLayoutResultRecorded) {
mLayoutResultRecorded = true;
NewTabPageUma.recordNTPLayoutResult(layoutResult);
}
}
Aggregations