Merge changes I3c7a2886,Ib959f44b into sc-v2-dev am: 90db2335da

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/16442963

Change-Id: I080e99a219d3823918fb3036d760cd78b0b15c41
This commit is contained in:
Mady Mellor
2021-12-14 15:38:45 +00:00
committed by Automerger Merge Worker
4 changed files with 111 additions and 40 deletions

View File

@@ -151,7 +151,13 @@ public class DragAndDropPolicy {
final Rect rightHitRegion = new Rect(); final Rect rightHitRegion = new Rect();
final Rect rightDrawRegion = bottomOrRightBounds; final Rect rightDrawRegion = bottomOrRightBounds;
displayRegion.splitVertically(leftHitRegion, rightHitRegion); // If we have existing split regions use those bounds, otherwise split it 50/50
if (inSplitScreen) {
leftHitRegion.set(topOrLeftBounds);
rightHitRegion.set(bottomOrRightBounds);
} else {
displayRegion.splitVertically(leftHitRegion, rightHitRegion);
}
mTargets.add(new Target(TYPE_SPLIT_LEFT, leftHitRegion, leftDrawRegion)); mTargets.add(new Target(TYPE_SPLIT_LEFT, leftHitRegion, leftDrawRegion));
mTargets.add(new Target(TYPE_SPLIT_RIGHT, rightHitRegion, rightDrawRegion)); mTargets.add(new Target(TYPE_SPLIT_RIGHT, rightHitRegion, rightDrawRegion));
@@ -162,8 +168,13 @@ public class DragAndDropPolicy {
final Rect bottomHitRegion = new Rect(); final Rect bottomHitRegion = new Rect();
final Rect bottomDrawRegion = bottomOrRightBounds; final Rect bottomDrawRegion = bottomOrRightBounds;
displayRegion.splitHorizontally( // If we have existing split regions use those bounds, otherwise split it 50/50
topHitRegion, bottomHitRegion); if (inSplitScreen) {
topHitRegion.set(topOrLeftBounds);
bottomHitRegion.set(bottomOrRightBounds);
} else {
displayRegion.splitHorizontally(topHitRegion, bottomHitRegion);
}
mTargets.add(new Target(TYPE_SPLIT_TOP, topHitRegion, topDrawRegion)); mTargets.add(new Target(TYPE_SPLIT_TOP, topHitRegion, topDrawRegion));
mTargets.add(new Target(TYPE_SPLIT_BOTTOM, bottomHitRegion, bottomDrawRegion)); mTargets.add(new Target(TYPE_SPLIT_BOTTOM, bottomHitRegion, bottomDrawRegion));

View File

@@ -17,7 +17,9 @@
package com.android.wm.shell.draganddrop; package com.android.wm.shell.draganddrop;
import static android.app.StatusBarManager.DISABLE_NONE; import static android.app.StatusBarManager.DISABLE_NONE;
import static android.view.ViewGroup.LayoutParams.MATCH_PARENT;
import static com.android.wm.shell.common.split.SplitScreenConstants.SPLIT_POSITION_BOTTOM_OR_RIGHT;
import static com.android.wm.shell.common.split.SplitScreenConstants.SPLIT_POSITION_TOP_OR_LEFT; import static com.android.wm.shell.common.split.SplitScreenConstants.SPLIT_POSITION_TOP_OR_LEFT;
import android.animation.Animator; import android.animation.Animator;
@@ -32,11 +34,11 @@ import android.content.Context;
import android.content.res.Configuration; import android.content.res.Configuration;
import android.graphics.Color; import android.graphics.Color;
import android.graphics.Insets; import android.graphics.Insets;
import android.graphics.Rect;
import android.graphics.drawable.Drawable; import android.graphics.drawable.Drawable;
import android.os.RemoteException; import android.os.RemoteException;
import android.view.DragEvent; import android.view.DragEvent;
import android.view.SurfaceControl; import android.view.SurfaceControl;
import android.view.ViewGroup;
import android.view.WindowInsets; import android.view.WindowInsets;
import android.view.WindowInsets.Type; import android.view.WindowInsets.Type;
import android.widget.LinearLayout; import android.widget.LinearLayout;
@@ -73,6 +75,7 @@ public class DragLayout extends LinearLayout {
private DropZoneView mDropZoneView2; private DropZoneView mDropZoneView2;
private int mDisplayMargin; private int mDisplayMargin;
private int mDividerSize;
private Insets mInsets = Insets.NONE; private Insets mInsets = Insets.NONE;
private boolean mIsShowing; private boolean mIsShowing;
@@ -89,13 +92,15 @@ public class DragLayout extends LinearLayout {
mDisplayMargin = context.getResources().getDimensionPixelSize( mDisplayMargin = context.getResources().getDimensionPixelSize(
R.dimen.drop_layout_display_margin); R.dimen.drop_layout_display_margin);
mDividerSize = context.getResources().getDimensionPixelSize(
R.dimen.split_divider_bar_width);
mDropZoneView1 = new DropZoneView(context); mDropZoneView1 = new DropZoneView(context);
mDropZoneView2 = new DropZoneView(context); mDropZoneView2 = new DropZoneView(context);
addView(mDropZoneView1, new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, addView(mDropZoneView1, new LinearLayout.LayoutParams(MATCH_PARENT,
ViewGroup.LayoutParams.MATCH_PARENT)); MATCH_PARENT));
addView(mDropZoneView2, new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, addView(mDropZoneView2, new LinearLayout.LayoutParams(MATCH_PARENT,
ViewGroup.LayoutParams.MATCH_PARENT)); MATCH_PARENT));
((LayoutParams) mDropZoneView1.getLayoutParams()).weight = 1; ((LayoutParams) mDropZoneView1.getLayoutParams()).weight = 1;
((LayoutParams) mDropZoneView2.getLayoutParams()).weight = 1; ((LayoutParams) mDropZoneView2.getLayoutParams()).weight = 1;
updateContainerMargins(); updateContainerMargins();
@@ -165,44 +170,82 @@ public class DragLayout extends LinearLayout {
mHasDropped = false; mHasDropped = false;
mCurrentTarget = null; mCurrentTarget = null;
List<ActivityManager.RunningTaskInfo> tasks = null; boolean alreadyInSplit = mSplitScreenController != null
// Figure out the splashscreen info for the existing task(s). && mSplitScreenController.isSplitScreenVisible();
try { if (!alreadyInSplit) {
tasks = ActivityTaskManager.getService().getTasks(2, List<ActivityManager.RunningTaskInfo> tasks = null;
false /* filterOnlyVisibleRecents */, // Figure out the splashscreen info for the existing task.
false /* keepIntentExtra */); try {
} catch (RemoteException e) { tasks = ActivityTaskManager.getService().getTasks(1,
// don't show an icon / will just use the defaults false /* filterOnlyVisibleRecents */,
} false /* keepIntentExtra */);
if (tasks != null && !tasks.isEmpty()) { } catch (RemoteException e) {
ActivityManager.RunningTaskInfo taskInfo1 = tasks.get(0); // don't show an icon / will just use the defaults
Drawable icon1 = mIconProvider.getIcon(taskInfo1.topActivityInfo); }
int bgColor1 = getResizingBackgroundColor(taskInfo1); if (tasks != null && !tasks.isEmpty()) {
ActivityManager.RunningTaskInfo taskInfo1 = tasks.get(0);
boolean alreadyInSplit = mSplitScreenController != null Drawable icon1 = mIconProvider.getIcon(taskInfo1.topActivityInfo);
&& mSplitScreenController.isSplitScreenVisible(); int bgColor1 = getResizingBackgroundColor(taskInfo1);
if (alreadyInSplit && tasks.size() > 1) {
ActivityManager.RunningTaskInfo taskInfo2 = tasks.get(1);
Drawable icon2 = mIconProvider.getIcon(taskInfo2.topActivityInfo);
int bgColor2 = getResizingBackgroundColor(taskInfo2);
// figure out which task is on which side
int splitPosition1 = mSplitScreenController.getSplitPosition(taskInfo1.taskId);
boolean isTask1TopOrLeft = splitPosition1 == SPLIT_POSITION_TOP_OR_LEFT;
if (isTask1TopOrLeft) {
mDropZoneView1.setAppInfo(bgColor1, icon1);
mDropZoneView2.setAppInfo(bgColor2, icon2);
} else {
mDropZoneView2.setAppInfo(bgColor1, icon1);
mDropZoneView1.setAppInfo(bgColor2, icon2);
}
} else {
mDropZoneView1.setAppInfo(bgColor1, icon1); mDropZoneView1.setAppInfo(bgColor1, icon1);
mDropZoneView2.setAppInfo(bgColor1, icon1); mDropZoneView2.setAppInfo(bgColor1, icon1);
updateDropZoneSizes(null, null); // passing null splits the views evenly
} }
} else {
// We're already in split so get taskInfo from the controller to populate icon / color.
ActivityManager.RunningTaskInfo topOrLeftTask =
mSplitScreenController.getTaskInfo(SPLIT_POSITION_TOP_OR_LEFT);
ActivityManager.RunningTaskInfo bottomOrRightTask =
mSplitScreenController.getTaskInfo(SPLIT_POSITION_BOTTOM_OR_RIGHT);
if (topOrLeftTask != null && bottomOrRightTask != null) {
Drawable topOrLeftIcon = mIconProvider.getIcon(topOrLeftTask.topActivityInfo);
int topOrLeftColor = getResizingBackgroundColor(topOrLeftTask);
Drawable bottomOrRightIcon = mIconProvider.getIcon(
bottomOrRightTask.topActivityInfo);
int bottomOrRightColor = getResizingBackgroundColor(bottomOrRightTask);
mDropZoneView1.setAppInfo(topOrLeftColor, topOrLeftIcon);
mDropZoneView2.setAppInfo(bottomOrRightColor, bottomOrRightIcon);
}
// Update the dropzones to match existing split sizes
Rect topOrLeftBounds = new Rect();
Rect bottomOrRightBounds = new Rect();
mSplitScreenController.getStageBounds(topOrLeftBounds, bottomOrRightBounds);
updateDropZoneSizes(topOrLeftBounds, bottomOrRightBounds);
} }
} }
/**
* Sets the size of the two drop zones based on the provided bounds. The divider sits between
* the views and its size is included in the calculations.
*
* @param bounds1 bounds to apply to the first dropzone view, null if split in half.
* @param bounds2 bounds to apply to the second dropzone view, null if split in half.
*/
private void updateDropZoneSizes(Rect bounds1, Rect bounds2) {
final int orientation = getResources().getConfiguration().orientation;
final boolean isPortrait = orientation == Configuration.ORIENTATION_PORTRAIT;
final int halfDivider = mDividerSize / 2;
final LinearLayout.LayoutParams dropZoneView1 =
(LayoutParams) mDropZoneView1.getLayoutParams();
final LinearLayout.LayoutParams dropZoneView2 =
(LayoutParams) mDropZoneView2.getLayoutParams();
if (isPortrait) {
dropZoneView1.width = MATCH_PARENT;
dropZoneView2.width = MATCH_PARENT;
dropZoneView1.height = bounds1 != null ? bounds1.height() + halfDivider : MATCH_PARENT;
dropZoneView2.height = bounds2 != null ? bounds2.height() + halfDivider : MATCH_PARENT;
} else {
dropZoneView1.width = bounds1 != null ? bounds1.width() + halfDivider : MATCH_PARENT;
dropZoneView2.width = bounds2 != null ? bounds2.width() + halfDivider : MATCH_PARENT;
dropZoneView1.height = MATCH_PARENT;
dropZoneView2.height = MATCH_PARENT;
}
dropZoneView1.weight = bounds1 != null ? 0 : 1;
dropZoneView2.weight = bounds2 != null ? 0 : 1;
mDropZoneView1.setLayoutParams(dropZoneView1);
mDropZoneView2.setLayoutParams(dropZoneView2);
}
public void show() { public void show() {
mIsShowing = true; mIsShowing = true;
recomputeDropTargets(); recomputeDropTargets();

View File

@@ -186,6 +186,15 @@ public class SplitScreenController implements DragAndDropPolicy.Starter,
return mStageCoordinator.isSplitScreenVisible(); return mStageCoordinator.isSplitScreenVisible();
} }
@Nullable
public ActivityManager.RunningTaskInfo getTaskInfo(@SplitPosition int splitPosition) {
if (isSplitScreenVisible()) {
int taskId = mStageCoordinator.getTaskId(splitPosition);
return mTaskOrganizer.getRunningTaskInfo(taskId);
}
return null;
}
public boolean isTaskInSplitScreen(int taskId) { public boolean isTaskInSplitScreen(int taskId) {
return isSplitScreenVisible() return isSplitScreenVisible()
&& mStageCoordinator.getStageOfTask(taskId) != STAGE_TYPE_UNDEFINED; && mStageCoordinator.getStageOfTask(taskId) != STAGE_TYPE_UNDEFINED;

View File

@@ -522,6 +522,14 @@ class StageCoordinator implements SplitLayout.SplitLayoutHandler,
return SplitLayout.reversePosition(mSideStagePosition); return SplitLayout.reversePosition(mSideStagePosition);
} }
int getTaskId(@SplitPosition int splitPosition) {
if (mSideStagePosition == splitPosition) {
return mSideStage.getTopVisibleChildTaskId();
} else {
return mMainStage.getTopVisibleChildTaskId();
}
}
void setSideStagePosition(@SplitPosition int sideStagePosition, void setSideStagePosition(@SplitPosition int sideStagePosition,
@Nullable WindowContainerTransaction wct) { @Nullable WindowContainerTransaction wct) {
setSideStagePosition(sideStagePosition, true /* updateBounds */, wct); setSideStagePosition(sideStagePosition, true /* updateBounds */, wct);