Commit a70166fd authored by Mia Glaese's avatar Mia Glaese Committed by Commit Bot

[Start Surface] Add toolbar animations

Screen capture:
https://drive.google.com/drive/folders/1VSZGz0yMwmYBV0uG0Zv5jgtLzKQt8DVM?usp=sharing

Bug: 1025296
Change-Id: I6d3671252578fa9f37e5f1173b8d55b364a898c1
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1981853
Commit-Queue: Mia Glaese <glamia@chromium.org>
Reviewed-by: default avatarYusuf Ozuysal <yusufo@chromium.org>
Reviewed-by: default avatarPatrick Noland <pnoland@chromium.org>
Reviewed-by: default avatarGanggui Tang <gogerald@chromium.org>
Cr-Commit-Position: refs/heads/master@{#741772}
parent 1f1e4e18
......@@ -10,7 +10,8 @@
android:id="@+id/tab_switcher_toolbar"
android:layout_width="match_parent"
android:layout_height="@dimen/toolbar_height_no_shadow"
android:clickable="true" >
android:clickable="true"
android:visibility="gone">
<Switch
android:id="@+id/incognito_switch"
......
......@@ -165,9 +165,6 @@ public class ToolbarManager implements ScrimObserver, ToolbarTabController, UrlF
*/
private static final float MINIMUM_LOAD_PROGRESS = 0.05f;
public static final int TAB_SWITCHER_MODE_NORMAL_ANIMATION_DURATION_MS = 200;
public static final int TAB_SWITCHER_MODE_GTS_ANIMATION_DURATION_MS = 150;
private final IncognitoStateProvider mIncognitoStateProvider;
private final TabCountProvider mTabCountProvider;
private final ThemeColorProvider mTabThemeColorProvider;
......
......@@ -16,7 +16,7 @@ import android.view.ViewGroup.MarginLayoutParams;
import org.chromium.chrome.R;
import org.chromium.chrome.browser.compositor.layouts.EmptyOverviewModeObserver;
import org.chromium.chrome.browser.toolbar.ToolbarManager;
import org.chromium.chrome.browser.toolbar.top.TopToolbarCoordinator;
import java.util.LinkedList;
import java.util.List;
......@@ -30,7 +30,7 @@ import java.util.List;
*/
public class BottomToolbarAnimationCoordinator extends EmptyOverviewModeObserver {
private static final long DURATION =
ToolbarManager.TAB_SWITCHER_MODE_NORMAL_ANIMATION_DURATION_MS;
TopToolbarCoordinator.TAB_SWITCHER_MODE_NORMAL_ANIMATION_DURATION_MS;
/** The browsing mode bottom toolbar component */
private final BrowsingModeBottomToolbarCoordinator mBrowsingModeCoordinator;
......
......@@ -28,13 +28,19 @@ class StartSurfaceToolbarCoordinator {
private final StartSurfaceToolbarMediator mToolbarMediator;
private final ViewStub mStub;
private final PropertyModel mPropertyModel;
private PropertyModelChangeProcessor mPropertyModelChangeProcessor;
private StartSurfaceToolbarView mView;
private TabModelSelector mTabModelSelector;
private IncognitoSwitchCoordinator mIncognitoSwitchCoordinator;
StartSurfaceToolbarCoordinator(ViewStub startSurfaceToolbarStub) {
mStub = startSurfaceToolbarStub;
mPropertyModel = new PropertyModel(StartSurfaceToolbarProperties.ALL_KEYS);
mPropertyModel = new PropertyModel.Builder(StartSurfaceToolbarProperties.ALL_KEYS)
.with(StartSurfaceToolbarProperties.IN_START_SURFACE_MODE, false)
.with(StartSurfaceToolbarProperties.MENU_IS_VISIBLE, false)
.with(StartSurfaceToolbarProperties.IS_VISIBLE, true)
.build();
mToolbarMediator = new StartSurfaceToolbarMediator(mPropertyModel);
}
......@@ -68,6 +74,7 @@ class StartSurfaceToolbarCoordinator {
mTabModelSelector = selector;
mToolbarMediator.setTabModelSelector(selector);
}
/**
* Called when Start Surface mode is entered or exited.
* @param inStartSurfaceMode Whether or not start surface mode should be shown or hidden.
......@@ -161,7 +168,7 @@ class StartSurfaceToolbarCoordinator {
private void inflate() {
mStub.setLayoutResource(R.layout.start_top_toolbar);
mView = (StartSurfaceToolbarView) mStub.inflate();
PropertyModelChangeProcessor.create(
mPropertyModelChangeProcessor = PropertyModelChangeProcessor.create(
mPropertyModel, mView, StartSurfaceToolbarViewBinder::bind);
if (IncognitoUtils.isIncognitoModeEnabled()) {
......
......@@ -14,10 +14,10 @@ import static org.chromium.chrome.browser.toolbar.top.StartSurfaceToolbarPropert
import static org.chromium.chrome.browser.toolbar.top.StartSurfaceToolbarProperties.IDENTITY_DISC_IS_VISIBLE;
import static org.chromium.chrome.browser.toolbar.top.StartSurfaceToolbarProperties.INCOGNITO_STATE_PROVIDER;
import static org.chromium.chrome.browser.toolbar.top.StartSurfaceToolbarProperties.INCOGNITO_SWITCHER_VISIBLE;
import static org.chromium.chrome.browser.toolbar.top.StartSurfaceToolbarProperties.IN_START_SURFACE_MODE;
import static org.chromium.chrome.browser.toolbar.top.StartSurfaceToolbarProperties.IS_INCOGNITO;
import static org.chromium.chrome.browser.toolbar.top.StartSurfaceToolbarProperties.IS_VISIBLE;
import static org.chromium.chrome.browser.toolbar.top.StartSurfaceToolbarProperties.LOGO_IS_VISIBLE;
import static org.chromium.chrome.browser.toolbar.top.StartSurfaceToolbarProperties.MENU_IS_VISIBLE;
import static org.chromium.chrome.browser.toolbar.top.StartSurfaceToolbarProperties.NEW_TAB_BUTTON_AT_LEFT;
import static org.chromium.chrome.browser.toolbar.top.StartSurfaceToolbarProperties.NEW_TAB_BUTTON_IS_VISIBLE;
import static org.chromium.chrome.browser.toolbar.top.StartSurfaceToolbarProperties.NEW_TAB_CLICK_HANDLER;
......@@ -58,7 +58,6 @@ class StartSurfaceToolbarMediator {
StartSurfaceToolbarMediator(PropertyModel model) {
mPropertyModel = model;
mPropertyModel.set(MENU_IS_VISIBLE, true);
mOverviewModeState = OverviewModeState.NOT_SHOWN;
}
......@@ -129,17 +128,20 @@ class StartSurfaceToolbarMediator {
}
void setStartSurfaceMode(boolean inStartSurfaceMode) {
mPropertyModel.set(IS_VISIBLE, inStartSurfaceMode);
}
void setIncognitoStateProvider(IncognitoStateProvider provider) {
mPropertyModel.set(INCOGNITO_STATE_PROVIDER, provider);
mPropertyModel.set(IN_START_SURFACE_MODE, inStartSurfaceMode);
}
void setStartSurfaceToolbarVisibility(boolean shouldShowStartSurfaceToolbar) {
if (!mPropertyModel.get(IN_START_SURFACE_MODE)) {
return;
}
mPropertyModel.set(IS_VISIBLE, shouldShowStartSurfaceToolbar);
}
void setIncognitoStateProvider(IncognitoStateProvider provider) {
mPropertyModel.set(INCOGNITO_STATE_PROVIDER, provider);
}
void onAccessibilityStatusChanged(boolean enabled) {
mPropertyModel.set(ACCESSIBILITY_ENABLED, enabled);
updateNewTabButtonVisibility();
......
......@@ -55,6 +55,8 @@ class StartSurfaceToolbarProperties {
new PropertyModel.WritableBooleanPropertyKey();
public static final PropertyModel.WritableBooleanPropertyKey IS_VISIBLE =
new PropertyModel.WritableBooleanPropertyKey();
public static final PropertyModel.WritableBooleanPropertyKey IN_START_SURFACE_MODE =
new PropertyModel.WritableBooleanPropertyKey();
public static final PropertyModel.WritableBooleanPropertyKey LOGO_IS_VISIBLE =
new PropertyModel.WritableBooleanPropertyKey();
public static final PropertyModel.WritableBooleanPropertyKey IS_INCOGNITO =
......@@ -81,10 +83,11 @@ class StartSurfaceToolbarProperties {
public static final PropertyModel.WritableBooleanPropertyKey NEW_TAB_BUTTON_AT_LEFT =
new PropertyModel.WritableBooleanPropertyKey();
public static final PropertyKey[] ALL_KEYS = new PropertyKey[] {APP_MENU_BUTTON_HELPER,
NEW_TAB_CLICK_HANDLER, IS_VISIBLE, LOGO_IS_VISIBLE, IS_INCOGNITO,
INCOGNITO_STATE_PROVIDER, ACCESSIBILITY_ENABLED, MENU_IS_VISIBLE,
NEW_TAB_BUTTON_IS_VISIBLE, BUTTONS_CLICKABLE, INCOGNITO_SWITCHER_VISIBLE,
NEW_TAB_BUTTON_AT_LEFT, IDENTITY_DISC_IS_VISIBLE, IDENTITY_DISC_CLICK_HANDLER,
IDENTITY_DISC_IMAGE, IDENTITY_DISC_DESCRIPTION, IDENTITY_DISC_IPH};
public static final PropertyKey[] ALL_KEYS =
new PropertyKey[] {APP_MENU_BUTTON_HELPER, NEW_TAB_CLICK_HANDLER, IS_VISIBLE,
LOGO_IS_VISIBLE, IS_INCOGNITO, INCOGNITO_STATE_PROVIDER, ACCESSIBILITY_ENABLED,
MENU_IS_VISIBLE, NEW_TAB_BUTTON_IS_VISIBLE, BUTTONS_CLICKABLE,
INCOGNITO_SWITCHER_VISIBLE, NEW_TAB_BUTTON_AT_LEFT, IDENTITY_DISC_IS_VISIBLE,
IDENTITY_DISC_CLICK_HANDLER, IDENTITY_DISC_IMAGE, IDENTITY_DISC_DESCRIPTION,
IDENTITY_DISC_IPH, IN_START_SURFACE_MODE};
}
......@@ -11,6 +11,7 @@ import android.graphics.drawable.Drawable;
import android.support.v7.content.res.AppCompatResources;
import android.util.AttributeSet;
import android.view.View;
import android.view.ViewPropertyAnimator;
import android.widget.ImageButton;
import android.widget.RelativeLayout;
......@@ -19,6 +20,8 @@ import androidx.annotation.StringRes;
import org.chromium.base.ApiCompatibilityUtils;
import org.chromium.chrome.R;
import org.chromium.chrome.browser.device.DeviceClassManager;
import org.chromium.chrome.browser.tab.TabFeatureUtilities;
import org.chromium.chrome.browser.toolbar.IncognitoStateProvider;
import org.chromium.chrome.browser.toolbar.MenuButton;
import org.chromium.chrome.browser.toolbar.NewTabButton;
......@@ -26,6 +29,7 @@ import org.chromium.chrome.browser.toolbar.top.StartSurfaceToolbarProperties.IPH
import org.chromium.chrome.browser.ui.appmenu.AppMenuButtonHelper;
import org.chromium.chrome.browser.util.AccessibilityUtil;
import org.chromium.components.browser_ui.styles.ChromeColors;
import org.chromium.components.browser_ui.widget.animation.Interpolators;
import org.chromium.components.browser_ui.widget.textbubble.TextBubble;
import org.chromium.ui.util.ColorUtils;
......@@ -40,6 +44,7 @@ class StartSurfaceToolbarView extends RelativeLayout {
private int mPrimaryColor;
private ColorStateList mLightIconTint;
private ColorStateList mDarkIconTint;
private ViewPropertyAnimator mVisibilityAnimator;
private Rect mLogoRect = new Rect();
private Rect mViewRect = new Rect();
......@@ -51,7 +56,6 @@ class StartSurfaceToolbarView extends RelativeLayout {
@Override
protected void onFinishInflate() {
super.onFinishInflate();
mNewTabButton = findViewById(R.id.new_tab_button);
mIncognitoSwitch = findViewById(R.id.incognito_switch);
mMenuButton = findViewById(R.id.menu_button_wrapper);
......@@ -224,6 +228,69 @@ class StartSurfaceToolbarView extends RelativeLayout {
textBubble.show();
}
/**
* Start animation to show or hide toolbar from tab.
* @param showToolbar Whether or not toolbar should be shown or hidden.
* */
void setStartSurfaceMode(boolean showToolbar) {
startAnimation(showToolbar, true);
}
/**
* Start animation to show or hide toolbar.
* @param showToolbar Whether or not toolbar should be shown or hidden.
* */
void setToolbarVisibility(boolean showToolbar) {
startAnimation(showToolbar, false);
}
/**
* Start animation to show or hide toolbar.
* @param showToolbar Whether or not toolbar should be shown or hidden.
* @param tabAnimation Whether or not animation is from or to tab.
*/
private void startAnimation(boolean showToolbar, boolean tabAnimation) {
if (mVisibilityAnimator != null) {
mVisibilityAnimator.cancel();
mVisibilityAnimator = null;
}
if ((showToolbar && (getVisibility() == View.VISIBLE))
|| (!showToolbar && (getVisibility() == View.GONE))) {
return;
}
if (DeviceClassManager.enableAccessibilityLayout()) {
finishAnimation(showToolbar);
return;
}
setAlpha(showToolbar ? 0.0f : 1.0f);
setVisibility(View.VISIBLE);
boolean showZoomingAnimation =
tabAnimation && TabFeatureUtilities.isTabToGtsAnimationEnabled();
final long duration = showZoomingAnimation
? TopToolbarCoordinator.TAB_SWITCHER_MODE_GTS_ANIMATION_DURATION_MS
: TopToolbarCoordinator.TAB_SWITCHER_MODE_NORMAL_ANIMATION_DURATION_MS;
mVisibilityAnimator =
animate()
.alpha(showToolbar ? 1.0f : 0.0f)
.setDuration(duration)
.setStartDelay(showZoomingAnimation && showToolbar ? duration : 0)
.setInterpolator(Interpolators.LINEAR_INTERPOLATOR)
.withEndAction(() -> {
finishAnimation(showToolbar);
mVisibilityAnimator = null;
});
}
private void finishAnimation(boolean showToolbar) {
setAlpha(1.0f);
setVisibility(showToolbar ? View.VISIBLE : View.GONE);
}
private void updatePrimaryColorAndTint(boolean isIncognito) {
int primaryColor = ChromeColors.getPrimaryBackgroundColor(getResources(), isIncognito);
setBackgroundColor(primaryColor);
......
......@@ -14,6 +14,7 @@ import static org.chromium.chrome.browser.toolbar.top.StartSurfaceToolbarPropert
import static org.chromium.chrome.browser.toolbar.top.StartSurfaceToolbarProperties.IDENTITY_DISC_IS_VISIBLE;
import static org.chromium.chrome.browser.toolbar.top.StartSurfaceToolbarProperties.INCOGNITO_STATE_PROVIDER;
import static org.chromium.chrome.browser.toolbar.top.StartSurfaceToolbarProperties.INCOGNITO_SWITCHER_VISIBLE;
import static org.chromium.chrome.browser.toolbar.top.StartSurfaceToolbarProperties.IN_START_SURFACE_MODE;
import static org.chromium.chrome.browser.toolbar.top.StartSurfaceToolbarProperties.IS_INCOGNITO;
import static org.chromium.chrome.browser.toolbar.top.StartSurfaceToolbarProperties.IS_VISIBLE;
import static org.chromium.chrome.browser.toolbar.top.StartSurfaceToolbarProperties.LOGO_IS_VISIBLE;
......@@ -22,8 +23,6 @@ import static org.chromium.chrome.browser.toolbar.top.StartSurfaceToolbarPropert
import static org.chromium.chrome.browser.toolbar.top.StartSurfaceToolbarProperties.NEW_TAB_BUTTON_IS_VISIBLE;
import static org.chromium.chrome.browser.toolbar.top.StartSurfaceToolbarProperties.NEW_TAB_CLICK_HANDLER;
import android.view.View;
import org.chromium.ui.modelutil.PropertyKey;
import org.chromium.ui.modelutil.PropertyModel;
......@@ -39,8 +38,6 @@ class StartSurfaceToolbarViewBinder {
view.setButtonClickableState(model.get(BUTTONS_CLICKABLE));
} else if (propertyKey == INCOGNITO_SWITCHER_VISIBLE) {
view.setIncognitoSwitcherVisibility(model.get(INCOGNITO_SWITCHER_VISIBLE));
} else if (propertyKey == NEW_TAB_BUTTON_AT_LEFT) {
view.setNewTabButtonAtLeft(model.get(NEW_TAB_BUTTON_AT_LEFT));
} else if (propertyKey == IDENTITY_DISC_CLICK_HANDLER) {
view.setIdentityDiscClickHandler(model.get(IDENTITY_DISC_CLICK_HANDLER));
} else if (propertyKey == IDENTITY_DISC_DESCRIPTION) {
......@@ -53,16 +50,20 @@ class StartSurfaceToolbarViewBinder {
view.setIdentityDiscVisibility(model.get(IDENTITY_DISC_IS_VISIBLE));
} else if (propertyKey == INCOGNITO_STATE_PROVIDER) {
view.setIncognitoStateProvider(model.get(INCOGNITO_STATE_PROVIDER));
} else if (propertyKey == IN_START_SURFACE_MODE) {
view.setStartSurfaceMode(model.get(IN_START_SURFACE_MODE));
} else if (propertyKey == IS_INCOGNITO) {
view.updateIncognito(model.get(IS_INCOGNITO));
} else if (propertyKey == IS_VISIBLE) {
view.setVisibility(model.get(IS_VISIBLE) ? View.VISIBLE : View.GONE);
view.setToolbarVisibility(model.get(IS_VISIBLE));
} else if (propertyKey == LOGO_IS_VISIBLE) {
view.setLogoVisibility(model.get(LOGO_IS_VISIBLE));
} else if (propertyKey == MENU_IS_VISIBLE) {
view.setMenuButtonVisibility(model.get(MENU_IS_VISIBLE));
} else if (propertyKey == NEW_TAB_CLICK_HANDLER) {
view.setOnNewTabClickHandler(model.get(NEW_TAB_CLICK_HANDLER));
} else if (propertyKey == NEW_TAB_BUTTON_AT_LEFT) {
view.setNewTabButtonAtLeft(model.get(NEW_TAB_BUTTON_AT_LEFT));
} else if (propertyKey == NEW_TAB_BUTTON_IS_VISIBLE) {
view.setNewTabButtonVisibility(model.get(NEW_TAB_BUTTON_IS_VISIBLE));
}
......
......@@ -22,7 +22,6 @@ import org.chromium.chrome.browser.tabmodel.TabModelObserver;
import org.chromium.chrome.browser.tabmodel.TabModelSelector;
import org.chromium.chrome.browser.toolbar.IncognitoStateProvider;
import org.chromium.chrome.browser.toolbar.TabCountProvider;
import org.chromium.chrome.browser.toolbar.ToolbarManager;
import org.chromium.chrome.browser.ui.appmenu.AppMenuButtonHelper;
import org.chromium.components.search_engines.TemplateUrlService.TemplateUrlServiceObserver;
......@@ -184,7 +183,7 @@ class TabSwitcherModeTTCoordinatorPhone implements TemplateUrlServiceObserver {
final float targetAlpha = shouldShowTabSwitcherToolbar ? 1.0f : 0.0f;
mTabSwitcherModeToolbar.animate()
.alpha(targetAlpha)
.setDuration(ToolbarManager.TAB_SWITCHER_MODE_NORMAL_ANIMATION_DURATION_MS)
.setDuration(TopToolbarCoordinator.TAB_SWITCHER_MODE_NORMAL_ANIMATION_DURATION_MS)
.setListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationStart(Animator animation) {
......
......@@ -29,7 +29,6 @@ import org.chromium.chrome.browser.toolbar.IncognitoToggleTabLayout;
import org.chromium.chrome.browser.toolbar.MenuButton;
import org.chromium.chrome.browser.toolbar.NewTabButton;
import org.chromium.chrome.browser.toolbar.TabCountProvider;
import org.chromium.chrome.browser.toolbar.ToolbarManager;
import org.chromium.chrome.browser.toolbar.bottom.BottomToolbarVariationManager;
import org.chromium.chrome.browser.ui.appmenu.AppMenuButtonHelper;
import org.chromium.components.browser_ui.styles.ChromeColors;
......@@ -140,8 +139,8 @@ public class TabSwitcherModeTTPhone extends OptimizedFrameLayout
boolean showZoomingAnimation = CachedFeatureFlags.isGridTabSwitcherEnabled()
&& TabFeatureUtilities.isTabToGtsAnimationEnabled();
long duration = showZoomingAnimation
? ToolbarManager.TAB_SWITCHER_MODE_GTS_ANIMATION_DURATION_MS
: ToolbarManager.TAB_SWITCHER_MODE_NORMAL_ANIMATION_DURATION_MS;
? TopToolbarCoordinator.TAB_SWITCHER_MODE_GTS_ANIMATION_DURATION_MS
: TopToolbarCoordinator.TAB_SWITCHER_MODE_NORMAL_ANIMATION_DURATION_MS;
mVisiblityAnimator =
ObjectAnimator.ofFloat(this, View.ALPHA, inTabSwitcherMode ? 1.0f : 0.0f);
......
......@@ -72,7 +72,6 @@ import org.chromium.chrome.browser.toolbar.TabCountProvider;
import org.chromium.chrome.browser.toolbar.TabCountProvider.TabCountObserver;
import org.chromium.chrome.browser.toolbar.TabSwitcherDrawable;
import org.chromium.chrome.browser.toolbar.ToolbarColors;
import org.chromium.chrome.browser.toolbar.ToolbarManager;
import org.chromium.chrome.browser.toolbar.bottom.BottomToolbarVariationManager;
import org.chromium.chrome.browser.toolbar.top.TopToolbarCoordinator.UrlExpansionObserver;
import org.chromium.components.browser_ui.styles.ChromeColors;
......@@ -1709,7 +1708,8 @@ public class ToolbarPhone extends ToolbarLayout implements Invalidator.Client, O
private ObjectAnimator createEnterTabSwitcherModeAnimation() {
ObjectAnimator enterAnimation =
ObjectAnimator.ofFloat(this, mTabSwitcherModePercentProperty, 1.f);
enterAnimation.setDuration(ToolbarManager.TAB_SWITCHER_MODE_NORMAL_ANIMATION_DURATION_MS);
enterAnimation.setDuration(
TopToolbarCoordinator.TAB_SWITCHER_MODE_NORMAL_ANIMATION_DURATION_MS);
enterAnimation.setInterpolator(Interpolators.LINEAR_INTERPOLATOR);
return enterAnimation;
......@@ -1719,7 +1719,7 @@ public class ToolbarPhone extends ToolbarLayout implements Invalidator.Client, O
ObjectAnimator exitAnimation =
ObjectAnimator.ofFloat(this, mTabSwitcherModePercentProperty, 0.f);
exitAnimation.setDuration(animateNormalToolbar
? ToolbarManager.TAB_SWITCHER_MODE_NORMAL_ANIMATION_DURATION_MS
? TopToolbarCoordinator.TAB_SWITCHER_MODE_NORMAL_ANIMATION_DURATION_MS
: TAB_SWITCHER_MODE_EXIT_FADE_ANIMATION_DURATION_MS);
exitAnimation.setInterpolator(Interpolators.LINEAR_INTERPOLATOR);
exitAnimation.addListener(new CancelAwareAnimatorListener() {
......
......@@ -51,6 +51,9 @@ public class TopToolbarCoordinator implements Toolbar {
void onUrlExpansionPercentageChanged(float percentage);
}
public static final int TAB_SWITCHER_MODE_NORMAL_ANIMATION_DURATION_MS = 200;
public static final int TAB_SWITCHER_MODE_GTS_ANIMATION_DURATION_MS = 150;
private final ToolbarLayout mToolbarLayout;
/**
......
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