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

Commit 49ee541b authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Tune swipe up resistance" into sc-v2-dev

parents 874d9aff 26a5f7f8
Loading
Loading
Loading
Loading
+31 −18
Original line number Diff line number Diff line
@@ -48,15 +48,16 @@ import com.android.quickstep.views.RecentsView;
public class AnimatorControllerWithResistance {

    private enum RecentsResistanceParams {
        FROM_APP(0.75f, 0.5f, 1f),
        FROM_APP_TABLET(0.9f, 0.75f, 1f),
        FROM_OVERVIEW(1f, 0.75f, 0.5f);
        FROM_APP(0.75f, 0.5f, 1f, false),
        FROM_APP_TABLET(1f, 0.7f, 1f, true),
        FROM_OVERVIEW(1f, 0.75f, 0.5f, false);

        RecentsResistanceParams(float scaleStartResist, float scaleMaxResist,
                float translationFactor) {
                float translationFactor, boolean stopScalingAtTop) {
            this.scaleStartResist = scaleStartResist;
            this.scaleMaxResist = scaleMaxResist;
            this.translationFactor = translationFactor;
            this.stopScalingAtTop = stopScalingAtTop;
        }

        /**
@@ -74,6 +75,12 @@ public class AnimatorControllerWithResistance {
         * where 0 will keep it centered and 1 will have it barely touch the top of the screen.
         */
        public final float translationFactor;

        /**
         * Whether to end scaling effect when the scaled down version of TaskView's top reaches the
         * non-scaled version of TaskView's top.
         */
        public final boolean stopScalingAtTop;
    }

    private static final TimeInterpolator RECENTS_SCALE_RESIST_INTERPOLATOR = DEACCEL;
@@ -161,6 +168,20 @@ public class AnimatorControllerWithResistance {
        PointF pivot = new PointF();
        float fullscreenScale = params.recentsOrientedState.getFullScreenScaleAndPivot(
                startRect, params.dp, pivot);

        // Compute where the task view would be based on the end scale.
        RectF endRectF = new RectF(startRect);
        Matrix temp = new Matrix();
        temp.setScale(params.resistanceParams.scaleMaxResist,
                params.resistanceParams.scaleMaxResist, pivot.x, pivot.y);
        temp.mapRect(endRectF);
        // Translate such that the task view touches the top of the screen when drag does.
        float endTranslation = endRectF.top
                * orientationHandler.getSecondaryTranslationDirectionFactor()
                * params.resistanceParams.translationFactor;
        resistAnim.addFloat(params.translationTarget, params.translationProperty,
                params.startTranslation, endTranslation, RECENTS_TRANSLATE_RESIST_INTERPOLATOR);

        float prevScaleRate = (fullscreenScale - params.startScale)
                / (params.dp.heightPx - startRect.bottom);
        // This is what the scale would be at the end of the drag if we didn't apply resistance.
@@ -171,30 +192,22 @@ public class AnimatorControllerWithResistance {
                params.startScale, endScale);
        float maxResist = Utilities.getProgress(params.resistanceParams.scaleMaxResist,
                params.startScale, endScale);
        float stopResist =
                params.resistanceParams.stopScalingAtTop ? 1f - startRect.top / endRectF.top : 1f;
        final TimeInterpolator scaleInterpolator = t -> {
            if (t < startResist) {
                return t;
            }
            float resistProgress = Utilities.getProgress(t, startResist, 1);
            if (t > stopResist) {
                return maxResist;
            }
            float resistProgress = Utilities.getProgress(t, startResist, stopResist);
            resistProgress = RECENTS_SCALE_RESIST_INTERPOLATOR.getInterpolation(resistProgress);
            return startResist + resistProgress * (maxResist - startResist);
        };
        resistAnim.addFloat(params.scaleTarget, params.scaleProperty, params.startScale, endScale,
                scaleInterpolator);

        // Compute where the task view would be based on the end scale.
        RectF endRectF = new RectF(startRect);
        Matrix temp = new Matrix();
        temp.setScale(params.resistanceParams.scaleMaxResist,
                params.resistanceParams.scaleMaxResist, pivot.x, pivot.y);
        temp.mapRect(endRectF);
        // Translate such that the task view touches the top of the screen when drag does.
        float endTranslation = endRectF.top
                * orientationHandler.getSecondaryTranslationDirectionFactor()
                * params.resistanceParams.translationFactor;
        resistAnim.addFloat(params.translationTarget, params.translationProperty,
                params.startTranslation, endTranslation, RECENTS_TRANSLATE_RESIST_INTERPOLATOR);

        return resistAnim;
    }