Browse Source

Button added

EpiTest
Patrick Halboth 2 years ago
parent
commit
77900b3088

+ 16
- 24
app/src/main/java/de/edotzlaff/detection/MainActivity.java View File

import com.google.android.gms.location.FusedLocationProviderClient; import com.google.android.gms.location.FusedLocationProviderClient;
import com.google.android.gms.location.LocationServices; import com.google.android.gms.location.LocationServices;
import com.google.android.gms.maps.GoogleMap; 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.OnCompleteListener;
import com.google.android.gms.tasks.Task; import com.google.android.gms.tasks.Task;


import org.w3c.dom.Text;

import java.util.Calendar; import java.util.Calendar;
import java.util.Objects; import java.util.Objects;


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 = 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 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 mAccel;
private float mAccelCurrent; private float mAccelCurrent;
private float mAccelLast; private float mAccelLast;
mAccel = 1f; mAccel = 1f;
mAccelCurrent = SensorManager.GRAVITY_EARTH; mAccelCurrent = SensorManager.GRAVITY_EARTH;
mAccelLast = SensorManager.GRAVITY_EARTH; mAccelLast = SensorManager.GRAVITY_EARTH;
mShakeDetectionIsActive = true;
mShakeDetectionIsActive = false;
mShakeDetected = false; mShakeDetected = false;
} }
private final SensorEventListener mSensorListener = new SensorEventListener() { private final SensorEventListener mSensorListener = new SensorEventListener() {
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(500, 10) {

new CountDownTimer(1000, 10) {


public void onTick(long millisUntilFinished) { public void onTick(long millisUntilFinished) {
mShakeDetectionIsActive = false; mShakeDetectionIsActive = false;
Toast.makeText(getApplicationContext(), "!Earthquake detected!", Toast.LENGTH_SHORT).show(); Toast.makeText(getApplicationContext(), "!Earthquake detected!", Toast.LENGTH_SHORT).show();
Log.d(TAG,"!Earthquake detected!"); Log.d(TAG,"!Earthquake detected!");
//setDataBaseValues(); //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);






startActivity(intent); 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);
}
});
} }





+ 12
- 0
app/src/main/res/layout/activity_main.xml View File

android:layout_marginBottom="0dp" android:layout_marginBottom="0dp"
android:text="Show Earthquake Location" /> 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> </RelativeLayout>

Loading…
Cancel
Save