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

Commit c127dff1 authored by Sunny Goyal's avatar Sunny Goyal
Browse files

Unifying FallbackNoButton input consumer with OtherActivityInputConsumer

using a different handler

This will allow us to use common logic for handling horizontal swipe

Bug: 137197916
Change-Id: I6f9cba6e8728dd0669482906c4bf34270af2bc82
parent 6b0eb384
Loading
Loading
Loading
Loading
+68 −5
Original line number Diff line number Diff line
@@ -22,22 +22,32 @@ import static com.android.launcher3.anim.Interpolators.DEACCEL;
import static com.android.quickstep.TouchInteractionService.BACKGROUND_EXECUTOR;

import android.annotation.TargetApi;
import android.app.ActivityManager.RunningTaskInfo;
import android.content.Context;
import android.graphics.PointF;
import android.os.Build;
import android.os.VibrationEffect;
import android.os.Vibrator;
import android.provider.Settings;
import android.view.MotionEvent;
import android.view.animation.Interpolator;

import com.android.launcher3.Utilities;
import com.android.launcher3.graphics.RotationMode;
import com.android.quickstep.util.ClipAnimationHelper;
import com.android.quickstep.util.ClipAnimationHelper.TransformParams;
import com.android.quickstep.util.SwipeAnimationTargetSet.SwipeAnimationListener;
import com.android.quickstep.views.RecentsView;

import java.util.function.Consumer;

import androidx.annotation.UiThread;

/**
 * Base class for swipe up handler with some utility methods
 */
@TargetApi(Build.VERSION_CODES.Q)
public abstract class BaseSwipeUpHandler {
public abstract class BaseSwipeUpHandler implements SwipeAnimationListener {

    // Start resisting when swiping past this factor of mTransitionDragLength.
    private static final float DRAG_LENGTH_FACTOR_START_PULLBACK = 1.4f;
@@ -57,6 +67,16 @@ public abstract class BaseSwipeUpHandler {

    private final Vibrator mVibrator;

    // Shift in the range of [0, 1].
    // 0 => preview snapShot is completely visible, and hotseat is completely translated down
    // 1 => preview snapShot is completely aligned with the recents view and hotseat is completely
    // visible.
    protected final AnimatedFloat mCurrentShift = new AnimatedFloat(this::updateFinalShift);

    protected RecentsView mRecentsView;

    protected Runnable mGestureEndCallback;

    protected BaseSwipeUpHandler(Context context) {
        mContext = context;
        mClipAnimationHelper = new ClipAnimationHelper(context);
@@ -80,14 +100,20 @@ public abstract class BaseSwipeUpHandler {
        BACKGROUND_EXECUTOR.execute(() -> mVibrator.vibrate(effect));
    }

    protected float getShiftForDisplacement(float displacement) {
    public Consumer<MotionEvent> getRecentsViewDispatcher(RotationMode rotationMode) {
        return mRecentsView != null ? mRecentsView.getEventDispatcher(rotationMode) : null;
    }

    @UiThread
    public void updateDisplacement(float displacement) {
        // We are moving in the negative x/y direction
        displacement = -displacement;
        float shift;
        if (displacement > mTransitionDragLength * mDragLengthFactor && mTransitionDragLength > 0) {
            return mDragLengthFactor;
            shift = mDragLengthFactor;
        } else {
            float translation = Math.max(displacement, 0);
            float shift = mTransitionDragLength == 0 ? 0 : translation / mTransitionDragLength;
            shift = mTransitionDragLength == 0 ? 0 : translation / mTransitionDragLength;
            if (shift > DRAG_LENGTH_FACTOR_START_PULLBACK) {
                float pullbackProgress = Utilities.getProgress(shift,
                        DRAG_LENGTH_FACTOR_START_PULLBACK, mDragLengthFactor);
@@ -95,7 +121,44 @@ public abstract class BaseSwipeUpHandler {
                shift = DRAG_LENGTH_FACTOR_START_PULLBACK + pullbackProgress
                        * (DRAG_LENGTH_FACTOR_MAX_PULLBACK - DRAG_LENGTH_FACTOR_START_PULLBACK);
            }
            return shift;
        }

        mCurrentShift.updateValue(shift);
    }

    public void setGestureEndCallback(Runnable gestureEndCallback) {
        mGestureEndCallback = gestureEndCallback;
    }

    /**
     * Called when the value of {@link #mCurrentShift} changes
     */
    public abstract void updateFinalShift();


    /**
     * Called when motion pause is detected
     */
    public abstract void onMotionPauseChanged(boolean isPaused);

    @UiThread
    public void onGestureStarted() { }

    @UiThread
    public abstract void onGestureCancelled();

    @UiThread
    public abstract void onGestureEnded(float endVelocity, PointF velocity, PointF downPos);

    public void onConsumerAboutToBeSwitched(SwipeSharedState sharedState) { }

    public void setIsLikelyToStartNewTask(boolean isLikelyToStartNewTask) { }

    public void initWhenReady() { }

    public interface Factory {

        BaseSwipeUpHandler newHandler(RunningTaskInfo runningTask,
                long touchTimeMs, boolean continuingLastGesture);
    }
}
+6 −0
Original line number Diff line number Diff line
@@ -199,6 +199,12 @@ public final class RecentsActivity extends BaseRecentsActivity {
        mFallbackRecentsView.resetTaskVisuals();
    }

    @Override
    protected void onStop() {
        super.onStop();
        mFallbackRecentsView.reset();
    }

    public void onTaskLaunched() {
        mFallbackRecentsView.resetTaskVisuals();
    }
+37 −12
Original line number Diff line number Diff line
@@ -239,6 +239,11 @@ public class TouchInteractionService extends Service implements
    private final InputConsumer mResetGestureInputConsumer =
            new ResetGestureInputConsumer(sSwipeSharedState);

    private final BaseSwipeUpHandler.Factory mWindowTreansformFactory =
            this::createWindowTransformSwipeHandler;
    private final BaseSwipeUpHandler.Factory mFallbackNoButtonFactory =
            this::createFallbackNoButtonSwipeHandler;

    private ActivityManagerWrapper mAM;
    private RecentsModel mRecentsModel;
    private ISystemUiProxy mISystemUiProxy;
@@ -623,10 +628,6 @@ public class TouchInteractionService extends Service implements
        } else if (mGestureBlockingActivity != null && runningTaskInfo != null
                && mGestureBlockingActivity.equals(runningTaskInfo.topActivity)) {
            return mResetGestureInputConsumer;
        } else if (mMode == Mode.NO_BUTTON && !mOverviewComponentObserver.isHomeAndOverviewSame()) {
            return new FallbackNoButtonInputConsumer(this, activityControl,
                    mInputMonitorCompat, sSwipeSharedState, mSwipeTouchRegion,
                    mOverviewComponentObserver, disableHorizontalSwipe(event), runningTaskInfo);
        } else {
            return createOtherActivityInputConsumer(event, runningTaskInfo);
        }
@@ -639,17 +640,28 @@ public class TouchInteractionService extends Service implements
                && exclusionRegion.contains((int) event.getX(), (int) event.getY());
    }

    private OtherActivityInputConsumer createOtherActivityInputConsumer(MotionEvent event,
    private InputConsumer createOtherActivityInputConsumer(MotionEvent event,
            RunningTaskInfo runningTaskInfo) {
        final ActivityControlHelper activityControl =
                mOverviewComponentObserver.getActivityControlHelper();
        boolean shouldDefer = activityControl.deferStartingActivity(mActiveNavBarRegion, event);

        return new OtherActivityInputConsumer(this, runningTaskInfo, mRecentsModel,
                mOverviewComponentObserver.getOverviewIntent(), activityControl,
                shouldDefer, mOverviewCallbacks, mInputConsumer, this::onConsumerInactive,
        final boolean shouldDefer;
        final BaseSwipeUpHandler.Factory factory;
        final Intent homeIntent;

        if (mMode == Mode.NO_BUTTON && !mOverviewComponentObserver.isHomeAndOverviewSame()) {
            shouldDefer = true;
            factory = mFallbackNoButtonFactory;
            homeIntent = mOverviewComponentObserver.getHomeIntent();
        } else {
            shouldDefer = mOverviewComponentObserver.getActivityControlHelper()
                    .deferStartingActivity(mActiveNavBarRegion, event);
            factory = mWindowTreansformFactory;
            homeIntent = mOverviewComponentObserver.getOverviewIntent();
        }

        return new OtherActivityInputConsumer(this, runningTaskInfo, homeIntent,
                shouldDefer, mOverviewCallbacks, this::onConsumerInactive,
                sSwipeSharedState, mInputMonitorCompat, mSwipeTouchRegion,
                disableHorizontalSwipe(event));
                disableHorizontalSwipe(event), factory);
    }

    private InputConsumer createDeviceLockedInputConsumer(RunningTaskInfo taskInfo) {
@@ -788,6 +800,19 @@ public class TouchInteractionService extends Service implements
        }
    }

    private BaseSwipeUpHandler createWindowTransformSwipeHandler(RunningTaskInfo runningTask,
            long touchTimeMs, boolean continuingLastGesture) {
        return  new WindowTransformSwipeHandler(
                runningTask, this, touchTimeMs,
                mOverviewComponentObserver.getActivityControlHelper(),
                continuingLastGesture, mInputConsumer, mRecentsModel);
    }

    private BaseSwipeUpHandler createFallbackNoButtonSwipeHandler(RunningTaskInfo runningTask,
            long touchTimeMs, boolean continuingLastGesture) {
        return new FallbackNoButtonInputConsumer(this, mOverviewComponentObserver, runningTask);
    }

    public static void startRecentsActivityAsync(Intent intent, RecentsAnimationListener listener) {
        BACKGROUND_EXECUTOR.execute(() -> ActivityManagerWrapper.getInstance()
                .startRecentsActivity(intent, null, listener, null, null));
+31 −42
Original line number Diff line number Diff line
@@ -58,7 +58,6 @@ import android.os.Handler;
import android.os.Looper;
import android.os.SystemClock;
import android.util.Log;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnApplyWindowInsetsListener;
import android.view.ViewTreeObserver.OnDrawListener;
@@ -66,10 +65,6 @@ import android.view.WindowInsets;
import android.view.WindowManager;
import android.view.animation.Interpolator;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.UiThread;

import com.android.launcher3.AbstractFloatingView;
import com.android.launcher3.BaseDraggingActivity;
import com.android.launcher3.DeviceProfile;
@@ -79,7 +74,6 @@ import com.android.launcher3.Utilities;
import com.android.launcher3.anim.AnimationSuccessListener;
import com.android.launcher3.anim.AnimatorPlaybackController;
import com.android.launcher3.anim.Interpolators;
import com.android.launcher3.graphics.RotationMode;
import com.android.launcher3.logging.UserEventDispatcher;
import com.android.launcher3.testing.TestProtocol;
import com.android.launcher3.userevent.nano.LauncherLogProto.Action.Direction;
@@ -99,9 +93,7 @@ import com.android.quickstep.util.ClipAnimationHelper.TargetAlphaProvider;
import com.android.quickstep.util.RectFSpringAnim;
import com.android.quickstep.util.RemoteAnimationTargetSet;
import com.android.quickstep.util.SwipeAnimationTargetSet;
import com.android.quickstep.util.SwipeAnimationTargetSet.SwipeAnimationListener;
import com.android.quickstep.views.LiveTileOverlay;
import com.android.quickstep.views.RecentsView;
import com.android.quickstep.views.TaskView;
import com.android.systemui.shared.recents.model.ThumbnailData;
import com.android.systemui.shared.system.InputConsumerController;
@@ -110,11 +102,12 @@ import com.android.systemui.shared.system.RemoteAnimationTargetCompat;
import com.android.systemui.shared.system.SyncRtSurfaceTransactionApplierCompat;
import com.android.systemui.shared.system.WindowCallbacksCompat;

import java.util.function.Consumer;
import androidx.annotation.NonNull;
import androidx.annotation.UiThread;

@TargetApi(Build.VERSION_CODES.O)
public class WindowTransformSwipeHandler<T extends BaseDraggingActivity> extends BaseSwipeUpHandler
        implements SwipeAnimationListener, OnApplyWindowInsetsListener {
        implements OnApplyWindowInsetsListener {
    private static final String TAG = WindowTransformSwipeHandler.class.getSimpleName();

    private static final Rect TEMP_RECT = new Rect();
@@ -222,18 +215,12 @@ public class WindowTransformSwipeHandler<T extends BaseDraggingActivity> extends
     */
    private static final int LOG_NO_OP_PAGE_INDEX = -1;

    private Runnable mGestureEndCallback;
    private GestureEndTarget mGestureEndTarget;
    // Either RectFSpringAnim (if animating home) or ObjectAnimator (from mCurrentShift) otherwise
    private RunningWindowAnim mRunningWindowAnim;
    private boolean mIsShelfPeeking;
    private DeviceProfile mDp;

    // Shift in the range of [0, 1].
    // 0 => preview snapShot is completely visible, and hotseat is completely translated down
    // 1 => preview snapShot is completely aligned with the recents view and hotseat is completely
    // visible.
    private final AnimatedFloat mCurrentShift = new AnimatedFloat(this::updateFinalShift);
    private boolean mContinuingLastGesture;
    // To avoid UI jump when gesture is started, we offset the animation by the threshold.
    private float mShiftAtGestureStart = 0;
@@ -242,6 +229,7 @@ public class WindowTransformSwipeHandler<T extends BaseDraggingActivity> extends

    private final ActivityControlHelper<T> mActivityControlHelper;
    private final ActivityInitListener mActivityInitListener;
    private final RecentsModel mRecentsModel;

    private final SysUINavigationMode.Mode mMode;

@@ -254,7 +242,6 @@ public class WindowTransformSwipeHandler<T extends BaseDraggingActivity> extends
    private boolean mHasLauncherTransitionControllerStarted;

    private T mActivity;
    private RecentsView mRecentsView;
    private AnimationFactory mAnimationFactory = (t) -> { };
    private LiveTileOverlay mLiveTileOverlay = new LiveTileOverlay();

@@ -276,11 +263,12 @@ public class WindowTransformSwipeHandler<T extends BaseDraggingActivity> extends

    public WindowTransformSwipeHandler(RunningTaskInfo runningTaskInfo, Context context,
            long touchTimeMs, ActivityControlHelper<T> controller, boolean continuingLastGesture,
            InputConsumerController inputConsumer) {
            InputConsumerController inputConsumer, RecentsModel recentsModel) {
        super(context);
        mRunningTaskId = runningTaskInfo.id;
        mTouchTimeMs = touchTimeMs;
        mActivityControlHelper = controller;
        mRecentsModel = recentsModel;
        mActivityInitListener = mActivityControlHelper
                .createActivityInitListener(this::onActivityInit);
        mContinuingLastGesture = continuingLastGesture;
@@ -375,7 +363,11 @@ public class WindowTransformSwipeHandler<T extends BaseDraggingActivity> extends
        }
    }

    @Override
    public void initWhenReady() {
        // Preload the plan
        mRecentsModel.getTasks(null);

        mActivityInitListener.register();
    }

@@ -546,15 +538,7 @@ public class WindowTransformSwipeHandler<T extends BaseDraggingActivity> extends
        return TaskView.getCurveScaleForInterpolation(interpolation);
    }

    public Consumer<MotionEvent> getRecentsViewDispatcher(RotationMode rotationMode) {
        return mRecentsView != null ? mRecentsView.getEventDispatcher(rotationMode) : null;
    }

    @UiThread
    public void updateDisplacement(float displacement) {
        mCurrentShift.updateValue(getShiftForDisplacement(displacement));
    }

    @Override
    public void onMotionPauseChanged(boolean isPaused) {
        setShelfState(isPaused ? PEEK : HIDE, OVERSHOOT_1_2, SHELF_ANIM_DURATION);
    }
@@ -605,6 +589,7 @@ public class WindowTransformSwipeHandler<T extends BaseDraggingActivity> extends
        mAnimationFactory.setRecentsAttachedToAppWindow(recentsAttachedToAppWindow, animate);
    }

    @Override
    public void setIsLikelyToStartNewTask(boolean isLikelyToStartNewTask) {
        if (mIsLikelyToStartNewTask != isLikelyToStartNewTask) {
            mIsLikelyToStartNewTask = isLikelyToStartNewTask;
@@ -651,7 +636,8 @@ public class WindowTransformSwipeHandler<T extends BaseDraggingActivity> extends
    }

    @UiThread
    private void updateFinalShift() {
    @Override
    public void updateFinalShift() {
        float shift = mCurrentShift.value;

        SwipeAnimationTargetSet controller = mRecentsAnimationWrapper.getController();
@@ -766,7 +752,7 @@ public class WindowTransformSwipeHandler<T extends BaseDraggingActivity> extends
        TOUCH_INTERACTION_LOG.addLog("cancelRecentsAnimation");
    }

    @UiThread
    @Override
    public void onGestureStarted() {
        notifyGestureStartedAsync();
        mShiftAtGestureStart = mCurrentShift.value;
@@ -790,7 +776,7 @@ public class WindowTransformSwipeHandler<T extends BaseDraggingActivity> extends
    /**
     * Called as a result on ACTION_CANCEL to return the UI to the start state.
     */
    @UiThread
    @Override
    public void onGestureCancelled() {
        updateDisplacement(0);
        setStateOnUiThread(STATE_GESTURE_COMPLETED);
@@ -803,7 +789,7 @@ public class WindowTransformSwipeHandler<T extends BaseDraggingActivity> extends
     * @param velocity The x and y components of the velocity when the gesture ends.
     * @param downPos The x and y value of where the gesture started.
     */
    @UiThread
    @Override
    public void onGestureEnded(float endVelocity, PointF velocity, PointF downPos) {
        float flingThreshold = mContext.getResources()
                .getDimension(R.dimen.quickstep_fling_threshold_velocity);
@@ -1174,11 +1160,18 @@ public class WindowTransformSwipeHandler<T extends BaseDraggingActivity> extends
        return anim;
    }

    /**
     * @return The GestureEndTarget if the gesture has ended, else null.
     */
    public @Nullable GestureEndTarget getGestureEndTarget() {
        return mGestureEndTarget;
    @Override
    public void onConsumerAboutToBeSwitched(SwipeSharedState sharedState) {
        if (mGestureEndTarget != null) {
            sharedState.canGestureBeContinued = mGestureEndTarget.canBeContinued;
            sharedState.goingToLauncher = mGestureEndTarget.isLauncher;
        }

        if (sharedState.canGestureBeContinued) {
            cancelCurrentAnimation(sharedState);
        } else {
            reset();
        }
    }

    @UiThread
@@ -1227,7 +1220,7 @@ public class WindowTransformSwipeHandler<T extends BaseDraggingActivity> extends
        TOUCH_INTERACTION_LOG.addLog("finishRecentsAnimation", true);
    }

    public void reset() {
    private void reset() {
        setStateOnUiThread(STATE_HANDLER_INVALIDATED);
    }

@@ -1235,7 +1228,7 @@ public class WindowTransformSwipeHandler<T extends BaseDraggingActivity> extends
     * Cancels any running animation so that the active target can be overriden by a new swipe
     * handle (in case of quick switch).
     */
    public void cancelCurrentAnimation(SwipeSharedState sharedState) {
    private void cancelCurrentAnimation(SwipeSharedState sharedState) {
        mCanceled = true;
        mCurrentShift.cancelAnimation();
        if (mLauncherTransitionController != null && mLauncherTransitionController
@@ -1398,10 +1391,6 @@ public class WindowTransformSwipeHandler<T extends BaseDraggingActivity> extends
        reset();
    }

    public void setGestureEndCallback(Runnable gestureEndCallback) {
        mGestureEndCallback = gestureEndCallback;
    }

    private void setTargetAlphaProvider(TargetAlphaProvider provider) {
        mClipAnimationHelper.setTaskAlphaCallback(provider);
        updateFinalShift();
+30 −224

File changed.

Preview size limit exceeded, changes collapsed.

Loading