Search in sources :

Example 1 with FlingSpringAnim

use of com.android.launcher3.anim.FlingSpringAnim in project android_packages_apps_Launcher3 by crdroidandroid.

the class RectFSpringAnim method start.

/**
 * Starts the fling/spring animation.
 * @param context The activity context.
 * @param velocityPxPerMs Velocity of swipe in px/ms.
 */
public void start(Context context, PointF velocityPxPerMs) {
    // Only tell caller that we ended if both x and y animations have ended.
    OnAnimationEndListener onXEndListener = ((animation, canceled, centerX, velocityX) -> {
        mRectXAnimEnded = true;
        maybeOnEnd();
    });
    OnAnimationEndListener onYEndListener = ((animation, canceled, centerY, velocityY) -> {
        mRectYAnimEnded = true;
        maybeOnEnd();
    });
    float startX = mCurrentCenterX;
    float endX = mTargetRect.centerX();
    float minXValue = Math.min(startX, endX);
    float maxXValue = Math.max(startX, endX);
    mRectXAnim = new FlingSpringAnim(this, context, RECT_CENTER_X, startX, endX, velocityPxPerMs.x * 1000, mMinVisChange, minXValue, maxXValue, 1f, onXEndListener);
    float startVelocityY = velocityPxPerMs.y * 1000;
    // Scale the Y velocity based on the initial velocity to tune the curves.
    float springVelocityFactor = 0.1f + 0.9f * Math.abs(startVelocityY) / 20000.0f;
    float startY = mCurrentY;
    float endY = mTrackingBottomY ? mTargetRect.bottom : mTargetRect.top;
    float minYValue = Math.min(startY, endY - mYOvershoot);
    float maxYValue = Math.max(startY, endY);
    mRectYAnim = new FlingSpringAnim(this, context, RECT_Y, startY, endY, startVelocityY, mMinVisChange, minYValue, maxYValue, springVelocityFactor, onYEndListener);
    float minVisibleChange = Math.abs(1f / mStartRect.height());
    ResourceProvider rp = DynamicResource.provider(context);
    float damping = rp.getFloat(R.dimen.swipe_up_rect_scale_damping_ratio);
    float stiffness = rp.getFloat(R.dimen.swipe_up_rect_scale_stiffness);
    mRectScaleAnim = new SpringAnimation(this, RECT_SCALE_PROGRESS).setSpring(new SpringForce(1f).setDampingRatio(damping).setStiffness(stiffness)).setStartVelocity(velocityPxPerMs.y * minVisibleChange).setMaxValue(1f).setMinimumVisibleChange(minVisibleChange).addEndListener((animation, canceled, value, velocity) -> {
        mRectScaleAnimEnded = true;
        maybeOnEnd();
    });
    setCanRelease(false);
    mAnimsStarted = true;
    mRectXAnim.start();
    mRectYAnim.start();
    mRectScaleAnim.start();
    for (Animator.AnimatorListener animatorListener : mAnimatorListeners) {
        animatorListener.onAnimationStart(null);
    }
}
Also used : RectF(android.graphics.RectF) Utilities(com.android.launcher3.Utilities) Context(android.content.Context) SpringForce(androidx.dynamicanimation.animation.SpringForce) PointF(android.graphics.PointF) FloatPropertyCompat(androidx.dynamicanimation.animation.FloatPropertyCompat) DynamicResource(com.android.launcher3.util.DynamicResource) ReleaseCheck(com.android.quickstep.RemoteAnimationTargets.ReleaseCheck) Animator(android.animation.Animator) FlingSpringAnim(com.android.launcher3.anim.FlingSpringAnim) ResourceProvider(com.android.systemui.plugins.ResourceProvider) ArrayList(java.util.ArrayList) OnAnimationEndListener(androidx.dynamicanimation.animation.DynamicAnimation.OnAnimationEndListener) List(java.util.List) Nullable(androidx.annotation.Nullable) R(com.android.launcher3.R) SpringAnimation(androidx.dynamicanimation.animation.SpringAnimation) FlingSpringAnim(com.android.launcher3.anim.FlingSpringAnim) Animator(android.animation.Animator) SpringForce(androidx.dynamicanimation.animation.SpringForce) ResourceProvider(com.android.systemui.plugins.ResourceProvider) SpringAnimation(androidx.dynamicanimation.animation.SpringAnimation) OnAnimationEndListener(androidx.dynamicanimation.animation.DynamicAnimation.OnAnimationEndListener)

Aggregations

Animator (android.animation.Animator)1 Context (android.content.Context)1 PointF (android.graphics.PointF)1 RectF (android.graphics.RectF)1 Nullable (androidx.annotation.Nullable)1 OnAnimationEndListener (androidx.dynamicanimation.animation.DynamicAnimation.OnAnimationEndListener)1 FloatPropertyCompat (androidx.dynamicanimation.animation.FloatPropertyCompat)1 SpringAnimation (androidx.dynamicanimation.animation.SpringAnimation)1 SpringForce (androidx.dynamicanimation.animation.SpringForce)1 R (com.android.launcher3.R)1 Utilities (com.android.launcher3.Utilities)1 FlingSpringAnim (com.android.launcher3.anim.FlingSpringAnim)1 DynamicResource (com.android.launcher3.util.DynamicResource)1 ReleaseCheck (com.android.quickstep.RemoteAnimationTargets.ReleaseCheck)1 ResourceProvider (com.android.systemui.plugins.ResourceProvider)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1