| 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 951cb0fe45b905877b16cfcbfe07ce3ea5673e2d..917cfb384ca42c5c2234eb1d63e8eb81128bbbac 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
|
| @@ -12,7 +12,6 @@
|
| import android.graphics.BitmapFactory;
|
| import android.graphics.Canvas;
|
| import android.graphics.Color;
|
| -import android.graphics.Point;
|
| import android.graphics.Rect;
|
| import android.graphics.drawable.BitmapDrawable;
|
| import android.support.v4.graphics.drawable.RoundedBitmapDrawable;
|
| @@ -394,49 +393,37 @@
|
| private void updateSearchBoxOnScroll() {
|
| if (mDisableUrlFocusChangeAnimations) return;
|
|
|
| + float toolbarTransitionPercentage;
|
| + // During startup the view may not be fully initialized, so we only calculate the current
|
| + // percentage if some basic view properties are sane.
|
| + if (getWrapperView().getHeight() == 0 || mSearchBoxView.getTop() == 0) {
|
| + toolbarTransitionPercentage = 0f;
|
| + } else if (!mUseCardsUi) {
|
| + toolbarTransitionPercentage =
|
| + MathUtils.clamp(getVerticalScroll() / (float) mSearchBoxView.getTop(), 0f, 1f);
|
| + } else {
|
| + if (!mRecyclerView.isFirstItemVisible()) {
|
| + // getVerticalScroll is valid only for the RecyclerView if the first item is
|
| + // visible. Luckily, if the first item is not visible, we know the toolbar
|
| + // transition should be 100%.
|
| + toolbarTransitionPercentage = 1f;
|
| + } else {
|
| + 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.
|
| + toolbarTransitionPercentage = MathUtils.clamp(
|
| + (scrollY - top + transitionLength) / (float) transitionLength, 0f, 1f);
|
| + }
|
| + }
|
| +
|
| + updateVisualsForToolbarTransition(toolbarTransitionPercentage);
|
| +
|
| if (mSearchBoxScrollListener != null) {
|
| - mSearchBoxScrollListener.onNtpScrollChanged(getToolbarTransitionPercentage());
|
| - }
|
| - }
|
| -
|
| - /**
|
| - * Calculates the percentage (between 0 and 1) of the transition from the search box to the
|
| - * omnibox at the top of the New Tab Page, which is determined by the amount of scrolling and
|
| - * the position of the search box.
|
| - *
|
| - * @return the transition percentage
|
| - */
|
| - private float getToolbarTransitionPercentage() {
|
| - // During startup the view may not be fully initialized, so we only calculate the current
|
| - // percentage if some basic view properties (height of the containing view, position of the
|
| - // search box) are sane.
|
| - if (getWrapperView().getHeight() == 0) return 0f;
|
| -
|
| - int searchBoxTop = mSearchBoxView.getTop();
|
| - if (searchBoxTop == 0) return 0f;
|
| -
|
| - // For all other calculations, add the search box padding, because it defines where the
|
| - // visible "border" of the search box is.
|
| - searchBoxTop += mSearchBoxView.getPaddingTop();
|
| -
|
| - if (!mUseCardsUi) {
|
| - return MathUtils.clamp(getVerticalScroll() / (float) searchBoxTop, 0f, 1f);
|
| - }
|
| -
|
| - if (!mRecyclerView.isFirstItemVisible()) {
|
| - // getVerticalScroll is valid only for the RecyclerView if the first item is
|
| - // visible. If the first item is not visible, we know the toolbar transition
|
| - // should be 100%.
|
| - return 1f;
|
| - }
|
| -
|
| - final int scrollY = getVerticalScroll();
|
| - final float transitionLength =
|
| - getResources().getDimension(R.dimen.ntp_search_box_transition_length);
|
| -
|
| - // |scrollY - searchBoxTop| gives the distance the search bar is from the top of the screen.
|
| - return MathUtils.clamp(
|
| - (scrollY - searchBoxTop + transitionLength) / transitionLength, 0f, 1f);
|
| + mSearchBoxScrollListener.onNtpScrollChanged(toolbarTransitionPercentage);
|
| + }
|
| }
|
|
|
| private ViewGroup getWrapperView() {
|
| @@ -674,52 +661,55 @@
|
| int scrollOffset = mUseCardsUi ? 0 : mScrollView.getScrollY();
|
| mNewTabPageLayout.setTranslationY(percent * (-mMostVisitedLayout.getTop() + scrollOffset
|
| + mNewTabPageLayout.getPaddingTop()));
|
| - }
|
| -
|
| - /**
|
| - * Updates the opacity of the search box when scrolling.
|
| - *
|
| - * @param alpha opacity (alpha) value to use.
|
| - */
|
| - public void setSearchBoxAlpha(float alpha) {
|
| - mSearchBoxView.setAlpha(alpha);
|
| - }
|
| -
|
| - /**
|
| - * Updates the opacity of the search provider logo when scrolling.
|
| - *
|
| - * @param alpha opacity (alpha) value to use.
|
| - */
|
| - public void setSearchProviderLogoAlpha(float alpha) {
|
| - mSearchProviderLogoView.setAlpha(alpha);
|
| + updateVisualsForToolbarTransition(percent);
|
| + }
|
| +
|
| + /**
|
| + * Updates the opacity of the fake omnibox and Google logo when scrolling.
|
| + * @param transitionPercentage
|
| + */
|
| + private void updateVisualsForToolbarTransition(float transitionPercentage) {
|
| + // Complete the full alpha transition in the first 40% of the animation.
|
| + float searchUiAlpha =
|
| + transitionPercentage >= 0.4f ? 0f : (0.4f - transitionPercentage) * 2.5f;
|
| + // Ensure there are no rounding issues when the animation percent is 0.
|
| + if (transitionPercentage == 0f) searchUiAlpha = 1f;
|
| +
|
| + if (!mUseCardsUi) {
|
| + mSearchProviderLogoView.setAlpha(searchUiAlpha);
|
| + }
|
| + mSearchBoxView.setAlpha(searchUiAlpha);
|
| }
|
|
|
| /**
|
| * Get the bounds of the search box in relation to the top level NewTabPage view.
|
| *
|
| - * @param bounds The current drawing location of the search box.
|
| - * @param translation The translation applied to the search box by the parent view hierarchy up
|
| - * to the NewTabPage view.
|
| - */
|
| - void getSearchBoxBounds(Rect bounds, Point translation) {
|
| + * @param originalBounds The bounding region of the search box without external transforms
|
| + * applied. The delta between this and the transformed bounds determines
|
| + * the amount of scroll applied to this view.
|
| + * @param transformedBounds The bounding region of the search box including any transforms
|
| + * applied by the parent view hierarchy up to the NewTabPage view.
|
| + * This more accurately reflects the current drawing location of the
|
| + * search box.
|
| + */
|
| + void getSearchBoxBounds(Rect originalBounds, Rect transformedBounds) {
|
| int searchBoxX = (int) mSearchBoxView.getX();
|
| int searchBoxY = (int) mSearchBoxView.getY();
|
|
|
| - bounds.set(searchBoxX + mSearchBoxView.getPaddingLeft(),
|
| + originalBounds.set(
|
| + searchBoxX + mSearchBoxView.getPaddingLeft(),
|
| searchBoxY + mSearchBoxView.getPaddingTop(),
|
| searchBoxX + mSearchBoxView.getWidth() - mSearchBoxView.getPaddingRight(),
|
| searchBoxY + mSearchBoxView.getHeight() - mSearchBoxView.getPaddingBottom());
|
|
|
| - translation.set(0, 0);
|
| -
|
| + transformedBounds.set(originalBounds);
|
| View view = (View) mSearchBoxView.getParent();
|
| while (view != null) {
|
| - translation.offset(-view.getScrollX(), -view.getScrollY());
|
| + transformedBounds.offset(-view.getScrollX(), -view.getScrollY());
|
| if (view == this) break;
|
| - translation.offset((int) view.getX(), (int) view.getY());
|
| + transformedBounds.offset((int) view.getX(), (int) view.getY());
|
| view = (View) view.getParent();
|
| }
|
| - bounds.offset(translation.x, translation.y);
|
| }
|
|
|
| /**
|
|
|