Home | History | Annotate | Download | only in JumpingJack
      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>
     22     <group>Wearable</group>
     23     <package>com.example.android.wearable.jumpingjack</package>
     24 
     25 
     26 
     27     <!-- change minSdk if needed-->
     28     <minSdk>18</minSdk>
     29 
     30 
     31     <strings>
     32         <intro>
     33             <![CDATA[
     34             Uses the Gravity sensor to count how many jumping jacks you have performed.
     35             ]]>
     36         </intro>
     37     </strings>
     38 
     39     <template src="base"/>
     40     <template src="Wear"/>
     41     <common src="logger"/>
     42     <common src="activities"/>
     43 
     44     <metadata>
     45         <status>PUBLISHED</status>
     46         <categories>Wearable</categories>
     47         <technologies>Android</technologies>
     48         <languages>Java</languages>
     49         <solutions>Mobile</solutions>
     50         <level>INTERMEDIATE</level>
     51         <icon>screenshots/web-icon.png</icon>
     52         <screenshots>
     53             <img>screenshots/jumping_jack.gif</img>
     54         </screenshots>
     55         <api_refs>
     56             <android>android.hardware.SensorEvent</android>
     57             <android>android.hardware.SensorEventManager</android>
     58         </api_refs>
     59 
     60         <description>
     61 <![CDATA[
     62 A basic sample showing how to use the Gravity sensor on the wearable device
     63 by counting how many jumping jacks you have performed.
     64 ]]>
     65         </description>
     66 
     67         <intro>
     68 <![CDATA[
     69 [SensorEventListener][1] offers you methods used for receiving notifications from the
     70 [SensorManager][2] when sensor values have changed.
     71 
     72 This example counts how many times Jumping Jakcs are performed by detecting the value
     73 of the Gravity sensor by the following code:
     74 
     75 ```java
     76 @Override
     77 public void onSensorChanged(SensorEvent event) {
     78     detectJump(event.values[0], event.timestamp);
     79 }
     80 
     81 private void detectJump(float xValue, long timestamp) {
     82     if ((Math.abs(xValue) > GRAVITY_THRESHOLD)) {
     83         if(timestamp - mLastTime < TIME_THRESHOLD_NS && mUp != (xValue > 0)) {
     84             onJumpDetected(!mUp);
     85         }
     86         mUp = xValue > 0;
     87         mLastTime = timestamp;
     88     }
     89 }
     90 ```
     91 
     92 The detectJump method above assumes that when a person is wearing the watch, the x-component of gravity
     93 as measured by the Gravity Sensor is +9.8 when the hand is downward and -9.8 when the hand
     94 is upward (signs are reversed if the watch is worn on the right hand). Since the upward or
     95 downward may not be completely accurate, we leave some room and instead of 9.8, we use
     96 GRAVITY_THRESHOLD (7.0f). We also consider the up <-> down movement successful if it takes less than
     97 TIME_THRESHOLD_NS (2000000000 nanoseconds).
     98 
     99 [1]: http://developer.android.com/reference/android/hardware/SensorEventListener.html
    100 [2]: http://developer.android.com/reference/android/hardware/SensorManager.html
    101 ]]>
    102         </intro>
    103     </metadata>
    104 </sample>
    105