mirror of
https://github.com/flutter/flutter.git
synced 2025-06-03 00:51:18 +00:00

This CL adds a sensor_service to sky/services and wires it into SkyShell The plan is to eventually use this data to implement shake-to-refresh. R=eseidel@chromium.org Review URL: https://codereview.chromium.org/962043002
39 lines
946 B
Plaintext
39 lines
946 B
Plaintext
<script>
|
|
import '/sky/framework/shell.dart' as shell;
|
|
import 'dart:sky';
|
|
import 'package:sky/services/sensors/sensors.mojom.dart';
|
|
|
|
class MyListener extends SensorListener {
|
|
int count = 0;
|
|
|
|
void onAccuracyChanged(int accuracy) {
|
|
print("onAccuracyChanged $accuracy");
|
|
}
|
|
|
|
void onSensorChanged(SensorData data) {
|
|
double value = data.values[0] + data.values[1] + data.values[2];
|
|
if (value > 40.0) {
|
|
document.querySelector('div').textContent =
|
|
"Shake count " + (count++).toString();
|
|
}
|
|
}
|
|
|
|
MyListener.unbound() {
|
|
stub = new SensorListenerStub.unbound()
|
|
..delegate = this;
|
|
}
|
|
|
|
SensorListenerStub stub;
|
|
}
|
|
|
|
void main() {
|
|
var sensorService = new SensorServiceProxy.unbound();
|
|
shell.requestService(sensorService);
|
|
|
|
var listener = new MyListener.unbound();
|
|
sensorService.ptr.addListener(SensorType_ACCELEROMETER, listener.stub);
|
|
listener.stub.listen();
|
|
}
|
|
</script>
|
|
<div>Shake me.</div>
|