Google Glass gdk-gesture operation

Source: Internet
Author: User

It is found that the onkeydown event does not work when multiple cards or other things are used, so the gdk gesture operation is clarified and a note record is written ~

First, create a card and gesture detector.

1 // create Card 2 private card mcard; 3 // gesture detector 4 private gesturedetector mgesturedetector;

Then initialize our variables in the oncreate method.

1 protected void oncreate (bundle savedinstancestate) {2 super. oncreate (savedinstancestate); 3 // setcontentview (R. layout. activity_main); 4 mcard = new card (this); 5 mgesturedetector = creategesturedetector (this); 6 mcard. settext ("gesture recognition"); 7 setcontentview (mcard. getview (); 8}
Creategesturedetector is a new function used to instantiate the gesture detector and bind events.
1 private gesturedetector creategesturedetector (context) {2 gesturedetector = new gesturedetector (context); 3 // 4 // basic key event 5/6 gesturedetector. setbaselistener (New gesturedetector. baselistener () {7 @ override 8 Public Boolean ongesture (gesture arg0) {9 // todo auto-generated method stub10 // Pat 11 if (arg0 = gesture. tap) {12 mcard. settext ("one finger PAT => play | pause"); 13} else if (arg0 = gesture. two_tap) {14 // two-finger pat 15 mcard. settext ("two-finger PAT => pop-up menu"); 16} else if (arg0 = gesture. long_press) {17 // long press 18 mcard. settext ("Long press => exit"); 19} else if (arg0 = gesture. swipe_left) {20 mcard. settext ("Backward => previous"); 21} else if (arg0 = gesture. swipe_right) {22 mcard. settext ("Forward => next"); 23} else if (arg0 = gesture. swipe_down) {24 mcard. settext ("down => running in the background"); 25} else {26 return false; 27} 28 setcontentview (mcard. getview (); 29 return true; 30} 31}); 32 // 33 // listener index 34 // 35 gesturedetector. setfingerlistener (New gesturedetector. fingerlistener () {36 37 @ override38 public void onfingercountchanged (INT arg0, int arg1) {39 // todo auto-generated method stub40 system. out. println ("Finger: original =" + arg0 + "Current:" + arg1); 41} 42}); 43 // 44 // rolling event 45 // 46 gesturedetector. setscrolllistener (New gesturedetector. scrolllistener () {47 48 @ override49 public Boolean onscroll (float arg0, float arg1, float arg2) {50 // todo auto-generated method stub51 system. out. println ("scroll: arg0 =" + arg0 + "arg1 =" + arg1 + "arg2 =" + arg2); 52 return false; 53} 54}); 55 return gesturedetector; 56}

Finally, we want to send the event to the gesture detector.

1     @Override2     public boolean onGenericMotionEvent(MotionEvent event){3         if(mGestureDetector != null){4             return mGestureDetector.onMotionEvent(event);5         }6         return false;7     }

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.