From 6c8bec167b1a51f5c4731f69dd770166670ac4af Mon Sep 17 00:00:00 2001 From: peconn Date: Fri, 3 Mar 2017 08:41:56 -0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=8F=A1=20Updated=20animation=20for=20Goog?= =?UTF-8?q?le=20G=20in=20search=20box.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Previously as the location approached the top of the screen: * The G fades to 0% opacity. * The G shrinks to 30% of its size. * These transitions occur simultaneously. Now the G will have faded to 0% by the time it has shrunk to 45% scale. BUG=697809 Review-Url: https://codereview.chromium.org/2729853002 Cr-Commit-Position: refs/heads/master@{#454596} --- .../browser/omnibox/LocationBarPhone.java | 27 ++++++++++++------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/chrome/android/java/src/org/chromium/chrome/browser/omnibox/LocationBarPhone.java b/chrome/android/java/src/org/chromium/chrome/browser/omnibox/LocationBarPhone.java index dd3d39efa6e6..66ec8c00f5a4 100644 --- a/chrome/android/java/src/org/chromium/chrome/browser/omnibox/LocationBarPhone.java +++ b/chrome/android/java/src/org/chromium/chrome/browser/omnibox/LocationBarPhone.java @@ -292,22 +292,29 @@ private void updateGoogleG() { mGoogleGContainer.setVisibility(View.VISIBLE); float animationProgress = GOOGLE_G_FADE_INTERPOLATOR.getInterpolation(mUrlFocusChangePercent); - mGoogleG.setAlpha(1 - animationProgress); + + final float finalGScale = 0.3f; + // How much we have reduced the size of the G, 0 at the beginning, 0.7 at the end. + final float shrinkingProgress = animationProgress * (1 - finalGScale); FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams) mGoogleG.getLayoutParams(); + layoutParams.width = Math.round(mGoogleGWidth * (1f - shrinkingProgress)); - // Shrink the width down to 30%. - layoutParams.width = Math.round( - MathUtils.interpolate(mGoogleGWidth, mGoogleGWidth * 0.3f, animationProgress)); - - // Shrink the margin down to 50% minus half of the G width (in the end state), i.e. 15%. - ApiCompatibilityUtils.setMarginEnd(layoutParams, - Math.round(MathUtils.interpolate(mGoogleGMargin, - mGoogleGMargin * 0.5f - mGoogleGWidth * 0.15f, animationProgress))); - + // Shrink the margin down to 50% minus half of the G width (in the end state). + final float finalGoogleGMargin = (mGoogleGMargin - mGoogleGWidth * finalGScale) / 2f; + ApiCompatibilityUtils.setMarginEnd(layoutParams, Math.round(MathUtils.interpolate( + mGoogleGMargin, finalGoogleGMargin, animationProgress))); // Just calling requestLayout() would not resolve the end margin. mGoogleG.setLayoutParams(layoutParams); + + // We want the G to be fully transparent when it is 45% of its size. + final float scaleWhenTransparent = 0.45f; + assert scaleWhenTransparent >= finalGScale; + + // How much we have faded out the G, 0 at the beginning, 1 when we've reduced size to 0.45. + final float fadingProgress = Math.min(1, shrinkingProgress / (1 - scaleWhenTransparent)); + mGoogleG.setAlpha(1 - fadingProgress); } @Override