private void setUpDotIndicator() { if (viewPager != null && viewPager.getAdapter() != null && viewPager.getAdapter().getCount() == 0) { return; } if (dotIndicatorView != null && indexOfChild(dotIndicatorView) != -1) { removeView(dotIndicatorView); } dotIndicatorView = buildDot(false); addView(dotIndicatorView); dotIndicatorSpring = new SpringAnimation(dotIndicatorView, SpringAnimation.TRANSLATION_X); SpringForce springForce = new SpringForce(0); springForce.setDampingRatio(dampingRatio); springForce.setStiffness(stiffness); dotIndicatorSpring.setSpring(springForce); }
springAnimationY.setStartVelocity(velocityY); springAnimationY.setStartValue(mParams.y); springAnimationY.setSpring(springY); springAnimationY.setMinimumVisibleChange(DynamicAnimation.MIN_VISIBLE_CHANGE_PIXELS); springAnimationY.addUpdateListener(new DynamicAnimation.OnAnimationUpdateListener() {
springAnimationX.setStartVelocity(mVelocityTracker.getXVelocity()); springAnimationX.setStartValue(mParams.x); springAnimationX.setSpring(springX); springAnimationX.setMinimumVisibleChange(DynamicAnimation.MIN_VISIBLE_CHANGE_PIXELS); springAnimationX.addUpdateListener(new DynamicAnimation.OnAnimationUpdateListener() {
public static SpringAnimation createSpringAnimation(View view, DynamicAnimation.ViewProperty property, float finalPosition, float stiffness, float dampingRatio) { SpringAnimation animation = new SpringAnimation(view, property); SpringForce springForce = new SpringForce(finalPosition); springForce.setStiffness(stiffness); springForce.setDampingRatio(dampingRatio); animation.setSpring(springForce); return animation; }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_ball); buttonBounce = (Button)findViewById(R.id.bounce); final View ball = findViewById(R.id.ball); SpringForce springForce = new SpringForce(0) .setDampingRatio(0.05f) .setStiffness(SpringForce.STIFFNESS_VERY_LOW); final SpringAnimation anim = new SpringAnimation(ball ,SpringAnimation.TRANSLATION_Y).setSpring(springForce); buttonBounce.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { anim.cancel(); anim.setStartValue(-700); anim.start(); } }); } }
springForceX.setStiffness(SpringForce.STIFFNESS_MEDIUM); springForceX.setDampingRatio(SpringForce.DAMPING_RATIO_HIGH_BOUNCY); mSpringTranslationXAnimation.setSpring(springForceX); springForceY.setStiffness(SpringForce.STIFFNESS_MEDIUM); springForceY.setDampingRatio(SpringForce.DAMPING_RATIO_HIGH_BOUNCY); mSpringTranslationYAnimation.setSpring(springForceY);
@Override public void onClick(View view) { final SpringAnimation springAnimation = new SpringAnimation(img, DynamicAnimation.X); final SpringForce springForce = new SpringForce(); springForce.setDampingRatio(SpringForce.DAMPING_RATIO_HIGH_BOUNCY); springForce.setStiffness(SpringForce.STIFFNESS_VERY_LOW); springForce.setFinalPosition(img.getX()); springAnimation.setSpring(springForce); springAnimation.setStartVelocity(2000); springAnimation.start(); } });
@Override public void onClick(View view) { SpringAnimation springAnimation = new SpringAnimation(img, DynamicAnimation.X); SpringForce springForce = new SpringForce(); springForce.setFinalPosition(img.getX()); springForce.setDampingRatio(SpringForce.DAMPING_RATIO_HIGH_BOUNCY); springForce.setStiffness(SpringForce.STIFFNESS_LOW); springAnimation.setSpring(springForce); springAnimation.setStartVelocity(2000); springAnimation.start(); img.setImageResource(R.drawable.ic_sentiment_very_satisfied_black_56dp); springAnimation.addEndListener(new DynamicAnimation.OnAnimationEndListener() { @Override public void onAnimationEnd(DynamicAnimation animation, boolean canceled, float value, float velocity) { img.setImageResource(R.drawable.ic_sentiment_neutral_black_56dp); } }); } });
rotationAnim.setSpring(springForce).setStartValue(-30).start();
@Override public void onClick(View view) { FloatPropertyCompat<View> scale = new FloatPropertyCompat<View>("scale") { @Override public float getValue(View view) { return view.getScaleX(); } @Override public void setValue(View view, float value) { view.setScaleX(value); view.setScaleY(value); } }; SpringAnimation stretchAnimation = new SpringAnimation(img, scale); stretchAnimation.setMinimumVisibleChange( DynamicAnimation.MIN_VISIBLE_CHANGE_SCALE); SpringForce force = new SpringForce(1); force.setDampingRatio(SpringForce.DAMPING_RATIO_HIGH_BOUNCY) .setStiffness(SpringForce.STIFFNESS_VERY_LOW); stretchAnimation.setSpring(force) .setStartVelocity(100); stretchAnimation.start(); } });
HorizontalMoveAnimatorImpl(View target, RectF restrictionRect, int maxScale) { this.maxScale = maxScale; this.restrictionRect = restrictionRect; spring = new SpringAnimation(target, new FloatPropertyCompat<View>("X") { @Override public float getValue(View view) { return view.getX(); } @Override public void setValue(View view, float value) { view.setX(value); } }) .setSpring(new SpringForce() .setStiffness(STIFFNESS) .setDampingRatio(DAMPING_RATIO) ); fling = new FlingAnimation(target, DynamicAnimation.X).setFriction(FRICTION); animator = new ObjectAnimator(); animator.setProperty(TRANSLATION_X); animator.setTarget(target); }
VerticalMoveAnimatorImpl(View target, RectF restrictionRect, int maxScale) { this.maxScale = maxScale; this.restrictionRect = restrictionRect; spring = new SpringAnimation(target, new FloatPropertyCompat<View>("Y") { @Override public float getValue(View view) { return view.getY(); } @Override public void setValue(View view, float value) { view.setY(value); } }) .setSpring(new SpringForce() .setStiffness(STIFFNESS) .setDampingRatio(DAMPING_RATIO) ); fling = new FlingAnimation(target, DynamicAnimation.Y).setFriction(FRICTION); animator = new ObjectAnimator(); animator.setProperty(TRANSLATION_Y); animator.setTarget(target); }