Created
September 4, 2014 04:07
-
-
Save parallelcross/0d0f236b647e506d5f0c 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 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) { | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi, when i use this helper class, when i press widget, thats cause of rotate widget, why?