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

Commit 6d939f9e authored by Jean Chen's avatar Jean Chen
Browse files

Fix pinch zoom with partial magnification window not very responsive

When two fingers are too close, the android.view.ScaleGestureDetector will end the scale by minSpan value. This is because the size limit of window magnification can easily trigger the end scale, leading to the zoom out having little effect.

Solution is creating a new construct on android.view.ScaleGestureDetector and set the minSpan to zero.In this way, pinch zoom can work completely on the entire magnification window.

Bug: 295327792
Test: manual
Change-Id: I0afb5021221a7bf00cc1a16299a951f76dd62317
parent 2934897e
Loading
Loading
Loading
Loading
+25 −4
Original line number Diff line number Diff line
@@ -200,11 +200,32 @@ public class ScaleGestureDetector {
     */
    public ScaleGestureDetector(@NonNull Context context, @NonNull OnScaleGestureListener listener,
            @Nullable Handler handler) {
        this(context, ViewConfiguration.get(context).getScaledTouchSlop() * 2,
                ViewConfiguration.get(context).getScaledMinimumScalingSpan(), handler, listener);
    }

    /**
     * Creates a ScaleGestureDetector with span slop and min span.
     *
     * @param context the application's context.
     * @param spanSlop the threshold for interpreting a touch movement as scaling.
     * @param minSpan the minimum threshold of scaling span. The span could be
     *                overridden by other usages to specify a different scaling span, for instance,
     *                if you need pinch gestures to continue closer together than the default.
     * @param listener the listener invoked for all the callbacks, this must not be null.
     * @param handler the handler to use for running deferred listener events.
     *
     * @throws NullPointerException if {@code listener} is null.
     *
     * @hide
     */
    public ScaleGestureDetector(@NonNull Context context, @NonNull int spanSlop,
            @NonNull int minSpan, @Nullable Handler handler,
            @NonNull OnScaleGestureListener listener) {
        mContext = context;
        mListener = listener;
        final ViewConfiguration viewConfiguration = ViewConfiguration.get(context);
        mSpanSlop = viewConfiguration.getScaledTouchSlop() * 2;
        mMinSpan = viewConfiguration.getScaledMinimumScalingSpan();
        mSpanSlop = spanSlop;
        mMinSpan = minSpan;
        mHandler = handler;
        // Quick scale is enabled by default after JB_MR2
        final int targetSdkVersion = context.getApplicationInfo().targetSdkVersion;
+7 −0
Original line number Diff line number Diff line
@@ -34,3 +34,10 @@ flag {
    description: "Calls WMS.addWindowToken without holding A11yManagerService#mLock"
    bug: "297972548"
}

flag {
    name: "pinch_zoom_zero_min_span"
    namespace: "accessibility"
    description: "Whether to set min span of ScaleGestureDetector to zero."
    bug: "295327792"
}
 No newline at end of file
+9 −1
Original line number Diff line number Diff line
@@ -28,8 +28,10 @@ import android.util.TypedValue;
import android.view.GestureDetector;
import android.view.MotionEvent;
import android.view.ScaleGestureDetector;
import android.view.ViewConfiguration;

import com.android.internal.R;
import com.android.server.accessibility.Flags;

/**
 * Handles the behavior while receiving scaling and panning gestures if it's enabled.
@@ -70,7 +72,13 @@ class PanningScalingHandler extends
        mMaxScale = maxScale;
        mMinScale = minScale;
        mBlockScroll = blockScroll;
        if (Flags.pinchZoomZeroMinSpan()) {
            mScaleGestureDetector = new ScaleGestureDetector(context,
                    ViewConfiguration.get(context).getScaledTouchSlop() * 2,
                    /* minSpan= */ 0, Handler.getMain(), this);
        } else {
            mScaleGestureDetector = new ScaleGestureDetector(context, this, Handler.getMain());
        }
        mScrollGestureDetector = new GestureDetector(context, this, Handler.getMain());
        mScaleGestureDetector.setQuickScaleEnabled(false);
        mMagnificationDelegate = magnificationDelegate;