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

Commit 0dae9e4f authored by Daniel Hsieh's avatar Daniel Hsieh
Browse files

Adds moveWindowMagnifierToPosition method

For following typing focus feature, we add a
moveWindowMagnifierToPosition method for a window magnifier to move it
to the center of onRectangleOnScreenRequested.

Apart from calling this method to fulfill movement functionality, we can
separate the movement from calling enableWindowMagnification which is a
temporary replacement for movement functionality. Therefore, we can
distinguish whether the it is enabled by the first time or the further
movement behavior. It would help us differentiate the condition whether
we should reset the following typing focus to on/off state. (b/216394179)

Bug: 219654280
Test: atest IWindowMagnificationConnectionTest
      atest WindowMagnificationTest
      atest WindowMagnificationAnimationControllerTest
      atest WindowMagnificationControllerTest
      atest WindowMagnificationConnectionWrapperTest
      atest WindowMagnificationManagerTest
Change-Id: Iaac3ca6868d948571c1aee54a5f122c9697059d8
parent 0153cbf9
Loading
Loading
Loading
Loading
+17 −5
Original line number Diff line number Diff line
@@ -32,7 +32,7 @@ oneway interface IWindowMagnificationConnection {
    /**
     * Enables window magnification on specified display with given center and scale and animation.
     *
     * @param displayId The logical display id.
     * @param displayId the logical display id.
     * @param scale magnification scale.
     * @param centerX the screen-relative X coordinate around which to center,
     *                or {@link Float#NaN} to leave unchanged.
@@ -51,7 +51,7 @@ oneway interface IWindowMagnificationConnection {
    /**
     * Sets the scale of the window magnifier on specified display.
     *
     * @param displayId The logical display id.
     * @param displayId the logical display id.
     * @param scale magnification scale.
     */
    void setScale(int displayId, float scale);
@@ -59,7 +59,7 @@ oneway interface IWindowMagnificationConnection {
     /**
     * Disables window magnification on specified display with animation.
     *
     * @param displayId The logical display id.
     * @param displayId the logical display id.
     * @param callback The callback called when the animation is completed or interrupted.
     */
    void disableWindowMagnification(int displayId,
@@ -68,6 +68,7 @@ oneway interface IWindowMagnificationConnection {
    /**
     * Moves the window magnifier on the specified display. It has no effect while animating.
     *
     * @param displayId the logical display id.
     * @param offsetX the amount in pixels to offset the window magnifier in the X direction, in
     *                current screen pixels.
     * @param offsetY the amount in pixels to offset the window magnifier in the Y direction, in
@@ -75,10 +76,21 @@ oneway interface IWindowMagnificationConnection {
     */
    void moveWindowMagnifier(int displayId, float offsetX, float offsetY);

    /**
     * Moves the window magnifier on the given display.
     *
     * @param displayId the logical display id.
     * @param positionX the x-axis position of the center of the magnified source bounds.
     * @param positionY the y-axis position of the center of the magnified source bounds.
     * @param callback the callback called when the animation is completed or interrupted.
     */
    void moveWindowMagnifierToPosition(int displayId, float positionX, float positionY,
        in IRemoteMagnificationAnimationCallback callback);

    /**
     * Requests System UI show magnification mode button UI on the specified display.
     *
     * @param displayId The logical display id.
     * @param displayId the logical display id.
     * @param magnificationMode the current magnification mode.
     */
    void showMagnificationButton(int displayId, int magnificationMode);
@@ -86,7 +98,7 @@ oneway interface IWindowMagnificationConnection {
    /**
     * Requests System UI remove magnification mode button UI on the specified display.
     *
     * @param displayId The logical display id.
     * @param displayId the logical display id.
     */
    void removeMagnificationButton(int displayId);

+11 −0
Original line number Diff line number Diff line
@@ -171,6 +171,17 @@ public class WindowMagnification extends CoreStartable implements WindowMagnifie
        }
    }

    @MainThread
    void moveWindowMagnifierToPositionInternal(int displayId, float positionX, float positionY,
            IRemoteMagnificationAnimationCallback callback) {
        final WindowMagnificationController windowMagnificationController =
                mMagnificationControllerSupplier.get(displayId);
        if (windowMagnificationController != null) {
            windowMagnificationController.moveWindowMagnifierToPosition(positionX, positionY,
                    callback);
        }
    }

    @MainThread
    void disableWindowMagnification(int displayId,
            @Nullable IRemoteMagnificationAnimationCallback callback) {
+34 −5
Original line number Diff line number Diff line
@@ -156,6 +156,7 @@ class WindowMagnificationAnimationController implements ValueAnimator.AnimatorUp
        }
        mAnimationCallback = animationCallback;
        setupEnableAnimationSpecs(scale, centerX, centerY);

        if (mEndSpec.equals(mStartSpec)) {
            if (mState == STATE_DISABLED) {
                mController.enableWindowMagnificationInternal(scale, centerX, centerY,
@@ -178,6 +179,24 @@ class WindowMagnificationAnimationController implements ValueAnimator.AnimatorUp
        }
    }

    void moveWindowMagnifierToPosition(float centerX, float centerY,
            IRemoteMagnificationAnimationCallback callback) {
        if (mState == STATE_ENABLED) {
            // We set the animation duration to shortAnimTime which would be reset at the end.
            mValueAnimator.setDuration(mContext.getResources()
                    .getInteger(com.android.internal.R.integer.config_shortAnimTime));
            enableWindowMagnification(Float.NaN, centerX, centerY,
                    /* magnificationFrameOffsetRatioX */ Float.NaN,
                    /* magnificationFrameOffsetRatioY */ Float.NaN, callback);
        } else if (mState == STATE_ENABLING) {
            sendAnimationCallback(false);
            mAnimationCallback = callback;
            mValueAnimator.setDuration(mContext.getResources()
                    .getInteger(com.android.internal.R.integer.config_shortAnimTime));
            setupEnableAnimationSpecs(Float.NaN, centerX, centerY);
        }
    }

    private void setupEnableAnimationSpecs(float scale, float centerX, float centerY) {
        if (mController == null) {
            return;
@@ -193,9 +212,16 @@ class WindowMagnificationAnimationController implements ValueAnimator.AnimatorUp
                    R.integer.magnification_default_scale) : scale, centerX, centerY);
        } else {
            mStartSpec.set(currentScale, currentCenterX, currentCenterY);
            mEndSpec.set(Float.isNaN(scale) ? currentScale : scale,
                    Float.isNaN(centerX) ? currentCenterX : centerX,
                    Float.isNaN(centerY) ? currentCenterY : centerY);

            final float endScale = (mState == STATE_ENABLING ? mEndSpec.mScale : currentScale);
            final float endCenterX =
                    (mState == STATE_ENABLING ? mEndSpec.mCenterX : currentCenterX);
            final float endCenterY =
                    (mState == STATE_ENABLING ? mEndSpec.mCenterY : currentCenterY);

            mEndSpec.set(Float.isNaN(scale) ? endScale : scale,
                    Float.isNaN(centerX) ? endCenterX : centerX,
                    Float.isNaN(centerY) ? endCenterY : centerY);
        }
        if (DEBUG) {
            Log.d(TAG, "SetupEnableAnimationSpecs : mStartSpec = " + mStartSpec + ", endSpec = "
@@ -269,6 +295,9 @@ class WindowMagnificationAnimationController implements ValueAnimator.AnimatorUp
            setState(STATE_ENABLED);
        }
        sendAnimationCallback(true);
        // We reset the duration to config_longAnimTime
        mValueAnimator.setDuration(mContext.getResources()
                .getInteger(com.android.internal.R.integer.config_longAnimTime));
    }

    @Override
@@ -313,10 +342,10 @@ class WindowMagnificationAnimationController implements ValueAnimator.AnimatorUp
                mMagnificationFrameOffsetRatioX, mMagnificationFrameOffsetRatioY);
    }

    private static ValueAnimator newValueAnimator(Resources resources) {
    private static ValueAnimator newValueAnimator(Resources resource) {
        final ValueAnimator valueAnimator = new ValueAnimator();
        valueAnimator.setDuration(
                resources.getInteger(com.android.internal.R.integer.config_longAnimTime));
                resource.getInteger(com.android.internal.R.integer.config_longAnimTime));
        valueAnimator.setInterpolator(new AccelerateInterpolator(2.5f));
        valueAnimator.setFloatValues(0.0f, 1.0f);
        return valueAnimator;
+7 −0
Original line number Diff line number Diff line
@@ -76,6 +76,13 @@ class WindowMagnificationConnectionImpl extends IWindowMagnificationConnection.S
                () -> mWindowMagnification.moveWindowMagnifier(displayId, offsetX, offsetY));
    }

    @Override
    public void moveWindowMagnifierToPosition(int displayId, float positionX, float positionY,
            IRemoteMagnificationAnimationCallback callback) {
        mHandler.post(() -> mWindowMagnification.moveWindowMagnifierToPositionInternal(
                displayId, positionX, positionY, callback));
    }

    @Override
    public void showMagnificationButton(int displayId, int magnificationMode) {
        mHandler.post(
+8 −0
Original line number Diff line number Diff line
@@ -985,6 +985,14 @@ class WindowMagnificationController implements View.OnTouchListener, SurfaceHold
        }
    }

    void moveWindowMagnifierToPosition(float positionX, float positionY,
            IRemoteMagnificationAnimationCallback callback) {
        if (mMirrorSurfaceView == null) {
            return;
        }
        mAnimationController.moveWindowMagnifierToPosition(positionX, positionY, callback);
    }

    /**
     * Gets the scale.
     *
Loading