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

Commit 79b10ec7 authored by Shan Huang's avatar Shan Huang
Browse files

Forward motion events to BackAnimation from EdgeBackGestureHandler.

This decouples BackAnimation from NavigationEdgeBackPlugin, so that the back affordance plugins can work with the predictive back
infra introduced in T.

Test: install go/back-prototype and verify that back nav works.
Bug: 229027400
Change-Id: Ia9e583b5107e3190f342092a5a7e20d2078d7902
parent 3d8c880d
Loading
Loading
Loading
Loading
+0 −27
Original line number Diff line number Diff line
@@ -34,7 +34,6 @@ import android.view.ViewConfiguration
import android.view.WindowManager
import android.view.animation.DecelerateInterpolator
import android.view.animation.PathInterpolator
import android.window.BackEvent
import androidx.dynamicanimation.animation.DynamicAnimation
import androidx.dynamicanimation.animation.SpringForce
import com.android.internal.util.LatencyTracker
@@ -97,7 +96,6 @@ private val DECELERATE_INTERPOLATOR_SLOW = DecelerateInterpolator(0.7f)

class BackPanelController private constructor(
    context: Context,
    private var backAnimation: BackAnimation?,
    private val windowManager: WindowManager,
    private val viewConfiguration: ViewConfiguration,
    @Main private val mainHandler: Handler,
@@ -124,7 +122,6 @@ class BackPanelController private constructor(
        fun create(context: Context, backAnimation: BackAnimation?): BackPanelController {
            val backPanelController = BackPanelController(
                context,
                backAnimation,
                windowManager,
                viewConfiguration,
                mainHandler,
@@ -266,7 +263,6 @@ class BackPanelController private constructor(
     */
    private fun updateConfiguration() {
        params.update(resources)
        updateBackAnimationSwipeThresholds()
        mView.updateArrowPaint(params.arrowThickness)
    }

@@ -298,13 +294,6 @@ class BackPanelController private constructor(
    }

    override fun onMotionEvent(event: MotionEvent) {
        backAnimation?.onBackMotion(
            event.x,
            event.y,
            event.actionMasked,
            if (mView.isLeftPanel) BackEvent.EDGE_LEFT else BackEvent.EDGE_RIGHT
        )

        velocityTracker!!.addMovement(event)
        when (event.actionMasked) {
            MotionEvent.ACTION_DOWN -> {
@@ -483,18 +472,6 @@ class BackPanelController private constructor(
        )
    }

    fun setBackAnimation(backAnimation: BackAnimation?) {
        this.backAnimation = backAnimation
        updateBackAnimationSwipeThresholds()
    }

    private fun updateBackAnimationSwipeThresholds() {
        backAnimation?.setSwipeThresholds(
            params.swipeTriggerThreshold,
            fullyStretchedThreshold
        )
    }

    override fun onDestroy() {
        cancelFailsafe()
        windowManager.removeView(mView)
@@ -567,7 +544,6 @@ class BackPanelController private constructor(
        totalTouchDelta = 0f
        vibrationTime = 0
        cancelFailsafe()
        backAnimation?.setTriggerBack(false)
    }

    private fun updateYPosition(touchY: Float) {
@@ -580,7 +556,6 @@ class BackPanelController private constructor(
    override fun setDisplaySize(displaySize: Point) {
        this.displaySize.set(displaySize.x, displaySize.y)
        fullyStretchedThreshold = min(displaySize.x.toFloat(), params.swipeProgressThreshold)
        updateBackAnimationSwipeThresholds()
    }

    /**
@@ -664,7 +639,6 @@ class BackPanelController private constructor(
                updateRestingArrowDimens(animated = true, currentState)
            }
            GestureState.ACTIVE -> {
                backAnimation?.setTriggerBack(true)
                updateRestingArrowDimens(animated = true, currentState)
                // Vibrate the first time we transition to ACTIVE
                if (!hasHapticPlayed) {
@@ -674,7 +648,6 @@ class BackPanelController private constructor(
                }
            }
            GestureState.INACTIVE -> {
                backAnimation?.setTriggerBack(false)
                updateRestingArrowDimens(animated = true, currentState)
            }
            GestureState.FLUNG -> playFlingBackAnimation()
+39 −7
Original line number Diff line number Diff line
@@ -53,6 +53,7 @@ import android.view.MotionEvent;
import android.view.Surface;
import android.view.ViewConfiguration;
import android.view.WindowManager;
import android.window.BackEvent;

import com.android.internal.config.sysui.SystemUiDeviceConfigFlags;
import com.android.internal.policy.GestureNavigationSettingsObserver;
@@ -208,6 +209,10 @@ public class EdgeBackGestureHandler extends CurrentUserTracker
    private float mBottomGestureHeight;
    // The slop to distinguish between horizontal and vertical motion
    private float mTouchSlop;
    // The threshold for triggering back
    private float mBackSwipeTriggerThreshold;
    // The threshold for back swipe full progress.
    private float mBackSwipeProgressThreshold;
    // Duration after which we consider the event as longpress.
    private final int mLongPressTimeout;
    private int mStartingQuickstepRotation = -1;
@@ -274,6 +279,8 @@ public class EdgeBackGestureHandler extends CurrentUserTracker
                            Log.d(DEBUG_MISSING_GESTURE_TAG, "Triggered back: down="
                                    + sendDown + ", up=" + sendUp);
                        }
                    } else {
                        mBackAnimation.setTriggerBack(true);
                    }

                    mOverviewProxyService.notifyBackAction(true, (int) mDownPoint.x,
@@ -285,6 +292,9 @@ public class EdgeBackGestureHandler extends CurrentUserTracker

                @Override
                public void cancelBack() {
                    if (mBackAnimation != null) {
                        mBackAnimation.setTriggerBack(false);
                    }
                    logGesture(SysUiStatsLog.BACK_GESTURE__TYPE__INCOMPLETE);
                    mOverviewProxyService.notifyBackAction(false, (int) mDownPoint.x,
                            (int) mDownPoint.y, false /* isButton */, !mIsOnLeftEdge);
@@ -406,6 +416,11 @@ public class EdgeBackGestureHandler extends CurrentUserTracker
        final float backGestureSlop = DeviceConfig.getFloat(DeviceConfig.NAMESPACE_SYSTEMUI,
                        SystemUiDeviceConfigFlags.BACK_GESTURE_SLOP_MULTIPLIER, 0.75f);
        mTouchSlop = mViewConfiguration.getScaledTouchSlop() * backGestureSlop;
        mBackSwipeTriggerThreshold = res.getDimension(
                R.dimen.navigation_edge_action_drag_threshold);
        mBackSwipeProgressThreshold = res.getDimension(
                R.dimen.navigation_edge_action_progress_threshold);
        updateBackAnimationThresholds();
    }

    public void updateNavigationBarOverlayExcludeRegion(Rect exclude) {
@@ -748,6 +763,7 @@ public class EdgeBackGestureHandler extends CurrentUserTracker
        MotionEvent cancelEv = MotionEvent.obtain(ev);
        cancelEv.setAction(MotionEvent.ACTION_CANCEL);
        mEdgeBackPlugin.onMotionEvent(cancelEv);
        dispatchToBackAnimation(cancelEv);
        cancelEv.recycle();
    }

@@ -794,6 +810,7 @@ public class EdgeBackGestureHandler extends CurrentUserTracker
            if (mAllowGesture) {
                mEdgeBackPlugin.setIsLeftPanel(mIsOnLeftEdge);
                mEdgeBackPlugin.onMotionEvent(ev);
                dispatchToBackAnimation(ev);
            }
            if (mLogGesture) {
                mDownPoint.set(ev.getX(), ev.getY());
@@ -867,12 +884,23 @@ public class EdgeBackGestureHandler extends CurrentUserTracker
            if (mAllowGesture) {
                // forward touch
                mEdgeBackPlugin.onMotionEvent(ev);
                dispatchToBackAnimation(ev);
            }
        }

        mProtoTracer.scheduleFrameUpdate();
    }

    private void dispatchToBackAnimation(MotionEvent event) {
        if (mBackAnimation != null) {
            mBackAnimation.onBackMotion(
                    event.getX(),
                    event.getY(),
                    event.getActionMasked(),
                    mIsOnLeftEdge ? BackEvent.EDGE_LEFT : BackEvent.EDGE_RIGHT);
        }
    }

    private void updateDisabledForQuickstep(Configuration newConfig) {
        int rotation = newConfig.windowConfiguration.getRotation();
        mDisabledForQuickstep = mStartingQuickstepRotation > -1 &&
@@ -900,6 +928,16 @@ public class EdgeBackGestureHandler extends CurrentUserTracker
        if (mEdgeBackPlugin != null) {
            mEdgeBackPlugin.setDisplaySize(mDisplaySize);
        }
        updateBackAnimationThresholds();
    }

    private void updateBackAnimationThresholds() {
        if (mBackAnimation == null) {
            return;
        }
        mBackAnimation.setSwipeThresholds(
                mBackSwipeTriggerThreshold,
                Math.min(mDisplaySize.x, mBackSwipeProgressThreshold));
    }

    private boolean sendEvent(int action, int code) {
@@ -979,13 +1017,7 @@ public class EdgeBackGestureHandler extends CurrentUserTracker

    public void setBackAnimation(BackAnimation backAnimation) {
        mBackAnimation = backAnimation;
        if (mEdgeBackPlugin != null) {
            if (mEdgeBackPlugin instanceof NavigationBarEdgePanel) {
                ((NavigationBarEdgePanel) mEdgeBackPlugin).setBackAnimation(backAnimation);
            } else if (mEdgeBackPlugin instanceof BackPanelController) {
                ((BackPanelController) mEdgeBackPlugin).setBackAnimation(backAnimation);
            }
        }
        updateBackAnimationThresholds();
    }

    /**