Skip to content

Instantly share code, notes, and snippets.

@parallelcross
Created September 4, 2014 04:07
Show Gist options
  • Save parallelcross/0d0f236b647e506d5f0c to your computer and use it in GitHub Desktop.
Save parallelcross/0d0f236b647e506d5f0c to your computer and use it in GitHub Desktop.
public class ReboundScaleActivity extends Activity implements View.OnTouchListener, SpringListener {
private static double TENSION = 800;
private static double DAMPER = 20; //friction
private ImageView mImageToAnimate;
private SpringSystem mSpringSystem;
private Spring mSpring;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mImageToAnimate = (ImageView) findViewById(R.id.imageView);
mImageToAnimate.setOnTouchListener(this);
mSpringSystem = SpringSystem.create();
mSpring = mSpringSystem.createSpring();
mSpring.addListener(this);
SpringConfig config = new SpringConfig(TENSION, DAMPER);
mSpring.setSpringConfig(config);
}
@Override
public boolean onTouch(View v, MotionEvent event) {
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
mSpring.setEndValue(1f);
return true;
case MotionEvent.ACTION_UP:
mSpring.setEndValue(0f);
return true;
}
return false;
}
@Override
public void onSpringUpdate(Spring spring) {
float value = (float) spring.getCurrentValue();
float scale = 1f - (value * 0.5f);
mImageToAnimate.setScaleX(scale);
mImageToAnimate.setScaleY(scale);
}
@Override
public void onSpringAtRest(Spring spring) {
}
@Override
public void onSpringActivate(Spring spring) {
}
@Override
public void onSpringEndStateChange(Spring spring) {
}
}
@pishguy
Copy link

pishguy commented Sep 6, 2016

Hi, when i use this helper class, when i press widget, thats cause of rotate widget, why?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment