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

Commit 597bcbb1 authored by Matthew Ng's avatar Matthew Ng
Browse files

Avoid saving position before minimizing when in transition

Changed to save snap targets instead of positions when divider is
attached to window and after any stopdragged animations occur.

Test: manual - split 2 apps, rotate screen, hold home launch assistant,
click keyboard, hold device back to portrait and press home
Fixes: 64977831
Change-Id: If47a04742b812eed3be0d08a243d4226515308b5
parent bff95c0d
Loading
Loading
Loading
Loading
+32 −31
Original line number Diff line number Diff line
@@ -66,9 +66,7 @@ import com.android.systemui.recents.Recents;
import com.android.systemui.recents.events.EventBus;
import com.android.systemui.recents.events.activity.DockedTopTaskEvent;
import com.android.systemui.recents.events.activity.RecentsActivityStartingEvent;
import com.android.systemui.recents.events.activity.ToggleRecentsEvent;
import com.android.systemui.recents.events.activity.UndockingTaskEvent;
import com.android.systemui.recents.events.ui.RecentsDrawnEvent;
import com.android.systemui.recents.events.ui.RecentsGrowingEvent;
import com.android.systemui.recents.misc.SystemServicesProxy;
import com.android.systemui.stackdivider.events.StartedDragingEvent;
@@ -124,7 +122,7 @@ public class DividerView extends FrameLayout implements OnTouchListener,
    private int mTouchSlop;
    private boolean mBackgroundLifted;
    private boolean mIsInMinimizeInteraction;
    private int mDividerPositionBeforeMinimized;
    private SnapTarget mSnapTargetBeforeMinimized;

    private int mDividerInsets;
    private int mDisplayWidth;
@@ -318,6 +316,12 @@ public class DividerView extends FrameLayout implements OnTouchListener,
    protected void onAttachedToWindow() {
        super.onAttachedToWindow();
        EventBus.getDefault().register(this);

        // Save the current target if not minimized once attached to window
        if (mHomeStackResizable && mDockSide != WindowManager.DOCKED_INVALID
                && !mIsInMinimizeInteraction) {
            saveSnapTargetBeforeMinimized(mSnapTargetBeforeMinimized);
        }
    }

    @Override
@@ -381,8 +385,10 @@ public class DividerView extends FrameLayout implements OnTouchListener,
                (isHorizontalDivision() ? mDisplayHeight : mDisplayWidth));
        mSnapAlgorithm = null;
        initializeSnapAlgorithm();
        mDividerPositionBeforeMinimized = mSnapAlgorithm.calculateNonDismissingSnapTarget(position)
                .position;

        // Set the snap target before minimized but do not save until divider is attached and not
        // minimized because it does not know its minimized state yet.
        mSnapTargetBeforeMinimized = mSnapAlgorithm.calculateNonDismissingSnapTarget(position);
    }

    public WindowManagerProxy getWindowManagerProxy() {
@@ -601,6 +607,11 @@ public class DividerView extends FrameLayout implements OnTouchListener,
            mEntranceAnimationRunning = false;
            mExitAnimationRunning = false;
            EventBus.getDefault().send(new StoppedDragingEvent());

            // Record last snap target the divider moved to
            if (mHomeStackResizable && !mIsInMinimizeInteraction) {
                saveSnapTargetBeforeMinimized(snapTarget);
            }
        };
        Runnable notCancelledEndAction = () -> {
            // Reset minimized divider position after unminimized state animation finishes
@@ -629,15 +640,15 @@ public class DividerView extends FrameLayout implements OnTouchListener,
                    delay = mSfChoreographer.getSurfaceFlingerOffsetMs();
                }
                if (delay == 0) {
                    endAction.run();
                    if (!mCancelled) {
                        notCancelledEndAction.run();
                    }
                    endAction.run();
                } else {
                    mHandler.postDelayed(endAction, delay);
                    if (!mCancelled) {
                        mHandler.postDelayed(notCancelledEndAction, delay);
                    }
                    mHandler.postDelayed(endAction, delay);
                }
            }
        });
@@ -744,12 +755,9 @@ public class DividerView extends FrameLayout implements OnTouchListener,
            if (mIsInMinimizeInteraction != minimized) {
                if (minimized) {
                    mIsInMinimizeInteraction = true;
                    int position = mMinimizedSnapAlgorithm.getMiddleTarget().position;
                    resizeStack(position, position, mMinimizedSnapAlgorithm.getMiddleTarget());
                    resizeStack(mMinimizedSnapAlgorithm.getMiddleTarget());
                } else {
                    resizeStack(mDividerPositionBeforeMinimized, mDividerPositionBeforeMinimized,
                            mSnapAlgorithm.calculateNonDismissingSnapTarget(
                                    mDividerPositionBeforeMinimized));
                    resizeStack(mSnapTargetBeforeMinimized);
                    mIsInMinimizeInteraction = false;
                }
            }
@@ -786,20 +794,15 @@ public class DividerView extends FrameLayout implements OnTouchListener,
            mDockedStackMinimized = minimized;
        } else if (mDockedStackMinimized != minimized) {
            mIsInMinimizeInteraction = true;
            if (minimized && (mCurrentAnimator == null || !mCurrentAnimator.isRunning())
                    && (mDividerPositionBeforeMinimized <= 0 || !mAdjustedForIme)) {
                savePositionBeforeMinimized();
            }
            mMinimizedSnapAlgorithm = null;
            mDockedStackMinimized = minimized;
            initializeSnapAlgorithm();
            stopDragging(minimized
                            ? mDividerPositionBeforeMinimized
                            ? mSnapTargetBeforeMinimized.position
                            : getCurrentPosition(),
                    minimized
                            ? mMinimizedSnapAlgorithm.getMiddleTarget()
                            : mSnapAlgorithm.calculateNonDismissingSnapTarget(
                                    mDividerPositionBeforeMinimized),
                            : mSnapTargetBeforeMinimized,
                    animDuration, Interpolators.FAST_OUT_SLOW_IN, 0);
            setAdjustedForIme(false, animDuration);
        }
@@ -844,17 +847,11 @@ public class DividerView extends FrameLayout implements OnTouchListener,
                .setDuration(animDuration)
                .start();
        mAdjustedForIme = adjustedForIme;

        // Only get new position if home stack is resizable, ime is open and not minimized
        // (including the animation)
        if (mHomeStackResizable && adjustedForIme && !mIsInMinimizeInteraction) {
            savePositionBeforeMinimized();
        }
    }

    private void savePositionBeforeMinimized() {
        mDividerPositionBeforeMinimized = getCurrentPosition();
        mState.mRatioPositionBeforeMinimized = (float) mDividerPositionBeforeMinimized /
    private void saveSnapTargetBeforeMinimized(SnapTarget target) {
        mSnapTargetBeforeMinimized = target;
        mState.mRatioPositionBeforeMinimized = (float) target.position /
                (isHorizontalDivision() ? mDisplayHeight : mDisplayWidth);
    }

@@ -872,7 +869,6 @@ public class DividerView extends FrameLayout implements OnTouchListener,
        updateDisplayInfo();
    }


    public void notifyDockSideChanged(int newDockSide) {
        mDockSide = newDockSide;
        mMinimizedShadow.setDockSide(mDockSide);
@@ -934,6 +930,10 @@ public class DividerView extends FrameLayout implements OnTouchListener,
        mSfChoreographer.scheduleAtSfVsync(mHandler, message);
    }

    private void resizeStack(SnapTarget taskSnapTarget) {
        resizeStack(taskSnapTarget.position, taskSnapTarget.position, taskSnapTarget);
    }

    public void resizeStack(int position, int taskPosition, SnapTarget taskSnapTarget) {
        if (mRemoved) {
            // This divider view has been removed so shouldn't have any additional influence.
@@ -952,8 +952,9 @@ public class DividerView extends FrameLayout implements OnTouchListener,

        mLastResizeRect.set(mDockedRect);
        if (mHomeStackResizable && mIsInMinimizeInteraction) {
            calculateBoundsForPosition(mDividerPositionBeforeMinimized, mDockSide, mDockedTaskRect);
            calculateBoundsForPosition(mDividerPositionBeforeMinimized,
            calculateBoundsForPosition(mSnapTargetBeforeMinimized.position, mDockSide,
                    mDockedTaskRect);
            calculateBoundsForPosition(mSnapTargetBeforeMinimized.position,
                    DockedDividerUtils.invertDockSide(mDockSide), mOtherTaskRect);
            mWindowManagerProxy.resizeDockedStack(mDockedRect, mDockedTaskRect, mDockedTaskRect,
                    mOtherTaskRect, null);