Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 18 additions & 2 deletions android/src/main/java/com/aeyrium/sensor/AeyriumSensorPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
import io.flutter.plugin.common.EventChannel;
import io.flutter.plugin.common.MethodChannel.Result;
import io.flutter.plugin.common.PluginRegistry.Registrar;
import io.flutter.plugin.common.MethodCall;
import io.flutter.plugin.common.MethodChannel;
import io.flutter.plugin.common.PluginRegistry;
import io.flutter.embedding.engine.plugins.FlutterPlugin;
import android.hardware.Sensor;
import android.hardware.SensorEvent;
import android.hardware.SensorEventListener;
Expand All @@ -13,11 +17,12 @@
import android.content.Context;

/** AeyriumSensorPlugin */
public class AeyriumSensorPlugin implements EventChannel.StreamHandler {
public class AeyriumSensorPlugin implements FlutterPlugin, EventChannel.StreamHandler {

private static final String SENSOR_CHANNEL_NAME =
"plugins.aeyrium.com/sensor";
private static final int SENSOR_DELAY_MICROS = 1000 * 1000;//16 * 1000;
private static MethodChannel channel;
private WindowManager mWindowManager;
private SensorEventListener sensorEventListener;
private SensorManager sensorManager;
Expand Down Expand Up @@ -48,10 +53,21 @@ public void onListen(Object arguments, EventChannel.EventSink events) {
@Override
public void onCancel(Object arguments) {
if (sensorManager != null && sensorEventListener != null){
sensorManager.unregisterListener(sensorEventListener);
sensorManager.unregisterListener(sensorEventListener);
}
}

@Override
public void onAttachedToEngine(@NonNull FlutterPlugin.FlutterPluginBinding binding) {
channel = new MethodChannel(binding.getFlutterEngine().getDartExecutor(), "aeyrium_sensor_plugin");
channel.setMethodCallHandler(this);
}

@Override
public void onDetachedFromEngine(@NonNull FlutterPlugin.FlutterPluginBinding binding) {
channel.setMethodCallHandler(null);
}

SensorEventListener createSensorEventListener(final EventChannel.EventSink events) {
return new SensorEventListener() {
@Override
Expand Down