Merge "Calculates the window height fraction on screen by the draggable bounds for magnification switch button" into sc-dev am: 70aaf815b6

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/14921895

Change-Id: I3e75bc49991c1682f7c36474dcf07496618817aa
This commit is contained in:
Minche Li
2021-06-16 05:20:24 +00:00
committed by Automerger Merge Worker
2 changed files with 14 additions and 15 deletions

View File

@@ -75,7 +75,6 @@ class MagnificationModeSwitch implements MagnificationGestureDetector.OnGestureL
private final SfVsyncFrameCallbackProvider mSfVsyncFrameProvider; private final SfVsyncFrameCallbackProvider mSfVsyncFrameProvider;
private int mMagnificationMode = ACCESSIBILITY_MAGNIFICATION_MODE_NONE; private int mMagnificationMode = ACCESSIBILITY_MAGNIFICATION_MODE_NONE;
private final LayoutParams mParams; private final LayoutParams mParams;
private int mWindowHeight;
@VisibleForTesting @VisibleForTesting
final Rect mDraggableWindowBounds = new Rect(); final Rect mDraggableWindowBounds = new Rect();
private boolean mIsVisible = false; private boolean mIsVisible = false;
@@ -95,7 +94,6 @@ class MagnificationModeSwitch implements MagnificationGestureDetector.OnGestureL
mWindowManager = mContext.getSystemService(WindowManager.class); mWindowManager = mContext.getSystemService(WindowManager.class);
mSfVsyncFrameProvider = sfVsyncFrameProvider; mSfVsyncFrameProvider = sfVsyncFrameProvider;
mParams = createLayoutParams(context); mParams = createLayoutParams(context);
mWindowHeight = mWindowManager.getCurrentWindowMetrics().getBounds().height();
mImageView = imageView; mImageView = imageView;
mImageView.setOnTouchListener(this::onTouch); mImageView.setOnTouchListener(this::onTouch);
mImageView.setAccessibilityDelegate(new View.AccessibilityDelegate() { mImageView.setAccessibilityDelegate(new View.AccessibilityDelegate() {
@@ -313,12 +311,14 @@ class MagnificationModeSwitch implements MagnificationGestureDetector.OnGestureL
void onConfigurationChanged(int configDiff) { void onConfigurationChanged(int configDiff) {
if ((configDiff & ActivityInfo.CONFIG_ORIENTATION) != 0) { if ((configDiff & ActivityInfo.CONFIG_ORIENTATION) != 0) {
final Rect previousDraggableBounds = new Rect(mDraggableWindowBounds);
mDraggableWindowBounds.set(getDraggableWindowBounds()); mDraggableWindowBounds.set(getDraggableWindowBounds());
// Keep the Y position with the same height ratio before the window height is changed. // Keep the Y position with the same height ratio before the window bounds and
final int windowHeight = mWindowManager.getCurrentWindowMetrics().getBounds().height(); // draggable bounds are changed.
final float windowHeightFraction = (float) mParams.y / mWindowHeight; final float windowHeightFraction = (float) (mParams.y - previousDraggableBounds.top)
mParams.y = (int) (windowHeight * windowHeightFraction); / previousDraggableBounds.height();
mWindowHeight = windowHeight; mParams.y = (int) (windowHeightFraction * mDraggableWindowBounds.height())
+ mDraggableWindowBounds.top;
stickToScreenEdge(mToLeftScreenEdge); stickToScreenEdge(mToLeftScreenEdge);
return; return;
} }

View File

@@ -59,7 +59,6 @@ import android.os.UserHandle;
import android.provider.Settings; import android.provider.Settings;
import android.testing.AndroidTestingRunner; import android.testing.AndroidTestingRunner;
import android.testing.TestableLooper; import android.testing.TestableLooper;
import android.util.MathUtils;
import android.view.Choreographer; import android.view.Choreographer;
import android.view.MotionEvent; import android.view.MotionEvent;
import android.view.View; import android.view.View;
@@ -489,20 +488,20 @@ public class MagnificationModeSwitchTest extends SysuiTestCase {
@Test @Test
public void onRotationChanged_buttonIsShowing_expectedYPosition() { public void onRotationChanged_buttonIsShowing_expectedYPosition() {
final Rect windowBounds = mWindowManager.getCurrentWindowMetrics().getBounds(); final Rect windowBounds = mWindowManager.getCurrentWindowMetrics().getBounds();
final int oldWindowHeight = windowBounds.height();
mMagnificationModeSwitch.showButton(ACCESSIBILITY_MAGNIFICATION_MODE_FULLSCREEN); mMagnificationModeSwitch.showButton(ACCESSIBILITY_MAGNIFICATION_MODE_FULLSCREEN);
final Rect oldDraggableBounds = new Rect(mMagnificationModeSwitch.mDraggableWindowBounds);
final float windowHeightFraction = final float windowHeightFraction =
(float) mWindowManager.getLayoutParamsFromAttachedView().y / oldWindowHeight; (float) (mWindowManager.getLayoutParamsFromAttachedView().y
- oldDraggableBounds.top) / oldDraggableBounds.height();
// The window bounds are changed due to the rotation change. // The window bounds and the draggable bounds are changed due to the rotation change.
final Rect newWindowBounds = new Rect(0, 0, windowBounds.height(), windowBounds.width()); final Rect newWindowBounds = new Rect(0, 0, windowBounds.height(), windowBounds.width());
mWindowManager.setWindowBounds(newWindowBounds); mWindowManager.setWindowBounds(newWindowBounds);
mMagnificationModeSwitch.onConfigurationChanged(ActivityInfo.CONFIG_ORIENTATION); mMagnificationModeSwitch.onConfigurationChanged(ActivityInfo.CONFIG_ORIENTATION);
int expectedY = (int) (newWindowBounds.height() * windowHeightFraction); int expectedY = (int) (windowHeightFraction
expectedY = MathUtils.constrain(expectedY, * mMagnificationModeSwitch.mDraggableWindowBounds.height())
mMagnificationModeSwitch.mDraggableWindowBounds.top, + mMagnificationModeSwitch.mDraggableWindowBounds.top;
mMagnificationModeSwitch.mDraggableWindowBounds.bottom);
assertEquals( assertEquals(
"The Y position does not keep the same height ratio after the rotation changed.", "The Y position does not keep the same height ratio after the rotation changed.",
expectedY, mWindowManager.getLayoutParamsFromAttachedView().y); expectedY, mWindowManager.getLayoutParamsFromAttachedView().y);