Commit e5725605 authored by spdonghao's avatar spdonghao Committed by Commit Bot

Adjust the fade-in animation for StartSurfaceToolbarView.

Showing start surface toolbar is busy with its fade-in animation.
Please see demos:
https://drive.google.com/file/d/12wbd0iA0IGlZGjqMWIaVTUvhCBfX19yF/view?usp=sharing

The animations are kept only when calling setToolbarVisibility().
Otherwise, when setStartSurfaceMode() is called, which means
showing or hiding toolbar from start up or other pages, the
animations are removed.

Bug: 1131608
Change-Id: I6f6e368580ba7e367abb425689e127b46897166b
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2451269Reviewed-by: default avatarWei-Yin Chen (陳威尹) <wychen@chromium.org>
Reviewed-by: default avatarGanggui Tang <gogerald@chromium.org>
Reviewed-by: default avatarXi Han <hanxi@chromium.org>
Commit-Queue: Hao Dong <spdonghao@chromium.org>
Cr-Commit-Position: refs/heads/master@{#817785}
parent 0c9ee9f9
...@@ -22,7 +22,6 @@ import androidx.appcompat.content.res.AppCompatResources; ...@@ -22,7 +22,6 @@ import androidx.appcompat.content.res.AppCompatResources;
import org.chromium.chrome.R; import org.chromium.chrome.R;
import org.chromium.chrome.browser.device.DeviceClassManager; import org.chromium.chrome.browser.device.DeviceClassManager;
import org.chromium.chrome.browser.tabmodel.IncognitoStateProvider; import org.chromium.chrome.browser.tabmodel.IncognitoStateProvider;
import org.chromium.chrome.browser.tasks.tab_management.TabUiFeatureUtilities;
import org.chromium.chrome.browser.toolbar.NewTabButton; import org.chromium.chrome.browser.toolbar.NewTabButton;
import org.chromium.components.browser_ui.styles.ChromeColors; import org.chromium.components.browser_ui.styles.ChromeColors;
import org.chromium.components.browser_ui.widget.animation.Interpolators; import org.chromium.components.browser_ui.widget.animation.Interpolators;
...@@ -222,7 +221,9 @@ class StartSurfaceToolbarView extends RelativeLayout { ...@@ -222,7 +221,9 @@ class StartSurfaceToolbarView extends RelativeLayout {
* */ * */
void setStartSurfaceMode(boolean inStartSurfaceMode) { void setStartSurfaceMode(boolean inStartSurfaceMode) {
mInStartSurfaceMode = inStartSurfaceMode; mInStartSurfaceMode = inStartSurfaceMode;
showStartSurfaceToolbar(mInStartSurfaceMode && mShouldShow, true); // When showing or hiding toolbar from a tab, the fade-in and fade-out animations are not
// needed. (eg: cold start, changing theme, changing incognito status...)
showStartSurfaceToolbar(mInStartSurfaceMode && mShouldShow, false);
} }
/** /**
...@@ -231,15 +232,17 @@ class StartSurfaceToolbarView extends RelativeLayout { ...@@ -231,15 +232,17 @@ class StartSurfaceToolbarView extends RelativeLayout {
* */ * */
void setToolbarVisibility(boolean shouldShowStartSurfaceToolbar) { void setToolbarVisibility(boolean shouldShowStartSurfaceToolbar) {
mShouldShow = shouldShowStartSurfaceToolbar; mShouldShow = shouldShowStartSurfaceToolbar;
showStartSurfaceToolbar(mInStartSurfaceMode && mShouldShow, false); // When simply setting visibility, the animations should be shown. (eg: search box has
// focus)
showStartSurfaceToolbar(mInStartSurfaceMode && mShouldShow, true);
} }
/** /**
* Start animation to show or hide toolbar. * Start animation to show or hide toolbar.
* @param showStartSurfaceToolbar Whether or not toolbar should be shown or hidden. * @param showStartSurfaceToolbar Whether or not toolbar should be shown or hidden.
* @param animateToTab Whether or not animation is from or to tab. * @param showAnimation Whether or not to show the animation.
*/ */
private void showStartSurfaceToolbar(boolean showStartSurfaceToolbar, boolean animateToTab) { private void showStartSurfaceToolbar(boolean showStartSurfaceToolbar, boolean showAnimation) {
if (showStartSurfaceToolbar == mIsShowing) return; if (showStartSurfaceToolbar == mIsShowing) return;
if (mVisibilityAnimator != null) { if (mVisibilityAnimator != null) {
...@@ -254,21 +257,24 @@ class StartSurfaceToolbarView extends RelativeLayout { ...@@ -254,21 +257,24 @@ class StartSurfaceToolbarView extends RelativeLayout {
return; return;
} }
setAlpha(showStartSurfaceToolbar ? 0.0f : 1.0f); // TODO(https://crbug.com/1139024): Show the fade-in animation when
// TabUiFeatureUtilities#isTabToGtsAnimationEnabled is true.
if (!showAnimation) {
setVisibility(showStartSurfaceToolbar ? View.VISIBLE : View.GONE);
return;
}
// Show the fade-in and fade-out animation. Set visibility as VISIBLE here to show the
// animation. The visibility will be finally set in finishAnimation().
setVisibility(View.VISIBLE); setVisibility(View.VISIBLE);
setAlpha(showStartSurfaceToolbar ? 0.0f : 1.0f);
boolean showZoomingAnimation = final long duration = TopToolbarCoordinator.TAB_SWITCHER_MODE_NORMAL_ANIMATION_DURATION_MS;
animateToTab && TabUiFeatureUtilities.isTabToGtsAnimationEnabled();
final long duration = showZoomingAnimation
? TopToolbarCoordinator.TAB_SWITCHER_MODE_GTS_ANIMATION_DURATION_MS
: TopToolbarCoordinator.TAB_SWITCHER_MODE_NORMAL_ANIMATION_DURATION_MS;
mVisibilityAnimator = mVisibilityAnimator =
animate() animate()
.alpha(showStartSurfaceToolbar ? 1.0f : 0.0f) .alpha(showStartSurfaceToolbar ? 1.0f : 0.0f)
.setDuration(duration) .setDuration(duration)
.setStartDelay(
showZoomingAnimation && showStartSurfaceToolbar ? duration : 0)
.setInterpolator(Interpolators.LINEAR_INTERPOLATOR) .setInterpolator(Interpolators.LINEAR_INTERPOLATOR)
.withEndAction(() -> { finishAnimation(showStartSurfaceToolbar); }); .withEndAction(() -> { finishAnimation(showStartSurfaceToolbar); });
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment