【问题标题】:TWO_SWIPE_DOWN TAP unable to catch on Google Glass GDK (XE16)TWO_SWIPE_DOWN TAP 无法捕捉 Google Glass GDK (XE16)
【发布时间】:2014-06-06 18:15:39
【问题描述】:

在 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?

【问题讨论】:

  • 看来这个问题还没有解决。我无法检测到 TWO_SWIPE_DOWN 手势。您最终找到解决方法了吗?

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


【解决方案1】:

如果您的代码在 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;
    }
}

这将使您可以完全控制您的 Views 事件。

这是我从谷歌得到的参考。

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

【讨论】:

  • 我想补充一点,对于 Glass,导入语句与正常情况不同。通常你可以导入android.gesture.Gesture 等,但是对于类你需要从com.google.android.glass.touchpad 导入你需要的任何东西,否则你会得到各种各样的模糊错误。很棒的是,Google 不会在其触控文档中的任何地方列出这样的废话。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-12-28
相关资源
最近更新 更多