I changed the logic of the asyncTask to be based on time rather than
point position, at least now I dont have a sleep but it would probably
hammer the UI thread. But I guess thats what I want to get smooth
animation. Should this be in the beginners thread? Anyway here is the
new pseudo-code:

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

                //~ Figure out the animation time

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

                long startTime = System.currentTimeMillis();
                int lastOffset = targetOffset;

                while (System.currentTimeMillis() - startTime < animationTime 
&& !
isCancelled())
                {
                        Float point = new Float(System.currentTimeMillis() - 
startTime) /
new Float(animationTime);
                        Float interpolation = 
interpolater.getInterpolation(point);
                        Float position = new Float(targetDistance) * 
interpolation;
                        int offset = initialOffset + position.intValue();

                        if (offset != lastOffset)
                        {
                                publishProgress(new Long(offset));

                                lastOffset = offset;
                        }
                }

                // Publish one final progress to cleanup any point difference 
after
loop
                publishProgress(new Long(targetOffset));

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

Any further 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