OLD | NEW |
---|---|
(Empty) | |
1 <script> | |
2 import '/sky/framework/shell.dart' as shell; | |
3 import 'dart:sky'; | |
4 import 'package:sky/services/sensors/sensors.mojom.dart'; | |
5 | |
6 // TODO(abarth): We should factor this out into a kinemetics library. | |
eseidel
2015/02/27 23:29:53
kinematics
| |
7 class _ShakeDetector extends SensorListener { | |
8 _ShakeDetector() { | |
9 SensorServiceProxy sensorService = new SensorServiceProxy.unbound(); | |
10 shell.requestService(sensorService); | |
11 | |
12 _stub = new SensorListenerStub.unbound() | |
13 ..delegate = this; | |
14 sensorService.ptr.addListener(SensorType_ACCELEROMETER, _stub); | |
15 _stub.listen(); | |
16 } | |
17 | |
18 void onAccuracyChanged(int accuracy) { | |
19 } | |
20 | |
21 void onSensorChanged(SensorData data) { | |
22 double value = data.values[0] + data.values[1] + data.values[2]; | |
23 if (isShaking && value < 15.0) | |
24 didCompleteShake(); | |
25 else if (value > 40.0) | |
26 isShaking = true; | |
27 } | |
28 | |
29 void didCompleteShake() { | |
30 window.location.assign(document.URL); | |
31 _stub.close(); | |
32 } | |
33 | |
34 bool isShaking = false; | |
35 SensorListenerStub _stub; | |
36 } | |
37 | |
38 _ShakeDetector _detector; | |
39 | |
40 void _init(_) { | |
41 _detector = new _ShakeDetector(); | |
42 } | |
43 </script> | |
OLD | NEW |