From 1f6b709ca67813e04212dec6eb48485b94753dfd Mon Sep 17 00:00:00 2001 From: Vladislav Kaznacheev Date: Wed, 4 May 2016 17:18:56 -0700 Subject: [PATCH] Let the framework position a window when switching to freeform When "freeform" button is tapped, the current Recents implementation puts the window into the left top corner, and sets window size to the size of the window snapshot as it is displayed in Recents. This is confusing. This patch lets the ActivityManager decide on the window bounds. The first "freeformed" window is put at the center, and subsequent windows are nicely cascaded. Bug: 28316396 Bug: 28312983 Change-Id: I3e305df3ab1e1f715e1f4f94e0ed2a8a1bbd2f22 --- .../com/android/systemui/recents/RecentsImpl.java | 7 +++++-- .../systemui/recents/misc/SystemServicesProxy.java | 8 +++++++- .../recents/tv/views/RecentsTvTransitionHelper.java | 4 +++- .../systemui/recents/tv/views/RecentsTvView.java | 6 ++++-- .../recents/views/RecentsTransitionHelper.java | 12 +++++++----- .../systemui/recents/views/TaskViewHeader.java | 5 +---- 6 files changed, 27 insertions(+), 15 deletions(-) diff --git a/packages/SystemUI/src/com/android/systemui/recents/RecentsImpl.java b/packages/SystemUI/src/com/android/systemui/recents/RecentsImpl.java index 297dec92d9b9f..e5739aa7c0142 100644 --- a/packages/SystemUI/src/com/android/systemui/recents/RecentsImpl.java +++ b/packages/SystemUI/src/com/android/systemui/recents/RecentsImpl.java @@ -17,6 +17,7 @@ package com.android.systemui.recents; import static android.app.ActivityManager.StackId.FREEFORM_WORKSPACE_STACK_ID; +import static android.app.ActivityManager.StackId.INVALID_STACK_ID; import static android.view.View.MeasureSpec; import android.app.ActivityManager; @@ -443,7 +444,8 @@ public class RecentsImpl implements ActivityOptions.OnAnimationFinishedListener } // Launch the task - ssp.startActivityFromRecents(mContext, toTask.key, toTask.title, launchOpts); + ssp.startActivityFromRecents( + mContext, toTask.key, toTask.title, launchOpts, INVALID_STACK_ID); } /** @@ -515,7 +517,8 @@ public class RecentsImpl implements ActivityOptions.OnAnimationFinishedListener MetricsLogger.count(mContext, "overview_affiliated_task_launch", 1); // Launch the task - ssp.startActivityFromRecents(mContext, toTask.key, toTask.title, launchOpts); + ssp.startActivityFromRecents( + mContext, toTask.key, toTask.title, launchOpts, INVALID_STACK_ID); } public void showNextAffiliatedTask() { diff --git a/packages/SystemUI/src/com/android/systemui/recents/misc/SystemServicesProxy.java b/packages/SystemUI/src/com/android/systemui/recents/misc/SystemServicesProxy.java index 46b2612ee7f09..68597b62ab521 100644 --- a/packages/SystemUI/src/com/android/systemui/recents/misc/SystemServicesProxy.java +++ b/packages/SystemUI/src/com/android/systemui/recents/misc/SystemServicesProxy.java @@ -20,6 +20,7 @@ import static android.app.ActivityManager.StackId.DOCKED_STACK_ID; import static android.app.ActivityManager.StackId.FREEFORM_WORKSPACE_STACK_ID; import static android.app.ActivityManager.StackId.FULLSCREEN_WORKSPACE_STACK_ID; import static android.app.ActivityManager.StackId.HOME_STACK_ID; +import static android.app.ActivityManager.StackId.INVALID_STACK_ID; import static android.app.ActivityManager.StackId.PINNED_STACK_ID; import static android.provider.Settings.Global.DEVELOPMENT_ENABLE_FREEFORM_WINDOWS_SUPPORT; @@ -940,7 +941,7 @@ public class SystemServicesProxy { /** Starts an activity from recents. */ public boolean startActivityFromRecents(Context context, Task.TaskKey taskKey, String taskName, - ActivityOptions options) { + ActivityOptions options, int stackId) { if (mIam != null) { try { if (taskKey.stackId == DOCKED_STACK_ID) { @@ -950,6 +951,11 @@ public class SystemServicesProxy { options = ActivityOptions.makeBasic(); } options.setLaunchStackId(FULLSCREEN_WORKSPACE_STACK_ID); + } else if (stackId != INVALID_STACK_ID){ + if (options == null) { + options = ActivityOptions.makeBasic(); + } + options.setLaunchStackId(stackId); } mIam.startActivityFromRecents( taskKey.id, options == null ? null : options.toBundle()); diff --git a/packages/SystemUI/src/com/android/systemui/recents/tv/views/RecentsTvTransitionHelper.java b/packages/SystemUI/src/com/android/systemui/recents/tv/views/RecentsTvTransitionHelper.java index 482115ed9b94c..2894cd885a388 100644 --- a/packages/SystemUI/src/com/android/systemui/recents/tv/views/RecentsTvTransitionHelper.java +++ b/packages/SystemUI/src/com/android/systemui/recents/tv/views/RecentsTvTransitionHelper.java @@ -34,6 +34,8 @@ import com.android.systemui.recents.misc.SystemServicesProxy; import com.android.systemui.recents.model.Task; import com.android.systemui.recents.model.TaskStack; +import static android.app.ActivityManager.StackId.INVALID_STACK_ID; + public class RecentsTvTransitionHelper { private static final String TAG = "RecentsTvTransitionHelper"; @@ -90,7 +92,7 @@ public class RecentsTvTransitionHelper { private void startTaskActivity(TaskStack stack, Task task, @Nullable TaskCardView taskView, ActivityOptions opts,final ActivityOptions.OnAnimationStartedListener animStartedListener) { SystemServicesProxy ssp = Recents.getSystemServices(); - if (ssp.startActivityFromRecents(mContext, task.key, task.title, opts)) { + if (ssp.startActivityFromRecents(mContext, task.key, task.title, opts, INVALID_STACK_ID)) { // Keep track of the index of the task launch int taskIndexFromFront = 0; int taskIndex = stack.indexOfStackTask(task); diff --git a/packages/SystemUI/src/com/android/systemui/recents/tv/views/RecentsTvView.java b/packages/SystemUI/src/com/android/systemui/recents/tv/views/RecentsTvView.java index 4058c6282ad7f..667e2f146ba5b 100644 --- a/packages/SystemUI/src/com/android/systemui/recents/tv/views/RecentsTvView.java +++ b/packages/SystemUI/src/com/android/systemui/recents/tv/views/RecentsTvView.java @@ -140,7 +140,8 @@ public class RecentsTvView extends FrameLayout { private void launchTaskFomRecents(final Task task, boolean animate) { if (!animate) { SystemServicesProxy ssp = Recents.getSystemServices(); - ssp.startActivityFromRecents(getContext(), task.key, task.title, null); + ssp.startActivityFromRecents(getContext(), task.key, task.title, null, + INVALID_STACK_ID); return; } mTaskStackHorizontalView.requestFocus(); @@ -164,7 +165,8 @@ public class RecentsTvView extends FrameLayout { // task with no animation. Log.e(TAG, "Card view for task : " + task + ", returned null."); SystemServicesProxy ssp = Recents.getSystemServices(); - ssp.startActivityFromRecents(getContext(), task.key, task.title, null); + ssp.startActivityFromRecents(getContext(), task.key, task.title, null, + INVALID_STACK_ID); } mTaskStackHorizontalView.removeOnScrollListener(mScrollListener); } diff --git a/packages/SystemUI/src/com/android/systemui/recents/views/RecentsTransitionHelper.java b/packages/SystemUI/src/com/android/systemui/recents/views/RecentsTransitionHelper.java index e3c3af0abbd5d..019df5e857329 100644 --- a/packages/SystemUI/src/com/android/systemui/recents/views/RecentsTransitionHelper.java +++ b/packages/SystemUI/src/com/android/systemui/recents/views/RecentsTransitionHelper.java @@ -149,7 +149,8 @@ public class RecentsTransitionHelper { if (taskView == null) { // If there is no task view, then we do not need to worry about animating out occluding // task views, and we can launch immediately - startTaskActivity(stack, task, taskView, opts, transitionFuture, animStartedListener); + startTaskActivity(stack, task, taskView, opts, transitionFuture, animStartedListener, + destinationStack); } else { LaunchTaskStartedEvent launchStartedEvent = new LaunchTaskStartedEvent(taskView, screenPinningRequested); @@ -158,14 +159,14 @@ public class RecentsTransitionHelper { @Override public void run() { startTaskActivity(stack, task, taskView, opts, transitionFuture, - animStartedListener); + animStartedListener, destinationStack); } }); EventBus.getDefault().send(launchStartedEvent); } else { EventBus.getDefault().send(launchStartedEvent); startTaskActivity(stack, task, taskView, opts, transitionFuture, - animStartedListener); + animStartedListener, destinationStack); } } Recents.getSystemServices().sendCloseSystemWindows( @@ -194,12 +195,13 @@ public class RecentsTransitionHelper { * * @param taskView this is the {@link TaskView} that we are launching from. This can be null if * we are toggling recents and the launch-to task is now offscreen. + * @param destinationStack id of the stack to put the task into. */ private void startTaskActivity(TaskStack stack, Task task, @Nullable TaskView taskView, ActivityOptions opts, IAppTransitionAnimationSpecsFuture transitionFuture, - final ActivityOptions.OnAnimationStartedListener animStartedListener) { + final OnAnimationStartedListener animStartedListener, int destinationStack) { SystemServicesProxy ssp = Recents.getSystemServices(); - if (ssp.startActivityFromRecents(mContext, task.key, task.title, opts)) { + if (ssp.startActivityFromRecents(mContext, task.key, task.title, opts, destinationStack)) { // Keep track of the index of the task launch int taskIndexFromFront = 0; int taskIndex = stack.indexOfStackTask(task); diff --git a/packages/SystemUI/src/com/android/systemui/recents/views/TaskViewHeader.java b/packages/SystemUI/src/com/android/systemui/recents/views/TaskViewHeader.java index 7b372eced043e..f21865ad4fe48 100644 --- a/packages/SystemUI/src/com/android/systemui/recents/views/TaskViewHeader.java +++ b/packages/SystemUI/src/com/android/systemui/recents/views/TaskViewHeader.java @@ -600,10 +600,7 @@ public class TaskViewHeader extends FrameLayout Constants.Metrics.DismissSourceHeaderButton); } else if (v == mMoveTaskButton) { TaskView tv = Utilities.findParent(this, TaskView.class); - Rect bounds = mMoveTaskTargetStackId == FREEFORM_WORKSPACE_STACK_ID - ? new Rect(mTaskViewRect) - : new Rect(); - EventBus.getDefault().send(new LaunchTaskEvent(tv, mTask, bounds, + EventBus.getDefault().send(new LaunchTaskEvent(tv, mTask, null, mMoveTaskTargetStackId, false)); } else if (v == mAppInfoView) { EventBus.getDefault().send(new ShowApplicationInfoEvent(mTask));