Takeshi Hagikura | a819ef7 | 2014-09-25 16:23:49 +0900 | [diff] [blame] | 1 | <?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 Hagikura | f457054 | 2014-09-26 13:20:42 +0900 | [diff] [blame] | 22 | <group>Wearable</group> |
Takeshi Hagikura | dff3866 | 2014-10-31 15:52:04 +0900 | [diff] [blame] | 23 | <package>com.example.android.wearable.jumpingjack</package> |
Takeshi Hagikura | a819ef7 | 2014-09-25 16:23:49 +0900 | [diff] [blame] | 24 | |
Trevor Johns | 3ba022b | 2014-11-06 22:45:31 +0000 | [diff] [blame] | 25 | <minSdk>18</minSdk> |
Takeshi Hagikura | a819ef7 | 2014-09-25 16:23:49 +0900 | [diff] [blame] | 26 | |
Takeshi Hagikura | a819ef7 | 2014-09-25 16:23:49 +0900 | [diff] [blame] | 27 | <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 | |
anaddaf | a9d5d9d | 2015-03-10 11:04:09 -0700 | [diff] [blame] | 35 | <template src="base-build"/> |
Takeshi Hagikura | a819ef7 | 2014-09-25 16:23:49 +0900 | [diff] [blame] | 36 | <template src="Wear"/> |
Trevor Johns | 678f4f3 | 2014-11-06 05:37:45 +0000 | [diff] [blame] | 37 | <common src="logger"/> |
| 38 | <common src="activities"/> |
Takeshi Hagikura | a819ef7 | 2014-09-25 16:23:49 +0900 | [diff] [blame] | 39 | |
Takeshi Hagikura | 3ba33cc | 2014-12-09 14:49:34 +0900 | [diff] [blame] | 40 | <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[ |
| 58 | A basic sample showing how to use the Gravity sensor on the wearable device |
| 59 | by 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 | |
| 68 | This example counts how many times Jumping Jakcs are performed by detecting the value |
| 69 | of the Gravity sensor by the following code: |
| 70 | |
| 71 | ```java |
| 72 | @Override |
| 73 | public void onSensorChanged(SensorEvent event) { |
| 74 | detectJump(event.values[0], event.timestamp); |
| 75 | } |
| 76 | |
| 77 | private 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 | |
| 88 | The detectJump method above assumes that when a person is wearing the watch, the x-component of gravity |
| 89 | as measured by the Gravity Sensor is +9.8 when the hand is downward and -9.8 when the hand |
| 90 | is upward (signs are reversed if the watch is worn on the right hand). Since the upward or |
| 91 | downward may not be completely accurate, we leave some room and instead of 9.8, we use |
| 92 | GRAVITY_THRESHOLD (7.0f). We also consider the up <-> down movement successful if it takes less than |
| 93 | TIME_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 Hagikura | a819ef7 | 2014-09-25 16:23:49 +0900 | [diff] [blame] | 100 | </sample> |