Back to project page GreenGear.
The source code is released under:
MIT License
If you think the Android project GreenGear listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package com.bradleycurran.viewquery.animation.hc; //from w w w.jav a 2 s. c o m import android.animation.TimeInterpolator; import android.annotation.SuppressLint; import android.view.MotionEvent; import android.view.View; import android.view.View.OnTouchListener; import android.view.ViewPropertyAnimator; import android.view.animation.DecelerateInterpolator; import android.view.animation.OvershootInterpolator; @SuppressLint("NewApi") public class BounceTouchListener implements OnTouchListener { private static final float SCALE_DECEL_FACTOR = 0.7f; private static final float SCALE_OVERSHOOT_FACTOR = 1.0f; private static final float OVERSHOOT_TENSION = 10.0f; private TimeInterpolator mDecelerator; private OvershootInterpolator mOvershootInterpolator; public BounceTouchListener() { mDecelerator = new DecelerateInterpolator(); mOvershootInterpolator = new OvershootInterpolator(OVERSHOOT_TENSION); } @Override public boolean onTouch(View v, MotionEvent event) { if (event.getAction() == MotionEvent.ACTION_DOWN) { ViewPropertyAnimator in = v.animate().setInterpolator(mDecelerator); in.scaleX(SCALE_DECEL_FACTOR).scaleY(SCALE_DECEL_FACTOR); } else if (event.getAction() == MotionEvent.ACTION_UP) { ViewPropertyAnimator in = v.animate().setInterpolator(mOvershootInterpolator); in.scaleX(SCALE_OVERSHOOT_FACTOR).scaleY(SCALE_OVERSHOOT_FACTOR); } return false; } }