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

Commit cf0e5eb9 authored by mpodolian's avatar mpodolian
Browse files

Added elevation animation for dragged bubble snapped back to the stack

Added Z animation for PhysicsAnimationLayout, so when bubble is being
dropped, it returns to it`s stack position reducing elevation to flat
state.

Test: PhysicsAnimationLayoutTest
Fixes: 301266186
Flag: N/A
Change-Id: Id179de36348ed0f056a18cda53e3db5dc32cb4ae
parent 51749341
Loading
Loading
Loading
Loading
+3 −2
Original line number Diff line number Diff line
@@ -468,9 +468,9 @@ public class ExpandedAnimationController
        final int index = mLayout.indexOfChild(bubbleView);
        final PointF p = mPositioner.getExpandedBubbleXY(index, mBubbleStackView.getState());
        animationForChildAtIndex(index)
                .position(p.x, p.y)
                .position(p.x, p.y, /* translationZ= */ 0f)
                .withPositionStartVelocities(velX, velY)
                .start(() -> bubbleView.setTranslationZ(0f) /* after */);
                .start();

        mMagnetizedBubbleDraggingOut = null;

@@ -509,6 +509,7 @@ public class ExpandedAnimationController
        return Sets.newHashSet(
                DynamicAnimation.TRANSLATION_X,
                DynamicAnimation.TRANSLATION_Y,
                DynamicAnimation.TRANSLATION_Z,
                DynamicAnimation.SCALE_X,
                DynamicAnimation.SCALE_Y,
                DynamicAnimation.ALPHA);
+37 −14
Original line number Diff line number Diff line
@@ -419,7 +419,8 @@ public class PhysicsAnimationLayout extends FrameLayout {
            // be animating in this case, even if the physics animations haven't been started yet.
            final boolean isTranslation =
                    property.equals(DynamicAnimation.TRANSLATION_X)
                            || property.equals(DynamicAnimation.TRANSLATION_Y);
                            || property.equals(DynamicAnimation.TRANSLATION_Y)
                            || property.equals(DynamicAnimation.TRANSLATION_Z);
            if (isTranslation && targetAnimator != null && targetAnimator.isRunning()) {
                return true;
            }
@@ -495,6 +496,8 @@ public class PhysicsAnimationLayout extends FrameLayout {
            return "TRANSLATION_X";
        } else if (property.equals(DynamicAnimation.TRANSLATION_Y)) {
            return "TRANSLATION_Y";
        } else if (property.equals(DynamicAnimation.TRANSLATION_Z)) {
            return "TRANSLATION_Z";
        } else if (property.equals(DynamicAnimation.SCALE_X)) {
            return "SCALE_X";
        } else if (property.equals(DynamicAnimation.SCALE_Y)) {
@@ -598,6 +601,8 @@ public class PhysicsAnimationLayout extends FrameLayout {
            return R.id.translation_x_dynamicanimation_tag;
        } else if (property.equals(DynamicAnimation.TRANSLATION_Y)) {
            return R.id.translation_y_dynamicanimation_tag;
        } else if (property.equals(DynamicAnimation.TRANSLATION_Z)) {
            return R.id.translation_z_dynamicanimation_tag;
        } else if (property.equals(DynamicAnimation.SCALE_X)) {
            return R.id.scale_x_dynamicanimation_tag;
        } else if (property.equals(DynamicAnimation.SCALE_Y)) {
@@ -763,6 +768,12 @@ public class PhysicsAnimationLayout extends FrameLayout {
            return property(DynamicAnimation.TRANSLATION_X, translationX, endActions);
        }

        /** Animate the view's translationZ value to the provided value. */
        public PhysicsPropertyAnimator translationZ(float translationZ, Runnable... endActions) {
            mPathAnimator = null; // We aren't using the path anymore if we're translating.
            return property(DynamicAnimation.TRANSLATION_Z, translationZ, endActions);
        }

        /** Set the view's translationX value to 'from', then animate it to the given value. */
        public PhysicsPropertyAnimator translationX(
                float from, float to, Runnable... endActions) {
@@ -785,13 +796,14 @@ public class PhysicsAnimationLayout extends FrameLayout {

        /**
         * Animate the view's translationX and translationY values, and call the end actions only
         * once both TRANSLATION_X and TRANSLATION_Y animations have completed.
         * once both TRANSLATION_X, TRANSLATION_Y and TRANSLATION_Z animations have completed.
         */
        public PhysicsPropertyAnimator position(
                float translationX, float translationY, Runnable... endActions) {
        public PhysicsPropertyAnimator position(float translationX, float translationY,
                float translationZ, Runnable... endActions) {
            mPositionEndActions = endActions;
            translationX(translationX);
            return translationY(translationY);
            translationY(translationY);
            return translationZ(translationZ);
        }

        /**
@@ -845,10 +857,13 @@ public class PhysicsAnimationLayout extends FrameLayout {
        private void clearTranslationValues() {
            mAnimatedProperties.remove(DynamicAnimation.TRANSLATION_X);
            mAnimatedProperties.remove(DynamicAnimation.TRANSLATION_Y);
            mAnimatedProperties.remove(DynamicAnimation.TRANSLATION_Z);
            mInitialPropertyValues.remove(DynamicAnimation.TRANSLATION_X);
            mInitialPropertyValues.remove(DynamicAnimation.TRANSLATION_Y);
            mInitialPropertyValues.remove(DynamicAnimation.TRANSLATION_Z);
            mEndActionForProperty.remove(DynamicAnimation.TRANSLATION_X);
            mEndActionForProperty.remove(DynamicAnimation.TRANSLATION_Y);
            mEndActionForProperty.remove(DynamicAnimation.TRANSLATION_Z);
        }

        /** Animate the view's scaleX value to the provided value. */
@@ -939,15 +954,19 @@ public class PhysicsAnimationLayout extends FrameLayout {
                }, propertiesArray);
            }

            // If we used position-specific end actions, we'll need to listen for both TRANSLATION_X
            // and TRANSLATION_Y animations ending, and call them once both have finished.
            // If we used position-specific end actions, we'll need to listen for TRANSLATION_X
            // TRANSLATION_Y and TRANSLATION_Z animations ending, and call them once both have
            // finished.
            if (mPositionEndActions != null) {
                final SpringAnimation translationXAnim =
                        getSpringAnimationFromView(DynamicAnimation.TRANSLATION_X, mView);
                final SpringAnimation translationYAnim =
                        getSpringAnimationFromView(DynamicAnimation.TRANSLATION_Y, mView);
                final Runnable waitForBothXAndY = () -> {
                    if (!translationXAnim.isRunning() && !translationYAnim.isRunning()) {
                final SpringAnimation translationZAnim =
                        getSpringAnimationFromView(DynamicAnimation.TRANSLATION_Z, mView);
                final Runnable waitForXYZ = () -> {
                    if (!translationXAnim.isRunning() && !translationYAnim.isRunning()
                            && !translationZAnim.isRunning()) {
                        if (mPositionEndActions != null) {
                            for (Runnable callback : mPositionEndActions) {
                                callback.run();
@@ -959,9 +978,11 @@ public class PhysicsAnimationLayout extends FrameLayout {
                };

                mEndActionsForProperty.put(DynamicAnimation.TRANSLATION_X,
                        new Runnable[]{waitForBothXAndY});
                        new Runnable[]{waitForXYZ});
                mEndActionsForProperty.put(DynamicAnimation.TRANSLATION_Y,
                        new Runnable[]{waitForBothXAndY});
                        new Runnable[]{waitForXYZ});
                mEndActionsForProperty.put(DynamicAnimation.TRANSLATION_Z,
                        new Runnable[]{waitForXYZ});
            }

            if (mPathAnimator != null) {
@@ -972,9 +993,10 @@ public class PhysicsAnimationLayout extends FrameLayout {
            for (DynamicAnimation.ViewProperty property : properties) {
                // Don't start translation animations if we're using a path animator, the update
                // listeners added to that animator will take care of that.
                if (mPathAnimator != null
                        && (property.equals(DynamicAnimation.TRANSLATION_X)
                            || property.equals(DynamicAnimation.TRANSLATION_Y))) {
                boolean isTranslationProperty = property.equals(DynamicAnimation.TRANSLATION_X)
                        || property.equals(DynamicAnimation.TRANSLATION_Y)
                        || property.equals(DynamicAnimation.TRANSLATION_Z);
                if (mPathAnimator != null && isTranslationProperty) {
                    return;
                }

@@ -1006,6 +1028,7 @@ public class PhysicsAnimationLayout extends FrameLayout {
            if (mPathAnimator != null) {
                animatedProperties.add(DynamicAnimation.TRANSLATION_X);
                animatedProperties.add(DynamicAnimation.TRANSLATION_Y);
                animatedProperties.add(DynamicAnimation.TRANSLATION_Z);
            }

            return animatedProperties;
+12 −5
Original line number Diff line number Diff line
@@ -69,7 +69,8 @@ public class PhysicsAnimationLayoutTest extends PhysicsAnimationLayoutTestCase {
        // to animate child views out before actually removing them).
        mTestableController.setAnimatedProperties(Sets.newHashSet(
                DynamicAnimation.TRANSLATION_X,
                DynamicAnimation.TRANSLATION_Y));
                DynamicAnimation.TRANSLATION_Y,
                DynamicAnimation.TRANSLATION_Z));
        mTestableController.setChainedProperties(Sets.newHashSet(DynamicAnimation.TRANSLATION_X));
        mTestableController.setOffsetForProperty(
                DynamicAnimation.TRANSLATION_X, TEST_TRANSLATION_X_OFFSET);
@@ -282,10 +283,13 @@ public class PhysicsAnimationLayoutTest extends PhysicsAnimationLayoutTestCase {
        addOneMoreThanBubbleLimitBubbles();

        assertFalse(mLayout.arePropertiesAnimating(
                DynamicAnimation.TRANSLATION_X, DynamicAnimation.TRANSLATION_Y));
                DynamicAnimation.TRANSLATION_X,
                DynamicAnimation.TRANSLATION_Y,
                DynamicAnimation.TRANSLATION_Z));

        mTestableController.animationForChildAtIndex(0)
                .translationX(100f)
                .translationZ(100f)
                .start();

        // Wait for the animations to get underway.
@@ -293,11 +297,13 @@ public class PhysicsAnimationLayoutTest extends PhysicsAnimationLayoutTestCase {

        assertTrue(mLayout.arePropertiesAnimating(DynamicAnimation.TRANSLATION_X));
        assertFalse(mLayout.arePropertiesAnimating(DynamicAnimation.TRANSLATION_Y));
        assertTrue(mLayout.arePropertiesAnimating(DynamicAnimation.TRANSLATION_Z));

        waitForPropertyAnimations(DynamicAnimation.TRANSLATION_X);
        waitForPropertyAnimations(DynamicAnimation.TRANSLATION_X, DynamicAnimation.TRANSLATION_Z);

        assertFalse(mLayout.arePropertiesAnimating(
                DynamicAnimation.TRANSLATION_X, DynamicAnimation.TRANSLATION_Y));
                DynamicAnimation.TRANSLATION_X, DynamicAnimation.TRANSLATION_Y,
                DynamicAnimation.TRANSLATION_Z));
    }

    @Test
@@ -307,7 +313,7 @@ public class PhysicsAnimationLayoutTest extends PhysicsAnimationLayoutTestCase {
        addOneMoreThanBubbleLimitBubbles();

        mTestableController.animationForChildAtIndex(0)
                .position(1000, 1000)
                .position(1000, 1000, 1000)
                .start();

        mLayout.cancelAllAnimations();
@@ -315,6 +321,7 @@ public class PhysicsAnimationLayoutTest extends PhysicsAnimationLayoutTestCase {
        // Animations should be somewhere before their end point.
        assertTrue(mViews.get(0).getTranslationX() < 1000);
        assertTrue(mViews.get(0).getTranslationY() < 1000);
        assertTrue(mViews.get(0).getZ() < 10000);
    }

    /** Standard test of chained translation animations. */