androidx.dynamicanimation.animation.FlingAnimation Java Examples

The following examples show how to use androidx.dynamicanimation.animation.FlingAnimation. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: FlingSpringAnim.java    From Animer with Apache License 2.0 6 votes vote down vote up
public <K> FlingSpringAnim(K object, FloatPropertyCompat<K> property, float startPosition,
        float targetPosition, float startVelocity, float minVisChange, float minValue,
        float maxValue, float springVelocityFactor, OnAnimationEndListener onEndListener) {
    mFlingAnim = new FlingAnimation(object, property)
            .setFriction(FLING_FRICTION)
            // Have the spring pull towards the target if we've slowed down too much before
            // reaching it.
            .setMinimumVisibleChange(minVisChange)
            .setStartVelocity(startVelocity)
            .setMinValue(minValue)
            .setMaxValue(maxValue);
    mTargetPosition = targetPosition;

    mFlingAnim.addEndListener(((animation, canceled, value, velocity) -> {
        mSpringAnim = new SpringAnimation(object, property)
                .setStartValue(value)
                .setStartVelocity(velocity * springVelocityFactor)
                .setSpring(new SpringForce(mTargetPosition)
                        .setStiffness(SPRING_STIFFNESS)
                        .setDampingRatio(SPRING_DAMPING));
        mSpringAnim.addEndListener(onEndListener);
        mSpringAnim.animateToFinalPosition(mTargetPosition);
    }));
}
 
Example #2
Source File: FlingSpringAnim.java    From Animer with Apache License 2.0 6 votes vote down vote up
public <K> FlingSpringAnim(K object, FloatPropertyCompat<K> property, float startPosition,
        float targetPosition, float startVelocity, float minVisChange, float minValue,
        float maxValue, float springVelocityFactor, OnAnimationEndListener onEndListener) {
    mFlingAnim = new FlingAnimation(object, property)
            .setFriction(FLING_FRICTION)
            // Have the spring pull towards the target if we've slowed down too much before
            // reaching it.
            .setMinimumVisibleChange(minVisChange)
            .setStartVelocity(startVelocity)
            .setMinValue(minValue)
            .setMaxValue(maxValue);
    mTargetPosition = targetPosition;

    mFlingAnim.addEndListener(((animation, canceled, value, velocity) -> {
        mSpringAnim = new SpringAnimation(object, property)
                .setStartValue(value)
                .setStartVelocity(velocity * springVelocityFactor)
                .setSpring(new SpringForce(mTargetPosition)
                        .setStiffness(SPRING_STIFFNESS)
                        .setDampingRatio(SPRING_DAMPING));
        mSpringAnim.addEndListener(onEndListener);
        mSpringAnim.animateToFinalPosition(mTargetPosition);
    }));
}
 
Example #3
Source File: Animer.java    From Animer with Apache License 2.0 5 votes vote down vote up
private void attachSolverToFling(AnimerSolver solver, FlingAnimation flingAnimation){
    final FlingAnimation flingAnim = flingAnimation;
    flingAnim.setStartVelocity((float) solver.getArg1());
    flingAnim.setFriction((float) solver.getArg2());

    solver.bindSolverListener(new AnimerSolver.SolverListener() {
        @Override
        public void onSolverUpdate(Object arg1, Object arg2) {
            flingAnim.setStartVelocity((float) arg1);
            flingAnim.setFriction((float) arg2);
        }
    });
}