FMX.GoogleGlass Sample
This is a sample project with Google Glass, although it will also run with similar functionality on most Android devices.
Contents
Location
You can find the GoogleGlass sample project at:
- Start | Programs | Embarcadero RAD Studio Rio | Samples and navigate to:
Object Pascal\Multi-Device Samples\Google Glass\GlassLevel
CPP\Multi-Device Samples\Google Glass
- Subversion Repository:
- You can find Delphi and C++ code samples in GitHub Repositories. Search by name into the samples repositories according to your RAD Studio version.
Description
This application uses the Google Glass style, uses the WakeLock to keep an Android device awake, and launches the app with voice on Google Glass.
Move your head (while wearing Google Glass) to provide input to this app. As you tip your head from left to right, you see the line also tips. As your lean your head forward and backward, you see the line also moves up and down. The lower corners display the value of the lines' movement.
How to Use the Sample
- Navigate to the one of the locations given above, and open:
- Delphi: GlassLevel.dproj
- C++: GlassLevelCpp.cbproj
- Press F9 or choose Run > Run.
- Build GlassLevel.dproj.
- Run the application by selecting the Run > Run menu from within the IDE, or by pressing F9.
- Launch it again from Google Glass by going to the Home Screen and saying "OK Glass, Am I Level?" or selecting the "Am I Level" from the app list.
Voice Launch
The voice trigger is added in multiple steps. In the AndroidManifest.template.xml file the following lines were added:
A special permission is required to use a non standard voice trigger command. In the Manifest, right below the <%uses-permission%> line you need to add the following special permission:
<uses-permission android:name="com.google.android.glass.permission.DEVELOPMENT" />
Inside the <intent-filter> element
<action android:name="com.google.android.glass.action.VOICE_TRIGGER" />
Inside the <activity> element
<meta-data
android:name="com.google.android.glass.VoiceTrigger"
android:resource="@xml/voice_trigger_start" />
The @xml/voice_trigger_start is a reference to the voice_trigger_start.xml file, which is also included in the project.
It is a standard XML file with the element:
<trigger keyword="Am I level?" />
Where "Am I level?" is the voice trigger keyword.
The voice_trigger_start.xml also requires deployment to the res\xml folder. This is specified under the Project > Deployment screen for the Android platform.
For more information on the Google Glass Voice Trigger, check out the GDK documentation.
Files
File | Contains |
---|---|
Androidapi.JNI.PowerManager.pas |
The JNI Interface for the PoweManager, WakeLock classes and a few helper methods to acquire a WakeLock. |
AndroidManifest.template.xml |
Edited lines to add the voice trigger in order to launch an app with voice on Google Glass. |
GlassLevel.dproj |
The project itself. |
uGlassLevel.pas/fmx |
The main form and code to display the level. |
voice_trigger_start.xml |
Contains the voice trigger keyword to launch the app. |
README.txt |
Further information about this sample. |
Implementation
- To provide smooth animation of level movement, TFloatAnimation is used.
- To obtain acceleration information for the movement of the level, TMotionSensor is used.
- To enable and disable the wake lock at the right time, TPlatformServices.Current.SupportsPlatformService is used.
- JPowerManager and JWakeLock keep the device awake (Androidapi.JNI.PowerManager.pas file).
- To obtain WakeLock Uses Permission go to Project > Options menu from within the IDE, then to Uses Permissions.
Uses
- IFMXApplicationEventService
- SupportsPlatformService
- TApplicationEvent
- TFloatAnimation
- TMotionSensor
- TStyleBook
- TTimer