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

Commit 1ad3c8f6 authored by Jonathan Miranda's avatar Jonathan Miranda Committed by Android (Google) Code Review
Browse files

Merge "Add spring to QSB when opening all apps." into ub-launcher3-dorval-polish2

parents 08680da4 c90a89d9
Loading
Loading
Loading
Loading
+14 −3
Original line number Diff line number Diff line
@@ -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);

+5 −0
Original line number Diff line number Diff line
@@ -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() {
+7 −0
Original line number Diff line number Diff line
@@ -15,6 +15,8 @@
 */
package com.android.launcher3.allapps;

import android.support.animation.SpringAnimation;
import android.support.annotation.NonNull;
import android.view.KeyEvent;

/**
@@ -27,6 +29,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.
+13 −0
Original line number Diff line number Diff line
@@ -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
@@ -126,6 +134,11 @@ public class AppsSearchContainerLayout extends FrameLayout
                new DefaultAppSearchAlgorithm(appsList.getApps()), mSearchInput, mLauncher, this);
    }

    @Override
    public @NonNull SpringAnimation getSpringForFling() {
        return mSpring;
    }

    @Override
    public void refreshSearchResult() {
        mSearchBarController.refreshSearchResult();
+24 −3
Original line number Diff line number Diff line
@@ -69,6 +69,20 @@ public class SpringAnimationHandler<T> {
        mAnimationFactory = factory;
    }

    /**
     * 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.
     *
@@ -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);
    }

    /**