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

Commit 1d19e2f1 authored by Jon Miranda's avatar Jon Miranda
Browse files

Start springs for All Apps when user flings up.

Bug: 77695481
Change-Id: Ifecfbbb89601947118f620f522662aee8a61946e
parent c0928c3b
Loading
Loading
Loading
Loading
+32 −0
Original line number Diff line number Diff line
@@ -15,12 +15,14 @@
 */
package com.android.launcher3.allapps;

import android.animation.ValueAnimator;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.Point;
import android.graphics.Rect;
import android.os.Process;
import android.support.animation.DynamicAnimation;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.annotation.StringRes;
@@ -61,6 +63,10 @@ import com.android.launcher3.views.SpringRelativeLayout;
public class AllAppsContainerView extends SpringRelativeLayout implements DragSource,
        Insettable, OnDeviceProfileChangeListener {

    private static final float FLING_VELOCITY_MULTIPLIER = 135f;
    // Starts the springs after at least 55% of the animation has passed.
    private static final float FLING_ANIMATION_THRESHOLD = 0.55f;

    private final Launcher mLauncher;
    private final AdapterHolder[] mAH;
    private final ItemInfoMatcher mPersonalMatcher = ItemInfoMatcher.ofUser(Process.myUserHandle());
@@ -455,6 +461,32 @@ public class AllAppsContainerView extends SpringRelativeLayout implements DragSo
        }
    }

    /**
     * Adds an update listener to {@param animator} that adds springs to the animation.
     */
    public void addSpringFromFlingUpdateListener(ValueAnimator animator, float velocity) {
        animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
            @Override
            public void onAnimationUpdate(ValueAnimator valueAnimator) {
                if (valueAnimator.getAnimatedFraction() >= FLING_ANIMATION_THRESHOLD) {
                    int searchViewId = getSearchView().getId();
                    addSpringView(searchViewId);

                    finishWithShiftAndVelocity(1, velocity * FLING_VELOCITY_MULTIPLIER,
                            new DynamicAnimation.OnAnimationEndListener() {
                                @Override
                                public void onAnimationEnd(DynamicAnimation animation,
                                        boolean canceled, float value, float velocity) {
                                    removeSpringView(searchViewId);
                                }
                            });

                    animator.removeUpdateListener(this);
                }
            }
        });
    }

    public class AdapterHolder {
        public static final int MAIN = 0;
        public static final int WORK = 1;
+3 −0
Original line number Diff line number Diff line
@@ -396,6 +396,9 @@ public abstract class AbstractStateChangeTouchController
        updateSwipeCompleteAnimation(anim, Math.max(duration, getRemainingAtomicDuration()),
                targetState, velocity, fling);
        mCurrentAnimation.dispatchOnStart();
        if (fling && targetState == LauncherState.ALL_APPS) {
            mLauncher.getAppsView().addSpringFromFlingUpdateListener(anim, velocity);
        }
        anim.start();
        if (mAtomicAnim == null) {
            startAtomicComponentsAnim(endProgress, anim.getDuration());
+13 −0
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@ package com.android.launcher3.views;

import android.content.Context;
import android.graphics.Canvas;
import android.support.animation.DynamicAnimation;
import android.support.animation.FloatPropertyCompat;
import android.support.animation.SpringAnimation;
import android.support.animation.SpringForce;
@@ -79,6 +80,11 @@ public class SpringRelativeLayout extends RelativeLayout {
        mSpringViews.put(id, true);
    }

    public void removeSpringView(int id) {
        mSpringViews.delete(id);
        invalidate();
    }

    @Override
    protected boolean drawChild(Canvas canvas, View child, long drawingTime) {
        if (mDampedScrollShift != 0 && mSpringViews.get(child.getId())) {
@@ -110,6 +116,13 @@ public class SpringRelativeLayout extends RelativeLayout {
        mSpring.start();
    }

    protected void finishWithShiftAndVelocity(float shift, float velocity,
            DynamicAnimation.OnAnimationEndListener listener) {
        setDampedScrollShift(shift);
        mSpring.addEndListener(listener);
        finishScrollWithVelocity(velocity);
    }

    public EdgeEffectFactory createEdgeEffectFactory() {
        return new SpringEdgeEffectFactory();
    }