Radio Inspire

How To Learn Sign Language

[Tutorial] The Basics of Gesture SDK


The Gesture SDK enables you to use motion to interact with your device. Hi! I’m Vincent. And we hope you enjoyed our previous episodes. In this tutorial, we will learn the basics of the gesture SDK and then create a sample application that recognizes hand gestures. The Gesture SDK was developed to augment touch or motion events. It enables users to utilize events that are generated by hand movements in front of the gesture sensor on the upper right corner of Samsung smart device. Some of the uses of the Gesture SDK includes answering incoming calls, navigating through the pages of e-books, activating voice commands, and other variants of launching application responses based on hand movement. To develop for the Gesture SDK, we will need the following. First, we’ll need an Eclipse with ADT plug-in. Jellybean (API level 18) is the minimum requirement to use the Gesture SDK. Second, we are required to have these jar files as well. These can be found in the Mobile SDK 1.5 archive file. And lastly, prepare a Samsung device that has Android 4.3 or higher. Also check whether your Samsung smart device has a gesture sensor. Due to hardware issues, Gesture cannot be used with the Galaxy S4. For this example, we will go ahead and use the Galaxy S5. Before we create our sample application, let’s take a look at the architecture and classes of the Gesture SDK. The architecture consists of 3 layers. The applications layer which refers to one or more applications that make use of Gesture. The second layer is the Samsung API that contains Gesture and SContext. Gesture is the main component that recognizes hand gestures. As for SContext, these are gesture components that provide Motion with gesture events. And lastly, at the very bottom we have the Android API. Let’s go ahead and talk about two main classes for the Gesture SDK. The first class is the SGesture this is the entry class that provides access to the Gesture package. This class provides methods for initializing the Gesture package and for checking whether the Gesture feature is supported. To initialize SGesture, we can refer to the code displayed on the screen. You can make use of the IllegalArgumentException to resolve issues that pertain to null listeners or invalid types. For example, this may eventually correspond to the start and isFeatureEnabled methods. For SsdkUnsupportedException, the important exception messages to handle are VENDOR_NOT_SUPPORTED for non-Samsung devices and DEVICE_NOT_SUPPORTED for devices which do not support Gesture. Other exception messages indicate whether installation or an update is recommended or required. The SgestureHand class provides the hand movement recognition functionality. It uses a gesture sensor placed in the top right side of the device. When you move your hand above the device, you can get the movement details (timestamp, direction, and angle) in your application. Take note that the hand movement is only captured when the screen is on. This class contains 2 nested classes, SgestureHand.ChangeListener which is an interface that receives hand gesture events and SgestureHand.Info which is a class that contains the hand gesture event information and provides methods to access it. Essentially, the SgestureHand class recognizes hand movements using device sensors. Now that we are familiar with the classes that we need, let’s start creating our application. Let’s name our application SimpleGesture. Set the minimum and target SDK to API 18 then proceed. Select Blank Activity. Then import the jar files in the library folder. And include the WRITE_USE_APP_FEATURE_SURVEY manifest permission. If you’re creating this application for Android 4.3, it’s okay to leave out this manifest However, for Android 4.4.2 (KitKat) and above a SecurityException is thrown and your application won’t work properly if you do not include this. Moving on, I updated my ADT that’s why the layout contains an auto-generated fragment. Let’s separate that to another class. It’d call it MainActivityView.java. Now edit the fragment_main.xml. Instead of hello world displayed on the textview, we’ll put the degrees information here. This will contain the angle information of the gestures performed. Add another textview. This will reflect the direction of the performed gesture. Add the following string responses inside strings.xml. Before we begin, let’s create a class and name it Gesturehand. This is where we will initialize SgestureHand. Let’s add the following variables. On the constructor, let’s instantiate the SgestureHand. Let’s create four methods namely: setListener, start, stop, and getDirection. On the setListener, let’s simply set the listener. On the start method, let’s simply call the start of our Sgesture object. On the stop method, let’s call the stop method of the SgestureHand. And finally, the getDirection. This will simply take the angle of the gesture and will calculate its direction. Open the MainActivity.java. Then let’s declare the things we need. Inside the onCreate method we initialize the mGesture and mGestureHand classes like so. As you can see, we have an error for changeListener because we haven’t added it yet. We can simply call the changeListener. But before that, let me tell you more about the HAND_PRIMITIVE type. The HAND_PRIMITIVE gesture type helps recognize hand gestures and return gesture data. When the user moves the hand above the gesture sensor, you can get the hand gesture details. Use the SgestureHand.Info.getAngle() method to get the angle of the hand at the end point of the gesture. The image displayed indicates how gesture recognizes angles. Going back to our code, we add the changeListener. By calling the ChangeListener and overriding the onChanged method inside it, we are telling our application that every time someone performs a hand gesture stroke we get the angle and indicate the direction by updating the textview in our layout. Let’s override the onStart method and check if the gesture functionality is supported. If it is, let’s change the message displayed to the user as “supported”. Then override the onDestroy method and call. It’s best that we call this method when we aren’t using the mGestureHand class. And we’re done. The sample application is included in this blog post. For those viewing directly from Youtube, you can go to developer.samsung.com and check out the tutorial entries. Let’s go ahead and test our application. Open the application. Gestures are recognized only when the screen is active. Now, let’s perform any gesture we like. As we can see, the textviews are updated with the respective labels for angle and direction. Let’s go ahead and summarize the things we have discussed in creating the basic application that uses Gesture. Always include the necessary SDK jar files in your project. Check if the device supports the Gesture SDK. Validate if the device has motion sensor and check the OS of the device. It must be Jelly Bean API 18 or higher. Implementing this through code would be calling the SsdkUnsupportedException or isFeatureEnabled(). And lastly, don’t forget to put in the necessary manifest permissions. We hope this tutorial helped. For inquiries, please post your questions on the official forum at developer.samsung.com. Thanks for watching.

Leave a Reply

Your email address will not be published. Required fields are marked *