If you think the Android project GhostStories listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
Java Source Code
package com.utils;
//www.java2s.comimport android.view.View;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
/**
* Animation utility methods
*/publicabstractclass AnimationUtils2 {
/**
* Animates the view to the given x/y coordinates using the given duration
* and calling the given {@link Runnable} once the animation completes.
* @param pView The view to animate
* @param pX The x location in pixels
* @param pY The y location in pixels
* @param pDuration The duration of the animation
* @param pEndAction The runnable to execute at the end of the animation
*/publicstaticvoid animateXY(final View pView,
finalint pX, finalint pY, finalint pDuration,
final Runnable pEndAction) {
if(AndroidUtils.isUIThread()) {
pView.animate().setDuration(pDuration).x(
pX).y(pY).withEndAction(pEndAction);
} else {
pView.post(new Runnable() {
publicvoid run() {
animateXY(pView, pX, pY, pDuration, pEndAction);
}
});
}
}
/**
* Runs the given animation on the given view.
* @param pAnimationId The animation id
* @param pView The view to run the animation on
*/publicstaticvoid runAnimation(finalint pAnimationId, final View pView) {
if(AndroidUtils.isUIThread()) {
Animation anim = AnimationUtils.loadAnimation(pView.getContext(),
pAnimationId);
pView.startAnimation(anim);
} else {
pView.post(new Runnable() {
publicvoid run() {
runAnimation(pAnimationId, pView);
}
});
}
}
/**
* Animates the view by translating the view in the x direction to the
* specified x value using the given duration. Calls the specified
* {@link Runnable} once the animation completes.
* @param pView The view to animate
* @param pValue The x value to animate the view to
* @param pDuration The duration of the animation
* @param pEndAction The runnable to execute at the end of the animation
*/publicstaticvoid translationX(final View pView,
finalfloat pValue, finalint pDuration, final Runnable pEndAction) {
if(AndroidUtils.isUIThread()) {
pView.animate().setDuration(pDuration).translationX(
pValue).withEndAction(pEndAction);
} else {
pView.post(new Runnable() {
publicvoid run() {
translationX(pView, pValue, pDuration, pEndAction);
}
});
}
}
/**
* Animates the view by translating the view in the y direction to the
* specified y value using the given duration. Calls the specified
* {@link Runnable} once the animation completes.
* @param pView The view to animate
* @param pValue The y value to animate the view to
* @param pDuration The duration of the animation
* @param pEndAction The runnable to execute at the end of the animation
*/publicstaticvoid translationY(final View pView,
finalfloat pValue, finalint pDuration, final Runnable pEndAction) {
if(AndroidUtils.isUIThread()) {
pView.animate().setDuration(pDuration).translationY(
pValue).withEndAction(pEndAction);
} else {
pView.post(new Runnable() {
publicvoid run() {
translationY(pView, pValue, pDuration, pEndAction);
}
});
}
}
/**
* Animates the view by translating the view in the x direction by the
* specified x value using the given duration. Calls the specified
* {@link Runnable} once the animation completes.
* @param pView The view to animate
* @param pValue The x value to animate the view by
* @param pDuration The duration of the animation
* @param pEndAction The runnable to execute at the end of the animation
*/publicstaticvoid translationXBy(final View pView,
finalfloat pValue, finalint pDuration, final Runnable pEndAction) {
if(AndroidUtils.isUIThread()) {
pView.animate().setDuration(pDuration).translationXBy(
pValue).withEndAction(pEndAction);
} else {
pView.post(new Runnable() {
publicvoid run() {
translationXBy(pView, pValue, pDuration, pEndAction);
}
});
}
}
/**
* Animates the view by translating the view in the y direction by the
* specified y value using the given duration. Calls the specified
* {@link Runnable} once the animation completes.
* @param pView The view to animate
* @param pValue The y value to animate the view by
* @param pDuration The duration of the animation
* @param pEndAction The runnable to execute at the end of the animation
*/publicstaticvoid translationYBy(final View pView,
finalfloat pValue, finalint pDuration, final Runnable pEndAction) {
if(AndroidUtils.isUIThread()) {
pView.animate().setDuration(pDuration).translationYBy(
pValue).withEndAction(pEndAction);
} else {
pView.post(new Runnable() {
publicvoid run() {
translationYBy(pView, pValue, pDuration, pEndAction);
}
});
}
}
}