In solving another problem I had I have written a gallery style view
based on framelayout which supports fling, animated transitions,
adapters, etc. Ill post it up as an example soon. But for now im not
really sure I have used the best approach for running the animation
threads.

I decided to use my own animation thread rather than any standard
transitions because they didnt seem to repaint all the views correctly
during the animation (I am working in a framelayout and scrolling
three views about, ive seen a couple of other posts about the repaint
issue but no solutions).

Anyway, rightly or wrongly I used an AsyncTask. The bit I am worried
about is the Thread.sleep() call. Seems kinda the wrong way to go
about it to me. Here is the psuedo-code for what I am doing (ive
removed alot of junk not relevant to my question):

-------------------------------------------------------------------------------
private class AnimationTask extends AsyncTask<Long, Long, Void>
{
        @Override
        protected Void doInBackground(Long... parameters)
        {
                try
                {
                        //~ Figure out the x offset we are animating from and to

                        android.view.animation.Interpolator interpolater =
AnimationUtils.loadInterpolator(mContext,
android.R.anim.decelerate_interpolator);

                        // Step through interpolation animation points from 0.0 
through to
1.0
                        for (Float point = 0.0f; point < 1.0f && 
!isCancelled(); point +=
step)
                        {
                                Float interpolation = 
interpolater.getInterpolation(point);
                                Float position = new Float(targetDistance) * 
interpolation;
                                int offset = initialOffset + 
position.intValue();

                                publishProgress(new Long(offset));

                                //~ Figure out the wait time based on elapsed 
time since animation
began

                                if (waitTime > 0)
                                {
                                        Thread.sleep(waitTime, 0);
                                }
                        }

                        // Publish one final progress to cleanup any point 
difference after
loop
                        publishProgress(new Long(targetOffset));
                }
                catch (InterruptedException  e)
                {
                }

                return null;

                // TODO: The task never seems to die? But it seems that android
                // will only keep a maximum of five of these threads before it
                // recycles one of the old threads to service a new one???
        }

        @Override
        protected void onProgressUpdate(Long... parameters)
        {
                int scrollOffset = parameters[0].intValue();

                //~ Scroll the view to the offset
        }
}
-------------------------------------------------------------------------------

Oh yeah, there is also that whole thing about the AsyncThreads still
running after you exit. I havent figured that one out yet.

Any suggestions?

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to