ImageView postDelayed on different devices?

Put your problem here if it does not fit any of the other categories.

ImageView postDelayed on different devices?

Postby jrowan » Mon Jan 07, 2013 3:00 am

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.
    }
   

     
};
jrowan
Once Poster
Once Poster
 
Posts: 1
Joined: Mon Jan 07, 2013 2:30 am

Top

Return to Other Coding-Problems

Who is online

Users browsing this forum: No registered users and 16 guests