From a685f972bf1124b7d730b93af2c57ccf7d9c5c64 Mon Sep 17 00:00:00 2001 From: Patrick Halboth Date: Sun, 27 Jun 2021 22:31:30 +0200 Subject: [PATCH] Threshold angepasst --- .../java/de/edotzlaff/detection/MainActivity.java | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/de/edotzlaff/detection/MainActivity.java b/app/src/main/java/de/edotzlaff/detection/MainActivity.java index d17441b..dd19d16 100644 --- a/app/src/main/java/de/edotzlaff/detection/MainActivity.java +++ b/app/src/main/java/de/edotzlaff/detection/MainActivity.java @@ -69,7 +69,7 @@ public class MainActivity extends AppCompatActivity { //########################################################################################################################################################################## //################################################################## vvv SensorParameter vvv ############################################################################## private SensorManager mSensorManager; - private static final float mUpperThreshold = 1.0f; // für Emulator auf 1.5 setzen + private static final float mUpperThreshold = 0.075f; // für Emulator auf 1.5 setzen private static final float mLowerThreshold = 0.5f; // für Emulator auf 0.5 setzen private static final long mShakeDetectionLockTimeMicroSeconds = 3500; private float mAccel; @@ -101,15 +101,17 @@ public class MainActivity extends AppCompatActivity { { //TextView txtEarthquake = (TextView) findViewById(R.id.txtEarthquake); mSensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE); - Objects.requireNonNull(mSensorManager).registerListener(mSensorListener, mSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER), SensorManager.SENSOR_DELAY_NORMAL); - mAccel = 1f; + Objects.requireNonNull(mSensorManager).registerListener(mSensorListener, mSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER), SensorManager.SENSOR_DELAY_FASTEST); + mAccel = 0.05f; mAccelCurrent = SensorManager.GRAVITY_EARTH; mAccelLast = SensorManager.GRAVITY_EARTH; mShakeDetectionIsActive = false; mShakeDetected = false; + } private final SensorEventListener mSensorListener = new SensorEventListener() { + @Override public void onSensorChanged(SensorEvent event) { float x = event.values[0]; @@ -119,11 +121,11 @@ public class MainActivity extends AppCompatActivity { mAccelCurrent = (float) Math.sqrt((double) (x * x + y * y + z * z)); float delta = mAccelCurrent - mAccelLast; mAccel = mAccel * 0.9f + delta; - // Log.d(TAG,"mAccel: "+ mAccel); + Log.d(TAG,"mAccel: "+ mAccel); if (mShakeDetectionIsActive && !mShakeDetected) { if(Math.abs(mAccel) > mUpperThreshold) { - new CountDownTimer(1000, 10) { + new CountDownTimer(750, 10) { public void onTick(long millisUntilFinished) { mShakeDetectionIsActive = false;