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