|
|
@@ -128,7 +128,7 @@ public class SensorMapsActivity extends FragmentActivity implements OnMapReadyCa |
|
|
|
Toast.makeText(getApplicationContext(), "The Ground is shaking!", Toast.LENGTH_SHORT).show();
|
|
|
|
performVibration(duration, amplitude);
|
|
|
|
( (TextView) findViewById(R.id.txtSensor)).setText("No Earthquake upcoming");
|
|
|
|
//Hier wird tatsächlich die DB beschrieben sobald der Timer abgelaufen ist
|
|
|
|
//Hier wird in DB geschrieben
|
|
|
|
setVibrationInDataBase(index);
|
|
|
|
}
|
|
|
|
}.start();
|
|
|
@@ -289,6 +289,100 @@ public class SensorMapsActivity extends FragmentActivity implements OnMapReadyCa |
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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++)
|
|
|
|
{
|
|
|
|
if(f>=2 && f<=indexMax)
|
|
|
|
{
|
|
|
|
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();
|
|
|
|
breitengrad = Double.parseDouble(breitengradString);
|
|
|
|
laengengrad = Double.parseDouble(laengengradString);
|
|
|
|
allocateIDtoDatabaseSlot(f);
|
|
|
|
grabGPSandID = false;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
//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))
|
|
|
|
{
|
|
|
|
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 (!analyzeForStateOfVibration(data,f))
|
|
|
|
{
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
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");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean analyzeForUseOfOwnGPS(DataSnapshot data)
|
|
|
|
{
|
|
|
|
String nativeGPSString;
|
|
|
@@ -393,112 +487,6 @@ public class SensorMapsActivity extends FragmentActivity implements OnMapReadyCa |
|
|
|
return bothGPSvaluesExist;
|
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
System.out.println("useOWNgps: " + useOwnGPS);
|
|
|
|
//Wichtig zur Verwendung von GPS-Daten explizit aus der Datenbank
|
|
|
|
if(!useOwnGPS && grabGPSandID)
|
|
|
|
{
|
|
|
|
System.out.println("Entry: ");
|
|
|
|
for (int f = 1; f<=indexMax; f++)
|
|
|
|
{
|
|
|
|
System.out.println("1Entry: ");
|
|
|
|
if(f>=2 && f<=indexMax)
|
|
|
|
{
|
|
|
|
System.out.println("2Entry: ");
|
|
|
|
if(analyzeIfAnroidIdIsEmpty(data,f))
|
|
|
|
{
|
|
|
|
System.out.println("3Entry: ");
|
|
|
|
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("4Entry: ");
|
|
|
|
breitengrad = Double.parseDouble(breitengradString);
|
|
|
|
laengengrad = Double.parseDouble(laengengradString);
|
|
|
|
System.out.println("5Entry: ");
|
|
|
|
allocateIDtoDatabaseSlot(f);
|
|
|
|
grabGPSandID = false;
|
|
|
|
System.out.println("6Entry: ");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//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))
|
|
|
|
{
|
|
|
|
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 (!analyzeForStateOfVibration(data,f))
|
|
|
|
{
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
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");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void allocateIDtoDatabaseSlot(int k)
|
|
|
|
{
|
|
|
|
mDatenbank = FirebaseDatabase.getInstance().getReference();
|