Ale*_*lex 10 android android-gesture google-glass
我能够使用原生应用中的SimpleOnGestureListener捕获谷歌眼镜触摸板触发的大部分事件.
使用以下代码,您可以捕获这些事件
MainActivity.java:
private GestureDetector gestureDetector;
@Override
protected void onCreate(Bundle savedInstanceState)
{
gestureDetector = new GestureDetector(this, new MyGestureListener());
}
@Override
public boolean onGenericMotionEvent(MotionEvent event)
{
gestureDetector.onTouchEvent(event);
return true;
}
Run Code Online (Sandbox Code Playgroud)
MyGestureListener:
public class MyGestureListener extends android.view.GestureDetector.SimpleOnGestureListener
{
@Override
public boolean onFling(MotionEvent start, MotionEvent finish, float velocityX, float velocityY)
{
// check for velocity direction to identify swipe forward / backward / up and down
return true;
}
}
Run Code Online (Sandbox Code Playgroud)
我找到了两个不同的手势处理源:
但是没有一个我能够捕获swipeDown事件.
回调onFling()仅在"向前滑动","向后滑动"和"向上滑动"时调用,但在"向下滑动"时从不调用.
任何提示或你已经设法抓住了向下滑动?我在这里真的很无能为力.
这是(奇怪的)解决方案.
似乎swipeDown手势实际上并不是一个手势,而是一个按钮点击.
这意味着您应该使用活动的回调方法来捕获这些事件.
private static final int KEY_SWIPE_DOWN = 4;
@Override
public boolean onKeyUp(int keyCode, KeyEvent event)
{
if (keyCode == KEY_SWIPE_DOWN)
{
// there was a swipe down event
return true;
}
return false;
}
Run Code Online (Sandbox Code Playgroud)
我认为您不需要关心onKeyDown()回调,因为此回调仅在onKeyUp()事件之前直接触发,而不是在您开始手势时触发.
| 归档时间: |
|
| 查看次数: |
1993 次 |
| 最近记录: |