Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to implement double tap for surface view in android

Please tell how to implement double tap for SurfaceView in Android using gesture detector. Can anybody provide code example?

like image 636
mohan Avatar asked Oct 27 '11 14:10

mohan


People also ask

What is SurfaceHolder?

android.view.SurfaceHolder. Abstract interface to someone holding a display surface. Allows you to control the surface size and format, edit the pixels in the surface, and monitor changes to the surface. This interface is typically available through the SurfaceView class.

What is a surface view Android?

In the context of the Android framework, Surface refers to a lower-level drawing surface whose contents are eventually displayed on the user's screen. A SurfaceView is a view in your view hierarchy that has its own separate Surface , as shown in the diagram below. You can draw to it in a separate thread.


1 Answers

You could try following.. actually i tested this and it works pretty well:

1) Extend GestureDetector.SimpleOnGestureListener and override it's onDoubleTap() method:

    class DoubleTapGestureDetector extends GestureDetector.SimpleOnGestureListener {

        @Override
        public boolean onDoubleTap(MotionEvent e) {
            Log.d("TAG", "Double Tap Detected ...");
            return true;
        }

    }

2) Instantiate the GestureDetector:

final GestureDetector mGesDetect = new GestureDetector(this, new DoubleTapGestureDetector());

3) Set an OnTouchListener on your SurfaceView, override its onTouch() method and call the onTouchEvent() on your GestureDetector object:

    surfview.setOnTouchListener(new OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            mGesDetect.onTouchEvent(event);
            return true;
        }
    });
like image 132
lukuluku Avatar answered Sep 28 '22 02:09

lukuluku