mirror of
https://github.com/flutter/flutter.git
synced 2025-06-03 00:51:18 +00:00
Expose Android sensors to via Mojo services
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
This commit is contained in:
parent
a128b09618
commit
5db8423f38
38
examples/shell/sensor.sky
Normal file
38
examples/shell/sensor.sky
Normal file
@ -0,0 +1,38 @@
|
||||
<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>
|
Loading…
Reference in New Issue
Block a user