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); }
addView(dotIndicatorLayout); dotIndicatorXSpring = new SpringAnimation(dotIndicatorLayout, SpringAnimation.TRANSLATION_X); SpringForce springForceX = new SpringForce(0); springForceX.setDampingRatio(1f); springForceX.setStiffness(300); SpringForce springForceWidth = new SpringForce(0); springForceWidth.setDampingRatio(1f); springForceWidth.setStiffness(300);
final SpringForce springY = new SpringForce(currentY < mMetrics.heightPixels / 2 ? mPositionLimitRect.top : mPositionLimitRect.bottom); springY.setDampingRatio(SpringForce.DAMPING_RATIO_LOW_BOUNCY); springY.setStiffness(SpringForce.STIFFNESS_LOW);
final SpringForce springX = new SpringForce(goalPositionX); springX.setDampingRatio(ANIMATION_SPRING_X_DAMPING_RATIO); springX.setStiffness(ANIMATION_SPRING_X_STIFFNESS);
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(); } }); } }
SpringForce springForceX = new SpringForce(0f); springForceX.setStiffness(SpringForce.STIFFNESS_MEDIUM); springForceX.setDampingRatio(SpringForce.DAMPING_RATIO_HIGH_BOUNCY); SpringForce springForceY = new SpringForce(0f); springForceY.setStiffness(SpringForce.STIFFNESS_MEDIUM); springForceY.setDampingRatio(SpringForce.DAMPING_RATIO_HIGH_BOUNCY);
@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); } }); } });
if (id == R.id.button_bring) { SpringForce springForce = new SpringForce(INITIAL_ROTATION); springForce.setStiffness(SpringForce.STIFFNESS_LOW); springForce.setDampingRatio(SpringForce.DAMPING_RATIO_HIGH_BOUNCY);
@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); }