From fbc5f923aae7afbce174e161583045f91cb8fbb9 Mon Sep 17 00:00:00 2001 From: Tony Huang Date: Thu, 19 Aug 2021 16:57:14 +0800 Subject: [PATCH] Keep split bounds after configuration update Before this change, split bounds always reset to half-half if rotation. This is weird on large screen devices because they can scale bounds in landscape too, so bounds will reset even if from landscape to seascape. Add restore mechanism by compute ration of current divider and total length. Use this ratio to compute estimate position in new configuration then get suitable snap target. Update divider position and split bounds by this snap target postition. Fix: 192533269 Test: pass existing tests Test: Set density to large screen, active stage split and make top task larger then rotate to landscape. Change-Id: I3ea12273348575ae968c76bdf9236155380526ec --- .../wm/shell/common/split/SplitLayout.java | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/common/split/SplitLayout.java b/libs/WindowManager/Shell/src/com/android/wm/shell/common/split/SplitLayout.java index 569cc1fe7467c..7f84cc2eb5d13 100644 --- a/libs/WindowManager/Shell/src/com/android/wm/shell/common/split/SplitLayout.java +++ b/libs/WindowManager/Shell/src/com/android/wm/shell/common/split/SplitLayout.java @@ -92,6 +92,7 @@ public final class SplitLayout { private final Rect mDividerBounds = new Rect(); private final Rect mBounds1 = new Rect(); private final Rect mBounds2 = new Rect(); + private final Rect mTmpBounds = new Rect(); private final SplitLayoutHandler mSplitLayoutHandler; private final SplitWindowManager mSplitWindowManager; private final DisplayImeController mDisplayImeController; @@ -187,9 +188,10 @@ public final class SplitLayout { final int rotation = configuration.windowConfiguration.getRotation(); final Rect rootBounds = configuration.windowConfiguration.getBounds(); if (rotation != mRotation || !mRootBounds.equals(rootBounds)) { + mTmpBounds.set(mRootBounds); mRootBounds.set(rootBounds); mDividerSnapAlgorithm = getSnapAlgorithm(mContext, mRootBounds); - resetDividerPosition(); + initDividerPosition(mTmpBounds); affectsLayout = true; } @@ -201,6 +203,19 @@ public final class SplitLayout { return affectsLayout; } + private void initDividerPosition(Rect oldBounds) { + final float snapRatio = (float) mDividePosition + / (float) (isLandscape(oldBounds) ? oldBounds.width() : oldBounds.height()); + // Estimate position by previous ratio. + final float length = + (float) (isLandscape() ? mRootBounds.width() : mRootBounds.height()); + final int estimatePosition = (int) (length * snapRatio); + // Init divider position by estimated position using current bounds snap algorithm. + mDividePosition = mDividerSnapAlgorithm.calculateNonDismissingSnapTarget( + estimatePosition).position; + updateBounds(mDividePosition); + } + /** Updates recording bounds of divider window and both of the splits. */ private void updateBounds(int position) { mDividerBounds.set(mRootBounds);