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

Commit 5909b00f authored by mincheli's avatar mincheli
Browse files

Notifies updating magnification switch visibility when the magnification shortcut is triggered

When the magnification is off then a user toggles on magnification by the
magnification shortcut (a11y button or triple-tap gesture),
the switch button should be shown immediately.
When the magnification is on then a user toggles off magnification by the
magnification shortcut, the switch button should be removed immediately.

Bug: 170976389
Test: atest FullScreenMagnificationGestureHandlerTest WindowMagnificationGestureHandlerTest MagnificationControllerTest
Change-Id: I28869f0954d0befd5c675e5f22c303d128e8d8d3
parent ed2f7d4b
Loading
Loading
Loading
Loading
+10 −10
Original line number Diff line number Diff line
@@ -211,8 +211,7 @@ public class FullScreenMagnificationGestureHandler extends MagnificationGestureH
    }

    @Override
    public void notifyShortcutTriggered() {
        if (mDetectShortcutTrigger) {
    public void handleShortcutTriggered() {
        boolean wasMagnifying = mFullScreenMagnificationController.resetIfNeeded(mDisplayId,
                /* animate */ true);
        if (wasMagnifying) {
@@ -222,7 +221,6 @@ public class FullScreenMagnificationGestureHandler extends MagnificationGestureH
            mDetectingState.toggleShortcutTriggered();
        }
    }
    }

    @Override
    public int getMode() {
@@ -868,6 +866,8 @@ public class FullScreenMagnificationGestureHandler extends MagnificationGestureH
                mPromptController.showNotificationIfNeeded();
                zoomOn(up.getX(), up.getY());
            }

            mCallback.onTripleTapped(mDisplayId, getMode());
        }

        private boolean isMagnifying() {
+24 −0
Original line number Diff line number Diff line
@@ -43,6 +43,11 @@ import com.android.server.accessibility.AccessibilityManagerService;
 *   the user touch interaction starts if magnification capabilities is all. </li>
 *   <li> 2. {@link #onTouchInteractionEnd} shows magnification switch UI when
 *   the user touch interaction ends if magnification capabilities is all. </li>
 *   <li> 3. {@link #onShortcutTriggered} updates magnification switch UI depending on
 *   magnification capabilities and magnification active state when magnification shortcut
 *   is triggered.</li>
 *   <li> 4. {@link #onTripleTapped} updates magnification switch UI depending on magnification
 *   capabilities and magnification active state when triple-tap gesture is detected. </li>
 * </ol>
 */
public class MagnificationController implements WindowMagnificationManager.Callback,
@@ -113,6 +118,25 @@ public class MagnificationController implements WindowMagnificationManager.Callb
        }
    }

    @Override
    public void onShortcutTriggered(int displayId, int mode) {
        updateMagnificationButton(displayId, mode);
    }

    @Override
    public void onTripleTapped(int displayId, int mode) {
        updateMagnificationButton(displayId, mode);
    }

    private void updateMagnificationButton(int displayId, int mode) {
        if (isActivated(displayId, mode) && mMagnificationCapabilities
                == Settings.Secure.ACCESSIBILITY_MAGNIFICATION_MODE_ALL) {
            getWindowMagnificationMgr().showMagnificationButton(displayId, mode);
        } else {
            getWindowMagnificationMgr().removeMagnificationButton(displayId);
        }
    }

    /**
     * Transitions to the target Magnification mode with current center of the magnification mode
     * if it is available.
+33 −1
Original line number Diff line number Diff line
@@ -78,6 +78,25 @@ public abstract class MagnificationGestureHandler extends BaseEventStreamTransfo
         * @param mode The magnification mode
         */
        void onTouchInteractionEnd(int displayId, int mode);

        /**
         * Called when the magnification shortcut is triggered by a user. The magnification
         * shortcut can be accessibility button or volume shortcut.
         *
         * @param displayId The logical display id
         * @param mode The magnification mode
         */
        void onShortcutTriggered(int displayId, int mode);

        /**
         * Called when the triple-tap gesture is handled. The magnification
         * shortcut can be a triple-tap gesture or accessibility button.
         * Called when the triple-tap gesture is handled
         *
         * @param displayId The logical display id
         * @param mode The magnification mode
         */
        void onTripleTapped(int displayId, int mode);
    }

    protected final Callback mCallback;
@@ -156,7 +175,20 @@ public abstract class MagnificationGestureHandler extends BaseEventStreamTransfo
    /**
     * Called when the shortcut target is magnification.
     */
    public abstract void notifyShortcutTriggered();
    public void notifyShortcutTriggered() {
        if (DEBUG_ALL) {
            Slog.i(mLogTag, "notifyShortcutTriggered():");
        }
        if (mDetectShortcutTrigger) {
            handleShortcutTriggered();
            mCallback.onShortcutTriggered(mDisplayId, getMode());
        }
    }

    /**
     * Handles shortcut triggered event.
     */
    abstract void handleShortcutTriggered();

    /**
     * Indicates the magnification mode.
+2 −7
Original line number Diff line number Diff line
@@ -152,13 +152,7 @@ public class WindowMagnificationGestureHandler extends MagnificationGestureHandl
    }

    @Override
    public void notifyShortcutTriggered() {
        if (DEBUG_ALL) {
            Slog.i(mLogTag, "notifyShortcutTriggered():");
        }
        if (!mDetectShortcutTrigger) {
            return;
        }
    public void handleShortcutTriggered() {
        final Point screenSize = mTempPoint;
        getScreenSize(mTempPoint);
        toggleMagnification(screenSize.x / 2.0f, screenSize.y / 2.0f);
@@ -205,6 +199,7 @@ public class WindowMagnificationGestureHandler extends MagnificationGestureHandl
            Slog.i(mLogTag, "onTripleTap()");
        }
        toggleMagnification(up.getX(), up.getY());
        mCallback.onTripleTapped(mDisplayId, getMode());
    }

    void resetToDetectState() {
+9 −0
Original line number Diff line number Diff line
@@ -42,6 +42,7 @@ import android.content.Context;
import android.graphics.PointF;
import android.os.Handler;
import android.os.Message;
import android.provider.Settings;
import android.util.DebugUtils;
import android.view.InputDevice;
import android.view.MotionEvent;
@@ -450,6 +451,14 @@ public class FullScreenMagnificationGestureHandlerTest {
        verify(mWindowMagnificationPromptController).showNotificationIfNeeded();
    }

    @Test
    public void testZoomedWithTripleTap_callsOnTripleTapped() {
        goFromStateIdleTo(STATE_ZOOMED_2TAPS);

        verify(mMockCallback).onTripleTapped(DISPLAY_0,
                Settings.Secure.ACCESSIBILITY_MAGNIFICATION_MODE_FULLSCREEN);
    }

    private void assertActionsInOrder(List<MotionEvent> actualEvents,
            List<Integer> expectedActions) {
        assertTrue(actualEvents.size() == expectedActions.size());
Loading