-
Notifications
You must be signed in to change notification settings - Fork 0
/
Sensores de movimento
42 lines (30 loc) · 1.33 KB
/
Sensores de movimento
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import android.hardware.Sensor;
import android.hardware.SensorEvent;
import android.hardware.SensorEventListener;
import android.hardware.SensorManager;
import android.content.Context;
public class SensorDeMovimento implements SensorEventListener {
private SensorManager sensorManager;
private Sensor sensorAcelerometro;
private Sensor sensorGiroscopio;
public SensorDeMovimento(Context context) {
sensorManager = (SensorManager) context.getSystemService(Context.SENSOR_SERVICE);
sensorAcelerometro = sensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);
sensorGiroscopio = sensorManager.getDefaultSensor(Sensor.TYPE_GYROSCOPE);
}
public void registrarListener() {
sensorManager.registerListener(this, sensorAcelerometro, SensorManager.SENSOR_DELAY_NORMAL);
sensorManager.registerListener(this, sensorGiroscopio, SensorManager.SENSOR_DELAY_NORMAL);
}
public void desregistrarListener() {
sensorManager.unregisterListener(this);
}
@Override
public void onSensorChanged(SensorEvent event) {
if (event.sensor == sensorAcelerometro) {
float[] valoresAcelerometro = event.values;
} else if (event.sensor == sensorGiroscopio) {
float[] valoresGiroscopio = event.values;
}
}
}