|
|
|
|
|
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
|
boolean vibrationTrigger = true;
|
|
|
boolean vibrationTrigger = true;
|
|
|
|
|
|
boolean grabGPSandID = true;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private DatabaseReference mDatenbank;
|
|
|
private DatabaseReference mDatenbank;
|
|
|
|
|
|
|
|
|
getLocationPermission(); //Zuerst werden die aktuellen Standortdaten ermittelt
|
|
|
getLocationPermission(); //Zuerst werden die aktuellen Standortdaten ermittelt
|
|
|
|
|
|
|
|
|
getVibrationAbility();
|
|
|
getVibrationAbility();
|
|
|
|
|
|
System.out.println("Global Shit: " + globalShit);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
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)
|
|
|
{
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
System.out.println("!!!!!!!!!!!!!!!!!!!!!!!!!!!!setVibrationTimer wurde getriggert mit Index " + 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");
|
|
|
|
|
|
|
|
|
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 tatsächlich die DB beschrieben sobald der Timer abgelaufen ist
|
|
|
setVibrationInDataBase(index);
|
|
|
setVibrationInDataBase(index);
|
|
|
}
|
|
|
}
|
|
|
}.start();
|
|
|
}.start();
|
|
|
|
|
|
|
|
|
if(duration == 0)
|
|
|
if(duration == 0)
|
|
|
{
|
|
|
{
|
|
|
v.cancel(); //stop vibration if still running
|
|
|
v.cancel(); //stop vibration if still running
|
|
|
|
|
|
|
|
|
return;
|
|
|
return;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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));
|
|
|
|
|
|
|
|
|
//################################################################## ^^^^ 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()
|
|
|
|
|
|
|
|
|
});
|
|
|
});
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
public void processDataBaseUpdate (DataSnapshot data)
|
|
|
|
|
|
|
|
|
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 breitengradString;
|
|
|
|
|
|
String laengengradString;
|
|
|
|
|
|
String vibrationString;
|
|
|
|
|
|
String androidid;
|
|
|
String androidid;
|
|
|
int vibratingDevices = 0;
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
for (int i = 1; i<=4; i++)
|
|
|
|
|
|
|
|
|
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++)
|
|
|
{
|
|
|
{
|
|
|
breitengradString = data.child("overviewAronTestetInDiesemAbschnitt").child("IDG" + i).child("breitengrad").getValue().toString();
|
|
|
|
|
|
laengengradString = data.child("overviewAronTestetInDiesemAbschnitt").child("IDG" + i).child("laengengrad").getValue().toString();
|
|
|
|
|
|
|
|
|
vibrationString = data.child("overviewnodes").child("IDG" + i).child("g_vibration").getValue().toString();
|
|
|
|
|
|
if(vibrationString.equals("true"))
|
|
|
|
|
|
{
|
|
|
|
|
|
stateOfVibration = true;
|
|
|
|
|
|
}else
|
|
|
|
|
|
{
|
|
|
|
|
|
stateOfVibration = false;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
return stateOfVibration;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
androidid = data.child("overviewAronTestetInDiesemAbschnitt").child("IDG" + i).child("androidid").getValue().toString();
|
|
|
|
|
|
vibrationString = data.child("overviewAronTestetInDiesemAbschnitt").child("IDG" + i).child("vibration").getValue().toString();
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
if(!androidid.isEmpty())
|
|
|
|
|
|
|
|
|
public void processDataBaseUpdate (DataSnapshot data)
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
int indexMax = (int) data.child("overviewnodes").getChildrenCount();
|
|
|
|
|
|
|
|
|
|
|
|
//Festellen ob DB oder eigene GPS-Daten verwendet werden sollen
|
|
|
|
|
|
if(analyzeForUseOfOwnGPS(data))
|
|
|
|
|
|
{
|
|
|
|
|
|
useOwnGPS = true;
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
useOwnGPS = false;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//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(vibrationString == "false")
|
|
|
|
|
|
|
|
|
if(f>=2 && f<=indexMax)
|
|
|
{
|
|
|
{
|
|
|
//System.out.println("Index " + i + " Vibration ist false");
|
|
|
|
|
|
continue;
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
//System.out.println("Index " + i + " Vibration ist true");
|
|
|
|
|
|
if(androidid.equals(getandroidid()))
|
|
|
|
|
|
|
|
|
if(analyzeIfAnroidIdIsEmpty(data,f))
|
|
|
{
|
|
|
{
|
|
|
//System.out.println("Index " + i + " Vibration ist von mir. Falscher Alarm");
|
|
|
|
|
|
vibrationTrigger = false;
|
|
|
|
|
|
|
|
|
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();
|
|
|
|
|
|
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 && permissionToWriteToDataBase; f++)
|
|
|
|
|
|
{
|
|
|
|
|
|
if((!analyzeIfAnroidIdIsEmpty(data,f) && !analyzeForOwnAndroidID(data,f) && analyzeForStateOfVibration(data,f) && analyzeForExisitingGPSvalues(data,f) && permissionToWriteToDataBase))
|
|
|
{
|
|
|
{
|
|
|
//System.out.println("Index " + i + " ist leer");
|
|
|
|
|
|
if(androidid.isEmpty() && !breitengradString.isEmpty() && !laengengradString.isEmpty() && vibrationString.equals("false") && takeGPSfromDB)
|
|
|
|
|
|
{
|
|
|
|
|
|
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 " + i +" -> Übernehme Breitengrad: " + breitengradString + " und Laengengrad: " + laengengradString + " als eigene Position.");
|
|
|
|
|
|
breitengrad = Double.parseDouble(breitengradString);
|
|
|
|
|
|
laengengrad = Double.parseDouble(laengengradString);
|
|
|
|
|
|
useOwnGPS = false;
|
|
|
|
|
|
takeGPSfromDB = false;
|
|
|
|
|
|
}else
|
|
|
|
|
|
|
|
|
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))
|
|
|
{
|
|
|
{
|
|
|
if(!tookOwnGPS && takeGPSfromDB)
|
|
|
|
|
|
|
|
|
if (!analyzeForStateOfVibration(data,f))
|
|
|
{
|
|
|
{
|
|
|
//System.out.println("Nutze eigene DB. Bin bei Index " + i + " ++++++++++++++++++++++++++++++++++++++++++++");
|
|
|
|
|
|
tookOwnGPS = true;
|
|
|
|
|
|
useOwnGPS = true;
|
|
|
|
|
|
|
|
|
if(analyzeForExisitingGPSvalues(data,f))
|
|
|
|
|
|
{
|
|
|
|
|
|
float distanceToEarthquake;
|
|
|
|
|
|
distanceToEarthquake = distance(currentLocation.getLatitude(), currentLocation.getLongitude(), Double.parseDouble(breitengradQuellVibration), Double.parseDouble(laengengradQuellVibration));
|
|
|
|
|
|
long wellenAusbreitungsGeschwindigkeit = 4500; //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 wurde breits true gesetzt. Falscher Alarm");
|
|
|
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
if(vibrationTrigger == true && (vibratingDevices == 1))
|
|
|
|
|
|
|
|
|
else
|
|
|
{
|
|
|
{
|
|
|
//System.out.println("#########Freigabe zum Schreiben in DB mit Index " + i + " liegt vor. Schreibe nun... !!!!!#####################");
|
|
|
|
|
|
/*
|
|
|
|
|
|
System.out.println("currentLocation.getLatitude(): " + currentLocation.getLatitude());
|
|
|
|
|
|
System.out.println("currentLocation.getLongitude(): " + currentLocation.getLongitude());
|
|
|
|
|
|
System.out.println("Double.parseDouble(breitengradQuellVibration): " + Double.parseDouble(breitengradQuellVibration));
|
|
|
|
|
|
System.out.println("Double.parseDouble(laengengradQuellVibration): " + Double.parseDouble(laengengradQuellVibration));
|
|
|
|
|
|
System.out.println("######################################################################################################################################################################");
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
vibrationTrigger = false;
|
|
|
|
|
|
float distanceToEarthquake;
|
|
|
|
|
|
distanceToEarthquake = distance(currentLocation.getLatitude(), currentLocation.getLongitude(), Double.parseDouble(breitengradQuellVibration), Double.parseDouble(laengengradQuellVibration));
|
|
|
|
|
|
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);
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
for(f = f; f<=indexMax; f++)
|
|
|
|
|
|
{
|
|
|
|
|
|
if(analyzeIfAnroidIdIsEmpty(data,f) || analyzeForOwnAndroidID(data,f))
|
|
|
|
|
|
{
|
|
|
|
|
|
float distanceToEarthquake;
|
|
|
|
|
|
distanceToEarthquake = distance(currentLocation.getLatitude(), currentLocation.getLongitude(), Double.parseDouble(breitengradQuellVibration), Double.parseDouble(laengengradQuellVibration));
|
|
|
|
|
|
long wellenAusbreitungsGeschwindigkeit = 4500; //Meter die Sekunde
|
|
|
|
|
|
long delayInSeconds = (long) distanceToEarthquake/wellenAusbreitungsGeschwindigkeit; //s
|
|
|
|
|
|
long delayInMilliSeconds = delayInSeconds*1000;
|
|
|
|
|
|
setVibrationTimer(delayInMilliSeconds,1500,255,f);
|
|
|
|
|
|
permissionToWriteToDataBase = false;
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if(f == indexMax && !analyzeIfAnroidIdIsEmpty(data,f))
|
|
|
|
|
|
{
|
|
|
|
|
|
System.out.println(">>>Index " + f + " >>>Konnte keine freien Slot finden");
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
//TODO Weiterer Code von Patrick. @Aron Anschauen ob dieser noch verwendet werden muss da paar Sachen schon in dieser Version umgesetzt worde sind.
|
|
|
|
|
|
/*
|
|
|
|
|
|
//####### Auslesen für boolean-Werte #######:
|
|
|
|
|
|
int i = 1;
|
|
|
|
|
|
String vibrationString = data.child("overview").child("IDG").child("vibration").getValue().toString();
|
|
|
|
|
|
String amplitudeString = data.child("overview").child("IDG").child("amplitude").getValue().toString();
|
|
|
|
|
|
boolean vibration;
|
|
|
|
|
|
if(vibrationString.equals("true")){
|
|
|
|
|
|
vibration = true;
|
|
|
|
|
|
}else{
|
|
|
|
|
|
vibration = false;
|
|
|
|
|
|
}
|
|
|
|
|
|
int amplitude = Integer.parseInt(amplitudeString);
|
|
|
|
|
|
// Workaround beseiteigen: hier wird immer davon ausgegangen, dass auslösendes Gerät die ID 1 besitzt
|
|
|
|
|
|
if(vibration == true && i == 1)
|
|
|
|
|
|
{
|
|
|
|
|
|
float distance = distance(currentLocation.getLatitude(), currentLocation.getLongitude(),breitengrad,laengengrad);
|
|
|
|
|
|
long delay = getTimeStampDifference(distance);
|
|
|
|
|
|
setVibrationTimer(delay,1000,amplitude);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
public void allocateIDtoDatabaseSlot(int k)
|
|
|
|
|
|
{
|
|
|
|
|
|
mDatenbank = FirebaseDatabase.getInstance().getReference();
|
|
|
|
|
|
mDatenbank.child("overviewnodes").child("IDG" + k).child("a_androidid").setValue(getandroidid());
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void setVibrationInDataBase(int k)
|
|
|
public void setVibrationInDataBase(int k)
|
|
|
{
|
|
|
{
|
|
|
mDatenbank = FirebaseDatabase.getInstance().getReference();
|
|
|
mDatenbank = FirebaseDatabase.getInstance().getReference();
|
|
|
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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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("c_ip").setValue(getDeviceIpAdress());
|
|
|
if (useOwnGPS)
|
|
|
if (useOwnGPS)
|
|
|
{
|
|
|
{
|
|
|
//System.out.println("YYYcurrentLocation.getLatitude(): " + currentLocation.getLatitude());
|
|
|
|
|
|
//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
|
|
|
|
|
|
|
|
|
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{
|
|
|
}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);
|
|
|
|
|
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
|
|
|
|
|
mDatenbank.child("overviewAronTestetInDiesemAbschnitt").child("IDG" + k).child("localdatetime").setValue(LocalDateTime.now().toString());
|
|
|
|
|
|
|
|
|
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("overviewAronTestetInDiesemAbschnitt").child("IDG" + k).child("androidid").setValue(getandroidid());
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
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 ()
|
|
|
public String getandroidid ()
|
|
|
|
|
|
|
|
|
Log.w("Datenbankfehler", error.toException());
|
|
|
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) {
|
|
|
private float distance(double currentlatitude, double currentlongitude, double originLat, double originLon) {
|
|
|
|
|
|
|
|
|
float[] results = new float[1];
|
|
|
float[] results = new float[1];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return distanceInMeters;
|
|
|
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 #######:
|
|
|
|
|
|
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();
|
|
|
|
|
|
boolean vibration;
|
|
|
|
|
|
if(vibrationString.equals("true")){
|
|
|
|
|
|
vibration = true;
|
|
|
|
|
|
}else{
|
|
|
|
|
|
vibration = false;
|
|
|
|
|
|
}
|
|
|
|
|
|
int amplitude = Integer.parseInt(amplitudeString);
|
|
|
|
|
|
// Workaround beseiteigen: hier wird immer davon ausgegangen, dass auslösendes Gerät die ID 1 besitzt
|
|
|
|
|
|
if(vibration == true && i == 1)
|
|
|
|
|
|
{
|
|
|
|
|
|
float distance = distance(currentLocation.getLatitude(), currentLocation.getLongitude(),breitengrad,laengengrad);
|
|
|
|
|
|
long delay = getTimeStampDifference(distance);
|
|
|
|
|
|
setVibrationTimer(delay,1000,amplitude);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//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)
|
|
|
|
|
|
{
|
|
|
|
|
|
long diff= 0;
|
|
|
|
|
|
|
|
|
|
|
|
if (distance>0)
|
|
|
|
|
|
{
|
|
|
|
|
|
diff = (long)Math.round(1/(EARTHQUAKE_VELOCITY/distance));
|
|
|
|
|
|
}
|
|
|
|
|
|
return diff;
|
|
|
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|