Pre-AlphaV3
This commit is contained in:
parent
77900b3088
commit
ab02421307
1
.idea/.name
generated
Normal file
1
.idea/.name
generated
Normal file
@ -0,0 +1 @@
|
|||||||
|
Detection
|
@ -1,5 +1,7 @@
|
|||||||
plugins {
|
plugins {
|
||||||
id 'com.android.application'
|
id 'com.android.application'
|
||||||
|
id 'com.google.gms.google-services'
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
android {
|
android {
|
||||||
@ -34,10 +36,12 @@ dependencies {
|
|||||||
implementation 'com.google.android.material:material:1.3.0'
|
implementation 'com.google.android.material:material:1.3.0'
|
||||||
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
|
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
|
||||||
implementation 'com.google.android.gms:play-services-maps:17.0.1'
|
implementation 'com.google.android.gms:play-services-maps:17.0.1'
|
||||||
|
implementation 'com.google.firebase:firebase-database:20.0.0'
|
||||||
testImplementation 'junit:junit:4.+'
|
testImplementation 'junit:junit:4.+'
|
||||||
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
|
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
|
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'
|
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
|
||||||
|
|
||||||
implementation("com.google.guava:guava:30.1.1-jre")
|
implementation("com.google.guava:guava:30.1.1-jre")
|
||||||
|
|
||||||
}
|
}
|
69
app/google-services.json
Normal file
69
app/google-services.json
Normal file
@ -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"
|
||||||
|
}
|
@ -10,12 +10,13 @@
|
|||||||
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
|
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
|
||||||
<uses-permission android:name="android.permission.INTERNET" />
|
<uses-permission android:name="android.permission.INTERNET" />
|
||||||
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
|
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
|
||||||
|
<uses-permission android:name="android.permission.VIBRATE" />
|
||||||
|
|
||||||
<application
|
<application
|
||||||
android:allowBackup="true"
|
android:allowBackup="true"
|
||||||
android:icon="@mipmap/ic_launcher"
|
android:icon="@mipmap/ic_trianglesign"
|
||||||
android:label="@string/app_name"
|
android:label="@string/app_name"
|
||||||
android:roundIcon="@mipmap/ic_launcher_round"
|
android:roundIcon="@mipmap/ic_trianglesign"
|
||||||
android:supportsRtl="true"
|
android:supportsRtl="true"
|
||||||
android:theme="@style/Theme.Detection">
|
android:theme="@style/Theme.Detection">
|
||||||
|
|
||||||
|
@ -37,8 +37,7 @@ public class EarthquakeLocation extends FragmentActivity implements OnMapReadyCa
|
|||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
setContentView(R.layout.activity_earthquake_location);
|
setContentView(R.layout.activity_earthquake_location);
|
||||||
// Obtain the SupportMapFragment and get notified when the map is ready to be used.
|
// Obtain the SupportMapFragment and get notified when the map is ready to be used.
|
||||||
SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager()
|
SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map);
|
||||||
.findFragmentById(R.id.map);
|
|
||||||
mapFragment.getMapAsync(this);
|
mapFragment.getMapAsync(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package de.edotzlaff.detection;
|
package de.edotzlaff.detection;
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
|
import androidx.annotation.RequiresApi;
|
||||||
import androidx.appcompat.app.AppCompatActivity;
|
import androidx.appcompat.app.AppCompatActivity;
|
||||||
import androidx.core.app.ActivityCompat;
|
import androidx.core.app.ActivityCompat;
|
||||||
import androidx.core.content.ContextCompat;
|
import androidx.core.content.ContextCompat;
|
||||||
@ -15,8 +16,10 @@ import android.hardware.SensorEvent;
|
|||||||
import android.hardware.SensorEventListener;
|
import android.hardware.SensorEventListener;
|
||||||
import android.hardware.SensorManager;
|
import android.hardware.SensorManager;
|
||||||
import android.location.Location;
|
import android.location.Location;
|
||||||
|
import android.os.Build;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.CountDownTimer;
|
import android.os.CountDownTimer;
|
||||||
|
import android.provider.Settings;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.widget.Button;
|
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.maps.GoogleMap;
|
||||||
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 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.Calendar;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
|
||||||
@ -48,11 +58,14 @@ public class MainActivity extends AppCompatActivity {
|
|||||||
|
|
||||||
Long currentTime;
|
Long currentTime;
|
||||||
Location currentLocation;
|
Location currentLocation;
|
||||||
// private DatabaseReference mDatenbank;
|
private DatabaseReference mDatenbank;
|
||||||
private double breitengrad;
|
private double breitengrad;
|
||||||
private double laengengrad;
|
private double laengengrad;
|
||||||
private boolean useOwnGPS = true;
|
private boolean useOwnGPS = true;
|
||||||
private int indexID = 1;
|
private int indexID = 1;
|
||||||
|
private int writtenDevices = 1;
|
||||||
|
private boolean allowCalculation = true;
|
||||||
|
|
||||||
//##########################################################################################################################################################################
|
//##########################################################################################################################################################################
|
||||||
//################################################################## vvv SensorParameter vvv ##############################################################################
|
//################################################################## vvv SensorParameter vvv ##############################################################################
|
||||||
private SensorManager mSensorManager;
|
private SensorManager mSensorManager;
|
||||||
@ -65,7 +78,6 @@ public class MainActivity extends AppCompatActivity {
|
|||||||
private boolean mShakeDetectionIsActive = false;
|
private boolean mShakeDetectionIsActive = false;
|
||||||
private boolean mShakeDetected = false;
|
private boolean mShakeDetected = false;
|
||||||
private boolean allowShakeEvent = true;
|
private boolean allowShakeEvent = true;
|
||||||
|
|
||||||
//################################################################## ^^^^ SensorParameter ^^^^ ############################################################################
|
//################################################################## ^^^^ SensorParameter ^^^^ ############################################################################
|
||||||
//##########################################################################################################################################################################
|
//##########################################################################################################################################################################
|
||||||
|
|
||||||
@ -73,18 +85,13 @@ public class MainActivity extends AppCompatActivity {
|
|||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
setContentView(R.layout.activity_main);
|
setContentView(R.layout.activity_main);
|
||||||
|
|
||||||
if (isServiceOK()){
|
if (isServiceOK()){
|
||||||
init();
|
init();
|
||||||
}
|
}
|
||||||
|
|
||||||
//Detection funktion here
|
|
||||||
sensorManagementInit();
|
sensorManagementInit();
|
||||||
|
initDataBase();
|
||||||
getLocationPermission();
|
getLocationPermission();
|
||||||
|
getDataBaseValuesWithListener();
|
||||||
//DB function here
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//################################################################## vvv Detection Code vvv ###################################################################################
|
//################################################################## vvv Detection Code vvv ###################################################################################
|
||||||
@ -100,6 +107,7 @@ public class MainActivity extends AppCompatActivity {
|
|||||||
mShakeDetectionIsActive = false;
|
mShakeDetectionIsActive = false;
|
||||||
mShakeDetected = false;
|
mShakeDetected = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
private final SensorEventListener mSensorListener = new SensorEventListener() {
|
private final SensorEventListener mSensorListener = new SensorEventListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onSensorChanged(SensorEvent event) {
|
public void onSensorChanged(SensorEvent event) {
|
||||||
@ -127,14 +135,11 @@ public class MainActivity extends AppCompatActivity {
|
|||||||
*/
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void onFinish() {
|
public void onFinish() {
|
||||||
if (Math.abs(mAccel) > mUpperThreshold) {
|
if (Math.abs(mAccel) > mUpperThreshold) {
|
||||||
mShakeDetectionIsActive = false;
|
mShakeDetectionIsActive = false;
|
||||||
mShakeDetected = true;
|
mShakeDetected = true;
|
||||||
|
|
||||||
earthquakeDetected();
|
earthquakeDetected();
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
mShakeDetectionIsActive = true;
|
mShakeDetectionIsActive = true;
|
||||||
mShakeDetected = false;
|
mShakeDetected = false;
|
||||||
@ -153,12 +158,10 @@ public class MainActivity extends AppCompatActivity {
|
|||||||
{
|
{
|
||||||
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();
|
//Hier wird bei Vibration in Db geschrieben
|
||||||
|
getDataBaseValuesNoListenerForVibration();
|
||||||
Button buttonReadyToDetect = (Button) findViewById(R.id.buttonReadyToDetect);
|
Button buttonReadyToDetect = (Button) findViewById(R.id.buttonReadyToDetect);
|
||||||
buttonReadyToDetect.setEnabled(true);
|
buttonReadyToDetect.setEnabled(true);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//################################################################## ^^^^ Detection Code ^^^^ ###################################################################################
|
//################################################################## ^^^^ Detection Code ^^^^ ###################################################################################
|
||||||
@ -197,7 +200,7 @@ public class MainActivity extends AppCompatActivity {
|
|||||||
}
|
}
|
||||||
currentLocation.setLatitude(breitengrad);
|
currentLocation.setLatitude(breitengrad);
|
||||||
currentLocation.setLongitude(laengengrad);
|
currentLocation.setLongitude(laengengrad);
|
||||||
setText();
|
//setText();
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
Toast.makeText(MainActivity.this, "Current Location unavailable", Toast.LENGTH_SHORT).show();
|
Toast.makeText(MainActivity.this, "Current Location unavailable", Toast.LENGTH_SHORT).show();
|
||||||
@ -218,6 +221,257 @@ public class MainActivity extends AppCompatActivity {
|
|||||||
|
|
||||||
//TODO Aron
|
//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<DataSnapshot>() {
|
||||||
|
@Override
|
||||||
|
public void onComplete(@NonNull Task<DataSnapshot> 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<DataSnapshot>() {
|
||||||
|
@Override
|
||||||
|
public void onComplete(@NonNull Task<DataSnapshot> 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 ^^^^ ###################################################################################
|
//################################################################## ^^^^ DB Code ^^^^ ###################################################################################
|
||||||
//##########################################################################################################################################################################
|
//##########################################################################################################################################################################
|
||||||
|
|
||||||
@ -281,13 +535,31 @@ public class MainActivity extends AppCompatActivity {
|
|||||||
startActivity(intent);
|
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
|
@Override
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
mShakeDetectionIsActive = true;
|
for (int i=1; i<=5; i++)
|
||||||
mShakeDetected = false;
|
{
|
||||||
buttonReadyToDetect.setEnabled(false);
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -9,7 +9,7 @@
|
|||||||
<TextView
|
<TextView
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:text="Device 1"
|
android:text="@string/device_1"
|
||||||
app:layout_constraintBottom_toBottomOf="parent"
|
app:layout_constraintBottom_toBottomOf="parent"
|
||||||
app:layout_constraintLeft_toLeftOf="parent"
|
app:layout_constraintLeft_toLeftOf="parent"
|
||||||
app:layout_constraintRight_toRightOf="parent"
|
app:layout_constraintRight_toRightOf="parent"
|
||||||
@ -20,7 +20,7 @@
|
|||||||
<TextView
|
<TextView
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:text="Device 2"
|
android:text="@string/device_2"
|
||||||
app:layout_constraintBottom_toBottomOf="parent"
|
app:layout_constraintBottom_toBottomOf="parent"
|
||||||
app:layout_constraintLeft_toLeftOf="parent"
|
app:layout_constraintLeft_toLeftOf="parent"
|
||||||
app:layout_constraintRight_toRightOf="parent"
|
app:layout_constraintRight_toRightOf="parent"
|
||||||
@ -32,7 +32,7 @@
|
|||||||
<TextView
|
<TextView
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:text="Device 3"
|
android:text="@string/device_3"
|
||||||
app:layout_constraintBottom_toBottomOf="parent"
|
app:layout_constraintBottom_toBottomOf="parent"
|
||||||
app:layout_constraintLeft_toLeftOf="parent"
|
app:layout_constraintLeft_toLeftOf="parent"
|
||||||
app:layout_constraintRight_toRightOf="parent"
|
app:layout_constraintRight_toRightOf="parent"
|
||||||
@ -44,7 +44,7 @@
|
|||||||
<TextView
|
<TextView
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:text="Device 4"
|
android:text="@string/device_4"
|
||||||
app:layout_constraintBottom_toBottomOf="parent"
|
app:layout_constraintBottom_toBottomOf="parent"
|
||||||
app:layout_constraintLeft_toLeftOf="parent"
|
app:layout_constraintLeft_toLeftOf="parent"
|
||||||
app:layout_constraintRight_toRightOf="parent"
|
app:layout_constraintRight_toRightOf="parent"
|
||||||
@ -60,7 +60,7 @@
|
|||||||
android:layout_alignParentBottom="true"
|
android:layout_alignParentBottom="true"
|
||||||
android:layout_centerHorizontal="true"
|
android:layout_centerHorizontal="true"
|
||||||
android:layout_marginBottom="0dp"
|
android:layout_marginBottom="0dp"
|
||||||
android:text="Show Earthquake Location" />
|
android:text="@string/show_earthquake_location" />
|
||||||
|
|
||||||
<Button
|
<Button
|
||||||
android:id="@+id/buttonReadyToDetect"
|
android:id="@+id/buttonReadyToDetect"
|
||||||
@ -68,10 +68,26 @@
|
|||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_above="@id/btnEarthquakeLocation"
|
android:layout_above="@id/btnEarthquakeLocation"
|
||||||
android:layout_alignParentStart="false"
|
android:layout_alignParentStart="false"
|
||||||
android:layout_alignParentLeft="false"
|
|
||||||
android:layout_alignParentEnd="false"
|
android:layout_alignParentEnd="false"
|
||||||
android:layout_alignParentBottom="false"
|
android:layout_alignParentBottom="false"
|
||||||
android:layout_centerInParent="true"
|
android:layout_centerInParent="true"
|
||||||
android:text="Sensor Ready To Detect" />
|
android:text="@string/sensor_ready_to_detect" />
|
||||||
|
|
||||||
|
<Button
|
||||||
|
android:id="@+id/btnResetDB"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_centerHorizontal="true"
|
||||||
|
android:layout_above="@id/buttonReadyToDetect"
|
||||||
|
android:layout_alignParentStart="false"
|
||||||
|
android:layout_alignParentEnd="false"
|
||||||
|
android:layout_alignParentBottom="false"
|
||||||
|
android:layout_centerInParent="true"
|
||||||
|
android:textColor="@color/black"
|
||||||
|
android:text="@string/db_zur_cksetzen" />
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
</RelativeLayout>
|
</RelativeLayout>
|
BIN
app/src/main/res/mipmap-mdpi/ic_trianglesign.png
Normal file
BIN
app/src/main/res/mipmap-mdpi/ic_trianglesign.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 17 KiB |
@ -1,4 +1,12 @@
|
|||||||
<resources>
|
<resources>
|
||||||
<string name="app_name">Detection</string>
|
<string name="app_name">Detection</string>
|
||||||
<string name="title_activity_earthquake_location">Map</string>
|
<string name="title_activity_earthquake_location">Map</string>
|
||||||
|
<string name="testbutton">Testbutton</string>
|
||||||
|
<string name="sensor_ready_to_detect">Sensor Ready To Detect</string>
|
||||||
|
<string name="show_earthquake_location">Show Earthquake Location</string>
|
||||||
|
<string name="device_4">Device 4</string>
|
||||||
|
<string name="device_3">Device 3</string>
|
||||||
|
<string name="device_2">Device 2</string>
|
||||||
|
<string name="device_1">Device 1</string>
|
||||||
|
<string name="db_zur_cksetzen">DB zurücksetzen</string>
|
||||||
</resources>
|
</resources>
|
@ -6,6 +6,8 @@ buildscript {
|
|||||||
}
|
}
|
||||||
dependencies {
|
dependencies {
|
||||||
classpath 'com.android.tools.build:gradle:4.2.1'
|
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
|
// NOTE: Do not place your application dependencies here; they belong
|
||||||
// in the individual module build.gradle files
|
// in the individual module build.gradle files
|
||||||
|
Loading…
x
Reference in New Issue
Block a user