Indicate whether to apply layout change when setting divide position
To prevent it conflicting with shell transition when entering split, we
don't want to apply layout change when setting up divide position. Add a
boolean parameter to indicate whether to apply layout change or not for
setDividePosition.
Bug: 206487881
Bug: 208954095
Test: Trigger split screen, snap divider to non-middle position and
observed no crash after dismissed and re-entered split screen.
Change-Id: I91ba735ade538e1bb3d5a5eba0c782c4456e1746
This commit is contained in:
@@ -93,7 +93,7 @@ public final class SplitLayout implements DisplayInsetsController.OnInsetsChange
|
||||
private final InsetsState mInsetsState = new InsetsState();
|
||||
|
||||
private Context mContext;
|
||||
private DividerSnapAlgorithm mDividerSnapAlgorithm;
|
||||
@VisibleForTesting DividerSnapAlgorithm mDividerSnapAlgorithm;
|
||||
private WindowContainerToken mWinToken1;
|
||||
private WindowContainerToken mWinToken2;
|
||||
private int mDividePosition;
|
||||
@@ -294,20 +294,22 @@ public final class SplitLayout implements DisplayInsetsController.OnInsetsChange
|
||||
mSplitLayoutHandler.onLayoutSizeChanging(this);
|
||||
}
|
||||
|
||||
void setDividePosition(int position) {
|
||||
void setDividePosition(int position, boolean applyLayoutChange) {
|
||||
mDividePosition = position;
|
||||
updateBounds(mDividePosition);
|
||||
mSplitLayoutHandler.onLayoutSizeChanged(this);
|
||||
if (applyLayoutChange) {
|
||||
mSplitLayoutHandler.onLayoutSizeChanged(this);
|
||||
}
|
||||
}
|
||||
|
||||
/** Sets divide position base on the ratio within root bounds. */
|
||||
/** Updates divide position and split bounds base on the ratio within root bounds. */
|
||||
public void setDivideRatio(float ratio) {
|
||||
final int position = isLandscape()
|
||||
? mRootBounds.left + (int) (mRootBounds.width() * ratio)
|
||||
: mRootBounds.top + (int) (mRootBounds.height() * ratio);
|
||||
DividerSnapAlgorithm.SnapTarget snapTarget =
|
||||
final DividerSnapAlgorithm.SnapTarget snapTarget =
|
||||
mDividerSnapAlgorithm.calculateNonDismissingSnapTarget(position);
|
||||
setDividePosition(snapTarget.position);
|
||||
setDividePosition(snapTarget.position, false /* applyLayoutChange */);
|
||||
}
|
||||
|
||||
/** Resets divider position. */
|
||||
@@ -336,7 +338,7 @@ public final class SplitLayout implements DisplayInsetsController.OnInsetsChange
|
||||
break;
|
||||
default:
|
||||
flingDividePosition(currentPosition, snapTarget.position,
|
||||
() -> setDividePosition(snapTarget.position));
|
||||
() -> setDividePosition(snapTarget.position, true /* applyLayoutChange */));
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -389,7 +391,7 @@ public final class SplitLayout implements DisplayInsetsController.OnInsetsChange
|
||||
|
||||
@Override
|
||||
public void onAnimationCancel(Animator animation) {
|
||||
setDividePosition(to);
|
||||
setDividePosition(to, true /* applyLayoutChange */);
|
||||
}
|
||||
});
|
||||
animator.start();
|
||||
|
||||
@@ -341,12 +341,12 @@ class StageCoordinator implements SplitLayout.SplitLayoutHandler,
|
||||
sideOptions = sideOptions != null ? sideOptions : new Bundle();
|
||||
setSideStagePosition(sidePosition, wct);
|
||||
|
||||
mSplitLayout.setDivideRatio(splitRatio);
|
||||
// Build a request WCT that will launch both apps such that task 0 is on the main stage
|
||||
// while task 1 is on the side stage.
|
||||
mMainStage.activate(getMainStageBounds(), wct, false /* reparent */);
|
||||
mSideStage.setBounds(getSideStageBounds(), wct);
|
||||
|
||||
mSplitLayout.setDivideRatio(splitRatio);
|
||||
// Make sure the launch options will put tasks in the corresponding split roots
|
||||
addActivityOptions(mainOptions, mMainStage);
|
||||
addActivityOptions(sideOptions, mSideStage);
|
||||
|
||||
@@ -24,6 +24,7 @@ import static com.google.common.truth.Truth.assertThat;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.anyInt;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.Mockito.never;
|
||||
import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.verify;
|
||||
|
||||
@@ -101,14 +102,21 @@ public class SplitLayoutTests extends ShellTestCase {
|
||||
|
||||
@Test
|
||||
public void testSetDividePosition() {
|
||||
mSplitLayout.setDividePosition(anyInt());
|
||||
mSplitLayout.setDividePosition(100, false /* applyLayoutChange */);
|
||||
assertThat(mSplitLayout.getDividePosition()).isEqualTo(100);
|
||||
verify(mSplitLayoutHandler, never()).onLayoutSizeChanged(any(SplitLayout.class));
|
||||
|
||||
mSplitLayout.setDividePosition(200, true /* applyLayoutChange */);
|
||||
assertThat(mSplitLayout.getDividePosition()).isEqualTo(200);
|
||||
verify(mSplitLayoutHandler).onLayoutSizeChanged(any(SplitLayout.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSetDivideRatio() {
|
||||
mSplitLayout.setDividePosition(200, false /* applyLayoutChange */);
|
||||
mSplitLayout.setDivideRatio(0.5f);
|
||||
verify(mSplitLayoutHandler).onLayoutSizeChanged(any(SplitLayout.class));
|
||||
assertThat(mSplitLayout.getDividePosition()).isEqualTo(
|
||||
mSplitLayout.mDividerSnapAlgorithm.getMiddleTarget().position);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
Reference in New Issue
Block a user