由Google提供的GDK和示例代碼,TAP手勢未被識別爲TAP。每次都以LONG_PRESS的形式返回。下面是代碼:Google Glass GDK Tap Gesture
import com.google.android.glass.touchpad.Gesture;
import com.google.android.glass.touchpad.GestureDetector;
public class MainActivity extends Activity {
Logger log = Logger.getLogger("MainActivity");
private GestureDetector mGestureDetector;
// ...
@Override
protected void onCreate(Bundle savedInstanceState) {
// ...
mGestureDetector = createGestureDetector(this);
}
private GestureDetector createGestureDetector(Context context) {
GestureDetector gestureDetector = new GestureDetector(context);
//Create a base listener for generic gestures
gestureDetector.setBaseListener(new GestureDetector.BaseListener() {
@Override
public boolean onGesture(Gesture gesture) {
log.info(gesture.name());
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;
}
});
gestureDetector.setFingerListener(new GestureDetector.FingerListener() {
@Override
public void onFingerCountChanged(int previousCount, int currentCount) {
// do something on finger count changes
}
});
gestureDetector.setScrollListener(new GestureDetector.ScrollListener() {
@Override
public boolean onScroll(float displacement, float delta, float velocity) {
// do something on scrolling
}
});
return gestureDetector;
}
/*
* Send generic motion events to the gesture detector
*/
@Override
public boolean onGenericMotionEvent(MotionEvent event) {
if (mGestureDetector != null) {
return mGestureDetector.onMotionEvent(event);
}
return false;
}
}
我失去了一些東西在這裏或者這是一個錯誤?
您提供的版畫「TAP」對我來說,當我在觸摸板上簡單點擊代碼。你是否說過,當你做一個快速分裂的水龍頭時,它仍然打印出「LONG_PRESS」? –
是的。儘可能快地嘗試嘗試,並且從未得到過「TAP」 – Patrick
然後,假設您在Glass的其他部分沒有出現問題。出於好奇,你可以嘗試其他手勢,看看它們是否按預期工作,比如TWO_TAP和THREE_TAP,或者一些滑動? –