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

Commit 85d6f250 authored by Tony Wickham's avatar Tony Wickham
Browse files

Move shelf peeking anim code to ShelfPeekAnim class

Bug: 126596417
Change-Id: I5ba501b04b3eaf12a20ba1312ef362f9734761c3
parent 5bdae3d8
Loading
Loading
Loading
Loading
+27 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2019 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;

/** Empty class, only exists so that lowRamWithQuickstepIconRecentsDebug compiles. */
public class ShelfPeekAnim {
    public ShelfPeekAnim(Launcher launcher) {
    }

    public enum ShelfAnimState {
    }
}
+6 −26
Original line number Diff line number Diff line
@@ -47,6 +47,7 @@ import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.UiThread;

import com.android.launcher3.BaseQuickstepLauncher;
import com.android.launcher3.DeviceProfile;
import com.android.launcher3.Launcher;
import com.android.launcher3.LauncherInitListener;
@@ -56,12 +57,13 @@ import com.android.launcher3.allapps.DiscoveryBounce;
import com.android.launcher3.anim.AnimatorPlaybackController;
import com.android.launcher3.anim.AnimatorSetBuilder;
import com.android.launcher3.appprediction.PredictionUiStateManager;
import com.android.launcher3.uioverrides.states.OverviewState;
import com.android.launcher3.userevent.nano.LauncherLogProto;
import com.android.launcher3.views.FloatingIconView;
import com.android.quickstep.SysUINavigationMode.Mode;
import com.android.quickstep.util.ActivityInitListener;
import com.android.quickstep.util.LayoutUtils;
import com.android.quickstep.util.ShelfPeekAnim;
import com.android.quickstep.util.ShelfPeekAnim.ShelfAnimState;
import com.android.quickstep.util.StaggeredWorkspaceAnim;
import com.android.quickstep.views.LauncherRecentsView;
import com.android.quickstep.views.RecentsView;
@@ -227,7 +229,8 @@ public final class LauncherActivityInterface implements BaseActivityInterface<La
        launcher.getAppsView().reset(false /* animate */);

        return new AnimationFactory() {
            private ShelfAnimState mShelfState;
            private final ShelfPeekAnim mShelfAnim =
                    ((BaseQuickstepLauncher) launcher).getShelfPeekAnim();
            private boolean mIsAttachedToWindow;

            @Override
@@ -256,30 +259,7 @@ public final class LauncherActivityInterface implements BaseActivityInterface<La
            @Override
            public void setShelfState(ShelfAnimState shelfState, Interpolator interpolator,
                    long duration) {
                if (mShelfState == shelfState) {
                    return;
                }
                mShelfState = shelfState;
                launcher.getStateManager().cancelStateElementAnimation(INDEX_SHELF_ANIM);
                if (mShelfState == ShelfAnimState.CANCEL) {
                    return;
                }
                float shelfHiddenProgress = BACKGROUND_APP.getVerticalProgress(launcher);
                float shelfOverviewProgress = OVERVIEW.getVerticalProgress(launcher);
                // Peek based on default overview progress so we can see hotseat if we're showing
                // that instead of predictions in overview.
                float defaultOverviewProgress = OverviewState.getDefaultVerticalProgress(launcher);
                float shelfPeekingProgress = shelfHiddenProgress
                        - (shelfHiddenProgress - defaultOverviewProgress) * 0.25f;
                float toProgress = mShelfState == ShelfAnimState.HIDE
                        ? shelfHiddenProgress
                        : mShelfState == ShelfAnimState.PEEK
                                ? shelfPeekingProgress
                                : shelfOverviewProgress;
                Animator shelfAnim = launcher.getStateManager()
                        .createStateElementAnimation(INDEX_SHELF_ANIM, toProgress);
                shelfAnim.setInterpolator(interpolator);
                shelfAnim.setDuration(duration).start();
                mShelfAnim.setShelfState(shelfState, interpolator, duration);
            }

            @Override
+5 −5
Original line number Diff line number Diff line
@@ -24,8 +24,6 @@ import static com.android.launcher3.config.FeatureFlags.ENABLE_QUICKSTEP_LIVE_TI
import static com.android.launcher3.config.FeatureFlags.QUICKSTEP_SPRINGS;
import static com.android.launcher3.util.DefaultDisplay.getSingleFrameMs;
import static com.android.launcher3.util.SystemUiController.UI_STATE_OVERVIEW;
import static com.android.quickstep.BaseActivityInterface.AnimationFactory.ShelfAnimState.HIDE;
import static com.android.quickstep.BaseActivityInterface.AnimationFactory.ShelfAnimState.PEEK;
import static com.android.quickstep.GestureState.GestureEndTarget.HOME;
import static com.android.quickstep.GestureState.GestureEndTarget.LAST_TASK;
import static com.android.quickstep.GestureState.GestureEndTarget.NEW_TASK;
@@ -33,6 +31,8 @@ import static com.android.quickstep.GestureState.GestureEndTarget.RECENTS;
import static com.android.quickstep.GestureState.STATE_END_TARGET_ANIMATION_FINISHED;
import static com.android.quickstep.MultiStateCallback.DEBUG_STATES;
import static com.android.quickstep.SysUINavigationMode.Mode.TWO_BUTTONS;
import static com.android.quickstep.util.ShelfPeekAnim.ShelfAnimState.HIDE;
import static com.android.quickstep.util.ShelfPeekAnim.ShelfAnimState.PEEK;
import static com.android.quickstep.views.RecentsView.UPDATE_SYSUI_FLAGS_THRESHOLD;

import android.animation.Animator;
@@ -69,13 +69,14 @@ import com.android.launcher3.userevent.nano.LauncherLogProto.Action.Touch;
import com.android.launcher3.userevent.nano.LauncherLogProto.ContainerType;
import com.android.launcher3.util.TraceHelper;
import com.android.quickstep.BaseActivityInterface.AnimationFactory;
import com.android.quickstep.BaseActivityInterface.AnimationFactory.ShelfAnimState;
import com.android.quickstep.BaseActivityInterface.HomeAnimationFactory;
import com.android.quickstep.GestureState.GestureEndTarget;
import com.android.quickstep.inputconsumers.OverviewInputConsumer;
import com.android.quickstep.util.ActiveGestureLog;
import com.android.quickstep.util.AppWindowAnimationHelper.TargetAlphaProvider;
import com.android.quickstep.util.RectFSpringAnim;
import com.android.quickstep.util.ShelfPeekAnim;
import com.android.quickstep.util.ShelfPeekAnim.ShelfAnimState;
import com.android.quickstep.views.LiveTileOverlay;
import com.android.quickstep.views.RecentsView;
import com.android.quickstep.views.TaskView;
@@ -151,7 +152,6 @@ public class LauncherSwipeHandler<T extends BaseDraggingActivity>
            Math.min(1 / MIN_PROGRESS_FOR_OVERVIEW, 1 / (1 - MIN_PROGRESS_FOR_OVERVIEW));
    private static final String SCREENSHOT_CAPTURED_EVT = "ScreenshotCaptured";

    private static final long SHELF_ANIM_DURATION = 240;
    public static final long RECENTS_ATTACH_DURATION = 300;

    /**
@@ -432,7 +432,7 @@ public class LauncherSwipeHandler<T extends BaseDraggingActivity>

    @Override
    public void onMotionPauseChanged(boolean isPaused) {
        setShelfState(isPaused ? PEEK : HIDE, OVERSHOOT_1_2, SHELF_ANIM_DURATION);
        setShelfState(isPaused ? PEEK : HIDE, ShelfPeekAnim.INTERPOLATOR, ShelfPeekAnim.DURATION);

        if (mDeviceState.isFullyGesturalNavMode() && isPaused) {
            // In fully gestural nav mode, switch to overview predictions once the user has paused
+104 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2019 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 static com.android.launcher3.LauncherAppTransitionManagerImpl.INDEX_SHELF_ANIM;
import static com.android.launcher3.LauncherState.BACKGROUND_APP;
import static com.android.launcher3.LauncherState.OVERVIEW;
import static com.android.launcher3.anim.Interpolators.OVERSHOOT_1_2;

import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
import android.view.animation.Interpolator;

import com.android.launcher3.Launcher;
import com.android.launcher3.uioverrides.states.OverviewState;

/**
 * Animates the shelf between states HIDE, PEEK, and OVERVIEW.
 */
public class ShelfPeekAnim {

    public static final Interpolator INTERPOLATOR = OVERSHOOT_1_2;
    public static final long DURATION = 240;

    private final Launcher mLauncher;

    private ShelfAnimState mShelfState;
    private boolean mIsPeeking;

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

    /**
     * Animates to the given state, canceling the previous animation if it was still running.
     */
    public void setShelfState(ShelfAnimState shelfState, Interpolator interpolator, long duration) {
        if (mShelfState == shelfState) {
            return;
        }
        mLauncher.getStateManager().cancelStateElementAnimation(INDEX_SHELF_ANIM);
        mShelfState = shelfState;
        mIsPeeking = mShelfState == ShelfAnimState.PEEK || mShelfState == ShelfAnimState.HIDE;
        if (mShelfState == ShelfAnimState.CANCEL) {
            return;
        }
        float shelfHiddenProgress = BACKGROUND_APP.getVerticalProgress(mLauncher);
        float shelfOverviewProgress = OVERVIEW.getVerticalProgress(mLauncher);
        // Peek based on default overview progress so we can see hotseat if we're showing
        // that instead of predictions in overview.
        float defaultOverviewProgress = OverviewState.getDefaultVerticalProgress(mLauncher);
        float shelfPeekingProgress = shelfHiddenProgress
                - (shelfHiddenProgress - defaultOverviewProgress) * 0.25f;
        float toProgress = mShelfState == ShelfAnimState.HIDE
                ? shelfHiddenProgress
                : mShelfState == ShelfAnimState.PEEK
                        ? shelfPeekingProgress
                        : shelfOverviewProgress;
        Animator shelfAnim = mLauncher.getStateManager()
                .createStateElementAnimation(INDEX_SHELF_ANIM, toProgress);
        shelfAnim.setInterpolator(interpolator);
        shelfAnim.addListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationCancel(Animator animation) {
                mShelfState = ShelfAnimState.CANCEL;
            }

            @Override
            public void onAnimationEnd(Animator animator) {
                mIsPeeking = mShelfState == ShelfAnimState.PEEK;
            }
        });
        shelfAnim.setDuration(duration).start();
    }

    /** @return Whether the shelf is currently peeking or animating to or from peeking. */
    public boolean isPeeking() {
        return mIsPeeking;
    }

    /** The various shelf states we can animate to. */
    public enum ShelfAnimState {
        HIDE(true), PEEK(true), OVERVIEW(false), CANCEL(false);

        ShelfAnimState(boolean shouldPreformHaptic) {
            this.shouldPreformHaptic = shouldPreformHaptic;
        }

        public final boolean shouldPreformHaptic;
    }
}
+7 −0
Original line number Diff line number Diff line
@@ -48,6 +48,7 @@ import com.android.quickstep.SysUINavigationMode.Mode;
import com.android.quickstep.SysUINavigationMode.NavigationModeChangeListener;
import com.android.quickstep.SystemUiProxy;
import com.android.quickstep.util.RemoteFadeOutAnimationListener;
import com.android.quickstep.util.ShelfPeekAnim;

import java.util.stream.Stream;

@@ -64,6 +65,8 @@ public abstract class BaseQuickstepLauncher extends Launcher
            (context, arg1, arg2) -> SystemUiProxy.INSTANCE.get(context).setBackButtonAlpha(
                    Float.intBitsToFloat(arg1), arg2 != 0);

    private final ShelfPeekAnim mShelfPeekAnim = new ShelfPeekAnim(this);

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
@@ -270,4 +273,8 @@ public abstract class BaseQuickstepLauncher extends Launcher
        return Stream.concat(super.getSupportedShortcuts(),
                Stream.of(WellbeingModel.SHORTCUT_FACTORY));
    }

    public ShelfPeekAnim getShelfPeekAnim() {
        return mShelfPeekAnim;
    }
}
Loading