Merge "Add leadBubbleEndAction to expansion animation." into rvc-dev am: f51a85f60a

Change-Id: I62f986e7465e58150b22a404e9480660c25d41ed
This commit is contained in:
Josh Tsuji
2020-04-22 20:52:03 +00:00
committed by Automerger Merge Worker
2 changed files with 44 additions and 11 deletions

View File

@@ -128,15 +128,29 @@ public class ExpandedAnimationController
*/
private boolean mBubbleDraggedOutEnough = false;
/** End action to run when the lead bubble's expansion animation completes. */
@Nullable private Runnable mLeadBubbleEndAction;
/**
* Animates expanding the bubbles into a row along the top of the screen, optionally running an
* end action when the entire animation completes, and an end action when the lead bubble's
* animation ends.
*/
public void expandFromStack(
@Nullable Runnable after, @Nullable Runnable leadBubbleEndAction) {
mAnimatingCollapse = false;
mAnimatingExpand = true;
mAfterExpand = after;
mLeadBubbleEndAction = leadBubbleEndAction;
startOrUpdatePathAnimation(true /* expanding */);
}
/**
* Animates expanding the bubbles into a row along the top of the screen.
*/
public void expandFromStack(@Nullable Runnable after) {
mAnimatingCollapse = false;
mAnimatingExpand = true;
mAfterExpand = after;
startOrUpdatePathAnimation(true /* expanding */);
expandFromStack(after, null /* leadBubbleEndAction */);
}
/** Animate collapsing the bubbles back to their stacked position. */
@@ -237,11 +251,17 @@ public class ExpandedAnimationController
? (index * 10)
: ((mLayout.getChildCount() - index) * 10);
final boolean isLeadBubble =
(firstBubbleLeads && index == 0)
|| (!firstBubbleLeads && index == mLayout.getChildCount() - 1);
animation
.followAnimatedTargetAlongPath(
path,
EXPAND_COLLAPSE_TARGET_ANIM_DURATION /* targetAnimDuration */,
Interpolators.LINEAR /* targetAnimInterpolator */)
Interpolators.LINEAR /* targetAnimInterpolator */,
isLeadBubble ? mLeadBubbleEndAction : null /* endAction */,
() -> mLeadBubbleEndAction = null /* endAction */)
.withStartDelay(startDelay)
.withStiffness(EXPAND_COLLAPSE_ANIM_STIFFNESS);
}).startAll(after);

View File

@@ -758,21 +758,34 @@ public class PhysicsAnimationLayout extends FrameLayout {
* or {@link #position}, ultimately animating the view's position to the final point on the
* given path.
*
* Any provided end listeners will be called when the physics-based animations kicked off by
* the moving target have completed - not when the target animation completes.
* @param pathAnimEndActions End actions to run after the animator that moves the target
* along the path ends. The views following the target may still
* be moving.
*/
public PhysicsPropertyAnimator followAnimatedTargetAlongPath(
Path path,
int targetAnimDuration,
TimeInterpolator targetAnimInterpolator,
Runnable... endActions) {
Runnable... pathAnimEndActions) {
mPathAnimator = ObjectAnimator.ofFloat(
this, mCurrentPointOnPathXProperty, mCurrentPointOnPathYProperty, path);
if (pathAnimEndActions != null) {
mPathAnimator.addListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animation) {
for (Runnable action : pathAnimEndActions) {
if (action != null) {
action.run();
}
}
}
});
}
mPathAnimator.setDuration(targetAnimDuration);
mPathAnimator.setInterpolator(targetAnimInterpolator);
mPositionEndActions = endActions;
// Remove translation related values since we're going to ignore them and follow the
// path instead.
clearTranslationValues();