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

Commit 19188bcc authored by Minche Li's avatar Minche Li Committed by Android (Google) Code Review
Browse files

Merge "Handles magnification scale change when requesting Accessibility action"

parents 2eda8497 f7ff2c89
Loading
Loading
Loading
Loading
+10 −0
Original line number Diff line number Diff line
@@ -50,4 +50,14 @@ import android.graphics.Rect;
     * @param sourceBounds The magnified bounds in screen coordinates.
     */
    void onSourceBoundsChanged(int displayId, in Rect sourceBounds);

    /**
     * Called when the accessibility action of scale requests to be performed.
     * It is invoked from System UI. And the action is provided by the mirror window.
     *
     * @param displayId The logical display id.
     * @param scale the target scale, or {@link Float#NaN} to leave unchanged
     */
    void onPerformScaleAction(int displayId, float scale);

}
+17 −0
Original line number Diff line number Diff line
@@ -145,6 +145,13 @@ public class WindowMagnification extends SystemUI implements WindowMagnifierCall
        }
    }

    @Override
    public void onPerformScaleAction(int displayId, float scale) {
        if (mWindowMagnificationConnectionImpl != null) {
            mWindowMagnificationConnectionImpl.onPerformScaleAction(displayId, scale);
        }
    }

    @Override
    public void requestWindowMagnificationConnection(boolean connect) {
        if (connect) {
@@ -247,5 +254,15 @@ public class WindowMagnification extends SystemUI implements WindowMagnifierCall
                }
            }
        }

        void onPerformScaleAction(int displayId, float scale) {
            if (mConnectionCallback != null) {
                try {
                    mConnectionCallback.onPerformScaleAction(displayId, scale);
                } catch (RemoteException e) {
                    Log.e(TAG, "Failed to inform performing scale action", e);
                }
            }
        }
    }
}
+4 −2
Original line number Diff line number Diff line
@@ -719,12 +719,14 @@ class WindowMagnificationController implements View.OnTouchListener, SurfaceHold
        private boolean performA11yAction(int action) {
            if (action == R.id.accessibility_action_zoom_in) {
                final float scale = mScale + A11Y_CHANGE_SCALE_DIFFERENCE;
                setScale(A11Y_ACTION_SCALE_RANGE.clamp(scale));
                mWindowMagnifierCallback.onPerformScaleAction(mDisplayId,
                        A11Y_ACTION_SCALE_RANGE.clamp(scale));
                return true;
            }
            if (action == R.id.accessibility_action_zoom_out) {
                final float scale = mScale - A11Y_CHANGE_SCALE_DIFFERENCE;
                setScale(A11Y_ACTION_SCALE_RANGE.clamp(scale));
                mWindowMagnifierCallback.onPerformScaleAction(mDisplayId,
                        A11Y_ACTION_SCALE_RANGE.clamp(scale));
                return true;
            }
            if (action == R.id.accessibility_action_move_up) {
+9 −0
Original line number Diff line number Diff line
@@ -37,4 +37,13 @@ interface WindowMagnifierCallback {
     * @param sourceBounds The magnified bounds in screen coordinates.
     */
    void onSourceBoundsChanged(int displayId, Rect sourceBounds);

    /**
     * Called when the accessibility action of scale requests to be performed.
     * It is invoked from System UI. And the action is provided by the mirror window.
     *
     * @param displayId The logical display id.
     * @param scale the target scale, or {@link Float#NaN} to leave unchanged
     */
    void onPerformScaleAction(int displayId, float scale);
}
+3 −2
Original line number Diff line number Diff line
@@ -275,6 +275,7 @@ public class WindowMagnificationControllerTest extends SysuiTestCase {

    @Test
    public void performA11yActions_visible_expectedResults() {
        final int displayId = mContext.getDisplayId();
        mInstrumentation.runOnMainSync(() -> {
            mWindowMagnificationController.enableWindowMagnification(2.5f, Float.NaN,
                    Float.NaN);
@@ -284,10 +285,10 @@ public class WindowMagnificationControllerTest extends SysuiTestCase {
        assertTrue(
                mMirrorView.performAccessibilityAction(R.id.accessibility_action_zoom_out, null));
        // Minimum scale is 2.0.
        assertEquals(2.0f, mWindowMagnificationController.getScale(), 0f);
        verify(mWindowMagnifierCallback).onPerformScaleAction(eq(displayId), eq(2.0f));

        assertTrue(mMirrorView.performAccessibilityAction(R.id.accessibility_action_zoom_in, null));
        assertEquals(3.0f, mWindowMagnificationController.getScale(), 0f);
        verify(mWindowMagnifierCallback).onPerformScaleAction(eq(displayId), eq(3.5f));

        // TODO: Verify the final state when the mirror surface is visible.
        assertTrue(mMirrorView.performAccessibilityAction(R.id.accessibility_action_move_up, null));
Loading