TWO_SWIPE_DOWN TAP unable to catch on Google Glass GDK (XE16)

十年热恋 提交于 2020-01-03 09:09:48

问题


In Google Glass XE16 GestureDetector can detect several gestures like LONG_PRESS, SWIPE_DOWN, THREE_LONG_PRESS, TWO_SWIPE_DOWN , TWO_TAP & SOME OTHER GESTURES.

In glass TWO_SWIPE_DOWN is like shortcut option to cancel everything and go to black screen. After that black screen it comes "ok glass".

But I need to override the TWO_SWIPE_DOWN TAP so that user can not go outside the application in this way. I want to show the user specific message in the time of tapping TWO_SWIPE_DOWN.

I have code following GDK Touch Gestures like below :

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

Above code able to catch every other tap without the TWO_SWIPE_DOWN TAP!

So how I will be able to catch the TWO_SWIPE_DOWN TAP?


回答1:


If your code is within a View/SurfaceView this is the implementation that Google provides

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

That will give you full control of your Views events.

Here is my reference from google.

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



来源:https://stackoverflow.com/questions/23218457/two-swipe-down-tap-unable-to-catch-on-google-glass-gdk-xe16

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!