0

I am developing a game in which I want to perform certain operations when user single touch the screen, and some other operations when user long press the screen. For this, I have created a Gesture Detector class and add events to them.

Surface View Class

public class MySurfaceView extends SurfaceView implements SurfaceHolder.Callback {
public MySurfaceView(Context context, AttributeSet attrs) {
gestureDetector = new GestureDetector(context, new GestureListener(this));
}


@Override
public boolean onTouchEvent(MotionEvent event) {
     Log.d(TAG,"Inside Touch Event");
    float lasttouched_X, lasttouched_Y;
    Card localcard;
    int index=-1;
    Log.d(TAG,"Inside OnTouch event");
    gestureDetector.onTouchEvent(event);
    return true;
  }
 }

Gesture Detector class

 class GestureListener extends GestureDetector.SimpleOnGestureListener{
private static final String TAG = GestureListener.class.getSimpleName();  // To get name of class in Logging
    MySurfaceView mySurfaceView;



    public GestureListener(MySurfaceView paramMySurfaceView)
    {
        mySurfaceView=paramMySurfaceView;
    }

@Override
public void onLongPress(MotionEvent e) {

    Log.d(TAG,"Inside Long Pressed event");
        mySurfaceView.addTouchedCardToLongTouched(e);
}


@Override
public boolean onDown(MotionEvent e) {

  // don't return false here or else none of the other
  // gestures will work

    return  false;
}


@Override
public boolean onSingleTapConfirmed(MotionEvent e) {
    mySurfaceView.swapSingleTouchCard(e);
    return false;
}

@Override
public boolean onDoubleTap(MotionEvent e) {
    Log.d(TAG,"Inside On Double Tap event");
    return false;
}

}

OnLongPress event is working only for first time, after that whenever i long press touch screen, it is firing onSingleTapConfirmed event.I am not able to understand why this is happening.

Please let me know why this is happening. Thanks in advance.

Chetan Mehra
  • 189
  • 1
  • 3
  • 20

0 Answers0