Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit c8afa5ce authored by Riley Jones's avatar Riley Jones
Browse files

Adds FAB animation skip on configuration change

If a configuration change occurs while a fling or spring animation is in progress,
skipping to the end of it should prevent the FAB from sticking in an unintended place.

Test: rotate the screen while the FAB is in motion. The FAB should end up at a reasonable position at side of the screen.
Bug: 344794208
Flag: EXEMPT small self-contained change
Change-Id: Ifb05e239e8b673ff737d72decb7d836f580613df
parent 195158b1
Loading
Loading
Loading
Loading
+24 −0
Original line number Diff line number Diff line
@@ -72,6 +72,7 @@ class MenuAnimationController {
    private final Handler mHandler;
    private boolean mIsFadeEffectEnabled;
    private Runnable mSpringAnimationsEndAction;
    private PointF mAnimationEndPosition = new PointF();

    // Cache the animations state of {@link DynamicAnimation.TRANSLATION_X} and {@link
    // DynamicAnimation.TRANSLATION_Y} to be well controlled by the touch handler
@@ -104,10 +105,12 @@ class MenuAnimationController {
                    @Override
                    public void onRadiiAnimationStop() {}
                });
        mAnimationEndPosition = mMenuView.getMenuPosition();
    }

    void moveToPosition(PointF position) {
        moveToPosition(position, /* animateMovement = */ false);
        mAnimationEndPosition = position;
    }

    /* Moves position without updating underlying percentage position. Can be animated. */
@@ -129,6 +132,7 @@ class MenuAnimationController {
        } else {
            DynamicAnimation.TRANSLATION_X.setValue(mMenuView, positionX);
        }
        mAnimationEndPosition.x = positionX;
    }

    void moveToPositionY(float positionY) {
@@ -144,6 +148,7 @@ class MenuAnimationController {
        } else {
            DynamicAnimation.TRANSLATION_Y.setValue(mMenuView, positionY);
        }
        mAnimationEndPosition.y = positionY;
    }

    void moveToPositionYIfNeeded(float positionY) {
@@ -259,6 +264,9 @@ class MenuAnimationController {

        cancelAnimation(property);
        mPositionAnimations.put(property, flingAnimation);
        if (finalPosition != null) {
            setAnimationEndPosition(property, finalPosition);
        }
        flingAnimation.start();
    }

@@ -292,6 +300,7 @@ class MenuAnimationController {

        cancelAnimation(property);
        mPositionAnimations.put(property, springAnimation);
        setAnimationEndPosition(property, finalPosition);
        springAnimation.animateToFinalPosition(finalPosition);
    }

@@ -385,6 +394,21 @@ class MenuAnimationController {
        mPositionAnimations.get(property).cancel();
    }

    private void setAnimationEndPosition(
            DynamicAnimation.ViewProperty property, Float endPosition) {
        if (property.equals(DynamicAnimation.TRANSLATION_X)) {
            mAnimationEndPosition.x = endPosition;
        }
        if (property.equals(DynamicAnimation.TRANSLATION_Y)) {
            mAnimationEndPosition.y = endPosition;
        }
    }

    void skipAnimations() {
        cancelAnimations();
        moveToPosition(mAnimationEndPosition, false);
    }

    @VisibleForTesting
    DynamicAnimation getAnimation(DynamicAnimation.ViewProperty property) {
        return mPositionAnimations.getOrDefault(property, null);
+1 −0
Original line number Diff line number Diff line
@@ -334,6 +334,7 @@ class MenuViewLayer extends FrameLayout implements
        mDragToInteractView.updateResources();
        mDismissView.updateResources();
        mDragToInteractAnimationController.updateResources();
        mMenuAnimationController.skipAnimations();
    }

    @Override