-
-
Save aminelaadhari/9731076 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
import android.os.Build; | |
import android.view.MotionEvent; | |
import android.view.View; | |
import android.view.animation.AlphaAnimation; | |
/** | |
* | |
* View Press Effect Helper | |
* - usage : do some simple press effect like iOS | |
* | |
* Simple Usage: | |
* ImageView img = (ImageView) findViewById(R.id.img); | |
* ViewPressEffectHelper.attach(img) | |
* | |
* @author Lam @ HongKong | |
* | |
*/ | |
public class ViewPressEffectHelper { | |
public static void attach(View view){ | |
view.setOnTouchListener(new View.OnTouchListener() { | |
@Override | |
public boolean onTouch(View v, MotionEvent event) { | |
switch (event.getAction()) { | |
case MotionEvent.ACTION_DOWN: { | |
if (Build.VERSION.SDK_INT < 11) { | |
final AlphaAnimation animation = new AlphaAnimation(1.0f, 0.5f); | |
animation.setDuration(100); | |
animation.setFillAfter(true); | |
v.startAnimation(animation); | |
} else | |
v.setAlpha(0.5f); | |
} | |
break; | |
case MotionEvent.ACTION_UP: | |
case MotionEvent.ACTION_CANCEL:{ | |
if (Build.VERSION.SDK_INT < 11) { | |
final AlphaAnimation animation = new AlphaAnimation(0.5f, 1.0f); | |
animation.setDuration(100); | |
animation.setFillAfter(true); | |
v.startAnimation(animation); | |
} else | |
v.setAlpha(1.0f); | |
} | |
break; | |
} | |
return false; | |
} | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment