> hmm, seems OK to me, anyway you have working (not bad) solution w/
> Handler :)
>
> what i like in Animation approach is that interpolatedTime [0..1] but
> if it doesn't work... tough luck
>
> pskink

I just created a custom class to get interpolatedTime...

package com.whatever.utils;

public class TimeTracker {

        private long startTime;
        private long duration;
        private boolean complete;

        public TimeTracker(){
                mark();
        }

        public TimeTracker(long len){
                setDuration(len);
                mark();
        }

        public void setDuration(long len){
                duration = len;
        }

        public void mark(){
                startTime = System.currentTimeMillis();
                complete = false;
        }

        public long getEllapsed(){
                return System.currentTimeMillis() - startTime;
        }

        public boolean atEnd(){
                return complete;
        }

        public double getProgress(){
                double ellapsed = (double) getEllapsed();
                double total = (double) duration;
                double factor = ellapsed / total;
                factor = Math.min(1, factor);
                factor = Math.max(0, factor);
                complete = (factor == 1);
                return factor;  // i can apply easing here with standard penner
equations...
        }

}

one last question though - since the Handler is running in the main UI
thread, are there potential issues?  The animation is brief (500ms)
and I'll probably try to disable any other interactions while it's
happening, but I'm pretty new to multithreaded environments and wonder
if there's a likely problem with how I've got it set up now:

private Handler handler = new Handler() {
    @Override
    public void handleMessage(final Message message) {
        switch (message.what) {
            case TWEEN:
            try {
                double progress = timeKeeper.getEasedProgress(5);
                float position = (float) originalValue +
((destinationValue - originalValue) * progress));
                setValue(position);
                if(!timeKeeper.atEnd()){
                    sendEmptyMessage(TWEEN);
                }
            } catch (Exception e) {
            }
        }
    }
};

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

Reply via email to