Merge "Prevent rendering divider bar into wrong orientation" into sc-v2-dev am: 85c712a6ba
Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/14703484 Change-Id: Ie77908c13e56204e88b83c4df2dfab8944ef232d
This commit is contained in:
@@ -92,12 +92,16 @@ public final class SplitLayout {
|
|||||||
private DividerSnapAlgorithm mDividerSnapAlgorithm;
|
private DividerSnapAlgorithm mDividerSnapAlgorithm;
|
||||||
private int mDividePosition;
|
private int mDividePosition;
|
||||||
private boolean mInitialized = false;
|
private boolean mInitialized = false;
|
||||||
|
private int mOrientation;
|
||||||
|
private int mRotation;
|
||||||
|
|
||||||
public SplitLayout(String windowName, Context context, Configuration configuration,
|
public SplitLayout(String windowName, Context context, Configuration configuration,
|
||||||
SplitLayoutHandler splitLayoutHandler,
|
SplitLayoutHandler splitLayoutHandler,
|
||||||
SplitWindowManager.ParentContainerCallbacks parentContainerCallbacks,
|
SplitWindowManager.ParentContainerCallbacks parentContainerCallbacks,
|
||||||
DisplayImeController displayImeController, ShellTaskOrganizer taskOrganizer) {
|
DisplayImeController displayImeController, ShellTaskOrganizer taskOrganizer) {
|
||||||
mContext = context.createConfigurationContext(configuration);
|
mContext = context.createConfigurationContext(configuration);
|
||||||
|
mOrientation = configuration.orientation;
|
||||||
|
mRotation = configuration.windowConfiguration.getRotation();
|
||||||
mSplitLayoutHandler = splitLayoutHandler;
|
mSplitLayoutHandler = splitLayoutHandler;
|
||||||
mDisplayImeController = displayImeController;
|
mDisplayImeController = displayImeController;
|
||||||
mSplitWindowManager = new SplitWindowManager(
|
mSplitWindowManager = new SplitWindowManager(
|
||||||
@@ -144,27 +148,39 @@ public final class SplitLayout {
|
|||||||
|
|
||||||
/** Applies new configuration, returns {@code false} if there's no effect to the layout. */
|
/** Applies new configuration, returns {@code false} if there's no effect to the layout. */
|
||||||
public boolean updateConfiguration(Configuration configuration) {
|
public boolean updateConfiguration(Configuration configuration) {
|
||||||
final Rect rootBounds = configuration.windowConfiguration.getBounds();
|
boolean affectsLayout = false;
|
||||||
if (mRootBounds.equals(rootBounds)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
// Make sure to render the divider bar with proper resources that matching the screen
|
||||||
|
// orientation.
|
||||||
|
final int orientation = configuration.orientation;
|
||||||
|
if (orientation != mOrientation) {
|
||||||
|
mOrientation = orientation;
|
||||||
mContext = mContext.createConfigurationContext(configuration);
|
mContext = mContext.createConfigurationContext(configuration);
|
||||||
mSplitWindowManager.setConfiguration(configuration);
|
mSplitWindowManager.setConfiguration(configuration);
|
||||||
|
affectsLayout = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Update the split bounds when necessary. Besides root bounds changed, split bounds need to
|
||||||
|
// be updated when the rotation changed to cover the case that users rotated the screen 180
|
||||||
|
// degrees.
|
||||||
|
final int rotation = configuration.windowConfiguration.getRotation();
|
||||||
|
final Rect rootBounds = configuration.windowConfiguration.getBounds();
|
||||||
|
if (rotation != mRotation || !mRootBounds.equals(rootBounds)) {
|
||||||
mRootBounds.set(rootBounds);
|
mRootBounds.set(rootBounds);
|
||||||
mDividerSnapAlgorithm = getSnapAlgorithm(mContext, mRootBounds);
|
mDividerSnapAlgorithm = getSnapAlgorithm(mContext, mRootBounds);
|
||||||
resetDividerPosition();
|
resetDividerPosition();
|
||||||
|
affectsLayout = true;
|
||||||
// Don't inflate divider bar if it is not initialized.
|
|
||||||
if (!mInitialized) {
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (mInitialized && affectsLayout) {
|
||||||
release();
|
release();
|
||||||
init();
|
init();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
/** Updates recording bounds of divider window and both of the splits. */
|
/** Updates recording bounds of divider window and both of the splits. */
|
||||||
private void updateBounds(int position) {
|
private void updateBounds(int position) {
|
||||||
mDividerBounds.set(mRootBounds);
|
mDividerBounds.set(mRootBounds);
|
||||||
|
|||||||
@@ -61,7 +61,7 @@ public class SplitLayoutTests extends ShellTestCase {
|
|||||||
mSplitLayout = new SplitLayout(
|
mSplitLayout = new SplitLayout(
|
||||||
"TestSplitLayout",
|
"TestSplitLayout",
|
||||||
mContext,
|
mContext,
|
||||||
getConfiguration(false),
|
getConfiguration(),
|
||||||
mSplitLayoutHandler,
|
mSplitLayoutHandler,
|
||||||
b -> b.setParent(mRootLeash),
|
b -> b.setParent(mRootLeash),
|
||||||
mDisplayImeController,
|
mDisplayImeController,
|
||||||
@@ -71,9 +71,23 @@ public class SplitLayoutTests extends ShellTestCase {
|
|||||||
@Test
|
@Test
|
||||||
@UiThreadTest
|
@UiThreadTest
|
||||||
public void testUpdateConfiguration() {
|
public void testUpdateConfiguration() {
|
||||||
|
final Configuration config = getConfiguration();
|
||||||
mSplitLayout.init();
|
mSplitLayout.init();
|
||||||
assertThat(mSplitLayout.updateConfiguration(getConfiguration(false))).isFalse();
|
|
||||||
assertThat(mSplitLayout.updateConfiguration(getConfiguration(true))).isTrue();
|
// Verify it returns true if new config won't affect split layout.
|
||||||
|
assertThat(mSplitLayout.updateConfiguration(config)).isFalse();
|
||||||
|
|
||||||
|
// Verify updateConfiguration returns true if the orientation changed.
|
||||||
|
config.orientation = ORIENTATION_LANDSCAPE;
|
||||||
|
assertThat(mSplitLayout.updateConfiguration(config)).isTrue();
|
||||||
|
|
||||||
|
// Verify updateConfiguration returns true if it rotated.
|
||||||
|
config.windowConfiguration.setRotation(1);
|
||||||
|
assertThat(mSplitLayout.updateConfiguration(config)).isTrue();
|
||||||
|
|
||||||
|
// Verify updateConfiguration returns true if the root bounds changed.
|
||||||
|
config.windowConfiguration.setBounds(new Rect(0, 0, 2160, 1080));
|
||||||
|
assertThat(mSplitLayout.updateConfiguration(config)).isTrue();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -108,12 +122,13 @@ public class SplitLayoutTests extends ShellTestCase {
|
|||||||
verify(mSplitLayoutHandler).onSnappedToDismiss(eq(true));
|
verify(mSplitLayoutHandler).onSnappedToDismiss(eq(true));
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Configuration getConfiguration(boolean isLandscape) {
|
private static Configuration getConfiguration() {
|
||||||
final Configuration configuration = new Configuration();
|
final Configuration configuration = new Configuration();
|
||||||
configuration.unset();
|
configuration.unset();
|
||||||
configuration.orientation = isLandscape ? ORIENTATION_LANDSCAPE : ORIENTATION_PORTRAIT;
|
configuration.orientation = ORIENTATION_PORTRAIT;
|
||||||
|
configuration.windowConfiguration.setRotation(0);
|
||||||
configuration.windowConfiguration.setBounds(
|
configuration.windowConfiguration.setBounds(
|
||||||
new Rect(0, 0, isLandscape ? 2160 : 1080, isLandscape ? 1080 : 2160));
|
new Rect(0, 0, 1080, 2160));
|
||||||
return configuration;
|
return configuration;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user