Threshold angepasst
This commit is contained in:
parent
53528a82e9
commit
a685f972bf
@ -69,7 +69,7 @@ public class MainActivity extends AppCompatActivity {
|
|||||||
//##########################################################################################################################################################################
|
//##########################################################################################################################################################################
|
||||||
//################################################################## vvv SensorParameter vvv ##############################################################################
|
//################################################################## vvv SensorParameter vvv ##############################################################################
|
||||||
private SensorManager mSensorManager;
|
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 float mLowerThreshold = 0.5f; // für Emulator auf 0.5 setzen
|
||||||
private static final long mShakeDetectionLockTimeMicroSeconds = 3500;
|
private static final long mShakeDetectionLockTimeMicroSeconds = 3500;
|
||||||
private float mAccel;
|
private float mAccel;
|
||||||
@ -101,15 +101,17 @@ public class MainActivity extends AppCompatActivity {
|
|||||||
{
|
{
|
||||||
//TextView txtEarthquake = (TextView) findViewById(R.id.txtEarthquake);
|
//TextView txtEarthquake = (TextView) findViewById(R.id.txtEarthquake);
|
||||||
mSensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE);
|
mSensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE);
|
||||||
Objects.requireNonNull(mSensorManager).registerListener(mSensorListener, mSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER), SensorManager.SENSOR_DELAY_NORMAL);
|
Objects.requireNonNull(mSensorManager).registerListener(mSensorListener, mSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER), SensorManager.SENSOR_DELAY_FASTEST);
|
||||||
mAccel = 1f;
|
mAccel = 0.05f;
|
||||||
mAccelCurrent = SensorManager.GRAVITY_EARTH;
|
mAccelCurrent = SensorManager.GRAVITY_EARTH;
|
||||||
mAccelLast = SensorManager.GRAVITY_EARTH;
|
mAccelLast = SensorManager.GRAVITY_EARTH;
|
||||||
mShakeDetectionIsActive = false;
|
mShakeDetectionIsActive = false;
|
||||||
mShakeDetected = false;
|
mShakeDetected = false;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private final SensorEventListener mSensorListener = new SensorEventListener() {
|
private final SensorEventListener mSensorListener = new SensorEventListener() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onSensorChanged(SensorEvent event) {
|
public void onSensorChanged(SensorEvent event) {
|
||||||
float x = event.values[0];
|
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));
|
mAccelCurrent = (float) Math.sqrt((double) (x * x + y * y + z * z));
|
||||||
float delta = mAccelCurrent - mAccelLast;
|
float delta = mAccelCurrent - mAccelLast;
|
||||||
mAccel = mAccel * 0.9f + delta;
|
mAccel = mAccel * 0.9f + delta;
|
||||||
// Log.d(TAG,"mAccel: "+ mAccel);
|
Log.d(TAG,"mAccel: "+ mAccel);
|
||||||
if (mShakeDetectionIsActive && !mShakeDetected) {
|
if (mShakeDetectionIsActive && !mShakeDetected) {
|
||||||
if(Math.abs(mAccel) > mUpperThreshold) {
|
if(Math.abs(mAccel) > mUpperThreshold) {
|
||||||
|
|
||||||
new CountDownTimer(1000, 10) {
|
new CountDownTimer(750, 10) {
|
||||||
|
|
||||||
public void onTick(long millisUntilFinished) {
|
public void onTick(long millisUntilFinished) {
|
||||||
mShakeDetectionIsActive = false;
|
mShakeDetectionIsActive = false;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user