User-defined Gestures

Draw one of the Greek lowercase letters α, β, γ, δ with your finger and the app will recognize it. Shown above is an α (alpha); draw it starting with the upper right end. R.raw.gestures is the id number of the file named gestures I created with the Gestures Builder app. The file contains four gestures, named alpha, beta, gamma, delta.

Class ArrayList is a Java generic because it has <angle brackets>. In C++, we would have called it a template. An ArrayList can grow, but a Java array cannot. See ListView for the interface List that ArrayList implements.

Source code in Gesture.zip

  1. MainActivity.java
  2. activity_main.xml
  3. gestures (not humanly readable)
  4. AndroidManifest.xml
  5. build.gradle (Module: app)

Run the Gestures Builder app

The Gestures Builder app is present on the Android Nexus 5 emulator and the Genymotion Samsung Galaxy S5 emulator. But you can make the gestures more smoothly with your finger rather than with a mouse, so you should run Gestures Builder on an Android device. If your device does not have the Gestures Builder app, you can create it by following the “Import Project” directions as we did for ApiDemos, but select
~/Library/Android/sdk/samples/android-22/legacy/GestureBuilder
instead of
~/Library/Android/sdk/samples/android-22/legacy/ApiDemos.

Launch the Gestures Builder app in the emulator that has the SD card.
No gestures
Press “Add gesture”, type the name of your gesture (e.g., alpha), perform the gesture (it will outline in yellow), and press Done.
Gesture saved in /storage/emulated/0/gestures
Add several more gestures and then press the Android home button.

Look at the /storage/emulated/0/gestures file

adb -d shell

find / -type f -name gestures
cd /storage/emulated/0
pwd

ls -l gestures
-rw-rw---- root     sdcard_r     3489 2015-07-24 23:26 gestures

exit

Another way to see the files in the device or emulator is go to Android Studio and pull down
Tools → Android → Android Device Monitor
Select the device and click on the File Explorer tab.

Copy the gestures file to your Mac or PC

The pull command copies a file from the emulator to your Mac or PC.

cd ~/Desktop
adb -d pull /storage/emulated/0/gestures
1695 KB/s (3489 bytes in 0.002s)
ls -l gestures
-rw-r--r--  1 myname  mygroup  3489 Jul 24 23:37 gestures
file gestures
gestures: TrueType font data

Create the app/res/raw folder

In the Android Studio project view, select the app/res folder and pull down
File → New → Folder → Assets Folder
☑ Change Folder Location
New Folder Location: src/main/assets/raw
Finish

Add the gestures file to your project

Control-click the gestures file on your Desktop and select “Copy gestures”. Control-click on your new raw folder in the Android Studio project view and select Paste.
OK

Things to try

  1. Can you use a GestureOverlayView.OnGestureListener to detect the start or end of a gesture?