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

Commit d5315f8c authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Using taskView simulator for animation a task to recentsView" into ub-launcher3-rvc-dev

parents e5a83db4 b9abae9f
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -71,7 +71,7 @@ public final class RecentsViewStateController extends
            builder.addOnFrameCallback(mRecentsView::loadVisibleTaskData);
            mRecentsView.updateEmptyMessage();
        } else {
            builder.getAnim().addListener(
            builder.addListener(
                    AnimationSuccessListener.forRunnable(mRecentsView::resetTaskVisuals));
        }

+39 −63
Original line number Diff line number Diff line
@@ -18,29 +18,26 @@ package com.android.quickstep;
import static com.android.launcher3.LauncherState.BACKGROUND_APP;
import static com.android.launcher3.LauncherState.OVERVIEW;
import static com.android.launcher3.anim.Interpolators.TOUCH_RESPONSE_INTERPOLATOR;
import static com.android.launcher3.anim.Interpolators.clampToProgress;
import static com.android.launcher3.statehandlers.DepthController.DEPTH;
import static com.android.systemui.shared.system.RemoteAnimationTargetCompat.MODE_CLOSING;
import static com.android.systemui.shared.system.RemoteAnimationTargetCompat.MODE_OPENING;

import android.animation.Animator;
import android.animation.AnimatorSet;
import android.animation.ObjectAnimator;
import android.animation.ValueAnimator;
import android.graphics.Rect;
import android.util.Log;
import android.view.View;
import android.view.animation.Interpolator;

import com.android.launcher3.AbstractFloatingView;
import com.android.launcher3.anim.AnimationSuccessListener;
import com.android.launcher3.anim.PendingAnimation;
import com.android.launcher3.statehandlers.DepthController;
import com.android.launcher3.statemanager.StatefulActivity;
import com.android.quickstep.util.AppWindowAnimationHelper;
import com.android.quickstep.util.RemoteAnimationProvider;
import com.android.quickstep.util.TaskViewSimulator;
import com.android.quickstep.util.TransformParams;
import com.android.quickstep.views.RecentsView;
import com.android.systemui.shared.system.RemoteAnimationTargetCompat;
import com.android.systemui.shared.system.SyncRtSurfaceTransactionApplierCompat;
import com.android.systemui.shared.system.TransactionCompat;

/**
 * Provider for the atomic (for 3-button mode) remote window animation from the app to the overview.
@@ -97,32 +94,25 @@ final class AppToOverviewAnimationProvider<T extends StatefulActivity<?>> extend
    @Override
    public AnimatorSet createWindowAnimation(RemoteAnimationTargetCompat[] appTargets,
            RemoteAnimationTargetCompat[] wallpaperTargets) {
        if (mRecentsView != null) {
            mRecentsView.setRunningTaskIconScaledDown(true);
        PendingAnimation pa = new PendingAnimation(RECENTS_LAUNCH_DURATION);
        if (mActivity == null) {
            Log.e(TAG, "Animation created, before activity");
            return pa.buildAnim();
        }

        AnimatorSet anim = new AnimatorSet();
        anim.addListener(new AnimationSuccessListener() {
        mRecentsView.setRunningTaskIconScaledDown(true);
        pa.addListener(new AnimationSuccessListener() {
            @Override
            public void onAnimationSuccess(Animator animator) {
                mActivityInterface.onSwipeUpToRecentsComplete();
                if (mRecentsView != null) {
                mRecentsView.animateUpRunningTaskIconScale();
            }
            }
        });
        if (mActivity == null) {
            Log.e(TAG, "Animation created, before activity");
            anim.play(ValueAnimator.ofInt(0, 1).setDuration(RECENTS_LAUNCH_DURATION));
            return anim;
        }

        DepthController depthController = mActivityInterface.getDepthController();
        if (depthController != null) {
            anim.play(ObjectAnimator.ofFloat(depthController, DEPTH,
                    BACKGROUND_APP.getDepth(mActivity),
                    OVERVIEW.getDepth(mActivity))
                    .setDuration(RECENTS_LAUNCH_DURATION));
            pa.addFloat(depthController, DEPTH, BACKGROUND_APP.getDepth(mActivity),
                    OVERVIEW.getDepth(mActivity), TOUCH_RESPONSE_INTERPOLATOR);
        }

        RemoteAnimationTargets targets = new RemoteAnimationTargets(appTargets,
@@ -132,53 +122,39 @@ final class AppToOverviewAnimationProvider<T extends StatefulActivity<?>> extend
        RemoteAnimationTargetCompat runningTaskTarget = targets.findTask(mTargetTaskId);
        if (runningTaskTarget == null) {
            Log.e(TAG, "No closing app");
            anim.play(ValueAnimator.ofInt(0, 1).setDuration(RECENTS_LAUNCH_DURATION));
            return anim;
            return pa.buildAnim();
        }

        final AppWindowAnimationHelper clipHelper = new AppWindowAnimationHelper(
            mRecentsView.getPagedViewOrientedState(), mActivity);

        // At this point, the activity is already started and laid-out. Get the home-bounds
        // relative to the screen using the rootView of the activity.
        int loc[] = new int[2];
        View rootView = mActivity.getRootView();
        rootView.getLocationOnScreen(loc);
        Rect homeBounds = new Rect(loc[0], loc[1],
                loc[0] + rootView.getWidth(), loc[1] + rootView.getHeight());
        clipHelper.updateSource(homeBounds, runningTaskTarget);

        Rect targetRect = new Rect();
        mActivityInterface.getSwipeUpDestinationAndLength(mActivity.getDeviceProfile(), mActivity,
                targetRect);
        clipHelper.updateTargetRect(targetRect);
        clipHelper.prepareAnimation(mActivity.getDeviceProfile());
        TaskViewSimulator tsv = new TaskViewSimulator(mActivity, mRecentsView.getSizeStrategy());
        tsv.setDp(mActivity.getDeviceProfile());
        tsv.setPreview(runningTaskTarget);
        tsv.setLayoutRotation(mRecentsView.getPagedViewOrientedState().getTouchRotation(),
                mRecentsView.getPagedViewOrientedState().getDisplayRotation());

        TransformParams params = new TransformParams()
                .setSyncTransactionApplier(new SyncRtSurfaceTransactionApplierCompat(rootView));
        ValueAnimator valueAnimator = ValueAnimator.ofFloat(0, 1);
        valueAnimator.setDuration(RECENTS_LAUNCH_DURATION);
        valueAnimator.setInterpolator(TOUCH_RESPONSE_INTERPOLATOR);
        valueAnimator.addUpdateListener((v) -> {
            params.setProgress((float) v.getAnimatedValue()).setTargetSet(targets);
            clipHelper.applyTransform(params);
        });
                .setTargetSet(targets)
                .setSyncTransactionApplier(
                        new SyncRtSurfaceTransactionApplierCompat(mActivity.getRootView()));

        AnimatedFloat recentsAlpha = new AnimatedFloat(() -> { });
        params.setBaseAlphaCallback((t, a) -> recentsAlpha.value);

        Interpolator taskInterpolator;
        if (targets.isAnimatingHome()) {
            // If we are animating home, fade in the opening targets
            RemoteAnimationTargets openingSet = new RemoteAnimationTargets(appTargets,
                    wallpaperTargets, MODE_OPENING);

            TransactionCompat transaction = new TransactionCompat();
            valueAnimator.addUpdateListener((v) -> {
                for (RemoteAnimationTargetCompat app : openingSet.apps) {
                    transaction.setAlpha(app.leash, (float) v.getAnimatedValue());
            taskInterpolator = TOUCH_RESPONSE_INTERPOLATOR;
            pa.addFloat(recentsAlpha, AnimatedFloat.VALUE, 0, 1, TOUCH_RESPONSE_INTERPOLATOR);
        } else {
            // When animation from app to recents, the recents layer is drawn on top of the app. To
            // prevent the overlap, we animate the task first and then quickly fade in the recents.
            taskInterpolator = clampToProgress(TOUCH_RESPONSE_INTERPOLATOR, 0, 0.8f);
            pa.addFloat(recentsAlpha, AnimatedFloat.VALUE, 0, 1,
                    clampToProgress(TOUCH_RESPONSE_INTERPOLATOR, 0.8f, 1));
        }
                transaction.apply();
            });
        }
        anim.play(valueAnimator);
        return anim;

        pa.addFloat(params, TransformParams.PROGRESS, 0, 1, taskInterpolator);
        tsv.addAppToOverviewAnim(pa, taskInterpolator);
        pa.addOnFrameCallback(() -> tsv.apply(params));
        return pa.buildAnim();
    }

    /**
+9 −24
Original line number Diff line number Diff line
@@ -15,8 +15,6 @@
 */
package com.android.quickstep;

import static com.android.launcher3.LauncherState.BACKGROUND_APP;
import static com.android.launcher3.LauncherState.OVERVIEW;
import static com.android.launcher3.anim.Interpolators.ACCEL_1_5;
import static com.android.launcher3.anim.Interpolators.DEACCEL;
import static com.android.launcher3.config.FeatureFlags.ENABLE_QUICKSTEP_LIVE_TILE;
@@ -25,8 +23,6 @@ import static com.android.launcher3.util.VibratorWrapper.OVERVIEW_HAPTIC;
import static com.android.launcher3.views.FloatingIconView.SHAPE_PROGRESS_DURATION;

import android.animation.Animator;
import android.animation.AnimatorSet;
import android.animation.ObjectAnimator;
import android.annotation.TargetApi;
import android.content.Context;
import android.content.Intent;
@@ -50,6 +46,7 @@ import com.android.launcher3.InvariantDeviceProfile;
import com.android.launcher3.Utilities;
import com.android.launcher3.anim.AnimationSuccessListener;
import com.android.launcher3.anim.AnimatorPlaybackController;
import com.android.launcher3.anim.PendingAnimation;
import com.android.launcher3.statemanager.StatefulActivity;
import com.android.launcher3.testing.TestProtocol;
import com.android.launcher3.touch.PagedOrientationHandler;
@@ -380,18 +377,9 @@ public abstract class BaseSwipeUpHandler<T extends StatefulActivity<?>, Q extend
            mDragLengthFactorStartPullback = mDragLengthFactorMaxPullback = 1;
        }

        AnimatorSet anim = new AnimatorSet();
        anim.setDuration(mTransitionDragLength * 2);
        anim.setInterpolator(t -> t * mDragLengthFactor);
        anim.play(ObjectAnimator.ofFloat(mTaskViewSimulator.recentsViewScale,
                AnimatedFloat.VALUE,
                mTaskViewSimulator.getFullScreenScale(), 1));
        anim.play(ObjectAnimator.ofFloat(mTaskViewSimulator.fullScreenProgress,
                AnimatedFloat.VALUE,
                BACKGROUND_APP.getOverviewFullscreenProgress(),
                OVERVIEW.getOverviewFullscreenProgress()));
        mWindowTransitionController =
                AnimatorPlaybackController.wrap(anim, mTransitionDragLength * 2);
        PendingAnimation pa = new PendingAnimation(mTransitionDragLength * 2);
        mTaskViewSimulator.addAppToOverviewAnim(pa, t -> t * mDragLengthFactor);
        mWindowTransitionController = pa.createPlaybackController();
    }

    /**
@@ -663,15 +651,12 @@ public abstract class BaseSwipeUpHandler<T extends StatefulActivity<?>, Q extend
        }

        @Override
        public void onBuildParams(Builder builder, RemoteAnimationTargetCompat app, int targetMode,
                TransformParams params) {
            if (app.mode == targetMode
                    && app.activityType != RemoteAnimationTargetCompat.ACTIVITY_TYPE_HOME) {
        public void onBuildTargetParams(
                Builder builder, RemoteAnimationTargetCompat app, TransformParams params) {
            builder.withMatrix(mMatrix)
                    .withWindowCrop(mCropRect)
                    .withCornerRadius(params.getCornerRadius());
        }
        }

        @Override
        public void onCancel() {
+35 −39
Original line number Diff line number Diff line
@@ -18,6 +18,7 @@ package com.android.quickstep.inputconsumers;
import static android.view.MotionEvent.ACTION_CANCEL;
import static android.view.MotionEvent.ACTION_POINTER_DOWN;
import static android.view.MotionEvent.ACTION_UP;

import static com.android.launcher3.Utilities.squaredHypot;
import static com.android.launcher3.Utilities.squaredTouchSlop;
import static com.android.quickstep.LauncherSwipeHandler.MIN_PROGRESS_FOR_OVERVIEW;
@@ -26,21 +27,22 @@ import static com.android.quickstep.util.ActiveGestureLog.INTENT_EXTRA_LOG_TRACE

import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
import android.animation.ValueAnimator;
import android.animation.ObjectAnimator;
import android.content.Context;
import android.content.Intent;
import android.graphics.Matrix;
import android.graphics.Point;
import android.graphics.PointF;
import android.graphics.Rect;
import android.view.MotionEvent;
import android.view.VelocityTracker;
import android.view.ViewConfiguration;

import com.android.launcher3.R;
import com.android.launcher3.Utilities;
import com.android.launcher3.anim.Interpolators;
import com.android.launcher3.testing.TestLogging;
import com.android.launcher3.testing.TestProtocol;
import com.android.launcher3.util.DefaultDisplay;
import com.android.quickstep.AnimatedFloat;
import com.android.quickstep.GestureState;
import com.android.quickstep.InputConsumer;
import com.android.quickstep.MultiStateCallback;
@@ -49,18 +51,19 @@ import com.android.quickstep.RecentsAnimationController;
import com.android.quickstep.RecentsAnimationDeviceState;
import com.android.quickstep.RecentsAnimationTargets;
import com.android.quickstep.TaskAnimationManager;
import com.android.quickstep.util.AppWindowAnimationHelper;
import com.android.quickstep.util.TransformParams;
import com.android.quickstep.util.TransformParams.BuilderProxy;
import com.android.systemui.shared.recents.model.ThumbnailData;
import com.android.systemui.shared.system.ActivityManagerWrapper;
import com.android.systemui.shared.system.InputMonitorCompat;
import com.android.systemui.shared.system.RemoteAnimationTargetCompat;
import com.android.systemui.shared.system.SyncRtSurfaceTransactionApplierCompat.SurfaceParams.Builder;

/**
 * A dummy input consumer used when the device is still locked, e.g. from secure camera.
 */
public class DeviceLockedInputConsumer implements InputConsumer,
        RecentsAnimationCallbacks.RecentsAnimationListener {
        RecentsAnimationCallbacks.RecentsAnimationListener, BuilderProxy {

    private static final String[] STATE_NAMES = DEBUG_STATES ? new String[2] : null;
    private static int getFlagForIndex(int index, String name) {
@@ -83,19 +86,20 @@ public class DeviceLockedInputConsumer implements InputConsumer,
    private final InputMonitorCompat mInputMonitorCompat;

    private final PointF mTouchDown = new PointF();
    private final AppWindowAnimationHelper mAppWindowAnimationHelper;
    private final TransformParams mTransformParams;
    private final Point mDisplaySize;
    private final MultiStateCallback mStateCallback;

    private final Point mDisplaySize;
    private final Matrix mMatrix = new Matrix();
    private final float mMaxTranslationY;

    private VelocityTracker mVelocityTracker;
    private float mProgress;
    private final AnimatedFloat mProgress = new AnimatedFloat(this::applyTransform);

    private boolean mThresholdCrossed = false;
    private boolean mHomeLaunched = false;

    private RecentsAnimationController mRecentsAnimationController;
    private RecentsAnimationTargets mRecentsAnimationTargets;

    public DeviceLockedInputConsumer(Context context, RecentsAnimationDeviceState deviceState,
            TaskAnimationManager taskAnimationManager, GestureState gestureState,
@@ -105,9 +109,10 @@ public class DeviceLockedInputConsumer implements InputConsumer,
        mTaskAnimationManager = taskAnimationManager;
        mGestureState = gestureState;
        mTouchSlopSquared = squaredTouchSlop(context);
        mAppWindowAnimationHelper = new AppWindowAnimationHelper(context);
        mTransformParams = new TransformParams();
        mInputMonitorCompat = inputMonitorCompat;
        mMaxTranslationY = context.getResources().getDimensionPixelSize(
                R.dimen.device_locked_y_offset);

        // Do not use DeviceProfile as the user data might be locked
        mDisplaySize = DefaultDisplay.INSTANCE.get(context).getInfo().realSize;
@@ -158,9 +163,7 @@ public class DeviceLockedInputConsumer implements InputConsumer,
                    }
                } else {
                    float dy = Math.max(mTouchDown.y - y, 0);
                    mProgress = dy / mDisplaySize.y;
                    mTransformParams.setProgress(mProgress);
                    mAppWindowAnimationHelper.applyTransform(mTransformParams);
                    mProgress.updateValue(dy / mDisplaySize.y);
                }
                break;
            }
@@ -189,20 +192,13 @@ public class DeviceLockedInputConsumer implements InputConsumer,
                // Is fling
                dismissTask = velocityY < 0;
            } else {
                dismissTask = mProgress >= (1 - MIN_PROGRESS_FOR_OVERVIEW);
                dismissTask = mProgress.value >= (1 - MIN_PROGRESS_FOR_OVERVIEW);
            }

            // Animate back to fullscreen before finishing
            ValueAnimator animator = ValueAnimator.ofFloat(mTransformParams.getProgress(), 0f);
            ObjectAnimator animator = mProgress.animateToValue(mProgress.value, 0);
            animator.setDuration(100);
            animator.setInterpolator(Interpolators.ACCEL);
            animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
                @Override
                public void onAnimationUpdate(ValueAnimator valueAnimator) {
                    mTransformParams.setProgress((float) valueAnimator.getAnimatedValue());
                    mAppWindowAnimationHelper.applyTransform(mTransformParams);
                }
            });
            animator.addListener(new AnimatorListenerAdapter() {
                @Override
                public void onAnimationEnd(Animator animation) {
@@ -239,29 +235,15 @@ public class DeviceLockedInputConsumer implements InputConsumer,
    public void onRecentsAnimationStart(RecentsAnimationController controller,
            RecentsAnimationTargets targets) {
        mRecentsAnimationController = controller;
        mRecentsAnimationTargets = targets;

        Rect displaySize = new Rect(0, 0, mDisplaySize.x, mDisplaySize.y);
        RemoteAnimationTargetCompat targetCompat = targets.findTask(
                mGestureState.getRunningTaskId());
        if (targetCompat != null) {
            mAppWindowAnimationHelper.updateSource(displaySize, targetCompat);
        }

        // Offset the surface slightly
        displaySize.offset(0, mContext.getResources().getDimensionPixelSize(
                R.dimen.device_locked_y_offset));
        mTransformParams.setTargetSet(mRecentsAnimationTargets);
        mAppWindowAnimationHelper.updateTargetRect(displaySize);
        mAppWindowAnimationHelper.applyTransform(mTransformParams);

        mTransformParams.setTargetSet(targets);
        applyTransform();
        mStateCallback.setState(STATE_TARGET_RECEIVED);
    }

    @Override
    public void onRecentsAnimationCanceled(ThumbnailData thumbnailData) {
        mRecentsAnimationController = null;
        mRecentsAnimationTargets = null;
        mTransformParams.setTargetSet(null);
    }

    private void endRemoteAnimation() {
@@ -273,6 +255,20 @@ public class DeviceLockedInputConsumer implements InputConsumer,
        }
    }

    private void applyTransform() {
        mTransformParams.setProgress(mProgress.value);
        if (mTransformParams.getTargetSet() != null) {
            mTransformParams.applySurfaceParams(mTransformParams.createSurfaceParams(this));
        }
    }

    @Override
    public void onBuildTargetParams(
            Builder builder, RemoteAnimationTargetCompat app, TransformParams params) {
        mMatrix.setTranslate(0, mProgress.value * mMaxTranslationY);
        builder.withMatrix(mMatrix);
    }

    @Override
    public void onConsumerAboutToBeSwitched() {
        mStateCallback.setState(STATE_HANDLER_INVALIDATED);
+0 −27
Original line number Diff line number Diff line
@@ -77,7 +77,6 @@ public class AppWindowAnimationHelper implements TransformParams.BuilderProxy {
    private final Matrix mTmpMatrix = new Matrix();
    private final Rect mTmpRect = new Rect();
    private final RectF mTmpRectF = new RectF();
    private final RectF mCurrentRectWithInsets = new RectF();
    private RecentsOrientedState mOrientedState;
    // Corner radius of windows, in pixels
    private final float mWindowCornerRadius;
@@ -88,9 +87,6 @@ public class AppWindowAnimationHelper implements TransformParams.BuilderProxy {
    // Whether or not to actually use the rounded cornders on windows
    private boolean mUseRoundedCornersOnWindows;

    // Corner radius currently applied to transformed window.
    private float mCurrentCornerRadius;

    public AppWindowAnimationHelper(RecentsOrientedState orientedState, Context context) {
        Resources res = context.getResources();
        mOrientedState = orientedState;
@@ -100,10 +96,6 @@ public class AppWindowAnimationHelper implements TransformParams.BuilderProxy {
        mUseRoundedCornersOnWindows = mSupportsRoundedCornersOnWindows;
    }

    public AppWindowAnimationHelper(Context context) {
        this(null, context);
    }

    private void updateSourceStack(RemoteAnimationTargetCompat target) {
        mSourceInsets.set(target.contentInsets);
        mSourceStackBounds.set(target.screenSpaceBounds);
@@ -112,15 +104,6 @@ public class AppWindowAnimationHelper implements TransformParams.BuilderProxy {
        mSourceStackBounds.offsetTo(target.position.x, target.position.y);
    }

    public void updateSource(Rect homeStackBounds, RemoteAnimationTargetCompat target) {
        updateSourceStack(target);
        updateHomeBounds(homeStackBounds);
    }

    public void updateHomeBounds(Rect homeStackBounds) {
        mHomeStackBounds.set(homeStackBounds);
    }

    public void updateTargetRect(Rect targetRect) {
        mSourceRect.set(mSourceInsets.left, mSourceInsets.top,
                mSourceStackBounds.width() - mSourceInsets.right,
@@ -205,7 +188,6 @@ public class AppWindowAnimationHelper implements TransformParams.BuilderProxy {
                    cornerRadius = mapRange(boundToRange(params.getProgress(), 0, 1),
                            windowCornerRadius, mTaskCornerRadius);
                }
                mCurrentCornerRadius = cornerRadius;
            }

            builder.withMatrix(mTmpMatrix)
@@ -241,11 +223,6 @@ public class AppWindowAnimationHelper implements TransformParams.BuilderProxy {
                mSourceStackBounds.height() - (mSourceWindowClipInsets.bottom * progress);
    }

    public RectF getCurrentRectWithInsets() {
        mTmpMatrix.mapRect(mCurrentRectWithInsets, mCurrentClipRectF);
        return mCurrentRectWithInsets;
    }

    public void fromTaskThumbnailView(TaskThumbnailView ttv, RecentsView rv,
            @Nullable RemoteAnimationTargetCompat target) {
        BaseDraggingActivity activity = BaseDraggingActivity.fromContext(ttv.getContext());
@@ -317,8 +294,4 @@ public class AppWindowAnimationHelper implements TransformParams.BuilderProxy {
        return mTargetRect;
    }

    public float getCurrentCornerRadius() {
        return mCurrentCornerRadius;
    }

}
Loading