Skip to content

Commit

Permalink
Changes to use new startTasks API
Browse files Browse the repository at this point in the history
When shell transitions is enabled, this will use the
newer multi-task-launch api and control the animation.

There is no actual animation yet, this just adds the
infrastructure.

Bug: 182002789
Test: enable developer option and enter split via recents
Change-Id: If5be104a86e7b5f743f85efed20b0d2bf1b8bfd1
  • Loading branch information
vinitnayak7 authored and Evan Rosky committed Apr 9, 2021
1 parent 7f463d3 commit b1bbc0f
Show file tree
Hide file tree
Showing 5 changed files with 114 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ protected void setupViews() {
mSplitPlaceholderView = findViewById(R.id.split_placeholder);
RecentsView overviewPanel = (RecentsView) getOverviewPanel();
mSplitPlaceholderView.init(
new SplitSelectStateController(SystemUiProxy.INSTANCE.get(this))
new SplitSelectStateController(mHandler, SystemUiProxy.INSTANCE.get(this))
);
overviewPanel.init(mActionsView, mSplitPlaceholderView);
mActionsView.updateVerticalMargin(SysUINavigationMode.getMode(this));
Expand Down
3 changes: 1 addition & 2 deletions quickstep/src/com/android/quickstep/RecentsActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,7 @@ protected void setupViews() {

SplitPlaceholderView splitPlaceholderView = findViewById(R.id.split_placeholder);
splitPlaceholderView.init(
new SplitSelectStateController(
SystemUiProxy.INSTANCE.get(this))
new SplitSelectStateController(mUiHandler, SystemUiProxy.INSTANCE.get(this))
);

mDragLayer.recreateControllers();
Expand Down
15 changes: 15 additions & 0 deletions quickstep/src/com/android/quickstep/SystemUiProxy.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import android.view.MotionEvent;

import com.android.launcher3.util.MainThreadInitializedObject;
import com.android.launcher3.util.SplitConfigurationOptions;
import com.android.systemui.shared.recents.ISystemUiProxy;
import com.android.systemui.shared.recents.model.Task;
import com.android.systemui.shared.system.RemoteTransitionCompat;
Expand Down Expand Up @@ -491,6 +492,20 @@ public void startTask(int taskId, int stage, int position, Bundle options) {
}
}

/** Start multiple tasks in split-screen simultaneously. */
public void startTasks(int mainTaskId, Bundle mainOptions, int sideTaskId, Bundle sideOptions,
@SplitConfigurationOptions.StagePosition int sidePosition,
RemoteTransitionCompat remoteTransition) {
if (mSystemUiProxy != null) {
try {
mSplitScreen.startTasks(mainTaskId, mainOptions, sideTaskId, sideOptions,
sidePosition, remoteTransition.getTransition());
} catch (RemoteException e) {
Log.w(TAG, "Failed call startTask");
}
}
}

public void startShortcut(String packageName, String shortcutId, int stage, int position,
Bundle options, UserHandle user) {
if (mSplitScreen != null) {
Expand Down
47 changes: 46 additions & 1 deletion quickstep/src/com/android/quickstep/TaskViewUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
*/
package com.android.quickstep;

import static android.view.WindowManager.TRANSIT_OPEN;
import static android.view.WindowManager.TRANSIT_TO_FRONT;

import static com.android.launcher3.LauncherAnimUtils.VIEW_ALPHA;
import static com.android.launcher3.LauncherState.BACKGROUND_APP;
import static com.android.launcher3.LauncherState.NORMAL;
Expand Down Expand Up @@ -47,7 +50,9 @@
import android.graphics.Rect;
import android.graphics.RectF;
import android.os.Build;
import android.view.SurfaceControl;
import android.view.View;
import android.window.TransitionInfo;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
Expand Down Expand Up @@ -352,7 +357,47 @@ public void onAnimationEnd(Animator animation) {
* device is considered in multiWindowMode and things like insets and stuff change
* and calculations have to be adjusted in the animations for that
*/
public static void composeRecentsSplitLaunchAnimator(@NonNull AnimatorSet anim,
public static void composeRecentsSplitLaunchAnimator(@NonNull TaskView initialView,
@NonNull TaskView v, @NonNull TransitionInfo transitionInfo,
SurfaceControl.Transaction t, @NonNull Runnable finishCallback) {

final TransitionInfo.Change[] splitRoots = new TransitionInfo.Change[2];
for (int i = 0; i < transitionInfo.getChanges().size(); ++i) {
final TransitionInfo.Change change = transitionInfo.getChanges().get(i);
final int taskId = change.getTaskInfo() != null ? change.getTaskInfo().taskId : -1;
final int mode = change.getMode();
// Find the target tasks' root tasks since those are the split stages that need to
// be animated (the tasks themselves are children and thus inherit animation).
if (taskId == initialView.getTask().key.id || taskId == v.getTask().key.id) {
if (!(mode == TRANSIT_OPEN || mode == TRANSIT_TO_FRONT)) {
throw new IllegalStateException(
"Expected task to be showing, but it is " + mode);
}
if (change.getParent() == null) {
throw new IllegalStateException("Initiating multi-split launch but the split"
+ "root of " + taskId + " is already visible or has broken hierarchy.");
}
splitRoots[taskId == initialView.getTask().key.id ? 0 : 1] =
transitionInfo.getChange(change.getParent());
}
}

// This is where we should animate the split roots. For now, though, just make them visible.
for (int i = 0; i < 2; ++i) {
t.show(splitRoots[i].getLeash());
t.setAlpha(splitRoots[i].getLeash(), 1.f);
}

// This contains the initial state (before animation), so apply this at the beginning of
// the animation.
t.apply();

// Once there is an animation, this should be called AFTER the animation completes.
finishCallback.run();
}

/** Legacy version (until shell transitions are enabled) */
public static void composeRecentsSplitLaunchAnimatorLegacy(@NonNull AnimatorSet anim,
@NonNull TaskView v, @NonNull RemoteAnimationTargetCompat[] appTargets,
@NonNull RemoteAnimationTargetCompat[] wallpaperTargets,
@NonNull RemoteAnimationTargetCompat[] nonAppTargets, boolean launcherClosing,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,17 @@

package com.android.quickstep.util;

import static com.android.launcher3.util.Executors.MAIN_EXECUTOR;
import static com.android.launcher3.util.SplitConfigurationOptions.STAGE_POSITION_BOTTOM_OR_RIGHT;
import static com.android.launcher3.util.SplitConfigurationOptions.STAGE_POSITION_TOP_OR_LEFT;

import android.animation.AnimatorSet;
import android.app.ActivityOptions;
import android.os.Handler;
import android.os.Looper;
import android.util.Pair;
import android.view.SurfaceControl;
import android.window.TransitionInfo;

import androidx.annotation.Nullable;

Expand All @@ -31,12 +37,15 @@
import com.android.launcher3.WrappedLauncherAnimationRunner;
import com.android.launcher3.util.SplitConfigurationOptions.SplitPositionOption;
import com.android.quickstep.SystemUiProxy;
import com.android.quickstep.TaskAnimationManager;
import com.android.quickstep.TaskViewUtils;
import com.android.quickstep.views.TaskView;
import com.android.systemui.shared.system.ActivityOptionsCompat;
import com.android.systemui.shared.system.RemoteAnimationAdapterCompat;
import com.android.systemui.shared.system.RemoteAnimationRunnerCompat;
import com.android.systemui.shared.system.RemoteAnimationTargetCompat;
import com.android.systemui.shared.system.RemoteTransitionCompat;
import com.android.systemui.shared.system.RemoteTransitionRunner;

/**
* Represent data needed for the transient state when user has selected one app for split screen
Expand All @@ -47,9 +56,11 @@ public class SplitSelectStateController {
private final SystemUiProxy mSystemUiProxy;
private TaskView mInitialTaskView;
private SplitPositionOption mInitialPosition;
private final Handler mHandler;

public SplitSelectStateController(SystemUiProxy systemUiProxy) {
public SplitSelectStateController(Handler handler, SystemUiProxy systemUiProxy) {
mSystemUiProxy = systemUiProxy;
mHandler = handler;
}

/**
Expand All @@ -64,6 +75,19 @@ public void setInitialTaskSelect(TaskView taskView, SplitPositionOption position
* To be called after second task selected
*/
public void setSecondTaskId(TaskView taskView) {
if (TaskAnimationManager.ENABLE_SHELL_TRANSITIONS) {
// Assume initial task is for top/left part of screen
final int[] taskIds = mInitialPosition.mStagePosition == STAGE_POSITION_TOP_OR_LEFT
? new int[]{mInitialTaskView.getTask().key.id, taskView.getTask().key.id}
: new int[]{taskView.getTask().key.id, mInitialTaskView.getTask().key.id};

RemoteSplitLaunchAnimationRunner animationRunner =
new RemoteSplitLaunchAnimationRunner(mInitialTaskView, taskView);
mSystemUiProxy.startTasks(taskIds[0], null /* mainOptions */, taskIds[1],
null /* sideOptions */, STAGE_POSITION_BOTTOM_OR_RIGHT,
new RemoteTransitionCompat(animationRunner, MAIN_EXECUTOR));
return;
}
// Assume initial mInitialTaskId is for top/left part of screen
WrappedAnimationRunnerImpl initialSplitRunnerWrapped = new SplitLaunchAnimationRunner(
mInitialTaskView, 0);
Expand Down Expand Up @@ -96,6 +120,30 @@ public SplitPositionOption getActiveSplitPositionOption() {
}

/**
* Requires Shell Transitions
*/
private class RemoteSplitLaunchAnimationRunner implements RemoteTransitionRunner {

private final TaskView mInitialTaskView;
private final TaskView mTaskView;

RemoteSplitLaunchAnimationRunner(TaskView initialTaskView, TaskView taskView) {
mInitialTaskView = initialTaskView;
mTaskView = taskView;
}

@Override
public void startAnimation(TransitionInfo info, SurfaceControl.Transaction t,
Runnable finishCallback) {
TaskViewUtils.composeRecentsSplitLaunchAnimator(mInitialTaskView, mTaskView,
info, t, finishCallback);
// After successful launch, call resetState
resetState();
}
}

/**
* LEGACY
* @return the opposite stage and position from the {@param position} provided as first and
* second object, respectively
* Ex. If position is has stage = Main and position = Top/Left, this will return
Expand All @@ -109,6 +157,7 @@ private Pair<Integer, Integer> getComplimentaryStageAndPosition(SplitPositionOpt
}

/**
* LEGACY
* Remote animation runner for animation to launch an app.
*/
private class SplitLaunchAnimationRunner implements WrappedAnimationRunnerImpl {
Expand All @@ -129,7 +178,7 @@ public void onCreateAnimation(int transit,
LauncherAnimationRunner.AnimationResult result) {
AnimatorSet anim = new AnimatorSet();
BaseQuickstepLauncher activity = BaseActivity.fromContext(mV.getContext());
TaskViewUtils.composeRecentsSplitLaunchAnimator(anim, mV,
TaskViewUtils.composeRecentsSplitLaunchAnimatorLegacy(anim, mV,
appTargets, wallpaperTargets, nonAppTargets, true, activity.getStateManager(),
activity.getDepthController(), mTargetState);
result.setAnimation(anim, activity);
Expand Down

0 comments on commit b1bbc0f

Please sign in to comment.