Browse Source

vvv Detection Code vvv

EpiTest
Patrick Halboth 2 years ago
parent
commit
cfb0b0c612

+ 6
- 0
.idea/vcs.xml View File

<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="" vcs="Git" />
</component>
</project>

+ 79
- 3
app/src/main/java/de/edotzlaff/detection/EarthquakeLocation.java View File

package de.edotzlaff.detection; package de.edotzlaff.detection;


import android.hardware.Sensor;
import android.hardware.SensorEvent;
import android.hardware.SensorEventListener;
import android.hardware.SensorManager;
import android.os.Build; import android.os.Build;
import android.os.CountDownTimer;
import android.util.Log; import android.util.Log;
import androidx.annotation.RequiresApi; import androidx.annotation.RequiresApi;
import androidx.fragment.app.FragmentActivity; import androidx.fragment.app.FragmentActivity;


import android.os.Bundle; import android.os.Bundle;
import android.widget.Toast;


import com.google.android.gms.maps.CameraUpdateFactory; import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap; import com.google.android.gms.maps.GoogleMap;


private GoogleMap mMap; private GoogleMap mMap;
private static final String TAGEPIZENTRUM = "Epizentrum"; private static final String TAGEPIZENTRUM = "Epizentrum";
//##########################################################################################################################################################################
//################################################################## vvv SensorParameter vvv ##############################################################################
private SensorManager mSensorManager;
private static final float mUpperThreshold = 1.5f; // 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 = 10000;
private float mAccel;
private float mAccelCurrent;
private float mAccelLast;
private boolean mShakeDetectionIsActive = false;
private boolean mShakeDetected = false;
private boolean allowShakeEvent = true;
//################################################################## ^^^^ SensorParameter ^^^^ ############################################################################
//##########################################################################################################################################################################


@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {


//################################################################## ^^^^ DB Code ^^^^ ################################################################################### //################################################################## ^^^^ DB Code ^^^^ ###################################################################################
//########################################################################################################################################################################## //##########################################################################################################################################################################
//################################################################## vvv Detection Code vvv ###################################################################################
//##########################################################################################################################################################################


private final SensorEventListener mSensorListener = new SensorEventListener() {
@Override
public void onSensorChanged(SensorEvent event) {
float x = event.values[0];
float y = event.values[1];
float z = event.values[2];
mAccelLast = mAccelCurrent;
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);
if (mShakeDetectionIsActive) {
if(Math.abs(mAccel) > mUpperThreshold) {
new CountDownTimer(1500, 10) {

public void onTick(long millisUntilFinished) {
if (Math.abs(mAccel) > mUpperThreshold) {
mShakeDetectionIsActive = false;
} else if (Math.abs(mAccel) < mLowerThreshold) {
mShakeDetectionIsActive = true;
this.cancel();
}
}

public void onFinish() {
if (Math.abs(mAccel) > mUpperThreshold) {
mShakeDetectionIsActive = false;
mShakeDetected = true;

earthquakeDetected();

} else {
mShakeDetectionIsActive = true;
mShakeDetected = false;
}
}
}.start();
}
}
}
@Override
public void onAccuracyChanged(Sensor sensor, int accuracy) {
}
};


private void earthquakeDetected()
{
Toast.makeText(getApplicationContext(), "!Earthquake detected!", Toast.LENGTH_SHORT).show();
//setDataBaseValues();
}

//################################################################## ^^^^ Detection Code ^^^^ ###################################################################################
//##########################################################################################################################################################################


//########################################################################################################################################################################## //##########################################################################################################################################################################
//################################################################## vvv Calculate Epicenter vvv ######################################################################### //################################################################## vvv Calculate Epicenter vvv #########################################################################
//TODO Jan //TODO Jan


@RequiresApi(api = Build.VERSION_CODES.O) @RequiresApi(api = Build.VERSION_CODES.O)
public Epizentrum ermittleEpizentrum(DataSnapshot data)
/* public Epizentrum ermittleEpizentrum(DataSnapshot data)
{ {
Erdbeben erdbeben = new Erdbeben(); Erdbeben erdbeben = new Erdbeben();
erdbeben.addDetektionssignalList(mapToDetektionssignale(data)); erdbeben.addDetektionssignalList(mapToDetektionssignale(data));
return epizentrum; return epizentrum;


} }
public ArrayList<Detektionssignal> mapToDetektionssignale(DataSnapshot data)
*/
/* public ArrayList<Detektionssignal> mapToDetektionssignale(DataSnapshot data)
{ {
ArrayList<Detektionssignal> detektionssignale = new ArrayList<>(); ArrayList<Detektionssignal> detektionssignale = new ArrayList<>();
for(data.child("overviewnodes").getChildernKey) for(data.child("overviewnodes").getChildernKey)
return detektionssignale; return detektionssignale;
} }


*/



//################################################################## ^^^^ Calculate Epicenter ^^^^ ####################################################################### //################################################################## ^^^^ Calculate Epicenter ^^^^ #######################################################################
//########################################################################################################################################################################## //##########################################################################################################################################################################

+ 1
- 1
build.gradle View File

jcenter() jcenter()
} }
dependencies { dependencies {
classpath "com.android.tools.build:gradle:4.1.3"
classpath 'com.android.tools.build:gradle:4.2.1'


// NOTE: Do not place your application dependencies here; they belong // NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files // in the individual module build.gradle files

+ 1
- 1
gradle/wrapper/gradle-wrapper.properties View File

distributionPath=wrapper/dists distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.5-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-6.7.1-bin.zip

Loading…
Cancel
Save