I'm making some progress on using the GestureDetector to start scrolls
and flings for a custom view.

I am using View.scrollBy(x,y) and Scroller.fling in response to
Gestures.

I have a hopefully simple question, though, how do I know when the
scroll/fling is over?
I want to take some action at this point, start recreating the views
buffer and then rest the scroll to (0,0).

But I am uncertain when to do that. GestureDetector doesn't give me
the UP event. I could capture that separately even while most motion
events are consumed by the detector.
This is evidence enough that a scroll is finished, but a fling may
still be in progress.  Sure I can check Scroller.isFinished() here,
but if isn't done, how will I get an event when it is?

        @Override
        public boolean onTouchEvent(MotionEvent event) {

                //let the touch event be handled by the GestureDetector
                boolean handled= this.detector.onTouchEvent(event);
                if(event.getAction()==MotionEvent.ACTION_UP)
                {

                        //be done with scrolling or flinging
                        //recreate view buffer
                        //reset scroll

                }

                if(!handled)
                        return super.onTouchEvent(event);
                else
                        return true;

        }

Here's the Gesture Listener code.

        /*
         * (non-Javadoc)
         * @see android.view.GestureDetector.OnGestureListener#onDown
(android.view.MotionEvent)
         */
        @Override
        public boolean onDown(MotionEvent arg0) {
                // TODO Auto-generated method stub
                return true;
        }

        /*
         * (non-Javadoc)
         * @see android.view.GestureDetector.OnGestureListener#onFling
(android.view.MotionEvent, android.view.MotionEvent, float, float)
         */
        @Override
        public boolean onFling(MotionEvent arg0, MotionEvent arg1, float
velocityX,
                        float velocityY) {
                mScroller.fling(getScrollX(), getScrollY(), (int)(-2*velocityX),
(int)(-2*velocityY), -10000, 10000, -10000, 10000);
                return false;
        }

        /*
         * (non-Javadoc)
         * @see android.view.GestureDetector.OnGestureListener#onLongPress
(android.view.MotionEvent)
         */
        @Override
        public void onLongPress(MotionEvent e) {
                // TODO Auto-generated method stub

        }

        /*
         * (non-Javadoc)
         * @see android.view.GestureDetector.OnGestureListener#onScroll
(android.view.MotionEvent, android.view.MotionEvent, float, float)
         */
        @Override
        public boolean onScroll(MotionEvent e1, MotionEvent e2, float
distanceX,
                        float distanceY) {
                this.scrollBy((int)distanceX, (int)distanceY);
                return true;
        }

        /*
         * (non-Javadoc)
         * @see android.view.GestureDetector.OnGestureListener#onShowPress
(android.view.MotionEvent)
         */
        @Override
        public void onShowPress(MotionEvent e) {
                // TODO Auto-generated method stub

        }

        /*
         * (non-Javadoc)
         * @see android.view.GestureDetector.OnGestureListener#onSingleTapUp
(android.view.MotionEvent)
         */
        @Override
        public boolean onSingleTapUp(MotionEvent e) {
                // Auto-generated method stub
                return false;
        }

This method does get a call during a scroll, but not during a fling,
and it's while the scroll is in progress, not finished.

        @Override
        protected void onScrollChanged(int l, int t, int oldl, int oldt) {
                super.onScrollChanged(l, t, oldl, oldt);
        }


Thanks for any advice. I have checked the archives on this question
and didn't find a solution.




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