Merge "Indicate whether to apply layout change when setting divide position"
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();
|
||||
|
||||
@@ -342,12 +342,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