Index: chrome/android/java/src/org/chromium/chrome/browser/ntp/NewTabPageView.java |
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 f6c875ccb5e14d0c7ea69f303fc5e8cb35a3f3c8..a958694418ddee9efc3fe48a0fb6900133fa03b6 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 |
@@ -45,7 +45,6 @@ import org.chromium.chrome.browser.ntp.LogoBridge.LogoObserver; |
import org.chromium.chrome.browser.ntp.MostVisitedItem.MostVisitedItemManager; |
import org.chromium.chrome.browser.ntp.NewTabPage.OnSearchBoxScrollListener; |
import org.chromium.chrome.browser.ntp.cards.CardItemDecoration; |
-import org.chromium.chrome.browser.ntp.cards.CardsLayoutOperations; |
import org.chromium.chrome.browser.ntp.cards.NewTabPageAdapter; |
import org.chromium.chrome.browser.ntp.cards.NewTabPageListItem; |
import org.chromium.chrome.browser.ntp.cards.NewTabPageRecyclerView; |
@@ -417,8 +416,14 @@ public class NewTabPageView extends FrameLayout |
// be 100%. |
percentage = 1f; |
} else { |
- percentage = MathUtils.clamp(getVerticalScroll() / (float) mSearchBoxView.getTop(), |
- 0f, 1f); |
+ final int scrollY = getVerticalScroll(); |
+ final int top = mSearchBoxView.getTop(); // Relative to mNewTabPageLayout. |
+ final int transitionLength = getResources() |
+ .getDimensionPixelSize(R.dimen.ntp_search_box_transition_length); |
+ |
+ // |scrollY - top| gives the distance the search bar is from the top of the screen. |
+ percentage = MathUtils.clamp( |
+ (scrollY - top + transitionLength) / (float) transitionLength, 0f, 1f); |
} |
updateVisualsForToolbarTransition(percentage); |
@@ -448,23 +453,51 @@ public class NewTabPageView extends FrameLayout |
return viewCount; |
} |
+ private void snapScroll() { |
+ // Snap scroll to prevent resting in the middle of the omnibox transition. |
+ final int searchBoxTransitionLength = getResources() |
+ .getDimensionPixelSize(R.dimen.ntp_search_box_transition_length); |
+ if (mRecyclerView.scrollOutOfRegion(mSearchBoxView.getTop() - searchBoxTransitionLength, |
+ mSearchBoxView.getTop())) { |
+ // The snap scrolling regions should never overlap. |
+ return; |
+ } |
+ |
+ // Snap scroll to prevent resting in the middle of the peeking card transition |
+ // and to allow the peeking card to peek a bit before snapping back. |
+ if (mRecyclerView.isPeekingCardVisible() && mRecyclerView.isFirstItemVisible()) { |
+ final int peekingHeight = getResources().getDimensionPixelSize( |
+ R.dimen.snippets_padding_and_peeking_card_height); |
+ |
+ // |A + B| gives the offset of the peeking card relative to the Recycler View, |
+ // so scrolling to this point would put the peeking card at the top of the |
+ // screen. |
+ // |A + B - C| will scroll us so that the peeking card is just off the bottom |
+ // of the screen. |
+ // Finally, we get |A + B - C + D| because the transition starts from the |
+ // peeking card's resting point, which is |D| from the bottom of the screen. |
+ int start = mRecyclerView.getPeekingCardTop() // A. |
+ + getVerticalScroll() // B. |
+ - getHeight() // C. |
+ + peekingHeight; // D. |
+ mRecyclerView.scrollOutOfRegion(start, |
+ start + mRecyclerView.getPeekingCardHeight() / 2, |
+ start + mRecyclerView.getPeekingCardHeight() / 2); |
+ } |
+ } |
+ |
/** |
* Sets up scrolling when snippets are enabled. It adds scroll listeners and touch listeners to |
* the RecyclerView. |
*/ |
private void initializeSearchBoxRecyclerViewScrollHandling() { |
- final NewTabPageUma.SnapStateObserver snapStateObserver = |
- new NewTabPageUma.SnapStateObserver(); |
- |
final Runnable mSnapScrollRunnable = new Runnable() { |
@Override |
public void run() { |
assert mPendingSnapScroll; |
mPendingSnapScroll = false; |
- NewTabPageUma.SnapState currentSnapState = CardsLayoutOperations.snapScroll( |
- mRecyclerView, mNewTabPageLayout, mMostVisitedLayout, getVerticalScroll(), |
- false); |
- snapStateObserver.updateSnapState(NewTabPageView.this, currentSnapState); |
+ |
+ snapScroll(); |
} |
}; |
@@ -689,7 +722,6 @@ public class NewTabPageView extends FrameLayout |
// Ensure there are no rounding issues when the animation percent is 0. |
if (transitionPercentage == 0f) searchUiAlpha = 1f; |
- mSearchProviderLogoView.setAlpha(searchUiAlpha); |
Bernhard Bauer
2016/06/28 14:44:00
Can we also guard this with the cardsUI check?
PEConn
2016/06/28 15:39:04
Done.
|
mSearchBoxView.setAlpha(searchUiAlpha); |
} |
@@ -812,10 +844,8 @@ public class NewTabPageView extends FrameLayout |
if (mUseCardsUi) { |
mRecyclerView.updatePeekingCard(); |
// The positioning of elements may have been changed (since the elements expand to fill |
- // the available vertical space), so adjust the scroll. We force snapping to Most Likely |
- // so the user's snap point doesn't change on rotation. |
- CardsLayoutOperations.snapScroll(mRecyclerView, mNewTabPageLayout, mMostVisitedLayout, |
- getVerticalScroll(), true); |
+ // the available vertical space), so adjust the scroll. |
+ snapScroll(); |
} |
} |