Button added
This commit is contained in:
parent
2b5b997192
commit
77900b3088
@ -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);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
|
@ -62,4 +62,16 @@
|
||||
android:layout_marginBottom="0dp"
|
||||
android:text="Show Earthquake Location" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/buttonReadyToDetect"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_above="@id/btnEarthquakeLocation"
|
||||
android:layout_alignParentStart="false"
|
||||
android:layout_alignParentLeft="false"
|
||||
android:layout_alignParentEnd="false"
|
||||
android:layout_alignParentBottom="false"
|
||||
android:layout_centerInParent="true"
|
||||
android:text="Sensor Ready To Detect" />
|
||||
|
||||
</RelativeLayout>
|
Loading…
x
Reference in New Issue
Block a user