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

Commit 3c795033 authored by Candice Lo's avatar Candice Lo
Browse files

Match default magnifier window size to Medium in settings

We would like to initialize the magnifier to be Medium size, which is
one of the sizes that provided through magnification settings panel icon buttons, so that users could get back to the initial window size easily.

Since we are following the sizes provided by the settings panel, we will
need to rethink if those provided sizes are appropriate and useful for
users with different screen sizes. We would like to deal with the issue in a separate bug.

Bug: 265363901
Test: manually - check the magnifier is initialized to be Medium size
Test: atest WindowMagnificationControllerTest
Change-Id: I37762e002cb766b06f99817c87a25c9539faed6d
parent d667d0b1
Loading
Loading
Loading
Loading
+0 −1
Original line number Diff line number Diff line
@@ -1188,7 +1188,6 @@
    <dimen name="magnification_window_drag_corner_stroke">3dp</dimen>
    <!-- The extra padding to show the whole outer border -->
    <dimen name="magnifier_drag_handle_padding">3dp</dimen>
    <dimen name="magnification_max_frame_size">300dp</dimen>
    <!-- Magnification settings panel -->
    <dimen name="magnification_setting_view_margin">24dp</dimen>
    <dimen name="magnification_setting_text_size">18sp</dimen>
+17 −15
Original line number Diff line number Diff line
@@ -124,7 +124,7 @@ class WindowMagnificationController implements View.OnTouchListener, SurfaceHold
    private float mScale;

    /**
     * MagnificationFrame represents the bound of {@link #mMirrorSurface} and is constrained
     * MagnificationFrame represents the bound of {@link #mMirrorSurfaceView} and is constrained
     * by the {@link #mMagnificationFrameBoundary}.
     * We use MagnificationFrame to calculate the position of {@link #mMirrorView}.
     * We combine MagnificationFrame with {@link #mMagnificationFrameOffsetX} and
@@ -272,8 +272,8 @@ class WindowMagnificationController implements View.OnTouchListener, SurfaceHold
                com.android.internal.R.integer.config_shortAnimTime);
        updateDimensions();

        final Size windowSize = getDefaultWindowSizeWithWindowBounds(mWindowBounds);
        setMagnificationFrame(windowSize.getWidth(), windowSize.getHeight(),
        final Size windowFrameSize = getDefaultMagnificationWindowFrameSize();
        setMagnificationFrame(windowFrameSize.getWidth(), windowFrameSize.getHeight(),
                mWindowBounds.width() / 2, mWindowBounds.height() / 2);
        computeBounceAnimationScale();

@@ -381,12 +381,16 @@ class WindowMagnificationController implements View.OnTouchListener, SurfaceHold
        if (!mMagnificationSizeScaleOptions.contains(index)) {
            return;
        }
        final float scale = mMagnificationSizeScaleOptions.get(index, 1.0f);
        final int initSize = Math.min(mWindowBounds.width(), mWindowBounds.height()) / 3;
        int size = (int) (initSize * scale);
        int size = getMagnificationWindowSizeFromIndex(index);
        setWindowSize(size, size);
    }

    int getMagnificationWindowSizeFromIndex(@MagnificationSize int index) {
        final float scale = mMagnificationSizeScaleOptions.get(index, 1.0f);
        int initSize = Math.min(mWindowBounds.width(), mWindowBounds.height()) / 3;
        return (int) (initSize * scale) - (int) (initSize * scale) % 2;
    }

    void setEditMagnifierSizeMode(boolean enable) {
        mEditSizeEnable = enable;
        applyResourcesValues();
@@ -519,12 +523,12 @@ class WindowMagnificationController implements View.OnTouchListener, SurfaceHold
            return false;
        }
        mWindowBounds.set(currentWindowBounds);
        final Size windowSize = getDefaultWindowSizeWithWindowBounds(mWindowBounds);
        final Size windowFrameSize = getDefaultMagnificationWindowFrameSize();
        final float newCenterX = (getCenterX()) * mWindowBounds.width() / oldWindowBounds.width();
        final float newCenterY = (getCenterY()) * mWindowBounds.height() / oldWindowBounds.height();

        setMagnificationFrame(windowSize.getWidth(), windowSize.getHeight(), (int) newCenterX,
                (int) newCenterY);
        setMagnificationFrame(windowFrameSize.getWidth(), windowFrameSize.getHeight(),
                (int) newCenterX, (int) newCenterY);
        calculateMagnificationFrameBoundary();
        return true;
    }
@@ -745,12 +749,10 @@ class WindowMagnificationController implements View.OnTouchListener, SurfaceHold
        mMagnificationFrame.set(initX, initY, initX + width, initY + height);
    }

    private Size getDefaultWindowSizeWithWindowBounds(Rect windowBounds) {
        int initSize = Math.min(windowBounds.width(), windowBounds.height()) / 2;
        initSize = Math.min(mResources.getDimensionPixelSize(R.dimen.magnification_max_frame_size),
                initSize);
        initSize += 2 * mMirrorSurfaceMargin;
        return new Size(initSize, initSize);
    private Size getDefaultMagnificationWindowFrameSize() {
        final int defaultSize = getMagnificationWindowSizeFromIndex(MagnificationSize.MEDIUM)
                - 2 * mMirrorSurfaceMargin;
        return new Size(defaultSize, defaultSize);
    }

    /**
+12 −10
Original line number Diff line number Diff line
@@ -100,6 +100,7 @@ import com.google.common.util.concurrent.AtomicDouble;
import org.junit.After;
import org.junit.Assume;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Answers;
@@ -313,10 +314,10 @@ public class WindowMagnificationControllerTest extends SysuiTestCase {
        assertFalse(rects.isEmpty());
    }

    @Ignore("The default window size should be constrained after fixing b/288056772")
    @Test
    public void enableWindowMagnification_LargeScreen_windowSizeIsConstrained() {
        final int screenSize = mContext.getResources().getDimensionPixelSize(
                R.dimen.magnification_max_frame_size) * 10;
        final int screenSize = mWindowManager.getCurrentWindowMetrics().getBounds().width() * 10;
        mWindowManager.setWindowBounds(new Rect(0, 0, screenSize, screenSize));

        mInstrumentation.runOnMainSync(() -> {
@@ -568,26 +569,27 @@ public class WindowMagnificationControllerTest extends SysuiTestCase {
                mWindowMagnificationController.getCenterY() / testWindowBounds.height(),
                0);
    }

    @Test
    public void screenSizeIsChangedToLarge_enabled_windowSizeIsConstrained() {
    public void screenSizeIsChangedToLarge_enabled_defaultWindowSize() {
        mInstrumentation.runOnMainSync(() -> {
            mWindowMagnificationController.enableWindowMagnificationInternal(Float.NaN, Float.NaN,
                    Float.NaN);
        });
        final int screenSize = mContext.getResources().getDimensionPixelSize(
                R.dimen.magnification_max_frame_size) * 10;
        final int screenSize = mWindowManager.getCurrentWindowMetrics().getBounds().width() * 10;
        mWindowManager.setWindowBounds(new Rect(0, 0, screenSize, screenSize));

        mInstrumentation.runOnMainSync(() -> {
            mWindowMagnificationController.onConfigurationChanged(ActivityInfo.CONFIG_SCREEN_SIZE);
        });

        final int halfScreenSize = screenSize / 2;
        final int defaultWindowSize =
                mWindowMagnificationController.getMagnificationWindowSizeFromIndex(
                        WindowMagnificationSettings.MagnificationSize.MEDIUM);
        WindowManager.LayoutParams params = mWindowManager.getLayoutParamsFromAttachedView();
        // The frame size should be the half of smaller value of window height/width unless it
        //exceed the max frame size.
        assertTrue(params.width < halfScreenSize);
        assertTrue(params.height < halfScreenSize);

        assertTrue(params.width == defaultWindowSize);
        assertTrue(params.height == defaultWindowSize);
    }

    @Test