I want to implement the gesturedetector to set baselistener for my Google Glass. Android studio gave me an error saying the symbol touchpad
cannot be found. I have already imported the relevant libraries.
setBaseListener
continues to give an error.
private GestureDetector createGestureDetector(Context context, GestureDetector.OnGestureListener listener) {
GestureDetector gestureDetector = new GestureDetector(context, listener);
//Create a base listener for generic gestures
gestureDetector.setBaseListener(new GestureDetector.BaseListener() {
@Override
public boolean onGesture(Gesture gesture) {
if (gesture == Gesture.TAP) {
// do something on tap
return true;
} else if (gesture == Gesture.TWO_TAP) {
// do something on two finger tap
return true;
} else if (gesture == Gesture.SWIPE_RIGHT) {
// do something on right (forward) swipe
return true;
} else if (gesture == Gesture.SWIPE_LEFT) {
// do something on left (backwards) swipe
return true;
}
return false;
}
});
Your code formatting is a bit off, but it seems you are initializing "gestureDetector" as
GestureDetector.OnGestureListener listener) { GestureDetector gestureDetector = new GestureDetector(context, listener);
However, according to the Glass GDK docs at https://developers.google.com/glass/develop/gdk/reference/com/google/android/glass/touchpad/GestureDetector
I see only a single constructor: public GestureDetector (Context context)
Depending on where you are constructing this, could you try
GestureDetector gestureDetector = new GestureDetector(context);
or
GestureDetector gestureDetector = new GestureDetector(this);
with the following imports:
import com.google.android.glass.touchpad.Gesture;
import com.google.android.glass.touchpad.GestureDetector;