Merge "Fixes splitscreen when executed from fullscreen app" into pi-dev

This commit is contained in:
Matthew Ng
2018-05-12 00:27:28 +00:00
committed by Android (Google) Code Review
3 changed files with 73 additions and 34 deletions

View File

@@ -25,7 +25,6 @@ import android.content.res.Configuration;
import android.content.res.Resources; import android.content.res.Resources;
import android.graphics.Rect; import android.graphics.Rect;
import android.hardware.display.DisplayManager; import android.hardware.display.DisplayManager;
import android.util.Log;
import android.view.Display; import android.view.Display;
import android.view.DisplayInfo; import android.view.DisplayInfo;
@@ -107,6 +106,12 @@ public class DividerSnapAlgorithm {
DOCKED_INVALID, false); DOCKED_INVALID, false);
} }
public DividerSnapAlgorithm(Resources res, int displayWidth, int displayHeight, int dividerSize,
boolean isHorizontalDivision, Rect insets, int dockSide) {
this(res, displayWidth, displayHeight, dividerSize, isHorizontalDivision, insets,
dockSide, false);
}
public DividerSnapAlgorithm(Resources res, int displayWidth, int displayHeight, int dividerSize, public DividerSnapAlgorithm(Resources res, int displayWidth, int displayHeight, int dividerSize,
boolean isHorizontalDivision, Rect insets, int dockSide, boolean isMinimizedMode) { boolean isHorizontalDivision, Rect insets, int dockSide, boolean isMinimizedMode) {
mMinFlingVelocityPxPerSecond = mMinFlingVelocityPxPerSecond =
@@ -265,7 +270,11 @@ public class DividerSnapAlgorithm {
? mDisplayHeight ? mDisplayHeight
: mDisplayWidth; : mDisplayWidth;
int navBarSize = isHorizontalDivision ? mInsets.bottom : mInsets.right; int navBarSize = isHorizontalDivision ? mInsets.bottom : mInsets.right;
mTargets.add(new SnapTarget(-mDividerSize, -mDividerSize, SnapTarget.FLAG_DISMISS_START, int startPos = -mDividerSize;
if (dockedSide == DOCKED_RIGHT) {
startPos += mInsets.left;
}
mTargets.add(new SnapTarget(startPos, startPos, SnapTarget.FLAG_DISMISS_START,
0.35f)); 0.35f));
switch (mSnapMode) { switch (mSnapMode) {
case SNAP_MODE_16_9: case SNAP_MODE_16_9:

View File

@@ -126,8 +126,10 @@ public class DividerView extends FrameLayout implements OnTouchListener,
private SnapTarget mSnapTargetBeforeMinimized; private SnapTarget mSnapTargetBeforeMinimized;
private int mDividerInsets; private int mDividerInsets;
private final Display mDefaultDisplay;
private int mDisplayWidth; private int mDisplayWidth;
private int mDisplayHeight; private int mDisplayHeight;
private int mDisplayRotation;
private int mDividerWindowWidth; private int mDividerWindowWidth;
private int mDividerSize; private int mDividerSize;
private int mTouchElevation; private int mTouchElevation;
@@ -140,7 +142,7 @@ public class DividerView extends FrameLayout implements OnTouchListener,
private final Rect mDockedInsetRect = new Rect(); private final Rect mDockedInsetRect = new Rect();
private final Rect mOtherInsetRect = new Rect(); private final Rect mOtherInsetRect = new Rect();
private final Rect mLastResizeRect = new Rect(); private final Rect mLastResizeRect = new Rect();
private final Rect mDisplayRect = new Rect(); private final Rect mTmpRect = new Rect();
private final WindowManagerProxy mWindowManagerProxy = WindowManagerProxy.getInstance(); private final WindowManagerProxy mWindowManagerProxy = WindowManagerProxy.getInstance();
private DividerWindowManager mWindowManager; private DividerWindowManager mWindowManager;
private VelocityTracker mVelocityTracker; private VelocityTracker mVelocityTracker;
@@ -274,6 +276,9 @@ public class DividerView extends FrameLayout implements OnTouchListener,
super(context, attrs, defStyleAttr, defStyleRes); super(context, attrs, defStyleAttr, defStyleRes);
mSfChoreographer = new SurfaceFlingerVsyncChoreographer(mHandler, context.getDisplay(), mSfChoreographer = new SurfaceFlingerVsyncChoreographer(mHandler, context.getDisplay(),
Choreographer.getInstance()); Choreographer.getInstance());
final DisplayManager displayManager =
(DisplayManager) mContext.getSystemService(Context.DISPLAY_SERVICE);
mDefaultDisplay = displayManager.getDisplay(Display.DEFAULT_DISPLAY);
} }
@Override @Override
@@ -373,7 +378,13 @@ public class DividerView extends FrameLayout implements OnTouchListener,
if (mStableInsets.isEmpty()) { if (mStableInsets.isEmpty()) {
SystemServicesProxy.getInstance(mContext).getStableInsets(mStableInsets); SystemServicesProxy.getInstance(mContext).getStableInsets(mStableInsets);
} }
repositionSnapTargetBeforeMinimized();
if (mState.mRatioPositionBeforeMinimized == 0) {
// Set the middle target as the initial state
mSnapTargetBeforeMinimized = mSnapAlgorithm.getMiddleTarget();
} else {
repositionSnapTargetBeforeMinimized();
}
} }
public WindowManagerProxy getWindowManagerProxy() { public WindowManagerProxy getWindowManagerProxy() {
@@ -403,6 +414,11 @@ public class DividerView extends FrameLayout implements OnTouchListener,
mHandle.setTouching(true, animate); mHandle.setTouching(true, animate);
} }
mDockSide = mWindowManagerProxy.getDockSide(); mDockSide = mWindowManagerProxy.getDockSide();
// Update snap algorithm if rotation has occurred
if (mDisplayRotation != mDefaultDisplay.getRotation()) {
updateDisplayInfo();
}
initializeSnapAlgorithm(); initializeSnapAlgorithm();
mWindowManagerProxy.setResizing(true); mWindowManagerProxy.setResizing(true);
if (touching) { if (touching) {
@@ -453,7 +469,7 @@ public class DividerView extends FrameLayout implements OnTouchListener,
private void initializeSnapAlgorithm() { private void initializeSnapAlgorithm() {
if (mSnapAlgorithm == null) { if (mSnapAlgorithm == null) {
mSnapAlgorithm = new DividerSnapAlgorithm(getContext().getResources(), mDisplayWidth, mSnapAlgorithm = new DividerSnapAlgorithm(getContext().getResources(), mDisplayWidth,
mDisplayHeight, mDividerSize, isHorizontalDivision(), mStableInsets); mDisplayHeight, mDividerSize, isHorizontalDivision(), mStableInsets, mDockSide);
} }
if (mMinimizedSnapAlgorithm == null) { if (mMinimizedSnapAlgorithm == null) {
mMinimizedSnapAlgorithm = new DividerSnapAlgorithm(getContext().getResources(), mMinimizedSnapAlgorithm = new DividerSnapAlgorithm(getContext().getResources(),
@@ -620,7 +636,10 @@ public class DividerView extends FrameLayout implements OnTouchListener,
} else { } else {
saveTarget = snapTarget; saveTarget = snapTarget;
} }
saveSnapTargetBeforeMinimized(saveTarget); if (saveTarget.position != mSnapAlgorithm.getDismissEndTarget().position
&& saveTarget.position != mSnapAlgorithm.getDismissStartTarget().position) {
saveSnapTargetBeforeMinimized(saveTarget);
}
} }
}; };
Runnable notCancelledEndAction = () -> { Runnable notCancelledEndAction = () -> {
@@ -764,6 +783,8 @@ public class DividerView extends FrameLayout implements OnTouchListener,
initializeSnapAlgorithm(); initializeSnapAlgorithm();
if (mIsInMinimizeInteraction != minimized) { if (mIsInMinimizeInteraction != minimized) {
if (minimized) { if (minimized) {
// Relayout to recalculate the divider shadow when minimizing
requestLayout();
mIsInMinimizeInteraction = true; mIsInMinimizeInteraction = true;
resizeStack(mMinimizedSnapAlgorithm.getMiddleTarget()); resizeStack(mMinimizedSnapAlgorithm.getMiddleTarget());
} else { } else {
@@ -913,11 +934,9 @@ public class DividerView extends FrameLayout implements OnTouchListener,
} }
private void updateDisplayInfo() { private void updateDisplayInfo() {
final DisplayManager displayManager = mDisplayRotation = mDefaultDisplay.getRotation();
(DisplayManager) mContext.getSystemService(Context.DISPLAY_SERVICE);
Display display = displayManager.getDisplay(Display.DEFAULT_DISPLAY);
final DisplayInfo info = new DisplayInfo(); final DisplayInfo info = new DisplayInfo();
display.getDisplayInfo(info); mDefaultDisplay.getDisplayInfo(info);
mDisplayWidth = info.logicalWidth; mDisplayWidth = info.logicalWidth;
mDisplayHeight = info.logicalHeight; mDisplayHeight = info.logicalHeight;
mSnapAlgorithm = null; mSnapAlgorithm = null;
@@ -991,44 +1010,47 @@ public class DividerView extends FrameLayout implements OnTouchListener,
if (mHomeStackResizable && mIsInMinimizeInteraction) { if (mHomeStackResizable && mIsInMinimizeInteraction) {
calculateBoundsForPosition(mSnapTargetBeforeMinimized.position, mDockSide, calculateBoundsForPosition(mSnapTargetBeforeMinimized.position, mDockSide,
mDockedTaskRect); mDockedTaskRect);
calculateBoundsForPosition(mSnapTargetBeforeMinimized.position,
DockedDividerUtils.invertDockSide(mDockSide), mOtherTaskRect);
// Move a right-docked-app to line up with the divider while dragging it // Move a right-docked-app to line up with the divider while dragging it
if (mDockSide == DOCKED_RIGHT) { if (mDockSide == DOCKED_RIGHT) {
mDockedTaskRect.offset(Math.max(position, mStableInsets.left - mDividerSize) mDockedTaskRect.offset(Math.max(position, mStableInsets.left - mDividerSize)
- mDockedTaskRect.left + mDividerSize, 0); - mDockedTaskRect.left + mDividerSize, 0);
mOtherTaskRect.offset(mStableInsets.left, 0);
} }
calculateBoundsForPosition(mSnapTargetBeforeMinimized.position,
DockedDividerUtils.invertDockSide(mDockSide), mOtherTaskRect);
mWindowManagerProxy.resizeDockedStack(mDockedRect, mDockedTaskRect, mDockedTaskRect, mWindowManagerProxy.resizeDockedStack(mDockedRect, mDockedTaskRect, mDockedTaskRect,
mOtherTaskRect, null); mOtherTaskRect, null);
return; return;
} }
if (mEntranceAnimationRunning && taskPosition != TASK_POSITION_SAME) { if (mEntranceAnimationRunning && taskPosition != TASK_POSITION_SAME) {
if (mCurrentAnimator != null) { calculateBoundsForPosition(taskPosition, mDockSide, mDockedTaskRect);
calculateBoundsForPosition(taskPosition, mDockSide, mDockedTaskRect);
} else {
calculateBoundsForPosition(isHorizontalDivision() ? mDisplayHeight : mDisplayWidth,
mDockSide, mDockedTaskRect);
}
// Move a docked app if from the right in position with the divider up to insets // Move a docked app if from the right in position with the divider up to insets
if (mDockSide == DOCKED_RIGHT) { if (mDockSide == DOCKED_RIGHT) {
mDockedTaskRect.offset(Math.max(position, mDockedTaskRect.offset(Math.max(position, mStableInsets.left - mDividerSize)
mStableInsets.left) - mDockedTaskRect.left, 0); - mDockedTaskRect.left + mDividerSize, 0);
mOtherTaskRect.offset(mStableInsets.left, 0);
} }
calculateBoundsForPosition(taskPosition, DockedDividerUtils.invertDockSide(mDockSide), calculateBoundsForPosition(taskPosition, DockedDividerUtils.invertDockSide(mDockSide),
mOtherTaskRect); mOtherTaskRect);
mWindowManagerProxy.resizeDockedStack(mDockedRect, mDockedTaskRect, null, mWindowManagerProxy.resizeDockedStack(mDockedRect, mDockedTaskRect, null,
mOtherTaskRect, null); mOtherTaskRect, null);
} else if (mExitAnimationRunning && taskPosition != TASK_POSITION_SAME) { } else if (mExitAnimationRunning && taskPosition != TASK_POSITION_SAME) {
calculateBoundsForPosition(taskPosition, calculateBoundsForPosition(taskPosition, mDockSide, mDockedTaskRect);
mDockSide, mDockedTaskRect); mDockedInsetRect.set(mDockedTaskRect);
calculateBoundsForPosition(mExitStartPosition, calculateBoundsForPosition(mExitStartPosition,
DockedDividerUtils.invertDockSide(mDockSide), mOtherTaskRect); DockedDividerUtils.invertDockSide(mDockSide), mOtherTaskRect);
mOtherInsetRect.set(mOtherTaskRect); mOtherInsetRect.set(mOtherTaskRect);
applyExitAnimationParallax(mOtherTaskRect, position); applyExitAnimationParallax(mOtherTaskRect, position);
mWindowManagerProxy.resizeDockedStack(mDockedRect, mDockedTaskRect, null,
// Move a right-docked-app to line up with the divider while dragging it
if (mDockSide == DOCKED_RIGHT) {
mDockedTaskRect.offset(position - mStableInsets.left + mDividerSize, 0);
mOtherTaskRect.offset(mStableInsets.left, 0);
}
mWindowManagerProxy.resizeDockedStack(mDockedRect, mDockedTaskRect, mDockedInsetRect,
mOtherTaskRect, mOtherInsetRect); mOtherTaskRect, mOtherInsetRect);
} else if (taskPosition != TASK_POSITION_SAME) { } else if (taskPosition != TASK_POSITION_SAME) {
calculateBoundsForPosition(position, DockedDividerUtils.invertDockSide(mDockSide), calculateBoundsForPosition(position, DockedDividerUtils.invertDockSide(mDockSide),
@@ -1040,17 +1062,17 @@ public class DividerView extends FrameLayout implements OnTouchListener,
restrictDismissingTaskPosition(taskPosition, dockSideInverted, taskSnapTarget); restrictDismissingTaskPosition(taskPosition, dockSideInverted, taskSnapTarget);
calculateBoundsForPosition(taskPositionDocked, mDockSide, mDockedTaskRect); calculateBoundsForPosition(taskPositionDocked, mDockSide, mDockedTaskRect);
calculateBoundsForPosition(taskPositionOther, dockSideInverted, mOtherTaskRect); calculateBoundsForPosition(taskPositionOther, dockSideInverted, mOtherTaskRect);
mDisplayRect.set(0, 0, mDisplayWidth, mDisplayHeight); mTmpRect.set(0, 0, mDisplayWidth, mDisplayHeight);
alignTopLeft(mDockedRect, mDockedTaskRect); alignTopLeft(mDockedRect, mDockedTaskRect);
alignTopLeft(mOtherRect, mOtherTaskRect); alignTopLeft(mOtherRect, mOtherTaskRect);
mDockedInsetRect.set(mDockedTaskRect); mDockedInsetRect.set(mDockedTaskRect);
mOtherInsetRect.set(mOtherTaskRect); mOtherInsetRect.set(mOtherTaskRect);
if (dockSideTopLeft(mDockSide)) { if (dockSideTopLeft(mDockSide)) {
alignTopLeft(mDisplayRect, mDockedInsetRect); alignTopLeft(mTmpRect, mDockedInsetRect);
alignBottomRight(mDisplayRect, mOtherInsetRect); alignBottomRight(mTmpRect, mOtherInsetRect);
} else { } else {
alignBottomRight(mDisplayRect, mDockedInsetRect); alignBottomRight(mTmpRect, mDockedInsetRect);
alignTopLeft(mDisplayRect, mOtherInsetRect); alignTopLeft(mTmpRect, mOtherInsetRect);
} }
applyDismissingParallax(mDockedTaskRect, mDockSide, taskSnapTarget, position, applyDismissingParallax(mDockedTaskRect, mDockSide, taskSnapTarget, position,
taskPositionDocked); taskPositionDocked);
@@ -1269,23 +1291,22 @@ public class DividerView extends FrameLayout implements OnTouchListener,
startDragging(false /* animate */, false /* touching */); startDragging(false /* animate */, false /* touching */);
} }
updateDockSide(); updateDockSide();
int position = DockedDividerUtils.calculatePositionForBounds(event.initialRect,
mDockSide, mDividerSize);
mEntranceAnimationRunning = true; mEntranceAnimationRunning = true;
resizeStack(position, mSnapAlgorithm.getMiddleTarget().position, resizeStack(calculatePositionForInsetBounds(), mSnapAlgorithm.getMiddleTarget().position,
mSnapAlgorithm.getMiddleTarget()); mSnapAlgorithm.getMiddleTarget());
} }
public void onRecentsDrawn() { public void onRecentsDrawn() {
updateDockSide();
final int position = calculatePositionForInsetBounds();
if (mState.animateAfterRecentsDrawn) { if (mState.animateAfterRecentsDrawn) {
mState.animateAfterRecentsDrawn = false; mState.animateAfterRecentsDrawn = false;
updateDockSide();
mHandler.post(() -> { mHandler.post(() -> {
// Delay switching resizing mode because this might cause jank in recents animation // Delay switching resizing mode because this might cause jank in recents animation
// that's longer than this animation. // that's longer than this animation.
stopDragging(getCurrentPosition(), mSnapAlgorithm.getMiddleTarget(), stopDragging(position, getSnapAlgorithm().getMiddleTarget(),
mLongPressEntraceAnimDuration, Interpolators.FAST_OUT_SLOW_IN, mLongPressEntraceAnimDuration, Interpolators.FAST_OUT_SLOW_IN,
200 /* endDelay */); 200 /* endDelay */);
}); });
@@ -1294,7 +1315,7 @@ public class DividerView extends FrameLayout implements OnTouchListener,
mState.growAfterRecentsDrawn = false; mState.growAfterRecentsDrawn = false;
updateDockSide(); updateDockSide();
EventBus.getDefault().send(new RecentsGrowingEvent()); EventBus.getDefault().send(new RecentsGrowingEvent());
stopDragging(getCurrentPosition(), mSnapAlgorithm.getMiddleTarget(), 336, stopDragging(position, getSnapAlgorithm().getMiddleTarget(), 336,
Interpolators.FAST_OUT_SLOW_IN); Interpolators.FAST_OUT_SLOW_IN);
} }
} }
@@ -1315,4 +1336,10 @@ public class DividerView extends FrameLayout implements OnTouchListener,
0 /* endDelay */, Interpolators.FAST_OUT_SLOW_IN); 0 /* endDelay */, Interpolators.FAST_OUT_SLOW_IN);
} }
} }
private int calculatePositionForInsetBounds() {
mTmpRect.set(0, 0, mDisplayWidth, mDisplayHeight);
mTmpRect.inset(mStableInsets);
return DockedDividerUtils.calculatePositionForBounds(mTmpRect, mDockSide, mDividerSize);
}
} }

View File

@@ -639,6 +639,9 @@ class ActivityStack<T extends StackWindowController> extends ConfigurationContai
// so that the divider matches and remove this logic. // so that the divider matches and remove this logic.
// TODO: This is currently only called when entering split-screen while in another // TODO: This is currently only called when entering split-screen while in another
// task, and from the tests // task, and from the tests
// TODO (b/78247419): Check if launcher and overview are same then move home stack
// instead of recents stack. Then fix the rotation animation from fullscreen to
// minimized mode
final ActivityStack recentStack = display.getOrCreateStack( final ActivityStack recentStack = display.getOrCreateStack(
WINDOWING_MODE_SPLIT_SCREEN_SECONDARY, ACTIVITY_TYPE_RECENTS, WINDOWING_MODE_SPLIT_SCREEN_SECONDARY, ACTIVITY_TYPE_RECENTS,
true /* onTop */); true /* onTop */);