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

Commit e6adb4d8 authored by Johannes Gallmann's avatar Johannes Gallmann
Browse files

Use custom interpolator for predictive back system animations

Bug: 332512902
Flag: ACONFIG com.android.window.flags.predictive_back_system_anims TRUNKFOOD
Test: Manual, i.e. analysing screenrecordings and verify that there are no more animation jumps at the start/end of the back animation
Change-Id: Iaa84952ebce1ed0391a5db712630edef69f32b94
parent ef54218e
Loading
Loading
Loading
Loading
+3 −2
Original line number Diff line number Diff line
@@ -28,6 +28,7 @@ import android.annotation.NonNull;
import android.annotation.Nullable;
import android.graphics.Insets;
import android.util.Log;
import android.view.animation.BackGestureInterpolator;
import android.view.animation.Interpolator;
import android.view.animation.PathInterpolator;
import android.window.BackEvent;
@@ -44,7 +45,7 @@ public class ImeBackAnimationController implements OnBackAnimationCallback {
    private static final int POST_COMMIT_DURATION_MS = 200;
    private static final int POST_COMMIT_CANCEL_DURATION_MS = 50;
    private static final float PEEK_FRACTION = 0.1f;
    private static final Interpolator STANDARD_DECELERATE = new PathInterpolator(0f, 0f, 0f, 1f);
    private static final Interpolator BACK_GESTURE = new BackGestureInterpolator();
    private static final Interpolator EMPHASIZED_DECELERATE = new PathInterpolator(
            0.05f, 0.7f, 0.1f, 1f);
    private static final Interpolator STANDARD_ACCELERATE = new PathInterpolator(0.3f, 0f, 1f, 1f);
@@ -140,7 +141,7 @@ public class ImeBackAnimationController implements OnBackAnimationCallback {
            float hiddenY = mWindowInsetsAnimationController.getHiddenStateInsets().bottom;
            float shownY = mWindowInsetsAnimationController.getShownStateInsets().bottom;
            float imeHeight = shownY - hiddenY;
            float interpolatedProgress = STANDARD_DECELERATE.getInterpolation(progress);
            float interpolatedProgress = BACK_GESTURE.getInterpolation(progress);
            int newY = (int) (imeHeight - interpolatedProgress * (imeHeight * PEEK_FRACTION));
            mWindowInsetsAnimationController.setInsetsAndAlpha(Insets.of(0, 0, 0, newY), 1f,
                    progress);
+26 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2024 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package android.view.animation;
/**
 * Decelerating interpolator with a very slight acceleration phase at the beginning.
 * @hide
 */
public class BackGestureInterpolator extends PathInterpolator {
    public BackGestureInterpolator() {
        super(0.1f, 0.1f, 0f, 1f);
    }
}
+10 −0
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@
package com.android.wm.shell.animation;

import android.graphics.Path;
import android.view.animation.BackGestureInterpolator;
import android.view.animation.Interpolator;
import android.view.animation.LinearInterpolator;
import android.view.animation.PathInterpolator;
@@ -95,6 +96,15 @@ public class Interpolators {
    public static final PathInterpolator DIM_INTERPOLATOR =
            new PathInterpolator(.23f, .87f, .52f, -0.11f);

    /**
     * Use this interpolator for animating progress values coming from the back callback to get
     * the predictive-back-typical decelerate motion.
     *
     * This interpolator is similar to {@link Interpolators#STANDARD_DECELERATE} but has a slight
     * acceleration phase at the start.
     */
    public static final Interpolator BACK_GESTURE = new BackGestureInterpolator();

    // Create the default emphasized interpolator
    private static PathInterpolator createEmphasizedInterpolator() {
        Path path = new Path();
+2 −2
Original line number Diff line number Diff line
@@ -86,7 +86,7 @@ class CrossActivityBackAnimation @Inject constructor(
    private val enteringStartOffset =
        context.resources.getDimension(R.dimen.cross_activity_back_entering_start_offset)

    private val gestureInterpolator = Interpolators.STANDARD_DECELERATE
    private val gestureInterpolator = Interpolators.BACK_GESTURE
    private val postCommitInterpolator = Interpolators.FAST_OUT_SLOW_IN
    private val verticalMoveInterpolator: Interpolator = DecelerateInterpolator()

@@ -287,7 +287,7 @@ class CrossActivityBackAnimation @Inject constructor(
            // in case we're still animating an onBackCancelled event, let's remove the finish-
            // callback from the progress animator to prevent calling finishAnimation() before
            // restarting a new animation
            progressAnimator.removeOnBackCancelledFinishCallback();
            progressAnimator.removeOnBackCancelledFinishCallback()

            startBackAnimation(backMotionEvent)
            progressAnimator.onBackStarted(backMotionEvent) { backEvent: BackEvent ->
+1 −1
Original line number Diff line number Diff line
@@ -91,7 +91,7 @@ public class CrossTaskBackAnimation extends ShellBackAnimation {

    private final PointF mInitialTouchPos = new PointF();
    private final Interpolator mPostAnimationInterpolator = Interpolators.EMPHASIZED;
    private final Interpolator mProgressInterpolator = Interpolators.STANDARD_DECELERATE;
    private final Interpolator mProgressInterpolator = Interpolators.BACK_GESTURE;
    private final Interpolator mVerticalMoveInterpolator = new DecelerateInterpolator();
    private final Matrix mTransformMatrix = new Matrix();