Calculates the window height fraction on screen by the draggable bounds for magnification switch button
In the previous change ag/14776093, the window height fraction used "windowHeightFraction = (float) mParams.y / mWindowHeight;". And it causes the Y-position deviated after the rotation is changed. To correct this, we used the draggable bounds to calculate the window height fraction. See b/189715285#comment3 Bug: 189715285 Test: atest MagnificationModeSwitchTest Change-Id: I1adcea12f0a96c64c9c6e386dc2feb8e3a9ffcf3
This commit is contained in:
@@ -75,7 +75,6 @@ class MagnificationModeSwitch implements MagnificationGestureDetector.OnGestureL
|
||||
private final SfVsyncFrameCallbackProvider mSfVsyncFrameProvider;
|
||||
private int mMagnificationMode = ACCESSIBILITY_MAGNIFICATION_MODE_NONE;
|
||||
private final LayoutParams mParams;
|
||||
private int mWindowHeight;
|
||||
@VisibleForTesting
|
||||
final Rect mDraggableWindowBounds = new Rect();
|
||||
private boolean mIsVisible = false;
|
||||
@@ -95,7 +94,6 @@ class MagnificationModeSwitch implements MagnificationGestureDetector.OnGestureL
|
||||
mWindowManager = mContext.getSystemService(WindowManager.class);
|
||||
mSfVsyncFrameProvider = sfVsyncFrameProvider;
|
||||
mParams = createLayoutParams(context);
|
||||
mWindowHeight = mWindowManager.getCurrentWindowMetrics().getBounds().height();
|
||||
mImageView = imageView;
|
||||
mImageView.setOnTouchListener(this::onTouch);
|
||||
mImageView.setAccessibilityDelegate(new View.AccessibilityDelegate() {
|
||||
@@ -313,12 +311,14 @@ class MagnificationModeSwitch implements MagnificationGestureDetector.OnGestureL
|
||||
|
||||
void onConfigurationChanged(int configDiff) {
|
||||
if ((configDiff & ActivityInfo.CONFIG_ORIENTATION) != 0) {
|
||||
final Rect previousDraggableBounds = new Rect(mDraggableWindowBounds);
|
||||
mDraggableWindowBounds.set(getDraggableWindowBounds());
|
||||
// Keep the Y position with the same height ratio before the window height is changed.
|
||||
final int windowHeight = mWindowManager.getCurrentWindowMetrics().getBounds().height();
|
||||
final float windowHeightFraction = (float) mParams.y / mWindowHeight;
|
||||
mParams.y = (int) (windowHeight * windowHeightFraction);
|
||||
mWindowHeight = windowHeight;
|
||||
// Keep the Y position with the same height ratio before the window bounds and
|
||||
// draggable bounds are changed.
|
||||
final float windowHeightFraction = (float) (mParams.y - previousDraggableBounds.top)
|
||||
/ previousDraggableBounds.height();
|
||||
mParams.y = (int) (windowHeightFraction * mDraggableWindowBounds.height())
|
||||
+ mDraggableWindowBounds.top;
|
||||
stickToScreenEdge(mToLeftScreenEdge);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -59,7 +59,6 @@ import android.os.UserHandle;
|
||||
import android.provider.Settings;
|
||||
import android.testing.AndroidTestingRunner;
|
||||
import android.testing.TestableLooper;
|
||||
import android.util.MathUtils;
|
||||
import android.view.Choreographer;
|
||||
import android.view.MotionEvent;
|
||||
import android.view.View;
|
||||
@@ -489,20 +488,20 @@ public class MagnificationModeSwitchTest extends SysuiTestCase {
|
||||
@Test
|
||||
public void onRotationChanged_buttonIsShowing_expectedYPosition() {
|
||||
final Rect windowBounds = mWindowManager.getCurrentWindowMetrics().getBounds();
|
||||
final int oldWindowHeight = windowBounds.height();
|
||||
mMagnificationModeSwitch.showButton(ACCESSIBILITY_MAGNIFICATION_MODE_FULLSCREEN);
|
||||
final Rect oldDraggableBounds = new Rect(mMagnificationModeSwitch.mDraggableWindowBounds);
|
||||
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());
|
||||
mWindowManager.setWindowBounds(newWindowBounds);
|
||||
mMagnificationModeSwitch.onConfigurationChanged(ActivityInfo.CONFIG_ORIENTATION);
|
||||
|
||||
int expectedY = (int) (newWindowBounds.height() * windowHeightFraction);
|
||||
expectedY = MathUtils.constrain(expectedY,
|
||||
mMagnificationModeSwitch.mDraggableWindowBounds.top,
|
||||
mMagnificationModeSwitch.mDraggableWindowBounds.bottom);
|
||||
int expectedY = (int) (windowHeightFraction
|
||||
* mMagnificationModeSwitch.mDraggableWindowBounds.height())
|
||||
+ mMagnificationModeSwitch.mDraggableWindowBounds.top;
|
||||
assertEquals(
|
||||
"The Y position does not keep the same height ratio after the rotation changed.",
|
||||
expectedY, mWindowManager.getLayoutParamsFromAttachedView().y);
|
||||
|
||||
Reference in New Issue
Block a user