blob: 96ce475edf093129c19ed72aff4989bd57131680 [file] [log] [blame]
Takeshi Hagikuraa819ef72014-09-25 16:23:49 +09001<?xml version="1.0" encoding="UTF-8"?>
2<!--
3 Copyright 2013 The Android Open Source Project
4
5 Licensed under the Apache License, Version 2.0 (the "License");
6 you may not use this file except in compliance with the License.
7 You may obtain a copy of the License at
8
9 http://www.apache.org/licenses/LICENSE-2.0
10
11 Unless required by applicable law or agreed to in writing, software
12 distributed under the License is distributed on an "AS IS" BASIS,
13 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 See the License for the specific language governing permissions and
15 limitations under the License.
16-->
17
18
19
20<sample>
21 <name>JumpingJack</name>
Takeshi Hagikuraf4570542014-09-26 13:20:42 +090022 <group>Wearable</group>
Takeshi Hagikuradff38662014-10-31 15:52:04 +090023 <package>com.example.android.wearable.jumpingjack</package>
Takeshi Hagikuraa819ef72014-09-25 16:23:49 +090024
Trevor Johns3ba022b2014-11-06 22:45:31 +000025 <minSdk>18</minSdk>
Takeshi Hagikuraa819ef72014-09-25 16:23:49 +090026
Takeshi Hagikuraa819ef72014-09-25 16:23:49 +090027 <strings>
28 <intro>
29 <![CDATA[
30 Uses the Gravity sensor to count how many jumping jacks you have performed.
31 ]]>
32 </intro>
33 </strings>
34
anaddafa9d5d9d2015-03-10 11:04:09 -070035 <template src="base-build"/>
Takeshi Hagikuraa819ef72014-09-25 16:23:49 +090036 <template src="Wear"/>
Trevor Johns678f4f32014-11-06 05:37:45 +000037 <common src="logger"/>
38 <common src="activities"/>
Takeshi Hagikuraa819ef72014-09-25 16:23:49 +090039
Takeshi Hagikura3ba33cc2014-12-09 14:49:34 +090040 <metadata>
41 <status>PUBLISHED</status>
42 <categories>Wearable</categories>
43 <technologies>Android</technologies>
44 <languages>Java</languages>
45 <solutions>Mobile</solutions>
46 <level>INTERMEDIATE</level>
47 <icon>screenshots/web-icon.png</icon>
48 <screenshots>
49 <img>screenshots/jumping_jack.gif</img>
50 </screenshots>
51 <api_refs>
52 <android>android.hardware.SensorEvent</android>
53 <android>android.hardware.SensorEventManager</android>
54 </api_refs>
55
56 <description>
57<![CDATA[
58A basic sample showing how to use the Gravity sensor on the wearable device
59by counting how many jumping jacks you have performed.
60]]>
61 </description>
62
63 <intro>
64<![CDATA[
65[SensorEventListener][1] offers you methods used for receiving notifications from the
66[SensorManager][2] when sensor values have changed.
67
68This example counts how many times Jumping Jakcs are performed by detecting the value
69of the Gravity sensor by the following code:
70
71```java
72@Override
73public void onSensorChanged(SensorEvent event) {
74 detectJump(event.values[0], event.timestamp);
75}
76
77private void detectJump(float xValue, long timestamp) {
78 if ((Math.abs(xValue) > GRAVITY_THRESHOLD)) {
79 if(timestamp - mLastTime < TIME_THRESHOLD_NS && mUp != (xValue > 0)) {
80 onJumpDetected(!mUp);
81 }
82 mUp = xValue > 0;
83 mLastTime = timestamp;
84 }
85}
86```
87
88The detectJump method above assumes that when a person is wearing the watch, the x-component of gravity
89as measured by the Gravity Sensor is +9.8 when the hand is downward and -9.8 when the hand
90is upward (signs are reversed if the watch is worn on the right hand). Since the upward or
91downward may not be completely accurate, we leave some room and instead of 9.8, we use
92GRAVITY_THRESHOLD (7.0f). We also consider the up <-> down movement successful if it takes less than
93TIME_THRESHOLD_NS (2000000000 nanoseconds).
94
95[1]: http://developer.android.com/reference/android/hardware/SensorEventListener.html
96[2]: http://developer.android.com/reference/android/hardware/SensorManager.html
97]]>
98 </intro>
99 </metadata>
Takeshi Hagikuraa819ef72014-09-25 16:23:49 +0900100</sample>