Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 66197596 authored by Minche Li's avatar Minche Li Committed by Automerger Merge Worker
Browse files

Merge "Calculates the window height fraction on screen by the draggable bounds...

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

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

Change-Id: I3e75bc49991c1682f7c36474dcf07496618817aa
parents 1522a2d9 70aaf815
Loading
Loading
Loading
Loading
+7 −7
Original line number Diff line number Diff line
@@ -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;
        }
+7 −8
Original line number Diff line number Diff line
@@ -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);