Search code examples
javaandroidgesture

What is the purpose of GestureDetector.OnGestureListener versus GestureDetector.SimpleOnGestureListener?


If GestureDetector.SimpleOnGestureListener does the same thing as GestureDetector.OnGestureListener but without requiring unused code, then what is the point of OnGestureListener at all?

Rarely do I ever need to handle every type of gesture, and if I did need to do so I could do it in SimpleOnGestureListener anyways.


Solution

  • SimpleOnGestureListener is not the same as OnGestureListener, It is a class that implements three interfaces including OnGestureListener and the main reason is to avoid too much code. And as you said you can just not use OnGestureListener at all, but it could not be eliminated from the framework because SimpleOnGestureListener implements it. see this https://developer.android.com/reference/android/view/GestureDetector.SimpleOnGestureListener.html

    SimpleOnGestureListener also implements: OnDoubleTapListener and OnContextClickListener

    and putting the methods in three different interfaces is to make them more understandable because they have different meaning, they don't want to make it necessary to every developer to implement unwanted methods. But as they found that they are often used together they created a sort of helper class that gather them with default implementation, this way they can keep the interfaces separated and gathered at the same time. There is no difference between using any of the two methods.