Merge "Polish bubble flyout fade transitions"

This commit is contained in:
Lyn Han
2020-10-20 22:40:12 +00:00
committed by Android (Google) Code Review

View File

@@ -61,7 +61,8 @@ public class BubbleFlyoutView extends FrameLayout {
/** Translation Y of fade animation. */
private static final float FLYOUT_FADE_Y = 40f;
private static final long FLYOUT_FADE_DURATION = 200L;
private static final long FLYOUT_FADE_OUT_DURATION = 150L;
private static final long FLYOUT_FADE_IN_DURATION = 250L;
private final int mFlyoutPadding;
private final int mFlyoutSpaceFromBubble;
@@ -235,26 +236,32 @@ public class BubbleFlyoutView extends FrameLayout {
* Fade animation for consecutive flyouts.
*/
void animateUpdate(Bubble.FlyoutMessage flyoutMessage, float parentWidth, float stackY) {
fade(false /* in */);
updateFlyoutMessage(flyoutMessage, parentWidth);
// Wait for TextViews to layout with updated height.
post(() -> {
mFlyoutY = stackY + (mBubbleSize - mFlyoutTextContainer.getHeight()) / 2f;
fade(true /* in */);
});
final Runnable afterFadeOut = () -> {
updateFlyoutMessage(flyoutMessage, parentWidth);
// Wait for TextViews to layout with updated height.
post(() -> {
mFlyoutY = stackY + (mBubbleSize - mFlyoutTextContainer.getHeight()) / 2f;
fade(true /* in */, () -> {} /* after */);
} /* after */ );
};
fade(false /* in */, afterFadeOut);
}
private void fade(boolean in) {
/*
* Fade-out above or fade-in from below.
*/
private void fade(boolean in, Runnable afterFade) {
setAlpha(in ? 0f : 1f);
setTranslationY(in ? mFlyoutY : mFlyoutY + FLYOUT_FADE_Y);
setTranslationY(in ? mFlyoutY + FLYOUT_FADE_Y : mFlyoutY);
animate()
.alpha(in ? 1f : 0f)
.setDuration(FLYOUT_FADE_DURATION)
.setDuration(in ? FLYOUT_FADE_IN_DURATION : FLYOUT_FADE_OUT_DURATION)
.setInterpolator(in ? ALPHA_IN : ALPHA_OUT);
animate()
.translationY(in ? mFlyoutY : mFlyoutY - FLYOUT_FADE_Y)
.setDuration(FLYOUT_FADE_DURATION)
.setInterpolator(in ? ALPHA_IN : ALPHA_OUT);
.setDuration(in ? FLYOUT_FADE_IN_DURATION : FLYOUT_FADE_OUT_DURATION)
.setInterpolator(in ? ALPHA_IN : ALPHA_OUT)
.withEndAction(afterFade);
}
private void updateFlyoutMessage(Bubble.FlyoutMessage flyoutMessage, float parentWidth) {