Changes

Jump to: navigation, search
no edit summary
Before the Gesture Builder app can be used to design gestures on an emulator, the virtual device needs to be configured with a virtual SD Card onto which the gestures file will be saved (this is not necessary when using a physical Android device).
For the purposes of this example, the AVD created in the chapter entitled Creating an Android Virtual Device (AVD) in Android Studio will be modified to add SD Card support using the AVD Manager. This can be launched from within an existing project main window via the Tools -> Android -> AVD Manager menu option or from the welcome screen by selecting Configure –> AVD Manager from the Quick Start menu. Within the resulting Android Virtual Device Manager screen, select an AVD (in this case the Nexus7 emulator) and click on the Edit… button to display the editing dialog as illustrated in Figure 2123-1.
Within the configuration dialog, enter a value of 10 MiB into the Size field of the SD Card section of the dialog, and then click on the OK button to commit the changes. The AVD now has virtual SD Card storage available to store the gestures file.
[[Image:android_studio_add_sd_Card_to_avd.png|Adding SD Card support to an avd configuration in Android Studio]]
Figure 2123-1
== Creating a Gestures File ==
Once the Gesture Builder application has loaded, it should indicate that no gestures have yet been created. To create a new gesture, click on the Add gesture button located at the bottom of the device screen, enter the name Circle Gesture into the Name text box and then “draw” a gesture using a circular motion on the screen as illustrated in Figure 2123-2. Assuming that the gesture appears as required (represented by the yellow line on the device screen), click on the Done button to add the gesture to the gestures file:
[[Image:android_studio_circle_gesture.png|Drawing a gesture in the Android Gesture Builder app]]
Figure 2123-2
After the gesture has been saved, the Gesture Builder app will display a list of currently defined gestures, which, at this point, will consist solely of the new Circle Gesture.
Repeat the gesture creation process to add a further gesture to the file. This should involve a two-stroke gesture creating an X on the screen named X Gesture. When creating gestures involving multiple strokes, be sure to allow as little time as possible between each stroke so that the builder knows that the strokes are part of the same gesture. Once this gesture has been added, the list within the Gesture Builder application should resemble that outlined in Figure 2123-3:
[[Image:android_studio_gesturesbuilder.png|The list of gestures in the Android Gesture Builder app]]
Figure 2123-3
== Extracting the Gestures File from the SD Card ==
This example application calls for a very simple user interface consisting of a LinearLayout view with a GestureOverlayView layered on top of it to intercept any gestures performed by the user. Locate the CustomGestures -> app -> src -> main -> res -> layout -> activity_custom_gestures.xml file and double click on it to load it into the Designer tool.
By default, Android Studio has provided a RelativeLayout component as the root element of the user interface layout so this will need to be deleted and replaced with a LinearLayout. Locate the RelativeLayout instance in the Component Tree, right click on it and select the Delete option from the popup menu (Figure 2123-4).
[[image:android_studio_delete_relative_layout.png|Deleting a view from the Android Studio Component Tree panel]]
Figure 2123-4

Navigation menu