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

1

6

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?

Viyella answered 22/4, 2014 at 11:40 Comment(1)
It seems this problem still has not been fixed. I am unable to detect the TWO_SWIPE_DOWN gesture. Did you eventually find a fix to this?Galvanometer
K
0

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

Knavery answered 23/4, 2014 at 17:20 Comment(1)
I want to add that for Glass the import statements are different than normal. Normally you can import android.gesture.Gesture and the like but for class you need to import whatever you need from com.google.android.glass.touchpad otherwise you'll get all sorts of vague errors thrown. Great thing Google doesn't list crap like that ANYWHERE on their touch docs.Rasputin

© 2022 - 2024 — McMap. All rights reserved.