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

Commit 5a5eb846 authored by Hyunyoung Song's avatar Hyunyoung Song Committed by Android (Google) Code Review
Browse files

Merge "Change interpolation logic to all apps transitioning on fling...

Merge "Change interpolation logic to all apps transitioning on fling b/30486958" into ub-launcher3-calgary
parents 40a29161 191e9d1b
Loading
Loading
Loading
Loading
+40 −36
Original line number Original line Diff line number Diff line
@@ -174,7 +174,7 @@ public class LauncherStateTransitionAnimation {
            animType = PULLUP;
            animType = PULLUP;
        }
        }
        // Only animate the search bar if animating from spring loaded mode back to all apps
        // Only animate the search bar if animating from spring loaded mode back to all apps
        mCurrentAnimation = startAnimationToOverlay(fromWorkspaceState,
        startAnimationToOverlay(fromWorkspaceState,
                Workspace.State.NORMAL_HIDDEN, buttonView, toView, animated, animType, cb);
                Workspace.State.NORMAL_HIDDEN, buttonView, toView, animated, animType, cb);
    }
    }


@@ -185,7 +185,7 @@ public class LauncherStateTransitionAnimation {
            final boolean animated) {
            final boolean animated) {
        final WidgetsContainerView toView = mLauncher.getWidgetsView();
        final WidgetsContainerView toView = mLauncher.getWidgetsView();
        final View buttonView = mLauncher.getWidgetsButton();
        final View buttonView = mLauncher.getWidgetsButton();
        mCurrentAnimation = startAnimationToOverlay(fromWorkspaceState,
        startAnimationToOverlay(fromWorkspaceState,
                Workspace.State.OVERVIEW_HIDDEN, buttonView, toView, animated, CIRCULAR_REVEAL,
                Workspace.State.OVERVIEW_HIDDEN, buttonView, toView, animated, CIRCULAR_REVEAL,
                new PrivateTransitionCallbacks(FINAL_REVEAL_ALPHA_FOR_WIDGETS){
                new PrivateTransitionCallbacks(FINAL_REVEAL_ALPHA_FOR_WIDGETS){
                    @Override
                    @Override
@@ -229,7 +229,7 @@ public class LauncherStateTransitionAnimation {
     * Creates and starts a new animation to a particular overlay view.
     * Creates and starts a new animation to a particular overlay view.
     */
     */
    @SuppressLint("NewApi")
    @SuppressLint("NewApi")
    private AnimatorSet startAnimationToOverlay(
    private void startAnimationToOverlay(
            final Workspace.State fromWorkspaceState, final Workspace.State toWorkspaceState,
            final Workspace.State fromWorkspaceState, final Workspace.State toWorkspaceState,
            final View buttonView, final BaseContainerView toView,
            final View buttonView, final BaseContainerView toView,
            final boolean animated, int animType, final PrivateTransitionCallbacks pCb) {
            final boolean animated, int animType, final PrivateTransitionCallbacks pCb) {
@@ -277,8 +277,7 @@ public class LauncherStateTransitionAnimation {
            dispatchOnLauncherTransitionStart(toView, animated, false);
            dispatchOnLauncherTransitionStart(toView, animated, false);
            dispatchOnLauncherTransitionEnd(toView, animated, false);
            dispatchOnLauncherTransitionEnd(toView, animated, false);
            pCb.onTransitionComplete();
            pCb.onTransitionComplete();

            return;
            return null;
        }
        }
        if (animType == CIRCULAR_REVEAL) {
        if (animType == CIRCULAR_REVEAL) {
            // Setup the reveal view animation
            // Setup the reveal view animation
@@ -414,8 +413,7 @@ public class LauncherStateTransitionAnimation {
            toView.bringToFront();
            toView.bringToFront();
            toView.setVisibility(View.VISIBLE);
            toView.setVisibility(View.VISIBLE);
            toView.post(startAnimRunnable);
            toView.post(startAnimRunnable);

            mCurrentAnimation = animation;
            return animation;
        } else if (animType == PULLUP) {
        } else if (animType == PULLUP) {
            // We are animating the content view alpha, so ensure we have a layer for it
            // We are animating the content view alpha, so ensure we have a layer for it
            layerViews.put(contentView, BUILD_AND_SET_LAYER);
            layerViews.put(contentView, BUILD_AND_SET_LAYER);
@@ -437,7 +435,7 @@ public class LauncherStateTransitionAnimation {
                    pCb.onTransitionComplete();
                    pCb.onTransitionComplete();
                }
                }
            });
            });
            mAllAppsController.animateToAllApps(animation, revealDurationSlide);
            boolean shouldPost = mAllAppsController.animateToAllApps(animation, revealDurationSlide);


            dispatchOnLauncherTransitionPrepare(fromView, animated, false);
            dispatchOnLauncherTransitionPrepare(fromView, animated, false);
            dispatchOnLauncherTransitionPrepare(toView, animated, false);
            dispatchOnLauncherTransitionPrepare(toView, animated, false);
@@ -467,10 +465,13 @@ public class LauncherStateTransitionAnimation {
                    stateAnimation.start();
                    stateAnimation.start();
                }
                }
            };
            };
            mCurrentAnimation = animation;
            if (shouldPost) {
                toView.post(startAnimRunnable);
                toView.post(startAnimRunnable);
            return animation;
            } else {
                startAnimRunnable.run();
            }
        }
        }
        return null;
    }
    }


    /**
    /**
@@ -552,7 +553,7 @@ public class LauncherStateTransitionAnimation {
            }
            }
        };
        };
        // Only animate the search bar if animating to spring loaded mode from all apps
        // Only animate the search bar if animating to spring loaded mode from all apps
        mCurrentAnimation = startAnimationToWorkspaceFromOverlay(fromWorkspaceState, toWorkspaceState,
        startAnimationToWorkspaceFromOverlay(fromWorkspaceState, toWorkspaceState,
                mLauncher.getStartViewForAllAppsRevealAnimation(), appsView,
                mLauncher.getStartViewForAllAppsRevealAnimation(), appsView,
                animated, type, onCompleteRunnable, cb);
                animated, type, onCompleteRunnable, cb);
    }
    }
@@ -581,7 +582,7 @@ public class LauncherStateTransitionAnimation {
                mLauncher.getUserEventDispatcher().resetElapsedContainerMillis();
                mLauncher.getUserEventDispatcher().resetElapsedContainerMillis();
            }
            }
        };
        };
        mCurrentAnimation = startAnimationToWorkspaceFromOverlay(
        startAnimationToWorkspaceFromOverlay(
                fromWorkspaceState, toWorkspaceState,
                fromWorkspaceState, toWorkspaceState,
                mLauncher.getWidgetsButton(), widgetsView,
                mLauncher.getWidgetsButton(), widgetsView,
                animated, CIRCULAR_REVEAL, onCompleteRunnable, cb);
                animated, CIRCULAR_REVEAL, onCompleteRunnable, cb);
@@ -673,7 +674,7 @@ public class LauncherStateTransitionAnimation {
    /**
    /**
     * Creates and starts a new animation to the workspace.
     * Creates and starts a new animation to the workspace.
     */
     */
    private AnimatorSet startAnimationToWorkspaceFromOverlay(
    private void startAnimationToWorkspaceFromOverlay(
            final Workspace.State fromWorkspaceState, final Workspace.State toWorkspaceState,
            final Workspace.State fromWorkspaceState, final Workspace.State toWorkspaceState,
            final View buttonView, final BaseContainerView fromView,
            final View buttonView, final BaseContainerView fromView,
            final boolean animated, int animType, final Runnable onCompleteRunnable,
            final boolean animated, int animType, final Runnable onCompleteRunnable,
@@ -720,7 +721,7 @@ public class LauncherStateTransitionAnimation {
            if (onCompleteRunnable != null) {
            if (onCompleteRunnable != null) {
                onCompleteRunnable.run();
                onCompleteRunnable.run();
            }
            }
            return null;
            return;
        }
        }
        if (animType == CIRCULAR_REVEAL) {
        if (animType == CIRCULAR_REVEAL) {
            // hideAppsCustomizeHelper is called in some cases when it is already hidden
            // hideAppsCustomizeHelper is called in some cases when it is already hidden
@@ -885,9 +886,8 @@ public class LauncherStateTransitionAnimation {
                    stateAnimation.start();
                    stateAnimation.start();
                }
                }
            };
            };
            mCurrentAnimation = animation;
            fromView.post(startAnimRunnable);
            fromView.post(startAnimRunnable);

            return animation;
        } else if (animType == PULLUP) {
        } else if (animType == PULLUP) {
            // We are animating the content view alpha, so ensure we have a layer for it
            // We are animating the content view alpha, so ensure we have a layer for it
            layerViews.put(contentView, BUILD_AND_SET_LAYER);
            layerViews.put(contentView, BUILD_AND_SET_LAYER);
@@ -921,7 +921,7 @@ public class LauncherStateTransitionAnimation {
                }
                }


            });
            });
            mAllAppsController.animateToWorkspace(animation, revealDurationSlide);
            boolean shouldPost = mAllAppsController.animateToWorkspace(animation, revealDurationSlide);


            // Dispatch the prepare transition signal
            // Dispatch the prepare transition signal
            dispatchOnLauncherTransitionPrepare(fromView, animated, multiplePagesVisible);
            dispatchOnLauncherTransitionPrepare(fromView, animated, multiplePagesVisible);
@@ -953,10 +953,14 @@ public class LauncherStateTransitionAnimation {
                    stateAnimation.start();
                    stateAnimation.start();
                }
                }
            };
            };
            mCurrentAnimation = animation;
            if (shouldPost) {
                fromView.post(startAnimRunnable);
                fromView.post(startAnimRunnable);
            return animation;
            } else {
                startAnimRunnable.run();
            }
            }
        return null;
        }
        return;
    }
    }


    /**
    /**
+47 −13
Original line number Original line Diff line number Diff line
@@ -17,7 +17,6 @@ import com.android.launcher3.DeviceProfile;
import com.android.launcher3.Hotseat;
import com.android.launcher3.Hotseat;
import com.android.launcher3.Launcher;
import com.android.launcher3.Launcher;
import com.android.launcher3.LauncherAnimUtils;
import com.android.launcher3.LauncherAnimUtils;
import com.android.launcher3.PagedView;
import com.android.launcher3.R;
import com.android.launcher3.R;
import com.android.launcher3.Utilities;
import com.android.launcher3.Utilities;
import com.android.launcher3.Workspace;
import com.android.launcher3.Workspace;
@@ -42,11 +41,12 @@ public class AllAppsTransitionController implements TouchController, VerticalPul


    private final Interpolator mAccelInterpolator = new AccelerateInterpolator(2f);
    private final Interpolator mAccelInterpolator = new AccelerateInterpolator(2f);
    private final Interpolator mFastOutSlowInInterpolator = new FastOutSlowInInterpolator();
    private final Interpolator mFastOutSlowInInterpolator = new FastOutSlowInInterpolator();
    private final Interpolator mScrollInterpolator = new PagedView.ScrollInterpolator();
    private final ScrollInterpolator mScrollInterpolator = new ScrollInterpolator();


    private static final float ANIMATION_DURATION = 1200;
    private static final float ANIMATION_DURATION = 1200;

    private static final float PARALLAX_COEFFICIENT = .125f;
    private static final float PARALLAX_COEFFICIENT = .125f;
    private static final float FAST_FLING_PX_MS = 10;
    private static final int SINGLE_FRAME_MS = 16;


    private AllAppsContainerView mAppsView;
    private AllAppsContainerView mAppsView;
    private int mAllAppsBackgroundColor;
    private int mAllAppsBackgroundColor;
@@ -72,6 +72,7 @@ public class AllAppsTransitionController implements TouchController, VerticalPul
    private float mShiftRange;      // changes depending on the orientation
    private float mShiftRange;      // changes depending on the orientation
    private float mProgress;        // [0, 1], mShiftRange * mProgress = shiftCurrent
    private float mProgress;        // [0, 1], mShiftRange * mProgress = shiftCurrent


    // Velocity of the container. Unit is in px/ms.
    private float mContainerVelocity;
    private float mContainerVelocity;


    private static final float DEFAULT_SHIFT_RANGE = 10;
    private static final float DEFAULT_SHIFT_RANGE = 10;
@@ -343,7 +344,7 @@ public class AllAppsTransitionController implements TouchController, VerticalPul


    private void calculateDuration(float velocity, float disp) {
    private void calculateDuration(float velocity, float disp) {
        // TODO: make these values constants after tuning.
        // TODO: make these values constants after tuning.
        float velocityDivisor = Math.max(1.5f, Math.abs(0.5f * velocity));
        float velocityDivisor = Math.max(2f, Math.abs(0.5f * velocity));
        float travelDistance = Math.max(0.2f, disp / mShiftRange);
        float travelDistance = Math.max(0.2f, disp / mShiftRange);
        mAnimationDuration = (long) Math.max(100, ANIMATION_DURATION / velocityDivisor * travelDistance);
        mAnimationDuration = (long) Math.max(100, ANIMATION_DURATION / velocityDivisor * travelDistance);
        if (DBG) {
        if (DBG) {
@@ -351,22 +352,29 @@ public class AllAppsTransitionController implements TouchController, VerticalPul
        }
        }
    }
    }


    public void animateToAllApps(AnimatorSet animationOut, long duration) {
    public boolean animateToAllApps(AnimatorSet animationOut, long duration) {
        Interpolator interpolator;
        boolean shouldPost = true;
        if (animationOut == null) {
        if (animationOut == null) {
            return;
            return shouldPost;
        }
        }
        Interpolator interpolator;
        if (mDetector.isIdleState()) {
        if (mDetector.isIdleState()) {
            preparePull(true);
            preparePull(true);
            mAnimationDuration = duration;
            mAnimationDuration = duration;
            mShiftStart = mAppsView.getTranslationY();
            mShiftStart = mAppsView.getTranslationY();
            interpolator = mFastOutSlowInInterpolator;
            interpolator = mFastOutSlowInInterpolator;
        } else {
        } else {
            mScrollInterpolator.setVelocityAtZero(Math.abs(mContainerVelocity));
            interpolator = mScrollInterpolator;
            interpolator = mScrollInterpolator;
            float nextFrameProgress = mProgress + mContainerVelocity * SINGLE_FRAME_MS / mShiftRange;
            if (nextFrameProgress >= 0f) {
                mProgress = nextFrameProgress;
            }
            }
        final float fromAllAppsTop = mAppsView.getTranslationY();
            shouldPost = false;
        }

        ObjectAnimator driftAndAlpha = ObjectAnimator.ofFloat(this, "progress",
        ObjectAnimator driftAndAlpha = ObjectAnimator.ofFloat(this, "progress",
                fromAllAppsTop / mShiftRange, 0f);
                mProgress, 0f);
        driftAndAlpha.setDuration(mAnimationDuration);
        driftAndAlpha.setDuration(mAnimationDuration);
        driftAndAlpha.setInterpolator(interpolator);
        driftAndAlpha.setInterpolator(interpolator);
        animationOut.play(driftAndAlpha);
        animationOut.play(driftAndAlpha);
@@ -391,6 +399,7 @@ public class AllAppsTransitionController implements TouchController, VerticalPul
            }
            }
        });
        });
        mCurrentAnimation = animationOut;
        mCurrentAnimation = animationOut;
        return shouldPost;
    }
    }


    public void showDiscoveryBounce() {
    public void showDiscoveryBounce() {
@@ -426,9 +435,10 @@ public class AllAppsTransitionController implements TouchController, VerticalPul
        });
        });
    }
    }


    public void animateToWorkspace(AnimatorSet animationOut, long duration) {
    public boolean animateToWorkspace(AnimatorSet animationOut, long duration) {
        boolean shouldPost = true;
        if (animationOut == null) {
        if (animationOut == null) {
            return;
            return shouldPost;
        }
        }
        Interpolator interpolator;
        Interpolator interpolator;
        if (mDetector.isIdleState()) {
        if (mDetector.isIdleState()) {
@@ -437,12 +447,17 @@ public class AllAppsTransitionController implements TouchController, VerticalPul
            mShiftStart = mAppsView.getTranslationY();
            mShiftStart = mAppsView.getTranslationY();
            interpolator = mFastOutSlowInInterpolator;
            interpolator = mFastOutSlowInInterpolator;
        } else {
        } else {
            mScrollInterpolator.setVelocityAtZero(Math.abs(mContainerVelocity));
            interpolator = mScrollInterpolator;
            interpolator = mScrollInterpolator;
            float nextFrameProgress = mProgress + mContainerVelocity * SINGLE_FRAME_MS / mShiftRange;
            if (nextFrameProgress <= 1f) {
                mProgress = nextFrameProgress;
            }
            shouldPost = false;
        }
        }
        final float fromAllAppsTop = mAppsView.getTranslationY();


        ObjectAnimator driftAndAlpha = ObjectAnimator.ofFloat(this, "progress",
        ObjectAnimator driftAndAlpha = ObjectAnimator.ofFloat(this, "progress",
                fromAllAppsTop / mShiftRange, 1f);
                mProgress, 1f);
        driftAndAlpha.setDuration(mAnimationDuration);
        driftAndAlpha.setDuration(mAnimationDuration);
        driftAndAlpha.setInterpolator(interpolator);
        driftAndAlpha.setInterpolator(interpolator);
        animationOut.play(driftAndAlpha);
        animationOut.play(driftAndAlpha);
@@ -467,6 +482,7 @@ public class AllAppsTransitionController implements TouchController, VerticalPul
            }
            }
        });
        });
        mCurrentAnimation = animationOut;
        mCurrentAnimation = animationOut;
        return shouldPost;
    }
    }


    public void finishPullUp() {
    public void finishPullUp() {
@@ -522,4 +538,22 @@ public class AllAppsTransitionController implements TouchController, VerticalPul
        }
        }
        setProgress(mProgress);
        setProgress(mProgress);
    }
    }

    static class ScrollInterpolator implements Interpolator {

        boolean mSteeper;

        public void setVelocityAtZero(float velocity) {
            mSteeper = velocity > FAST_FLING_PX_MS;
        }

        public float getInterpolation(float t) {
            t -= 1.0f;
            float output = t * t * t;
            if (mSteeper) {
                output *= t * t; // Make interpolation initial slope steeper
            }
            return output + 1;
        }
    }
}
}