Hello, i am using the following class to make full screen animations because i have about 70 full screen images and it dowsnt over load the VM Budget, the problem im having is when i put the time in for postDelayed the animation is faster or slower on different devices, also the duration is important in starting sounds and starting the next animation, i need to find out how to make the animation work the same on all devices, thank you for your time, and any help is very appreciated.
- Code: Select all
class SceneAnimation {
public int x;
public ImageView mImageView;
public int[] mFrameRess;
public int[] mDurations;
public int mDuration;
public int time;
public int mLastFrameNo;
public long mBreakDelay;
public static AnimationListener mAnimationListener;
public SceneAnimation(ImageView pImageView, int[] pFrameRess, int[] pDurations)
{
mImageView = pImageView;
mFrameRess = pFrameRess;
mDurations = pDurations;
mLastFrameNo = pFrameRess.length - 1;
}
public SceneAnimation(ImageView pImageView, int[] pFrameRess, int pDuration){
mImageView = pImageView;
mFrameRess = pFrameRess;
mDuration = pDuration;
mLastFrameNo = pFrameRess.length - 1;
mImageView.setImageResource(mFrameRess[0]);
playConstant(1);
}
public SceneAnimation(ImageView pImageView, int[] pFrameRess, int pDuration, long pBreakDelay){
mImageView = pImageView;
mFrameRess = pFrameRess;
mDuration = pDuration;
mLastFrameNo = pFrameRess.length - 1;
mBreakDelay = pBreakDelay;
mImageView.setImageResource(mFrameRess[0]);
playConstant(1);
}
public void setAnimationListener(AnimationListener listener){
this.mAnimationListener = listener;
}
public void play(final int pFrameNo)
{
{if( mAnimationListener != null ){
mAnimationListener.onAnimationStart();}}
mImageView.postDelayed(new Runnable(){
public void run() {
mImageView.setImageResource(mFrameRess[pFrameNo]);
if(pFrameNo == mLastFrameNo)
{if( mAnimationListener != null ){
mAnimationListener.onAnimationEnd();}
return;}
else
play(pFrameNo + 1);
}
}, mDurations[pFrameNo]);
}
public void playtimes(final int pFrameNo,final int y)
{
{if( mAnimationListener != null ){
mAnimationListener.onAnimationStart();}}
mImageView.postDelayed(new Runnable(){
public void run() {
mImageView.setImageResource(mFrameRess[pFrameNo]);
if(pFrameNo == mLastFrameNo)
{if(y == time)
{
{if( mAnimationListener != null )
mAnimationListener.onAnimationEnd();}
time = 0;
return;}
else
{
{if( mAnimationListener != null )
mAnimationListener.onAnimationRepeat();}
time++;
playtimes(1,y);
}}
else
{
playtimes(pFrameNo + 1,y);
}
}
}, mDurations[pFrameNo]);
}
public void playConstant(final int pFrameNo){
{if( mAnimationListener != null ){
mAnimationListener.onAnimationStart();}}
mImageView.postDelayed(new Runnable(){
public void run() {
mImageView.setImageResource(mFrameRess[pFrameNo]);
if(pFrameNo == mLastFrameNo)
{
if( mAnimationListener != null )
{
mAnimationListener.onAnimationRepeat();
}
playConstant(0);
}
else
playConstant(pFrameNo + 1);
if( mAnimationListener != null ){
mAnimationListener.onAnimationEnd();}
}
}, pFrameNo==mLastFrameNo && mBreakDelay>0 ? mBreakDelay : mDuration);
}
public static interface AnimationListener {
public void onAnimationEnd();
public void onAnimationStart();
public void onAnimationRepeat();
// You can add onAnimationStart(), and do the same thing like onAnimationEnd.
}
};