6

W Google Glass XE16 GestureDetector może wykryć kilka gestów jak LONG_PRESS, SWIPE_DOWN, THREE_LONG_PRESS, TWO_SWIPE_DOWN, TWO_TAP & SOME OTHER GESTURES.TWO_SWIPE_DOWN TAP stanie złapać na Google Glass GDK (XE16)

W szkle TWO_WWIPE_DOWN jest jak opcja skrótu, aby anulować wszystko i przejść do czarnego ekranu. Po tym czarnym ekranie pojawia się "szkło ok".

Ale muszę zastąpić TWO_WWIPE_DOWN TAP, aby użytkownik nie mógł wyjść poza aplikację w ten sposób. Chcę wyświetlić komunikat użytkownika w momencie dotknięcia TWO_SWIPE_DOWN.

Mam następujący kod GDK Touch Gestures jak poniżej:

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

powyższy kod w stanie złapać każdy inny kran bez TAP TWO_SWIPE_DOWN!

Jak mogę złapać TWO_SWIPE_DOWN TAP?

+0

Wydaje się ten problem nadal nie został rozwiązany. Nie mogę wykryć gestu TWO_SWIPE_DOWN. Czy w końcu znalazłeś jakieś rozwiązanie? – rottenoats

Odpowiedz

0

Jeśli kod jest wewnątrz view/SurfaceView to realizacja że Google zapewnia

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

który daje pełną kontrolę nad swoimi poglądami wydarzeń.

Oto moje odniesienie z google.

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

+0

Chcę dodać, że dla Glass instrukcje importu różnią się od normalnych. Normalnie możesz zaimportować 'android.gesture.Gesture 'i tym podobne, ale dla klasy musisz zaimportować wszystko, czego potrzebujesz z' com.google.android.glass.touchpad' w przeciwnym razie dostaniesz różnego rodzaju niejasne błędy. Wspaniale, że Google nie wymienia takich bzdur jak GDZIEKOLWIEK w swoich dokumentach dotykowych. – SMT

Powiązane problemy