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

Commit 1409d297 authored by Vinit Nayak's avatar Vinit Nayak
Browse files

Refactor TaskViewUtils to launch adjacent GroupedViewTaskView

* TaskViewUtils only used one TVS, now it can use
multiple necessary for staged split.
* Consolidate creating RemoteAnimationTargets into
TaskViewSimulators/TransformParams into RemoteTargetGluer

Test: Swipe to overview, tap on running task.
Swipe to overview, tap on adjacent task (single + split)
Bug: 195675206

Change-Id: I31e4aece60e2eaf94ce87ffc736b33fe7e0e5804
parent 11438429
Loading
Loading
Loading
Loading
+13 −9
Original line number Diff line number Diff line
@@ -96,6 +96,7 @@ import com.android.launcher3.util.VibratorWrapper;
import com.android.launcher3.util.WindowBounds;
import com.android.quickstep.BaseActivityInterface.AnimationFactory;
import com.android.quickstep.GestureState.GestureEndTarget;
import com.android.quickstep.RemoteTargetGluer.RemoteTargetHandle;
import com.android.quickstep.util.ActiveGestureLog;
import com.android.quickstep.util.ActivityInitListener;
import com.android.quickstep.util.AnimatorControllerWithResistance;
@@ -434,7 +435,7 @@ public abstract class AbsSwipeUpHandler<T extends StatefulActivity<S>,
        // RecentsView never updates the display rotation until swipe-up, force update
        // RecentsOrientedState before passing to TaskViewSimulator.
        mRecentsView.updateRecentsRotation();
        runActionOnRemoteHandles(remoteTargetHandle -> remoteTargetHandle.mTaskViewSimulator
        runActionOnRemoteHandles(remoteTargetHandle -> remoteTargetHandle.getTaskViewSimulator()
                .setOrientationState(mRecentsView.getPagedViewOrientedState()));

        // If we've already ended the gesture and are going home, don't prepare recents UI,
@@ -753,6 +754,8 @@ public abstract class AbsSwipeUpHandler<T extends StatefulActivity<S>,
    public void onRecentsAnimationStart(RecentsAnimationController controller,
            RecentsAnimationTargets targets) {
        super.onRecentsAnimationStart(controller, targets);
        ActiveGestureLog.INSTANCE.addLog("startRecentsAnimationCallback", targets.apps.length);
        mRemoteTargetHandles = mTargetGluer.assignTargetsForSplitScreen(targets);
        mRecentsAnimationController = controller;
        mRecentsAnimationTargets = targets;

@@ -763,7 +766,7 @@ public abstract class AbsSwipeUpHandler<T extends StatefulActivity<S>,
            // orientation state is independent of which remote target handle we use since both
            // should be pointing to the same one. Just choose index 0 for now since that works for
            // both split and non-split
            RecentsOrientedState orientationState = mRemoteTargetHandles[0].mTaskViewSimulator
            RecentsOrientedState orientationState = mRemoteTargetHandles[0].getTaskViewSimulator()
                    .getOrientationState();
            DeviceProfile dp = orientationState.getLauncherDeviceProfile();
            if (targets.minimizedHomeBounds != null && primaryTaskTarget != null) {
@@ -1350,7 +1353,7 @@ public abstract class AbsSwipeUpHandler<T extends StatefulActivity<S>,
            RemoteAnimationTargetCompat runningTaskTarget, float startProgress) {
        // Directly animate the app to PiP (picture-in-picture) mode
        final ActivityManager.RunningTaskInfo taskInfo = mGestureState.getRunningTask();
        final RecentsOrientedState orientationState = mRemoteTargetHandles[0].mTaskViewSimulator
        final RecentsOrientedState orientationState = mRemoteTargetHandles[0].getTaskViewSimulator()
                .getOrientationState();
        final int windowRotation = calculateWindowRotation(runningTaskTarget, orientationState);
        final int homeRotation = orientationState.getRecentsActivityRotation();
@@ -1386,7 +1389,7 @@ public abstract class AbsSwipeUpHandler<T extends StatefulActivity<S>,
        // is not ROTATION_0 (which implies the rotation is turned on in launcher settings).
        if (homeRotation == ROTATION_0
                && (windowRotation == ROTATION_90 || windowRotation == ROTATION_270)) {
            builder.setFromRotation(mRemoteTargetHandles[0].mTaskViewSimulator, windowRotation,
            builder.setFromRotation(mRemoteTargetHandles[0].getTaskViewSimulator(), windowRotation,
                    taskInfo.displayCutoutInsets);
        }
        final SwipePipToHomeAnimator swipePipToHomeAnimator = builder.build();
@@ -1756,7 +1759,7 @@ public abstract class AbsSwipeUpHandler<T extends StatefulActivity<S>,
     * depend on proper class initialization.
     */
    protected void initAfterSubclassConstructor() {
        initTransitionEndpoints(mRemoteTargetHandles[0].mTaskViewSimulator
        initTransitionEndpoints(mRemoteTargetHandles[0].getTaskViewSimulator()
                        .getOrientationState().getLauncherDeviceProfile());
    }

@@ -1774,7 +1777,7 @@ public abstract class AbsSwipeUpHandler<T extends StatefulActivity<S>,

    protected void linkRecentsViewScroll() {
        SurfaceTransactionApplier.create(mRecentsView, applier -> {
            runActionOnRemoteHandles(remoteTargetHandle -> remoteTargetHandle.mTransformParams
            runActionOnRemoteHandles(remoteTargetHandle -> remoteTargetHandle.getTransformParams()
                            .setSyncTransactionApplier(applier));
            runOnRecentsAnimationStart(() ->
                    mRecentsAnimationTargets.addReleaseCheck(applier));
@@ -1910,18 +1913,19 @@ public abstract class AbsSwipeUpHandler<T extends StatefulActivity<S>,
        boolean notSwipingPipToHome = mRecentsAnimationTargets != null && !mIsSwipingPipToHome;
        boolean setRecentsScroll = mRecentsViewScrollLinked && mRecentsView != null;
        for (RemoteTargetHandle remoteHandle : mRemoteTargetHandles) {
            AnimatorControllerWithResistance playbackController = remoteHandle.mPlaybackController;
            AnimatorControllerWithResistance playbackController =
                    remoteHandle.getPlaybackController();
            if (playbackController != null) {
                playbackController.setProgress(Math.max(mCurrentShift.value,
                        getScaleProgressDueToScroll()), mDragLengthFactor);
            }

            if (notSwipingPipToHome) {
                TaskViewSimulator taskViewSimulator = remoteHandle.mTaskViewSimulator;
                TaskViewSimulator taskViewSimulator = remoteHandle.getTaskViewSimulator();
                if (setRecentsScroll) {
                    taskViewSimulator.setScroll(mRecentsView.getScrollOffset());
                }
                taskViewSimulator.apply(remoteHandle.mTransformParams);
                taskViewSimulator.apply(remoteHandle.getTransformParams());
            }
        }
        ProtoTracer.INSTANCE.get(mContext).scheduleFrameUpdate();
+6 −5
Original line number Diff line number Diff line
@@ -105,7 +105,7 @@ public class FallbackSwipeHandler extends
        mRunningOverHome = ActivityManagerWrapper.isHomeTask(mGestureState.getRunningTask());
        if (mRunningOverHome) {
            runActionOnRemoteHandles(remoteTargetHandle ->
                    remoteTargetHandle.mTransformParams.setHomeBuilderProxy(
                    remoteTargetHandle.getTransformParams().setHomeBuilderProxy(
                    FallbackSwipeHandler.this::updateHomeActivityTransformDuringSwipeUp));
        }
    }
@@ -115,7 +115,8 @@ public class FallbackSwipeHandler extends
        super.initTransitionEndpoints(dp);
        if (mRunningOverHome) {
            // Full screen scale should be independent of remote target handle
            mMaxLauncherScale = 1 / mRemoteTargetHandles[0].mTaskViewSimulator.getFullScreenScale();
            mMaxLauncherScale = 1 / mRemoteTargetHandles[0].getTaskViewSimulator()
                    .getFullScreenScale();
        }
    }

@@ -214,21 +215,21 @@ public class FallbackSwipeHandler extends
                mHomeAlpha.value = Utilities.boundToRange(1 - mCurrentShift.value, 0, 1);
                mVerticalShiftForScale.value = mCurrentShift.value;
                runActionOnRemoteHandles(remoteTargetHandle ->
                        remoteTargetHandle.mTransformParams.setHomeBuilderProxy(
                        remoteTargetHandle.getTransformParams().setHomeBuilderProxy(
                                FallbackHomeAnimationFactory.this
                                        ::updateHomeActivityTransformDuringHomeAnim));
            } else {
                mHomeAlpha = new AnimatedFloat(this::updateHomeAlpha);
                mHomeAlpha.value = 0;
                runActionOnRemoteHandles(remoteTargetHandle ->
                        remoteTargetHandle.mTransformParams.setHomeBuilderProxy(
                        remoteTargetHandle.getTransformParams().setHomeBuilderProxy(
                                FallbackHomeAnimationFactory.this
                                        ::updateHomeActivityTransformDuringHomeAnim));
            }

            mRecentsAlpha.value = 1;
            runActionOnRemoteHandles(remoteTargetHandle ->
                    remoteTargetHandle.mTransformParams.setHomeBuilderProxy(
                    remoteTargetHandle.getTransformParams().setHomeBuilderProxy(
                            FallbackHomeAnimationFactory.this
                                    ::updateRecentsActivityTransformDuringHomeAnim));
        }
+2 −2
Original line number Diff line number Diff line
@@ -183,13 +183,13 @@ public class LauncherSwipeHandlerV2 extends
        Rect crop = new Rect();
        // We can assume there is only one remote target here because staged split never animates
        // into the app icon, only into the homescreen
        mRemoteTargetHandles[0].mTaskViewSimulator.getCurrentCropRect().roundOut(crop);
        mRemoteTargetHandles[0].getTaskViewSimulator().getCurrentCropRect().roundOut(crop);
        Size windowSize = new Size(crop.width(), crop.height());
        int fallbackBackgroundColor =
                FloatingWidgetView.getDefaultBackgroundColor(mContext, runningTaskTarget);
        FloatingWidgetView floatingWidgetView = FloatingWidgetView.getFloatingWidgetView(mActivity,
                hostView, backgroundLocation, windowSize,
                mRemoteTargetHandles[0].mTaskViewSimulator.getCurrentCornerRadius(),
                mRemoteTargetHandles[0].getTaskViewSimulator().getCurrentCornerRadius(),
                isTargetTranslucent, fallbackBackgroundColor);

        return new FloatingViewHomeAnimationFactory(floatingWidgetView) {
+177 −0
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;

import static android.view.WindowManager.LayoutParams.TYPE_DOCK_DIVIDER;

import android.content.Context;

import androidx.annotation.Nullable;

import com.android.launcher3.util.SplitConfigurationOptions;
import com.android.quickstep.util.AnimatorControllerWithResistance;
import com.android.quickstep.util.LauncherSplitScreenListener;
import com.android.quickstep.util.TaskViewSimulator;
import com.android.quickstep.util.TransformParams;
import com.android.systemui.shared.system.RemoteAnimationTargetCompat;

/**
 * Glues together the necessary components to animate a remote target using a
 * {@link TaskViewSimulator}
 */
public class RemoteTargetGluer {
    private final RemoteTargetHandle[] mRemoteTargetHandles;
    private SplitConfigurationOptions.StagedSplitBounds mStagedSplitBounds;

    /**
     * Use this constructor if remote targets are split-screen independent
     */
    public RemoteTargetGluer(Context context, BaseActivityInterface sizingStrategy,
            RemoteAnimationTargets targets) {
        mRemoteTargetHandles = createHandles(context, sizingStrategy, targets.apps.length);
    }

    /**
     * Use this constructor if you want the number of handles created to match the number of active
     * running tasks
     */
    public RemoteTargetGluer(Context context, BaseActivityInterface sizingStrategy) {
        int[] splitIds = LauncherSplitScreenListener.INSTANCE.getNoCreate()
                .getRunningSplitTaskIds();
        mRemoteTargetHandles = createHandles(context, sizingStrategy, splitIds.length == 2 ? 2 : 1);
    }

    private RemoteTargetHandle[] createHandles(Context context,
            BaseActivityInterface sizingStrategy, int numHandles) {
        RemoteTargetHandle[] handles = new RemoteTargetHandle[numHandles];
        for (int i = 0; i < numHandles; i++) {
            TaskViewSimulator tvs = new TaskViewSimulator(context, sizingStrategy);
            TransformParams transformParams = new TransformParams();
            handles[i] = new RemoteTargetHandle(tvs, transformParams);
        }
        return handles;
    }

    /**
     * Pairs together {@link TaskViewSimulator}s and {@link TransformParams} into a
     * {@link RemoteTargetHandle}
     * Assigns only the apps associated with {@param targets} into their own TaskViewSimulators.
     * Length of targets.apps should match that of {@link #mRemoteTargetHandles}.
     *
     * If split screen may be active when this is called, you might want to use
     * {@link #assignTargetsForSplitScreen(RemoteAnimationTargets)}
     */
    public RemoteTargetHandle[] assignTargets(RemoteAnimationTargets targets) {
        for (int i = 0; i < mRemoteTargetHandles.length; i++) {
            RemoteAnimationTargetCompat primaryTaskTarget = targets.apps[i];
            mRemoteTargetHandles[i].mTransformParams.setTargetSet(
                    createRemoteAnimationTargetsForTarget(primaryTaskTarget, targets));
            mRemoteTargetHandles[i].mTaskViewSimulator.setPreview(primaryTaskTarget, null);
        }
        return mRemoteTargetHandles;
    }

    /**
     * Similar to {@link #assignTargets(RemoteAnimationTargets)}, except this matches the
     * apps in targets.apps to that of the split screened tasks. If split screen is active, then
     * {@link #mRemoteTargetHandles} index 0 will be the left/top task, index one right/bottom
     */
    public RemoteTargetHandle[] assignTargetsForSplitScreen(RemoteAnimationTargets targets) {
        int[] splitIds = LauncherSplitScreenListener.INSTANCE.getNoCreate()
                .getRunningSplitTaskIds();
        RemoteAnimationTargetCompat primaryTaskTarget;
        RemoteAnimationTargetCompat secondaryTaskTarget;
        if (mRemoteTargetHandles.length == 1) {
            // If we're not in split screen, the splitIds count doesn't really matter since we
            // should always hit this case. Right now there's no use case for multiple app targets
            // without being in split screen
            primaryTaskTarget = targets.apps[0];
            mRemoteTargetHandles[0].mTransformParams.setTargetSet(targets);
            mRemoteTargetHandles[0].mTaskViewSimulator.setPreview(primaryTaskTarget, null);
        } else {
            // split screen
            primaryTaskTarget = targets.findTask(splitIds[0]);
            secondaryTaskTarget = targets.findTask(splitIds[1]);

            RemoteAnimationTargetCompat dividerTarget = targets.getNonAppTargetOfType(
                    TYPE_DOCK_DIVIDER);
            mStagedSplitBounds = new SplitConfigurationOptions.StagedSplitBounds(
                    primaryTaskTarget.screenSpaceBounds,
                    secondaryTaskTarget.screenSpaceBounds, dividerTarget.screenSpaceBounds);
            mRemoteTargetHandles[0].mTransformParams.setTargetSet(
                    createRemoteAnimationTargetsForTarget(primaryTaskTarget, targets));
            mRemoteTargetHandles[0].mTaskViewSimulator.setPreview(primaryTaskTarget,
                    mStagedSplitBounds);

            mRemoteTargetHandles[1].mTransformParams.setTargetSet(
                    createRemoteAnimationTargetsForTarget(secondaryTaskTarget, targets));
            mRemoteTargetHandles[1].mTaskViewSimulator.setPreview(secondaryTaskTarget,
                    mStagedSplitBounds);
        }
        return mRemoteTargetHandles;
    }

    private RemoteAnimationTargets createRemoteAnimationTargetsForTarget(
            RemoteAnimationTargetCompat target,
            RemoteAnimationTargets targets) {
        return new RemoteAnimationTargets(new RemoteAnimationTargetCompat[]{target},
                targets.wallpapers, targets.nonApps, targets.targetMode);
    }

    public RemoteTargetHandle[] getRemoteTargetHandles() {
        return mRemoteTargetHandles;
    }

    public SplitConfigurationOptions.StagedSplitBounds getStagedSplitBounds() {
        return mStagedSplitBounds;
    }

    /**
     * Container to keep together all the associated objects whose properties need to be updated to
     * animate a single remote app target
     */
    public static class RemoteTargetHandle {
        private final TaskViewSimulator mTaskViewSimulator;
        private final TransformParams mTransformParams;
        @Nullable
        private AnimatorControllerWithResistance mPlaybackController;

        public RemoteTargetHandle(TaskViewSimulator taskViewSimulator,
                TransformParams transformParams) {
            mTransformParams = transformParams;
            mTaskViewSimulator = taskViewSimulator;
        }

        public TaskViewSimulator getTaskViewSimulator() {
            return mTaskViewSimulator;
        }

        public TransformParams getTransformParams() {
            return mTransformParams;
        }

        @Nullable
        public AnimatorControllerWithResistance getPlaybackController() {
            return mPlaybackController;
        }

        public void setPlaybackController(
                @Nullable AnimatorControllerWithResistance playbackController) {
            mPlaybackController = playbackController;
        }
    }
}
+15 −86

File changed.

Preview size limit exceeded, changes collapsed.

Loading