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

Commit 2be65d5d authored by Josh Tsuji's avatar Josh Tsuji Committed by Automerger Merge Worker
Browse files

Merge "Add configurable physics settings for UX refinement." into rvc-dev am: 54b0b93f

Change-Id: I1b9e267f84d1541294ec22c17dc358c6f661d969
parents cff16409 54b0b93f
Loading
Loading
Loading
Loading
+7 −1
Original line number Original line Diff line number Diff line
@@ -32,6 +32,7 @@ import android.animation.AnimatorListenerAdapter;
import android.animation.ValueAnimator;
import android.animation.ValueAnimator;
import android.annotation.SuppressLint;
import android.annotation.SuppressLint;
import android.app.Notification;
import android.app.Notification;
import android.content.ContentResolver;
import android.content.Context;
import android.content.Context;
import android.content.Intent;
import android.content.Intent;
import android.content.res.Configuration;
import android.content.res.Configuration;
@@ -49,6 +50,7 @@ import android.graphics.RectF;
import android.graphics.Region;
import android.graphics.Region;
import android.os.Bundle;
import android.os.Bundle;
import android.os.Vibrator;
import android.os.Vibrator;
import android.provider.Settings;
import android.service.notification.StatusBarNotification;
import android.service.notification.StatusBarNotification;
import android.util.Log;
import android.util.Log;
import android.view.Choreographer;
import android.view.Choreographer;
@@ -763,9 +765,13 @@ public class BubbleStackView extends FrameLayout
        targetView.setTranslationY(
        targetView.setTranslationY(
                getResources().getDimensionPixelSize(R.dimen.floating_dismiss_gradient_height));
                getResources().getDimensionPixelSize(R.dimen.floating_dismiss_gradient_height));


        final ContentResolver contentResolver = getContext().getContentResolver();
        final int dismissRadius = Settings.Secure.getInt(
                contentResolver, "bubble_dismiss_radius", mBubbleSize * 2 /* default */);

        // Save the MagneticTarget instance for the newly set up view - we'll add this to the
        // Save the MagneticTarget instance for the newly set up view - we'll add this to the
        // MagnetizedObjects.
        // MagnetizedObjects.
        mMagneticTarget = new MagnetizedObject.MagneticTarget(targetView, mBubbleSize * 2);
        mMagneticTarget = new MagnetizedObject.MagneticTarget(targetView, dismissRadius);


        mExpandedViewXAnim =
        mExpandedViewXAnim =
                new SpringAnimation(mExpandedViewContainer, DynamicAnimation.TRANSLATION_X);
                new SpringAnimation(mExpandedViewContainer, DynamicAnimation.TRANSLATION_X);
+44 −12
Original line number Original line Diff line number Diff line
@@ -16,10 +16,12 @@


package com.android.systemui.bubbles.animation;
package com.android.systemui.bubbles.animation;


import android.content.ContentResolver;
import android.content.res.Resources;
import android.content.res.Resources;
import android.graphics.PointF;
import android.graphics.PointF;
import android.graphics.Rect;
import android.graphics.Rect;
import android.graphics.RectF;
import android.graphics.RectF;
import android.provider.Settings;
import android.util.Log;
import android.util.Log;
import android.view.View;
import android.view.View;
import android.view.WindowInsets;
import android.view.WindowInsets;
@@ -83,8 +85,7 @@ public class StackAnimationController extends
     * screen, we want less friction horizontally so that the stack has a better chance of making it
     * screen, we want less friction horizontally so that the stack has a better chance of making it
     * to the side without needing a spring.
     * to the side without needing a spring.
     */
     */
    private static final float FLING_FRICTION_X = 2.2f;
    private static final float FLING_FRICTION = 2.2f;
    private static final float FLING_FRICTION_Y = 2.2f;


    /**
    /**
     * Values to use for the stack spring animation used to spring the stack to its final position
     * Values to use for the stack spring animation used to spring the stack to its final position
@@ -363,18 +364,26 @@ public class StackAnimationController extends
            return destinationRelativeX;
            return destinationRelativeX;
        }
        }


        final ContentResolver contentResolver = mLayout.getContext().getContentResolver();
        final float stiffness = Settings.Secure.getFloat(contentResolver, "bubble_stiffness",
                SPRING_AFTER_FLING_STIFFNESS /* default */);
        final float dampingRatio = Settings.Secure.getFloat(contentResolver, "bubble_damping",
                SPRING_AFTER_FLING_DAMPING_RATIO);
        final float friction = Settings.Secure.getFloat(contentResolver, "bubble_friction",
                FLING_FRICTION);

        // Minimum velocity required for the stack to make it to the targeted side of the screen,
        // Minimum velocity required for the stack to make it to the targeted side of the screen,
        // taking friction into account (4.2f is the number that friction scalars are multiplied by
        // taking friction into account (4.2f is the number that friction scalars are multiplied by
        // in DynamicAnimation.DragForce). This is an estimate - it could possibly be slightly off,
        // in DynamicAnimation.DragForce). This is an estimate - it could possibly be slightly off,
        // but the SpringAnimation at the end will ensure that it reaches the destination X
        // but the SpringAnimation at the end will ensure that it reaches the destination X
        // regardless.
        // regardless.
        final float minimumVelocityToReachEdge =
        final float minimumVelocityToReachEdge =
                (destinationRelativeX - x) * (FLING_FRICTION_X * 4.2f);
                (destinationRelativeX - x) * (friction * 4.2f);


        final float estimatedY = PhysicsAnimator.estimateFlingEndValue(
        final float estimatedY = PhysicsAnimator.estimateFlingEndValue(
                mStackPosition.y, velY,
                mStackPosition.y, velY,
                new PhysicsAnimator.FlingConfig(
                new PhysicsAnimator.FlingConfig(
                        FLING_FRICTION_Y, stackBounds.top, stackBounds.bottom));
                        friction, stackBounds.top, stackBounds.bottom));


        notifyFloatingCoordinatorStackAnimatingTo(destinationRelativeX, estimatedY);
        notifyFloatingCoordinatorStackAnimatingTo(destinationRelativeX, estimatedY);


@@ -384,22 +393,24 @@ public class StackAnimationController extends
                ? Math.min(minimumVelocityToReachEdge, velX)
                ? Math.min(minimumVelocityToReachEdge, velX)
                : Math.max(minimumVelocityToReachEdge, velX);
                : Math.max(minimumVelocityToReachEdge, velX);




        flingThenSpringFirstBubbleWithStackFollowing(
        flingThenSpringFirstBubbleWithStackFollowing(
                DynamicAnimation.TRANSLATION_X,
                DynamicAnimation.TRANSLATION_X,
                startXVelocity,
                startXVelocity,
                FLING_FRICTION_X,
                friction,
                new SpringForce()
                new SpringForce()
                        .setStiffness(SPRING_AFTER_FLING_STIFFNESS)
                        .setStiffness(stiffness)
                        .setDampingRatio(SPRING_AFTER_FLING_DAMPING_RATIO),
                        .setDampingRatio(dampingRatio),
                destinationRelativeX);
                destinationRelativeX);


        flingThenSpringFirstBubbleWithStackFollowing(
        flingThenSpringFirstBubbleWithStackFollowing(
                DynamicAnimation.TRANSLATION_Y,
                DynamicAnimation.TRANSLATION_Y,
                velY,
                velY,
                FLING_FRICTION_Y,
                friction,
                new SpringForce()
                new SpringForce()
                        .setStiffness(SPRING_AFTER_FLING_STIFFNESS)
                        .setStiffness(stiffness)
                        .setDampingRatio(SPRING_AFTER_FLING_DAMPING_RATIO),
                        .setDampingRatio(dampingRatio),
                /* destination */ null);
                /* destination */ null);


        // If we're flinging now, there's no more touch event to catch up to.
        // If we're flinging now, there's no more touch event to catch up to.
@@ -761,9 +772,15 @@ public class StackAnimationController extends


    @Override
    @Override
    SpringForce getSpringForce(DynamicAnimation.ViewProperty property, View view) {
    SpringForce getSpringForce(DynamicAnimation.ViewProperty property, View view) {
        final ContentResolver contentResolver = mLayout.getContext().getContentResolver();
        final float stiffness = Settings.Secure.getFloat(contentResolver, "bubble_stiffness",
                mIsMovingFromFlinging ? FLING_FOLLOW_STIFFNESS : DEFAULT_STIFFNESS /* default */);
        final float dampingRatio = Settings.Secure.getFloat(contentResolver, "bubble_damping",
                DEFAULT_BOUNCINESS);

        return new SpringForce()
        return new SpringForce()
                .setDampingRatio(DEFAULT_BOUNCINESS)
                .setDampingRatio(dampingRatio)
                .setStiffness(mIsMovingFromFlinging ? FLING_FOLLOW_STIFFNESS : DEFAULT_STIFFNESS);
                .setStiffness(stiffness);
    }
    }


    @Override
    @Override
@@ -1011,6 +1028,21 @@ public class StackAnimationController extends
            mMagnetizedStack.setFlingToTargetMinVelocity(FLING_TO_DISMISS_MIN_VELOCITY);
            mMagnetizedStack.setFlingToTargetMinVelocity(FLING_TO_DISMISS_MIN_VELOCITY);
        }
        }


        final ContentResolver contentResolver = mLayout.getContext().getContentResolver();
        final float minVelocity = Settings.Secure.getFloat(contentResolver,
                "bubble_dismiss_fling_min_velocity",
                mMagnetizedStack.getFlingToTargetMinVelocity() /* default */);
        final float maxVelocity = Settings.Secure.getFloat(contentResolver,
                "bubble_dismiss_stick_max_velocity",
                mMagnetizedStack.getStickToTargetMaxVelocity() /* default */);
        final float targetWidth = Settings.Secure.getFloat(contentResolver,
                "bubble_dismiss_target_width_percent",
                mMagnetizedStack.getFlingToTargetWidthPercent() /* default */);

        mMagnetizedStack.setFlingToTargetMinVelocity(minVelocity);
        mMagnetizedStack.setStickToTargetMaxVelocity(maxVelocity);
        mMagnetizedStack.setFlingToTargetWidthPercent(targetWidth);

        return mMagnetizedStack;
        return mMagnetizedStack;
    }
    }