|
|
|
|
|
|
|
|
//########################################################################################################################################################################## |
|
|
//########################################################################################################################################################################## |
|
|
//################################################################## 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; |
|
|
|
|
|
|
|
|
{ |
|
|
{ |
|
|
//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); |
|
|
|
|
|
mAccel = 1f; |
|
|
|
|
|
|
|
|
Objects.requireNonNull(mSensorManager).registerListener(mSensorListener, mSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER), SensorManager.SENSOR_DELAY_FASTEST); |
|
|
|
|
|
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]; |
|
|
|
|
|
|
|
|
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; |