diff --git a/.idea/.name b/.idea/.name
new file mode 100644
index 0000000..cac5722
--- /dev/null
+++ b/.idea/.name
@@ -0,0 +1 @@
+Detection
\ No newline at end of file
diff --git a/app/build.gradle b/app/build.gradle
index 9ae4618..5c71b89 100644
--- a/app/build.gradle
+++ b/app/build.gradle
@@ -1,5 +1,7 @@
plugins {
id 'com.android.application'
+ id 'com.google.gms.google-services'
+
}
android {
@@ -34,10 +36,12 @@ dependencies {
implementation 'com.google.android.material:material:1.3.0'
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
implementation 'com.google.android.gms:play-services-maps:17.0.1'
+ implementation 'com.google.firebase:firebase-database:20.0.0'
testImplementation 'junit:junit:4.+'
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
implementation "com.google.android.gms:play-services-location:15.0.1" //Important to find the location from the device
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
implementation("com.google.guava:guava:30.1.1-jre")
+
}
\ No newline at end of file
diff --git a/app/google-services.json b/app/google-services.json
new file mode 100644
index 0000000..b7eca85
--- /dev/null
+++ b/app/google-services.json
@@ -0,0 +1,69 @@
+{
+ "project_info": {
+ "project_number": "957720376634",
+ "firebase_url": "https://schockwelle-mdt5-g1-default-rtdb.europe-west1.firebasedatabase.app",
+ "project_id": "schockwelle-mdt5-g1",
+ "storage_bucket": "schockwelle-mdt5-g1.appspot.com"
+ },
+ "client": [
+ {
+ "client_info": {
+ "mobilesdk_app_id": "1:957720376634:android:7e4e3f644d052e6f70cc03",
+ "android_client_info": {
+ "package_name": "de.edotzlaff.detection"
+ }
+ },
+ "oauth_client": [
+ {
+ "client_id": "957720376634-gvj86hvfrnt5npvqfbsb8lnu77fgaumh.apps.googleusercontent.com",
+ "client_type": 3
+ }
+ ],
+ "api_key": [
+ {
+ "current_key": "AIzaSyDNnG6F_VIzKbu4r7QBqsUZ3z6ELFbgyuc"
+ }
+ ],
+ "services": {
+ "appinvite_service": {
+ "other_platform_oauth_client": [
+ {
+ "client_id": "957720376634-gvj86hvfrnt5npvqfbsb8lnu77fgaumh.apps.googleusercontent.com",
+ "client_type": 3
+ }
+ ]
+ }
+ }
+ },
+ {
+ "client_info": {
+ "mobilesdk_app_id": "1:957720376634:android:fdc03f689ff71b2f70cc03",
+ "android_client_info": {
+ "package_name": "de.edotzlaff.schockwelle"
+ }
+ },
+ "oauth_client": [
+ {
+ "client_id": "957720376634-gvj86hvfrnt5npvqfbsb8lnu77fgaumh.apps.googleusercontent.com",
+ "client_type": 3
+ }
+ ],
+ "api_key": [
+ {
+ "current_key": "AIzaSyDNnG6F_VIzKbu4r7QBqsUZ3z6ELFbgyuc"
+ }
+ ],
+ "services": {
+ "appinvite_service": {
+ "other_platform_oauth_client": [
+ {
+ "client_id": "957720376634-gvj86hvfrnt5npvqfbsb8lnu77fgaumh.apps.googleusercontent.com",
+ "client_type": 3
+ }
+ ]
+ }
+ }
+ }
+ ],
+ "configuration_version": "1"
+}
\ No newline at end of file
diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml
index c4a7c9b..87bc632 100644
--- a/app/src/main/AndroidManifest.xml
+++ b/app/src/main/AndroidManifest.xml
@@ -10,12 +10,13 @@
+
diff --git a/app/src/main/java/de/edotzlaff/detection/EarthquakeLocation.java b/app/src/main/java/de/edotzlaff/detection/EarthquakeLocation.java
index d3dc3aa..37f57dd 100644
--- a/app/src/main/java/de/edotzlaff/detection/EarthquakeLocation.java
+++ b/app/src/main/java/de/edotzlaff/detection/EarthquakeLocation.java
@@ -37,8 +37,7 @@ public class EarthquakeLocation extends FragmentActivity implements OnMapReadyCa
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_earthquake_location);
// Obtain the SupportMapFragment and get notified when the map is ready to be used.
- SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager()
- .findFragmentById(R.id.map);
+ SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map);
mapFragment.getMapAsync(this);
}
diff --git a/app/src/main/java/de/edotzlaff/detection/MainActivity.java b/app/src/main/java/de/edotzlaff/detection/MainActivity.java
index 76f95b1..a3f5eca 100644
--- a/app/src/main/java/de/edotzlaff/detection/MainActivity.java
+++ b/app/src/main/java/de/edotzlaff/detection/MainActivity.java
@@ -1,6 +1,7 @@
package de.edotzlaff.detection;
import androidx.annotation.NonNull;
+import androidx.annotation.RequiresApi;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.app.ActivityCompat;
import androidx.core.content.ContextCompat;
@@ -15,8 +16,10 @@ import android.hardware.SensorEvent;
import android.hardware.SensorEventListener;
import android.hardware.SensorManager;
import android.location.Location;
+import android.os.Build;
import android.os.Bundle;
import android.os.CountDownTimer;
+import android.provider.Settings;
import android.util.Log;
import android.view.View;
import android.widget.Button;
@@ -30,7 +33,14 @@ import com.google.android.gms.location.LocationServices;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.tasks.OnCompleteListener;
import com.google.android.gms.tasks.Task;
+import com.google.firebase.database.DataSnapshot;
+import com.google.firebase.database.DatabaseError;
+import com.google.firebase.database.DatabaseReference;
+import com.google.firebase.database.FirebaseDatabase;
+import com.google.firebase.database.ValueEventListener;
+import java.time.LocalDateTime;
+import java.time.ZoneOffset;
import java.util.Calendar;
import java.util.Objects;
@@ -48,11 +58,14 @@ public class MainActivity extends AppCompatActivity {
Long currentTime;
Location currentLocation;
- // private DatabaseReference mDatenbank;
+ private DatabaseReference mDatenbank;
private double breitengrad;
private double laengengrad;
private boolean useOwnGPS = true;
private int indexID = 1;
+ private int writtenDevices = 1;
+ private boolean allowCalculation = true;
+
//##########################################################################################################################################################################
//################################################################## vvv SensorParameter vvv ##############################################################################
private SensorManager mSensorManager;
@@ -65,7 +78,6 @@ public class MainActivity extends AppCompatActivity {
private boolean mShakeDetectionIsActive = false;
private boolean mShakeDetected = false;
private boolean allowShakeEvent = true;
-
//################################################################## ^^^^ SensorParameter ^^^^ ############################################################################
//##########################################################################################################################################################################
@@ -73,18 +85,13 @@ public class MainActivity extends AppCompatActivity {
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
-
if (isServiceOK()){
init();
}
-
- //Detection funktion here
sensorManagementInit();
+ initDataBase();
getLocationPermission();
-
- //DB function here
-
-
+ getDataBaseValuesWithListener();
}
//################################################################## vvv Detection Code vvv ###################################################################################
@@ -100,6 +107,7 @@ public class MainActivity extends AppCompatActivity {
mShakeDetectionIsActive = false;
mShakeDetected = false;
}
+
private final SensorEventListener mSensorListener = new SensorEventListener() {
@Override
public void onSensorChanged(SensorEvent event) {
@@ -127,14 +135,11 @@ public class MainActivity extends AppCompatActivity {
*/
}
-
public void onFinish() {
if (Math.abs(mAccel) > mUpperThreshold) {
mShakeDetectionIsActive = false;
mShakeDetected = true;
-
earthquakeDetected();
-
} else {
mShakeDetectionIsActive = true;
mShakeDetected = false;
@@ -153,12 +158,10 @@ public class MainActivity extends AppCompatActivity {
{
Toast.makeText(getApplicationContext(), "!Earthquake detected!", Toast.LENGTH_SHORT).show();
Log.d(TAG,"!Earthquake detected!");
- //setDataBaseValues();
+ //Hier wird bei Vibration in Db geschrieben
+ getDataBaseValuesNoListenerForVibration();
Button buttonReadyToDetect = (Button) findViewById(R.id.buttonReadyToDetect);
buttonReadyToDetect.setEnabled(true);
-
-
-
}
//################################################################## ^^^^ Detection Code ^^^^ ###################################################################################
@@ -197,7 +200,7 @@ public class MainActivity extends AppCompatActivity {
}
currentLocation.setLatitude(breitengrad);
currentLocation.setLongitude(laengengrad);
- setText();
+ //setText();
}
else{
Toast.makeText(MainActivity.this, "Current Location unavailable", Toast.LENGTH_SHORT).show();
@@ -218,6 +221,257 @@ public class MainActivity extends AppCompatActivity {
//TODO Aron
+ //###### Für Start der APP ####
+ public void initDataBase()
+ {
+ getDataBaseValuesNoListener();
+ }
+ public void getDataBaseValuesNoListener()
+ {
+ mDatenbank = FirebaseDatabase.getInstance().getReference().child("overviewdetection");
+ mDatenbank.get().addOnCompleteListener(new OnCompleteListener() {
+ @Override
+ public void onComplete(@NonNull Task task) {
+ if (!task.isSuccessful()) {
+ System.out.println("Datenbank Fehler in getDataBaseValuesNoListener");
+ }
+ else {
+ analyzeForEmptyDB(task.getResult());
+ }
+ }
+ });
+ }
+ //Methode bestimmt, ob DB mit leer IDGn Felder überhaupt vorhanden ist
+ public void analyzeForEmptyDB(DataSnapshot data)
+ {
+ String androidid;
+ String localedatetime;
+ String breitengrad;
+ String laengengrad;
+ String timestamp;
+ String ampltiude;
+ int emptyIDG =0;
+
+ for (int i=1; i<=data.getChildrenCount(); i++)
+ {
+ androidid = data.child("IDG" + i).child("a_androidid").getValue().toString();
+ localedatetime = data.child("IDG" + i).child("b_localdatetime").getValue().toString();
+ breitengrad = data.child("IDG" + i).child("d_breitengrad").getValue().toString();
+ laengengrad = data.child("IDG" + i).child("e_laengengrad").getValue().toString();
+ timestamp = data.child("IDG" + i).child("h_timestamp").getValue().toString();
+ ampltiude = data.child("IDG" + i).child("i_amplitude").getValue().toString();
+
+ if(androidid.isEmpty() && localedatetime.isEmpty() && breitengrad.isEmpty() && laengengrad.isEmpty() && timestamp.isEmpty() && ampltiude.isEmpty())
+ {
+ emptyIDG++;
+ }else{
+ emptyIDG--;
+ }
+ }
+ //Wenn DB nicht vorhanden ODER leer ist, erstelle diese DB mit IDG 1-5
+ if(emptyIDG == data.getChildrenCount())
+ {
+ for (int i=1; i<=5; i++)
+ {
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
+ writeEmptyToSecondDataBase(i);
+ }
+ }
+ }
+ }
+ @RequiresApi(api = Build.VERSION_CODES.O)
+ public void writeEmptyToSecondDataBase(int k)
+ {
+ mDatenbank = FirebaseDatabase.getInstance().getReference().child("overviewdetection");
+ mDatenbank.child("IDG" + k).child("a_androidid").setValue("");
+ mDatenbank.child("IDG" + k).child("b_localdatetime").setValue("");
+ mDatenbank.child("IDG" + k).child("d_breitengrad").setValue("");
+ mDatenbank.child("IDG" + k).child("e_laengengrad").setValue("");
+ mDatenbank.child("IDG" + k).child("h_timestamp").setValue("");
+ mDatenbank.child("IDG" + k).child("i_amplitude").setValue("");
+
+ /*
+ k=1;
+ mDatenbank.child("IDG" + k).child("a_androidid").setValue(getandroidid());
+ mDatenbank.child("IDG" + k).child("b_localdatetime").setValue(LocalDateTime.now(ZoneOffset.UTC).toString());
+ mDatenbank.child("IDG" + k).child("d_breitengrad").setValue(123);
+ mDatenbank.child("IDG" + k).child("e_laengengrad").setValue(456);
+ mDatenbank.child("IDG" + k).child("h_timestamp").setValue(Calendar.getInstance().getTimeInMillis());
+ */
+ }
+
+ //###### Bei Vibration der APP ####
+ public void getDataBaseValuesNoListenerForVibration()
+ {
+ mDatenbank = FirebaseDatabase.getInstance().getReference().child("overviewdetection");
+ mDatenbank.get().addOnCompleteListener(new OnCompleteListener() {
+ @Override
+ public void onComplete(@NonNull Task task) {
+ if (!task.isSuccessful()) {
+ System.out.println("Datenbank Fehler in getDataBaseValuesNoListener");
+ }
+ else {
+ checkForEmptyIDG(task.getResult());
+ }
+ }
+ });
+ }
+ public void checkForEmptyIDG(DataSnapshot data)
+ {
+ for (int i=1; i<=data.getChildrenCount(); i++)
+ {
+ System.out.println("Schaue ob in DB IDG leer ist bei: " + i );
+ if(analyzeForEmptyIDG(data,i))
+ {
+ System.out.println("Schreibe in DB mit IDG " + i );
+ writeDeviceToDB(i);
+ break;
+ }
+ }
+ }
+ public boolean analyzeForEmptyIDG(DataSnapshot data, int i)
+ {
+ String androidid;
+ String localedatetime;
+ String breitengrad;
+ String laengengrad;
+ String timestamp;
+ String ampltiude;
+ androidid = data.child("IDG" + i).child("a_androidid").getValue().toString();
+ localedatetime = data.child("IDG" + i).child("b_localdatetime").getValue().toString();
+ breitengrad = data.child("IDG" + i).child("d_breitengrad").getValue().toString();
+ laengengrad = data.child("IDG" + i).child("e_laengengrad").getValue().toString();
+ timestamp = data.child("IDG" + i).child("h_timestamp").getValue().toString();
+ ampltiude = data.child("IDG" + i).child("i_amplitude").getValue().toString();
+
+ if(androidid.isEmpty() && localedatetime.isEmpty() && breitengrad.isEmpty() && laengengrad.isEmpty() && timestamp.isEmpty() && ampltiude.isEmpty())
+ {
+ return true;
+ }else
+ {
+ return false;
+ }
+ }
+ public void writeDeviceToDB (int k)
+ {
+ mDatenbank = FirebaseDatabase.getInstance().getReference().child("overviewdetection");
+
+ mDatenbank.child("IDG" + k).child("a_androidid").setValue(getandroidid());
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
+ mDatenbank.child("IDG" + k).child("b_localdatetime").setValue(LocalDateTime.now(ZoneOffset.UTC).toString());
+ }
+ mDatenbank.child("IDG" + k).child("d_breitengrad").setValue(currentLocation.getLatitude());
+ mDatenbank.child("IDG" + k).child("e_laengengrad").setValue(currentLocation.getLongitude());
+ mDatenbank.child("IDG" + k).child("h_timestamp").setValue(Calendar.getInstance().getTimeInMillis());
+ mDatenbank.child("IDG" + k).child("i_amplitude").setValue(1000);
+ }
+
+ //###### Bei Eintragungen in der DB ####
+ public void getDataBaseValuesWithListener()
+ {
+ mDatenbank = FirebaseDatabase.getInstance().getReference().child("overviewdetection");
+ mDatenbank.addValueEventListener(new ValueEventListener() {
+ @Override
+ public void onDataChange(@NonNull DataSnapshot snapshot) {
+ analyzeDBchanges(snapshot);
+ }
+ @Override
+ public void onCancelled(@NonNull DatabaseError error) {
+ getDataBaseFailure(error);
+ }
+ });
+ }
+
+ public void analyzeDBchanges(DataSnapshot data)
+ {
+ System.out.println("########################Höre auf Veränderungen....");
+ int takenIDG = 0;
+ for (int i=1; i<=data.getChildrenCount(); i++)
+ {
+ if(analyzeForFullIDG(data,i))
+ {
+ takenIDG++;
+ }
+ }
+ if(takenIDG>=1 && takenIDG <=5)
+ {
+ //Schreibt bei einer neuen vollen IDG ins Display
+ for(writtenDevices = writtenDevices; writtenDevices <= takenIDG; writtenDevices++)
+ {
+ setDisplayText(data,writtenDevices);
+ }
+ }
+ //TODO @Aron hier Jans Code anschließen
+ //Bei genau 3 Einträgen:
+ if(takenIDG >= 3 && allowCalculation)
+ {
+ Toast.makeText(MainActivity.this, "Es wurden 3 Geräteeinträge registriert!", Toast.LENGTH_SHORT).show();
+ allowCalculation = false;
+ System.out.println("Gebe an Berechnung raus");
+ //An Jans Code anknüpfen
+ }
+ }
+
+ public boolean analyzeForFullIDG(DataSnapshot data, int i)
+ {
+ String androidid = data.child("IDG" + i).child("a_androidid").getValue().toString();
+ String localedatetime = data.child("IDG" + i).child("b_localdatetime").getValue().toString();
+ String breitengrad = data.child("IDG" + i).child("d_breitengrad").getValue().toString();
+ String laengengrad = data.child("IDG" + i).child("e_laengengrad").getValue().toString();
+ String timestamp = data.child("IDG" + i).child("h_timestamp").getValue().toString();
+ String ampltiude = data.child("IDG" + i).child("i_amplitude").getValue().toString();
+
+ if(!androidid.isEmpty() && !localedatetime.isEmpty() && !breitengrad.isEmpty() && !laengengrad.isEmpty() && !timestamp.isEmpty() && !ampltiude.isEmpty())
+ {
+ return true;
+ }else
+ {
+ return false;
+ }
+ }
+
+ public void setDisplayText(DataSnapshot data, int i)
+ {
+ String androidid = data.child("IDG" + i).child("a_androidid").getValue().toString();
+ String localedatetime = data.child("IDG" + i).child("b_localdatetime").getValue().toString();
+ String breitengrad = data.child("IDG" + i).child("d_breitengrad").getValue().toString();
+ String laengengrad = data.child("IDG" + i).child("e_laengengrad").getValue().toString();
+ String timestamp = data.child("IDG" + i).child("h_timestamp").getValue().toString();
+ String ampltiude = data.child("IDG" + i).child("i_amplitude").getValue().toString();
+ TextView txtDevice1 = (TextView) findViewById(R.id.txtdevice1);
+ TextView txtDevice2 = (TextView) findViewById(R.id.txtdevice2);
+ TextView txtDevice3 = (TextView) findViewById(R.id.txtdevice3);
+ TextView txtDevice4 = (TextView) findViewById(R.id.txtdevice4);
+ switch (i){
+ case 1:
+ txtDevice1.setText("Device ID 1: "+ androidid + "\n" + "Latitude: "+breitengrad+"\n"+ "Longitude: "+ laengengrad +"\n" + "Time Stamp: "+ timestamp + "\n" + "LocalDateTime: " + localedatetime +"\n"+ "Amplitude: "+ ampltiude+"\n");
+ break;
+ case 2:
+ txtDevice2.setText("Device ID 2: "+ androidid + "\n" + "Latitude: "+breitengrad+"\n"+ "Longitude: "+ laengengrad +"\n" + "Time Stamp: "+ timestamp + "\n" + "LocalDateTime: " + localedatetime +"\n"+ "Amplitude: "+ ampltiude+"\n");
+ break;
+ case 3:
+ txtDevice3.setText("Device ID 3: "+ androidid + "\n" + "Latitude: "+breitengrad+"\n"+ "Longitude: "+ laengengrad +"\n" + "Time Stamp: "+ timestamp + "\n" + "LocalDateTime: " + localedatetime +"\n"+ "Amplitude: "+ ampltiude+"\n");
+ break;
+ case 4:
+ txtDevice4.setText("Device ID 4: "+ androidid + "\n" + "Latitude: "+breitengrad+"\n"+ "Longitude: "+ laengengrad +"\n" + "Time Stamp: "+ timestamp + "\n" + "LocalDateTime: " + localedatetime +"\n"+ "Amplitude: "+ ampltiude+"\n");
+ break;
+ default:
+ System.out.println("Default Case trifft zu");
+ break;
+ }
+ }
+
+ public String getandroidid ()
+ {
+ return Settings.Secure.getString(this.getContentResolver(), Settings.Secure.ANDROID_ID);
+ }
+
+ public void getDataBaseFailure (DatabaseError error)
+ {
+ System.out.println("Fehler");
+ Log.w("Datenbankfehler", error.toException());
+ }
+
//################################################################## ^^^^ DB Code ^^^^ ###################################################################################
//##########################################################################################################################################################################
@@ -281,13 +535,31 @@ public class MainActivity extends AppCompatActivity {
startActivity(intent);
}
});
- Button buttonReadyToDetect = (Button) findViewById(R.id.buttonReadyToDetect);
- buttonReadyToDetect.setOnClickListener(new View.OnClickListener() {
+
+ Button btnResetDB = (Button) findViewById(R.id.btnResetDB);
+ btnResetDB.setOnClickListener(new View.OnClickListener() {
+ @RequiresApi(api = Build.VERSION_CODES.O)
@Override
public void onClick(View v) {
- mShakeDetectionIsActive = true;
- mShakeDetected = false;
- buttonReadyToDetect.setEnabled(false);
+ for (int i=1; i<=5; i++)
+ {
+ writeEmptyToSecondDataBase(i);
+ }
+ }
+ });
+
+ Button btnReadyToDetect = (Button) findViewById(R.id.buttonReadyToDetect);
+ btnReadyToDetect.setOnClickListener(new View.OnClickListener() {
+ @RequiresApi(api = Build.VERSION_CODES.O)
+ @Override
+ public void onClick(View v) {
+ for (int i=1; i<=5; i++)
+ {
+ System.out.println("Ready to Detect");
+ mShakeDetectionIsActive = true;
+ mShakeDetected = false;
+ btnReadyToDetect.setEnabled(false);
+ }
}
});
}
diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml
index 62dcb85..c2c6535 100644
--- a/app/src/main/res/layout/activity_main.xml
+++ b/app/src/main/res/layout/activity_main.xml
@@ -9,7 +9,7 @@
+ android:text="@string/show_earthquake_location" />
+ android:text="@string/sensor_ready_to_detect" />
+
+
+
+
+
+
\ No newline at end of file
diff --git a/app/src/main/res/mipmap-mdpi/ic_trianglesign.png b/app/src/main/res/mipmap-mdpi/ic_trianglesign.png
new file mode 100644
index 0000000..a8dcabe
Binary files /dev/null and b/app/src/main/res/mipmap-mdpi/ic_trianglesign.png differ
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index 794bde1..21e68ff 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -1,4 +1,12 @@
Detection
Map
+ Testbutton
+ Sensor Ready To Detect
+ Show Earthquake Location
+ Device 4
+ Device 3
+ Device 2
+ Device 1
+ DB zurücksetzen
\ No newline at end of file
diff --git a/build.gradle b/build.gradle
index 996b567..45c3103 100644
--- a/build.gradle
+++ b/build.gradle
@@ -6,6 +6,8 @@ buildscript {
}
dependencies {
classpath 'com.android.tools.build:gradle:4.2.1'
+ classpath 'com.google.gms:google-services:4.3.8'
+
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files