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

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

Merge changes from topic "magnification_switch"

* changes:
  Notifies updating magnification switch visibility when the magnification shortcut is triggered
  Notifies showing magnification switch when the touch interaction starts or ends
  Not need to show magnification switch UI when magnification scale is changed
parents 9096542e 5909b00f
Loading
Loading
Loading
Loading
+12 −13
Original line number Diff line number Diff line
@@ -141,12 +141,12 @@ public class FullScreenMagnificationGestureHandler extends MagnificationGestureH

    public FullScreenMagnificationGestureHandler(Context context,
            FullScreenMagnificationController fullScreenMagnificationController,
            ScaleChangedListener listener,
            Callback callback,
            boolean detectTripleTap,
            boolean detectShortcutTrigger,
            @NonNull WindowMagnificationPromptController promptController,
            int displayId) {
        super(displayId, detectTripleTap, detectShortcutTrigger, listener);
        super(displayId, detectTripleTap, detectShortcutTrigger, callback);
        if (DEBUG_ALL) {
            Log.i(mLogTag,
                    "FullScreenMagnificationGestureHandler(detectTripleTap = " + detectTripleTap
@@ -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() {
@@ -395,7 +393,6 @@ public class FullScreenMagnificationGestureHandler extends MagnificationGestureH
            if (DEBUG_PANNING_SCALING) Slog.i(mLogTag, "Scaled content to: " + scale + "x");
            mFullScreenMagnificationController.setScale(mDisplayId, scale, pivotX, pivotY, false,
                    AccessibilityManagerService.MAGNIFICATION_GESTURE_HANDLER_ID);
            mListener.onMagnificationScaleChanged(mDisplayId, getMode());
            return /* handled: */ true;
        }

@@ -869,6 +866,8 @@ public class FullScreenMagnificationGestureHandler extends MagnificationGestureH
                mPromptController.showNotificationIfNeeded();
                zoomOn(up.getX(), up.getY());
            }

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

        private boolean isMagnifying() {
+60 −7
Original line number Diff line number Diff line
@@ -34,11 +34,24 @@ import com.android.internal.annotations.VisibleForTesting;
import com.android.server.accessibility.AccessibilityManagerService;

/**
 * Handles all magnification controllers initialization, generic interactions
 * and magnification mode transition.
 * Handles all magnification controllers initialization, generic interactions,
 * magnification mode transition and magnification switch UI show/hide logic
 * in the following callbacks:
 *
 * <ol>
 *   <li> 1. {@link #onTouchInteractionStart} shows magnification switch UI when
 *   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,
        MagnificationGestureHandler.ScaleChangedListener {
        MagnificationGestureHandler.Callback {

    private static final boolean DEBUG = false;
    private static final String TAG = "MagnificationController";
@@ -84,17 +97,45 @@ public class MagnificationController implements WindowMagnificationManager.Callb
    public void onPerformScaleAction(int displayId, float scale) {
        getWindowMagnificationMgr().setScale(displayId, scale);
        getWindowMagnificationMgr().persistScale(displayId);
        onMagnificationScaleChanged(displayId,
                Settings.Secure.ACCESSIBILITY_MAGNIFICATION_MODE_WINDOW);
    }

    @Override
    public void onMagnificationScaleChanged(int displayId, int mode) {
    public void onTouchInteractionStart(int displayId, int mode) {
        handleUserInteractionChanged(displayId, mode);
    }

    @Override
    public void onTouchInteractionEnd(int displayId, int mode) {
        handleUserInteractionChanged(displayId, mode);
    }

    private void handleUserInteractionChanged(int displayId, int mode) {
        if (mMagnificationCapabilities != Settings.Secure.ACCESSIBILITY_MAGNIFICATION_MODE_ALL) {
            return;
        }
        if (isActivated(displayId, mode)) {
            getWindowMagnificationMgr().showMagnificationButton(displayId, mode);
        }
    }

    @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
@@ -272,6 +313,18 @@ public class MagnificationController implements WindowMagnificationManager.Callb
        return mTempPoint;
    }

    private boolean isActivated(int displayId, int mode) {
        boolean isActivated = false;
        if (mode == ACCESSIBILITY_MAGNIFICATION_MODE_FULLSCREEN
                && mFullScreenMagnificationController != null) {
            isActivated = mFullScreenMagnificationController.isMagnifying(displayId);
        } else if (mode == ACCESSIBILITY_MAGNIFICATION_MODE_WINDOW
                && mWindowMagnificationMgr != null) {
            isActivated = mWindowMagnificationMgr.isWindowMagnifierEnabled(displayId);
        }
        return isActivated;
    }

    private final class DisableMagnificationCallback implements
            MagnificationAnimationCallback {
        private final TransitionCallBack mTransitionCallBack;
+59 −11
Original line number Diff line number Diff line
@@ -17,6 +17,8 @@
package com.android.server.accessibility.magnification;

import static android.view.InputDevice.SOURCE_TOUCHSCREEN;
import static android.view.MotionEvent.ACTION_CANCEL;
import static android.view.MotionEvent.ACTION_UP;

import android.annotation.NonNull;
import android.util.Log;
@@ -59,26 +61,53 @@ public abstract class MagnificationGestureHandler extends BaseEventStreamTransfo
     */
    protected final boolean mDetectTripleTap;

    /** Interface for listening to the magnification scaling gesture. */
    public interface ScaleChangedListener {
    /** Callback interface to report that magnification is interactive with a user. */
    public interface Callback {
        /**
         * Called when the magnification scale is changed by users.
         * Called when the touch interaction is started by a user.
         *
         * @param displayId The logical display id
         * @param mode The magnification mode
         */
        void onMagnificationScaleChanged(int displayId, int mode);
        void onTouchInteractionStart(int displayId, int mode);

        /**
         * Called when the touch interaction is ended by a user.
         *
         * @param displayId The logical display id
         * @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 ScaleChangedListener mListener;
    protected final Callback mCallback;

    protected MagnificationGestureHandler(int displayId, boolean detectTripleTap,
            boolean detectShortcutTrigger,
            @NonNull ScaleChangedListener listener) {
            @NonNull Callback callback) {
        mDisplayId = displayId;
        mDetectTripleTap = detectTripleTap;
        mDetectShortcutTrigger = detectShortcutTrigger;
        mListener = listener;
        mCallback = callback;

        mDebugInputEventHistory = DEBUG_EVENT_STREAM ? new ArrayDeque<>() : null;
        mDebugOutputEventHistory = DEBUG_EVENT_STREAM ? new ArrayDeque<>() : null;
@@ -96,6 +125,13 @@ public abstract class MagnificationGestureHandler extends BaseEventStreamTransfo
            dispatchTransformedEvent(event, rawEvent, policyFlags);
        } else {
            onMotionEventInternal(event, rawEvent, policyFlags);

            final int action = event.getAction();
            if (action == MotionEvent.ACTION_DOWN) {
                mCallback.onTouchInteractionStart(mDisplayId, getMode());
            } else if (action == ACTION_UP || action == ACTION_CANCEL) {
                mCallback.onTouchInteractionEnd(mDisplayId, getMode());
            }
        }
    }

@@ -107,8 +143,7 @@ public abstract class MagnificationGestureHandler extends BaseEventStreamTransfo
        return false;
    }

    final void dispatchTransformedEvent(MotionEvent event, MotionEvent rawEvent,
            int policyFlags) {
    final void dispatchTransformedEvent(MotionEvent event, MotionEvent rawEvent, int policyFlags) {
        if (DEBUG_EVENT_STREAM) {
            storeEventInto(mDebugOutputEventHistory, event);
            try {
@@ -140,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.
+4 −10
Original line number Diff line number Diff line
@@ -88,9 +88,9 @@ public class WindowMagnificationGestureHandler extends MagnificationGestureHandl

    public WindowMagnificationGestureHandler(Context context,
            WindowMagnificationManager windowMagnificationMgr,
            ScaleChangedListener listener,
            Callback callback,
            boolean detectTripleTap, boolean detectShortcutTrigger, int displayId) {
        super(displayId, detectTripleTap, detectShortcutTrigger, listener);
        super(displayId, detectTripleTap, detectShortcutTrigger, callback);
        if (DEBUG_ALL) {
            Slog.i(mLogTag,
                    "WindowMagnificationGestureHandler() , displayId = " + displayId + ")");
@@ -115,7 +115,6 @@ public class WindowMagnificationGestureHandler extends MagnificationGestureHandl
                            @Override
                            public void setScale(int displayId, float scale) {
                                mWindowMagnificationMgr.setScale(displayId, scale);
                                mListener.onMagnificationScaleChanged(displayId, getMode());
                            }

                            @Override
@@ -153,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);
@@ -206,6 +199,7 @@ public class WindowMagnificationGestureHandler extends MagnificationGestureHandl
            Slog.i(mLogTag, "onTripleTap()");
        }
        toggleMagnification(up.getX(), up.getY());
        mCallback.onTripleTapped(mDisplayId, getMode());
    }

    void resetToDetectState() {
+10 −4
Original line number Diff line number Diff line
@@ -124,7 +124,7 @@ public class FullScreenMagnificationGestureHandlerTest {
    private Context mContext;
    FullScreenMagnificationController mFullScreenMagnificationController;
    @Mock
    MagnificationGestureHandler.ScaleChangedListener mMockScaleChangedListener;
    MagnificationGestureHandler.Callback mMockCallback;
    @Mock
    MagnificationRequestObserver mMagnificationRequestObserver;
    @Mock
@@ -179,7 +179,7 @@ public class FullScreenMagnificationGestureHandlerTest {
    private FullScreenMagnificationGestureHandler newInstance(boolean detectTripleTap,
            boolean detectShortcutTrigger) {
        FullScreenMagnificationGestureHandler h = new FullScreenMagnificationGestureHandler(
                mContext, mFullScreenMagnificationController, mMockScaleChangedListener,
                mContext, mFullScreenMagnificationController, mMockCallback,
                detectTripleTap, detectShortcutTrigger,
                mWindowMagnificationPromptController, DISPLAY_0);
        mHandler = new TestHandler(h.mDetectingState, mClock) {
@@ -451,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());
@@ -554,8 +562,6 @@ public class FullScreenMagnificationGestureHandlerTest {
                check(mMgh.mCurrentState == mMgh.mPanningScalingState,
                        state);
                check(mMgh.mPanningScalingState.mScaling, state);
                verify(mMockScaleChangedListener).onMagnificationScaleChanged(DISPLAY_0,
                        Settings.Secure.ACCESSIBILITY_MAGNIFICATION_MODE_FULLSCREEN);
            } break;
            default: throw new IllegalArgumentException("Illegal state: " + state);
        }
Loading