Get current Y position of touch events on GLSurfaceView

671 views Asked by At

In my Application I have a GLSurfaceView where I draw things using OpenGL ES. Now I want the user to be able to touch this GLSurfaceview. Moreover, once the user puts his finger on the view I want to detect the current position on the y axis of the touch event. I am using the following code:

 mGLSurfaceView.setOnTouchListener(new View.OnTouchListener() {
            @Override
            public boolean onTouch(View view, MotionEvent motionEvent) {
                Log.d(TAG,motionEvent.getY()+"");
                return false;
            }
        });

This works fine, however what I exactly want is that I also get the y postion value while the user swipes up and down on the Surface. Using the code above the onTouch() callback gets only called a single time when the user touches the surface. Is there another Listener I can use for this which I am missing?

In the end I want to implement some scrolling/zooming feature on my GLSurfaceView.

ty

1

There are 1 answers

0
Moonlit On BEST ANSWER

Ok, figured it out on my own. The Callback gets called not only when the user presses on the view. However, one has to "filter out" the MOVE actions from motion Event.

So here is the working code:

 mSurfaceView.setOnTouchListener(new View.OnTouchListener() {
            @Override
            public boolean onTouch(View view, MotionEvent motionEvent) {

               if(motionEvent.getAction() == MotionEvent.ACTION_MOVE)
                Log.d(TAG,"Y:Postion: " + motionEvent.getY());
                return true;
            }
        });