Last active
August 29, 2015 14:06
-
-
Save parallelcross/bb65659d72f30850b1d0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class ReboundTranslateActivity extends Activity implements View.OnClickListener, SpringListener { | |
private static double TENSION = 800; | |
private static double DAMPER = 20; //friction | |
private ImageView mImageToAnimate; | |
private SpringSystem mSpringSystem; | |
private Spring mSpring; | |
private boolean mMovedUp = false; | |
private float mOrigY; | |
@Override | |
protected void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
setContentView(R.layout.activity_main); | |
mImageToAnimate = (ImageView) findViewById(R.id.imageView); | |
mImageToAnimate.setOnClickListener(this); | |
mSpringSystem = SpringSystem.create(); | |
mSpring = mSpringSystem.createSpring(); | |
mSpring.addListener(this); | |
SpringConfig config = new SpringConfig(TENSION, DAMPER); | |
mSpring.setSpringConfig(config); | |
} | |
@Override | |
public void onClick(View v) { | |
if (mMovedUp) { | |
mSpring.setEndValue(mOrigY); | |
} else { | |
mOrigY = mImageToAnimate.getY(); | |
mSpring.setEndValue(mOrigY - 300f); | |
} | |
mMovedUp = !mMovedUp; | |
} | |
@Override | |
public void onSpringUpdate(Spring spring) { | |
float value = (float) spring.getCurrentValue(); | |
mImageToAnimate.setY(value); | |
} | |
@Override | |
public void onSpringAtRest(Spring spring) { | |
} | |
@Override | |
public void onSpringActivate(Spring spring) { | |
} | |
@Override | |
public void onSpringEndStateChange(Spring spring) { | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment