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("aron"); | |||||
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; | |||||
} | |||||
} |
private boolean g_vibration; | private boolean g_vibration; | ||||
private long h_timestamp; | private long h_timestamp; | ||||
private int i_amplitude; | private int i_amplitude; | ||||
private int w_wellengeschwindigkeit; | |||||
public Devices() { | public Devices() { | ||||
} | } | ||||
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) { | |||||
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.a_androidid = a_androidid; | this.a_androidid = a_androidid; | ||||
this.b_localdatetime = b_localdatetime; | this.b_localdatetime = b_localdatetime; | ||||
this.c_ip = c_ip; | this.c_ip = c_ip; | ||||
this.g_vibration = g_vibration; | this.g_vibration = g_vibration; | ||||
this.h_timestamp = h_timestamp; | this.h_timestamp = h_timestamp; | ||||
this.i_amplitude = i_amplitude; | this.i_amplitude = i_amplitude; | ||||
this.w_wellengeschwindigkeit = w_wellengeschwindigkeit; | |||||
} | } | ||||
public String getA_androidid() { | public String getA_androidid() { | ||||
public void setI_amplitude(int i_amplitude) { | public void setI_amplitude(int i_amplitude) { | ||||
this.i_amplitude = 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; | |||||
} | |||||
} | } |
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; | ||||
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 mLowerThreshold = 5.5f; // für Emulator auf 0.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 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; | ||||
super.onCreate(savedInstanceState); | super.onCreate(savedInstanceState); | ||||
setContentView(R.layout.activity_earthquake_maps); | setContentView(R.layout.activity_earthquake_maps); | ||||
getDataBaseValuesNoListener(); | |||||
//Database Init | |||||
db.setMyWaveSpeed(2000); | |||||
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(); | ||||
} | } | ||||
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; | ||||
} | } | ||||
}; | }; | ||||
@RequiresApi(api = Build.VERSION_CODES.O) | |||||
private void writeEarthquakeToDatabase() | |||||
{ | |||||
setDataBaseValues(); | |||||
} | |||||
@Override | @Override | ||||
protected void onResume() { | protected void onResume() { | ||||
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(); | ||||
if(useOwnGPS) | |||||
System.out.println(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>" + db.getNativeGPScaseInDB()); | |||||
if(db.getNativeGPScaseInDB()) | |||||
{ | { | ||||
System.out.println("---Eigene GPS Daten werden verwendet"); | |||||
breitengrad = currentLocation.getLatitude(); | breitengrad = currentLocation.getLatitude(); | ||||
laengengrad = currentLocation.getLongitude(); | laengengrad = currentLocation.getLongitude(); | ||||
db.setShakeBreitengrad(breitengrad); | |||||
db.setShakeLaengengrad(laengengrad); | |||||
} | } | ||||
/* | |||||
if(useOwnGPS) //TODO Aron | |||||
{ | |||||
breitengrad = currentLocation.getLatitude(); | |||||
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); | ||||
//##################################################################################################################################################################### | //##################################################################################################################################################################### | ||||
//################################################################## vvv Datenbank Code vvv ######################################################################### | //################################################################## vvv Datenbank Code vvv ######################################################################### | ||||
public void getDataBaseValuesNoListener() | |||||
{ | |||||
mDatenbank = FirebaseDatabase.getInstance().getReference(); | |||||
mDatenbank.child("overviewnodes").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) | |||||
{ | |||||
processDeviceIndex(data); | |||||
processLocation(data); | |||||
//processMessageDisplay(data); | |||||
} | |||||
public void processDeviceIndex(DataSnapshot data) //Bestimmt freien IDG Index um Daten einschreiben zu können und legt diesen Index als indexID fest. | |||||
@RequiresApi(api = Build.VERSION_CODES.O) | |||||
private void writeEarthquakeToDatabase() | |||||
{ | { | ||||
for (int i = 1; i<=5; i++) | |||||
{ | |||||
String androidid = data.child("IDG" + i).child("a_androidid").getValue().toString(); | |||||
if(androidid.isEmpty()) | |||||
{ | |||||
indexID = i; | |||||
break; | |||||
}else | |||||
{ | |||||
continue; | |||||
} | |||||
} | |||||
} | |||||
public void processLocation(DataSnapshot data) //Wenn in DB f_nativegps als true hinterlegt ist, werden infolge eigene GPS koordinaten verwendet. Andernfalls wird Breitengrad und Laegengrad mit IDG = indexID als eigene GPS Daten verwendet | |||||
{ | |||||
String nativegpsString = data.child("IDG" + indexID).child("f_nativegps").getValue().toString(); | |||||
String breitengradString = data.child("IDG" + indexID).child("d_breitengrad").getValue().toString(); | |||||
String laengengradString = data.child("IDG" + indexID).child("e_laengengrad").getValue().toString(); | |||||
if(nativegpsString.equals("true")) | |||||
boolean nativeGPS; | |||||
if(db.getNativeGPScaseInDB()) | |||||
{ | { | ||||
useOwnGPS = true; | |||||
nativeGPS = true; | |||||
}else{ | }else{ | ||||
useOwnGPS = false; | |||||
breitengrad = Double.parseDouble(breitengradString); | |||||
laengengrad = Double.parseDouble(laengengradString); | |||||
nativeGPS = false; | |||||
} | } | ||||
} | |||||
public void processMessageDisplay(DataSnapshot data) | |||||
{ | |||||
String vibrationString; | |||||
String androidid; | |||||
for (int i = 1; i<=5; i++) | |||||
for(int i=1; i<=db.getAmountOfIDGs(); i++) | |||||
{ | { | ||||
androidid = data.child("overviewnodes").child("IDG" + i).child("a_androidid").getValue().toString(); | |||||
vibrationString = data.child("overviewnodes").child("IDG" + i).child("g_vibration").getValue().toString(); | |||||
if((!androidid.isEmpty()) && vibrationString.equals("true")) | |||||
if(!db.getStatusIFAndroidIDexistsInDB(db.getMyAndroidID())) | |||||
{ | { | ||||
allowShakeEvent = false; | |||||
//Wenn eigenen androidID nicht in DB existiert | |||||
Devices d1 = new Devices(); | |||||
d1 = new Devices(db.getMyAndroidID(), | |||||
LocalDateTime.now(ZoneOffset.UTC).toString(), | |||||
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; | |||||
} | } | ||||
} | } | ||||
} | } | ||||
public String getandroidid () | |||||
{ | |||||
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; | |||||
} | |||||
@RequiresApi(api = Build.VERSION_CODES.O) | |||||
public void setDataBaseValues() | |||||
{ | |||||
mDatenbank = FirebaseDatabase.getInstance().getReference(); | |||||
mDatenbank.child("overviewnodes").child("IDG" + indexID).child("a_androidid").setValue(getandroidid()); | |||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { | |||||
mDatenbank.child("overviewnodes").child("IDG" + indexID).child("b_localdatetime").setValue(LocalDateTime.now(ZoneOffset.UTC).toString()); | |||||
} | |||||
//mDatenbank.child("overviewnodes").child("IDG" + indexID).child("b_localdatetime").setValue(LocalDateTime.now(ZoneOffset.UTC).toString()); | |||||
//mDatenbank.child("overviewnodes").child("IDG" + indexID).child("b_localdatetime").setValue(LocalDateTime.now(ZoneOffset.UTC).toString()); | |||||
mDatenbank.child("overviewnodes").child("IDG" + indexID).child("c_ip").setValue(getDeviceIpAdress()); | |||||
mDatenbank.child("overviewnodes").child("IDG" + indexID).child("d_breitengrad").setValue(breitengrad); | |||||
mDatenbank.child("overviewnodes").child("IDG" + indexID).child("e_laengengrad").setValue(laengengrad); | |||||
//mDatenbank.child("overviewnodes").child("IDG" + indexID).child("f_nativegps").setValue(true); | |||||
mDatenbank.child("overviewnodes").child("IDG" + indexID).child("g_vibration").setValue(true); | |||||
mDatenbank.child("overviewnodes").child("IDG" + indexID).child("h_timestamp").setValue(Calendar.getInstance().getTimeInMillis()); | |||||
mDatenbank.child("overviewnodes").child("IDG" + indexID).child("i_amplitude").setValue(1000); | |||||
} | |||||
//################################################################## ^^^^ 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()); | |||||
} | |||||
*/ |
import androidx.fragment.app.FragmentActivity; | import androidx.fragment.app.FragmentActivity; | ||||
import android.app.Dialog; | import android.app.Dialog; | ||||
import android.content.Intent; | import android.content.Intent; | ||||
import android.net.wifi.WifiManager; | |||||
import android.os.Bundle; | import android.os.Bundle; | ||||
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; | ||||
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; | ||||
Datenbank db = new Datenbank(); | |||||
@Override | @Override | ||||
protected void onCreate(Bundle savedInstanceState) { | protected void onCreate(Bundle savedInstanceState) { | ||||
setContentView(R.layout.activity_main); | setContentView(R.layout.activity_main); | ||||
if (isServiceOK()){ | if (isServiceOK()){ | ||||
//Für Dantenbank | |||||
db.setMyWaveSpeed(2000); | |||||
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(); | ||||
} | } | ||||
} | } | ||||
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); | |||||
btnSensor.setEnabled(false); | |||||
btnEarthquake.setEnabled(true); | |||||
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); | |||||
btnEarthquake.setEnabled(false); | |||||
btnSensor.setEnabled(true); | |||||
btnEarthquake.setEnabled(true); | |||||
startActivity(intent); | startActivity(intent); | ||||
} | } | ||||
}); | }); | ||||
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); | |||||
btnMuster.setEnabled(false); | |||||
btnLeer.setEnabled(true); | |||||
btnMuster.setEnabled(true); | |||||
btnReset.setEnabled(true); | btnReset.setEnabled(true); | ||||
deviceInitDataBase(); | |||||
db.setNonNativeCaseInDB(); | |||||
//deviceInitDataBase(); //TODO: ARON | |||||
} | } | ||||
}); | }); | ||||
btnSensor.setEnabled(true); | btnSensor.setEnabled(true); | ||||
btnMuster.setEnabled(false); | btnMuster.setEnabled(false); | ||||
btnReset.setEnabled(true); | btnReset.setEnabled(true); | ||||
btnLeer.setEnabled(false); | |||||
datenBankLeeren(); | |||||
btnLeer.setEnabled(true); | |||||
//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 | |||||
btnMuster.setEnabled(true); | btnMuster.setEnabled(true); | ||||
btnLeer.setEnabled(true); | btnLeer.setEnabled(true); | ||||
btnEarthquake.setEnabled(true); | |||||
btnSensor.setEnabled(true); | |||||
} | } | ||||
}); | }); | ||||
public void deviceInitDataBase() | public void deviceInitDataBase() | ||||
{ | { | ||||
mDatenbank = FirebaseDatabase.getInstance().getReference(); | mDatenbank = FirebaseDatabase.getInstance().getReference(); | ||||
Devices d1 = new Devices("","","",49.58967957913626,11.011387124069765,false,false,0,1000); //Erlangen 49.58967957913626, 11.011387124069765 | |||||
Devices d2 = new Devices("","","",48.7560280895443,11.425157702952347,false,false,0,1000); //Ingolstadt 48.7560280895443, 11.425157702952347 | |||||
Devices d3 = new Devices("","","",48.16958655466396,11.617418429524394,false,false,0,1000); //München 48.16958655466396, 11.617418429524394 | |||||
Devices d4 = new Devices("","","",45.55620112204013,12.342516140205387,false,false,0,1000); //Venedig 45.55620112204013, 12.342516140205387 | |||||
Devices d5 = new Devices("","","",41.9204784730154,12.651055829215638,false,false,0,1000); //Rom 41.9204784730154, 12.651055829215638 | |||||
mDatenbank.child("overviewnodes").child("IDG1").setValue(d1); | |||||
mDatenbank.child("overviewnodes").child("IDG2").setValue(d2); | |||||
mDatenbank.child("overviewnodes").child("IDG3").setValue(d3); | |||||
mDatenbank.child("overviewnodes").child("IDG4").setValue(d4); | |||||
mDatenbank.child("overviewnodes").child("IDG5").setValue(d4); | |||||
mDatenbank.child("overviewnodes").child("IDG5").setValue(d5); | |||||
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("aron").child("IDG1").setValue(d1); | |||||
mDatenbank.child("aron").child("IDG2").setValue(d2); | |||||
mDatenbank.child("aron").child("IDG3").setValue(d3); | |||||
mDatenbank.child("aron").child("IDG4").setValue(d4); | |||||
mDatenbank.child("aron").child("IDG5").setValue(d4); | |||||
mDatenbank.child("aron").child("IDG5").setValue(d5); | |||||
} | } | ||||
public void getDataBaseValuesNoListener() | public void getDataBaseValuesNoListener() | ||||
{ | { | ||||
mDatenbank = FirebaseDatabase.getInstance().getReference(); | mDatenbank = FirebaseDatabase.getInstance().getReference(); | ||||
mDatenbank.child("overviewnodes").get().addOnCompleteListener(new OnCompleteListener<DataSnapshot>() { | |||||
mDatenbank.child("aron").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()) { | ||||
mDatenbank = FirebaseDatabase.getInstance().getReference(); | mDatenbank = FirebaseDatabase.getInstance().getReference(); | ||||
for (int i = 1; i<=5; i++) | for (int i = 1; i<=5; i++) | ||||
{ | { | ||||
mDatenbank.child("overviewnodes").child("IDG" + i).child("a_androidid").setValue(""); | |||||
mDatenbank.child("overviewnodes").child("IDG" + i).child("b_localdatetime").setValue(""); | |||||
mDatenbank.child("overviewnodes").child("IDG" + i).child("c_ip").setValue(""); | |||||
mDatenbank.child("overviewnodes").child("IDG" + i).child("d_breitengrad").setValue(""); | |||||
mDatenbank.child("overviewnodes").child("IDG" + i).child("e_laengengrad").setValue(""); | |||||
mDatenbank.child("overviewnodes").child("IDG" + i).child("f_nativegps").setValue(true); | |||||
mDatenbank.child("overviewnodes").child("IDG" + i).child("g_vibration").setValue(false); | |||||
mDatenbank.child("overviewnodes").child("IDG" + i).child("h_timestamp").setValue(""); | |||||
mDatenbank.child("overviewnodes").child("IDG" + i).child("i_amplitude").setValue(""); | |||||
mDatenbank.child("aron").child("IDG" + i).child("a_androidid").setValue(""); | |||||
mDatenbank.child("aron").child("IDG" + i).child("b_localdatetime").setValue(""); | |||||
mDatenbank.child("aron").child("IDG" + i).child("c_ip").setValue(""); | |||||
mDatenbank.child("aron").child("IDG" + i).child("d_breitengrad").setValue(""); | |||||
mDatenbank.child("aron").child("IDG" + i).child("e_laengengrad").setValue(""); | |||||
mDatenbank.child("aron").child("IDG" + i).child("f_nativegps").setValue(true); | |||||
mDatenbank.child("aron").child("IDG" + i).child("g_vibration").setValue(false); | |||||
mDatenbank.child("aron").child("IDG" + i).child("h_timestamp").setValue(""); | |||||
mDatenbank.child("aron").child("IDG" + i).child("i_amplitude").setValue(""); | |||||
} | } | ||||
} | } | ||||
public void testProcess(DataSnapshot data) | public void testProcess(DataSnapshot data) | ||||
{ | { | ||||
mDatenbank = FirebaseDatabase.getInstance().getReference().child("overviewnodes"); | |||||
mDatenbank = FirebaseDatabase.getInstance().getReference().child("aron"); | |||||
} | } | ||||
} | } |
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; | ||||
private boolean tookOwnGPS = false; | private boolean tookOwnGPS = false; | ||||
private boolean globalShit = true; | private boolean globalShit = true; | ||||
private boolean permissionToWriteToDataBase = true; | private boolean permissionToWriteToDataBase = true; | ||||
private DataSnapshot datenBankSnapShot; | |||||
boolean vibrationTrigger = true; | boolean vibrationTrigger = true; | ||||
boolean grabGPSandID = true; | boolean grabGPSandID = true; | ||||
super.onCreate(savedInstanceState); | super.onCreate(savedInstanceState); | ||||
setContentView(R.layout.activity_sensor_maps); | setContentView(R.layout.activity_sensor_maps); | ||||
//Database Init | |||||
db.setMyWaveSpeed(2000); | |||||
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); | ||||
getLocationPermission(); //Zuerst werden die aktuellen Standortdaten ermittelt | getLocationPermission(); //Zuerst werden die aktuellen Standortdaten ermittelt | ||||
getVibrationAbility(); | getVibrationAbility(); | ||||
System.out.println("Global Shit: " + globalShit); | |||||
} | } | ||||
performVibration(duration, amplitude); | performVibration(duration, amplitude); | ||||
( (TextView) findViewById(R.id.txtSensor)).setText("No Earthquake upcoming"); | ( (TextView) findViewById(R.id.txtSensor)).setText("No Earthquake upcoming"); | ||||
//Hier wird in DB geschrieben | //Hier wird in DB geschrieben | ||||
setVibrationInDataBase(index); | |||||
setVibrationInDataBase(index); //TODO Aron | |||||
} | } | ||||
}.start(); | }.start(); | ||||
} | } | ||||
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); | ||||
} | } | ||||
@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) { | ||||
}); | }); | ||||
} | } | ||||
public void processDataBaseUpdate (DataSnapshot data) | public void processDataBaseUpdate (DataSnapshot data) | ||||
{ | { | ||||
int indexMax = (int) data.child("overviewnodes").getChildrenCount(); | |||||
int indexMax = (int) data.child("aron").getChildrenCount(); | |||||
//Festellen ob DB oder eigene GPS-Daten verwendet werden sollen | //Festellen ob DB oder eigene GPS-Daten verwendet werden sollen | ||||
if(analyzeForUseOfOwnGPS(data)) | if(analyzeForUseOfOwnGPS(data)) | ||||
{ | { | ||||
{ | { | ||||
if(analyzeIfAnroidIdIsEmpty(data,f)) | if(analyzeIfAnroidIdIsEmpty(data,f)) | ||||
{ | { | ||||
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(); | |||||
String breitengradString = data.child("aron").child("IDG" + f).child("d_breitengrad").getValue().toString(); | |||||
String laengengradString = data.child("aron").child("IDG" + f).child("e_laengengrad").getValue().toString(); | |||||
breitengrad = Double.parseDouble(breitengradString); | breitengrad = Double.parseDouble(breitengradString); | ||||
laengengrad = Double.parseDouble(laengengradString); | laengengrad = Double.parseDouble(laengengradString); | ||||
allocateIDtoDatabaseSlot(f); | allocateIDtoDatabaseSlot(f); | ||||
} | } | ||||
} | } | ||||
//Hier sind die Schreibregeln für die DB definiert wenn Sensor aktiviert ist | //Hier sind die Schreibregeln für die DB definiert wenn Sensor aktiviert ist | ||||
for (int f = 1; f<=indexMax && permissionToWriteToDataBase; f++) | |||||
for (int f = 1; f<=indexMax; f++) | |||||
{ | { | ||||
if((!analyzeIfAnroidIdIsEmpty(data,f) && !analyzeForOwnAndroidID(data,f) && analyzeForStateOfVibration(data,f) && analyzeForExisitingGPSvalues(data,f) && permissionToWriteToDataBase)) | if((!analyzeIfAnroidIdIsEmpty(data,f) && !analyzeForOwnAndroidID(data,f) && analyzeForStateOfVibration(data,f) && analyzeForExisitingGPSvalues(data,f) && permissionToWriteToDataBase)) | ||||
{ | { | ||||
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(); | |||||
System.out.println("Index: " + f + ": Eintrittskriterien erfüllt."); | |||||
//Nehme Quelle GPS Daten | |||||
String breitengradString = data.child("aron").child("IDG" + f).child("d_breitengrad").getValue().toString(); | |||||
String laengengradString = data.child("aron").child("IDG" + f).child("e_laengengrad").getValue().toString(); | |||||
breitengradQuellVibration = breitengradString; | breitengradQuellVibration = breitengradString; | ||||
laengengradQuellVibration = laengengradString; | laengengradQuellVibration = laengengradString; | ||||
f=1; | f=1; | ||||
if(analyzeForOwnAndroidID(data,f)) | if(analyzeForOwnAndroidID(data,f)) | ||||
{ | { | ||||
System.out.println("Index: " + f + ": Eigene ID vorhanden."); | |||||
if (!analyzeForStateOfVibration(data,f)) | if (!analyzeForStateOfVibration(data,f)) | ||||
{ | { | ||||
if(analyzeForExisitingGPSvalues(data,f)) | |||||
System.out.println("Index: " + f + ": Vibration is false."); | |||||
if(analyzeForExisitingGPSvalues(data,f) && permissionToWriteToDataBase) | |||||
{ | { | ||||
//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("aron").child("IDG" + f).child("a_androidid").setValue(getandroidid()); | |||||
float distanceToEarthquake; | float distanceToEarthquake; | ||||
distanceToEarthquake = distance(currentLocation.getLatitude(), currentLocation.getLongitude(), Double.parseDouble(breitengradQuellVibration), Double.parseDouble(laengengradQuellVibration)); | distanceToEarthquake = distance(currentLocation.getLatitude(), currentLocation.getLongitude(), Double.parseDouble(breitengradQuellVibration), Double.parseDouble(laengengradQuellVibration)); | ||||
long wellenAusbreitungsGeschwindigkeit = 500; //Meter die Sekunde | |||||
long wellenAusbreitungsGeschwindigkeit = (long) db.getMyWaveSpeed(); //Meter die Sekunde | |||||
long delayInSeconds = (long) distanceToEarthquake/wellenAusbreitungsGeschwindigkeit; //s | long delayInSeconds = (long) distanceToEarthquake/wellenAusbreitungsGeschwindigkeit; //s | ||||
long delayInMilliSeconds = delayInSeconds*1000; | long delayInMilliSeconds = delayInSeconds*1000; | ||||
setVibrationTimer(delayInMilliSeconds,1500,255,f); | setVibrationTimer(delayInMilliSeconds,1500,255,f); | ||||
break; | break; | ||||
} | } | ||||
else{ | else{ | ||||
System.out.println("###Index " + f + " >>>Habe keine GPS daten..."); | |||||
System.out.println("Index: " + f + ": Habe keine GPS Daten"); | |||||
} | } | ||||
}else{ | }else{ | ||||
System.out.println(">>>Index " + f + " >>>Meine Vibration wurde breits true gesetzt. Falscher Alarm"); | |||||
System.out.println("Index: " + f + ": Meine Vibration ist bereits true."); | |||||
break; | break; | ||||
} | } | ||||
} | } | ||||
else | else | ||||
{ | { | ||||
System.out.println("Index: " + f + ": Eigene ID nicht vorhanden"); | |||||
for(f = f; f<=indexMax; f++) | for(f = f; f<=indexMax; f++) | ||||
{ | { | ||||
if(analyzeIfAnroidIdIsEmpty(data,f) || analyzeForOwnAndroidID(data,f)) | |||||
if((analyzeIfAnroidIdIsEmpty(data,f) || analyzeForOwnAndroidID(data,f)) && permissionToWriteToDataBase) | |||||
{ | { | ||||
//System.out.println("Index: " + f + ": Diese Slot war leer oder es ist meine eigene ID. Ich schreibe hier rein"); | |||||
//mDatenbank = FirebaseDatabase.getInstance().getReference(); | |||||
//mDatenbank.child("aron").child("IDG" + f).child("a_androidid").setValue(getandroidid()); | |||||
float distanceToEarthquake; | float distanceToEarthquake; | ||||
distanceToEarthquake = distance(currentLocation.getLatitude(), currentLocation.getLongitude(), Double.parseDouble(breitengradQuellVibration), Double.parseDouble(laengengradQuellVibration)); | distanceToEarthquake = distance(currentLocation.getLatitude(), currentLocation.getLongitude(), Double.parseDouble(breitengradQuellVibration), Double.parseDouble(laengengradQuellVibration)); | ||||
long wellenAusbreitungsGeschwindigkeit = 500; //Meter die Sekunde | |||||
long wellenAusbreitungsGeschwindigkeit = (long) db.getMyWaveSpeed(); //Meter die Sekunde | |||||
long delayInSeconds = (long) distanceToEarthquake/wellenAusbreitungsGeschwindigkeit; //s | long delayInSeconds = (long) distanceToEarthquake/wellenAusbreitungsGeschwindigkeit; //s | ||||
long delayInMilliSeconds = delayInSeconds*1000; | long delayInMilliSeconds = delayInSeconds*1000; | ||||
setVibrationTimer(delayInMilliSeconds,1500,255,f); | setVibrationTimer(delayInMilliSeconds,1500,255,f); | ||||
String nativeGPSString; | String nativeGPSString; | ||||
boolean nativeGPS; | boolean nativeGPS; | ||||
int amountNativeGPSisTrue = 0; | int amountNativeGPSisTrue = 0; | ||||
int indexMax = (int) data.child("overviewnodes").getChildrenCount(); | |||||
int indexMax = (int) data.child("aron").getChildrenCount(); | |||||
for (int i = 1; i <= indexMax; i++) | for (int i = 1; i <= indexMax; i++) | ||||
{ | { | ||||
nativeGPSString = data.child("overviewnodes").child("IDG" + i).child("f_nativegps").getValue().toString(); | |||||
nativeGPSString = data.child("aron").child("IDG" + i).child("f_nativegps").getValue().toString(); | |||||
if(nativeGPSString.equals("true")) | if(nativeGPSString.equals("true")) | ||||
{ | { | ||||
amountNativeGPSisTrue++; | amountNativeGPSisTrue++; | ||||
public boolean analyzeIfAnroidIdIsEmpty(DataSnapshot data, int k) | public boolean analyzeIfAnroidIdIsEmpty(DataSnapshot data, int k) | ||||
{ | { | ||||
String androidid; | String androidid; | ||||
int indexMax = (int) data.child("overviewnodes").getChildrenCount(); | |||||
int indexMax = (int) data.child("aron").getChildrenCount(); | |||||
boolean androididempty = false; | boolean androididempty = false; | ||||
for (int i = k; i <= k; i++) | for (int i = k; i <= k; i++) | ||||
{ | { | ||||
androidid = data.child("overviewnodes").child("IDG" + i).child("a_androidid").getValue().toString(); | |||||
androidid = data.child("aron").child("IDG" + i).child("a_androidid").getValue().toString(); | |||||
if(androidid.isEmpty()) | if(androidid.isEmpty()) | ||||
{ | { | ||||
androididempty = true; | androididempty = true; | ||||
{ | { | ||||
String androididString; | String androididString; | ||||
boolean ownAndroidID = false; | boolean ownAndroidID = false; | ||||
int indexMax = (int) data.child("overviewnodes").getChildrenCount(); | |||||
int indexMax = (int) data.child("aron").getChildrenCount(); | |||||
for (int i = k; i <= k; i++) | for (int i = k; i <= k; i++) | ||||
{ | { | ||||
androididString = data.child("overviewnodes").child("IDG" + i).child("a_androidid").getValue().toString(); | |||||
androididString = data.child("aron").child("IDG" + i).child("a_androidid").getValue().toString(); | |||||
if(androididString.equals(getandroidid())) | if(androididString.equals(getandroidid())) | ||||
{ | { | ||||
ownAndroidID = true; | ownAndroidID = true; | ||||
{ | { | ||||
String vibrationString; | String vibrationString; | ||||
boolean stateOfVibration = false; | boolean stateOfVibration = false; | ||||
int indexMax = (int) data.child("overviewnodes").getChildrenCount(); | |||||
int indexMax = (int) data.child("aron").getChildrenCount(); | |||||
for (int i = k; i <= k; i++) | for (int i = k; i <= k; i++) | ||||
{ | { | ||||
vibrationString = data.child("overviewnodes").child("IDG" + i).child("g_vibration").getValue().toString(); | |||||
vibrationString = data.child("aron").child("IDG" + i).child("g_vibration").getValue().toString(); | |||||
if(vibrationString.equals("true")) | if(vibrationString.equals("true")) | ||||
{ | { | ||||
stateOfVibration = true; | stateOfVibration = true; | ||||
String breitengradString; | String breitengradString; | ||||
String laengengradString; | String laengengradString; | ||||
boolean bothGPSvaluesExist = false; | boolean bothGPSvaluesExist = false; | ||||
int indexMax = (int) data.child("overviewnodes").getChildrenCount(); | |||||
int indexMax = (int) data.child("aron").getChildrenCount(); | |||||
for (int i = k; i <= k; i++) | 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(); | |||||
breitengradString = data.child("aron").child("IDG" + i).child("d_breitengrad").getValue().toString(); | |||||
laengengradString = data.child("aron").child("IDG" + i).child("e_laengengrad").getValue().toString(); | |||||
if(!breitengradString.isEmpty() && !laengengradString.isEmpty()) | if(!breitengradString.isEmpty() && !laengengradString.isEmpty()) | ||||
{ | { | ||||
bothGPSvaluesExist = true; | bothGPSvaluesExist = true; | ||||
public void allocateIDtoDatabaseSlot(int k) | public void allocateIDtoDatabaseSlot(int k) | ||||
{ | { | ||||
mDatenbank = FirebaseDatabase.getInstance().getReference(); | mDatenbank = FirebaseDatabase.getInstance().getReference(); | ||||
mDatenbank.child("overviewnodes").child("IDG" + k).child("a_androidid").setValue(getandroidid()); | |||||
mDatenbank.child("aron").child("IDG" + k).child("a_androidid").setValue(getandroidid()); | |||||
} | } | ||||
@RequiresApi(api = Build.VERSION_CODES.O) | @RequiresApi(api = Build.VERSION_CODES.O) | ||||
public void setVibrationInDataBase(int k) | public void setVibrationInDataBase(int k) | ||||
{ | { | ||||
mDatenbank = FirebaseDatabase.getInstance().getReference(); | |||||
mDatenbank.child("overviewnodes").child("IDG" + k).child("a_androidid").setValue(getandroidid()); | |||||
System.out.println("Es wird versucht in DB zu schreiben...."); | |||||
for(k =k; k<=datenBankSnapShot.child("aron").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)); | |||||
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()); | |||||
//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("aron").child("IDG" + k).child("a_androidid").setValue(getandroidid()); | |||||
} | |||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { | |||||
//mDatenbank.child("aron").child("IDG" + k).child("b_localdatetime").setValue(LocalDateTime.now().toString()); | |||||
mDatenbank.child("aron").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("aron").child("IDG" + k).child("c_ip").setValue(getDeviceIpAdress()); | |||||
if (useOwnGPS) | |||||
{ | |||||
mDatenbank.child("aron").child("IDG" + k).child("f_nativegps").setValue(true); | |||||
mDatenbank.child("aron").child("IDG" + k).child("d_breitengrad").setValue(currentLocation.getLatitude()); //aktueller Breitengrad | |||||
mDatenbank.child("aron").child("IDG" + k).child("e_laengengrad").setValue(currentLocation.getLongitude()); //aktueller Längergrad | |||||
}else{ | |||||
mDatenbank.child("aron").child("IDG" + k).child("d_breitengrad").setValue(breitengrad); //aktueller Breitengrad | |||||
mDatenbank.child("aron").child("IDG" + k).child("e_laengengrad").setValue(laengengrad); //aktueller Längergrad | |||||
mDatenbank.child("aron").child("IDG" + k).child("f_nativegps").setValue(false); | |||||
} | |||||
mDatenbank.child("aron").child("IDG" + k).child("g_vibration").setValue(true); | |||||
mDatenbank.child("aron").child("IDG" + k).child("h_timestamp").setValue(Calendar.getInstance().getTimeInMillis()); //aktueller Zeitstempel wird in Datenbank eingetragen | |||||
mDatenbank.child("aron").child("IDG" + k).child("i_amplitude").setValue(1000); | |||||
mDatenbank.child("aron").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("aron").getChildrenCount()) | |||||
{ | |||||
System.out.println("Kein freier Slot mehr vorhanden"); | |||||
break; | |||||
} | |||||
} | |||||
} | } | ||||
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); | |||||
} | } | ||||
public String getDeviceIpAdress () | public String getDeviceIpAdress () | ||||
/* | /* | ||||
//####### Auslesen für boolean-Werte #######: | //####### Auslesen für boolean-Werte #######: | ||||
int i = 1; | int i = 1; | ||||
String vibrationString = data.child("overviewnodes").child("IDG").child("vibration").getValue().toString(); | |||||
String amplitudeString = data.child("overviewnodes").child("IDG").child("amplitude").getValue().toString(); | |||||
String vibrationString = data.child("aron").child("IDG").child("vibration").getValue().toString(); | |||||
String amplitudeString = data.child("aron").child("IDG").child("amplitude").getValue().toString(); | |||||
boolean vibration; | boolean vibration; | ||||
if(vibrationString.equals("true")){ | if(vibrationString.equals("true")){ | ||||
vibration = true; | vibration = true; |