android – 如何使用本机应用程序在google玻璃上捕获onSwipeDown事件?

前端之家收集整理的这篇文章主要介绍了android – 如何使用本机应用程序在google玻璃上捕获onSwipeDown事件?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我能够使用本机应用程序中的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;
}

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

我发现手势处理的两个不同来源我试过:

> Capture Glass D-Pad events in Android
> Capturing Gesture Controls for Use in Native Android Glass Apps

但是,没有一个我能够抓住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;
}

我认为你不需要关心onKeyDown()回调,因为这个回调只是在onKeyUp()事件之前直接触发,而不是当你开始手势时.

原文链接:https://www.f2er.com/android/313461.html

猜你在找的Android相关文章