Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(333)

Side by Side Diff: sky/framework/debug/shake-to-reload.sky

Issue 987103003: Fix shake-to-reload (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 <script> 1 <script>
2 import '/sky/framework/shell.dart' as shell; 2 import '/sky/framework/shell.dart' as shell;
3 import 'dart:sky'; 3 import 'dart:sky';
4 import 'package:sky/services/sensors/sensors.mojom.dart'; 4 import 'package:sky/services/sensors/sensors.mojom.dart';
5 5
6 // TODO(abarth): We should factor this out into a kinematics library. 6 // TODO(abarth): We should factor this out into a kinematics library.
7 class _ShakeDetector extends SensorListener { 7 class _ShakeDetector extends SensorListener {
8 _ShakeDetector() { 8 _ShakeDetector() {
9 SensorServiceProxy sensorService = new SensorServiceProxy.unbound(); 9 SensorServiceProxy sensorService = new SensorServiceProxy.unbound();
10 shell.requestService(sensorService); 10 shell.requestService(sensorService);
11 11
12 _stub = new SensorListenerStub.unbound() 12 _stub = new SensorListenerStub.unbound()..impl = this;
13 ..delegate = this;
14 sensorService.ptr.addListener(SensorType_ACCELEROMETER, _stub); 13 sensorService.ptr.addListener(SensorType_ACCELEROMETER, _stub);
15 _stub.listen();
16 } 14 }
17 15
18 void onAccuracyChanged(int accuracy) { 16 void onAccuracyChanged(int accuracy) {
19 } 17 }
20 18
21 void onSensorChanged(SensorData data) { 19 void onSensorChanged(SensorData data) {
22 double value = data.values[0] + data.values[1] + data.values[2]; 20 double value = data.values[0] + data.values[1] + data.values[2];
23 if (isShaking && value < 15.0) 21 if (isShaking && value < 15.0)
24 didCompleteShake(); 22 didCompleteShake();
25 else if (value > 40.0) 23 else if (value > 40.0)
26 isShaking = true; 24 isShaking = true;
27 } 25 }
28 26
29 void didCompleteShake() { 27 void didCompleteShake() {
30 window.location.assign(document.URL); 28 window.location.assign(document.URL);
31 _stub.close(); 29 _stub.close();
32 } 30 }
33 31
34 bool isShaking = false; 32 bool isShaking = false;
35 SensorListenerStub _stub; 33 SensorListenerStub _stub;
36 } 34 }
37 35
38 _ShakeDetector _detector; 36 _ShakeDetector _detector;
39 37
40 void _init(_) { 38 void _init(_) {
41 _detector = new _ShakeDetector(); 39 _detector = new _ShakeDetector();
42 } 40 }
43 </script> 41 </script>
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698