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

Commit 16eb9226 authored by Tony Wickham's avatar Tony Wickham
Browse files

Fix adjacent task offset distance

Instead of calculating an overall distance for tasks to translate
based on RecentsView width, calculate the distance for the tasks
to the left and right of the midpoint based on how far the first
adjacent tasks in those directions are from being offscreen.

Changes made to make "distance to offscreen" calculations possible:
- Update TaskView curve scale to reach final scale as soon as it is
  completely offscreen. Before, it would reach its final scale just
  shy of that point (calculations were off).
- As we update RecentsView scale, calculate how much the new scale
  will push out tasks that are just offscreen.
- With both above, we can calculate the scale and position of a
  TaskView such that it is just offscreen, and interpolate
  between its current position and that position.

Tests:
- Task comes in immediately when quick switching from home, and
  doesn't shift as you swipe directly upwards.
- When swiping far up from an app, tasks come in from all the way
  offscreen, and cover distance appropriately (e.g. if you're
  scrolled a bit to the right when you pause, the left adjacent
  app will move faster to cover the farther distance).
- Task modalness: entering Select mode now animates adjacent tasks
  at the same rate as the scaling up, because they move only the
  distance needed to get offscreen (before they moved way too far
  and thus seemed to be much faster than the rest of the animation).

Bug: 149934536
Change-Id: Ie3fffe0e5c304cb16e7637f058f5ce72cee40aeb
Merged-In: Ie3fffe0e5c304cb16e7637f058f5ce72cee40aeb
parent 94be66ac
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -17,7 +17,6 @@ package com.android.launcher3.uioverrides.states;

import static android.view.View.VISIBLE;

import static com.android.launcher3.LauncherAnimUtils.SCALE_PROPERTY;
import static com.android.launcher3.LauncherState.BACKGROUND_APP;
import static com.android.launcher3.LauncherState.HINT_STATE;
import static com.android.launcher3.LauncherState.HOTSEAT_ICONS;
@@ -52,6 +51,7 @@ import static com.android.launcher3.states.StateAnimationConfig.ANIM_WORKSPACE_S
import static com.android.launcher3.states.StateAnimationConfig.ANIM_WORKSPACE_TRANSLATE;
import static com.android.quickstep.SysUINavigationMode.Mode.NO_BUTTON;
import static com.android.quickstep.SysUINavigationMode.removeShelfFromOverview;
import static com.android.quickstep.views.RecentsView.RECENTS_SCALE_PROPERTY;

import android.animation.Animator;
import android.animation.AnimatorSet;
@@ -212,7 +212,7 @@ public class QuickstepAtomicAnimationFactory extends
                // Scale up the recents, if it is not coming from the side
                RecentsView overview = mActivity.getOverviewPanel();
                if (overview.getVisibility() != VISIBLE || overview.getContentAlpha() == 0) {
                    SCALE_PROPERTY.set(overview, RECENTS_PREPARE_SCALE);
                    RECENTS_SCALE_PROPERTY.set(overview, RECENTS_PREPARE_SCALE);
                }
            }
            config.setInterpolator(ANIM_WORKSPACE_FADE, OVERSHOOT_1_2);
+4 −3
Original line number Diff line number Diff line
@@ -15,7 +15,6 @@
 */
package com.android.launcher3.uioverrides.touchcontrollers;

import static com.android.launcher3.LauncherAnimUtils.SCALE_PROPERTY;
import static com.android.launcher3.LauncherState.HOTSEAT_ICONS;
import static com.android.launcher3.LauncherState.NORMAL;
import static com.android.launcher3.LauncherState.OVERVIEW;
@@ -47,6 +46,7 @@ import static com.android.quickstep.util.ShelfPeekAnim.ShelfAnimState.HIDE;
import static com.android.quickstep.util.ShelfPeekAnim.ShelfAnimState.PEEK;
import static com.android.quickstep.views.RecentsView.ADJACENT_PAGE_OFFSET;
import static com.android.quickstep.views.RecentsView.FULLSCREEN_PROGRESS;
import static com.android.quickstep.views.RecentsView.RECENTS_SCALE_PROPERTY;
import static com.android.systemui.shared.system.QuickStepContract.SYSUI_STATE_OVERVIEW_DISABLED;

import android.animation.Animator;
@@ -244,7 +244,7 @@ public class NoButtonQuickSwitchTouchController implements TouchController,
        final LauncherState toState = OVERVIEW;

        // Set RecentView's initial properties.
        SCALE_PROPERTY.set(mRecentsView, fromState.getOverviewScaleAndOffset(mLauncher)[0]);
        RECENTS_SCALE_PROPERTY.set(mRecentsView, fromState.getOverviewScaleAndOffset(mLauncher)[0]);
        ADJACENT_PAGE_OFFSET.set(mRecentsView, 1f);
        mRecentsView.setContentAlpha(1);
        mRecentsView.setFullscreenProgress(fromState.getOverviewFullscreenProgress());
@@ -266,7 +266,8 @@ public class NoButtonQuickSwitchTouchController implements TouchController,
        //   - RecentsView scale
        //   - RecentsView fullscreenProgress
        PendingAnimation yAnim = new PendingAnimation((long) (mYRange * 2));
        yAnim.setFloat(mRecentsView, SCALE_PROPERTY, scaleAndOffset[0], SCALE_DOWN_INTERPOLATOR);
        yAnim.setFloat(mRecentsView, RECENTS_SCALE_PROPERTY, scaleAndOffset[0],
                SCALE_DOWN_INTERPOLATOR);
        yAnim.setFloat(mRecentsView, FULLSCREEN_PROGRESS,
                toState.getOverviewFullscreenProgress(), SCALE_DOWN_INTERPOLATOR);
        mYOverviewAnim = yAnim.createPlaybackController();
+2 −2
Original line number Diff line number Diff line
@@ -15,7 +15,6 @@
 */
package com.android.quickstep.fallback;

import static com.android.launcher3.LauncherAnimUtils.SCALE_PROPERTY;
import static com.android.launcher3.anim.Interpolators.LINEAR;
import static com.android.launcher3.states.StateAnimationConfig.ANIM_OVERVIEW_MODAL;
import static com.android.launcher3.states.StateAnimationConfig.ANIM_OVERVIEW_SCALE;
@@ -25,6 +24,7 @@ import static com.android.launcher3.states.StateAnimationConfig.PLAY_ATOMIC_OVER
import static com.android.launcher3.states.StateAnimationConfig.SKIP_OVERVIEW;
import static com.android.quickstep.views.RecentsView.ADJACENT_PAGE_OFFSET;
import static com.android.quickstep.views.RecentsView.FULLSCREEN_PROGRESS;
import static com.android.quickstep.views.RecentsView.RECENTS_SCALE_PROPERTY;
import static com.android.quickstep.views.RecentsView.TASK_MODALNESS;

import com.android.launcher3.anim.PendingAnimation;
@@ -82,7 +82,7 @@ public class FallbackRecentsStateController implements StateHandler<RecentsState
                MultiValueAlpha.VALUE, buttonAlpha, LINEAR);

        float[] scaleAndOffset = state.getOverviewScaleAndOffset(mActivity);
        setter.setFloat(mRecentsView, SCALE_PROPERTY, scaleAndOffset[0],
        setter.setFloat(mRecentsView, RECENTS_SCALE_PROPERTY, scaleAndOffset[0],
                config.getInterpolator(ANIM_OVERVIEW_SCALE, LINEAR));
        setter.setFloat(mRecentsView, ADJACENT_PAGE_OFFSET, scaleAndOffset[1],
                config.getInterpolator(ANIM_OVERVIEW_TRANSLATE_X, LINEAR));
+2 −4
Original line number Diff line number Diff line
@@ -31,7 +31,6 @@ import android.graphics.RectF;
import android.util.IntProperty;

import com.android.launcher3.DeviceProfile;
import com.android.launcher3.R;
import com.android.launcher3.Utilities;
import com.android.launcher3.anim.PendingAnimation;
import com.android.launcher3.touch.PagedOrientationHandler;
@@ -92,7 +91,6 @@ public class TaskViewSimulator implements TransformParams.BuilderProxy {
    public final AnimatedFloat recentsViewScale = new AnimatedFloat();
    public final AnimatedFloat fullScreenProgress = new AnimatedFloat();
    private final ScrollState mScrollState = new ScrollState();
    private final int mPageSpacing;

    // Cached calculations
    private boolean mLayoutValid = false;
@@ -105,7 +103,6 @@ public class TaskViewSimulator implements TransformParams.BuilderProxy {
        mOrientationState = new RecentsOrientedState(context, sizeStrategy, i -> { });

        mCurrentFullscreenParams = new FullscreenDrawParams(context);
        mPageSpacing = context.getResources().getDimensionPixelSize(R.dimen.recents_page_spacing);
    }

    /**
@@ -251,7 +248,8 @@ public class TaskViewSimulator implements TransformParams.BuilderProxy {
            int start = mOrientationState.getOrientationHandler()
                    .getPrimaryValue(mTaskRect.left, mTaskRect.top);
            mScrollState.screenCenter = start + mScrollState.scroll + mScrollState.halfPageSize;
            mScrollState.updateInterpolation(start, mPageSpacing);
            mScrollState.pageParentScale = recentsViewScale.value;
            mScrollState.updateInterpolation(start);
            mCurveScale = TaskView.getCurveScaleForInterpolation(mScrollState.linearInterpolation);
        }

+112 −14
Original line number Diff line number Diff line
@@ -22,7 +22,6 @@ import static android.view.View.MeasureSpec.makeMeasureSpec;

import static com.android.launcher3.BaseActivity.STATE_HANDLER_INVISIBILITY_FLAGS;
import static com.android.launcher3.InvariantDeviceProfile.CHANGE_FLAG_ICON_PARAMS;
import static com.android.launcher3.LauncherAnimUtils.SCALE_PROPERTY;
import static com.android.launcher3.LauncherAnimUtils.VIEW_ALPHA;
import static com.android.launcher3.LauncherState.BACKGROUND_APP;
import static com.android.launcher3.Utilities.EDGE_NAV_BAR;
@@ -62,6 +61,7 @@ import android.graphics.Canvas;
import android.graphics.Point;
import android.graphics.PointF;
import android.graphics.Rect;
import android.graphics.RectF;
import android.graphics.Typeface;
import android.graphics.drawable.Drawable;
import android.os.Build;
@@ -209,6 +209,23 @@ public abstract class RecentsView<T extends StatefulActivity> extends PagedView
                }
            };

    /** Same as normal SCALE_PROPERTY, but also updates page offsets that depend on this scale. */
    public static final FloatProperty<RecentsView> RECENTS_SCALE_PROPERTY =
            new FloatProperty<RecentsView>("recentsScale") {
                @Override
                public void setValue(RecentsView view, float scale) {
                    view.setScaleX(scale);
                    view.setScaleY(scale);
                    view.mLastComputedTaskPushOutDistance = null;
                    view.updatePageOffsets();
                }

                @Override
                public Float get(RecentsView view) {
                    return view.getScaleX();
                }
            };

    protected RecentsOrientedState mOrientationState;
    protected final BaseActivityInterface mSizeStrategy;
    protected RecentsAnimationController mRecentsAnimationController;
@@ -216,8 +233,12 @@ public abstract class RecentsView<T extends StatefulActivity> extends PagedView
    protected SurfaceTransactionApplier mSyncTransactionApplier;
    protected int mTaskWidth;
    protected int mTaskHeight;
    protected final Rect mLastComputedTaskSize = new Rect();
    // How much a task that is directly offscreen will be pushed out due to RecentsView scale/pivot.
    protected Float mLastComputedTaskPushOutDistance = null;
    protected boolean mEnableDrawingLiveTile = false;
    protected final Rect mTempRect = new Rect();
    protected final RectF mTempRectF = new RectF();
    private final PointF mTempPointF = new PointF();

    private static final int DISMISS_TASK_DURATION = 300;
@@ -864,6 +885,7 @@ public abstract class RecentsView<T extends StatefulActivity> extends PagedView
    public void getTaskSize(Rect outRect) {
        mSizeStrategy.calculateTaskSize(mActivity, mActivity.getDeviceProfile(), outRect,
                mOrientationHandler);
        mLastComputedTaskSize.set(outRect);
    }

    /** Gets the task size for modal state. */
@@ -905,8 +927,8 @@ public abstract class RecentsView<T extends StatefulActivity> extends PagedView
        final int pageCount = getPageCount();
        for (int i = 0; i < pageCount; i++) {
            View page = getPageAt(i);
            mScrollState.updateInterpolation(mOrientationHandler.getChildStartWithTranslation(page),
                    mPageSpacing);
            mScrollState.updateInterpolation(
                    mOrientationHandler.getChildStartWithTranslation(page));
            ((PageCallbacks) page).onPageScroll(mScrollState);
        }
    }
@@ -1321,10 +1343,14 @@ public abstract class RecentsView<T extends StatefulActivity> extends PagedView
        /**
         * Updates linearInterpolation for the provided child position
         */
        public void updateInterpolation(float childStart, int pageSpacing) {
            float pageCenter = childStart + halfPageSize;
        public void updateInterpolation(float childStart) {
            float scaledHalfPageSize = halfPageSize / pageParentScale;
            float pageCenter = childStart + scaledHalfPageSize;
            float distanceFromScreenCenter = screenCenter - pageCenter;
            float distanceToReachEdge = halfScreenSize + halfPageSize + pageSpacing;
            // How far the page has to move from the center to be offscreen, taking into account
            // the EDGE_SCALE_DOWN_FACTOR that will be applied at that position.
            float distanceToReachEdge = halfScreenSize
                    + scaledHalfPageSize * (1 - TaskView.EDGE_SCALE_DOWN_FACTOR);
            linearInterpolation = Math.min(1,
                    Math.abs(distanceFromScreenCenter) / distanceToReachEdge);
        }
@@ -1761,14 +1787,15 @@ public abstract class RecentsView<T extends StatefulActivity> extends PagedView
        setPivotX(mTempPointF.x);
        setPivotY(mTempPointF.y);
        setTaskModalness(mTaskModalness);
        mLastComputedTaskPushOutDistance = null;
        updatePageOffsets();
        setImportantForAccessibility(isModal() ? IMPORTANT_FOR_ACCESSIBILITY_NO
                : IMPORTANT_FOR_ACCESSIBILITY_AUTO);
    }

    private void updatePageOffsets() {
        float offset = mAdjacentPageOffset * getWidth();
        float modalOffset = ACCEL_0_75.getInterpolation(mTaskModalness) * getWidth();
        float offset = mAdjacentPageOffset;
        float modalOffset = ACCEL_0_75.getInterpolation(mTaskModalness);
        if (mIsRtl) {
            offset = -offset;
            modalOffset = -modalOffset;
@@ -1777,18 +1804,89 @@ public abstract class RecentsView<T extends StatefulActivity> extends PagedView

        TaskView runningTask = mRunningTaskId == -1 || !mRunningTaskTileHidden
                ? null : getTaskView(mRunningTaskId);
        int midPoint = runningTask == null ? -1 : indexOfChild(runningTask);
        int currentPage = getCurrentPage();
        int midpoint = runningTask == null ? -1 : indexOfChild(runningTask);
        int modalMidpoint = getCurrentPage();

        float midpointOffsetSize = 0;
        float leftOffsetSize = midpoint - 1 >= 0
                ? -getOffsetSize(midpoint - 1, midpoint, offset)
                : 0;
        float rightOffsetSize = midpoint + 1 < count
                ? getOffsetSize(midpoint + 1, midpoint, offset)
                : 0;

        float modalMidpointOffsetSize = 0;
        float modalLeftOffsetSize = modalMidpoint - 1 >= 0
                ? -getOffsetSize(modalMidpoint - 1, modalMidpoint, modalOffset)
                : 0;
        float modalRightOffsetSize = modalMidpoint + 1 < count
                ? getOffsetSize(modalMidpoint + 1, modalMidpoint, modalOffset)
                : 0;

        for (int i = 0; i < count; i++) {
            float translation = i == midPoint ? 0 : (i < midPoint ? -offset : offset);
            float modalTranslation =
                    i == currentPage ? 0 : (i < currentPage ? -modalOffset : modalOffset);
            float translation = i == midpoint
                    ? midpointOffsetSize
                    : i < midpoint
                            ? leftOffsetSize
                            : rightOffsetSize;
            float modalTranslation = i == modalMidpoint
                    ? modalMidpointOffsetSize
                    : i < modalMidpoint
                            ? modalLeftOffsetSize
                            : modalRightOffsetSize;
            getChildAt(i).setTranslationX(translation + modalTranslation);
        }
        updateCurveProperties();
    }

    /**
     * Computes the distance to offset the given child such that it is completely offscreen when
     * translating away from the given midpoint.
     * @param offsetProgress From 0 to 1 where 0 means no offset and 1 means offset offscreen.
     */
    private float getOffsetSize(int childIndex, int midpointIndex, float offsetProgress) {
        if (offsetProgress == 0) {
            // Don't bother calculating everything below if we won't offset anyway.
            return 0;
        }
        // First, get the position of the task relative to the midpoint. If there is no midpoint
        // then we just use the normal (centered) task position.
        mTempRectF.set(mLastComputedTaskSize);
        RectF taskPosition = mTempRectF;
        float desiredLeft = getWidth();
        float distanceToOffscreen = desiredLeft - taskPosition.left;
        // Used to calculate the scale of the task view based on its new offset.
        float centerToOffscreenProgress = Math.abs(offsetProgress);
        if (midpointIndex > -1) {
            // When there is a midpoint reference task, adjacent tasks have less distance to travel
            // to reach offscreen. Offset the task position to the task's starting point.
            View child = getChildAt(childIndex);
            View midpointChild = getChildAt(midpointIndex);
            int distanceFromMidpoint = Math.abs(mOrientationHandler.getChildStart(child)
                    - mOrientationHandler.getChildStart(midpointChild)
                    + getDisplacementFromScreenCenter(midpointIndex));
            taskPosition.offset(distanceFromMidpoint, 0);
            centerToOffscreenProgress = Utilities.mapRange(centerToOffscreenProgress,
                    distanceFromMidpoint / distanceToOffscreen, 1);
        }
        // Find the task's scale based on its offscreen progress, then see how far it still needs to
        // move to be completely offscreen.
        Utilities.scaleRectFAboutCenter(taskPosition,
                TaskView.getCurveScaleForInterpolation(centerToOffscreenProgress));
        distanceToOffscreen = desiredLeft - taskPosition.left;
        // Finally, we need to account for RecentsView scale, because it moves tasks based on its
        // pivot. To do this, we move the task position to where it would be offscreen at scale = 1
        // (computed above), then we apply the scale via getMatrix() to determine how much that
        // moves the task from its desired position, and adjust the computed distance accordingly.
        if (mLastComputedTaskPushOutDistance == null) {
            taskPosition.offsetTo(desiredLeft, 0);
            getMatrix().mapRect(taskPosition);
            mLastComputedTaskPushOutDistance = (taskPosition.left - desiredLeft) / getScaleX();
        }
        distanceToOffscreen -= mLastComputedTaskPushOutDistance;
        return distanceToOffscreen * offsetProgress;
    }

    /**
     * TODO: Do not assume motion across X axis for adjacent page
     */
@@ -1887,7 +1985,7 @@ public abstract class RecentsView<T extends StatefulActivity> extends PagedView
        float toScale = getMaxScaleForFullScreen();
        if (launchingCenterTask) {
            RecentsView recentsView = tv.getRecentsView();
            anim.play(ObjectAnimator.ofFloat(recentsView, SCALE_PROPERTY, toScale));
            anim.play(ObjectAnimator.ofFloat(recentsView, RECENTS_SCALE_PROPERTY, toScale));
            anim.play(ObjectAnimator.ofFloat(recentsView, FULLSCREEN_PROGRESS, 1));
        } else {
            // We are launching an adjacent task, so parallax the center and other adjacent task.
Loading