Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3843)

Unified Diff: chrome/android/java/src/org/chromium/chrome/browser/ntp/NewTabPageView.java

Issue 2134663002: Use only toolbar to transition from fakebox to real omnibox. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fixes Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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 4ddbb0c939ede6c75f0219bc6f211265f2ce33d5..3f4c05642f97f560cc6af5bf96d7b21699ade31d 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
@@ -11,6 +11,7 @@ import android.graphics.Bitmap;
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.net.Uri;
@@ -390,37 +391,41 @@ public class NewTabPageView extends FrameLayout
private void updateSearchBoxOnScroll() {
if (mDisableUrlFocusChangeAnimations) return;
- float toolbarTransitionPercentage;
+ if (mSearchBoxScrollListener != null) {
+ mSearchBoxScrollListener.onNtpScrollChanged(getToolbarTransitionPercentage());
+ }
+ }
+
mcwilliams 2016/07/12 16:20:47 Add java doc to function as to how it is getting t
Bernhard Bauer 2016/07/12 16:54:37 Done.
+ private float getToolbarTransitionPercentage() {
// 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);
- }
- }
+ if (getWrapperView().getHeight() == 0) return 0f;
mcwilliams 2016/07/12 16:20:47 Add a doc for this - When search box is a the top,
Bernhard Bauer 2016/07/12 16:54:37 I've expanded the comment above, as it refers to t
- updateVisualsForToolbarTransition(toolbarTransitionPercentage);
+ int searchBoxTop = mSearchBoxView.getTop();
+ if (searchBoxTop == 0) return 0f;
- if (mSearchBoxScrollListener != null) {
- mSearchBoxScrollListener.onNtpScrollChanged(toolbarTransitionPercentage);
+ // 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. Luckily, if the first item is not visible, we know the toolbar
mcwilliams 2016/07/12 16:20:47 Remove 'Luckily' from doc :)
Bernhard Bauer 2016/07/12 16:54:37 Done.
+ // transition should be 100%.
+ return 1f;
+ }
+
+ final int scrollY = getVerticalScroll();
mcwilliams 2016/07/12 16:20:47 Is this final?
Bernhard Bauer 2016/07/12 16:54:37 I don't understand the question... If you mean, do
+ 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);
}
private ViewGroup getWrapperView() {
@@ -665,55 +670,46 @@ public class NewTabPageView extends FrameLayout
int scrollOffset = mUseCardsUi ? 0 : mScrollView.getScrollY();
mNewTabPageLayout.setTranslationY(percent * (-mMostVisitedLayout.getTop() + scrollOffset
+ mNewTabPageLayout.getPaddingTop()));
- updateVisualsForToolbarTransition(percent);
}
/**
- * Updates the opacity of the fake omnibox and Google logo when scrolling.
- * @param transitionPercentage
+ * Updates the opacity of the search UI (fake omnibox and search provider logo) when scrolling.
+ *
+ * @param alpha opacity (alpha) value to use.
*/
- 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;
-
+ public void setSearchBoxAlpha(float alpha) {
if (!mUseCardsUi) {
- mSearchProviderLogoView.setAlpha(searchUiAlpha);
+ mSearchProviderLogoView.setAlpha(alpha);
}
- mSearchBoxView.setAlpha(searchUiAlpha);
+ mSearchBoxView.setAlpha(alpha);
}
/**
* Get the bounds of the search box in relation to the top level NewTabPage view.
*
- * @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.
+ * @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 originalBounds, Rect transformedBounds) {
+ void getSearchBoxBounds(Rect bounds, Point translation) {
int searchBoxX = (int) mSearchBoxView.getX();
int searchBoxY = (int) mSearchBoxView.getY();
- originalBounds.set(
- searchBoxX + mSearchBoxView.getPaddingLeft(),
+ bounds.set(searchBoxX + mSearchBoxView.getPaddingLeft(),
searchBoxY + mSearchBoxView.getPaddingTop(),
searchBoxX + mSearchBoxView.getWidth() - mSearchBoxView.getPaddingRight(),
searchBoxY + mSearchBoxView.getHeight() - mSearchBoxView.getPaddingBottom());
- transformedBounds.set(originalBounds);
+ translation.set(0, 0);
+
View view = (View) mSearchBoxView.getParent();
while (view != null) {
- transformedBounds.offset(-view.getScrollX(), -view.getScrollY());
+ translation.offset(-view.getScrollX(), -view.getScrollY());
if (view == this) break;
- transformedBounds.offset((int) view.getX(), (int) view.getY());
+ translation.offset((int) view.getX(), (int) view.getY());
view = (View) view.getParent();
}
+ bounds.offset(translation.x, translation.y);
}
/**

Powered by Google App Engine
This is Rietveld 408576698