Commit 71bdacf2 authored by Theresa's avatar Theresa Committed by Commit Bot

[EoC] Add animation for button appearance/disappearance

Add an animtion for the button appearing and disappearing. Also animate
the button when the URL is focused/unfocused.

BUG=889536

Change-Id: I7ca53c2e41da3bedab5b07a133ab4475887c3e17
Reviewed-on: https://chromium-review.googlesource.com/1246944
Commit-Queue: Theresa <twellington@chromium.org>
Reviewed-by: default avatarTed Choc <tedchoc@chromium.org>
Cr-Commit-Position: refs/heads/master@{#595182}
parent b6709dfe
......@@ -267,6 +267,7 @@
<dimen name="tablet_toolbar_start_padding">4dp</dimen>
<dimen name="tablet_toolbar_end_padding">6dp</dimen>
<dimen name="location_bar_status_separator_width">1dp</dimen>
<dimen name="toolbar_optional_button_animation_translation">10dp</dimen>
<!-- Modern toolbar dimensions -->
<dimen name="modern_toolbar_background_size">40dp</dimen>
......
......@@ -25,6 +25,7 @@ import org.chromium.chrome.browser.fullscreen.ChromeFullscreenManager.Fullscreen
import org.chromium.chrome.browser.profiles.Profile;
import org.chromium.chrome.browser.tabmodel.TabModelSelector;
import org.chromium.chrome.browser.toolbar.ToolbarManager;
import org.chromium.chrome.browser.toolbar.ToolbarPhone;
import org.chromium.chrome.browser.util.AccessibilityUtil;
import org.chromium.chrome.browser.util.MathUtils;
import org.chromium.chrome.browser.widget.ListMenuButton;
......@@ -289,7 +290,8 @@ class ContextualSuggestionsMediator
reportEvent(ContextualSuggestionsEvent.UI_BUTTON_SHOWN);
TrackerFactory.getTrackerForProfile(mProfile).notifyEvent(
EventConstants.CONTEXTUAL_SUGGESTIONS_BUTTON_SHOWN);
maybeShowHelpBubble();
mHandler.postDelayed(() -> maybeShowHelpBubble(),
ToolbarPhone.LOC_BAR_WIDTH_CHANGE_ANIMATION_DURATION_MS);
}
@Override
......@@ -433,13 +435,19 @@ class ContextualSuggestionsMediator
}
private void maybeShowHelpBubble() {
View anchorView =
mIphParentView.getRootView().findViewById(R.id.experimental_toolbar_button);
if (mToolbarManager.isUrlBarFocused() || anchorView == null
|| anchorView.getVisibility() != View.VISIBLE) {
return;
}
Tracker tracker = TrackerFactory.getTrackerForProfile(mProfile);
if (!tracker.shouldTriggerHelpUI(FeatureConstants.CONTEXTUAL_SUGGESTIONS_FEATURE)) {
return;
}
ViewRectProvider rectProvider = new ViewRectProvider(
mIphParentView.getRootView().findViewById(R.id.experimental_toolbar_button));
ViewRectProvider rectProvider = new ViewRectProvider(anchorView);
rectProvider.setInsetPx(0, 0, 0,
mIphParentView.getResources().getDimensionPixelOffset(
R.dimen.text_bubble_menu_anchor_y_inset));
......
......@@ -63,7 +63,7 @@ public abstract class ToolbarLayout extends FrameLayout implements Toolbar {
/**
* The ImageButton view that represents the menu button.
*/
private TintedImageButton mMenuButton;
protected TintedImageButton mMenuButton;
private ImageView mMenuBadge;
private View mMenuButtonWrapper;
private AppMenuButtonHelper mAppMenuButtonHelper;
......
......@@ -667,6 +667,13 @@ public class ToolbarManager implements ToolbarTabController, UrlFocusChangeListe
mLoadProgressSimulator = new LoadProgressSimulator(this);
}
/**
* @return Whether the UrlBar currently has focus.
*/
public boolean isUrlBarFocused() {
return getToolbarLayout().getLocationBar().isUrlBarFocused();
}
/**
* @param reason A {@link OmniboxFocusReason} that the omnibox was focused.
*/
......
......@@ -105,6 +105,7 @@ public class ToolbarPhone extends ToolbarLayout
public static final int URL_FOCUS_CHANGE_ANIMATION_DURATION_MS = 225;
private static final int URL_FOCUS_TOOLBAR_BUTTONS_TRANSLATION_X_DP = 10;
private static final int URL_FOCUS_TOOLBAR_BUTTONS_DURATION_MS = 100;
private static final int URL_CLEAR_FOCUS_EXPERIMENTAL_BUTTON_DELAY_MS = 150;
private static final int URL_CLEAR_FOCUS_TABSTACK_DELAY_MS = 200;
private static final int URL_CLEAR_FOCUS_MENU_DELAY_MS = 250;
......@@ -113,6 +114,11 @@ public class ToolbarPhone extends ToolbarLayout
private static final int TAB_SWITCHER_MODE_EXIT_FADE_ANIMATION_DURATION_MS = 100;
private static final int TAB_SWITCHER_MODE_POST_EXIT_ANIMATION_DURATION_MS = 100;
// Values used during animation to show/hide optional toolbar button.
public static final int LOC_BAR_WIDTH_CHANGE_ANIMATION_DURATION_MS = 225;
private static final int EXPERIMENTAL_ICON_ANIMATION_DURATION_MS = 100;
private static final int EXPERIMENTAL_ICON_ANIMATION_DELAY_MS = 125;
private static final float UNINITIALIZED_PERCENT = -1f;
/** States that the toolbar can be in regarding the tab switcher. */
......@@ -210,6 +216,7 @@ public class ToolbarPhone extends ToolbarLayout
protected boolean mDisableLocationBarRelayout;
protected boolean mLayoutLocationBarInFocusedMode;
private boolean mLayoutLocationBarWithoutExtraButton;
protected int mUnfocusedLocationBarLayoutWidth;
protected int mUnfocusedLocationBarLayoutLeft;
protected int mUnfocusedLocationBarLayoutRight;
......@@ -300,6 +307,17 @@ public class ToolbarPhone extends ToolbarLayout
private float mPreTextureCaptureAlpha = 1f;
private boolean mIsOverlayTabStackDrawableLight;
private AnimatorSet mExperimentalButtonAnimator;
private boolean mExperimentalButtonAnimationRunning;
private int mExperimentalButtonTranslation;
/**
* The percent completion for the location bar width change animation that is run when the
* experimental button is shown/hidden. Animates from 1.f to 0.f when showing the button and
* 0.f to 1.f when hiding the button, where 0.f indicates the location bar width is not offset
* at all for the animation.
*/
private float mLocBarWidthChangePercent;
/**
* A global layout listener used to capture a new texture when the experimental toolbar button
* is added or removed.
......@@ -336,6 +354,20 @@ public class ToolbarPhone extends ToolbarLayout
}
};
private final Property<ToolbarPhone, Float> mLocBarWidthChangePercentProperty =
new Property<ToolbarPhone, Float>(Float.class, "") {
@Override
public Float get(ToolbarPhone object) {
return object.mLocBarWidthChangePercent;
}
@Override
public void set(ToolbarPhone object, Float value) {
mLocBarWidthChangePercent = value;
updateLocationBarLayoutForExpansionAnimation();
}
};
/**
* Constructs a ToolbarPhone object.
* @param context The Context in which this View object is created.
......@@ -684,6 +716,12 @@ public class ToolbarPhone extends ToolbarLayout
leftMargin = mUnfocusedLocationBarLayoutLeft;
}
if (mLayoutLocationBarWithoutExtraButton) {
float offset = getLocationBarWidthOffsetForExperimentalButton();
if (ApiCompatibilityUtils.isLayoutRtl(this)) leftMargin -= (int) offset;
width += (int) offset;
}
boolean changed = false;
changed |= (width != locationBarLayoutParams.width);
locationBarLayoutParams.width = width;
......@@ -915,6 +953,11 @@ public class ToolbarPhone extends ToolbarLayout
int leftViewPosition =
(int) MathUtils.interpolate(getViewBoundsLeftOfLocationBar(visualState),
getFocusedLeftPositionOfLocationBarBackground(), expansion);
if (mExperimentalButtonAnimationRunning && ApiCompatibilityUtils.isLayoutRtl(this)) {
leftViewPosition -= getLocationBarBackgroundOffsetForExperimentalButton();
}
return leftViewPosition;
}
......@@ -936,9 +979,38 @@ public class ToolbarPhone extends ToolbarLayout
(int) MathUtils.interpolate(getViewBoundsRightOfLocationBar(visualState),
getFocusedRightPositionOfLocationBarBackground(), expansion);
if (mExperimentalButtonAnimationRunning && !ApiCompatibilityUtils.isLayoutRtl(this)) {
rightViewPosition += getLocationBarBackgroundOffsetForExperimentalButton();
}
return rightViewPosition;
}
/**
* @return The location bar background position offset, for use when the experimental button
* show/hide animation is running.
*/
private int getLocationBarBackgroundOffsetForExperimentalButton() {
return (int) (getLocationBarWidthOffsetForExperimentalButton() * mLocBarWidthChangePercent);
}
/**
* @return The difference in the location bar width when the experimental button is hidden
* rather than showing. This is effectively the width of the experimental button with
* some adjustment to account for possible padding differences when the button
* visibility changes.
*/
private float getLocationBarWidthOffsetForExperimentalButton() {
float widthChange = mExperimentalButton.getWidth();
// When the experimental button is the only visible button after the location bar and the
// button is hidden mToolbarSidePadding is used for the padding after the location bar.
if (!isMenuButtonPresent()) {
widthChange -= mToolbarSidePadding;
}
return widthChange;
}
/**
* @return The right drawing position for the location bar background when the location bar
* has focus.
......@@ -1003,12 +1075,32 @@ public class ToolbarPhone extends ToolbarLayout
int currentWidth = locationBarLayoutParams.width;
float locationBarBaseTranslationX = mUnfocusedLocationBarLayoutLeft - currentLeftMargin;
if (mExperimentalButtonAnimationRunning) {
// When showing the button, we disable location bar relayout
// (mDisableLocationBarRelayout), so the location bar's left margin and
// mUnfocusedLocationBarLayoutLeft have not been updated to take into account the
// appearance of the experimental icon. The views to left of the location bar will
// be wider than mUnfocusedlocationBarLayoutLeft in RTL, so adjust the translation by
// that amount.
// When hiding the button, we force a relayout without the experimental toolbar button
// (mLayoutLocationBarWithoutExtraButton). mUnfocusedLocationBarLayoutLeft reflects
// the view bounds left of the location bar, which still includes the experimental
// button. The location bar left margin, however, has been adjusted to reflect its
// end value when the experimental button is fully hidden. The
// locationBarBaseTranslationX above accounts for the difference between
// mUnfocusedLocationBarLayoutLeft and the location bar's current left margin.
locationBarBaseTranslationX +=
getViewBoundsLeftOfLocationBar(mVisualState) - mUnfocusedLocationBarLayoutLeft;
}
boolean isLocationBarRtl = ApiCompatibilityUtils.isLayoutRtl(mLocationBar);
if (isLocationBarRtl) {
locationBarBaseTranslationX += mUnfocusedLocationBarLayoutWidth - currentWidth;
}
locationBarBaseTranslationX *= 1f - mUrlExpansionPercent;
locationBarBaseTranslationX *= 1f
- (mExperimentalButtonAnimationRunning ? mLocBarWidthChangePercent
: mUrlExpansionPercent);
mLocationBarBackgroundNtpOffset.setEmpty();
mLocationBarNtpOffsetLeft = 0;
......@@ -1038,23 +1130,25 @@ public class ToolbarPhone extends ToolbarLayout
}
mLocationBar.setTranslationX(locationBarTranslationX);
mUrlActionContainer.setTranslationX(getUrlActionsTranslationXForExpansionAnimation(
isLocationBarRtl, locationBarBaseTranslationX));
mLocationBar.setUrlFocusChangePercent(mUrlExpansionPercent);
// Only transition theme colors if in static tab mode that is not the NTP. In practice this
// only runs when you focus the omnibox on a web page.
if (!isLocationBarShownInNTP() && mTabSwitcherState == STATIC_TAB) {
int defaultColor = ColorUtils.getDefaultThemeColor(getResources(), isIncognito());
int defaultLocationBarColor = getLocationBarColorForToolbarColor(defaultColor);
int primaryColor = getToolbarDataProvider().getPrimaryColor();
int themedLocationBarColor = getLocationBarColorForToolbarColor(primaryColor);
updateToolbarBackground(ColorUtils.getColorWithOverlay(
primaryColor, defaultColor, mUrlFocusChangePercent));
if (!mExperimentalButtonAnimationRunning) {
mUrlActionContainer.setTranslationX(getUrlActionsTranslationXForExpansionAnimation(
isLocationBarRtl, locationBarBaseTranslationX));
mLocationBar.setUrlFocusChangePercent(mUrlExpansionPercent);
// Only transition theme colors if in static tab mode that is not the NTP. In practice
// this only runs when you focus the omnibox on a web page.
if (!isLocationBarShownInNTP() && mTabSwitcherState == STATIC_TAB) {
int defaultColor = ColorUtils.getDefaultThemeColor(getResources(), isIncognito());
int defaultLocationBarColor = getLocationBarColorForToolbarColor(defaultColor);
int primaryColor = getToolbarDataProvider().getPrimaryColor();
int themedLocationBarColor = getLocationBarColorForToolbarColor(primaryColor);
updateToolbarBackground(ColorUtils.getColorWithOverlay(
primaryColor, defaultColor, mUrlFocusChangePercent));
updateModernLocationBarColor(ColorUtils.getColorWithOverlay(
themedLocationBarColor, defaultLocationBarColor, mUrlFocusChangePercent));
updateModernLocationBarColor(ColorUtils.getColorWithOverlay(
themedLocationBarColor, defaultLocationBarColor, mUrlFocusChangePercent));
}
}
// Force an invalidation of the location bar to properly handle the clipping of the URL
......@@ -1441,7 +1535,7 @@ public class ToolbarPhone extends ToolbarLayout
// viewport used to draw the background. During expansion transitions, compensation
// is applied to increase the clip regions such that when the location bar converts
// to the narrower collapsed layout the visible content is the same.
if (mUrlExpansionPercent != 1f) {
if (mUrlExpansionPercent != 1f && !mExperimentalButtonAnimationRunning) {
int leftDelta = mUnfocusedLocationBarLayoutLeft
- getViewBoundsLeftOfLocationBar(mVisualState);
int rightDelta = getViewBoundsRightOfLocationBar(mVisualState)
......@@ -1461,6 +1555,13 @@ public class ToolbarPhone extends ToolbarLayout
locationBarClipRight -= ViewCompat.getPaddingEnd(mLocationBar) * inversePercent;
}
}
if (mExperimentalButtonAnimationRunning) {
if (ApiCompatibilityUtils.isLayoutRtl(mLocationBar)) {
locationBarClipLeft += ViewCompat.getPaddingStart(mLocationBar);
} else {
locationBarClipRight -= ViewCompat.getPaddingEnd(mLocationBar);
}
}
// Clip the location bar child to the URL viewport calculated in onDraw.
canvas.clipRect(
......@@ -1969,6 +2070,19 @@ public class ToolbarPhone extends ToolbarLayout
animators.add(animator);
}
if (mExperimentalButton != null && mExperimentalButton.getVisibility() != View.GONE) {
animator = ObjectAnimator.ofFloat(
mExperimentalButton, TRANSLATION_X, toolbarButtonTranslationX);
animator.setDuration(URL_FOCUS_TOOLBAR_BUTTONS_DURATION_MS);
animator.setInterpolator(BakedBezierInterpolator.FADE_OUT_CURVE);
animators.add(animator);
animator = ObjectAnimator.ofFloat(mExperimentalButton, ALPHA, 0);
animator.setDuration(URL_FOCUS_TOOLBAR_BUTTONS_DURATION_MS);
animator.setInterpolator(BakedBezierInterpolator.FADE_OUT_CURVE);
animators.add(animator);
}
animator = ObjectAnimator.ofFloat(mToolbarShadow, ALPHA, 0);
animator.setDuration(URL_FOCUS_CHANGE_ANIMATION_DURATION_MS);
animator.setInterpolator(BakedBezierInterpolator.TRANSFORM_CURVE);
......@@ -2010,6 +2124,23 @@ public class ToolbarPhone extends ToolbarLayout
animators.add(animator);
}
if (mExperimentalButton != null && mExperimentalButton.getVisibility() != View.GONE) {
// TODO(twellington): it's possible that the experimental button was shown while
// the url bar was focused, in which case the translation x and alpha animators
// are a no-op. Account for this case.
animator = ObjectAnimator.ofFloat(mExperimentalButton, TRANSLATION_X, 0);
animator.setDuration(URL_FOCUS_TOOLBAR_BUTTONS_DURATION_MS);
animator.setStartDelay(URL_CLEAR_FOCUS_EXPERIMENTAL_BUTTON_DELAY_MS);
animator.setInterpolator(BakedBezierInterpolator.TRANSFORM_CURVE);
animators.add(animator);
animator = ObjectAnimator.ofFloat(mExperimentalButton, ALPHA, 1);
animator.setDuration(URL_FOCUS_TOOLBAR_BUTTONS_DURATION_MS);
animator.setStartDelay(URL_CLEAR_FOCUS_EXPERIMENTAL_BUTTON_DELAY_MS);
animator.setInterpolator(BakedBezierInterpolator.TRANSFORM_CURVE);
animators.add(animator);
}
for (int i = 0; i < mLocationBar.getChildCount(); i++) {
View childView = mLocationBar.getChildAt(i);
if (childView == mLocationBar.getFirstViewVisibleWhenFocused()) break;
......@@ -2042,6 +2173,7 @@ public class ToolbarPhone extends ToolbarLayout
mUrlFocusLayoutAnimator.cancel();
mUrlFocusLayoutAnimator = null;
}
if (mExperimentalButtonAnimationRunning) mExperimentalButtonAnimator.end();
List<Animator> animators = new ArrayList<>();
if (hasFocus) {
......@@ -2559,10 +2691,14 @@ public class ToolbarPhone extends ToolbarLayout
ViewStub viewStub = findViewById(R.id.experimental_button_stub);
mExperimentalButton = (TintedImageButton) viewStub.inflate();
if (FeatureUtilities.isBottomToolbarEnabled()) {
mExperimentalButton.setPadding(0, 0, 0, 0);
}
if (!isMenuButtonPresent()) mExperimentalButton.setPadding(0, 0, 0, 0);
mExperimentalButtonTranslation = getResources().getDimensionPixelSize(
R.dimen.toolbar_optional_button_animation_translation);
if (ApiCompatibilityUtils.isLayoutRtl(this)) mExperimentalButtonTranslation *= -1;
} else {
if (mExperimentalButtonAnimationRunning) {
mExperimentalButtonAnimator.end();
}
assert mExperimentalButton.getVisibility()
== View.GONE : "#disableExperimentalButton() should be called first.";
}
......@@ -2573,8 +2709,13 @@ public class ToolbarPhone extends ToolbarLayout
mExperimentalButton.setContentDescription(
getContext().getResources().getString(contentDescriptionResId));
mExperimentalButton.setTint(mUseLightToolbarDrawables ? mLightModeTint : mDarkModeTint);
if (mTabSwitcherState == STATIC_TAB) {
mExperimentalButton.setVisibility(View.VISIBLE);
if (!mUrlFocusChangeInProgress && !urlHasFocus()) {
runShowExperimentalButtonAnimation();
} else {
mExperimentalButton.setVisibility(View.VISIBLE);
}
} else {
mExperimentalButton.setVisibility(View.INVISIBLE);
}
......@@ -2585,24 +2726,158 @@ public class ToolbarPhone extends ToolbarLayout
@Override
public void disableExperimentalButton() {
if (mExperimentalButton == null) return;
if (mExperimentalButton == null || mExperimentalButton.getVisibility() == View.GONE) {
return;
}
if (mTabSwitcherState == STATIC_TAB && !mUrlFocusChangeInProgress && !urlHasFocus()) {
runHideExperimentalButtonsAnimators();
} else {
mExperimentalButton.setVisibility(View.GONE);
}
mExperimentalButton.setVisibility(View.GONE);
mBrowsingModeViews.remove(mExperimentalButton);
getViewTreeObserver().addOnGlobalLayoutListener(mExperimentalButtonLayoutListener);
}
/**
* Whether the menu button is visible. Used as a proxy for whether there are end toolbar
* buttons besides the experimental button.
*/
private boolean isMenuButtonPresent() {
return mMenuButton != null;
}
private void requestLayoutHostUpdateForExperimentalButton() {
if (mLayoutUpdateHost != null) mLayoutUpdateHost.requestUpdate();
getViewTreeObserver().removeOnGlobalLayoutListener(mExperimentalButtonLayoutListener);
}
/**
* Runs an animation that fades in the experimental button while shortening the location bar
* background.
*/
private void runShowExperimentalButtonAnimation() {
if (mExperimentalButtonAnimationRunning) mExperimentalButtonAnimator.end();
List<Animator> animators = new ArrayList<>();
mLocBarWidthChangePercent = 1.f;
Animator widthChangeAnimator =
ObjectAnimator.ofFloat(this, mLocBarWidthChangePercentProperty, 0.f);
widthChangeAnimator.setDuration(LOC_BAR_WIDTH_CHANGE_ANIMATION_DURATION_MS);
widthChangeAnimator.setInterpolator(BakedBezierInterpolator.TRANSFORM_CURVE);
animators.add(widthChangeAnimator);
mExperimentalButton.setAlpha(0.f);
ObjectAnimator buttonAnimator =
ObjectAnimator.ofFloat(mExperimentalButton, View.ALPHA, 1.f);
buttonAnimator.setInterpolator(BakedBezierInterpolator.TRANSFORM_CURVE);
buttonAnimator.setStartDelay(EXPERIMENTAL_ICON_ANIMATION_DELAY_MS);
buttonAnimator.setDuration(EXPERIMENTAL_ICON_ANIMATION_DURATION_MS);
animators.add(buttonAnimator);
mExperimentalButton.setTranslationX(mExperimentalButtonTranslation);
ObjectAnimator buttonTranslationAnimator =
ObjectAnimator.ofFloat(mExperimentalButton, View.TRANSLATION_X, 0);
buttonTranslationAnimator.setInterpolator(BakedBezierInterpolator.TRANSFORM_CURVE);
buttonTranslationAnimator.setStartDelay(EXPERIMENTAL_ICON_ANIMATION_DELAY_MS);
buttonTranslationAnimator.setDuration(EXPERIMENTAL_ICON_ANIMATION_DURATION_MS);
animators.add(buttonTranslationAnimator);
mExperimentalButtonAnimator = new AnimatorSet();
mExperimentalButtonAnimator.addListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationStart(Animator animation) {
mDisableLocationBarRelayout = true;
mExperimentalButtonAnimationRunning = true;
mExperimentalButton.setVisibility(View.VISIBLE);
}
@Override
public void onAnimationEnd(Animator animation) {
onExperimentalButtonAnimationEnd();
mDisableLocationBarRelayout = false;
mExperimentalButtonAnimationRunning = false;
requestLayout();
}
});
mExperimentalButtonAnimator.playTogether(animators);
mExperimentalButtonAnimator.start();
}
/**
* Runs an animation that fades out the experimental button while lengthening the location bar
* background.
*/
private void runHideExperimentalButtonsAnimators() {
if (mExperimentalButtonAnimationRunning) mExperimentalButtonAnimator.end();
List<Animator> animators = new ArrayList<>();
mLocBarWidthChangePercent = 0.f;
Animator widthChangeAnimator =
ObjectAnimator.ofFloat(this, mLocBarWidthChangePercentProperty, 1.f);
widthChangeAnimator.setDuration(LOC_BAR_WIDTH_CHANGE_ANIMATION_DURATION_MS);
widthChangeAnimator.setInterpolator(BakedBezierInterpolator.TRANSFORM_CURVE);
animators.add(widthChangeAnimator);
mExperimentalButton.setAlpha(1.f);
ObjectAnimator buttonAnimator =
ObjectAnimator.ofFloat(mExperimentalButton, View.ALPHA, 0.f);
buttonAnimator.setInterpolator(BakedBezierInterpolator.FADE_OUT_CURVE);
buttonAnimator.setDuration(EXPERIMENTAL_ICON_ANIMATION_DURATION_MS);
animators.add(buttonAnimator);
mExperimentalButton.setTranslationX(0);
ObjectAnimator buttonTranslationAnimator = ObjectAnimator.ofFloat(
mExperimentalButton, View.TRANSLATION_X, mExperimentalButtonTranslation);
buttonTranslationAnimator.setInterpolator(BakedBezierInterpolator.FADE_OUT_CURVE);
buttonTranslationAnimator.setDuration(EXPERIMENTAL_ICON_ANIMATION_DURATION_MS);
animators.add(buttonTranslationAnimator);
mExperimentalButtonAnimator = new AnimatorSet();
mExperimentalButtonAnimator.addListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationStart(Animator animation) {
mLayoutLocationBarWithoutExtraButton = true;
mExperimentalButtonAnimationRunning = true;
requestLayout();
}
@Override
public void onAnimationEnd(Animator animation) {
onExperimentalButtonAnimationEnd();
mExperimentalButton.setVisibility(View.GONE);
mLayoutLocationBarWithoutExtraButton = false;
mExperimentalButtonAnimationRunning = false;
}
});
mExperimentalButtonAnimator.playTogether(animators);
mExperimentalButtonAnimator.start();
}
/**
* Resets the alpha and translation X for all views affected by the animations for showing or
* hiding buttons.
*/
private void onExperimentalButtonAnimationEnd() {
mExperimentalButtonAnimator = null;
mExperimentalButton.setAlpha(1.f);
mExperimentalButton.setTranslationX(0);
}
@VisibleForTesting
public View getExperimentalButtonForTesting() {
return mExperimentalButton;
}
@VisibleForTesting
public void endExperimentalButtonAnimationForTesting() {
if (mExperimentalButtonAnimator != null) mExperimentalButtonAnimator.end();
}
private void setTabSwitcherAnimationMenuDrawable() {
mTabSwitcherAnimationMenuDrawable = ApiCompatibilityUtils.getDrawable(
getResources(), R.drawable.ic_more_vert_black_24dp);
......
......@@ -528,7 +528,10 @@ public class ContextualSuggestionsTest {
"Toolbar button should be visible", View.VISIBLE, toolbarButton.getVisibility());
// Simulate suggestions being cleared.
ThreadUtils.runOnUiThreadBlocking(() -> mMediator.clearState());
ThreadUtils.runOnUiThreadBlocking(() -> {
mMediator.clearState();
getToolbarPhone().endExperimentalButtonAnimationForTesting();
});
assertEquals("Toolbar button should be gone", View.GONE, toolbarButton.getVisibility());
assertEquals("Suggestions should be cleared", 0, mModel.getClusterList().getItemCount());
......@@ -598,10 +601,8 @@ public class ContextualSuggestionsTest {
}
private View getToolbarButton(ChromeActivity activity) throws ExecutionException {
return ThreadUtils.runOnUiThreadBlocking(() -> {
return ((ToolbarPhone) activity.getToolbarManager().getToolbarLayout())
.getExperimentalButtonForTesting();
});
return ThreadUtils.runOnUiThreadBlocking(
() -> { return getToolbarPhone(activity).getExperimentalButtonForTesting(); });
}
private void clickToolbarButton() throws ExecutionException {
......@@ -641,6 +642,9 @@ public class ContextualSuggestionsTest {
CriteriaHelper.pollUiThread(() -> {
return mActivityTestRule.getActivity().getActivityTab().getUrl().equals(expectedUrl);
});
ThreadUtils.runOnUiThreadBlocking(
() -> getToolbarPhone().endExperimentalButtonAnimationForTesting());
}
private void dismissHelpBubble() {
......@@ -650,4 +654,12 @@ public class ContextualSuggestionsTest {
}
});
}
private ToolbarPhone getToolbarPhone() {
return getToolbarPhone(mActivityTestRule.getActivity());
}
private ToolbarPhone getToolbarPhone(ChromeActivity activity) {
return (ToolbarPhone) activity.getToolbarManager().getToolbarLayout();
}
}
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