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

Commit feb31ca5 authored by Josh Tsuji's avatar Josh Tsuji
Browse files

Add the staggered ring appear animation!

Bug: 197636896
Test: a lot of unlocking
Change-Id: I9a713ac12eae5128d409166110cece0b86d89ae4
parent 69066115
Loading
Loading
Loading
Loading
+0 −83
Original line number Diff line number Diff line
/*
 * Copyright (C) 2021 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.quickstep.util;

import com.android.launcher3.Launcher;
import com.android.launcher3.Utilities;

/**
 * Animation to animate in a workspace during the unlock transition.
 */
// TODO(b/219444608): use SCALE_PROPERTY_FACTORY once the scale is reset to 1.0 after unlocking.
public class WorkspaceUnlockAnim {
    /** Scale for the workspace icons at the beginning of the animation. */
    private static final float START_SCALE = 0.9f;

    /**
     * Starting translation Y values for the animation. We use a larger value if we're animating in
     * from a swipe, since there is more perceived upward movement when we unlock from a swipe.
     */
    private static final int START_TRANSLATION_DP = 15;
    private static final int START_TRANSLATION_SWIPE_DP = 60;

    private Launcher mLauncher;
    private float mUnlockAmount = 0f;

    public WorkspaceUnlockAnim(Launcher launcher) {
        mLauncher = launcher;
    }

    /**
     * Called when we're about to make the Launcher window visible and play the unlock animation.
     *
     * This is a blocking call so that System UI knows it's safe to show the Launcher window without
     * causing the Launcher contents to flicker on screen. Do not do anything expensive here.
     */
    public void prepareForUnlock() {
        mLauncher.getWorkspace().setAlpha(0f);
        mLauncher.getHotseat().setAlpha(0f);

        mUnlockAmount = 0f;
    }

    public void setUnlockAmount(float amount, boolean fromSwipe) {
        mUnlockAmount = amount;

        final float amountInverse = 1f - amount;
        final float scale = START_SCALE + (1f - START_SCALE) * amount;

        mLauncher.getWorkspace().setScaleX(scale);
        mLauncher.getWorkspace().setScaleY(scale);
        mLauncher.getWorkspace().setAlpha(amount);
        mLauncher.getWorkspace().setPivotToScaleWithSelf(mLauncher.getHotseat());

        mLauncher.getHotseat().setScaleX(scale);
        mLauncher.getHotseat().setScaleY(scale);
        mLauncher.getHotseat().setAlpha(amount);

        if (fromSwipe) {
            mLauncher.getWorkspace().setTranslationY(
                    Utilities.dpToPx(START_TRANSLATION_SWIPE_DP) * amountInverse);
            mLauncher.getHotseat().setTranslationY(
                    Utilities.dpToPx(START_TRANSLATION_SWIPE_DP) * amountInverse);
        } else {
            mLauncher.getWorkspace().setTranslationY(
                    Utilities.dpToPx(START_TRANSLATION_DP) * amountInverse);
            mLauncher.getHotseat().setTranslationY(
                    Utilities.dpToPx(START_TRANSLATION_DP) * amountInverse);
        }
    }
}
+34 −14
Original line number Diff line number Diff line
@@ -47,6 +47,13 @@ public class Interpolators {
    public static final Interpolator DEACCEL_2_5 = new DecelerateInterpolator(2.5f);
    public static final Interpolator DEACCEL_3 = new DecelerateInterpolator(3f);

    /**
     * The decelerating emphasized interpolator. Used for hero / emphasized movement of content that
     * is appearing e.g. when coming from off screen
     */
    public static final Interpolator EMPHASIZED_DECELERATE = new PathInterpolator(
            0.05f, 0.7f, 0.1f, 1f);

    public static final Interpolator ACCEL_DEACCEL = new AccelerateDecelerateInterpolator();

    public static final Interpolator FAST_OUT_SLOW_IN = new PathInterpolator(0.4f, 0f, 0.2f, 1f);
@@ -162,8 +169,9 @@ public class Interpolators {
    }

    /**
     * Runs the given interpolator such that the entire progress is set between the given bounds.
     * That is, we set the interpolation to 0 until lowerBound and reach 1 by upperBound.
     * Returns a function that runs the given interpolator such that the entire progress is set
     * between the given bounds. That is, we set the interpolation to 0 until lowerBound and reach
     * 1 by upperBound.
     */
    public static Interpolator clampToProgress(Interpolator interpolator, float lowerBound,
            float upperBound) {
@@ -172,18 +180,30 @@ public class Interpolators {
                    String.format("upperBound (%f) must be greater than lowerBound (%f)",
                            upperBound, lowerBound));
        }
        return t -> {
            if (t == lowerBound && t == upperBound) {
                return t == 0f ? 0 : 1;
        return t -> clampToProgress(t, lowerBound, upperBound);
    }

    /**
     * Returns the progress value's progress between the lower and upper bounds. That is, the
     * progress will be 0f from 0f to lowerBound, and reach 1f by upperBound.
     */
    public static float clampToProgress(float progress, float lowerBound, float upperBound) {
        if (upperBound < lowerBound) {
            throw new IllegalArgumentException(
                    String.format("upperBound (%f) must be greater than lowerBound (%f)",
                            upperBound, lowerBound));
        }

        if (progress == lowerBound && progress == upperBound) {
            return progress == 0f ? 0 : 1;
        }
            if (t < lowerBound) {
        if (progress < lowerBound) {
            return 0;
        }
            if (t > upperBound) {
        if (progress > upperBound) {
            return 1;
        }
            return interpolator.getInterpolation((t - lowerBound) / (upperBound - lowerBound));
        };
        return (progress - lowerBound) / (upperBound - lowerBound);
    }

    /**