Merge "Keeps the Y position with the same height ratio before the window height is changed" into sc-dev

This commit is contained in:
Minche Li
2021-06-03 01:39:20 +00:00
committed by Android (Google) Code Review
3 changed files with 55 additions and 1 deletions

View File

@@ -75,6 +75,7 @@ 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;
@@ -94,6 +95,7 @@ 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() {
@@ -310,6 +312,16 @@ class MagnificationModeSwitch implements MagnificationGestureDetector.OnGestureL
}
void onConfigurationChanged(int configDiff) {
if ((configDiff & ActivityInfo.CONFIG_ORIENTATION) != 0) {
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;
stickToScreenEdge(mToLeftScreenEdge);
return;
}
if ((configDiff & ActivityInfo.CONFIG_DENSITY) != 0) {
applyResourcesValuesWithDensityChanged();
return;

View File

@@ -59,6 +59,7 @@ 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;
@@ -251,6 +252,18 @@ public class MagnificationModeSwitchTest extends SysuiTestCase {
assertNotEquals(oldDraggableBounds, mMagnificationModeSwitch.mDraggableWindowBounds);
}
@Test
public void onWindowBoundsChanged_buttonIsShowing_draggableBoundsChanged() {
mWindowManager.setWindowBounds(new Rect(0, 0, 800, 1000));
mMagnificationModeSwitch.showButton(ACCESSIBILITY_MAGNIFICATION_MODE_FULLSCREEN);
final Rect oldDraggableBounds = new Rect(mMagnificationModeSwitch.mDraggableWindowBounds);
mWindowManager.setWindowBounds(new Rect(0, 0, 1000, 800));
mSpyImageView.onApplyWindowInsets(WindowInsets.CONSUMED);
assertNotEquals(oldDraggableBounds, mMagnificationModeSwitch.mDraggableWindowBounds);
}
@Test
public void onDraggingGestureFinish_buttonIsShowing_stickToRightEdge() {
final int windowHalfWidth =
@@ -473,6 +486,28 @@ public class MagnificationModeSwitchTest extends SysuiTestCase {
assertEquals(newA11yWindowTitle, layoutParams.accessibilityTitle);
}
@Test
public void onRotationChanged_buttonIsShowing_expectedYPosition() {
final Rect windowBounds = mWindowManager.getCurrentWindowMetrics().getBounds();
final int oldWindowHeight = windowBounds.height();
mMagnificationModeSwitch.showButton(ACCESSIBILITY_MAGNIFICATION_MODE_FULLSCREEN);
final float windowHeightFraction =
(float) mWindowManager.getLayoutParamsFromAttachedView().y / oldWindowHeight;
// The window 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);
assertEquals(
"The Y position does not keep the same height ratio after the rotation changed.",
expectedY, mWindowManager.getLayoutParamsFromAttachedView().y);
}
private void assertModeUnchanged(int expectedMode) {
final int actualMode = Settings.Secure.getInt(mContext.getContentResolver(),
Settings.Secure.ACCESSIBILITY_MAGNIFICATION_MODE, 0);

View File

@@ -19,6 +19,7 @@ package com.android.systemui.accessibility;
import static android.view.WindowInsets.Type.systemGestures;
import android.graphics.Insets;
import android.graphics.Rect;
import android.graphics.Region;
import android.view.Display;
import android.view.View;
@@ -31,6 +32,7 @@ public class TestableWindowManager implements WindowManager {
private final WindowManager mWindowManager;
private View mView;
private Rect mWindowBounds = null;
private WindowInsets mWindowInsets = null;
TestableWindowManager(WindowManager windowManager) {
@@ -82,7 +84,8 @@ public class TestableWindowManager implements WindowManager {
.setInsets(systemGestures(), systemGesturesInsets)
.build();
final WindowMetrics windowMetrics = new WindowMetrics(
mWindowManager.getCurrentWindowMetrics().getBounds(),
mWindowBounds == null ? mWindowManager.getCurrentWindowMetrics().getBounds()
: mWindowBounds,
mWindowInsets == null ? insets : mWindowInsets);
return windowMetrics;
}
@@ -103,6 +106,10 @@ public class TestableWindowManager implements WindowManager {
return (WindowManager.LayoutParams) mView.getLayoutParams();
}
public void setWindowBounds(Rect bounds) {
mWindowBounds = bounds;
}
public void setWindowInsets(WindowInsets insets) {
mWindowInsets = insets;
}