TWO_SWIPE_DOWN TAP无法捕获Google Glass GDK(XE16)

时间:2014-04-22 11:40:48

标签: android google-glass android-4.4-kitkat gesture-recognition gestures

在Google Glass XE16 GestureDetector中可以检测到多种手势,例如LONG_PRESS,SWIPE_DOWN,THREE_LONG_PRESS,TWO_SWIPE_DOWN,TWO_TAP& SOME OTHER GESTURES

在玻璃杯中,TWO_SWIPE_DOWN就像取消所有内容并进入黑屏一样的快捷方式选项。在那个黑屏之后,它来了" ok glass"

但是我需要覆盖TWO_SWIPE_DOWN TAP,这样用户就不能以这种方式离开应用程序。我想在点击TWO_SWIPE_DOWN时显示用户特定的消息。

我的代码如下GDK Touch Gestures所示:

    gestureDetector.setBaseListener(new GestureDetector.BaseListener() {
        @Override
        public boolean onGesture(Gesture gesture) {
            if (gesture == Gesture.TAP) {
                return true;
            } else if (gesture == Gesture.TWO_TAP) {
                return true;
            } else if (gesture == Gesture.SWIPE_RIGHT) {
                return true;
            } else if (gesture == Gesture.SWIPE_LEFT) {
                return true;
            } else if (gesture == Gesture.TWO_SWIPE_DOWN) {
                Log.i("Checking the TAPPING of TWO_SWIPE_DOWN", "Its working fine.");
                return true;
            }
            return true;
        }
    });

以上代码能够在没有TWO_SWIPE_DOWN TAP的情况下捕获每个其他分区!

那么我将如何能够捕获TWO_SWIPE_DOWN TAP?

1 个答案:

答案 0 :(得分:0)

如果您的代码位于View / SurfaceView中,则这是Google提供的实施

    /**
    * TextView that handles touchpad input (currently only TAP).
    */
    public class TouchpadHandlingTextView extends TextView
        implements OnAttachStateChangeListener{

    private final GestureDetector mTouchDetector;

    public TouchpadHandlingTextView(Context context, AttributeSet attrs) {
        super(context, attrs);
        mTouchDetector = createGestureDetector(context);
        // must set the view to be focusable
        setFocusable(true);
        setFocusableInTouchMode(true);
    }

    public TouchpadHandlingTextView(Context context) {
        this(context, null);
    }

    @Override
    public void onViewAttachedToWindow(View v) {
        requestFocus();
    }

    @Override
    public void onViewDetachedFromWindow(View v) {
    }

    /**
     * Pass a MotionEvent into the gesture detector
     */
    @Override
    public boolean dispatchGenericFocusedEvent(MotionEvent event) {
        if (isFocused()) {
            return mTouchDetector.onMotionEvent(event);
        }
        return super.dispatchGenericFocusedEvent(event);
    }

    /**
     * Create gesture detector that triggers onClickListener. Implement
     * onClickListener in your Activity and override
     * onClick() to handle the "tap" gesture.
     */
    private GestureDetector createGestureDetector(Context context) {
        GestureDetector gd = new GestureDetector(context);
        gd.setBaseListener(new GestureDetector.BaseListener() {

            @Override
            public boolean onGesture(Gesture gesture) {
                if (gesture == Gesture.TAP) {
                    return performClick();
                }
                if(gesture == Gesture.SWIPE_DOWN){
                    //Do something instead of close app
                return true;
                }
            }
        });
        return gd;
    }
}

这将使您完全控制您的观看事件。

以下是谷歌的参考资料。

https://developers.google.com/glass/develop/gdk/touch