Created
March 19, 2015 15:40
-
-
Save Aracem/a5beadaa67f82db98441 to your computer and use it in GitHub Desktop.
Tada Animation from Cyrill Mottier
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
package com.aracem.utils.animation; | |
import android.animation.Animator; | |
import android.animation.AnimatorListenerAdapter; | |
import android.animation.Keyframe; | |
import android.animation.ObjectAnimator; | |
import android.animation.PropertyValuesHolder; | |
import android.annotation.TargetApi; | |
import android.content.Context; | |
import android.os.Build; | |
import android.view.View; | |
/** | |
* Based on the Cyrill Mottier code. | |
* Added other funny animations by my own | |
* | |
* https://plus.google.com/118417777153109946393/posts/FABaJhRMCuy | |
* | |
* Created by Marcos Trujillo on 28/05/14. | |
*/ | |
public class AnimationViewUtils { | |
public static ObjectAnimator tada(View view) { | |
return tada(view, 1f); | |
} | |
@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH) | |
public static ObjectAnimator tada(View view, float shakeFactor) { | |
PropertyValuesHolder pvhScaleX = PropertyValuesHolder.ofKeyframe(View.SCALE_X, | |
Keyframe.ofFloat(0f, 1f), | |
Keyframe.ofFloat(.1f, .9f), | |
Keyframe.ofFloat(.2f, .9f), | |
Keyframe.ofFloat(.3f, 1.1f), | |
Keyframe.ofFloat(.4f, 1.1f), | |
Keyframe.ofFloat(.5f, 1.1f), | |
Keyframe.ofFloat(.6f, 1.1f), | |
Keyframe.ofFloat(.7f, 1.1f), | |
Keyframe.ofFloat(.8f, 1.1f), | |
Keyframe.ofFloat(.9f, 1.1f), | |
Keyframe.ofFloat(1f, 1f) | |
); | |
PropertyValuesHolder pvhScaleY = PropertyValuesHolder.ofKeyframe(View.SCALE_Y, | |
Keyframe.ofFloat(0f, 1f), | |
Keyframe.ofFloat(.1f, .9f), | |
Keyframe.ofFloat(.2f, .9f), | |
Keyframe.ofFloat(.3f, 1.1f), | |
Keyframe.ofFloat(.4f, 1.1f), | |
Keyframe.ofFloat(.5f, 1.1f), | |
Keyframe.ofFloat(.6f, 1.1f), | |
Keyframe.ofFloat(.7f, 1.1f), | |
Keyframe.ofFloat(.8f, 1.1f), | |
Keyframe.ofFloat(.9f, 1.1f), | |
Keyframe.ofFloat(1f, 1f) | |
); | |
PropertyValuesHolder pvhRotate = PropertyValuesHolder.ofKeyframe(View.ROTATION, | |
Keyframe.ofFloat(0f, 0f), | |
Keyframe.ofFloat(.1f, -3f * shakeFactor), | |
Keyframe.ofFloat(.2f, -3f * shakeFactor), | |
Keyframe.ofFloat(.3f, 3f * shakeFactor), | |
Keyframe.ofFloat(.4f, -3f * shakeFactor), | |
Keyframe.ofFloat(.5f, 3f * shakeFactor), | |
Keyframe.ofFloat(.6f, -3f * shakeFactor), | |
Keyframe.ofFloat(.7f, 3f * shakeFactor), | |
Keyframe.ofFloat(.8f, -3f * shakeFactor), | |
Keyframe.ofFloat(.9f, 3f * shakeFactor), | |
Keyframe.ofFloat(1f, 0) | |
); | |
return ObjectAnimator.ofPropertyValuesHolder(view, pvhScaleX, pvhScaleY, pvhRotate). | |
setDuration(1000); | |
} | |
@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH) | |
public static ObjectAnimator shakeRight(View view, float translateFactor, int millis) { | |
PropertyValuesHolder pvhTranslateX = PropertyValuesHolder.ofKeyframe(View.TRANSLATION_X, | |
Keyframe.ofFloat(0f, 0f * translateFactor), | |
Keyframe.ofFloat(.1f, 24f * translateFactor), | |
Keyframe.ofFloat(.2f, -16f * translateFactor), | |
Keyframe.ofFloat(.3f, 28 * translateFactor), | |
Keyframe.ofFloat(.4f, -20f * translateFactor), | |
Keyframe.ofFloat(.5f, 32f * translateFactor), | |
Keyframe.ofFloat(.6f, -16f * translateFactor), | |
Keyframe.ofFloat(.7f, 24f * translateFactor), | |
Keyframe.ofFloat(.8f, -12f * translateFactor), | |
Keyframe.ofFloat(.9f, 12f * translateFactor), | |
Keyframe.ofFloat(1f, 0f * translateFactor) | |
); | |
PropertyValuesHolder pvhScaleX = PropertyValuesHolder.ofKeyframe(View.SCALE_X, | |
Keyframe.ofFloat(0f, 1f), | |
Keyframe.ofFloat(.1f, 1.03f), | |
Keyframe.ofFloat(.2f, .97f), | |
Keyframe.ofFloat(.3f, 1.03f), | |
Keyframe.ofFloat(.4f, .97f), | |
Keyframe.ofFloat(.5f, 1.03f), | |
Keyframe.ofFloat(.6f, .97f), | |
Keyframe.ofFloat(.7f, 1.03f), | |
Keyframe.ofFloat(.8f, .97f), | |
Keyframe.ofFloat(.9f, 1f), | |
Keyframe.ofFloat(1f, 1f) | |
); | |
PropertyValuesHolder pvhScaleY = PropertyValuesHolder.ofKeyframe(View.SCALE_Y, | |
Keyframe.ofFloat(0f, 1f), | |
Keyframe.ofFloat(.1f, 1.03f), | |
Keyframe.ofFloat(.2f, .97f), | |
Keyframe.ofFloat(.3f, 1.03f), | |
Keyframe.ofFloat(.4f, .97f), | |
Keyframe.ofFloat(.5f, 1.03f), | |
Keyframe.ofFloat(.6f, .97f), | |
Keyframe.ofFloat(.7f, 1.03f), | |
Keyframe.ofFloat(.8f, .97f), | |
Keyframe.ofFloat(.9f, 1f), | |
Keyframe.ofFloat(1f, 1f) | |
); | |
return ObjectAnimator.ofPropertyValuesHolder(view, pvhTranslateX, pvhScaleX, pvhScaleY). | |
setDuration(millis); | |
} | |
@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH) | |
public static ObjectAnimator shakeRightSlow(View view, float translateFactor, int millis) { | |
PropertyValuesHolder pvhTranslateX = PropertyValuesHolder.ofKeyframe(View.TRANSLATION_X, | |
Keyframe.ofFloat(0f, 0f * translateFactor), | |
Keyframe.ofFloat(.1f, 24f * translateFactor), | |
Keyframe.ofFloat(.3f, -16 * translateFactor), | |
Keyframe.ofFloat(.5f, 32f * translateFactor), | |
Keyframe.ofFloat(.7f, -18f * translateFactor), | |
Keyframe.ofFloat(.9f, 24f * translateFactor), | |
Keyframe.ofFloat(1f, 0f * translateFactor) | |
); | |
PropertyValuesHolder pvhScaleX = PropertyValuesHolder.ofKeyframe(View.SCALE_X, | |
Keyframe.ofFloat(0f, 1f), | |
Keyframe.ofFloat(.1f, 1.03f), | |
Keyframe.ofFloat(.3f, .97f), | |
Keyframe.ofFloat(.5f, 1.03f), | |
Keyframe.ofFloat(.7f, .97f), | |
Keyframe.ofFloat(.9f, 1.03f), | |
Keyframe.ofFloat(1f, 1f) | |
); | |
PropertyValuesHolder pvhScaleY = PropertyValuesHolder.ofKeyframe(View.SCALE_Y, | |
Keyframe.ofFloat(0f, 1f), | |
Keyframe.ofFloat(.1f, 1.03f), | |
Keyframe.ofFloat(.3f, .97f), | |
Keyframe.ofFloat(.5f, 1.03f), | |
Keyframe.ofFloat(.7f, .97f), | |
Keyframe.ofFloat(.9f, 1.03f), | |
Keyframe.ofFloat(1f, 1f) | |
); | |
return ObjectAnimator.ofPropertyValuesHolder(view, pvhTranslateX, pvhScaleX, pvhScaleY). | |
setDuration(millis); | |
} | |
@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH) | |
public static ObjectAnimator shakeUp(View view, float translateFactor, int millis) { | |
PropertyValuesHolder pvhTranslateX = PropertyValuesHolder.ofKeyframe(View.TRANSLATION_Y, | |
Keyframe.ofFloat(0f, 0f * translateFactor), | |
Keyframe.ofFloat(.1f, 24f * translateFactor), | |
Keyframe.ofFloat(.2f, -16f * translateFactor), | |
Keyframe.ofFloat(.3f, 28 * translateFactor), | |
Keyframe.ofFloat(.4f, -20f * translateFactor), | |
Keyframe.ofFloat(.5f, 32f * translateFactor), | |
Keyframe.ofFloat(.6f, -16f * translateFactor), | |
Keyframe.ofFloat(.7f, 24f * translateFactor), | |
Keyframe.ofFloat(.8f, -12f * translateFactor), | |
Keyframe.ofFloat(.9f, 12f * translateFactor), | |
Keyframe.ofFloat(1f, 0f * translateFactor) | |
); | |
PropertyValuesHolder pvhScaleX = PropertyValuesHolder.ofKeyframe(View.SCALE_X, | |
Keyframe.ofFloat(0f, 1f), | |
Keyframe.ofFloat(.1f, 1.03f), | |
Keyframe.ofFloat(.2f, .97f), | |
Keyframe.ofFloat(.3f, 1.03f), | |
Keyframe.ofFloat(.4f, .97f), | |
Keyframe.ofFloat(.5f, 1.03f), | |
Keyframe.ofFloat(.6f, .97f), | |
Keyframe.ofFloat(.7f, 1.03f), | |
Keyframe.ofFloat(.8f, .97f), | |
Keyframe.ofFloat(.9f, 1f), | |
Keyframe.ofFloat(1f, 1f) | |
); | |
PropertyValuesHolder pvhScaleY = PropertyValuesHolder.ofKeyframe(View.SCALE_Y, | |
Keyframe.ofFloat(0f, 1f), | |
Keyframe.ofFloat(.1f, 1.03f), | |
Keyframe.ofFloat(.2f, .97f), | |
Keyframe.ofFloat(.3f, 1.03f), | |
Keyframe.ofFloat(.4f, .97f), | |
Keyframe.ofFloat(.5f, 1.03f), | |
Keyframe.ofFloat(.6f, .97f), | |
Keyframe.ofFloat(.7f, 1.03f), | |
Keyframe.ofFloat(.8f, .97f), | |
Keyframe.ofFloat(.9f, 1f), | |
Keyframe.ofFloat(1f, 1f) | |
); | |
return ObjectAnimator.ofPropertyValuesHolder(view, pvhTranslateX, pvhScaleX, pvhScaleY). | |
setDuration(millis); | |
} | |
@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH) | |
public static ObjectAnimator shakeUpSlow(View view, float translateFactor, int millis) { | |
PropertyValuesHolder pvhTranslateX = PropertyValuesHolder.ofKeyframe(View.TRANSLATION_Y, | |
Keyframe.ofFloat(0f, 0f * translateFactor), | |
Keyframe.ofFloat(.1f, 24f * translateFactor), | |
Keyframe.ofFloat(.3f, -16 * translateFactor), | |
Keyframe.ofFloat(.5f, 32f * translateFactor), | |
Keyframe.ofFloat(.7f, -18f * translateFactor), | |
Keyframe.ofFloat(.9f, 24f * translateFactor), | |
Keyframe.ofFloat(1f, 0f * translateFactor) | |
); | |
PropertyValuesHolder pvhScaleX = PropertyValuesHolder.ofKeyframe(View.SCALE_X, | |
Keyframe.ofFloat(0f, 1f), | |
Keyframe.ofFloat(.1f, 1.03f), | |
Keyframe.ofFloat(.3f, .97f), | |
Keyframe.ofFloat(.5f, 1.03f), | |
Keyframe.ofFloat(.7f, .97f), | |
Keyframe.ofFloat(.9f, 1.03f), | |
Keyframe.ofFloat(1f, 1f) | |
); | |
PropertyValuesHolder pvhScaleY = PropertyValuesHolder.ofKeyframe(View.SCALE_Y, | |
Keyframe.ofFloat(0f, 1f), | |
Keyframe.ofFloat(.1f, 1.03f), | |
Keyframe.ofFloat(.3f, .97f), | |
Keyframe.ofFloat(.5f, 1.03f), | |
Keyframe.ofFloat(.7f, .97f), | |
Keyframe.ofFloat(.9f, 1.03f), | |
Keyframe.ofFloat(1f, 1f) | |
); | |
return ObjectAnimator.ofPropertyValuesHolder(view, pvhTranslateX, pvhScaleX, pvhScaleY). | |
setDuration(millis); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment