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

Commit ed85be92 authored by Matthew Ng's avatar Matthew Ng
Browse files

Add back recents staggering entrance animation

Since there was a change in ValueAnimator that did not allow setting
initial play time per interpolator grouped in an AnimatorSet, set the
initial play time for each animation to allow the same effect.

Change-Id: I05445bde6e185a99250d7d193bd0e74d5ce98fa0
Fixes: 36175824
Test: manual - launch recents
parent 25329fa1
Loading
Loading
Loading
Loading
+0 −30
Original line number Diff line number Diff line
@@ -54,7 +54,6 @@ public class AnimationProps {
    public static final int FOCUS_STATE = 8;

    private SparseLongArray mPropStartDelay;
    private SparseLongArray mPropInitialPlayTime;
    private SparseLongArray mPropDuration;
    private SparseArray<Interpolator> mPropInterpolators;
    private Animator.AnimatorListener mListener;
@@ -122,10 +121,6 @@ public class AnimationProps {
        animator.setStartDelay(getStartDelay(propertyType));
        animator.setDuration(getDuration(propertyType));
        animator.setInterpolator(getInterpolator(propertyType));
        long initialPlayTime = getInitialPlayTime(propertyType);
        if (initialPlayTime != 0) {
            animator.setCurrentPlayTime(initialPlayTime);
        }
        return animator;
    }

@@ -140,17 +135,6 @@ public class AnimationProps {
        return this;
    }

    /**
     * Sets a initial play time for a specific property.
     */
    public AnimationProps setInitialPlayTime(@PropType int propertyType, int initialPlayTime) {
        if (mPropInitialPlayTime == null) {
            mPropInitialPlayTime = new SparseLongArray();
        }
        mPropInitialPlayTime.append(propertyType, initialPlayTime);
        return this;
    }

    /**
     * Returns the start delay for a specific property.
     */
@@ -216,20 +200,6 @@ public class AnimationProps {
        return Interpolators.LINEAR;
    }

    /**
     * Returns the initial play time for a specific property, falling back to the general initial
     * play time if there is no specific property interpolator.
     */
    public long getInitialPlayTime(@PropType int propertyType) {
        if (mPropInitialPlayTime != null) {
            if (mPropInitialPlayTime.indexOfKey(propertyType) != -1) {
                return mPropInitialPlayTime.get(propertyType);
            }
            return mPropInitialPlayTime.get(ALL, 0);
        }
        return 0;
    }

    /**
     * Sets an animator listener for this animation.
     */
+47 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2017 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 com.android.systemui.recents.views;

import android.view.animation.PathInterpolator;

/**
 * A helper interpolator to stagger the entrance animation in recents by offsetting the start time
 */
public class RecentsEntrancePathInterpolator extends PathInterpolator {
    final float mStartOffsetFraction;

    /**
     * Create an interpolator for a cubic Bezier curve with an offset play time. The end points
     * <code>(0, 0)</code> and <code>(1, 1)</code> are assumed.
     *
     * @param controlX1 The x coordinate of the first control point of the cubic Bezier.
     * @param controlY1 The y coordinate of the first control point of the cubic Bezier.
     * @param controlX2 The x coordinate of the second control point of the cubic Bezier.
     * @param controlY2 The y coordinate of the second control point of the cubic Bezier.
     * @param startOffsetFraction The fraction from 0 to 1 to start the animation from
     */
    public RecentsEntrancePathInterpolator(float controlX1, float controlY1, float controlX2,
            float controlY2, float startOffsetFraction) {
        super(controlX1, controlY1, controlX2, controlY2);
        mStartOffsetFraction = startOffsetFraction;
    }

    @Override
    public float getInterpolation(float t) {
        return super.getInterpolation(t + mStartOffsetFraction);
    }
}
+5 −6
Original line number Diff line number Diff line
@@ -82,8 +82,6 @@ public class TaskStackAnimationHelper {

    private static final int ENTER_FROM_HOME_ALPHA_DURATION = 100;
    public static final int ENTER_FROM_HOME_TRANSLATION_DURATION = 300;
    private static final Interpolator ENTER_FROM_HOME_TRANSLATION_INTERPOLATOR =
            Interpolators.LINEAR_OUT_SLOW_IN;
    private static final Interpolator ENTER_FROM_HOME_ALPHA_INTERPOLATOR = Interpolators.LINEAR;

    public static final int EXIT_TO_HOME_TRANSLATION_DURATION = 200;
@@ -260,17 +258,18 @@ public class TaskStackAnimationHelper {
            } else if (launchState.launchedFromHome) {
                // Animate the tasks up, but offset the animations to be relative to the front-most
                // task animation
                final float startOffsetFraction = (float) (Math.min(ENTER_EXIT_NUM_ANIMATING_TASKS,
                        taskIndexFromFront) * mEnterAndExitFromHomeTranslationOffset) /
                        ENTER_FROM_HOME_TRANSLATION_DURATION;
                AnimationProps taskAnimation = new AnimationProps()
                        .setInitialPlayTime(AnimationProps.BOUNDS,
                                Math.min(ENTER_EXIT_NUM_ANIMATING_TASKS, taskIndexFromFront) *
                                        mEnterAndExitFromHomeTranslationOffset)
                        .setStartDelay(AnimationProps.ALPHA,
                                Math.min(ENTER_EXIT_NUM_ANIMATING_TASKS, taskIndexFromFront) *
                                        FRAME_OFFSET_MS)
                        .setDuration(AnimationProps.BOUNDS, ENTER_FROM_HOME_TRANSLATION_DURATION)
                        .setDuration(AnimationProps.ALPHA, ENTER_FROM_HOME_ALPHA_DURATION)
                        .setInterpolator(AnimationProps.BOUNDS,
                                ENTER_FROM_HOME_TRANSLATION_INTERPOLATOR)
                                new RecentsEntrancePathInterpolator(0f, 0f, 0.2f, 1f,
                                        startOffsetFraction))
                        .setInterpolator(AnimationProps.ALPHA, ENTER_FROM_HOME_ALPHA_INTERPOLATOR)
                        .setListener(postAnimationTrigger.decrementOnAnimationEnd());
                postAnimationTrigger.increment();