I would like to implement in this piece of code some instructions to increase the sensitivity of the accelerometer sensor, and increase the brightness of the screen when the phone is shaken
sensorManager = (SensorManager) getSystemService(SENSOR_SERVICE);
sensorManager.registerListener(this, sensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER), SensorManager.SENSOR_DELAY_NORMAL);
lastUpdate = System.currentTimeMillis();
@Override
public void onSensorChanged(SensorEvent event) {
if (event.sensor.getType() == Sensor.TYPE_ACCELEROMETER) { getAccelerometer(event);
}
}
private void getAccelerometer(SensorEvent event) {
super.onResume();
float[] values = event.values;
// Movement
float x = values[0];
float y = values[1];
float z = values[2];
float accelationSquareRoot = (x * x + y * y + z * z)
/ (SensorManager.GRAVITY_EARTH * SensorManager.GRAVITY_EARTH);
long actualTime = System.currentTimeMillis();
if (accelationSquareRoot >= 2) //
{
if (actualTime - lastUpdate < 200) {
return;
}
lastUpdate = actualTime;
Toast.makeText(this, "Device was shuffed", Toast.LENGTH_SHORT).show();
if (mMediaPlayer.isPlaying() == false){
mMediaPlayer.start();
}
}
}
just a very basic filter
as far as screen brightness goes :