Commit a02c005f authored by perezju's avatar perezju Committed by Commit bot

Revert of 馃彔 Polish bottom sheet content transitions (patchset #1 id:1 of...

Revert of 馃彔 Polish bottom sheet content transitions (patchset #1 id:1 of https://codereview.chromium.org/2839673002/ )

Reason for revert:
Appears to be causing multiple chrome_public_test_apk failures on Marshmallow 64 bit Tester.
crbug.com/715336

Original issue's description:
> [Home] Polish bottom sheet content transitions
>
> This change adds animation when transitioning between bottom sheet
> content. The existing view is faded out completely before the new
> view is faded in. The animation is applied to both the sheet content
> and the toolbar view.
>
> Notably, the onContentChanged() event is now called when the
> transition animation has finished instead of immediately when
> showContent(...) is called.
>
> BUG=702717
>
> Review-Url: https://codereview.chromium.org/2839673002
> Cr-Commit-Position: refs/heads/master@{#466780}
> Committed: https://chromium.googlesource.com/chromium/src/+/419509cbf0ac3a8a8595b3ce9e56daf75e5c2f0c

TBR=twellington@chromium.org,mdjones@chromium.org
# Not skipping CQ checks because original CL landed more than 1 days ago.
BUG=702717

Review-Url: https://codereview.chromium.org/2838313003
Cr-Commit-Position: refs/heads/master@{#467301}
parent f2c7bd6e
......@@ -34,8 +34,7 @@
android:id="@+id/toolbar_holder"
android:layout_width="match_parent"
android:layout_height="@dimen/bottom_control_container_height"
android:layout_marginTop="@dimen/toolbar_shadow_height"
android:background="@color/default_primary_color" >
android:layout_marginTop="@dimen/toolbar_shadow_height" >
<ViewStub
android:id="@+id/toolbar_stub"
......@@ -67,8 +66,7 @@
android:id="@+id/bottom_sheet_content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/bottom_nav_height"
android:background="@color/default_primary_color" />
android:paddingBottom="@dimen/bottom_nav_height" />
<ViewStub
android:id="@+id/bottom_omnibox_results_container_stub"
......
......@@ -6,7 +6,6 @@ package org.chromium.chrome.browser.widget.bottomsheet;
import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
import android.animation.AnimatorSet;
import android.animation.ObjectAnimator;
import android.animation.ValueAnimator;
import android.content.Context;
......@@ -21,7 +20,6 @@ import android.view.GestureDetector;
import android.view.MotionEvent;
import android.view.VelocityTracker;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.view.animation.DecelerateInterpolator;
import android.view.animation.Interpolator;
......@@ -51,8 +49,6 @@ import org.chromium.content_public.browser.LoadUrlParams;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.util.ArrayList;
import java.util.List;
/**
* This class defines the bottom sheet that has multiple states and a persistently showing toolbar.
......@@ -90,9 +86,6 @@ public class BottomSheet
*/
private static final long BASE_ANIMATION_DURATION_MS = 218;
/** The amount of time it takes to transition sheet content in or out. */
private static final long TRANSITION_DURATION_MS = 150;
/**
* The fraction of the way to the next state the sheet must be swiped to animate there when
* released. This is the value used when there are 3 active states. A smaller value here means
......@@ -147,8 +140,8 @@ public class BottomSheet
/** The animator used to move the sheet to a fixed state when released by the user. */
private ValueAnimator mSettleAnimator;
/** The animator set responsible for swapping the bottom sheet content. */
private AnimatorSet mContentSwapAnimatorSet;
/** The animator used for the toolbar fades. */
private ValueAnimator mToolbarFadeAnimator;
/** The height of the toolbar. */
private float mToolbarHeight;
......@@ -564,7 +557,7 @@ public class BottomSheet
LayoutParams placeHolderParams =
new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
mPlaceholder.setBackgroundColor(
ApiCompatibilityUtils.getColor(getResources(), R.color.default_primary_color));
ApiCompatibilityUtils.getColor(getResources(), android.R.color.white));
mBottomSheetContentContainer.addView(mPlaceholder, placeHolderParams);
mToolbarHolder = (FrameLayout) mControlContainer.findViewById(R.id.toolbar_holder);
......@@ -652,86 +645,83 @@ public class BottomSheet
* Show content in the bottom sheet's content area.
* @param content The {@link BottomSheetContent} to show.
*/
public void showContent(final BottomSheetContent content) {
public void showContent(BottomSheetContent content) {
// If the desired content is already showing, do nothing.
if (mSheetContent == content) return;
mBottomSheetContentContainer.removeView(mPlaceholder);
View newToolbar =
content.getToolbarView() != null ? content.getToolbarView() : mDefaultToolbarView;
View oldToolbar = mSheetContent != null && mSheetContent.getToolbarView() != null
? mSheetContent.getToolbarView()
: mDefaultToolbarView;
View oldContent = mSheetContent != null ? mSheetContent.getContentView() : null;
View newToolbar = content.getToolbarView();
View oldToolbar = null;
// If an animation is already running, end it.
if (mContentSwapAnimatorSet != null) mContentSwapAnimatorSet.end();
if (mSheetContent != null) {
oldToolbar = mSheetContent.getToolbarView();
mBottomSheetContentContainer.removeView(mSheetContent.getContentView());
mSheetContent = null;
}
List<Animator> animators = new ArrayList<>();
mContentSwapAnimatorSet = new AnimatorSet();
mContentSwapAnimatorSet.addListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animation) {
mSheetContent = content;
for (BottomSheetObserver o : mObservers) {
o.onSheetContentChanged(content);
}
updateHandleTint();
mContentSwapAnimatorSet = null;
}
});
mBottomSheetContentContainer.removeView(mPlaceholder);
mSheetContent = content;
mBottomSheetContentContainer.addView(mSheetContent.getContentView());
// For the toolbar transition, make sure we don't detach the default toolbar view.
animators.add(getViewTransitionAnimator(
newToolbar, oldToolbar, mToolbarHolder, mDefaultToolbarView != oldToolbar));
animators.add(getViewTransitionAnimator(
content.getContentView(), oldContent, mBottomSheetContentContainer, true));
doToolbarSwap(newToolbar, oldToolbar);
mContentSwapAnimatorSet.playTogether(animators);
mContentSwapAnimatorSet.start();
for (BottomSheetObserver o : mObservers) {
o.onSheetContentChanged(mSheetContent);
}
}
/**
* Creates a transition animation between two views. The old view is faded out completely
* before the new view is faded in. There is an option to detach the old view or not.
* @param newView The new view to transition to.
* @param oldView The old view to transition from.
* @param detachOldView Whether or not to detach the old view once faded out.
* @return An animator that runs the specified animation.
* Fade between a new toolbar and the old toolbar to be shown. A null parameter can be used to
* refer to the default omnibox toolbar. Normally, the new toolbar is attached to the toolbar
* container and faded in. In the case of the default toolbar, the old toolbar is faded out.
* This is because the default toolbar is always attached to the view hierarchy and sits behind
* the attach point for the other toolbars.
* @param newToolbar The toolbar that will be shown.
* @param oldToolbar The toolbar being replaced.
*/
private Animator getViewTransitionAnimator(final View newView, final View oldView,
final ViewGroup parent, final boolean detachOldView) {
if (newView == oldView) return null;
AnimatorSet animatorSet = new AnimatorSet();
List<Animator> animators = new ArrayList<>();
// Fade out the old view.
if (oldView != null) {
ValueAnimator fadeOutAnimator = ObjectAnimator.ofFloat(oldView, View.ALPHA, 0);
fadeOutAnimator.setDuration(TRANSITION_DURATION_MS);
fadeOutAnimator.addListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animation) {
if (detachOldView && oldView.getParent() != null) {
parent.removeView(oldView);
}
}
});
animators.add(fadeOutAnimator);
}
private void doToolbarSwap(View newToolbar, View oldToolbar) {
if (mToolbarFadeAnimator != null) mToolbarFadeAnimator.end();
final View targetToolbar = newToolbar != null ? newToolbar : mDefaultToolbarView;
final View currentToolbar = oldToolbar != null ? oldToolbar : mDefaultToolbarView;
// Fade in the new view.
if (parent != newView.getParent()) parent.addView(newView);
newView.setAlpha(0);
ValueAnimator fadeInAnimator = ObjectAnimator.ofFloat(newView, View.ALPHA, 1);
fadeInAnimator.setDuration(TRANSITION_DURATION_MS);
animators.add(fadeInAnimator);
if (targetToolbar == currentToolbar) return;
if (targetToolbar != mDefaultToolbarView) {
mToolbarHolder.addView(targetToolbar);
targetToolbar.setAlpha(0f);
} else {
targetToolbar.setVisibility(View.VISIBLE);
targetToolbar.setAlpha(1f);
}
animatorSet.playSequentially(animators);
mToolbarFadeAnimator = ObjectAnimator.ofFloat(0, 1);
mToolbarFadeAnimator.setDuration(BASE_ANIMATION_DURATION_MS);
mToolbarFadeAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(ValueAnimator animator) {
if (targetToolbar == mDefaultToolbarView) {
currentToolbar.setAlpha(1f - animator.getAnimatedFraction());
} else {
targetToolbar.setAlpha(animator.getAnimatedFraction());
}
}
});
mToolbarFadeAnimator.addListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animation) {
targetToolbar.setAlpha(1f);
currentToolbar.setAlpha(0f);
if (currentToolbar != mDefaultToolbarView) {
mToolbarHolder.removeView(currentToolbar);
} else {
currentToolbar.setVisibility(View.GONE);
}
mToolbarFadeAnimator = null;
updateHandleTint();
}
});
return animatorSet;
mToolbarFadeAnimator.start();
}
/**
......
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