gpt4 book ai didi

google-glass - 谷歌眼镜 GDK 点击手势

转载 作者:行者123 更新时间:2023-12-04 20:44:35 24 4
gpt4 key购买 nike

使用 GDK 和 Google 提供的示例代码,TAP 手势不会被识别为 TAP。每次都作为 LONG_PRESS 返回。下面是代码:

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;
}

}

我在这里遗漏了什么还是这是一个错误?

最佳答案

如果您只想捕获 UI 的点击事件(不使用 GestureDetector 和所有内容),在 Glass 触摸板中,点击被注册为中心点击 d-pad,因此您可以简单地拦截 KEYCODE_DPAD_CENTER 按键。

尝试这个:

public boolean onKeyDown(int keyCode, KeyEvent event) {
if(keyCode == KeyEvent.KEYCODE_DPAD_CENTER){
// The touchpad was tapped
return true;
}

return false;
}

关于google-glass - 谷歌眼镜 GDK 点击手势,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20151745/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com