Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Replacing Deprecated GestureDetector constructor

So below I've got a GestureDetector, but the whole thing shows "Deprecated Constructor" in Eclipse..

I'm using it to detect flings and it works great but I'm unable to find a parallel constructor. The whole thing is deprecated. To what do I switch over to?

Anyways, here's the code:

mGestureDetector = new GestureDetector(
            new GestureDetector.SimpleOnGestureListener() {
                @Override
                public boolean onDown(MotionEvent e) {
                    return true;
                }

                @Override
                public boolean onFling(MotionEvent e1, MotionEvent e2,
                        float velocityX, float velocityY) {
                    // Roll the ball in the direction of the fling
                    Direction mCommandedRollDirection = Direction.NONE;

                    if (Math.abs(velocityX) > Math.abs(velocityY)) {
                        if (velocityX < 0)
                            mCommandedRollDirection = Direction.LEFT;


                    else
                                mCommandedRollDirection = Direction.RIGHT;
                        } else {
                            if (velocityY < 0)
                                mCommandedRollDirection = Direction.UP;
                            else
                                mCommandedRollDirection = Direction.DOWN;
                        }

                        if (mCommandedRollDirection != Direction.NONE) {
                            mGameEngine.rollBall(mCommandedRollDirection);
                        }

                        return true;
                    }
                });
        mGestureDetector.setIsLongpressEnabled(false);
    }

Clearly, I want the same functionality. So what new functions do I have to add (if any) and which constructor exactly do I need to use?

(Yes, I know about the Android dev docs but like I said I'm having trouble finding the newer version of what's-it-called-GestureDetector)

Thank you!

like image 310
user3139736 Avatar asked Dec 20 '22 19:12

user3139736


1 Answers

exchange for this:

GestureDetector gd = new GestureDetector(getActivity(), new OnGestureListener() {
   Methods for the listener 
}
like image 146
Daniel Bo Avatar answered Jan 09 '23 00:01

Daniel Bo