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

Commit 8499e1af authored by Android Build Merger (Role)'s avatar Android Build Merger (Role)
Browse files

[automerger] Fixing atomic animation not getting completed properly am: 2b03b713

Change-Id: I781f244fd4bbccd3d582f8857d6e1d24c215bf93
parents a9d82c45 2b03b713
Loading
Loading
Loading
Loading
+48 −17
Original line number Original line Diff line number Diff line
@@ -29,6 +29,7 @@ import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
import android.animation.AnimatorListenerAdapter;
import android.animation.AnimatorSet;
import android.animation.AnimatorSet;
import android.animation.ValueAnimator;
import android.animation.ValueAnimator;
import android.os.SystemClock;
import android.view.HapticFeedbackConstants;
import android.view.HapticFeedbackConstants;
import android.view.MotionEvent;
import android.view.MotionEvent;


@@ -88,6 +89,7 @@ public abstract class AbstractStateChangeTouchController
    private AnimatorSet mAtomicAnim;
    private AnimatorSet mAtomicAnim;
    // True if we want to resume playing atomic components when mAtomicAnim completes.
    // True if we want to resume playing atomic components when mAtomicAnim completes.
    private boolean mScheduleResumeAtomicComponent;
    private boolean mScheduleResumeAtomicComponent;
    private AutoPlayAtomicAnimationInfo mAtomicAnimAutoPlayInfo;


    private boolean mPassedOverviewAtomicThreshold;
    private boolean mPassedOverviewAtomicThreshold;
    // mAtomicAnim plays the atomic components of the state animations when we pass the threshold.
    // mAtomicAnim plays the atomic components of the state animations when we pass the threshold.
@@ -235,12 +237,17 @@ public abstract class AbstractStateChangeTouchController
        if (mCurrentAnimation == null) {
        if (mCurrentAnimation == null) {
            mFromState = mStartState;
            mFromState = mStartState;
            mToState = null;
            mToState = null;
            mAtomicComponentsController = null;
            cancelAnimationControllers();
            reinitCurrentAnimation(false, mDetector.wasInitialTouchPositive());
            reinitCurrentAnimation(false, mDetector.wasInitialTouchPositive());
            mDisplacementShift = 0;
            mDisplacementShift = 0;
        } else {
        } else {
            mCurrentAnimation.pause();
            mCurrentAnimation.pause();
            mStartProgress = mCurrentAnimation.getProgressFraction();
            mStartProgress = mCurrentAnimation.getProgressFraction();

            mAtomicAnimAutoPlayInfo = null;
            if (mAtomicComponentsController != null) {
                mAtomicComponentsController.pause();
            }
        }
        }
        mCanBlockFling = mFromState == NORMAL;
        mCanBlockFling = mFromState == NORMAL;
        mFlingBlockCheck.unblockFling();
        mFlingBlockCheck.unblockFling();
@@ -315,6 +322,7 @@ public abstract class AbstractStateChangeTouchController
                        return;
                        return;
                    }
                    }
                    cancelAtomicComponentsController();
                    cancelAtomicComponentsController();

                    if (mCurrentAnimation != null) {
                    if (mCurrentAnimation != null) {
                        mAtomicComponentsStartProgress = mCurrentAnimation.getProgressFraction();
                        mAtomicComponentsStartProgress = mCurrentAnimation.getProgressFraction();
                        long duration = (long) (getShiftRange() * 2);
                        long duration = (long) (getShiftRange() * 2);
@@ -322,6 +330,7 @@ public abstract class AbstractStateChangeTouchController
                                createAtomicAnimForState(mFromState, mToState, duration), duration);
                                createAtomicAnimForState(mFromState, mToState, duration), duration);
                        mAtomicComponentsController.dispatchOnStart();
                        mAtomicComponentsController.dispatchOnStart();
                        mAtomicComponentsTargetState = mToState;
                        mAtomicComponentsTargetState = mToState;
                        maybeAutoPlayAtomicComponentsAnim();
                    }
                    }
                }
                }
            });
            });
@@ -416,16 +425,8 @@ public abstract class AbstractStateChangeTouchController
            mLauncher.getAppsView().addSpringFromFlingUpdateListener(anim, velocity);
            mLauncher.getAppsView().addSpringFromFlingUpdateListener(anim, velocity);
        }
        }
        anim.start();
        anim.start();
        if (mAtomicAnim == null) {
        mAtomicAnimAutoPlayInfo = new AutoPlayAtomicAnimationInfo(endProgress, anim.getDuration());
            startAtomicComponentsAnim(endProgress, anim.getDuration());
        maybeAutoPlayAtomicComponentsAnim();
        } else {
            mAtomicAnim.addListener(new AnimationSuccessListener() {
                @Override
                public void onAnimationSuccess(Animator animator) {
                    startAtomicComponentsAnim(endProgress, anim.getDuration());
                }
            });
        }
    }
    }


    /**
    /**
@@ -435,18 +436,32 @@ public abstract class AbstractStateChangeTouchController
     * the non-atomic components, which only happens if we reinit before the atomic animation
     * the non-atomic components, which only happens if we reinit before the atomic animation
     * finishes.
     * finishes.
     */
     */
    private void startAtomicComponentsAnim(float toProgress, long duration) {
    private void maybeAutoPlayAtomicComponentsAnim() {
        if (mAtomicComponentsController != null) {
        if (mAtomicComponentsController == null || mAtomicAnimAutoPlayInfo == null) {
            ValueAnimator atomicAnim = mAtomicComponentsController.getAnimationPlayer();
            return;
            atomicAnim.setFloatValues(mAtomicComponentsController.getProgressFraction(), toProgress);
        }
            atomicAnim.setDuration(duration);

        final AnimatorPlaybackController controller = mAtomicComponentsController;
        ValueAnimator atomicAnim = controller.getAnimationPlayer();
        atomicAnim.setFloatValues(controller.getProgressFraction(),
                mAtomicAnimAutoPlayInfo.toProgress);
        long duration = mAtomicAnimAutoPlayInfo.endTime - SystemClock.elapsedRealtime();
        mAtomicAnimAutoPlayInfo = null;
        if (duration <= 0) {
            atomicAnim.start();
            atomicAnim.start();
            atomicAnim.end();
            mAtomicComponentsController = null;
        } else {
            atomicAnim.setDuration(duration);
            atomicAnim.addListener(new AnimatorListenerAdapter() {
            atomicAnim.addListener(new AnimatorListenerAdapter() {
                @Override
                @Override
                public void onAnimationEnd(Animator animation) {
                public void onAnimationEnd(Animator animation) {
                    if (mAtomicComponentsController == controller) {
                        mAtomicComponentsController = null;
                        mAtomicComponentsController = null;
                    }
                    }
                }
            });
            });
            atomicAnim.start();
        }
        }
    }
    }


@@ -476,6 +491,10 @@ public abstract class AbstractStateChangeTouchController
    }
    }


    protected void onSwipeInteractionCompleted(LauncherState targetState, int logAction) {
    protected void onSwipeInteractionCompleted(LauncherState targetState, int logAction) {
        if (mAtomicComponentsController != null) {
            mAtomicComponentsController.getAnimationPlayer().end();
            mAtomicComponentsController = null;
        }
        cancelAnimationControllers();
        cancelAnimationControllers();
        boolean shouldGoToTargetState = true;
        boolean shouldGoToTargetState = true;
        if (mPendingAnimation != null) {
        if (mPendingAnimation != null) {
@@ -523,5 +542,17 @@ public abstract class AbstractStateChangeTouchController
            mAtomicComponentsController.getAnimationPlayer().cancel();
            mAtomicComponentsController.getAnimationPlayer().cancel();
            mAtomicComponentsController = null;
            mAtomicComponentsController = null;
        }
        }
        mAtomicAnimAutoPlayInfo = null;
    }

    private static class AutoPlayAtomicAnimationInfo {

        public final float toProgress;
        public final long endTime;

        AutoPlayAtomicAnimationInfo(float toProgress, long duration) {
            this.toProgress = toProgress;
            this.endTime = duration + SystemClock.elapsedRealtime();
        }
    }
    }
}
}