diff options
5 files changed, 63 insertions, 6 deletions
diff --git a/src/com/android/launcher3/allapps/AllAppsGridAdapter.java b/src/com/android/launcher3/allapps/AllAppsGridAdapter.java index ba4fbe061..1f60fcc73 100644 --- a/src/com/android/launcher3/allapps/AllAppsGridAdapter.java +++ b/src/com/android/launcher3/allapps/AllAppsGridAdapter.java @@ -448,9 +448,20 @@ public class AllAppsGridAdapter extends RecyclerView.Adapter<AllAppsGridAdapter. row = Math.abs(numTotalRows - row); } - // We manipulate the stiffness, min, and max values based on the items distance to the - // first row and the items distance to the center column to create the ^-shaped motion - // effect. + calculateSpringValues(spring, row, col); + } + + @Override + public void setDefaultValues(SpringAnimation spring) { + calculateSpringValues(spring, 0, mAppsPerRow / 2); + } + + /** + * We manipulate the stiffness, min, and max values based on the items distance to the + * first row and the items distance to the center column to create the ^-shaped motion + * effect. + */ + private void calculateSpringValues(SpringAnimation spring, int row, int col) { float rowFactor = (1 + row) * 0.5f; float colFactor = getColumnFactor(col, mAppsPerRow); diff --git a/src/com/android/launcher3/allapps/AllAppsTransitionController.java b/src/com/android/launcher3/allapps/AllAppsTransitionController.java index edfe0c15e..a1f2dd7e3 100644 --- a/src/com/android/launcher3/allapps/AllAppsTransitionController.java +++ b/src/com/android/launcher3/allapps/AllAppsTransitionController.java @@ -7,6 +7,7 @@ import android.animation.AnimatorSet; import android.animation.ArgbEvaluator; import android.animation.ObjectAnimator; import android.graphics.Color; +import android.support.animation.SpringAnimation; import android.support.v4.graphics.ColorUtils; import android.support.v4.view.animation.FastOutSlowInInterpolator; import android.view.MotionEvent; @@ -101,6 +102,7 @@ public class AllAppsTransitionController implements TouchController, SwipeDetect private AnimatorSet mDiscoBounceAnimation; private GradientView mGradientView; + private SpringAnimation mSearchSpring; private SpringAnimationHandler mSpringAnimationHandler; public AllAppsTransitionController(Launcher l) { @@ -226,6 +228,7 @@ public class AllAppsTransitionController implements TouchController, SwipeDetect } mLauncher.showAppsView(true /* animated */, false /* updatePredictedApps */); if (hasSpringAnimationHandler()) { + mSpringAnimationHandler.add(mSearchSpring, true /* setDefaultValues */); // The icons are moving upwards, so we go to 0 from 1. (y-axis 1 is below 0.) mSpringAnimationHandler.animateToFinalPosition(0 /* pos */, 1 /* startValue */); } @@ -499,6 +502,7 @@ public class AllAppsTransitionController implements TouchController, SwipeDetect public void finishPullUp() { mHotseat.setVisibility(View.INVISIBLE); if (hasSpringAnimationHandler()) { + mSpringAnimationHandler.remove(mSearchSpring); mSpringAnimationHandler.reset(); } setProgress(0f); @@ -544,6 +548,7 @@ public class AllAppsTransitionController implements TouchController, SwipeDetect mWorkspace.getPageIndicator().getCaretDrawable(), mLauncher); mAppsView.getSearchUiManager().addOnScrollRangeChangeListener(this); mSpringAnimationHandler = mAppsView.getSpringAnimationHandler(); + mSearchSpring = mAppsView.getSearchUiManager().getSpringForFling(); } private boolean hasSpringAnimationHandler() { diff --git a/src/com/android/launcher3/allapps/SearchUiManager.java b/src/com/android/launcher3/allapps/SearchUiManager.java index c0d78508f..34230e046 100644 --- a/src/com/android/launcher3/allapps/SearchUiManager.java +++ b/src/com/android/launcher3/allapps/SearchUiManager.java @@ -15,6 +15,8 @@ */ package com.android.launcher3.allapps; +import android.support.animation.SpringAnimation; +import android.support.annotation.NonNull; import android.view.KeyEvent; /** @@ -28,6 +30,11 @@ public interface SearchUiManager { void initialize(AlphabeticalAppsList appsList, AllAppsRecyclerView recyclerView); /** + * A {@link SpringAnimation} that will be used when the user flings. + */ + @NonNull SpringAnimation getSpringForFling(); + + /** * Notifies the search manager that the apps-list has changed and the search UI should be * updated accordingly. */ diff --git a/src/com/android/launcher3/allapps/search/AppsSearchContainerLayout.java b/src/com/android/launcher3/allapps/search/AppsSearchContainerLayout.java index d50455171..ddf6e5849 100644 --- a/src/com/android/launcher3/allapps/search/AppsSearchContainerLayout.java +++ b/src/com/android/launcher3/allapps/search/AppsSearchContainerLayout.java @@ -17,6 +17,9 @@ package com.android.launcher3.allapps.search; import android.content.Context; import android.graphics.Rect; +import android.support.animation.FloatValueHolder; +import android.support.animation.SpringAnimation; +import android.support.animation.SpringForce; import android.support.annotation.NonNull; import android.support.annotation.Nullable; import android.text.Selection; @@ -62,6 +65,8 @@ public class AppsSearchContainerLayout extends FrameLayout private View mDivider; private HeaderElevationController mElevationController; + private SpringAnimation mSpring; + public AppsSearchContainerLayout(Context context) { this(context, null); } @@ -81,6 +86,9 @@ public class AppsSearchContainerLayout extends FrameLayout mSearchQueryBuilder = new SpannableStringBuilder(); Selection.setSelection(mSearchQueryBuilder, 0); + + // Note: This spring does nothing. + mSpring = new SpringAnimation(new FloatValueHolder()).setSpring(new SpringForce(0)); } @Override @@ -127,6 +135,11 @@ public class AppsSearchContainerLayout extends FrameLayout } @Override + public @NonNull SpringAnimation getSpringForFling() { + return mSpring; + } + + @Override public void refreshSearchResult() { mSearchBarController.refreshSearchResult(); } diff --git a/src/com/android/launcher3/anim/SpringAnimationHandler.java b/src/com/android/launcher3/anim/SpringAnimationHandler.java index 3e58adc3f..eec3a48ee 100644 --- a/src/com/android/launcher3/anim/SpringAnimationHandler.java +++ b/src/com/android/launcher3/anim/SpringAnimationHandler.java @@ -70,6 +70,20 @@ public class SpringAnimationHandler<T> { } /** + * Adds a spring to the list of springs handled by this class. + * @param spring The new spring to be added. + * @param setDefaultValues If True, sets the spring to the default + * {@link AnimationFactory} values. + */ + public void add(SpringAnimation spring, boolean setDefaultValues) { + if (setDefaultValues) { + mAnimationFactory.setDefaultValues(spring); + } + spring.setStartVelocity(mCurrentVelocity); + mAnimations.add(spring); + } + + /** * Adds a new or recycled animation to the list of springs handled by this class. * * @param view The view the spring is attached to. @@ -82,15 +96,17 @@ public class SpringAnimationHandler<T> { view.setTag(R.id.spring_animation_tag, spring); } mAnimationFactory.update(spring, object); - spring.setStartVelocity(mCurrentVelocity); - mAnimations.add(spring); + add(spring, false /* setDefaultValues */); } /** * Stops and removes the spring attached to {@param view}. */ public void remove(View view) { - SpringAnimation animation = (SpringAnimation) view.getTag(R.id.spring_animation_tag); + remove((SpringAnimation) view.getTag(R.id.spring_animation_tag)); + } + + public void remove(SpringAnimation animation) { if (animation.canSkipToEnd()) { animation.skipToEnd(); } @@ -226,6 +242,11 @@ public class SpringAnimationHandler<T> { * Updates the value of {@param spring} based on {@param object}. */ void update(SpringAnimation spring, T object); + + /** + * Sets the factory default values for the given {@param spring}. + */ + void setDefaultValues(SpringAnimation spring); } /** |