Changes

Jump to: navigation, search
no edit summary
<table border="0" cellspacing="0" width="100%">
<tr>
<td width="20%">[[Detecting Common Gestures using the Android Gesture Detector Class|Previous]]<td align="center">[[Kindle Fire Android 4 App Development Essentials|Table of Contents]]<td width="20%" align="right">[[An Introduction to Android Fragments|Next]]</td>
<tr>
<td width="20%">Detecting Common Gestures using the Android Gesture Detector Class<td align="center"><td width="20%" align="right">An Introduction to Android Fragments</td>
<google>BUY_KINDLE_FIREBUY_ANDROID</google>
== Adding SD Card Support to an AVD ==
Before the Gestures 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 Kindle Fire Android device).
For the purposes of this example, the Kindle Fire AVD created in the chapter entitled [[Creating a Kindle Fire an Android Virtual Device (AVD) ]] will be modified to add SD Card support. Within the Eclipse environment, therefore, select the Window -> AVD Manager menu option. Within the resulting Android Virtual Device Manager screen, select an AVD (in this case the Kindle Fire Nexus7 emulator) and click on the Edit button to display the editing dialog as illustrated in Figure 1920-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_avd_add_sdcard.png|Adding an SD Card to an Android AVD]]
Figure 1920-1
== Building and Running the Gesture Builder Application ==
The Gesture Builder application is not bundled by default with the Kindle Fire AVD emulator profile, nor is it pre-installed on physical Kindle Fire Android devices. It is, however, included amongst the SDK samples and consequently may be compiled and run on any Kindle Fire Android device or emulator.
Within the Eclipse environment, select the Window -> Android SDK Manager menu option. Once the manager has loaded, locate the Samples for SDK package located beneath the Android 4.02.3 2 (API15API17) section. If the package is not already installed, set the checkbox next to the package and click on the Install 1 Package button to initiate the installation.
Once the installation is complete, the SDK samples will be installed in the following directory (where <path_to_adt_installation> represents the location on your system where the ADT bundle was originally installed):
<pre>
<path_to_adt_installation>/sdk/samples/android-1517
</pre>
Returning to the Eclipse window, select the File -> Import… menu option and, within the resulting dialog, select Android -> Existing Android Code into Workspace before clicking Next. Click on the Browse button next to the Root Directory text box, navigate to and select the GestureBuilder folder within the SDK samples directory and click on Finish.
Once imported, the code for the Gesture Builder application will appear in the Package Explorer panel as GestureBuilderActivity. Right-click on the GestureBuilderActivity project and use the menu to install and run it on a Kindle Fire device or emulator session attached to the development system.
== Creating a Gestures File ==
Once the Gesture Builder activity 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” using a circular motion on the screen as illustrated in Figure 19 20-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_gestures_builder_new_gesture2.png|Creating an Android Gesture]]
Figure 1920-2
After the gesture has been saved, the gestures builder 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 Gestures Builder application should resemble that outlined in Figure 1920-3:
[[Image:android_gestures_builder_list.png|New gestures created using the Android Gestures Builder application]]
Figure 1920-3
== Extracting the Gestures File from the SD Card ==
</pre>
In the event that the adb command is not found, refer to [[Setting up a Kindle Fire an Android Development Environment ]] for guidance on adding this to the PATH environment of your system.
Once executed, the command will list all active physical devices and AVD instances attached to the system. The following output, for example, indicates that a physical device and one AVD emulator are present on the system:
== Testing the Application ==
Build and run the application on either an emulator or a physical Kindle Fire Android device and perform the circle and swipe gestures on the display. When performed, the toast notification should appear containing the name of the gesture that was performed. Note, however, that when attempting to perform the X Gesture that the gesture is not recognized. Also, note that when a gesture is recognized, it is outlined on the display with a bright yellow line whilst gestures about which the overlay is uncertain appear as a faded yellow line. Whilst useful during development, this is probably not ideal for a real world application. Clearly, therefore, there is still some more configuration work to do.
== Configuring the GestureOverlayView ==
Within the onCreate() method, a reference to the text view object is obtained and assigned to the scaleText variable. Next, a new ScaleGestureDetector instance is created, passing through a reference to the enclosing activity and an instance of our new MyOnScaleGestureListener class as arguments. Finally, an onTouchEvent() callback method is implemented for the activity, which simply calls the corresponding onTouchEvent() method of the ScaleGestureDetector object, passing through the MotionEvent object as an argument.
Compile and run the application on a physical Kindle Fire Android device and perform pinching gestures on the screen, noting that the text view displays either the zoom in or zoom out message depending on the pinching motion.
== Summary ==
<google>BUY_KINDLE_FIREBUY_ANDROID</google>
<table border="0" cellspacing="0" width="100%">
<tr>
<td width="20%">[[Detecting Common Gestures using the Android Gesture Detector Class|Previous]]<td align="center">[[Kindle Fire Android 4 App Development Essentials|Table of Contents]]<td width="20%" align="right">[[An Introduction to Android Fragments|Next]]</td>
<tr>
<td width="20%">Detecting Common Gestures using the Android Gesture Detector Class<td align="center"><td width="20%" align="right">An Introduction to Android Fragments</td>
</table>

Navigation menu