Compare commits
39
Commits
c37a99723f
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
054e9687a8 | ||
|
|
2d4508ec1a | ||
|
|
5dd5d3c892 | ||
|
|
a4cb71a8f3 | ||
|
|
eb620bccbc | ||
|
|
69070b020f | ||
|
|
5159f9da57 | ||
|
|
e9d75b7ec4 | ||
|
|
45d9a86d48 | ||
|
|
085ea36824 | ||
|
|
a6b614dabe | ||
|
|
0809d06f3f | ||
|
|
3827352818 | ||
|
|
5c59f7732e | ||
|
|
eb68c99d99 | ||
|
|
0cb1101aa8 | ||
|
|
0864c39091 | ||
|
|
b6da735750 | ||
|
|
4d5e9405d4 | ||
|
|
a780c9e900 | ||
|
|
5b116a1773 | ||
|
|
41c36a9e02 | ||
|
|
e85656eb58 | ||
|
|
d1639e103e | ||
|
|
22dec5900c | ||
|
|
24e651da4e | ||
|
|
f414fa62f2 | ||
|
|
700c5ba792 | ||
|
|
7345a35d97 | ||
|
|
23dd646e90 | ||
|
|
7e10399b92 | ||
|
|
3c7f30a74b | ||
|
|
e50fafd505 | ||
|
|
af1e25bf8c | ||
|
|
b930e39dee | ||
|
|
d7addc222d | ||
|
|
903664503a | ||
|
|
1d2485d59e | ||
|
|
eba661a070 |
No files matched your search
@@ -10,7 +10,7 @@
|
|||||||
<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.ACCESS_WIFI_STATE" />
|
||||||
<uses-permission android:name="android.permission.VIBRATE" />
|
<uses-permission android:name="android.permission.VIBRATE" />
|
||||||
|
|
||||||
<application
|
<application
|
||||||
|
|||||||
@@ -0,0 +1,664 @@
|
|||||||
|
package de.edotzlaff.schockwelle;
|
||||||
|
|
||||||
|
import android.net.wifi.WifiManager;
|
||||||
|
import android.os.Build;
|
||||||
|
import android.util.Log;
|
||||||
|
import android.widget.Toast;
|
||||||
|
|
||||||
|
import androidx.annotation.NonNull;
|
||||||
|
|
||||||
|
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;
|
||||||
|
|
||||||
|
public class Datenbank {
|
||||||
|
private String myAndroidID;
|
||||||
|
private String myIPadress;
|
||||||
|
private int myWaveSpeed; // Meter pro Sekunde
|
||||||
|
private double shakeBreitengrad;
|
||||||
|
private double shakeLaengengrad;
|
||||||
|
private String a_androidid;
|
||||||
|
private String b_localdatetime;
|
||||||
|
private String c_ip;
|
||||||
|
private double d_breitengrad;
|
||||||
|
private double e_laengengrad;
|
||||||
|
private boolean f_nativegps;
|
||||||
|
private boolean g_vibration;
|
||||||
|
private long h_timestamp;
|
||||||
|
private int i_amplitude;
|
||||||
|
private int w_wellengeschwindigkeit;
|
||||||
|
private DatabaseReference mDatenbank = FirebaseDatabase.getInstance().getReference().child("overviewnodes");
|
||||||
|
private String TAG = "Datenbank";
|
||||||
|
DataSnapshot DatenBankInhalt;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//######### Für andere Klassen: ###########################
|
||||||
|
//Datenbank db = new Datenbank(); <--Bei Initialisierung
|
||||||
|
//db.getDatafromDBnoListener(); <--OnCreate
|
||||||
|
//db.getDataBaseValuesWithListener(); <--OnCreate
|
||||||
|
|
||||||
|
public Datenbank(String a_androidid, String b_localdatetime, String c_ip, double d_breitengrad, double e_laengengrad, boolean f_nativegps, boolean g_vibration, long h_timestamp, int i_amplitude, int w_wellengeschwindigkeit) {
|
||||||
|
this.a_androidid = a_androidid;
|
||||||
|
this.b_localdatetime = b_localdatetime;
|
||||||
|
this.c_ip = c_ip;
|
||||||
|
this.d_breitengrad = d_breitengrad;
|
||||||
|
this.e_laengengrad = e_laengengrad;
|
||||||
|
this.f_nativegps = f_nativegps;
|
||||||
|
this.g_vibration = g_vibration;
|
||||||
|
this.h_timestamp = h_timestamp;
|
||||||
|
this.i_amplitude = i_amplitude;
|
||||||
|
this.w_wellengeschwindigkeit = w_wellengeschwindigkeit;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Datenbank ()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
//DatenBankInhalt wird einmalig Aktualisiert
|
||||||
|
public void getDatafromDBnoListener()
|
||||||
|
{
|
||||||
|
mDatenbank.get().addOnCompleteListener(new OnCompleteListener<DataSnapshot>() {
|
||||||
|
@Override
|
||||||
|
public void onComplete(@NonNull Task<DataSnapshot> task) {
|
||||||
|
if (!task.isSuccessful()) {
|
||||||
|
Log.d(TAG,"Fehler in getDatafromDBnoListener" + task.getException());
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
setDatenBankInhalt(task.getResult());
|
||||||
|
initializeDataBase_ShockApplication_Main();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
//DatenBankInhalt wird bei Veränderung Aktualisiert
|
||||||
|
public void getDataBaseValuesWithListener()
|
||||||
|
{
|
||||||
|
mDatenbank.addValueEventListener(new ValueEventListener() {
|
||||||
|
@Override
|
||||||
|
public void onDataChange(@NonNull DataSnapshot snapshot) {
|
||||||
|
setDatenBankInhalt(snapshot);
|
||||||
|
//Geänderte DB schicken an SensorMapActivity
|
||||||
|
SensorMapsActivity sensor = new SensorMapsActivity();
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
public void onCancelled(@NonNull DatabaseError error) {
|
||||||
|
getDataBaseFailure(error);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public void getDataBaseFailure (DatabaseError error)
|
||||||
|
{
|
||||||
|
Log.w("Datenbankfehler", error.toException());
|
||||||
|
}
|
||||||
|
|
||||||
|
public void initializeDataBase_ShockApplication_Main()
|
||||||
|
{
|
||||||
|
if(getDatenBankInhalt().exists())
|
||||||
|
{
|
||||||
|
//Wenn DB schon exisitiert
|
||||||
|
if(getIfPureIDGareEmpty())
|
||||||
|
{
|
||||||
|
//Wenn IDG nocht KOMPLETT leer sind und keine weiteren Children haben
|
||||||
|
setEmptyDataInDBcompletly();
|
||||||
|
Log.d(TAG,"Datenbankzweig wurde für Anwendung angepasst. Weitermachen.");
|
||||||
|
}
|
||||||
|
}else
|
||||||
|
{
|
||||||
|
//Wenn DB nicht exisitert
|
||||||
|
setEmptyIDGinDBcomplety();
|
||||||
|
Log.d(TAG,"Datenbankzweig nicht existent. Dieser wurde angelgt. Neustart der App nötig");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public void setCommand()
|
||||||
|
{
|
||||||
|
setAndroidIDInDB(2,"hello");
|
||||||
|
setBreitengrad(2,15);
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getCommand()
|
||||||
|
{
|
||||||
|
getAndroidIDInDB(2);
|
||||||
|
getBreitengrad(2);
|
||||||
|
return getAndroidIDInDB(2) + getBreitengrad(2);
|
||||||
|
}
|
||||||
|
|
||||||
|
//########################################################################### Set / Get von IDGs
|
||||||
|
public void setEmptyDataInIDG(int i) //Setzt leere Strings children von IDGi
|
||||||
|
{
|
||||||
|
mDatenbank.child("IDG" + i).child("a_androidid").setValue("");
|
||||||
|
mDatenbank.child("IDG" + i).child("b_localdatetime").setValue("");
|
||||||
|
mDatenbank.child("IDG" + i).child("c_ip").setValue("");
|
||||||
|
mDatenbank.child("IDG" + i).child("d_breitengrad").setValue("");
|
||||||
|
mDatenbank.child("IDG" + i).child("e_laengengrad").setValue("");
|
||||||
|
mDatenbank.child("IDG" + i).child("f_nativegps").setValue("");
|
||||||
|
mDatenbank.child("IDG" + i).child("g_vibration").setValue("");
|
||||||
|
mDatenbank.child("IDG" + i).child("h_timestamp").setValue("");
|
||||||
|
mDatenbank.child("IDG" + i).child("i_amplitude").setValue("");
|
||||||
|
mDatenbank.child("IDG" + i).child("w_wellengeschwindigkeit").setValue("");
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean getStatusEmptyAboutIDG(int i) //Gibt true wenn IDG i leer ist
|
||||||
|
{
|
||||||
|
String androidid = getDatenBankInhalt().child("IDG" + i).child("a_androidid").getValue().toString();
|
||||||
|
String localdatetime = getDatenBankInhalt().child("IDG" + i).child("b_localdatetime").getValue().toString();
|
||||||
|
String ip = getDatenBankInhalt().child("IDG" + i).child("c_ip").getValue().toString();
|
||||||
|
String breitengrad = getDatenBankInhalt().child("IDG" + i).child("d_breitengrad").getValue().toString();
|
||||||
|
String laengengrad = getDatenBankInhalt().child("IDG" + i).child("e_laengengrad").getValue().toString();
|
||||||
|
String nativegps = getDatenBankInhalt().child("IDG" + i).child("f_nativegps").getValue().toString();
|
||||||
|
String vibration = getDatenBankInhalt().child("IDG" + i).child("g_vibration").getValue().toString();
|
||||||
|
String timestamp = getDatenBankInhalt().child("IDG" + i).child("h_timestamp").getValue().toString();
|
||||||
|
String amplitude = getDatenBankInhalt().child("IDG" + i).child("i_amplitude").getValue().toString();
|
||||||
|
String wellengeschwindigkeit = getDatenBankInhalt().child("IDG" + i).child("w_wellengeschwindigkeit").getValue().toString();
|
||||||
|
|
||||||
|
if(androidid.isEmpty() && localdatetime.isEmpty() && ip.isEmpty() && breitengrad.isEmpty() && laengengrad.isEmpty() && nativegps.isEmpty() && vibration.isEmpty() && timestamp.isEmpty() && amplitude.isEmpty() && wellengeschwindigkeit.isEmpty())
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}else
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean getStatusEmptyAboutIDGexceptNativeGPSandVibration(int i) //Gibt true wenn IDG i, bis auf nativegps und vibration, leer ist
|
||||||
|
{
|
||||||
|
String androidid = getDatenBankInhalt().child("IDG" + i).child("a_androidid").getValue().toString();
|
||||||
|
String localdatetime = getDatenBankInhalt().child("IDG" + i).child("b_localdatetime").getValue().toString();
|
||||||
|
String ip = getDatenBankInhalt().child("IDG" + i).child("c_ip").getValue().toString();
|
||||||
|
String breitengrad = getDatenBankInhalt().child("IDG" + i).child("d_breitengrad").getValue().toString();
|
||||||
|
String laengengrad = getDatenBankInhalt().child("IDG" + i).child("e_laengengrad").getValue().toString();
|
||||||
|
String timestamp = getDatenBankInhalt().child("IDG" + i).child("h_timestamp").getValue().toString();
|
||||||
|
String amplitude = getDatenBankInhalt().child("IDG" + i).child("i_amplitude").getValue().toString();
|
||||||
|
String wellengeschwindigkeit = getDatenBankInhalt().child("IDG" + i).child("w_wellengeschwindigkeit").getValue().toString();
|
||||||
|
|
||||||
|
if(androidid.isEmpty() && localdatetime.isEmpty() && ip.isEmpty() && breitengrad.isEmpty() && laengengrad.isEmpty() && timestamp.isEmpty() && amplitude.isEmpty() && wellengeschwindigkeit.isEmpty())
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}else
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean getStatusFullAboutIDG(int i) //Gibt true wenn IDG i voll ist
|
||||||
|
{
|
||||||
|
String androidid = getDatenBankInhalt().child("IDG" + i).child("a_androidid").getValue().toString();
|
||||||
|
String localdatetime = getDatenBankInhalt().child("IDG" + i).child("b_localdatetime").getValue().toString();
|
||||||
|
String ip = getDatenBankInhalt().child("IDG" + i).child("c_ip").getValue().toString();
|
||||||
|
String breitengrad = getDatenBankInhalt().child("IDG" + i).child("d_breitengrad").getValue().toString();
|
||||||
|
String laengengrad = getDatenBankInhalt().child("IDG" + i).child("e_laengengrad").getValue().toString();
|
||||||
|
String nativegps = getDatenBankInhalt().child("IDG" + i).child("f_nativegps").getValue().toString();
|
||||||
|
String vibration = getDatenBankInhalt().child("IDG" + i).child("g_vibration").getValue().toString();
|
||||||
|
String timestamp = getDatenBankInhalt().child("IDG" + i).child("h_timestamp").getValue().toString();
|
||||||
|
String amplitude = getDatenBankInhalt().child("IDG" + i).child("i_amplitude").getValue().toString();
|
||||||
|
String wellengeschwindigkeit = getDatenBankInhalt().child("IDG" + i).child("w_wellengeschwindigkeit").getValue().toString();
|
||||||
|
|
||||||
|
|
||||||
|
if(!androidid.isEmpty() && !localdatetime.isEmpty() && !ip.isEmpty() && !breitengrad.isEmpty() && !laengengrad.isEmpty() && !nativegps.isEmpty() && !vibration.isEmpty() && !timestamp.isEmpty() && !amplitude.isEmpty() && !wellengeschwindigkeit.isEmpty())
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}else
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//########################################################################### Set / Get von kompletter DB
|
||||||
|
public void setEmptyDataInDBcompletly() //Setzt leere Strings in alle children von allen IDGs
|
||||||
|
{
|
||||||
|
for (int i = 1; i<=getDatenBankInhalt().getChildrenCount(); i++)
|
||||||
|
{
|
||||||
|
mDatenbank.child("IDG" + i).child("a_androidid").setValue("");
|
||||||
|
mDatenbank.child("IDG" + i).child("b_localdatetime").setValue("");
|
||||||
|
mDatenbank.child("IDG" + i).child("c_ip").setValue("");
|
||||||
|
mDatenbank.child("IDG" + i).child("d_breitengrad").setValue("");
|
||||||
|
mDatenbank.child("IDG" + i).child("e_laengengrad").setValue("");
|
||||||
|
mDatenbank.child("IDG" + i).child("f_nativegps").setValue("");
|
||||||
|
mDatenbank.child("IDG" + i).child("g_vibration").setValue("");
|
||||||
|
mDatenbank.child("IDG" + i).child("h_timestamp").setValue("");
|
||||||
|
mDatenbank.child("IDG" + i).child("i_amplitude").setValue("");
|
||||||
|
mDatenbank.child("IDG" + i).child("w_wellengeschwindigkeit").setValue("");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setEmptyDataInDBcompletlyForNativeUse() //Setzt leere Strings in alle children von allen IDGs, wobei nativeGPS = true und vibration = false gesetzt werden
|
||||||
|
{
|
||||||
|
for (int i = 1; i<=getDatenBankInhalt().getChildrenCount(); i++)
|
||||||
|
{
|
||||||
|
mDatenbank.child("IDG" + i).child("a_androidid").setValue("");
|
||||||
|
mDatenbank.child("IDG" + i).child("b_localdatetime").setValue("");
|
||||||
|
mDatenbank.child("IDG" + i).child("c_ip").setValue("");
|
||||||
|
mDatenbank.child("IDG" + i).child("d_breitengrad").setValue("");
|
||||||
|
mDatenbank.child("IDG" + i).child("e_laengengrad").setValue("");
|
||||||
|
mDatenbank.child("IDG" + i).child("f_nativegps").setValue(true);
|
||||||
|
mDatenbank.child("IDG" + i).child("g_vibration").setValue(false);
|
||||||
|
mDatenbank.child("IDG" + i).child("h_timestamp").setValue("");
|
||||||
|
mDatenbank.child("IDG" + i).child("i_amplitude").setValue("");
|
||||||
|
mDatenbank.child("IDG" + i).child("w_wellengeschwindigkeit").setValue("");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean getStatusOnEmptyDBcomplety() //Gibt true wenn alle Strings aller IDGs leer sind
|
||||||
|
{
|
||||||
|
int emptyIDGs = 0;
|
||||||
|
for (int i = 1; i<=getDatenBankInhalt().getChildrenCount(); i++)
|
||||||
|
{
|
||||||
|
if(getStatusEmptyAboutIDG(i))
|
||||||
|
{
|
||||||
|
emptyIDGs++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(emptyIDGs == (int) getDatenBankInhalt().getChildrenCount())
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}else{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setVibrationInDBcompletly(boolean boolValue) //Setzt Vibration true/false in allen children aller IDGs
|
||||||
|
{
|
||||||
|
for (int i = 1; i<=getDatenBankInhalt().getChildrenCount(); i++)
|
||||||
|
{
|
||||||
|
mDatenbank.child("IDG" + i).child("g_vibration").setValue(boolValue);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setNativeGPSInDBcompletly(boolean boolValue) //Setzt nativeGPS true/false in allen children aller IDGs
|
||||||
|
{
|
||||||
|
for (int i = 1; i<=getDatenBankInhalt().getChildrenCount(); i++)
|
||||||
|
{
|
||||||
|
mDatenbank.child("IDG" + i).child("f_nativegps").setValue(boolValue);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public boolean getNativeGPScaseInDB() //Gibt true an, wenn in allen IDGs der wert nativeGPs true oder leer ist
|
||||||
|
{
|
||||||
|
int nativeGPS = 0;
|
||||||
|
for (int i = 1; i<=getAmountOfIDGs(); i++)
|
||||||
|
{
|
||||||
|
if(getDatenBankInhalt().child("IDG" + i).child("f_nativegps").getValue().toString().equals("true") || getDatenBankInhalt().child("IDG" + i).child("f_nativegps").getValue().toString().isEmpty())
|
||||||
|
{
|
||||||
|
nativeGPS++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(nativeGPS == getDatenBankInhalt().getChildrenCount())
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}else
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public boolean getIfPureIDGareEmpty() //Gibt true an, wenn alle IDGs komplett leer sind
|
||||||
|
{
|
||||||
|
int pureEmptyIDG = 0;
|
||||||
|
for (int i = 1; i<=getDatenBankInhalt().getChildrenCount(); i++)
|
||||||
|
{
|
||||||
|
if(getDatenBankInhalt().child("IDG" + i).getValue().toString().isEmpty())
|
||||||
|
{
|
||||||
|
pureEmptyIDG++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(pureEmptyIDG == getDatenBankInhalt().getChildrenCount())
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public void setNonNativeCaseInDB() //Setzt Musterwerte ein
|
||||||
|
{
|
||||||
|
Devices d1 = new Devices("","","",49.58967957913626,11.011387124069765,false,false,0,1000,10); //Erlangen 49.58967957913626, 11.011387124069765
|
||||||
|
Devices d2 = new Devices("","","",48.7560280895443,11.425157702952347,false,false,0,1000,10); //Ingolstadt 48.7560280895443, 11.425157702952347
|
||||||
|
Devices d3 = new Devices("","","",48.16958655466396,11.617418429524394,false,false,0,1000,10); //München 48.16958655466396, 11.617418429524394
|
||||||
|
Devices d4 = new Devices("","","",45.55620112204013,12.342516140205387,false,false,0,1000,10); //Venedig 45.55620112204013, 12.342516140205387
|
||||||
|
Devices d5 = new Devices("","","",41.9204784730154,12.651055829215638,false,false,0,1000,10); //Rom 41.9204784730154, 12.651055829215638
|
||||||
|
mDatenbank.child("IDG1").setValue(d1);
|
||||||
|
mDatenbank.child("IDG2").setValue(d2);
|
||||||
|
mDatenbank.child("IDG3").setValue(d3);
|
||||||
|
mDatenbank.child("IDG4").setValue(d4);
|
||||||
|
mDatenbank.child("IDG5").setValue(d4);
|
||||||
|
mDatenbank.child("IDG5").setValue(d5);
|
||||||
|
}
|
||||||
|
public void setEmptyIDGinDBcomplety() //Setzt leer IDGs in einen Dantenbankzweig
|
||||||
|
{
|
||||||
|
for (int i = 1; i<=5; i++)
|
||||||
|
{
|
||||||
|
mDatenbank.child("IDG" + i).setValue("");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//########################################################################### Allgemeine Getter und Setter
|
||||||
|
|
||||||
|
|
||||||
|
public long getAmountOfIDGs() //Gibt Anzahl der Children an
|
||||||
|
{
|
||||||
|
return getDatenBankInhalt().getChildrenCount();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setIDGtoDevice(int i, Devices dev) //Gibt Anzahl der Children an
|
||||||
|
{
|
||||||
|
mDatenbank.child("IDG" + i).setValue(dev);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//Get-Set AndroidID
|
||||||
|
public void setAndroidIDInDB(int i, String andoridID)
|
||||||
|
{
|
||||||
|
mDatenbank.child("IDG" + i).child("a_androidid").setValue(andoridID);
|
||||||
|
}
|
||||||
|
public String getAndroidIDInDB(int i)
|
||||||
|
{
|
||||||
|
return getDatenBankInhalt().child("IDG" + i).child("a_androidid").getValue().toString();
|
||||||
|
}
|
||||||
|
public boolean getAndroidIDisEmpty(int i)
|
||||||
|
{
|
||||||
|
if(getDatenBankInhalt().child("IDG" + i).child("a_androidid").getValue().toString().isEmpty())
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}else
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public boolean getStatusIFAndroidIDexistsInDB(String androidID)
|
||||||
|
{
|
||||||
|
boolean androidIDexists;
|
||||||
|
for (int i = 1; i<=getAmountOfIDGs(); i++)
|
||||||
|
{
|
||||||
|
if(getDatenBankInhalt().child("IDG" + i).child("a_androidid").getValue().toString().equals(getMyAndroidID()))
|
||||||
|
{
|
||||||
|
androidIDexists = true;
|
||||||
|
return androidIDexists;
|
||||||
|
}else
|
||||||
|
{
|
||||||
|
if(i == (int) getAmountOfIDGs())
|
||||||
|
{
|
||||||
|
androidIDexists = false;
|
||||||
|
return androidIDexists;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
//Get-Set LocalDatetime
|
||||||
|
public void setLocalDateTimeInDB(int i, String localdatetime)
|
||||||
|
{
|
||||||
|
mDatenbank.child("IDG" + i).child("b_localdatetime").setValue(localdatetime);
|
||||||
|
}
|
||||||
|
public String getLocalDateTimeInDB(int i)
|
||||||
|
{
|
||||||
|
return getDatenBankInhalt().child("IDG" + i).child("b_localdatetime").getValue().toString();
|
||||||
|
}
|
||||||
|
public boolean getLocalDateTimeIsEmpty(int i)
|
||||||
|
{
|
||||||
|
if(getDatenBankInhalt().child("IDG" + i).child("b_localdatetime").getValue().toString().isEmpty())
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}else
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//Get-Set IP
|
||||||
|
public void setIPInDB(int i, String ipAdress)
|
||||||
|
{
|
||||||
|
mDatenbank.child("IDG" + i).child("c_ip").setValue(ipAdress);
|
||||||
|
}
|
||||||
|
public String getIPInDB(int i)
|
||||||
|
{
|
||||||
|
return getDatenBankInhalt().child("IDG" + i).child("c_ip").getValue().toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
//Get-Set Breitengrad
|
||||||
|
public void setBreitengrad(int i, double breitengrad)
|
||||||
|
{
|
||||||
|
mDatenbank.child("IDG" + i).child("d_breitengrad").setValue(breitengrad);
|
||||||
|
}
|
||||||
|
public String getBreitengrad(int i)
|
||||||
|
{
|
||||||
|
return getDatenBankInhalt().child("IDG" + i).child("d_breitengrad").getValue().toString();
|
||||||
|
}
|
||||||
|
public boolean getBreitengradIsEmpty(int i)
|
||||||
|
{
|
||||||
|
if(getDatenBankInhalt().child("IDG" + i).child("d_breitengrad").getValue().toString().isEmpty())
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}else
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//Get-Set Laengengrad
|
||||||
|
public void setLaengengrad(int i, double laengengrad)
|
||||||
|
{
|
||||||
|
mDatenbank.child("IDG" + i).child("e_laengengrad").setValue(laengengrad);
|
||||||
|
}
|
||||||
|
public String getLaengengrad(int i)
|
||||||
|
{
|
||||||
|
return getDatenBankInhalt().child("IDG" + i).child("e_laengengrad").getValue().toString();
|
||||||
|
}
|
||||||
|
public boolean getLaengengradIsEmpty(int i)
|
||||||
|
{
|
||||||
|
if(getDatenBankInhalt().child("IDG" + i).child("e_laengengrad").getValue().toString().isEmpty())
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}else
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//Set GPS
|
||||||
|
public void setBreitengradUndLaengengrad(int i, double breitengrad, double laengengrad)
|
||||||
|
{
|
||||||
|
mDatenbank.child("IDG" + i).child("d_breitengrad").setValue(breitengrad);
|
||||||
|
mDatenbank.child("IDG" + i).child("e_laengengrad").setValue(laengengrad);
|
||||||
|
}
|
||||||
|
|
||||||
|
//Get-Set NativeGPS
|
||||||
|
public void setNativeGPS(int i, boolean nativegps)
|
||||||
|
{
|
||||||
|
mDatenbank.child("IDG" + i).child("f_nativegps").setValue(nativegps);
|
||||||
|
}
|
||||||
|
public String getNativeGPS(int i)
|
||||||
|
{
|
||||||
|
return getDatenBankInhalt().child("IDG" + i).child("f_nativegps").getValue().toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
//Get-Set Vibration
|
||||||
|
public void setVibration(int i, boolean vibration)
|
||||||
|
{
|
||||||
|
mDatenbank.child("IDG" + i).child("g_vibration").setValue(vibration);
|
||||||
|
}
|
||||||
|
public String getVibration(int i)
|
||||||
|
{
|
||||||
|
return getDatenBankInhalt().child("IDG" + i).child("g_vibration").getValue().toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
//Get-Set timestamp
|
||||||
|
public void setTimestamp(int i, long timestamp)
|
||||||
|
{
|
||||||
|
mDatenbank.child("IDG" + i).child("h_timestamp").setValue(timestamp);
|
||||||
|
}
|
||||||
|
public String getTimestamp(int i)
|
||||||
|
{
|
||||||
|
return getDatenBankInhalt().child("IDG" + i).child("h_timestamp").getValue().toString();
|
||||||
|
}
|
||||||
|
public boolean getTimestampIsEmpty(int i)
|
||||||
|
{
|
||||||
|
if(getDatenBankInhalt().child("IDG" + i).child("h_timestamp").getValue().toString().isEmpty())
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}else
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//Get-Set Amplitude
|
||||||
|
public void setAmplitude(int i, int amplitude)
|
||||||
|
{
|
||||||
|
mDatenbank.child("IDG" + i).child("i_amplitude").setValue(amplitude);
|
||||||
|
}
|
||||||
|
public String getAmplitude(int i)
|
||||||
|
{
|
||||||
|
return getDatenBankInhalt().child("IDG" + i).child("i_amplitude").getValue().toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
//Get-Set Wellengeschwindigkeit
|
||||||
|
public void setWellengeschwindigkeit(int i, int wellengeschwindigkeit)
|
||||||
|
{
|
||||||
|
mDatenbank.child("IDG" + i).child("w_wellengeschwindigkeit").setValue(wellengeschwindigkeit);
|
||||||
|
}
|
||||||
|
public String getWellengeschwindigkeit(int i)
|
||||||
|
{
|
||||||
|
return getDatenBankInhalt().child("IDG" + i).child("w_wellengeschwindigkeit").getValue().toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
//########################################################################### Sontiges
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//########################################################################### Contruktor Getter und Setter
|
||||||
|
public String getA_androidid() {
|
||||||
|
return a_androidid;
|
||||||
|
}
|
||||||
|
public void setA_androidid(String a_androidid) {
|
||||||
|
this.a_androidid = a_androidid;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getB_localdatetime() {
|
||||||
|
return b_localdatetime;
|
||||||
|
}
|
||||||
|
public void setB_localdatetime(String b_localdatetime) {
|
||||||
|
this.b_localdatetime = b_localdatetime;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getC_ip() {
|
||||||
|
return c_ip;
|
||||||
|
}
|
||||||
|
public void setC_ip(String c_ip) {
|
||||||
|
this.c_ip = c_ip;
|
||||||
|
}
|
||||||
|
|
||||||
|
public double getD_breitengrad() {
|
||||||
|
return d_breitengrad;
|
||||||
|
}
|
||||||
|
public void setD_breitengrad(double d_breitengrad) {
|
||||||
|
this.d_breitengrad = d_breitengrad;
|
||||||
|
}
|
||||||
|
|
||||||
|
public double getE_laengengrad() {
|
||||||
|
return e_laengengrad;
|
||||||
|
}
|
||||||
|
public void setE_laengengrad(double e_laengengrad) {
|
||||||
|
this.e_laengengrad = e_laengengrad;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isF_nativegps() {
|
||||||
|
return f_nativegps;
|
||||||
|
}
|
||||||
|
public void setF_nativegps(boolean f_nativegps) {
|
||||||
|
this.f_nativegps = f_nativegps;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isG_vibration() {
|
||||||
|
return g_vibration;
|
||||||
|
}
|
||||||
|
public void setG_vibration(boolean g_vibration) {
|
||||||
|
this.g_vibration = g_vibration;
|
||||||
|
}
|
||||||
|
|
||||||
|
public long getH_timestamp() {
|
||||||
|
return h_timestamp;
|
||||||
|
}
|
||||||
|
public void setH_timestamp(long h_timestamp) {
|
||||||
|
this.h_timestamp = h_timestamp;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getI_amplitude() {
|
||||||
|
return i_amplitude;
|
||||||
|
}
|
||||||
|
public void setI_amplitude(int i_amplitude) {
|
||||||
|
this.i_amplitude = i_amplitude;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getW_wellengeschwindigkeit() {
|
||||||
|
return w_wellengeschwindigkeit;
|
||||||
|
}
|
||||||
|
public void setW_wellengeschwindigkeit(int w_wellengeschwindigkeit) {
|
||||||
|
this.w_wellengeschwindigkeit = w_wellengeschwindigkeit;
|
||||||
|
}
|
||||||
|
|
||||||
|
public DataSnapshot getDatenBankInhalt() {
|
||||||
|
return DatenBankInhalt;
|
||||||
|
|
||||||
|
}
|
||||||
|
public void setDatenBankInhalt(DataSnapshot datenBankInhalt) {
|
||||||
|
DatenBankInhalt = datenBankInhalt;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getMyAndroidID() {
|
||||||
|
return myAndroidID;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setMyAndroidID(String myAndroidID) {
|
||||||
|
this.myAndroidID = myAndroidID;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getMyWaveSpeed() {
|
||||||
|
return myWaveSpeed;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setMyWaveSpeed(int myWaveSpeed) {
|
||||||
|
this.myWaveSpeed = myWaveSpeed;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getMyIPadress() {
|
||||||
|
return myIPadress;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setMyIPadress(String myIPadress) {
|
||||||
|
this.myIPadress = myIPadress;
|
||||||
|
}
|
||||||
|
|
||||||
|
public double getShakeBreitengrad() {
|
||||||
|
return shakeBreitengrad;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setShakeBreitengrad(double shakeBreitengrad) {
|
||||||
|
this.shakeBreitengrad = shakeBreitengrad;
|
||||||
|
}
|
||||||
|
|
||||||
|
public double getShakeLaengengrad() {
|
||||||
|
return shakeLaengengrad;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setShakeLaengengrad(double shakeLaengengrad) {
|
||||||
|
this.shakeLaengengrad = shakeLaengengrad;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -3,84 +3,112 @@ package de.edotzlaff.schockwelle;
|
|||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
|
|
||||||
public class Devices {
|
public class Devices {
|
||||||
private String ip;
|
private String a_androidid;
|
||||||
private boolean vibration;
|
private String b_localdatetime;
|
||||||
private long timestamp;
|
private String c_ip;
|
||||||
private double breitengrad;
|
private double d_breitengrad;
|
||||||
private double laengengrad;
|
private double e_laengengrad;
|
||||||
private int amplitude;
|
private boolean f_nativegps;
|
||||||
private String localdatetime;
|
private boolean g_vibration;
|
||||||
private boolean idvergeben;
|
private long h_timestamp;
|
||||||
private String androidid;
|
private int i_amplitude;
|
||||||
|
private int w_wellengeschwindigkeit;
|
||||||
|
|
||||||
|
|
||||||
public Devices() {
|
public Devices() {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Devices(String ip, boolean vibration, long timestamp, double breitengrad, double laengengrad, int amplitude, String localdatetime, String androidid) {
|
public Devices(String a_androidid, String b_localdatetime, String c_ip, double d_breitengrad, double e_laengengrad, boolean f_nativegps, boolean g_vibration, long h_timestamp, int i_amplitude, int w_wellengeschwindigkeit) {
|
||||||
this.ip = ip;
|
this.a_androidid = a_androidid;
|
||||||
this.vibration = vibration;
|
this.b_localdatetime = b_localdatetime;
|
||||||
this.timestamp = timestamp;
|
this.c_ip = c_ip;
|
||||||
this.breitengrad = breitengrad;
|
this.d_breitengrad = d_breitengrad;
|
||||||
this.laengengrad = laengengrad;
|
this.e_laengengrad = e_laengengrad;
|
||||||
this.amplitude = amplitude;
|
this.f_nativegps = f_nativegps;
|
||||||
this.localdatetime = localdatetime;
|
this.g_vibration = g_vibration;
|
||||||
this.androidid = androidid;
|
this.h_timestamp = h_timestamp;
|
||||||
|
this.i_amplitude = i_amplitude;
|
||||||
|
this.w_wellengeschwindigkeit = w_wellengeschwindigkeit;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getIp() {
|
public String getA_androidid() {
|
||||||
return ip;
|
return a_androidid;
|
||||||
}
|
|
||||||
public void setIp(String ip) {
|
|
||||||
this.ip = ip;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isVibration() {
|
public void setA_androidid(String a_androidid) {
|
||||||
return vibration;
|
this.a_androidid = a_androidid;
|
||||||
}
|
|
||||||
public void setVibration(boolean vibration) {
|
|
||||||
this.vibration = vibration;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public long getTimestamp() {
|
public String getB_localdatetime() {
|
||||||
return timestamp;
|
return b_localdatetime;
|
||||||
}
|
|
||||||
public void setTimestamp(long timestamp) {
|
|
||||||
this.timestamp = timestamp;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public double getBreitengrad() {
|
public void setB_localdatetime(String b_localdatetime) {
|
||||||
return breitengrad;
|
this.b_localdatetime = b_localdatetime;
|
||||||
}
|
|
||||||
public void setBreitengrad(double breitengrad) {
|
|
||||||
this.breitengrad = breitengrad;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public double getLaengengrad() {
|
public String getC_ip() {
|
||||||
return laengengrad;
|
return c_ip;
|
||||||
}
|
|
||||||
public void setLaengengrad(double laengengrad) {
|
|
||||||
this.laengengrad = laengengrad;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getAmplitude() {
|
public void setC_ip(String c_ip) {
|
||||||
return amplitude;
|
this.c_ip = c_ip;
|
||||||
}
|
|
||||||
public void setAmplitude(int amplitude) {
|
|
||||||
this.amplitude = amplitude;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getLocaldatetime() {
|
public double getD_breitengrad() {
|
||||||
return localdatetime;
|
return d_breitengrad;
|
||||||
}
|
|
||||||
public void setLocaldatetime(String localdatetime) {
|
|
||||||
this.localdatetime = localdatetime;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getAndroidid() {
|
public void setD_breitengrad(double d_breitengrad) {
|
||||||
return androidid;
|
this.d_breitengrad = d_breitengrad;
|
||||||
}
|
}
|
||||||
public void setAndroidid(String androidid) {
|
|
||||||
this.androidid = androidid;
|
public double getE_laengengrad() {
|
||||||
|
return e_laengengrad;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setE_laengengrad(double e_laengengrad) {
|
||||||
|
this.e_laengengrad = e_laengengrad;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isF_nativegps() {
|
||||||
|
return f_nativegps;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setF_nativegps(boolean f_nativegps) {
|
||||||
|
this.f_nativegps = f_nativegps;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isG_vibration() {
|
||||||
|
return g_vibration;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setG_vibration(boolean g_vibration) {
|
||||||
|
this.g_vibration = g_vibration;
|
||||||
|
}
|
||||||
|
|
||||||
|
public long getH_timestamp() {
|
||||||
|
return h_timestamp;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setH_timestamp(long h_timestamp) {
|
||||||
|
this.h_timestamp = h_timestamp;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getI_amplitude() {
|
||||||
|
return i_amplitude;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setI_amplitude(int i_amplitude) {
|
||||||
|
this.i_amplitude = i_amplitude;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getW_wellengeschwindigkeit() {
|
||||||
|
return w_wellengeschwindigkeit;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setW_wellengeschwindigkeit(int w_wellengeschwindigkeit) {
|
||||||
|
this.w_wellengeschwindigkeit = w_wellengeschwindigkeit;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -21,6 +21,7 @@ import android.widget.TextView;
|
|||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
|
import androidx.annotation.RequiresApi;
|
||||||
import androidx.core.app.ActivityCompat;
|
import androidx.core.app.ActivityCompat;
|
||||||
import androidx.core.content.ContextCompat;
|
import androidx.core.content.ContextCompat;
|
||||||
import androidx.fragment.app.FragmentActivity;
|
import androidx.fragment.app.FragmentActivity;
|
||||||
@@ -42,6 +43,7 @@ import com.google.firebase.database.FirebaseDatabase;
|
|||||||
import com.google.firebase.database.ValueEventListener;
|
import com.google.firebase.database.ValueEventListener;
|
||||||
|
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
|
import java.time.ZoneOffset;
|
||||||
import java.util.Calendar;
|
import java.util.Calendar;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
@@ -54,6 +56,7 @@ public class EarthquakeMapsActivity extends FragmentActivity implements OnMapRea
|
|||||||
private Boolean mLocationPermissionsGranted = false;
|
private Boolean mLocationPermissionsGranted = false;
|
||||||
private GoogleMap mMap;
|
private GoogleMap mMap;
|
||||||
private FusedLocationProviderClient mFusedLocationProviderClient;
|
private FusedLocationProviderClient mFusedLocationProviderClient;
|
||||||
|
Datenbank db = new Datenbank();
|
||||||
|
|
||||||
Long currentTime;
|
Long currentTime;
|
||||||
Location currentLocation;
|
Location currentLocation;
|
||||||
@@ -63,18 +66,21 @@ public class EarthquakeMapsActivity extends FragmentActivity implements OnMapRea
|
|||||||
private boolean useOwnGPS;
|
private boolean useOwnGPS;
|
||||||
private int indexID = 1;
|
private int indexID = 1;
|
||||||
|
|
||||||
|
|
||||||
//##########################################################################################################################################################################
|
//##########################################################################################################################################################################
|
||||||
//################################################################## vvv ShakeParameter vvv ##############################################################################
|
//################################################################## vvv ShakeParameter vvv ##############################################################################
|
||||||
private SensorManager mSensorManager;
|
private SensorManager mSensorManager;
|
||||||
private static final float mUpperThreshold = 10.5f; // für Emulator auf 1.5 setzen
|
private static final float mUpperThreshold = 10.5f; // für Emulator auf 1.5 setzen TODO Aron
|
||||||
private static final float mLowerThreshold = 5.5f; // für Emulator auf 0.5 setzen
|
private static final float mLowerThreshold = 5.5f; // für Emulator auf 0.5 setzen TODO Aron
|
||||||
|
//private static final float mUpperThreshold = 10.5f; // für Emulator auf 1.5 setzen TODO Aron
|
||||||
|
//private static final float mLowerThreshold = 5.5f; // für Emulator auf 0.5 setzen TODO Aron
|
||||||
private static final long mShakeDetectionLockTimeMicroSeconds = 10000;
|
private static final long mShakeDetectionLockTimeMicroSeconds = 10000;
|
||||||
private float mAccel;
|
private float mAccel;
|
||||||
private float mAccelCurrent;
|
private float mAccelCurrent;
|
||||||
private float mAccelLast;
|
private float mAccelLast;
|
||||||
private boolean mShakeDetectionIsActive = false;
|
private boolean mShakeDetectionIsActive = false;
|
||||||
private boolean mShakeDetected = false;
|
private boolean mShakeDetected = false;
|
||||||
//private boolean allowShakeEvent = true;
|
private boolean allowShakeEvent = true;
|
||||||
//################################################################## ^^^^ ShakeParameter ^^^^ ############################################################################
|
//################################################################## ^^^^ ShakeParameter ^^^^ ############################################################################
|
||||||
//##########################################################################################################################################################################
|
//##########################################################################################################################################################################
|
||||||
|
|
||||||
@@ -84,7 +90,15 @@ public class EarthquakeMapsActivity extends FragmentActivity implements OnMapRea
|
|||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
setContentView(R.layout.activity_earthquake_maps);
|
setContentView(R.layout.activity_earthquake_maps);
|
||||||
|
|
||||||
getDataBaseValuesNoListener();
|
//Database Init
|
||||||
|
db.setMyWaveSpeed(500);
|
||||||
|
db.setMyAndroidID(Settings.Secure.getString(this.getContentResolver(), Settings.Secure.ANDROID_ID));
|
||||||
|
WifiManager wm = (WifiManager) getApplicationContext().getSystemService(WIFI_SERVICE);
|
||||||
|
int ip = wm.getConnectionInfo().getIpAddress();
|
||||||
|
db.setMyIPadress(String.format("%d.%d.%d.%d",(ip & 0xff),(ip >> 8 & 0xff),(ip >> 16 & 0xff), (ip >> 24 & 0xff)));
|
||||||
|
db.getDatafromDBnoListener();
|
||||||
|
db.getDataBaseValuesWithListener();
|
||||||
|
|
||||||
sensorManagementInit();
|
sensorManagementInit();
|
||||||
getLocationPermission();
|
getLocationPermission();
|
||||||
}
|
}
|
||||||
@@ -142,12 +156,13 @@ public class EarthquakeMapsActivity extends FragmentActivity implements OnMapRea
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@RequiresApi(api = Build.VERSION_CODES.O)
|
||||||
public void onFinish() {
|
public void onFinish() {
|
||||||
if (Math.abs(mAccel) > mUpperThreshold) {
|
if (Math.abs(mAccel) > mUpperThreshold) {
|
||||||
mShakeDetectionIsActive = false;
|
mShakeDetectionIsActive = false;
|
||||||
mShakeDetected = true;
|
mShakeDetected = true;
|
||||||
Toast.makeText(getApplicationContext(), "Shake event detected", Toast.LENGTH_SHORT).show();
|
Toast.makeText(getApplicationContext(), "Shake event detected", Toast.LENGTH_SHORT).show();
|
||||||
writeEarthquakeToDatabase();
|
writeEarthquakeToDatabase(); //TODO Aron
|
||||||
mLockTimer.start();
|
mLockTimer.start();
|
||||||
} else {
|
} else {
|
||||||
mShakeDetectionIsActive = true;
|
mShakeDetectionIsActive = true;
|
||||||
@@ -163,15 +178,10 @@ public class EarthquakeMapsActivity extends FragmentActivity implements OnMapRea
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
private void writeEarthquakeToDatabase()
|
|
||||||
{
|
|
||||||
setDataBaseValues();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onResume() {
|
protected void onResume() {
|
||||||
mSensorManager.registerListener(mSensorListener, mSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER),
|
mSensorManager.registerListener(mSensorListener, mSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER), SensorManager.SENSOR_DELAY_NORMAL);
|
||||||
SensorManager.SENSOR_DELAY_NORMAL);
|
|
||||||
super.onResume();
|
super.onResume();
|
||||||
}
|
}
|
||||||
@Override
|
@Override
|
||||||
@@ -199,7 +209,6 @@ public class EarthquakeMapsActivity extends FragmentActivity implements OnMapRea
|
|||||||
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
|
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
|
||||||
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
|
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
|
||||||
mLocationPermissionsGranted = false;
|
mLocationPermissionsGranted = false;
|
||||||
|
|
||||||
switch (requestCode) {
|
switch (requestCode) {
|
||||||
case LOCATION_PERMISSION_REQUEST_CODE: {
|
case LOCATION_PERMISSION_REQUEST_CODE: {
|
||||||
if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
|
if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
|
||||||
@@ -231,7 +240,8 @@ public class EarthquakeMapsActivity extends FragmentActivity implements OnMapRea
|
|||||||
mMap.setMyLocationEnabled(true);
|
mMap.setMyLocationEnabled(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add a marker in Sydney and move the camera
|
//TODO @ Eddy: Ich denke diesen Code brauchst du auch, oder? :D
|
||||||
|
//Add a marker in Sydney and move the camera
|
||||||
//LatLng sydney = new LatLng(-34, 151);
|
//LatLng sydney = new LatLng(-34, 151);
|
||||||
//mMap.addMarker(new MarkerOptions().position(sydney).title("Marker in Sydney"));
|
//mMap.addMarker(new MarkerOptions().position(sydney).title("Marker in Sydney"));
|
||||||
//mMap.moveCamera(CameraUpdateFactory.newLatLng(sydney));
|
//mMap.moveCamera(CameraUpdateFactory.newLatLng(sydney));
|
||||||
@@ -249,17 +259,28 @@ public class EarthquakeMapsActivity extends FragmentActivity implements OnMapRea
|
|||||||
public void onComplete(@NonNull Task task) {
|
public void onComplete(@NonNull Task task) {
|
||||||
if (task.isSuccessful()){
|
if (task.isSuccessful()){
|
||||||
currentLocation = (Location) task.getResult();
|
currentLocation = (Location) task.getResult();
|
||||||
//currentTime = Calendar.getInstance().getTimeInMillis(); //verschoben in setDataBaseValues
|
System.out.println(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>" + db.getNativeGPScaseInDB());
|
||||||
//Toast.makeText(EarthquakeMapsActivity.this, currentTime.toString(), Toast.LENGTH_SHORT).show(); //verschoben in setDataBaseValues
|
|
||||||
if(useOwnGPS)
|
if(db.getNativeGPScaseInDB())
|
||||||
|
{
|
||||||
|
System.out.println("---Eigene GPS Daten werden verwendet");
|
||||||
|
breitengrad = currentLocation.getLatitude();
|
||||||
|
laengengrad = currentLocation.getLongitude();
|
||||||
|
db.setShakeBreitengrad(breitengrad);
|
||||||
|
db.setShakeLaengengrad(laengengrad);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
if(useOwnGPS) //TODO Aron
|
||||||
{
|
{
|
||||||
breitengrad = currentLocation.getLatitude();
|
breitengrad = currentLocation.getLatitude();
|
||||||
laengengrad = currentLocation.getLongitude();
|
laengengrad = currentLocation.getLongitude();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
*/
|
||||||
currentLocation.setLatitude(breitengrad);
|
currentLocation.setLatitude(breitengrad);
|
||||||
currentLocation.setLongitude(laengengrad);
|
currentLocation.setLongitude(laengengrad);
|
||||||
moveCamera(new LatLng(currentLocation.getLatitude(), currentLocation.getLongitude()),15f);
|
moveCamera(new LatLng(currentLocation.getLatitude(), currentLocation.getLongitude()),15f);
|
||||||
//setDataBaseValues(); //Wurde verschoben zu Methode writeEarthquakeToDatabase
|
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
Toast.makeText(EarthquakeMapsActivity.this, "Current Location unavailable", Toast.LENGTH_SHORT).show();
|
Toast.makeText(EarthquakeMapsActivity.this, "Current Location unavailable", Toast.LENGTH_SHORT).show();
|
||||||
@@ -282,137 +303,53 @@ public class EarthquakeMapsActivity extends FragmentActivity implements OnMapRea
|
|||||||
|
|
||||||
//#####################################################################################################################################################################
|
//#####################################################################################################################################################################
|
||||||
//################################################################## vvv Datenbank Code vvv #########################################################################
|
//################################################################## vvv Datenbank Code vvv #########################################################################
|
||||||
|
@RequiresApi(api = Build.VERSION_CODES.O)
|
||||||
public void getDataBaseValuesNoListener()
|
private void writeEarthquakeToDatabase()
|
||||||
{
|
{
|
||||||
mDatenbank = FirebaseDatabase.getInstance().getReference();
|
|
||||||
mDatenbank.child("overviewAronTestetInDiesemAbschnitt").get().addOnCompleteListener(new OnCompleteListener<DataSnapshot>() {
|
|
||||||
@Override
|
|
||||||
public void onComplete(@NonNull Task<DataSnapshot> task) {
|
|
||||||
if (!task.isSuccessful()) {
|
|
||||||
System.out.println("Datenbankfehler in getDataBaseValuesNoListener");
|
|
||||||
System.out.println("Error getting data: " + task.getException());
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
processDataBaseValues(task.getResult());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
public void processDataBaseValues (DataSnapshot data)
|
boolean nativeGPS;
|
||||||
{
|
if(db.getNativeGPScaseInDB())
|
||||||
processDeviceIndex(data);
|
|
||||||
processLocation(data);
|
|
||||||
//processMessageDisplay(data);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void processDeviceIndex(DataSnapshot data)
|
|
||||||
{
|
|
||||||
for (int i = 1; i<=4; i++)
|
|
||||||
{
|
{
|
||||||
String androidid = data.child("IDG" + i).child("androidid").getValue().toString();
|
nativeGPS = true;
|
||||||
if(androidid.isEmpty())
|
|
||||||
{
|
|
||||||
indexID = i;
|
|
||||||
break;
|
|
||||||
}else
|
|
||||||
{
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void processLocation(DataSnapshot data)
|
|
||||||
{
|
|
||||||
String breitengradString = data.child("IDG" + indexID).child("breitengrad").getValue().toString();
|
|
||||||
String laengengradString = data.child("IDG" + indexID).child("laengengrad").getValue().toString();
|
|
||||||
|
|
||||||
if(breitengradString.isEmpty() || laengengradString.isEmpty())
|
|
||||||
{
|
|
||||||
useOwnGPS = true;
|
|
||||||
}else{
|
}else{
|
||||||
useOwnGPS = false;
|
nativeGPS = false;
|
||||||
breitengrad = Double.parseDouble(breitengradString);
|
|
||||||
laengengrad = Double.parseDouble(laengengradString);
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
public void processMessageDisplay(DataSnapshot data)
|
|
||||||
{
|
|
||||||
String vibrationString;
|
|
||||||
String androidid;
|
|
||||||
for (int i = 1; i<=4; i++)
|
|
||||||
{
|
|
||||||
androidid = data.child("overviewAronTestetInDiesemAbschnitt").child("IDG" + i).child("androidid").getValue().toString();
|
|
||||||
vibrationString = data.child("overviewAronTestetInDiesemAbschnitt").child("IDG" + i).child("vibration").getValue().toString();
|
|
||||||
if((!androidid.isEmpty()) && vibrationString.equals("true"))
|
|
||||||
{
|
|
||||||
allowShakeEvent = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
*/
|
|
||||||
|
|
||||||
public String getandroidid ()
|
///Evtl löschen und localDateTimeMod mit LocalDateTime.now(ZoneOffset.UTC).toString() ersetzen...
|
||||||
{
|
String localDateTimeMod;
|
||||||
return Settings.Secure.getString(this.getContentResolver(), Settings.Secure.ANDROID_ID);
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getDeviceIpAdress ()
|
|
||||||
{
|
|
||||||
WifiManager wm = (WifiManager) getApplicationContext().getSystemService(WIFI_SERVICE);
|
|
||||||
int ip = wm.getConnectionInfo().getIpAddress();
|
|
||||||
String ipAddress = String.format("%d.%d.%d.%d",(ip & 0xff),(ip >> 8 & 0xff),(ip >> 16 & 0xff), (ip >> 24 & 0xff));
|
|
||||||
return ipAddress;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setDataBaseValues()
|
|
||||||
{
|
|
||||||
mDatenbank = FirebaseDatabase.getInstance().getReference();
|
|
||||||
mDatenbank.child("overviewAronTestetInDiesemAbschnitt").child("IDG" + indexID).child("ip").setValue(getDeviceIpAdress());
|
|
||||||
mDatenbank.child("overviewAronTestetInDiesemAbschnitt").child("IDG" + indexID).child("vibration").setValue(true);
|
|
||||||
mDatenbank.child("overviewAronTestetInDiesemAbschnitt").child("IDG" + indexID).child("timestamp").setValue(Calendar.getInstance().getTimeInMillis());
|
|
||||||
|
|
||||||
currentTime = Calendar.getInstance().getTimeInMillis();
|
|
||||||
Toast.makeText(EarthquakeMapsActivity.this, currentTime.toString(), Toast.LENGTH_SHORT).show();
|
|
||||||
|
|
||||||
mDatenbank.child("overviewAronTestetInDiesemAbschnitt").child("IDG" + indexID).child("breitengrad").setValue(breitengrad);
|
|
||||||
mDatenbank.child("overviewAronTestetInDiesemAbschnitt").child("IDG" + indexID).child("laengengrad").setValue(laengengrad);
|
|
||||||
mDatenbank.child("overviewAronTestetInDiesemAbschnitt").child("IDG" + indexID).child("amplitude").setValue(1001);
|
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||||
mDatenbank.child("overviewAronTestetInDiesemAbschnitt").child("IDG" + indexID).child("localdatetime").setValue(LocalDateTime.now().toString());
|
localDateTimeMod = LocalDateTime.now(ZoneOffset.UTC).toString();
|
||||||
|
} else
|
||||||
|
{
|
||||||
|
localDateTimeMod = LocalDateTime.now(ZoneOffset.UTC).toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
for(int i=1; i<=db.getAmountOfIDGs(); i++)
|
||||||
|
{
|
||||||
|
if(!db.getStatusIFAndroidIDexistsInDB(db.getMyAndroidID()))
|
||||||
|
{
|
||||||
|
//Wenn eigenen androidID nicht in DB existiert
|
||||||
|
Devices d1 = new Devices();
|
||||||
|
d1 = new Devices(db.getMyAndroidID(),
|
||||||
|
localDateTimeMod,
|
||||||
|
db.getMyIPadress(),
|
||||||
|
breitengrad,
|
||||||
|
laengengrad,
|
||||||
|
nativeGPS,
|
||||||
|
true,
|
||||||
|
Calendar.getInstance().getTimeInMillis(),
|
||||||
|
1000,
|
||||||
|
db.getMyWaveSpeed());
|
||||||
|
|
||||||
|
db.setIDGtoDevice(i,d1);
|
||||||
|
break;
|
||||||
|
}else{
|
||||||
|
Toast.makeText(getApplicationContext(), "Gerät ist bereits in DB eingetragen!", Toast.LENGTH_SHORT).show();
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
mDatenbank.child("overviewAronTestetInDiesemAbschnitt").child("IDG" + indexID).child("androidid").setValue(getandroidid());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//################################################################## ^^^^ Datenbank Code ^^^^ #############################################################################
|
|
||||||
//###########################################################################################################################################################################
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//Evtl. Redundanter Code
|
|
||||||
/*
|
|
||||||
public void getDataBaseValues()
|
|
||||||
{
|
|
||||||
mDatenbank = FirebaseDatabase.getInstance().getReference();
|
|
||||||
mDatenbank.addValueEventListener(new ValueEventListener() {
|
|
||||||
@Override
|
|
||||||
public void onDataChange(@NonNull DataSnapshot snapshot) {
|
|
||||||
processDataBaseValues(snapshot); //Daten Snapshot, Übergabe an processDataBaseValues
|
|
||||||
}
|
|
||||||
@Override
|
|
||||||
public void onCancelled(@NonNull DatabaseError error) {
|
|
||||||
getDataBaseFailure(error);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
public void getDataBaseFailure (DatabaseError error)
|
|
||||||
{
|
|
||||||
System.out.println("Datenbankfehler in gerDataBaseFailure");
|
|
||||||
Log.w("Datenbankfehler", error.toException());
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
@@ -1,43 +1,31 @@
|
|||||||
package de.edotzlaff.schockwelle;
|
package de.edotzlaff.schockwelle;
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
import androidx.annotation.RequiresApi;
|
|
||||||
import androidx.appcompat.app.AppCompatActivity;
|
|
||||||
import androidx.fragment.app.FragmentActivity;
|
import androidx.fragment.app.FragmentActivity;
|
||||||
|
|
||||||
import android.app.ActionBar;
|
|
||||||
import android.app.Dialog;
|
import android.app.Dialog;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.hardware.Sensor;
|
import android.net.wifi.WifiManager;
|
||||||
import android.os.Build;
|
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.provider.Settings;
|
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;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
|
||||||
import com.google.android.gms.common.ConnectionResult;
|
import com.google.android.gms.common.ConnectionResult;
|
||||||
import com.google.android.gms.common.GoogleApiAvailability;
|
import com.google.android.gms.common.GoogleApiAvailability;
|
||||||
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.DataSnapshot;
|
||||||
import com.google.firebase.database.DatabaseError;
|
|
||||||
import com.google.firebase.database.DatabaseReference;
|
import com.google.firebase.database.DatabaseReference;
|
||||||
import com.google.firebase.database.FirebaseDatabase;
|
import com.google.firebase.database.FirebaseDatabase;
|
||||||
import com.google.firebase.database.ValueEventListener;
|
|
||||||
|
|
||||||
import java.time.LocalDateTime;
|
|
||||||
import java.time.format.DateTimeFormatter;
|
|
||||||
import java.util.Calendar;
|
|
||||||
|
|
||||||
public class MainActivity extends FragmentActivity {
|
public class MainActivity extends FragmentActivity {
|
||||||
|
|
||||||
private static final String TAG = "MainActivity";
|
private static final String TAG = "MainActivity";
|
||||||
private static final int ERROR_DIALOG_REQUEST = 9001;
|
private static final int ERROR_DIALOG_REQUEST = 9001;
|
||||||
private DatabaseReference mDatenbank;
|
private DatabaseReference mDatenbank;
|
||||||
String android_id;
|
Datenbank db = new Datenbank();
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
@@ -45,6 +33,17 @@ public class MainActivity extends FragmentActivity {
|
|||||||
setContentView(R.layout.activity_main);
|
setContentView(R.layout.activity_main);
|
||||||
|
|
||||||
if (isServiceOK()){
|
if (isServiceOK()){
|
||||||
|
//Für Dantenbank
|
||||||
|
|
||||||
|
db.setMyWaveSpeed(500);
|
||||||
|
db.setMyAndroidID(Settings.Secure.getString(this.getContentResolver(), Settings.Secure.ANDROID_ID));
|
||||||
|
|
||||||
|
WifiManager wm = (WifiManager) getApplicationContext().getSystemService(WIFI_SERVICE);
|
||||||
|
int ip = wm.getConnectionInfo().getIpAddress();
|
||||||
|
db.setMyIPadress(String.format("%d.%d.%d.%d",(ip & 0xff),(ip >> 8 & 0xff),(ip >> 16 & 0xff), (ip >> 24 & 0xff)));
|
||||||
|
|
||||||
|
db.getDatafromDBnoListener();
|
||||||
|
|
||||||
init();
|
init();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -57,24 +56,24 @@ public class MainActivity extends FragmentActivity {
|
|||||||
Button btnLeer = (Button) findViewById(R.id.buttonDatenBankLeeren);
|
Button btnLeer = (Button) findViewById(R.id.buttonDatenBankLeeren);
|
||||||
Button btnReset = (Button) findViewById(R.id.buttonReset);
|
Button btnReset = (Button) findViewById(R.id.buttonReset);
|
||||||
|
|
||||||
btnEarthquake.setEnabled(false);
|
btnEarthquake.setEnabled(true);
|
||||||
btnEarthquake.setOnClickListener(new View.OnClickListener() {
|
btnEarthquake.setOnClickListener(new View.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
Intent intent = new Intent(MainActivity.this, EarthquakeMapsActivity.class);
|
Intent intent = new Intent(MainActivity.this, EarthquakeMapsActivity.class);
|
||||||
btnEarthquake.setEnabled(false);
|
btnEarthquake.setEnabled(true);
|
||||||
btnSensor.setEnabled(false);
|
btnSensor.setEnabled(true);
|
||||||
startActivity(intent);
|
startActivity(intent);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
btnSensor.setEnabled(false);
|
btnSensor.setEnabled(true);
|
||||||
btnSensor.setOnClickListener(new View.OnClickListener() {
|
btnSensor.setOnClickListener(new View.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
Intent intent = new Intent(MainActivity.this, SensorMapsActivity.class);
|
Intent intent = new Intent(MainActivity.this, SensorMapsActivity.class);
|
||||||
btnSensor.setEnabled(false);
|
btnSensor.setEnabled(true);
|
||||||
btnEarthquake.setEnabled(false);
|
btnEarthquake.setEnabled(true);
|
||||||
startActivity(intent);
|
startActivity(intent);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -84,10 +83,11 @@ public class MainActivity extends FragmentActivity {
|
|||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
btnEarthquake.setEnabled(true);
|
btnEarthquake.setEnabled(true);
|
||||||
btnSensor.setEnabled(true);
|
btnSensor.setEnabled(true);
|
||||||
btnLeer.setEnabled(false);
|
btnLeer.setEnabled(true);
|
||||||
btnMuster.setEnabled(false);
|
btnMuster.setEnabled(true);
|
||||||
btnReset.setEnabled(true);
|
btnReset.setEnabled(true);
|
||||||
deviceInitDataBase();
|
db.setNonNativeCaseInDB();
|
||||||
|
//deviceInitDataBase(); //TODO: ARON
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -98,25 +98,29 @@ public class MainActivity extends FragmentActivity {
|
|||||||
btnSensor.setEnabled(true);
|
btnSensor.setEnabled(true);
|
||||||
btnMuster.setEnabled(false);
|
btnMuster.setEnabled(false);
|
||||||
btnReset.setEnabled(true);
|
btnReset.setEnabled(true);
|
||||||
btnLeer.setEnabled(false);
|
btnLeer.setEnabled(true);
|
||||||
datenBankLeeren();
|
//datenBankLeeren(); //TODO: ARON
|
||||||
|
db.setEmptyDataInDBcompletlyForNativeUse();
|
||||||
|
System.out.println(db.getCommand());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
btnReset.setEnabled(false);
|
btnReset.setEnabled(true);
|
||||||
btnReset.setOnClickListener(new View.OnClickListener() {
|
btnReset.setOnClickListener(new View.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
getDataBaseValuesNoListener();
|
//getDataBaseValuesNoListener(); //TODO ARON
|
||||||
btnEarthquake.setEnabled(true);
|
|
||||||
btnSensor.setEnabled(true);
|
|
||||||
btnMuster.setEnabled(true);
|
btnMuster.setEnabled(true);
|
||||||
btnLeer.setEnabled(true);
|
btnLeer.setEnabled(true);
|
||||||
|
btnEarthquake.setEnabled(true);
|
||||||
|
btnSensor.setEnabled(true);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public boolean isServiceOK(){
|
public boolean isServiceOK(){
|
||||||
Log.d(TAG, "isServicesOK(): checking google services version");
|
Log.d(TAG, "isServicesOK(): checking google services version");
|
||||||
|
|
||||||
@@ -140,24 +144,23 @@ public class MainActivity extends FragmentActivity {
|
|||||||
public void deviceInitDataBase()
|
public void deviceInitDataBase()
|
||||||
{
|
{
|
||||||
mDatenbank = FirebaseDatabase.getInstance().getReference();
|
mDatenbank = FirebaseDatabase.getInstance().getReference();
|
||||||
Devices d1 = new Devices("10.00.00.000", false, Calendar.getInstance().getTimeInMillis(), 52.51624237821577, 13.37683380067744, 1000, LocalDateTime.now().toString(), ""); //Berlin 52.51624237821577, 13.37683380067744
|
Devices d1 = new Devices("","","",49.58967957913626,11.011387124069765,false,false,0,1000,10); //Erlangen 49.58967957913626, 11.011387124069765
|
||||||
Devices d2 = new Devices("20.00.00.000", false, Calendar.getInstance().getTimeInMillis(), 48.7560280895443, 11.425157702952347, 200, LocalDateTime.now().toString(),""); //Ingolstadt 48.7560280895443, 11.425157702952347
|
Devices d2 = new Devices("","","",48.7560280895443,11.425157702952347,false,false,0,1000,10); //Ingolstadt 48.7560280895443, 11.425157702952347
|
||||||
Devices d3 = new Devices("30.00.00.000", false, Calendar.getInstance().getTimeInMillis(), 48.16958655466396, 11.617418429524394, 30, LocalDateTime.now().toString(),""); //München 48.16958655466396, 11.617418429524394
|
Devices d3 = new Devices("","","",48.16958655466396,11.617418429524394,false,false,0,1000,10); //München 48.16958655466396, 11.617418429524394
|
||||||
Devices d4 = new Devices("40.00.00.000", false, Calendar.getInstance().getTimeInMillis(), 45.55620112204013, 12.342516140205387, 4, LocalDateTime.now().toString(),""); //Venedig 45.55620112204013, 12.342516140205387
|
Devices d4 = new Devices("","","",45.55620112204013,12.342516140205387,false,false,0,1000,10); //Venedig 45.55620112204013, 12.342516140205387
|
||||||
mDatenbank.child("overviewAronTestetInDiesemAbschnitt").child("IDG1").setValue(d1);
|
Devices d5 = new Devices("","","",41.9204784730154,12.651055829215638,false,false,0,1000,10); //Rom 41.9204784730154, 12.651055829215638
|
||||||
mDatenbank.child("overviewAronTestetInDiesemAbschnitt").child("IDG2").setValue(d2);
|
mDatenbank.child("overviewnodes").child("IDG1").setValue(d1);
|
||||||
mDatenbank.child("overviewAronTestetInDiesemAbschnitt").child("IDG3").setValue(d3);
|
mDatenbank.child("overviewnodes").child("IDG2").setValue(d2);
|
||||||
mDatenbank.child("overviewAronTestetInDiesemAbschnitt").child("IDG4").setValue(d4);
|
mDatenbank.child("overviewnodes").child("IDG3").setValue(d3);
|
||||||
|
mDatenbank.child("overviewnodes").child("IDG4").setValue(d4);
|
||||||
//Nürnberg HBF: 49.4474136331757, 11.082661293035727
|
mDatenbank.child("overviewnodes").child("IDG5").setValue(d4);
|
||||||
|
mDatenbank.child("overviewnodes").child("IDG5").setValue(d5);
|
||||||
}
|
}
|
||||||
|
|
||||||
//Datenbank auslesen OHNE Listener. D.h. es werden Daten (snapshot) ausgelesen und kein Listener hinterlegt.
|
|
||||||
//Sollten sich danach Daten zu einem beliebigen Zeitpunkt in der DB ändern, wird die Funktion "onDataChange" NICHT erneut ausgelöst.
|
|
||||||
public void getDataBaseValuesNoListener()
|
public void getDataBaseValuesNoListener()
|
||||||
{
|
{
|
||||||
mDatenbank = FirebaseDatabase.getInstance().getReference();
|
mDatenbank = FirebaseDatabase.getInstance().getReference();
|
||||||
mDatenbank.child("overviewAronTestetInDiesemAbschnitt").get().addOnCompleteListener(new OnCompleteListener<DataSnapshot>() {
|
mDatenbank.child("overviewnodes").get().addOnCompleteListener(new OnCompleteListener<DataSnapshot>() {
|
||||||
@Override
|
@Override
|
||||||
public void onComplete(@NonNull Task<DataSnapshot> task) {
|
public void onComplete(@NonNull Task<DataSnapshot> task) {
|
||||||
if (!task.isSuccessful()) {
|
if (!task.isSuccessful()) {
|
||||||
@@ -173,91 +176,22 @@ public class MainActivity extends FragmentActivity {
|
|||||||
public void datenBankLeeren()
|
public void datenBankLeeren()
|
||||||
{
|
{
|
||||||
mDatenbank = FirebaseDatabase.getInstance().getReference();
|
mDatenbank = FirebaseDatabase.getInstance().getReference();
|
||||||
for (int i = 1; i<=4; i++)
|
for (int i = 1; i<=5; i++)
|
||||||
{
|
{
|
||||||
mDatenbank.child("overviewAronTestetInDiesemAbschnitt").child("IDG" + i).child("ip").setValue("");
|
mDatenbank.child("overviewnodes").child("IDG" + i).child("a_androidid").setValue("");
|
||||||
mDatenbank.child("overviewAronTestetInDiesemAbschnitt").child("IDG" + i).child("vibration").setValue(false);
|
mDatenbank.child("overviewnodes").child("IDG" + i).child("b_localdatetime").setValue("");
|
||||||
mDatenbank.child("overviewAronTestetInDiesemAbschnitt").child("IDG" + i).child("timestamp").setValue("");
|
mDatenbank.child("overviewnodes").child("IDG" + i).child("c_ip").setValue("");
|
||||||
mDatenbank.child("overviewAronTestetInDiesemAbschnitt").child("IDG" + i).child("breitengrad").setValue("");
|
mDatenbank.child("overviewnodes").child("IDG" + i).child("d_breitengrad").setValue("");
|
||||||
mDatenbank.child("overviewAronTestetInDiesemAbschnitt").child("IDG" + i).child("laengengrad").setValue("");
|
mDatenbank.child("overviewnodes").child("IDG" + i).child("e_laengengrad").setValue("");
|
||||||
mDatenbank.child("overviewAronTestetInDiesemAbschnitt").child("IDG" + i).child("amplitude").setValue("");
|
mDatenbank.child("overviewnodes").child("IDG" + i).child("f_nativegps").setValue(true);
|
||||||
mDatenbank.child("overviewAronTestetInDiesemAbschnitt").child("IDG" + i).child("localdatetime").setValue("");
|
mDatenbank.child("overviewnodes").child("IDG" + i).child("g_vibration").setValue(false);
|
||||||
mDatenbank.child("overviewAronTestetInDiesemAbschnitt").child("IDG" + i).child("androidid").setValue("");
|
mDatenbank.child("overviewnodes").child("IDG" + i).child("h_timestamp").setValue("");
|
||||||
|
mDatenbank.child("overviewnodes").child("IDG" + i).child("i_amplitude").setValue("");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testProcess(DataSnapshot data)
|
public void testProcess(DataSnapshot data)
|
||||||
{
|
{
|
||||||
mDatenbank = FirebaseDatabase.getInstance().getReference().child("overviewAronTestetInDiesemAbschnitt");
|
mDatenbank = FirebaseDatabase.getInstance().getReference().child("overviewnodes");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
//Datenbank auslesen MIT Listener. D.h. es werden Daten (snapshot) ausgelesen und gleichzeitig ein Listener hinterlegt.
|
|
||||||
//Sollten sich danach Daten zu einem beliebigen Zeitpunkt in der DB ändern, wird die Funktion "onDataChange" erneut ausgelöst und wieder Daten (snapshot) ausgelesen.
|
|
||||||
public void getDataBaseValuesListener()
|
|
||||||
{
|
|
||||||
mDatenbank = FirebaseDatabase.getInstance().getReference();
|
|
||||||
mDatenbank.addValueEventListener(new ValueEventListener() {
|
|
||||||
@Override
|
|
||||||
public void onDataChange(@NonNull DataSnapshot snapshot) {
|
|
||||||
//testProcess(snapshot); //Daten - Snapshot, Übergabe an Methode processDataBaseValues
|
|
||||||
}
|
|
||||||
@Override
|
|
||||||
public void onCancelled(@NonNull DatabaseError error) {
|
|
||||||
getDataBaseFailure(error);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
/*
|
|
||||||
public void getDataBaseFailure (DatabaseError error)
|
|
||||||
{
|
|
||||||
System.out.println("Fehler");
|
|
||||||
Log.w("Datenbankfehler", error.toException());
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
/*
|
|
||||||
@RequiresApi(api = Build.VERSION_CODES.O)
|
|
||||||
public void processDataBaseValues (DataSnapshot data)
|
|
||||||
{
|
|
||||||
for (int i = 1; i<=4; i++) //Für alle IDG 1-4 werden Werte ausgegeben
|
|
||||||
{
|
|
||||||
//####### Auslesen für String-Werte #######:
|
|
||||||
String ipAdresse = data.child("overviewAronTestetInDiesemAbschnitt").child("IDG" + i).child("ip").getValue().toString();
|
|
||||||
|
|
||||||
//####### Auslesen für boolean-Werte #######:
|
|
||||||
String vibrationString = data.child("overviewAronTestetInDiesemAbschnitt").child("IDG" + i).child("vibration").getValue().toString();
|
|
||||||
boolean vibration;
|
|
||||||
if(vibrationString == "true"){
|
|
||||||
vibration = true;
|
|
||||||
}else{
|
|
||||||
vibration = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
//####### Auslesen für double-Werte #######:
|
|
||||||
String breitengradString = data.child("overviewAronTestetInDiesemAbschnitt").child("IDG" + i).child("breitengrad").getValue().toString();
|
|
||||||
String laengengradString = data.child("overviewAronTestetInDiesemAbschnitt").child("IDG" + i).child("laengengrad").getValue().toString();
|
|
||||||
double breitengrad = Double.parseDouble(breitengradString);
|
|
||||||
double laengengrad = Double.parseDouble(laengengradString);
|
|
||||||
|
|
||||||
//####### Auslesen für long-Werte #######:
|
|
||||||
String timestampString = data.child("overviewAronTestetInDiesemAbschnitt").child("IDG" + i).child("timestamp").getValue().toString();
|
|
||||||
long timestamp = Long.parseLong(timestampString);
|
|
||||||
|
|
||||||
//####### Auslesen für ing-Werte #######:
|
|
||||||
String amplitudeString = data.child("overviewAronTestetInDiesemAbschnitt").child("IDG" + i).child("amplitude").getValue().toString();
|
|
||||||
int amplitude = Integer.parseInt(amplitudeString);
|
|
||||||
|
|
||||||
//####### Auslesen für LocalDateTime#######:
|
|
||||||
String localdatetimeString = data.child("overviewAronTestetInDiesemAbschnitt").child("IDG" + i).child("localdatetime").getValue().toString();
|
|
||||||
DateTimeFormatter formatter = DateTimeFormatter.ISO_DATE_TIME;
|
|
||||||
LocalDateTime localdatetime = LocalDateTime.parse(localdatetimeString, formatter);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
@@ -2,8 +2,10 @@ package de.edotzlaff.schockwelle;
|
|||||||
|
|
||||||
import android.Manifest;
|
import android.Manifest;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
import android.content.Intent;
|
||||||
import android.content.pm.PackageManager;
|
import android.content.pm.PackageManager;
|
||||||
import android.location.Location;
|
import android.location.Location;
|
||||||
|
import android.net.wifi.WifiManager;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.CountDownTimer;
|
import android.os.CountDownTimer;
|
||||||
@@ -15,6 +17,7 @@ import android.widget.TextView;
|
|||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
|
import androidx.annotation.RequiresApi;
|
||||||
import androidx.core.app.ActivityCompat;
|
import androidx.core.app.ActivityCompat;
|
||||||
import androidx.core.content.ContextCompat;
|
import androidx.core.content.ContextCompat;
|
||||||
import androidx.fragment.app.FragmentActivity;
|
import androidx.fragment.app.FragmentActivity;
|
||||||
@@ -36,6 +39,7 @@ import com.google.firebase.database.FirebaseDatabase;
|
|||||||
import com.google.firebase.database.ValueEventListener;
|
import com.google.firebase.database.ValueEventListener;
|
||||||
|
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
|
import java.time.ZoneOffset;
|
||||||
import java.util.Calendar;
|
import java.util.Calendar;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
|
||||||
@@ -46,6 +50,7 @@ public class SensorMapsActivity extends FragmentActivity implements OnMapReadyCa
|
|||||||
private static final String FINE_LOCATION = Manifest.permission.ACCESS_FINE_LOCATION;
|
private static final String FINE_LOCATION = Manifest.permission.ACCESS_FINE_LOCATION;
|
||||||
private static final int LOCATION_PERMISSION_REQUEST_CODE = 1234;
|
private static final int LOCATION_PERMISSION_REQUEST_CODE = 1234;
|
||||||
private static final double EARTHQUAKE_VELOCITY = 1; // 1 Meter pro Sekunde Erdbebengeschwindigkeit
|
private static final double EARTHQUAKE_VELOCITY = 1; // 1 Meter pro Sekunde Erdbebengeschwindigkeit
|
||||||
|
Datenbank db = new Datenbank();
|
||||||
|
|
||||||
//vars
|
//vars
|
||||||
private Boolean mLocationPermissionsGranted = false;
|
private Boolean mLocationPermissionsGranted = false;
|
||||||
@@ -63,8 +68,12 @@ public class SensorMapsActivity extends FragmentActivity implements OnMapReadyCa
|
|||||||
private boolean useOwnGPS;
|
private boolean useOwnGPS;
|
||||||
private boolean takeGPSfromDB = true;
|
private boolean takeGPSfromDB = true;
|
||||||
private boolean tookOwnGPS = false;
|
private boolean tookOwnGPS = false;
|
||||||
|
private boolean globalShit = true;
|
||||||
|
private boolean permissionToWriteToDataBase = true;
|
||||||
|
private DataSnapshot datenBankSnapShot;
|
||||||
|
|
||||||
boolean vibrationTrigger = true;
|
boolean vibrationTrigger = true;
|
||||||
|
boolean grabGPSandID = true;
|
||||||
|
|
||||||
|
|
||||||
private DatabaseReference mDatenbank;
|
private DatabaseReference mDatenbank;
|
||||||
@@ -78,6 +87,19 @@ public class SensorMapsActivity extends FragmentActivity implements OnMapReadyCa
|
|||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
setContentView(R.layout.activity_sensor_maps);
|
setContentView(R.layout.activity_sensor_maps);
|
||||||
|
|
||||||
|
//Database Init
|
||||||
|
|
||||||
|
db.setMyWaveSpeed(500);
|
||||||
|
db.setMyAndroidID(Settings.Secure.getString(this.getContentResolver(), Settings.Secure.ANDROID_ID));
|
||||||
|
WifiManager wm = (WifiManager) getApplicationContext().getSystemService(WIFI_SERVICE);
|
||||||
|
int ip = wm.getConnectionInfo().getIpAddress();
|
||||||
|
db.setMyIPadress(String.format("%d.%d.%d.%d",(ip & 0xff),(ip >> 8 & 0xff),(ip >> 16 & 0xff), (ip >> 24 & 0xff)));
|
||||||
|
/*
|
||||||
|
db.getDatafromDBnoListener();
|
||||||
|
db.getDataBaseValuesWithListener();
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
getDataBaseValuesWithListener();
|
getDataBaseValuesWithListener();
|
||||||
|
|
||||||
TextView tv= (TextView) findViewById(R.id.txtSensor);
|
TextView tv= (TextView) findViewById(R.id.txtSensor);
|
||||||
@@ -108,33 +130,20 @@ public class SensorMapsActivity extends FragmentActivity implements OnMapReadyCa
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private long getTimeStampDifference(float distance)
|
|
||||||
{
|
|
||||||
long diff= 0;
|
|
||||||
//TODO Zeitdifferenz in Millisekunden zwischen aktuellen Uhrzeit und Vibratonszeitstempel berechnen
|
|
||||||
|
|
||||||
|
|
||||||
if (distance>0)
|
|
||||||
{
|
|
||||||
diff = (long)Math.round(1/(EARTHQUAKE_VELOCITY/distance));
|
|
||||||
}
|
|
||||||
return diff;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void setVibrationTimer(long msDelay, int duration, int amplitude, int index)
|
private void setVibrationTimer(long msDelay, int duration, int amplitude, int index)
|
||||||
{
|
{
|
||||||
|
|
||||||
new CountDownTimer(msDelay, 1000) {
|
new CountDownTimer(msDelay, 1000) {
|
||||||
public void onTick(long millisUntilFinished) {
|
public void onTick(long millisUntilFinished) {
|
||||||
((TextView) findViewById(R.id.txtSensor)).setText("Earthquake hits in " + millisUntilFinished / 1000 + " s");
|
((TextView) findViewById(R.id.txtSensor)).setText("Earthquake hits in " + millisUntilFinished / 1000 + " s");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@RequiresApi(api = Build.VERSION_CODES.O)
|
||||||
public void onFinish() {
|
public void onFinish() {
|
||||||
Toast.makeText(getApplicationContext(), "The Ground is shaking!", Toast.LENGTH_SHORT).show();
|
Toast.makeText(getApplicationContext(), "The Ground is shaking!", Toast.LENGTH_SHORT).show();
|
||||||
performVibration(duration, amplitude);
|
performVibration(duration, amplitude);
|
||||||
( (TextView) findViewById(R.id.txtSensor)).setText("No Earthquake upcoming");
|
( (TextView) findViewById(R.id.txtSensor)).setText("No Earthquake upcoming");
|
||||||
//In DB schreiben!
|
//Hier wird in DB geschrieben
|
||||||
setVibrationInDataBase(index);
|
setVibrationInDataBase(index); //TODO Aron
|
||||||
}
|
}
|
||||||
}.start();
|
}.start();
|
||||||
}
|
}
|
||||||
@@ -145,14 +154,15 @@ public class SensorMapsActivity extends FragmentActivity implements OnMapReadyCa
|
|||||||
|
|
||||||
Vibrator v = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);
|
Vibrator v = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);
|
||||||
if (Build.VERSION.SDK_INT >= 26) {
|
if (Build.VERSION.SDK_INT >= 26) {
|
||||||
|
if(amplitude > 255 || amplitude < 1)
|
||||||
|
amplitude = VibrationEffect.DEFAULT_AMPLITUDE;
|
||||||
if(duration == 0)
|
if(duration == 0)
|
||||||
{
|
{
|
||||||
v.cancel(); //stop vibration if still running
|
v.cancel(); //stop vibration if still running
|
||||||
Toast.makeText(this, "Vibration has been stopped", Toast.LENGTH_SHORT).show();
|
Toast.makeText(this, "Vibration has been stopped", Toast.LENGTH_SHORT).show();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
//Toast.makeText(this, "Ampl: " + amplitude + ", Dur: " + duration, Toast.LENGTH_SHORT).show();
|
||||||
Toast.makeText(this, "Ampl: " + amplitude + ", Dur: " + duration, Toast.LENGTH_SHORT).show();
|
|
||||||
|
|
||||||
v.vibrate(VibrationEffect.createOneShot(duration,amplitude));
|
v.vibrate(VibrationEffect.createOneShot(duration,amplitude));
|
||||||
|
|
||||||
@@ -162,7 +172,6 @@ public class SensorMapsActivity extends FragmentActivity implements OnMapReadyCa
|
|||||||
if(duration == 0)
|
if(duration == 0)
|
||||||
{
|
{
|
||||||
v.cancel(); //stop vibration if still running
|
v.cancel(); //stop vibration if still running
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -226,7 +235,8 @@ public class SensorMapsActivity extends FragmentActivity implements OnMapReadyCa
|
|||||||
mMap.setMyLocationEnabled(true);
|
mMap.setMyLocationEnabled(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add a marker in Sydney and move the camera
|
//TODO @ Eddy: Ich denke diesen Code brauchst du noch, oder? :D
|
||||||
|
//Add a marker in Sydney and move the camera
|
||||||
//LatLng sydney = new LatLng(-34, 151);
|
//LatLng sydney = new LatLng(-34, 151);
|
||||||
//mMap.addMarker(new MarkerOptions().position(sydney).title("Marker in Sydney"));
|
//mMap.addMarker(new MarkerOptions().position(sydney).title("Marker in Sydney"));
|
||||||
//mMap.moveCamera(CameraUpdateFactory.newLatLng(sydney));
|
//mMap.moveCamera(CameraUpdateFactory.newLatLng(sydney));
|
||||||
@@ -245,12 +255,23 @@ public class SensorMapsActivity extends FragmentActivity implements OnMapReadyCa
|
|||||||
if (task.isSuccessful()){
|
if (task.isSuccessful()){
|
||||||
currentLocation = (Location) task.getResult();
|
currentLocation = (Location) task.getResult();
|
||||||
currentTime = Calendar.getInstance().getTimeInMillis();
|
currentTime = Calendar.getInstance().getTimeInMillis();
|
||||||
|
|
||||||
|
/*
|
||||||
|
if(!db.getNativeGPScaseInDB())
|
||||||
|
{
|
||||||
|
System.out.println("---Fremde GPS Daten werden verwendet");
|
||||||
|
currentLocation.setLatitude(breitengrad);
|
||||||
|
currentLocation.setLongitude(laengengrad);
|
||||||
|
}
|
||||||
|
|
||||||
|
*/
|
||||||
if (!useOwnGPS)
|
if (!useOwnGPS)
|
||||||
{
|
{
|
||||||
currentLocation.setLatitude(breitengrad);
|
currentLocation.setLatitude(breitengrad);
|
||||||
currentLocation.setLongitude(laengengrad);
|
currentLocation.setLongitude(laengengrad);
|
||||||
}
|
}
|
||||||
Toast.makeText(SensorMapsActivity.this, currentTime.toString(), Toast.LENGTH_SHORT).show();
|
|
||||||
|
//Toast.makeText(SensorMapsActivity.this, currentTime.toString(), Toast.LENGTH_SHORT).show();
|
||||||
moveCamera(new LatLng(currentLocation.getLatitude(), currentLocation.getLongitude()),15f);
|
moveCamera(new LatLng(currentLocation.getLatitude(), currentLocation.getLongitude()),15f);
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
@@ -272,6 +293,9 @@ public class SensorMapsActivity extends FragmentActivity implements OnMapReadyCa
|
|||||||
//################################################################## ^^^^ GPS Code ^^^^ #############################################################################
|
//################################################################## ^^^^ GPS Code ^^^^ #############################################################################
|
||||||
//#####################################################################################################################################################################
|
//#####################################################################################################################################################################
|
||||||
|
|
||||||
|
//#####################################################################################################################################################################
|
||||||
|
//################################################################## vvv DB Code vvv ###############################################################################
|
||||||
|
|
||||||
//Datenbank auslesen mit Listener. D.h. es werden Daten (snapshot) ausgelesen und gleichzeitig ein Listener hinterlegt.
|
//Datenbank auslesen mit Listener. D.h. es werden Daten (snapshot) ausgelesen und gleichzeitig ein Listener hinterlegt.
|
||||||
//Sollten sich danach Daten zu einem beliebigen Zeitpunkt in der DB ändern, wird die Funktion "onDataChange" erneut ausgelöst und wieder Daten (snapshot) ausgelesen.
|
//Sollten sich danach Daten zu einem beliebigen Zeitpunkt in der DB ändern, wird die Funktion "onDataChange" erneut ausgelöst und wieder Daten (snapshot) ausgelesen.
|
||||||
public void getDataBaseValuesWithListener()
|
public void getDataBaseValuesWithListener()
|
||||||
@@ -281,6 +305,7 @@ public class SensorMapsActivity extends FragmentActivity implements OnMapReadyCa
|
|||||||
@Override
|
@Override
|
||||||
public void onDataChange(@NonNull DataSnapshot snapshot) {
|
public void onDataChange(@NonNull DataSnapshot snapshot) {
|
||||||
processDataBaseUpdate(snapshot);
|
processDataBaseUpdate(snapshot);
|
||||||
|
datenBankSnapShot = snapshot;
|
||||||
}
|
}
|
||||||
@Override
|
@Override
|
||||||
public void onCancelled(@NonNull DatabaseError error) {
|
public void onCancelled(@NonNull DatabaseError error) {
|
||||||
@@ -291,99 +316,313 @@ public class SensorMapsActivity extends FragmentActivity implements OnMapReadyCa
|
|||||||
|
|
||||||
public void processDataBaseUpdate (DataSnapshot data)
|
public void processDataBaseUpdate (DataSnapshot data)
|
||||||
{
|
{
|
||||||
String breitengradString;
|
int indexMax = (int) data.child("overviewnodes").getChildrenCount();
|
||||||
String laengengradString;
|
//Festellen ob DB oder eigene GPS-Daten verwendet werden sollen
|
||||||
String vibrationString;
|
if(analyzeForUseOfOwnGPS(data))
|
||||||
String androidid;
|
|
||||||
int vibratingDevices = 0;
|
|
||||||
|
|
||||||
for (int i = 1; i<=4; i++)
|
|
||||||
{
|
{
|
||||||
breitengradString = data.child("overviewAronTestetInDiesemAbschnitt").child("IDG" + i).child("breitengrad").getValue().toString();
|
useOwnGPS = true;
|
||||||
laengengradString = data.child("overviewAronTestetInDiesemAbschnitt").child("IDG" + i).child("laengengrad").getValue().toString();
|
}
|
||||||
|
else
|
||||||
androidid = data.child("overviewAronTestetInDiesemAbschnitt").child("IDG" + i).child("androidid").getValue().toString();
|
{
|
||||||
vibrationString = data.child("overviewAronTestetInDiesemAbschnitt").child("IDG" + i).child("vibration").getValue().toString();
|
useOwnGPS = false;
|
||||||
|
}
|
||||||
if(!androidid.isEmpty())
|
//Wichtig zur Verwendung von GPS-Daten explizit aus der Datenbank
|
||||||
|
if(!useOwnGPS && grabGPSandID)
|
||||||
|
{
|
||||||
|
for (int f = 1; f<=indexMax; f++)
|
||||||
{
|
{
|
||||||
//System.out.println("Index " + i + " ist nicht leer");
|
if(f>=2 && f<=indexMax)
|
||||||
if(vibrationString == "false")
|
|
||||||
{
|
{
|
||||||
//System.out.println("Index " + i + " Vibration ist false");
|
if(analyzeIfAnroidIdIsEmpty(data,f))
|
||||||
continue;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
//System.out.println("Index " + i + " Vibration ist true");
|
|
||||||
if(androidid.equals(getandroidid()))
|
|
||||||
{
|
{
|
||||||
//System.out.println("Index " + i + " Vibration ist von mir. Falscher Alarm");
|
String breitengradString = data.child("overviewnodes").child("IDG" + f).child("d_breitengrad").getValue().toString();
|
||||||
vibrationTrigger = false;
|
String laengengradString = data.child("overviewnodes").child("IDG" + f).child("e_laengengrad").getValue().toString();
|
||||||
|
breitengrad = Double.parseDouble(breitengradString);
|
||||||
|
laengengrad = Double.parseDouble(laengengradString);
|
||||||
|
allocateIDtoDatabaseSlot(f);
|
||||||
|
grabGPSandID = false;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
//System.out.println("Index " + i + " Vibration ist nicht von mir. Breitengrad und Laegengrad von Vibrationsquelle bestimmen.");
|
|
||||||
breitengradQuellVibration = breitengradString;
|
|
||||||
laengengradQuellVibration = laengengradString;
|
|
||||||
vibratingDevices++;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
}
|
||||||
|
//Hier sind die Schreibregeln für die DB definiert wenn Sensor aktiviert ist
|
||||||
|
for (int f = 1; f<=indexMax; f++)
|
||||||
|
{
|
||||||
|
|
||||||
|
if((!analyzeIfAnroidIdIsEmpty(data,f) && !analyzeForOwnAndroidID(data,f) && analyzeForStateOfVibration(data,f) && analyzeForExisitingGPSvalues(data,f) && permissionToWriteToDataBase))
|
||||||
{
|
{
|
||||||
//System.out.println("Index " + i + " ist leer");
|
System.out.println("Index: " + f + ": Eintrittskriterien erfüllt.");
|
||||||
if(androidid.isEmpty() && !breitengradString.isEmpty() && !laengengradString.isEmpty() && vibrationString.equals("false") && takeGPSfromDB)
|
//Nehme Quelle GPS Daten
|
||||||
|
String breitengradString = data.child("overviewnodes").child("IDG" + f).child("d_breitengrad").getValue().toString();
|
||||||
|
String laengengradString = data.child("overviewnodes").child("IDG" + f).child("e_laengengrad").getValue().toString();
|
||||||
|
breitengradQuellVibration = breitengradString;
|
||||||
|
laengengradQuellVibration = laengengradString;
|
||||||
|
|
||||||
|
f=1;
|
||||||
|
if(analyzeForOwnAndroidID(data,f))
|
||||||
{
|
{
|
||||||
System.out.println("Index " + i +" -> Leere AdnroidID. Breitengrad und Laengengrad sind belegt. Vibration ist false. Kann als eigenes Gerät beansprucht werden.");
|
System.out.println("Index: " + f + ": Eigene ID vorhanden.");
|
||||||
System.out.println("Index " + i +" -> Übernehme Breitengrad: " + breitengradString + " und Laengengrad: " + laengengradString + " als eigene Position.");
|
if (!analyzeForStateOfVibration(data,f))
|
||||||
breitengrad = Double.parseDouble(breitengradString);
|
|
||||||
laengengrad = Double.parseDouble(laengengradString);
|
|
||||||
useOwnGPS = false;
|
|
||||||
takeGPSfromDB = false;
|
|
||||||
}else
|
|
||||||
{
|
|
||||||
if(!tookOwnGPS && takeGPSfromDB)
|
|
||||||
{
|
{
|
||||||
//System.out.println("Nutze eigene DB. Bin bei Index " + i + " ++++++++++++++++++++++++++++++++++++++++++++");
|
System.out.println("Index: " + f + ": Vibration is false.");
|
||||||
tookOwnGPS = true;
|
if(analyzeForExisitingGPSvalues(data,f) && permissionToWriteToDataBase)
|
||||||
useOwnGPS = true;
|
{
|
||||||
|
//System.out.println("Index: " + f + ": Beide GPS Daten vorhanden. Ich reserviere mir diesen Platz und schreibe hier demnächst rein.");
|
||||||
|
//hier sofort ID eintragen
|
||||||
|
//mDatenbank = FirebaseDatabase.getInstance().getReference();
|
||||||
|
//mDatenbank.child("overviewnodes").child("IDG" + f).child("a_androidid").setValue(getandroidid());
|
||||||
|
float distanceToEarthquake;
|
||||||
|
distanceToEarthquake = distance(currentLocation.getLatitude(), currentLocation.getLongitude(), Double.parseDouble(breitengradQuellVibration), Double.parseDouble(laengengradQuellVibration));
|
||||||
|
long wellenAusbreitungsGeschwindigkeit = (long) db.getMyWaveSpeed(); //Meter die Sekunde
|
||||||
|
long delayInSeconds = (long) distanceToEarthquake/wellenAusbreitungsGeschwindigkeit; //s
|
||||||
|
long delayInMilliSeconds = delayInSeconds*1000;
|
||||||
|
setVibrationTimer(delayInMilliSeconds,1500,255,f);
|
||||||
|
permissionToWriteToDataBase = false;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
System.out.println("Index: " + f + ": Habe keine GPS Daten");
|
||||||
|
}
|
||||||
|
}else{
|
||||||
|
System.out.println("Index: " + f + ": Meine Vibration ist bereits true.");
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else
|
||||||
if(vibrationTrigger == true && (vibratingDevices == 1))
|
|
||||||
{
|
{
|
||||||
//System.out.println("#########Freigabe zum Schreiben in DB mit Index " + i + " liegt vor. Schreibe nun... !!!!!#####################");
|
System.out.println("Index: " + f + ": Eigene ID nicht vorhanden");
|
||||||
/*
|
for(f = f; f<=indexMax; f++)
|
||||||
System.out.println("currentLocation.getLatitude(): " + currentLocation.getLatitude());
|
{
|
||||||
System.out.println("currentLocation.getLongitude(): " + currentLocation.getLongitude());
|
if((analyzeIfAnroidIdIsEmpty(data,f) || analyzeForOwnAndroidID(data,f)) && permissionToWriteToDataBase)
|
||||||
System.out.println("Double.parseDouble(breitengradQuellVibration): " + Double.parseDouble(breitengradQuellVibration));
|
{
|
||||||
System.out.println("Double.parseDouble(laengengradQuellVibration): " + Double.parseDouble(laengengradQuellVibration));
|
//System.out.println("Index: " + f + ": Diese Slot war leer oder es ist meine eigene ID. Ich schreibe hier rein");
|
||||||
System.out.println("######################################################################################################################################################################");
|
//mDatenbank = FirebaseDatabase.getInstance().getReference();
|
||||||
*/
|
//mDatenbank.child("overviewnodes").child("IDG" + f).child("a_androidid").setValue(getandroidid());
|
||||||
|
float distanceToEarthquake;
|
||||||
|
distanceToEarthquake = distance(currentLocation.getLatitude(), currentLocation.getLongitude(), Double.parseDouble(breitengradQuellVibration), Double.parseDouble(laengengradQuellVibration));
|
||||||
|
long wellenAusbreitungsGeschwindigkeit = (long) db.getMyWaveSpeed(); //Meter die Sekunde
|
||||||
|
long delayInSeconds = (long) distanceToEarthquake/wellenAusbreitungsGeschwindigkeit; //s
|
||||||
|
long delayInMilliSeconds = delayInSeconds*1000;
|
||||||
|
setVibrationTimer(delayInMilliSeconds,1500,255,f);
|
||||||
|
permissionToWriteToDataBase = false;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
vibrationTrigger = false;
|
if(f == indexMax && !analyzeIfAnroidIdIsEmpty(data,f))
|
||||||
float distanceToEarthquake;
|
{
|
||||||
distanceToEarthquake = distance(currentLocation.getLatitude(), currentLocation.getLongitude(), Double.parseDouble(breitengradQuellVibration), Double.parseDouble(laengengradQuellVibration));
|
System.out.println(">>>Index " + f + " >>>Konnte keine freien Slot finden");
|
||||||
System.out.println("Distance to Earthquake: " + distanceToEarthquake);
|
}
|
||||||
long wellenAusbreitungsGeschwindigkeit = 4500; //Meter die Sekunde
|
}
|
||||||
long delayInSeconds = (long) distanceToEarthquake/wellenAusbreitungsGeschwindigkeit; //s
|
}
|
||||||
long delayInMilliSeconds = delayInSeconds*1000;
|
}
|
||||||
setVibrationTimer(delayInMilliSeconds,1500,255,i);
|
}
|
||||||
//setVibrationInDataBase(i);
|
}
|
||||||
|
|
||||||
|
public boolean analyzeForUseOfOwnGPS(DataSnapshot data)
|
||||||
|
{
|
||||||
|
String nativeGPSString;
|
||||||
|
boolean nativeGPS;
|
||||||
|
int amountNativeGPSisTrue = 0;
|
||||||
|
int indexMax = (int) data.child("overviewnodes").getChildrenCount();
|
||||||
|
for (int i = 1; i <= indexMax; i++)
|
||||||
|
{
|
||||||
|
nativeGPSString = data.child("overviewnodes").child("IDG" + i).child("f_nativegps").getValue().toString();
|
||||||
|
if(nativeGPSString.equals("true"))
|
||||||
|
{
|
||||||
|
amountNativeGPSisTrue++;
|
||||||
|
}else
|
||||||
|
{
|
||||||
|
amountNativeGPSisTrue--;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(amountNativeGPSisTrue == indexMax)
|
||||||
|
{
|
||||||
|
nativeGPS = true;
|
||||||
|
}else{
|
||||||
|
nativeGPS = false;
|
||||||
|
}
|
||||||
|
return nativeGPS;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean analyzeIfAnroidIdIsEmpty(DataSnapshot data, int k)
|
||||||
|
{
|
||||||
|
String androidid;
|
||||||
|
int indexMax = (int) data.child("overviewnodes").getChildrenCount();
|
||||||
|
boolean androididempty = false;
|
||||||
|
for (int i = k; i <= k; i++)
|
||||||
|
{
|
||||||
|
androidid = data.child("overviewnodes").child("IDG" + i).child("a_androidid").getValue().toString();
|
||||||
|
if(androidid.isEmpty())
|
||||||
|
{
|
||||||
|
androididempty = true;
|
||||||
|
}else
|
||||||
|
{
|
||||||
|
androididempty = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return androididempty;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean analyzeForOwnAndroidID(DataSnapshot data, int k)
|
||||||
|
{
|
||||||
|
String androididString;
|
||||||
|
boolean ownAndroidID = false;
|
||||||
|
int indexMax = (int) data.child("overviewnodes").getChildrenCount();
|
||||||
|
for (int i = k; i <= k; i++)
|
||||||
|
{
|
||||||
|
androididString = data.child("overviewnodes").child("IDG" + i).child("a_androidid").getValue().toString();
|
||||||
|
if(androididString.equals(getandroidid()))
|
||||||
|
{
|
||||||
|
ownAndroidID = true;
|
||||||
|
}else
|
||||||
|
{
|
||||||
|
ownAndroidID = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return ownAndroidID;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean analyzeForStateOfVibration(DataSnapshot data, int k)
|
||||||
|
{
|
||||||
|
String vibrationString;
|
||||||
|
boolean stateOfVibration = false;
|
||||||
|
int indexMax = (int) data.child("overviewnodes").getChildrenCount();
|
||||||
|
for (int i = k; i <= k; i++)
|
||||||
|
{
|
||||||
|
vibrationString = data.child("overviewnodes").child("IDG" + i).child("g_vibration").getValue().toString();
|
||||||
|
if(vibrationString.equals("true"))
|
||||||
|
{
|
||||||
|
stateOfVibration = true;
|
||||||
|
}else
|
||||||
|
{
|
||||||
|
stateOfVibration = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return stateOfVibration;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean analyzeForExisitingGPSvalues(DataSnapshot data, int k)
|
||||||
|
{
|
||||||
|
String breitengradString;
|
||||||
|
String laengengradString;
|
||||||
|
boolean bothGPSvaluesExist = false;
|
||||||
|
int indexMax = (int) data.child("overviewnodes").getChildrenCount();
|
||||||
|
for (int i = k; i <= k; i++)
|
||||||
|
{
|
||||||
|
breitengradString = data.child("overviewnodes").child("IDG" + i).child("d_breitengrad").getValue().toString();
|
||||||
|
laengengradString = data.child("overviewnodes").child("IDG" + i).child("e_laengengrad").getValue().toString();
|
||||||
|
if(!breitengradString.isEmpty() && !laengengradString.isEmpty())
|
||||||
|
{
|
||||||
|
bothGPSvaluesExist = true;
|
||||||
|
}else
|
||||||
|
{
|
||||||
|
bothGPSvaluesExist = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return bothGPSvaluesExist;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void allocateIDtoDatabaseSlot(int k)
|
||||||
|
{
|
||||||
|
mDatenbank = FirebaseDatabase.getInstance().getReference();
|
||||||
|
mDatenbank.child("overviewnodes").child("IDG" + k).child("a_androidid").setValue(getandroidid());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@RequiresApi(api = Build.VERSION_CODES.O)
|
||||||
|
public void setVibrationInDataBase(int k)
|
||||||
|
{
|
||||||
|
System.out.println("Es wird versucht in DB zu schreiben....");
|
||||||
|
for(k =k; k<=datenBankSnapShot.child("overviewnodes").getChildrenCount();k++)
|
||||||
|
{
|
||||||
|
System.out.println("Index...." + k);
|
||||||
|
System.out.println("analyzeIfAnroidIdIsEmpty(datenBankSnapShot,k)" + k + "___" + analyzeIfAnroidIdIsEmpty(datenBankSnapShot,k));
|
||||||
|
System.out.println("analyzeForOwnAndroidID(datenBankSnapShot,k)" + k + "___" + analyzeForOwnAndroidID(datenBankSnapShot,k));
|
||||||
|
System.out.println("analyzeForStateOfVibration(datenBankSnapShot,k)" + k + "___" + analyzeForStateOfVibration(datenBankSnapShot,k));
|
||||||
|
|
||||||
|
//Wenn Leer ODER eigene ID und Vibration = false;
|
||||||
|
if((analyzeIfAnroidIdIsEmpty(datenBankSnapShot,k) || analyzeForOwnAndroidID(datenBankSnapShot,k) && !analyzeForStateOfVibration(datenBankSnapShot,k) ))
|
||||||
|
{
|
||||||
|
System.out.println("Android ID war leer oder es war eigene ID mit Vibration = false. SChreibe in DB...... " + k);
|
||||||
|
//Reinschreieben
|
||||||
|
mDatenbank = FirebaseDatabase.getInstance().getReference();
|
||||||
|
mDatenbank.child("overviewnodes").child("IDG" + k).child("a_androidid").setValue(getandroidid());
|
||||||
|
|
||||||
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||||
|
//mDatenbank.child("overviewnodes").child("IDG" + k).child("b_localdatetime").setValue(LocalDateTime.now().toString());
|
||||||
|
mDatenbank.child("overviewnodes").child("IDG" + k).child("b_localdatetime").setValue(LocalDateTime.now(ZoneOffset.UTC).toString());
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
mDatenbank.child("overviewnodes").child("IDG" + k).child("c_ip").setValue(getDeviceIpAdress());
|
||||||
|
if (useOwnGPS)
|
||||||
|
{
|
||||||
|
mDatenbank.child("overviewnodes").child("IDG" + k).child("f_nativegps").setValue(true);
|
||||||
|
mDatenbank.child("overviewnodes").child("IDG" + k).child("d_breitengrad").setValue(currentLocation.getLatitude()); //aktueller Breitengrad
|
||||||
|
mDatenbank.child("overviewnodes").child("IDG" + k).child("e_laengengrad").setValue(currentLocation.getLongitude()); //aktueller Längergrad
|
||||||
|
}else{
|
||||||
|
mDatenbank.child("overviewnodes").child("IDG" + k).child("d_breitengrad").setValue(breitengrad); //aktueller Breitengrad
|
||||||
|
mDatenbank.child("overviewnodes").child("IDG" + k).child("e_laengengrad").setValue(laengengrad); //aktueller Längergrad
|
||||||
|
mDatenbank.child("overviewnodes").child("IDG" + k).child("f_nativegps").setValue(false);
|
||||||
|
}
|
||||||
|
mDatenbank.child("overviewnodes").child("IDG" + k).child("g_vibration").setValue(true);
|
||||||
|
mDatenbank.child("overviewnodes").child("IDG" + k).child("h_timestamp").setValue(Calendar.getInstance().getTimeInMillis()); //aktueller Zeitstempel wird in Datenbank eingetragen
|
||||||
|
mDatenbank.child("overviewnodes").child("IDG" + k).child("i_amplitude").setValue(1000);
|
||||||
|
mDatenbank.child("overviewnodes").child("IDG" + k).child("w_wellengeschwindigkeit").setValue(db.getMyWaveSpeed());
|
||||||
|
break;
|
||||||
|
}else
|
||||||
|
{
|
||||||
|
System.out.println("Erhöhe Index weil nicht durchgekommen" + k);
|
||||||
|
//k erhöhen solange leerer Slot ist oder abbruch weil zu voll
|
||||||
|
if(k ==(int) datenBankSnapShot.child("overviewnodes").getChildrenCount())
|
||||||
|
{
|
||||||
|
System.out.println("Kein freier Slot mehr vorhanden");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//TODO Weiterer Code von Patrick. @Aron Anschauen ob dieser noch verwendet werden muss da paar Sachen schon in dieser Version umgesetzt worde sind.
|
public String getDeviceIpAdress ()
|
||||||
|
{
|
||||||
|
WifiManager wm = (WifiManager) getApplicationContext().getSystemService(WIFI_SERVICE);
|
||||||
|
int ip = wm.getConnectionInfo().getIpAddress();
|
||||||
|
String ipAddress = String.format("%d.%d.%d.%d",(ip & 0xff),(ip >> 8 & 0xff),(ip >> 16 & 0xff), (ip >> 24 & 0xff));
|
||||||
|
return ipAddress;
|
||||||
|
}
|
||||||
|
|
||||||
|
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());
|
||||||
|
}
|
||||||
|
|
||||||
|
private float distance(double currentlatitude, double currentlongitude, double originLat, double originLon) {
|
||||||
|
|
||||||
|
float[] results = new float[1];
|
||||||
|
Location.distanceBetween(currentlatitude, currentlongitude, originLat, originLon, results);
|
||||||
|
float distanceInMeters = results[0];
|
||||||
|
|
||||||
|
return distanceInMeters;
|
||||||
|
}
|
||||||
|
|
||||||
|
//################################################################## ^^^^ DB Code ^^^^ #############################################################################
|
||||||
|
//#####################################################################################################################################################################
|
||||||
|
|
||||||
|
//TODO @Patrick: Ist backupVonAltemCode noch relevanter Code wenn Viration und das Schreiben in die Datenbank passt und synchron abläuft? Falls nichts relevant, können wir das ja löschen ;)
|
||||||
|
public void backupVonAltemCode (DataSnapshot data)
|
||||||
|
{
|
||||||
/*
|
/*
|
||||||
//####### Auslesen für boolean-Werte #######:
|
//####### Auslesen für boolean-Werte #######:
|
||||||
int i = 1;
|
int i = 1;
|
||||||
String vibrationString = data.child("overview").child("IDG").child("vibration").getValue().toString();
|
String vibrationString = data.child("overviewnodes").child("IDG").child("vibration").getValue().toString();
|
||||||
String amplitudeString = data.child("overview").child("IDG").child("amplitude").getValue().toString();
|
String amplitudeString = data.child("overviewnodes").child("IDG").child("amplitude").getValue().toString();
|
||||||
boolean vibration;
|
boolean vibration;
|
||||||
if(vibrationString.equals("true")){
|
if(vibrationString.equals("true")){
|
||||||
vibration = true;
|
vibration = true;
|
||||||
@@ -402,51 +641,19 @@ public class SensorMapsActivity extends FragmentActivity implements OnMapReadyCa
|
|||||||
*/
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setVibrationInDataBase(int k)
|
//TODO @Patrick: Ist getTimeStampDifference noch relevanter Code wenn Viration und das Schreiben in die Datenbank passt und synchron abläuft? Falls nichts relevant, können wir das ja löschen ;)
|
||||||
|
private long getTimeStampDifference(float distance)
|
||||||
{
|
{
|
||||||
mDatenbank = FirebaseDatabase.getInstance().getReference();
|
long diff= 0;
|
||||||
mDatenbank.child("overviewAronTestetInDiesemAbschnitt").child("IDG" + k).child("ip").setValue(k + "0.00.00.000");
|
|
||||||
mDatenbank.child("overviewAronTestetInDiesemAbschnitt").child("IDG" + k).child("vibration").setValue(true);
|
|
||||||
mDatenbank.child("overviewAronTestetInDiesemAbschnitt").child("IDG" + k).child("timestamp").setValue(Calendar.getInstance().getTimeInMillis()); //aktueller Zeitstempel wird in Datenbank eingetragen
|
|
||||||
|
|
||||||
if (useOwnGPS)
|
if (distance>0)
|
||||||
{
|
{
|
||||||
//System.out.println("YYYcurrentLocation.getLatitude(): " + currentLocation.getLatitude());
|
diff = (long)Math.round(1/(EARTHQUAKE_VELOCITY/distance));
|
||||||
//System.out.println("YYYcurrentLocation.getLongitude(): " + currentLocation.getLongitude());
|
|
||||||
mDatenbank.child("overviewAronTestetInDiesemAbschnitt").child("IDG" + k).child("breitengrad").setValue(currentLocation.getLatitude()); //aktueller Breitengrad
|
|
||||||
mDatenbank.child("overviewAronTestetInDiesemAbschnitt").child("IDG" + k).child("laengengrad").setValue(currentLocation.getLongitude()); //aktueller Längergrad
|
|
||||||
}else{
|
|
||||||
//System.out.println("YYYbreitengrad: " + breitengrad);
|
|
||||||
//System.out.println("YYYlaengengrad: " + laengengrad);
|
|
||||||
mDatenbank.child("overviewAronTestetInDiesemAbschnitt").child("IDG" + k).child("breitengrad").setValue(breitengrad); //aktueller Breitengrad
|
|
||||||
mDatenbank.child("overviewAronTestetInDiesemAbschnitt").child("IDG" + k).child("laengengrad").setValue(laengengrad); //aktueller Längergrad
|
|
||||||
}
|
}
|
||||||
mDatenbank.child("overviewAronTestetInDiesemAbschnitt").child("IDG" + k).child("amplitude").setValue(1001);
|
return diff;
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
|
||||||
mDatenbank.child("overviewAronTestetInDiesemAbschnitt").child("IDG" + k).child("localdatetime").setValue(LocalDateTime.now().toString());
|
|
||||||
}
|
|
||||||
mDatenbank.child("overviewAronTestetInDiesemAbschnitt").child("IDG" + k).child("androidid").setValue(getandroidid());
|
|
||||||
}
|
|
||||||
|
|
||||||
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());
|
|
||||||
}
|
|
||||||
|
|
||||||
//TODO Edward Dauer für Timer berechnen bis Smartphone vibriert
|
|
||||||
|
|
||||||
private float distance(double currentlatitude, double currentlongitude, double originLat, double originLon) {
|
|
||||||
|
|
||||||
float[] results = new float[1];
|
|
||||||
Location.distanceBetween(currentlatitude, currentlongitude, originLat, originLon, results);
|
|
||||||
float distanceInMeters = results[0];
|
|
||||||
|
|
||||||
return distanceInMeters;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Reference in new issue
Block a user