From 77900b30886d5c6dd0d4389f8089a9c5e305c43c Mon Sep 17 00:00:00 2001 From: Patrick Halboth Date: Fri, 25 Jun 2021 12:31:20 +0200 Subject: [PATCH] Button added --- .../de/edotzlaff/detection/MainActivity.java | 40 ++++++++----------- app/src/main/res/layout/activity_main.xml | 12 ++++++ 2 files changed, 28 insertions(+), 24 deletions(-) diff --git a/app/src/main/java/de/edotzlaff/detection/MainActivity.java b/app/src/main/java/de/edotzlaff/detection/MainActivity.java index 81bd4cf..76f95b1 100644 --- a/app/src/main/java/de/edotzlaff/detection/MainActivity.java +++ b/app/src/main/java/de/edotzlaff/detection/MainActivity.java @@ -28,14 +28,9 @@ import com.google.android.gms.common.GoogleApiAvailability; import com.google.android.gms.location.FusedLocationProviderClient; import com.google.android.gms.location.LocationServices; import com.google.android.gms.maps.GoogleMap; -import com.google.android.gms.maps.OnMapReadyCallback; -import com.google.android.gms.maps.SupportMapFragment; -import com.google.android.gms.maps.model.LatLng; import com.google.android.gms.tasks.OnCompleteListener; import com.google.android.gms.tasks.Task; -import org.w3c.dom.Text; - import java.util.Calendar; import java.util.Objects; @@ -63,7 +58,7 @@ public class MainActivity extends AppCompatActivity { private SensorManager mSensorManager; private static final float mUpperThreshold = 1.0f; // 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 = 1000; + private static final long mShakeDetectionLockTimeMicroSeconds = 3500; private float mAccel; private float mAccelCurrent; private float mAccelLast; @@ -102,7 +97,7 @@ public class MainActivity extends AppCompatActivity { mAccel = 1f; mAccelCurrent = SensorManager.GRAVITY_EARTH; mAccelLast = SensorManager.GRAVITY_EARTH; - mShakeDetectionIsActive = true; + mShakeDetectionIsActive = false; mShakeDetected = false; } private final SensorEventListener mSensorListener = new SensorEventListener() { @@ -115,10 +110,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(500, 10) { + + new CountDownTimer(1000, 10) { public void onTick(long millisUntilFinished) { mShakeDetectionIsActive = false; @@ -158,20 +154,8 @@ public class MainActivity extends AppCompatActivity { Toast.makeText(getApplicationContext(), "!Earthquake detected!", Toast.LENGTH_SHORT).show(); Log.d(TAG,"!Earthquake detected!"); //setDataBaseValues(); - new CountDownTimer(mShakeDetectionLockTimeMicroSeconds, 100) { - - public void onTick(long millisUntilFinished) { - Log.d(TAG,"Earthquake: "+ millisUntilFinished + " ms"); - } - - - public void onFinish() { - Log.d(TAG,"Earthquake Detection is Unlocked: "); - mShakeDetectionIsActive = true; - mShakeDetected = false; - - } - }.start(); + Button buttonReadyToDetect = (Button) findViewById(R.id.buttonReadyToDetect); + buttonReadyToDetect.setEnabled(true); @@ -297,7 +281,15 @@ public class MainActivity extends AppCompatActivity { startActivity(intent); } }); - + Button buttonReadyToDetect = (Button) findViewById(R.id.buttonReadyToDetect); + buttonReadyToDetect.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + mShakeDetectionIsActive = true; + mShakeDetected = false; + buttonReadyToDetect.setEnabled(false); + } + }); } diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index 16188ad..62dcb85 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -62,4 +62,16 @@ android:layout_marginBottom="0dp" android:text="Show Earthquake Location" /> +