Compare commits

...
39 Commits
Author SHA1 Message Date
Raz492 054e9687a8 Alpha Version 3.500 V2 2021-06-28 13:18:52 +02:00
Raz492 2d4508ec1a Alpha Version 3.500 2021-06-28 13:18:30 +02:00
Raz492 5dd5d3c892 Alpha Version 3.500 2021-06-28 12:02:41 +02:00
Raz492 a4cb71a8f3 Alpha Version 3.1 - Ohne DB Schreibkonflikte 2021-06-28 11:42:46 +02:00
Raz492 eb620bccbc Alpha Version 3 - Ohne DB Schreibkonflikte 2021-06-28 11:31:16 +02:00
Raz492 69070b020f AlphaV21 mit GeschwindigkeitWelle 500m-s 2021-06-27 20:50:58 +02:00
Raz492 5159f9da57 AlphaV21 mit Buildversion 2021-06-27 20:33:39 +02:00
Raz492 e9d75b7ec4 AlphaV21 2021-06-27 13:04:27 +02:00
Raz492 45d9a86d48 AlphaV20 2021-06-27 12:37:55 +02:00
AbdulajevAr51780 085ea36824 CrashFix 2021-06-26 12:53:48 +00:00
AbdulajevAr51780 a6b614dabe CrashFix 2021-06-26 12:53:34 +00:00
AbdulajevAr51780 0809d06f3f CrashFix 2021-06-26 12:53:16 +00:00
AbdulajevAr51780 3827352818 Dateien hochladen nach „app/src/main/java/de/edotzlaff/schockwelle“ 2021-06-26 12:52:43 +00:00
halbothpa61667 5c59f7732e if(amplitude > 255 || amplitude < 1)
amplitude = VibrationEffect.DEFAULT_AMPLITUDE;
2021-06-25 10:57:27 +02:00
halbothpa61667 eb68c99d99 onPause() onResume() 2021-06-25 10:37:45 +02:00
AbdulajevAr51780 0cb1101aa8 Dateien hochladen nach „app/src/main“ 2021-06-21 19:09:07 +00:00
AbdulajevAr51780 0864c39091 Dateien hochladen nach „app/src/main/res/layout“ 2021-06-21 19:08:37 +00:00
AbdulajevAr51780 b6da735750 Dateien hochladen nach „app/src/main/res/layout“ 2021-06-21 19:08:30 +00:00
AbdulajevAr51780 4d5e9405d4 Dateien hochladen nach „app/src/main/res/layout“ 2021-06-21 19:08:24 +00:00
AbdulajevAr51780 a780c9e900 Dateien hochladen nach „app/src/main/java/de/edotzlaff/schockwelle“ 2021-06-21 19:07:32 +00:00
AbdulajevAr51780 5b116a1773 Dateien hochladen nach „app/src/main/java/de/edotzlaff/schockwelle“ 2021-06-21 19:07:25 +00:00
AbdulajevAr51780 41c36a9e02 Dateien hochladen nach „app/src/main/java/de/edotzlaff/schockwelle“ 2021-06-21 19:07:19 +00:00
AbdulajevAr51780 e85656eb58 Dateien hochladen nach „app/src/main/java/de/edotzlaff/schockwelle“ 2021-06-21 19:07:12 +00:00
AbdulajevAr51780 d1639e103e Dateien hochladen nach „app/src/main“ 2021-06-20 20:36:50 +00:00
AbdulajevAr51780 22dec5900c Dateien hochladen nach „app/src/main/java/de/edotzlaff/schockwelle“ 2021-06-20 20:11:06 +00:00
AbdulajevAr51780 24e651da4e Dateien hochladen nach „app/src/main/java/de/edotzlaff/schockwelle“ 2021-06-20 20:10:55 +00:00
AbdulajevAr51780 f414fa62f2 Dateien hochladen nach „app/src/main/java/de/edotzlaff/schockwelle“ 2021-06-20 20:10:40 +00:00
AbdulajevAr51780 700c5ba792 Dateien hochladen nach „app/src/main/java/de/edotzlaff/schockwelle“ 2021-06-20 20:10:31 +00:00
AbdulajevAr51780 7345a35d97 Dateien hochladen nach „app/src/main/java/de/edotzlaff/schockwelle“ 2021-06-20 20:10:20 +00:00
AbdulajevAr51780 23dd646e90 Dateien hochladen nach „app/src/main/res/values“ 2021-06-20 19:31:13 +00:00
AbdulajevAr51780 7e10399b92 Dateien hochladen nach „app/src/main/res/layout“ 2021-06-20 19:30:26 +00:00
AbdulajevAr51780 3c7f30a74b Dateien hochladen nach „app/src/main/res/layout“ 2021-06-20 19:30:12 +00:00
AbdulajevAr51780 e50fafd505 Dateien hochladen nach „app/src/main/res/layout“ 2021-06-20 19:30:01 +00:00
AbdulajevAr51780 af1e25bf8c Dateien hochladen nach „app/src/main/java/de/edotzlaff/schockwelle“ 2021-06-20 19:28:07 +00:00
AbdulajevAr51780 b930e39dee Dateien hochladen nach „app/src/main/java/de/edotzlaff/schockwelle“ 2021-06-20 19:27:57 +00:00
AbdulajevAr51780 d7addc222d Dateien hochladen nach „app/src/main/java/de/edotzlaff/schockwelle“ 2021-06-20 19:27:36 +00:00
AbdulajevAr51780 903664503a Dateien hochladen nach „app/src/main/java/de/edotzlaff/schockwelle“ 2021-06-20 19:27:23 +00:00
Raz492 1d2485d59e Merge remote-tracking branch 'origin/master' 2021-06-20 21:24:34 +02:00
Raz492 eba661a070 Merge remote-tracking branch 'origin/master'
# Conflicts:
#	app/src/main/AndroidManifest.xml
#	app/src/main/java/de/edotzlaff/schockwelle/EarthquakeMapsActivity.java
#	app/src/main/java/de/edotzlaff/schockwelle/SensorMapsActivity.java
#	app/src/main/res/layout/activity_earthquake_maps.xml
2021-06-20 21:22:55 +02:00
10 changed files with 2161 additions and 1391 deletions

No files matched your search

+52 -52
View File
@@ -1,53 +1,53 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" <manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="de.edotzlaff.schockwelle"> package="de.edotzlaff.schockwelle">
<!-- <!--
The ACCESS_COARSE/FINE_LOCATION permissions are not required to use The ACCESS_COARSE/FINE_LOCATION permissions are not required to use
Google Maps Android API v2, but you must specify either coarse or fine Google Maps Android API v2, but you must specify either coarse or fine
location permissions for the "MyLocation" functionality. location permissions for the "MyLocation" functionality.
--> -->
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /> <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.VIBRATE" /> <uses-permission android:name="android.permission.VIBRATE" />
<application <application
android:allowBackup="true" android:allowBackup="true"
android:icon="@mipmap/schockicon" android:icon="@mipmap/schockicon"
android:label="@string/app_name" android:label="@string/app_name"
android:roundIcon="@mipmap/schockicon" android:roundIcon="@mipmap/schockicon"
android:supportsRtl="true" android:supportsRtl="true"
android:theme="@style/Theme.Schockwelle"> android:theme="@style/Theme.Schockwelle">
<!-- <!--
The API key for Google Maps-based APIs is defined as a string resource. The API key for Google Maps-based APIs is defined as a string resource.
(See the file "res/values/google_maps_api.xml"). (See the file "res/values/google_maps_api.xml").
Note that the API key is linked to the encryption key used to sign the APK. Note that the API key is linked to the encryption key used to sign the APK.
You need a different API key for each encryption key, including the release key that is used to You need a different API key for each encryption key, including the release key that is used to
sign the APK for publishing. sign the APK for publishing.
You can define the keys for the debug and release targets in src/debug/ and src/release/. You can define the keys for the debug and release targets in src/debug/ and src/release/.
--> -->
<meta-data <meta-data
android:name="com.google.android.geo.API_KEY" android:name="com.google.android.geo.API_KEY"
android:value="@string/google_maps_key" /> android:value="@string/google_maps_key" />
<activity <activity
android:name=".SensorMapsActivity" android:name=".SensorMapsActivity"
android:label="@string/title_activity_sensor_maps"></activity> android:label="@string/title_activity_sensor_maps"></activity>
<activity <activity
android:name=".EarthquakeMapsActivity" android:name=".EarthquakeMapsActivity"
android:label="@string/title_activity_earthquake_maps"/> android:label="@string/title_activity_earthquake_maps"/>
<activity android:name=".MainActivity"> <activity android:name=".MainActivity">
<intent-filter> <intent-filter>
<action android:name="android.intent.action.MAIN" /> <action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" /> <category android:name="android.intent.category.LAUNCHER" />
</intent-filter> </intent-filter>
</activity> </activity>
</application> </application>
</manifest> </manifest>
<!--android:parentActivityName=".MainActivity"--> <!--android:parentActivityName=".MainActivity"-->
@@ -0,0 +1,664 @@
package de.edotzlaff.schockwelle;
import android.net.wifi.WifiManager;
import android.os.Build;
import android.util.Log;
import android.widget.Toast;
import androidx.annotation.NonNull;
import com.google.android.gms.tasks.OnCompleteListener;
import com.google.android.gms.tasks.Task;
import com.google.firebase.database.DataSnapshot;
import com.google.firebase.database.DatabaseError;
import com.google.firebase.database.DatabaseReference;
import com.google.firebase.database.FirebaseDatabase;
import com.google.firebase.database.ValueEventListener;
import java.time.LocalDateTime;
import java.time.ZoneOffset;
import java.util.Calendar;
public class Datenbank {
private String myAndroidID;
private String myIPadress;
private int myWaveSpeed; // Meter pro Sekunde
private double shakeBreitengrad;
private double shakeLaengengrad;
private String a_androidid;
private String b_localdatetime;
private String c_ip;
private double d_breitengrad;
private double e_laengengrad;
private boolean f_nativegps;
private boolean g_vibration;
private long h_timestamp;
private int i_amplitude;
private int w_wellengeschwindigkeit;
private DatabaseReference mDatenbank = FirebaseDatabase.getInstance().getReference().child("overviewnodes");
private String TAG = "Datenbank";
DataSnapshot DatenBankInhalt;
//######### Für andere Klassen: ###########################
//Datenbank db = new Datenbank(); <--Bei Initialisierung
//db.getDatafromDBnoListener(); <--OnCreate
//db.getDataBaseValuesWithListener(); <--OnCreate
public Datenbank(String a_androidid, String b_localdatetime, String c_ip, double d_breitengrad, double e_laengengrad, boolean f_nativegps, boolean g_vibration, long h_timestamp, int i_amplitude, int w_wellengeschwindigkeit) {
this.a_androidid = a_androidid;
this.b_localdatetime = b_localdatetime;
this.c_ip = c_ip;
this.d_breitengrad = d_breitengrad;
this.e_laengengrad = e_laengengrad;
this.f_nativegps = f_nativegps;
this.g_vibration = g_vibration;
this.h_timestamp = h_timestamp;
this.i_amplitude = i_amplitude;
this.w_wellengeschwindigkeit = w_wellengeschwindigkeit;
}
public Datenbank ()
{
}
//DatenBankInhalt wird einmalig Aktualisiert
public void getDatafromDBnoListener()
{
mDatenbank.get().addOnCompleteListener(new OnCompleteListener<DataSnapshot>() {
@Override
public void onComplete(@NonNull Task<DataSnapshot> task) {
if (!task.isSuccessful()) {
Log.d(TAG,"Fehler in getDatafromDBnoListener" + task.getException());
}
else {
setDatenBankInhalt(task.getResult());
initializeDataBase_ShockApplication_Main();
}
}
});
}
//DatenBankInhalt wird bei Veränderung Aktualisiert
public void getDataBaseValuesWithListener()
{
mDatenbank.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot snapshot) {
setDatenBankInhalt(snapshot);
//Geänderte DB schicken an SensorMapActivity
SensorMapsActivity sensor = new SensorMapsActivity();
}
@Override
public void onCancelled(@NonNull DatabaseError error) {
getDataBaseFailure(error);
}
});
}
public void getDataBaseFailure (DatabaseError error)
{
Log.w("Datenbankfehler", error.toException());
}
public void initializeDataBase_ShockApplication_Main()
{
if(getDatenBankInhalt().exists())
{
//Wenn DB schon exisitiert
if(getIfPureIDGareEmpty())
{
//Wenn IDG nocht KOMPLETT leer sind und keine weiteren Children haben
setEmptyDataInDBcompletly();
Log.d(TAG,"Datenbankzweig wurde für Anwendung angepasst. Weitermachen.");
}
}else
{
//Wenn DB nicht exisitert
setEmptyIDGinDBcomplety();
Log.d(TAG,"Datenbankzweig nicht existent. Dieser wurde angelgt. Neustart der App nötig");
}
}
public void setCommand()
{
setAndroidIDInDB(2,"hello");
setBreitengrad(2,15);
}
public String getCommand()
{
getAndroidIDInDB(2);
getBreitengrad(2);
return getAndroidIDInDB(2) + getBreitengrad(2);
}
//########################################################################### Set / Get von IDGs
public void setEmptyDataInIDG(int i) //Setzt leere Strings children von IDGi
{
mDatenbank.child("IDG" + i).child("a_androidid").setValue("");
mDatenbank.child("IDG" + i).child("b_localdatetime").setValue("");
mDatenbank.child("IDG" + i).child("c_ip").setValue("");
mDatenbank.child("IDG" + i).child("d_breitengrad").setValue("");
mDatenbank.child("IDG" + i).child("e_laengengrad").setValue("");
mDatenbank.child("IDG" + i).child("f_nativegps").setValue("");
mDatenbank.child("IDG" + i).child("g_vibration").setValue("");
mDatenbank.child("IDG" + i).child("h_timestamp").setValue("");
mDatenbank.child("IDG" + i).child("i_amplitude").setValue("");
mDatenbank.child("IDG" + i).child("w_wellengeschwindigkeit").setValue("");
}
public boolean getStatusEmptyAboutIDG(int i) //Gibt true wenn IDG i leer ist
{
String androidid = getDatenBankInhalt().child("IDG" + i).child("a_androidid").getValue().toString();
String localdatetime = getDatenBankInhalt().child("IDG" + i).child("b_localdatetime").getValue().toString();
String ip = getDatenBankInhalt().child("IDG" + i).child("c_ip").getValue().toString();
String breitengrad = getDatenBankInhalt().child("IDG" + i).child("d_breitengrad").getValue().toString();
String laengengrad = getDatenBankInhalt().child("IDG" + i).child("e_laengengrad").getValue().toString();
String nativegps = getDatenBankInhalt().child("IDG" + i).child("f_nativegps").getValue().toString();
String vibration = getDatenBankInhalt().child("IDG" + i).child("g_vibration").getValue().toString();
String timestamp = getDatenBankInhalt().child("IDG" + i).child("h_timestamp").getValue().toString();
String amplitude = getDatenBankInhalt().child("IDG" + i).child("i_amplitude").getValue().toString();
String wellengeschwindigkeit = getDatenBankInhalt().child("IDG" + i).child("w_wellengeschwindigkeit").getValue().toString();
if(androidid.isEmpty() && localdatetime.isEmpty() && ip.isEmpty() && breitengrad.isEmpty() && laengengrad.isEmpty() && nativegps.isEmpty() && vibration.isEmpty() && timestamp.isEmpty() && amplitude.isEmpty() && wellengeschwindigkeit.isEmpty())
{
return true;
}else
{
return false;
}
}
public boolean getStatusEmptyAboutIDGexceptNativeGPSandVibration(int i) //Gibt true wenn IDG i, bis auf nativegps und vibration, leer ist
{
String androidid = getDatenBankInhalt().child("IDG" + i).child("a_androidid").getValue().toString();
String localdatetime = getDatenBankInhalt().child("IDG" + i).child("b_localdatetime").getValue().toString();
String ip = getDatenBankInhalt().child("IDG" + i).child("c_ip").getValue().toString();
String breitengrad = getDatenBankInhalt().child("IDG" + i).child("d_breitengrad").getValue().toString();
String laengengrad = getDatenBankInhalt().child("IDG" + i).child("e_laengengrad").getValue().toString();
String timestamp = getDatenBankInhalt().child("IDG" + i).child("h_timestamp").getValue().toString();
String amplitude = getDatenBankInhalt().child("IDG" + i).child("i_amplitude").getValue().toString();
String wellengeschwindigkeit = getDatenBankInhalt().child("IDG" + i).child("w_wellengeschwindigkeit").getValue().toString();
if(androidid.isEmpty() && localdatetime.isEmpty() && ip.isEmpty() && breitengrad.isEmpty() && laengengrad.isEmpty() && timestamp.isEmpty() && amplitude.isEmpty() && wellengeschwindigkeit.isEmpty())
{
return true;
}else
{
return false;
}
}
public boolean getStatusFullAboutIDG(int i) //Gibt true wenn IDG i voll ist
{
String androidid = getDatenBankInhalt().child("IDG" + i).child("a_androidid").getValue().toString();
String localdatetime = getDatenBankInhalt().child("IDG" + i).child("b_localdatetime").getValue().toString();
String ip = getDatenBankInhalt().child("IDG" + i).child("c_ip").getValue().toString();
String breitengrad = getDatenBankInhalt().child("IDG" + i).child("d_breitengrad").getValue().toString();
String laengengrad = getDatenBankInhalt().child("IDG" + i).child("e_laengengrad").getValue().toString();
String nativegps = getDatenBankInhalt().child("IDG" + i).child("f_nativegps").getValue().toString();
String vibration = getDatenBankInhalt().child("IDG" + i).child("g_vibration").getValue().toString();
String timestamp = getDatenBankInhalt().child("IDG" + i).child("h_timestamp").getValue().toString();
String amplitude = getDatenBankInhalt().child("IDG" + i).child("i_amplitude").getValue().toString();
String wellengeschwindigkeit = getDatenBankInhalt().child("IDG" + i).child("w_wellengeschwindigkeit").getValue().toString();
if(!androidid.isEmpty() && !localdatetime.isEmpty() && !ip.isEmpty() && !breitengrad.isEmpty() && !laengengrad.isEmpty() && !nativegps.isEmpty() && !vibration.isEmpty() && !timestamp.isEmpty() && !amplitude.isEmpty() && !wellengeschwindigkeit.isEmpty())
{
return true;
}else
{
return false;
}
}
//########################################################################### Set / Get von kompletter DB
public void setEmptyDataInDBcompletly() //Setzt leere Strings in alle children von allen IDGs
{
for (int i = 1; i<=getDatenBankInhalt().getChildrenCount(); i++)
{
mDatenbank.child("IDG" + i).child("a_androidid").setValue("");
mDatenbank.child("IDG" + i).child("b_localdatetime").setValue("");
mDatenbank.child("IDG" + i).child("c_ip").setValue("");
mDatenbank.child("IDG" + i).child("d_breitengrad").setValue("");
mDatenbank.child("IDG" + i).child("e_laengengrad").setValue("");
mDatenbank.child("IDG" + i).child("f_nativegps").setValue("");
mDatenbank.child("IDG" + i).child("g_vibration").setValue("");
mDatenbank.child("IDG" + i).child("h_timestamp").setValue("");
mDatenbank.child("IDG" + i).child("i_amplitude").setValue("");
mDatenbank.child("IDG" + i).child("w_wellengeschwindigkeit").setValue("");
}
}
public void setEmptyDataInDBcompletlyForNativeUse() //Setzt leere Strings in alle children von allen IDGs, wobei nativeGPS = true und vibration = false gesetzt werden
{
for (int i = 1; i<=getDatenBankInhalt().getChildrenCount(); i++)
{
mDatenbank.child("IDG" + i).child("a_androidid").setValue("");
mDatenbank.child("IDG" + i).child("b_localdatetime").setValue("");
mDatenbank.child("IDG" + i).child("c_ip").setValue("");
mDatenbank.child("IDG" + i).child("d_breitengrad").setValue("");
mDatenbank.child("IDG" + i).child("e_laengengrad").setValue("");
mDatenbank.child("IDG" + i).child("f_nativegps").setValue(true);
mDatenbank.child("IDG" + i).child("g_vibration").setValue(false);
mDatenbank.child("IDG" + i).child("h_timestamp").setValue("");
mDatenbank.child("IDG" + i).child("i_amplitude").setValue("");
mDatenbank.child("IDG" + i).child("w_wellengeschwindigkeit").setValue("");
}
}
public boolean getStatusOnEmptyDBcomplety() //Gibt true wenn alle Strings aller IDGs leer sind
{
int emptyIDGs = 0;
for (int i = 1; i<=getDatenBankInhalt().getChildrenCount(); i++)
{
if(getStatusEmptyAboutIDG(i))
{
emptyIDGs++;
}
}
if(emptyIDGs == (int) getDatenBankInhalt().getChildrenCount())
{
return true;
}else{
return false;
}
}
public void setVibrationInDBcompletly(boolean boolValue) //Setzt Vibration true/false in allen children aller IDGs
{
for (int i = 1; i<=getDatenBankInhalt().getChildrenCount(); i++)
{
mDatenbank.child("IDG" + i).child("g_vibration").setValue(boolValue);
}
}
public void setNativeGPSInDBcompletly(boolean boolValue) //Setzt nativeGPS true/false in allen children aller IDGs
{
for (int i = 1; i<=getDatenBankInhalt().getChildrenCount(); i++)
{
mDatenbank.child("IDG" + i).child("f_nativegps").setValue(boolValue);
}
}
public boolean getNativeGPScaseInDB() //Gibt true an, wenn in allen IDGs der wert nativeGPs true oder leer ist
{
int nativeGPS = 0;
for (int i = 1; i<=getAmountOfIDGs(); i++)
{
if(getDatenBankInhalt().child("IDG" + i).child("f_nativegps").getValue().toString().equals("true") || getDatenBankInhalt().child("IDG" + i).child("f_nativegps").getValue().toString().isEmpty())
{
nativeGPS++;
}
}
if(nativeGPS == getDatenBankInhalt().getChildrenCount())
{
return true;
}else
{
return false;
}
}
public boolean getIfPureIDGareEmpty() //Gibt true an, wenn alle IDGs komplett leer sind
{
int pureEmptyIDG = 0;
for (int i = 1; i<=getDatenBankInhalt().getChildrenCount(); i++)
{
if(getDatenBankInhalt().child("IDG" + i).getValue().toString().isEmpty())
{
pureEmptyIDG++;
}
}
if(pureEmptyIDG == getDatenBankInhalt().getChildrenCount())
{
return true;
}
else
{
return false;
}
}
public void setNonNativeCaseInDB() //Setzt Musterwerte ein
{
Devices d1 = new Devices("","","",49.58967957913626,11.011387124069765,false,false,0,1000,10); //Erlangen 49.58967957913626, 11.011387124069765
Devices d2 = new Devices("","","",48.7560280895443,11.425157702952347,false,false,0,1000,10); //Ingolstadt 48.7560280895443, 11.425157702952347
Devices d3 = new Devices("","","",48.16958655466396,11.617418429524394,false,false,0,1000,10); //München 48.16958655466396, 11.617418429524394
Devices d4 = new Devices("","","",45.55620112204013,12.342516140205387,false,false,0,1000,10); //Venedig 45.55620112204013, 12.342516140205387
Devices d5 = new Devices("","","",41.9204784730154,12.651055829215638,false,false,0,1000,10); //Rom 41.9204784730154, 12.651055829215638
mDatenbank.child("IDG1").setValue(d1);
mDatenbank.child("IDG2").setValue(d2);
mDatenbank.child("IDG3").setValue(d3);
mDatenbank.child("IDG4").setValue(d4);
mDatenbank.child("IDG5").setValue(d4);
mDatenbank.child("IDG5").setValue(d5);
}
public void setEmptyIDGinDBcomplety() //Setzt leer IDGs in einen Dantenbankzweig
{
for (int i = 1; i<=5; i++)
{
mDatenbank.child("IDG" + i).setValue("");
}
}
//########################################################################### Allgemeine Getter und Setter
public long getAmountOfIDGs() //Gibt Anzahl der Children an
{
return getDatenBankInhalt().getChildrenCount();
}
public void setIDGtoDevice(int i, Devices dev) //Gibt Anzahl der Children an
{
mDatenbank.child("IDG" + i).setValue(dev);
}
//Get-Set AndroidID
public void setAndroidIDInDB(int i, String andoridID)
{
mDatenbank.child("IDG" + i).child("a_androidid").setValue(andoridID);
}
public String getAndroidIDInDB(int i)
{
return getDatenBankInhalt().child("IDG" + i).child("a_androidid").getValue().toString();
}
public boolean getAndroidIDisEmpty(int i)
{
if(getDatenBankInhalt().child("IDG" + i).child("a_androidid").getValue().toString().isEmpty())
{
return true;
}else
{
return false;
}
}
public boolean getStatusIFAndroidIDexistsInDB(String androidID)
{
boolean androidIDexists;
for (int i = 1; i<=getAmountOfIDGs(); i++)
{
if(getDatenBankInhalt().child("IDG" + i).child("a_androidid").getValue().toString().equals(getMyAndroidID()))
{
androidIDexists = true;
return androidIDexists;
}else
{
if(i == (int) getAmountOfIDGs())
{
androidIDexists = false;
return androidIDexists;
}
}
}
return false;
}
//Get-Set LocalDatetime
public void setLocalDateTimeInDB(int i, String localdatetime)
{
mDatenbank.child("IDG" + i).child("b_localdatetime").setValue(localdatetime);
}
public String getLocalDateTimeInDB(int i)
{
return getDatenBankInhalt().child("IDG" + i).child("b_localdatetime").getValue().toString();
}
public boolean getLocalDateTimeIsEmpty(int i)
{
if(getDatenBankInhalt().child("IDG" + i).child("b_localdatetime").getValue().toString().isEmpty())
{
return true;
}else
{
return false;
}
}
//Get-Set IP
public void setIPInDB(int i, String ipAdress)
{
mDatenbank.child("IDG" + i).child("c_ip").setValue(ipAdress);
}
public String getIPInDB(int i)
{
return getDatenBankInhalt().child("IDG" + i).child("c_ip").getValue().toString();
}
//Get-Set Breitengrad
public void setBreitengrad(int i, double breitengrad)
{
mDatenbank.child("IDG" + i).child("d_breitengrad").setValue(breitengrad);
}
public String getBreitengrad(int i)
{
return getDatenBankInhalt().child("IDG" + i).child("d_breitengrad").getValue().toString();
}
public boolean getBreitengradIsEmpty(int i)
{
if(getDatenBankInhalt().child("IDG" + i).child("d_breitengrad").getValue().toString().isEmpty())
{
return true;
}else
{
return false;
}
}
//Get-Set Laengengrad
public void setLaengengrad(int i, double laengengrad)
{
mDatenbank.child("IDG" + i).child("e_laengengrad").setValue(laengengrad);
}
public String getLaengengrad(int i)
{
return getDatenBankInhalt().child("IDG" + i).child("e_laengengrad").getValue().toString();
}
public boolean getLaengengradIsEmpty(int i)
{
if(getDatenBankInhalt().child("IDG" + i).child("e_laengengrad").getValue().toString().isEmpty())
{
return true;
}else
{
return false;
}
}
//Set GPS
public void setBreitengradUndLaengengrad(int i, double breitengrad, double laengengrad)
{
mDatenbank.child("IDG" + i).child("d_breitengrad").setValue(breitengrad);
mDatenbank.child("IDG" + i).child("e_laengengrad").setValue(laengengrad);
}
//Get-Set NativeGPS
public void setNativeGPS(int i, boolean nativegps)
{
mDatenbank.child("IDG" + i).child("f_nativegps").setValue(nativegps);
}
public String getNativeGPS(int i)
{
return getDatenBankInhalt().child("IDG" + i).child("f_nativegps").getValue().toString();
}
//Get-Set Vibration
public void setVibration(int i, boolean vibration)
{
mDatenbank.child("IDG" + i).child("g_vibration").setValue(vibration);
}
public String getVibration(int i)
{
return getDatenBankInhalt().child("IDG" + i).child("g_vibration").getValue().toString();
}
//Get-Set timestamp
public void setTimestamp(int i, long timestamp)
{
mDatenbank.child("IDG" + i).child("h_timestamp").setValue(timestamp);
}
public String getTimestamp(int i)
{
return getDatenBankInhalt().child("IDG" + i).child("h_timestamp").getValue().toString();
}
public boolean getTimestampIsEmpty(int i)
{
if(getDatenBankInhalt().child("IDG" + i).child("h_timestamp").getValue().toString().isEmpty())
{
return true;
}else
{
return false;
}
}
//Get-Set Amplitude
public void setAmplitude(int i, int amplitude)
{
mDatenbank.child("IDG" + i).child("i_amplitude").setValue(amplitude);
}
public String getAmplitude(int i)
{
return getDatenBankInhalt().child("IDG" + i).child("i_amplitude").getValue().toString();
}
//Get-Set Wellengeschwindigkeit
public void setWellengeschwindigkeit(int i, int wellengeschwindigkeit)
{
mDatenbank.child("IDG" + i).child("w_wellengeschwindigkeit").setValue(wellengeschwindigkeit);
}
public String getWellengeschwindigkeit(int i)
{
return getDatenBankInhalt().child("IDG" + i).child("w_wellengeschwindigkeit").getValue().toString();
}
//########################################################################### Sontiges
//########################################################################### Contruktor Getter und Setter
public String getA_androidid() {
return a_androidid;
}
public void setA_androidid(String a_androidid) {
this.a_androidid = a_androidid;
}
public String getB_localdatetime() {
return b_localdatetime;
}
public void setB_localdatetime(String b_localdatetime) {
this.b_localdatetime = b_localdatetime;
}
public String getC_ip() {
return c_ip;
}
public void setC_ip(String c_ip) {
this.c_ip = c_ip;
}
public double getD_breitengrad() {
return d_breitengrad;
}
public void setD_breitengrad(double d_breitengrad) {
this.d_breitengrad = d_breitengrad;
}
public double getE_laengengrad() {
return e_laengengrad;
}
public void setE_laengengrad(double e_laengengrad) {
this.e_laengengrad = e_laengengrad;
}
public boolean isF_nativegps() {
return f_nativegps;
}
public void setF_nativegps(boolean f_nativegps) {
this.f_nativegps = f_nativegps;
}
public boolean isG_vibration() {
return g_vibration;
}
public void setG_vibration(boolean g_vibration) {
this.g_vibration = g_vibration;
}
public long getH_timestamp() {
return h_timestamp;
}
public void setH_timestamp(long h_timestamp) {
this.h_timestamp = h_timestamp;
}
public int getI_amplitude() {
return i_amplitude;
}
public void setI_amplitude(int i_amplitude) {
this.i_amplitude = i_amplitude;
}
public int getW_wellengeschwindigkeit() {
return w_wellengeschwindigkeit;
}
public void setW_wellengeschwindigkeit(int w_wellengeschwindigkeit) {
this.w_wellengeschwindigkeit = w_wellengeschwindigkeit;
}
public DataSnapshot getDatenBankInhalt() {
return DatenBankInhalt;
}
public void setDatenBankInhalt(DataSnapshot datenBankInhalt) {
DatenBankInhalt = datenBankInhalt;
}
public String getMyAndroidID() {
return myAndroidID;
}
public void setMyAndroidID(String myAndroidID) {
this.myAndroidID = myAndroidID;
}
public int getMyWaveSpeed() {
return myWaveSpeed;
}
public void setMyWaveSpeed(int myWaveSpeed) {
this.myWaveSpeed = myWaveSpeed;
}
public String getMyIPadress() {
return myIPadress;
}
public void setMyIPadress(String myIPadress) {
this.myIPadress = myIPadress;
}
public double getShakeBreitengrad() {
return shakeBreitengrad;
}
public void setShakeBreitengrad(double shakeBreitengrad) {
this.shakeBreitengrad = shakeBreitengrad;
}
public double getShakeLaengengrad() {
return shakeLaengengrad;
}
public void setShakeLaengengrad(double shakeLaengengrad) {
this.shakeLaengengrad = shakeLaengengrad;
}
}
@@ -1,86 +1,114 @@
package de.edotzlaff.schockwelle; package de.edotzlaff.schockwelle;
import java.time.LocalDateTime; import java.time.LocalDateTime;
public class Devices { public class Devices {
private String ip; private String a_androidid;
private boolean vibration; private String b_localdatetime;
private long timestamp; private String c_ip;
private double breitengrad; private double d_breitengrad;
private double laengengrad; private double e_laengengrad;
private int amplitude; private boolean f_nativegps;
private String localdatetime; private boolean g_vibration;
private boolean idvergeben; private long h_timestamp;
private String androidid; private int i_amplitude;
private int w_wellengeschwindigkeit;
public Devices() {
} public Devices() {
public Devices(String ip, boolean vibration, long timestamp, double breitengrad, double laengengrad, int amplitude, String localdatetime, String androidid) { }
this.ip = ip;
this.vibration = vibration; 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.timestamp = timestamp; this.a_androidid = a_androidid;
this.breitengrad = breitengrad; this.b_localdatetime = b_localdatetime;
this.laengengrad = laengengrad; this.c_ip = c_ip;
this.amplitude = amplitude; this.d_breitengrad = d_breitengrad;
this.localdatetime = localdatetime; this.e_laengengrad = e_laengengrad;
this.androidid = androidid; this.f_nativegps = f_nativegps;
} this.g_vibration = g_vibration;
this.h_timestamp = h_timestamp;
public String getIp() { this.i_amplitude = i_amplitude;
return ip; this.w_wellengeschwindigkeit = w_wellengeschwindigkeit;
} }
public void setIp(String ip) {
this.ip = ip; public String getA_androidid() {
} return a_androidid;
}
public boolean isVibration() {
return vibration; public void setA_androidid(String a_androidid) {
} this.a_androidid = a_androidid;
public void setVibration(boolean vibration) { }
this.vibration = vibration;
} public String getB_localdatetime() {
return b_localdatetime;
public long getTimestamp() { }
return timestamp;
} public void setB_localdatetime(String b_localdatetime) {
public void setTimestamp(long timestamp) { this.b_localdatetime = b_localdatetime;
this.timestamp = timestamp; }
}
public String getC_ip() {
public double getBreitengrad() { return c_ip;
return breitengrad; }
}
public void setBreitengrad(double breitengrad) { public void setC_ip(String c_ip) {
this.breitengrad = breitengrad; this.c_ip = c_ip;
} }
public double getLaengengrad() { public double getD_breitengrad() {
return laengengrad; return d_breitengrad;
} }
public void setLaengengrad(double laengengrad) {
this.laengengrad = laengengrad; public void setD_breitengrad(double d_breitengrad) {
} this.d_breitengrad = d_breitengrad;
}
public int getAmplitude() {
return amplitude; public double getE_laengengrad() {
} return e_laengengrad;
public void setAmplitude(int amplitude) { }
this.amplitude = amplitude;
} public void setE_laengengrad(double e_laengengrad) {
this.e_laengengrad = e_laengengrad;
public String getLocaldatetime() { }
return localdatetime;
} public boolean isF_nativegps() {
public void setLocaldatetime(String localdatetime) { return f_nativegps;
this.localdatetime = localdatetime; }
}
public void setF_nativegps(boolean f_nativegps) {
public String getAndroidid() { this.f_nativegps = f_nativegps;
return androidid; }
}
public void setAndroidid(String androidid) { public boolean isG_vibration() {
this.androidid = androidid; 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;
}
}
@@ -1,418 +1,355 @@
package de.edotzlaff.schockwelle; package de.edotzlaff.schockwelle;
import android.Manifest; import android.Manifest;
import android.app.ActionBar; import android.app.ActionBar;
import android.content.Context; import android.content.Context;
import android.content.pm.PackageManager; import android.content.pm.PackageManager;
import android.hardware.Sensor; import android.hardware.Sensor;
import android.hardware.SensorEvent; import android.hardware.SensorEvent;
import android.hardware.SensorEventListener; import android.hardware.SensorEventListener;
import android.hardware.SensorManager; import android.hardware.SensorManager;
import android.location.Location; import android.location.Location;
import android.net.wifi.WifiManager; 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;
import android.os.SystemClock; import android.os.SystemClock;
import android.provider.ContactsContract; import android.provider.ContactsContract;
import android.provider.Settings; import android.provider.Settings;
import android.util.Log; import android.util.Log;
import android.widget.TextView; import android.widget.TextView;
import android.widget.Toast; import android.widget.Toast;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.core.app.ActivityCompat; import androidx.annotation.RequiresApi;
import androidx.core.content.ContextCompat; import androidx.core.app.ActivityCompat;
import androidx.fragment.app.FragmentActivity; import androidx.core.content.ContextCompat;
import androidx.fragment.app.FragmentActivity;
import com.google.android.gms.location.FusedLocationProviderClient;
import com.google.android.gms.location.LocationServices; import com.google.android.gms.location.FusedLocationProviderClient;
import com.google.android.gms.maps.CameraUpdateFactory; import com.google.android.gms.location.LocationServices;
import com.google.android.gms.maps.GoogleMap; import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.OnMapReadyCallback; import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.SupportMapFragment; import com.google.android.gms.maps.OnMapReadyCallback;
import com.google.android.gms.maps.model.LatLng; import com.google.android.gms.maps.SupportMapFragment;
import com.google.android.gms.maps.model.MarkerOptions; import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.tasks.OnCompleteListener; import com.google.android.gms.maps.model.MarkerOptions;
import com.google.android.gms.tasks.Task; import com.google.android.gms.tasks.OnCompleteListener;
import com.google.firebase.database.DataSnapshot; import com.google.android.gms.tasks.Task;
import com.google.firebase.database.DatabaseError; import com.google.firebase.database.DataSnapshot;
import com.google.firebase.database.DatabaseReference; import com.google.firebase.database.DatabaseError;
import com.google.firebase.database.FirebaseDatabase; import com.google.firebase.database.DatabaseReference;
import com.google.firebase.database.ValueEventListener; import com.google.firebase.database.FirebaseDatabase;
import com.google.firebase.database.ValueEventListener;
import java.time.LocalDateTime;
import java.util.Calendar; import java.time.LocalDateTime;
import java.util.Date; import java.time.ZoneOffset;
import java.util.Objects; import java.util.Calendar;
import java.util.Date;
public class EarthquakeMapsActivity extends FragmentActivity implements OnMapReadyCallback { import java.util.Objects;
private static final String TAG = "MainActivity"; public class EarthquakeMapsActivity extends FragmentActivity implements OnMapReadyCallback {
private static final String FINE_LOCATION = Manifest.permission.ACCESS_FINE_LOCATION;
private static final int LOCATION_PERMISSION_REQUEST_CODE = 1234; private static final String TAG = "MainActivity";
private Boolean mLocationPermissionsGranted = false; private static final String FINE_LOCATION = Manifest.permission.ACCESS_FINE_LOCATION;
private GoogleMap mMap; private static final int LOCATION_PERMISSION_REQUEST_CODE = 1234;
private FusedLocationProviderClient mFusedLocationProviderClient; private Boolean mLocationPermissionsGranted = false;
private GoogleMap mMap;
Long currentTime; private FusedLocationProviderClient mFusedLocationProviderClient;
Location currentLocation; Datenbank db = new Datenbank();
private DatabaseReference mDatenbank;
private double breitengrad; Long currentTime;
private double laengengrad; Location currentLocation;
private boolean useOwnGPS; private DatabaseReference mDatenbank;
private int indexID = 1; private double breitengrad;
private double laengengrad;
//########################################################################################################################################################################## private boolean useOwnGPS;
//################################################################## vvv ShakeParameter vvv ############################################################################## private int indexID = 1;
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 long mShakeDetectionLockTimeMicroSeconds = 10000; //################################################################## vvv ShakeParameter vvv ##############################################################################
private float mAccel; private SensorManager mSensorManager;
private float mAccelCurrent; private static final float mUpperThreshold = 10.5f; // für Emulator auf 1.5 setzen TODO Aron
private float mAccelLast; private static final float mLowerThreshold = 5.5f; // für Emulator auf 0.5 setzen TODO Aron
private boolean mShakeDetectionIsActive = false; //private static final float mUpperThreshold = 10.5f; // für Emulator auf 1.5 setzen TODO Aron
private boolean mShakeDetected = false; //private static final float mLowerThreshold = 5.5f; // für Emulator auf 0.5 setzen TODO Aron
//private boolean allowShakeEvent = true; private static final long mShakeDetectionLockTimeMicroSeconds = 10000;
//################################################################## ^^^^ ShakeParameter ^^^^ ############################################################################ private float mAccel;
//########################################################################################################################################################################## private float mAccelCurrent;
private float mAccelLast;
private boolean mShakeDetectionIsActive = false;
@Override private boolean mShakeDetected = false;
protected void onCreate(Bundle savedInstanceState) { private boolean allowShakeEvent = true;
super.onCreate(savedInstanceState); //################################################################## ^^^^ ShakeParameter ^^^^ ############################################################################
setContentView(R.layout.activity_earthquake_maps); //##########################################################################################################################################################################
getDataBaseValuesNoListener();
sensorManagementInit(); @Override
getLocationPermission(); protected void onCreate(Bundle savedInstanceState) {
} super.onCreate(savedInstanceState);
setContentView(R.layout.activity_earthquake_maps);
//#####################################################################################################################################################################
//################################################################## vvv ShakeCode vvv ############################################################################## //Database Init
private void sensorManagementInit() db.setMyWaveSpeed(500);
{ db.setMyAndroidID(Settings.Secure.getString(this.getContentResolver(), Settings.Secure.ANDROID_ID));
TextView txtEarthquake = (TextView) findViewById(R.id.txtEarthquake); WifiManager wm = (WifiManager) getApplicationContext().getSystemService(WIFI_SERVICE);
mSensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE); int ip = wm.getConnectionInfo().getIpAddress();
Objects.requireNonNull(mSensorManager).registerListener(mSensorListener, mSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER), SensorManager.SENSOR_DELAY_NORMAL); db.setMyIPadress(String.format("%d.%d.%d.%d",(ip & 0xff),(ip >> 8 & 0xff),(ip >> 16 & 0xff), (ip >> 24 & 0xff)));
mAccel = 1f; db.getDatafromDBnoListener();
mAccelCurrent = SensorManager.GRAVITY_EARTH; db.getDataBaseValuesWithListener();
mAccelLast = SensorManager.GRAVITY_EARTH;
mShakeDetectionIsActive = true; sensorManagementInit();
mShakeDetected = false; getLocationPermission();
} }
private CountDownTimer mLockTimer = new CountDownTimer(mShakeDetectionLockTimeMicroSeconds, 1000) //#####################################################################################################################################################################
{ //################################################################## vvv ShakeCode vvv ##############################################################################
public void onTick(long millisUntilFinished) { private void sensorManagementInit()
((TextView) findViewById(R.id.txtEarthquake)).setText("Earthquake started! Detection locked for " + millisUntilFinished / 1000 + " s"); {
} TextView txtEarthquake = (TextView) findViewById(R.id.txtEarthquake);
mSensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE);
public void onFinish() { Objects.requireNonNull(mSensorManager).registerListener(mSensorListener, mSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER), SensorManager.SENSOR_DELAY_NORMAL);
mShakeDetectionIsActive = true; mAccel = 1f;
mShakeDetected = false; mAccelCurrent = SensorManager.GRAVITY_EARTH;
Toast.makeText(getApplicationContext(), "Shake Detection unlocked", Toast.LENGTH_SHORT).show(); mAccelLast = SensorManager.GRAVITY_EARTH;
( (TextView) findViewById(R.id.txtEarthquake)).setText("Shake your Smartphone for an Earthquake"); mShakeDetectionIsActive = true;
} mShakeDetected = false;
}; }
private CountDownTimer mLockTimer = new CountDownTimer(mShakeDetectionLockTimeMicroSeconds, 1000)
private final SensorEventListener mSensorListener = new SensorEventListener() { {
@Override public void onTick(long millisUntilFinished) {
public void onSensorChanged(SensorEvent event) { ((TextView) findViewById(R.id.txtEarthquake)).setText("Earthquake started! Detection locked for " + millisUntilFinished / 1000 + " s");
float x = event.values[0]; }
float y = event.values[1];
float z = event.values[2]; public void onFinish() {
mAccelLast = mAccelCurrent; mShakeDetectionIsActive = true;
mAccelCurrent = (float) Math.sqrt((double) (x * x + y * y + z * z)); mShakeDetected = false;
float delta = mAccelCurrent - mAccelLast; Toast.makeText(getApplicationContext(), "Shake Detection unlocked", Toast.LENGTH_SHORT).show();
mAccel = mAccel * 0.9f + delta; ( (TextView) findViewById(R.id.txtEarthquake)).setText("Shake your Smartphone for an Earthquake");
// Log.d(TAG,"mAccel: "+ mAccel); }
if (mShakeDetectionIsActive) { };
if(Math.abs(mAccel) > mUpperThreshold) {
new CountDownTimer(50, 10) {
private final SensorEventListener mSensorListener = new SensorEventListener() {
public void onTick(long millisUntilFinished) { @Override
if (Math.abs(mAccel) > mUpperThreshold) { public void onSensorChanged(SensorEvent event) {
mShakeDetectionIsActive = false; float x = event.values[0];
} else if (Math.abs(mAccel) < mLowerThreshold) { float y = event.values[1];
mShakeDetectionIsActive = true; float z = event.values[2];
this.cancel(); mAccelLast = mAccelCurrent;
} mAccelCurrent = (float) Math.sqrt((double) (x * x + y * y + z * z));
} float delta = mAccelCurrent - mAccelLast;
mAccel = mAccel * 0.9f + delta;
public void onFinish() { // Log.d(TAG,"mAccel: "+ mAccel);
if (Math.abs(mAccel) > mUpperThreshold) { if (mShakeDetectionIsActive) {
mShakeDetectionIsActive = false; if(Math.abs(mAccel) > mUpperThreshold) {
mShakeDetected = true; new CountDownTimer(50, 10) {
Toast.makeText(getApplicationContext(), "Shake event detected", Toast.LENGTH_SHORT).show();
writeEarthquakeToDatabase(); public void onTick(long millisUntilFinished) {
mLockTimer.start(); if (Math.abs(mAccel) > mUpperThreshold) {
} else { mShakeDetectionIsActive = false;
mShakeDetectionIsActive = true; } else if (Math.abs(mAccel) < mLowerThreshold) {
mShakeDetected = false; mShakeDetectionIsActive = true;
} this.cancel();
} }
}.start(); }
}
} @RequiresApi(api = Build.VERSION_CODES.O)
} public void onFinish() {
@Override if (Math.abs(mAccel) > mUpperThreshold) {
public void onAccuracyChanged(Sensor sensor, int accuracy) { mShakeDetectionIsActive = false;
} mShakeDetected = true;
}; Toast.makeText(getApplicationContext(), "Shake event detected", Toast.LENGTH_SHORT).show();
writeEarthquakeToDatabase(); //TODO Aron
private void writeEarthquakeToDatabase() mLockTimer.start();
{ } else {
setDataBaseValues(); mShakeDetectionIsActive = true;
} mShakeDetected = false;
}
@Override }
protected void onResume() { }.start();
mSensorManager.registerListener(mSensorListener, mSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER), }
SensorManager.SENSOR_DELAY_NORMAL); }
super.onResume(); }
} @Override
@Override public void onAccuracyChanged(Sensor sensor, int accuracy) {
protected void onPause() { }
mSensorManager.unregisterListener(mSensorListener); };
super.onPause();
}
//################################################################## ^^^^ ShakeCode ^^^^ ############################################################################ @Override
//##################################################################################################################################################################### protected void onResume() {
mSensorManager.registerListener(mSensorListener, mSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER), SensorManager.SENSOR_DELAY_NORMAL);
//##################################################################################################################################################################### super.onResume();
//################################################################## vvv GPS Code vvv ############################################################################### }
@Override
private void getLocationPermission() { protected void onPause() {
String[] permissions = {Manifest.permission.ACCESS_FINE_LOCATION}; mSensorManager.unregisterListener(mSensorListener);
if (ContextCompat.checkSelfPermission(this.getApplicationContext(), FINE_LOCATION) == PackageManager.PERMISSION_GRANTED) { super.onPause();
mLocationPermissionsGranted = true; }
initMap(); //################################################################## ^^^^ ShakeCode ^^^^ ############################################################################
} else { //#####################################################################################################################################################################
ActivityCompat.requestPermissions(this, permissions, LOCATION_PERMISSION_REQUEST_CODE);
} //#####################################################################################################################################################################
} //################################################################## vvv GPS Code vvv ###############################################################################
@Override private void getLocationPermission() {
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) { String[] permissions = {Manifest.permission.ACCESS_FINE_LOCATION};
super.onRequestPermissionsResult(requestCode, permissions, grantResults); if (ContextCompat.checkSelfPermission(this.getApplicationContext(), FINE_LOCATION) == PackageManager.PERMISSION_GRANTED) {
mLocationPermissionsGranted = false; mLocationPermissionsGranted = true;
initMap();
switch (requestCode) { } else {
case LOCATION_PERMISSION_REQUEST_CODE: { ActivityCompat.requestPermissions(this, permissions, LOCATION_PERMISSION_REQUEST_CODE);
if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) { }
mLocationPermissionsGranted = true; }
initMap(); //initalize or map
} @Override
} public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
} super.onRequestPermissionsResult(requestCode, permissions, grantResults);
} mLocationPermissionsGranted = false;
switch (requestCode) {
private void initMap() { case LOCATION_PERMISSION_REQUEST_CODE: {
SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map); if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
mapFragment.getMapAsync(this); mLocationPermissionsGranted = true;
} initMap(); //initalize or map
}
@Override }
public void onMapReady(GoogleMap googleMap) { }
Toast.makeText(this, "Map is ready", Toast.LENGTH_SHORT).show(); }
mMap = googleMap;
private void initMap() {
if (mLocationPermissionsGranted) { SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map);
getDeviceLocation(); mapFragment.getMapAsync(this);
}
if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION)
!= PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, @Override
Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) { public void onMapReady(GoogleMap googleMap) {
return; Toast.makeText(this, "Map is ready", Toast.LENGTH_SHORT).show();
} mMap = googleMap;
mMap.setMyLocationEnabled(true);
} if (mLocationPermissionsGranted) {
getDeviceLocation();
// Add a marker in Sydney and move the camera
//LatLng sydney = new LatLng(-34, 151); if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION)
//mMap.addMarker(new MarkerOptions().position(sydney).title("Marker in Sydney")); != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this,
//mMap.moveCamera(CameraUpdateFactory.newLatLng(sydney)); Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
} return;
}
private void getDeviceLocation(){ mMap.setMyLocationEnabled(true);
mFusedLocationProviderClient = LocationServices.getFusedLocationProviderClient(this); }
try {
if (mLocationPermissionsGranted){ //TODO @ Eddy: Ich denke diesen Code brauchst du auch, oder? :D
final Task location = mFusedLocationProviderClient.getLastLocation(); //Add a marker in Sydney and move the camera
//LatLng sydney = new LatLng(-34, 151);
location.addOnCompleteListener(new OnCompleteListener() { //mMap.addMarker(new MarkerOptions().position(sydney).title("Marker in Sydney"));
//mMap.moveCamera(CameraUpdateFactory.newLatLng(sydney));
@Override }
public void onComplete(@NonNull Task task) {
if (task.isSuccessful()){ private void getDeviceLocation(){
currentLocation = (Location) task.getResult(); mFusedLocationProviderClient = LocationServices.getFusedLocationProviderClient(this);
//currentTime = Calendar.getInstance().getTimeInMillis(); //verschoben in setDataBaseValues try {
//Toast.makeText(EarthquakeMapsActivity.this, currentTime.toString(), Toast.LENGTH_SHORT).show(); //verschoben in setDataBaseValues if (mLocationPermissionsGranted){
if(useOwnGPS) final Task location = mFusedLocationProviderClient.getLastLocation();
{
breitengrad = currentLocation.getLatitude(); location.addOnCompleteListener(new OnCompleteListener() {
laengengrad = currentLocation.getLongitude();
} @Override
currentLocation.setLatitude(breitengrad); public void onComplete(@NonNull Task task) {
currentLocation.setLongitude(laengengrad); if (task.isSuccessful()){
moveCamera(new LatLng(currentLocation.getLatitude(), currentLocation.getLongitude()),15f); currentLocation = (Location) task.getResult();
//setDataBaseValues(); //Wurde verschoben zu Methode writeEarthquakeToDatabase System.out.println(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>" + db.getNativeGPScaseInDB());
}
else{ if(db.getNativeGPScaseInDB())
Toast.makeText(EarthquakeMapsActivity.this, "Current Location unavailable", Toast.LENGTH_SHORT).show(); {
} System.out.println("---Eigene GPS Daten werden verwendet");
} breitengrad = currentLocation.getLatitude();
}); laengengrad = currentLocation.getLongitude();
} db.setShakeBreitengrad(breitengrad);
}catch (SecurityException e){ db.setShakeLaengengrad(laengengrad);
Log.e(TAG,"Device Location not found" + e.getMessage()); }
}
} /*
if(useOwnGPS) //TODO Aron
private void moveCamera(LatLng latlng, float zoom){ {
Log.d(TAG,"Latitude: "+latlng.latitude+"Longitude: "+latlng.longitude); breitengrad = currentLocation.getLatitude();
mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(latlng, zoom)); laengengrad = currentLocation.getLongitude();
} }
//################################################################## ^^^^ GPS Code ^^^^ ############################################################################# */
//##################################################################################################################################################################### currentLocation.setLatitude(breitengrad);
currentLocation.setLongitude(laengengrad);
//##################################################################################################################################################################### moveCamera(new LatLng(currentLocation.getLatitude(), currentLocation.getLongitude()),15f);
//################################################################## vvv Datenbank Code vvv ######################################################################### }
else{
public void getDataBaseValuesNoListener() Toast.makeText(EarthquakeMapsActivity.this, "Current Location unavailable", Toast.LENGTH_SHORT).show();
{ }
mDatenbank = FirebaseDatabase.getInstance().getReference(); }
mDatenbank.child("overviewAronTestetInDiesemAbschnitt").get().addOnCompleteListener(new OnCompleteListener<DataSnapshot>() { });
@Override }
public void onComplete(@NonNull Task<DataSnapshot> task) { }catch (SecurityException e){
if (!task.isSuccessful()) { Log.e(TAG,"Device Location not found" + e.getMessage());
System.out.println("Datenbankfehler in getDataBaseValuesNoListener"); }
System.out.println("Error getting data: " + task.getException()); }
}
else { private void moveCamera(LatLng latlng, float zoom){
processDataBaseValues(task.getResult()); Log.d(TAG,"Latitude: "+latlng.latitude+"Longitude: "+latlng.longitude);
} mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(latlng, zoom));
} }
});
} //################################################################## ^^^^ GPS Code ^^^^ #############################################################################
//#####################################################################################################################################################################
public void processDataBaseValues (DataSnapshot data)
{ //#####################################################################################################################################################################
processDeviceIndex(data); //################################################################## vvv Datenbank Code vvv #########################################################################
processLocation(data); @RequiresApi(api = Build.VERSION_CODES.O)
//processMessageDisplay(data); private void writeEarthquakeToDatabase()
} {
public void processDeviceIndex(DataSnapshot data) boolean nativeGPS;
{ if(db.getNativeGPScaseInDB())
for (int i = 1; i<=4; i++) {
{ nativeGPS = true;
String androidid = data.child("IDG" + i).child("androidid").getValue().toString(); }else{
if(androidid.isEmpty()) nativeGPS = false;
{ }
indexID = i;
break;
}else
{ ///Evtl löschen und localDateTimeMod mit LocalDateTime.now(ZoneOffset.UTC).toString() ersetzen...
continue; String localDateTimeMod;
} if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
} localDateTimeMod = LocalDateTime.now(ZoneOffset.UTC).toString();
} } else
{
public void processLocation(DataSnapshot data) localDateTimeMod = LocalDateTime.now(ZoneOffset.UTC).toString();
{ }
String breitengradString = data.child("IDG" + indexID).child("breitengrad").getValue().toString();
String laengengradString = data.child("IDG" + indexID).child("laengengrad").getValue().toString(); for(int i=1; i<=db.getAmountOfIDGs(); i++)
{
if(breitengradString.isEmpty() || laengengradString.isEmpty()) if(!db.getStatusIFAndroidIDexistsInDB(db.getMyAndroidID()))
{ {
useOwnGPS = true; //Wenn eigenen androidID nicht in DB existiert
}else{ Devices d1 = new Devices();
useOwnGPS = false; d1 = new Devices(db.getMyAndroidID(),
breitengrad = Double.parseDouble(breitengradString); localDateTimeMod,
laengengrad = Double.parseDouble(laengengradString); db.getMyIPadress(),
} breitengrad,
} laengengrad,
nativeGPS,
/* true,
public void processMessageDisplay(DataSnapshot data) Calendar.getInstance().getTimeInMillis(),
{ 1000,
String vibrationString; db.getMyWaveSpeed());
String androidid;
for (int i = 1; i<=4; i++) db.setIDGtoDevice(i,d1);
{ break;
androidid = data.child("overviewAronTestetInDiesemAbschnitt").child("IDG" + i).child("androidid").getValue().toString(); }else{
vibrationString = data.child("overviewAronTestetInDiesemAbschnitt").child("IDG" + i).child("vibration").getValue().toString(); Toast.makeText(getApplicationContext(), "Gerät ist bereits in DB eingetragen!", Toast.LENGTH_SHORT).show();
if((!androidid.isEmpty()) && vibrationString.equals("true")) break;
{ }
allowShakeEvent = false; }
} }
}
} }
*/
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;
}
public void setDataBaseValues()
{
mDatenbank = FirebaseDatabase.getInstance().getReference();
mDatenbank.child("overviewAronTestetInDiesemAbschnitt").child("IDG" + indexID).child("ip").setValue(getDeviceIpAdress());
mDatenbank.child("overviewAronTestetInDiesemAbschnitt").child("IDG" + indexID).child("vibration").setValue(true);
mDatenbank.child("overviewAronTestetInDiesemAbschnitt").child("IDG" + indexID).child("timestamp").setValue(Calendar.getInstance().getTimeInMillis());
currentTime = Calendar.getInstance().getTimeInMillis();
Toast.makeText(EarthquakeMapsActivity.this, currentTime.toString(), Toast.LENGTH_SHORT).show();
mDatenbank.child("overviewAronTestetInDiesemAbschnitt").child("IDG" + indexID).child("breitengrad").setValue(breitengrad);
mDatenbank.child("overviewAronTestetInDiesemAbschnitt").child("IDG" + indexID).child("laengengrad").setValue(laengengrad);
mDatenbank.child("overviewAronTestetInDiesemAbschnitt").child("IDG" + indexID).child("amplitude").setValue(1001);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
mDatenbank.child("overviewAronTestetInDiesemAbschnitt").child("IDG" + indexID).child("localdatetime").setValue(LocalDateTime.now().toString());
}
mDatenbank.child("overviewAronTestetInDiesemAbschnitt").child("IDG" + indexID).child("androidid").setValue(getandroidid());
}
//################################################################## ^^^^ Datenbank Code ^^^^ #############################################################################
//###########################################################################################################################################################################
}
//Evtl. Redundanter Code
/*
public void getDataBaseValues()
{
mDatenbank = FirebaseDatabase.getInstance().getReference();
mDatenbank.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot snapshot) {
processDataBaseValues(snapshot); //Daten Snapshot, Übergabe an processDataBaseValues
}
@Override
public void onCancelled(@NonNull DatabaseError error) {
getDataBaseFailure(error);
}
});
}
public void getDataBaseFailure (DatabaseError error)
{
System.out.println("Datenbankfehler in gerDataBaseFailure");
Log.w("Datenbankfehler", error.toException());
}
*/
@@ -1,263 +1,197 @@
package de.edotzlaff.schockwelle; package de.edotzlaff.schockwelle;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.annotation.RequiresApi; import androidx.fragment.app.FragmentActivity;
import androidx.appcompat.app.AppCompatActivity; import android.app.Dialog;
import androidx.fragment.app.FragmentActivity; import android.content.Intent;
import android.net.wifi.WifiManager;
import android.app.ActionBar; import android.os.Bundle;
import android.app.Dialog; import android.provider.Settings;
import android.content.Intent; import android.util.Log;
import android.hardware.Sensor; import android.view.View;
import android.os.Build; import android.widget.Button;
import android.os.Bundle; import android.widget.Toast;
import android.provider.Settings; import com.google.android.gms.common.ConnectionResult;
import android.util.Log; import com.google.android.gms.common.GoogleApiAvailability;
import android.view.View; import com.google.android.gms.tasks.OnCompleteListener;
import android.widget.Button; import com.google.android.gms.tasks.Task;
import android.widget.Toast; import com.google.firebase.database.DataSnapshot;
import com.google.firebase.database.DatabaseReference;
import com.google.android.gms.common.ConnectionResult; import com.google.firebase.database.FirebaseDatabase;
import com.google.android.gms.common.GoogleApiAvailability;
import com.google.android.gms.tasks.OnCompleteListener;
import com.google.android.gms.tasks.Task; public class MainActivity extends FragmentActivity {
import com.google.firebase.database.DataSnapshot;
import com.google.firebase.database.DatabaseError; private static final String TAG = "MainActivity";
import com.google.firebase.database.DatabaseReference; private static final int ERROR_DIALOG_REQUEST = 9001;
import com.google.firebase.database.FirebaseDatabase; private DatabaseReference mDatenbank;
import com.google.firebase.database.ValueEventListener; Datenbank db = new Datenbank();
import java.time.LocalDateTime; @Override
import java.time.format.DateTimeFormatter; protected void onCreate(Bundle savedInstanceState) {
import java.util.Calendar; super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
public class MainActivity extends FragmentActivity {
if (isServiceOK()){
private static final String TAG = "MainActivity"; //Für Dantenbank
private static final int ERROR_DIALOG_REQUEST = 9001;
private DatabaseReference mDatenbank; db.setMyWaveSpeed(500);
String android_id; db.setMyAndroidID(Settings.Secure.getString(this.getContentResolver(), Settings.Secure.ANDROID_ID));
WifiManager wm = (WifiManager) getApplicationContext().getSystemService(WIFI_SERVICE);
@Override int ip = wm.getConnectionInfo().getIpAddress();
protected void onCreate(Bundle savedInstanceState) { db.setMyIPadress(String.format("%d.%d.%d.%d",(ip & 0xff),(ip >> 8 & 0xff),(ip >> 16 & 0xff), (ip >> 24 & 0xff)));
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main); db.getDatafromDBnoListener();
if (isServiceOK()){ init();
init(); }
} }
}
private void init(){
private void init(){
Button btnEarthquake = (Button) findViewById(R.id.btnEarthquake);
Button btnEarthquake = (Button) findViewById(R.id.btnEarthquake); Button btnSensor = (Button) findViewById(R.id.btnSensor);
Button btnSensor = (Button) findViewById(R.id.btnSensor); Button btnMuster = (Button) findViewById(R.id.buttonDatenBankMuster);
Button btnMuster = (Button) findViewById(R.id.buttonDatenBankMuster); 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(true);
btnEarthquake.setEnabled(false); 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(true);
btnEarthquake.setEnabled(false); btnSensor.setEnabled(true);
btnSensor.setEnabled(false); startActivity(intent);
startActivity(intent); }
} });
});
btnSensor.setEnabled(true);
btnSensor.setEnabled(false); 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(true);
btnSensor.setEnabled(false); btnEarthquake.setEnabled(true);
btnEarthquake.setEnabled(false); startActivity(intent);
startActivity(intent); }
} });
});
btnMuster.setOnClickListener(new View.OnClickListener() {
btnMuster.setOnClickListener(new View.OnClickListener() { @Override
@Override public void onClick(View v) {
public void onClick(View v) { btnEarthquake.setEnabled(true);
btnEarthquake.setEnabled(true); btnSensor.setEnabled(true);
btnSensor.setEnabled(true); btnLeer.setEnabled(true);
btnLeer.setEnabled(false); btnMuster.setEnabled(true);
btnMuster.setEnabled(false); btnReset.setEnabled(true);
btnReset.setEnabled(true); db.setNonNativeCaseInDB();
deviceInitDataBase(); //deviceInitDataBase(); //TODO: ARON
} }
}); });
btnLeer.setOnClickListener(new View.OnClickListener() { btnLeer.setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
btnEarthquake.setEnabled(true); btnEarthquake.setEnabled(true);
btnSensor.setEnabled(true); btnSensor.setEnabled(true);
btnMuster.setEnabled(false); btnMuster.setEnabled(false);
btnReset.setEnabled(true); btnReset.setEnabled(true);
btnLeer.setEnabled(false); btnLeer.setEnabled(true);
datenBankLeeren(); //datenBankLeeren(); //TODO: ARON
} db.setEmptyDataInDBcompletlyForNativeUse();
}); System.out.println(db.getCommand());
}
btnReset.setEnabled(false); });
btnReset.setOnClickListener(new View.OnClickListener() {
@Override btnReset.setEnabled(true);
public void onClick(View v) { btnReset.setOnClickListener(new View.OnClickListener() {
getDataBaseValuesNoListener(); @Override
btnEarthquake.setEnabled(true); public void onClick(View v) {
btnSensor.setEnabled(true); //getDataBaseValuesNoListener(); //TODO ARON
btnMuster.setEnabled(true); btnMuster.setEnabled(true);
btnLeer.setEnabled(true); btnLeer.setEnabled(true);
} btnEarthquake.setEnabled(true);
}); btnSensor.setEnabled(true);
}
} });
public boolean isServiceOK(){ }
Log.d(TAG, "isServicesOK(): checking google services version");
int available = GoogleApiAvailability.getInstance().isGooglePlayServicesAvailable(MainActivity.this);
public boolean isServiceOK(){
if (available== ConnectionResult.SUCCESS){ Log.d(TAG, "isServicesOK(): checking google services version");
Log.d(TAG,"isServicesOK: Google Play Services is working");
return true; int available = GoogleApiAvailability.getInstance().isGooglePlayServicesAvailable(MainActivity.this);
}
else if (GoogleApiAvailability.getInstance().isUserResolvableError(available)){ if (available== ConnectionResult.SUCCESS){
Log.d(TAG, "isServicesOK(): an error occured but we can fix it"); Log.d(TAG,"isServicesOK: Google Play Services is working");
Dialog dialog = GoogleApiAvailability.getInstance().getErrorDialog(MainActivity.this, available, ERROR_DIALOG_REQUEST); return true;
dialog.show(); }
} else if (GoogleApiAvailability.getInstance().isUserResolvableError(available)){
else { Log.d(TAG, "isServicesOK(): an error occured but we can fix it");
Toast.makeText(this, "You can`t make map request", Toast.LENGTH_SHORT).show(); Dialog dialog = GoogleApiAvailability.getInstance().getErrorDialog(MainActivity.this, available, ERROR_DIALOG_REQUEST);
} dialog.show();
return false; }
} else {
Toast.makeText(this, "You can`t make map request", Toast.LENGTH_SHORT).show();
public void deviceInitDataBase() }
{ return false;
mDatenbank = FirebaseDatabase.getInstance().getReference(); }
Devices d1 = new Devices("10.00.00.000", false, Calendar.getInstance().getTimeInMillis(), 52.51624237821577, 13.37683380067744, 1000, LocalDateTime.now().toString(), ""); //Berlin 52.51624237821577, 13.37683380067744
Devices d2 = new Devices("20.00.00.000", false, Calendar.getInstance().getTimeInMillis(), 48.7560280895443, 11.425157702952347, 200, LocalDateTime.now().toString(),""); //Ingolstadt 48.7560280895443, 11.425157702952347 public void deviceInitDataBase()
Devices d3 = new Devices("30.00.00.000", false, Calendar.getInstance().getTimeInMillis(), 48.16958655466396, 11.617418429524394, 30, LocalDateTime.now().toString(),""); //München 48.16958655466396, 11.617418429524394 {
Devices d4 = new Devices("40.00.00.000", false, Calendar.getInstance().getTimeInMillis(), 45.55620112204013, 12.342516140205387, 4, LocalDateTime.now().toString(),""); //Venedig 45.55620112204013, 12.342516140205387 mDatenbank = FirebaseDatabase.getInstance().getReference();
mDatenbank.child("overviewAronTestetInDiesemAbschnitt").child("IDG1").setValue(d1); Devices d1 = new Devices("","","",49.58967957913626,11.011387124069765,false,false,0,1000,10); //Erlangen 49.58967957913626, 11.011387124069765
mDatenbank.child("overviewAronTestetInDiesemAbschnitt").child("IDG2").setValue(d2); Devices d2 = new Devices("","","",48.7560280895443,11.425157702952347,false,false,0,1000,10); //Ingolstadt 48.7560280895443, 11.425157702952347
mDatenbank.child("overviewAronTestetInDiesemAbschnitt").child("IDG3").setValue(d3); Devices d3 = new Devices("","","",48.16958655466396,11.617418429524394,false,false,0,1000,10); //München 48.16958655466396, 11.617418429524394
mDatenbank.child("overviewAronTestetInDiesemAbschnitt").child("IDG4").setValue(d4); 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
//Nürnberg HBF: 49.4474136331757, 11.082661293035727 mDatenbank.child("overviewnodes").child("IDG1").setValue(d1);
} mDatenbank.child("overviewnodes").child("IDG2").setValue(d2);
mDatenbank.child("overviewnodes").child("IDG3").setValue(d3);
//Datenbank auslesen OHNE Listener. D.h. es werden Daten (snapshot) ausgelesen und kein Listener hinterlegt. mDatenbank.child("overviewnodes").child("IDG4").setValue(d4);
//Sollten sich danach Daten zu einem beliebigen Zeitpunkt in der DB ändern, wird die Funktion "onDataChange" NICHT erneut ausgelöst. mDatenbank.child("overviewnodes").child("IDG5").setValue(d4);
public void getDataBaseValuesNoListener() mDatenbank.child("overviewnodes").child("IDG5").setValue(d5);
{ }
mDatenbank = FirebaseDatabase.getInstance().getReference();
mDatenbank.child("overviewAronTestetInDiesemAbschnitt").get().addOnCompleteListener(new OnCompleteListener<DataSnapshot>() { public void getDataBaseValuesNoListener()
@Override {
public void onComplete(@NonNull Task<DataSnapshot> task) { mDatenbank = FirebaseDatabase.getInstance().getReference();
if (!task.isSuccessful()) { mDatenbank.child("overviewnodes").get().addOnCompleteListener(new OnCompleteListener<DataSnapshot>() {
System.out.println("Error getting data: " + task.getException()); @Override
} public void onComplete(@NonNull Task<DataSnapshot> task) {
else { if (!task.isSuccessful()) {
testProcess(task.getResult()); System.out.println("Error getting data: " + task.getException());
} }
} else {
}); testProcess(task.getResult());
} }
}
public void datenBankLeeren() });
{ }
mDatenbank = FirebaseDatabase.getInstance().getReference();
for (int i = 1; i<=4; i++) public void datenBankLeeren()
{ {
mDatenbank.child("overviewAronTestetInDiesemAbschnitt").child("IDG" + i).child("ip").setValue(""); mDatenbank = FirebaseDatabase.getInstance().getReference();
mDatenbank.child("overviewAronTestetInDiesemAbschnitt").child("IDG" + i).child("vibration").setValue(false); for (int i = 1; i<=5; i++)
mDatenbank.child("overviewAronTestetInDiesemAbschnitt").child("IDG" + i).child("timestamp").setValue(""); {
mDatenbank.child("overviewAronTestetInDiesemAbschnitt").child("IDG" + i).child("breitengrad").setValue(""); mDatenbank.child("overviewnodes").child("IDG" + i).child("a_androidid").setValue("");
mDatenbank.child("overviewAronTestetInDiesemAbschnitt").child("IDG" + i).child("laengengrad").setValue(""); mDatenbank.child("overviewnodes").child("IDG" + i).child("b_localdatetime").setValue("");
mDatenbank.child("overviewAronTestetInDiesemAbschnitt").child("IDG" + i).child("amplitude").setValue(""); mDatenbank.child("overviewnodes").child("IDG" + i).child("c_ip").setValue("");
mDatenbank.child("overviewAronTestetInDiesemAbschnitt").child("IDG" + i).child("localdatetime").setValue(""); mDatenbank.child("overviewnodes").child("IDG" + i).child("d_breitengrad").setValue("");
mDatenbank.child("overviewAronTestetInDiesemAbschnitt").child("IDG" + i).child("androidid").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("");
public void testProcess(DataSnapshot data) mDatenbank.child("overviewnodes").child("IDG" + i).child("i_amplitude").setValue("");
{ }
mDatenbank = FirebaseDatabase.getInstance().getReference().child("overviewAronTestetInDiesemAbschnitt"); }
}
} public void testProcess(DataSnapshot data)
{
mDatenbank = FirebaseDatabase.getInstance().getReference().child("overviewnodes");
}
}
/*
//Datenbank auslesen MIT Listener. D.h. es werden Daten (snapshot) ausgelesen und gleichzeitig ein Listener hinterlegt.
//Sollten sich danach Daten zu einem beliebigen Zeitpunkt in der DB ändern, wird die Funktion "onDataChange" erneut ausgelöst und wieder Daten (snapshot) ausgelesen.
public void getDataBaseValuesListener()
{
mDatenbank = FirebaseDatabase.getInstance().getReference();
mDatenbank.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot snapshot) {
//testProcess(snapshot); //Daten - Snapshot, Übergabe an Methode processDataBaseValues
}
@Override
public void onCancelled(@NonNull DatabaseError error) {
getDataBaseFailure(error);
}
});
}
*/
/*
public void getDataBaseFailure (DatabaseError error)
{
System.out.println("Fehler");
Log.w("Datenbankfehler", error.toException());
}
*/
/*
@RequiresApi(api = Build.VERSION_CODES.O)
public void processDataBaseValues (DataSnapshot data)
{
for (int i = 1; i<=4; i++) //Für alle IDG 1-4 werden Werte ausgegeben
{
//####### Auslesen für String-Werte #######:
String ipAdresse = data.child("overviewAronTestetInDiesemAbschnitt").child("IDG" + i).child("ip").getValue().toString();
//####### Auslesen für boolean-Werte #######:
String vibrationString = data.child("overviewAronTestetInDiesemAbschnitt").child("IDG" + i).child("vibration").getValue().toString();
boolean vibration;
if(vibrationString == "true"){
vibration = true;
}else{
vibration = false;
}
//####### Auslesen für double-Werte #######:
String breitengradString = data.child("overviewAronTestetInDiesemAbschnitt").child("IDG" + i).child("breitengrad").getValue().toString();
String laengengradString = data.child("overviewAronTestetInDiesemAbschnitt").child("IDG" + i).child("laengengrad").getValue().toString();
double breitengrad = Double.parseDouble(breitengradString);
double laengengrad = Double.parseDouble(laengengradString);
//####### Auslesen für long-Werte #######:
String timestampString = data.child("overviewAronTestetInDiesemAbschnitt").child("IDG" + i).child("timestamp").getValue().toString();
long timestamp = Long.parseLong(timestampString);
//####### Auslesen für ing-Werte #######:
String amplitudeString = data.child("overviewAronTestetInDiesemAbschnitt").child("IDG" + i).child("amplitude").getValue().toString();
int amplitude = Integer.parseInt(amplitudeString);
//####### Auslesen für LocalDateTime#######:
String localdatetimeString = data.child("overviewAronTestetInDiesemAbschnitt").child("IDG" + i).child("localdatetime").getValue().toString();
DateTimeFormatter formatter = DateTimeFormatter.ISO_DATE_TIME;
LocalDateTime localdatetime = LocalDateTime.parse(localdatetimeString, formatter);
}
}
*/
File diff suppressed because it is too large. Load diff
@@ -1,28 +1,28 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools" xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
tools:context=".EarthquakeMapsActivity" tools:context=".EarthquakeMapsActivity"
android:paddingTop="?attr/actionBarSize"> android:paddingTop="?attr/actionBarSize">
<TextView <TextView
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:text="@string/shake_your_smartphone_for_a_earthquake" android:text="@string/shake_your_smartphone_for_a_earthquake"
android:layout_centerHorizontal="true" android:layout_centerHorizontal="true"
android:id="@+id/txtEarthquake"/> android:id="@+id/txtEarthquake"/>
<androidx.fragment.app.FragmentContainerView xmlns:map="http://schemas.android.com/apk/res-auto" <androidx.fragment.app.FragmentContainerView xmlns:map="http://schemas.android.com/apk/res-auto"
android:layout_below="@+id/txtEarthquake" android:layout_below="@+id/txtEarthquake"
android:id="@+id/map" android:id="@+id/map"
android:name="com.google.android.gms.maps.SupportMapFragment" android:name="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:layout_marginTop="50dp" android:layout_marginTop="50dp"
tools:context=".EarthquakeMapsActivity" /> tools:context=".EarthquakeMapsActivity" />
</RelativeLayout> </RelativeLayout>
+51 -51
View File
@@ -1,52 +1,52 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools" xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
tools:context=".MainActivity"> tools:context=".MainActivity">
<Button <Button
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:id="@+id/btnEarthquake" android:id="@+id/btnEarthquake"
android:text="@string/generate_earthquake" android:text="@string/generate_earthquake"
android:layout_centerVertical="true" android:layout_centerVertical="true"
android:layout_centerHorizontal="true" /> android:layout_centerHorizontal="true" />
<Button <Button
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:id="@+id/btnSensor" android:id="@+id/btnSensor"
android:text="@string/be_a_sensor" android:text="@string/be_a_sensor"
android:layout_centerHorizontal="true" android:layout_centerHorizontal="true"
android:layout_below="@id/btnEarthquake"/> android:layout_below="@id/btnEarthquake"/>
<Button <Button
android:id="@+id/buttonDatenBankMuster" android:id="@+id/buttonDatenBankMuster"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_below="@+id/btnSensor" android:layout_below="@+id/btnSensor"
android:layout_centerHorizontal="true" android:layout_centerHorizontal="true"
android:layout_marginTop="50dp" android:layout_marginTop="50dp"
android:text="@string/start_mit_vordefinierter_db" /> android:text="@string/start_mit_vordefinierter_db" />
<Button <Button
android:id="@+id/buttonDatenBankLeeren" android:id="@+id/buttonDatenBankLeeren"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_below="@+id/buttonDatenBankMuster" android:layout_below="@+id/buttonDatenBankMuster"
android:layout_centerHorizontal="true" android:layout_centerHorizontal="true"
android:text="@string/start_mit_leeren_db" /> android:text="@string/start_mit_leeren_db" />
<Button <Button
android:id="@+id/buttonReset" android:id="@+id/buttonReset"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_below="@+id/buttonDatenBankLeeren" android:layout_below="@+id/buttonDatenBankLeeren"
android:layout_centerHorizontal="true" android:layout_centerHorizontal="true"
android:text="@string/weitermachen_buttonreset" /> android:text="@string/weitermachen_buttonreset" />
</RelativeLayout> </RelativeLayout>
@@ -1,27 +1,27 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools" xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
tools:context=".EarthquakeMapsActivity"> tools:context=".EarthquakeMapsActivity">
<TextView <TextView
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:text="Timer till vibration" android:text="Timer till vibration"
android:layout_centerHorizontal="true" android:layout_centerHorizontal="true"
android:id="@+id/txtSensor"/> android:id="@+id/txtSensor"/>
<fragment xmlns:android="http://schemas.android.com/apk/res/android" <fragment xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:map="http://schemas.android.com/apk/res-auto" xmlns:map="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools" xmlns:tools="http://schemas.android.com/tools"
android:layout_below="@+id/txtSensor" android:layout_below="@+id/txtSensor"
android:id="@+id/map" android:id="@+id/map"
android:name="com.google.android.gms.maps.SupportMapFragment" android:name="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
tools:context=".SensorMapsActivity" /> tools:context=".SensorMapsActivity" />
</RelativeLayout> </RelativeLayout>
+16 -16
View File
@@ -1,17 +1,17 @@
<resources> <resources>
<string name="app_name">Schockwelle</string> <string name="app_name">Schockwelle</string>
<string name="title_activity_earthquake_maps">Map</string> <string name="title_activity_earthquake_maps">Map</string>
<string name="title_activity_sensor_maps">Map</string> <string name="title_activity_sensor_maps">Map</string>
<string name="be_a_sensor">Be a Sensor</string> <string name="be_a_sensor">Be a Sensor</string>
<string name="generate_earthquake">Generate Earthquake</string> <string name="generate_earthquake">Generate Earthquake</string>
<string name="buttontest">ButtonTest</string> <string name="buttontest">ButtonTest</string>
<string name="mit_leeren_db_starten">Mit leeren DB starten</string> <string name="mit_leeren_db_starten">Mit leeren DB starten</string>
<string name="mit_voller_db_starten_beispielwerte">Mit voller DB starten (Beispielwerte)</string> <string name="mit_voller_db_starten_beispielwerte">Mit voller DB starten (Beispielwerte)</string>
<string name="mit_voller_db_starten">Mit voller DB starten</string> <string name="mit_voller_db_starten">Mit voller DB starten</string>
<string name="universalertestbutton">UniversalerTestButton</string> <string name="universalertestbutton">UniversalerTestButton</string>
<string name="weitermachen">Weitermachen</string> <string name="weitermachen">Weitermachen</string>
<string name="shake_your_smartphone_for_a_earthquake">Shake your Smartphone for a Earthquake</string> <string name="shake_your_smartphone_for_a_earthquake">Shake your Smartphone for a Earthquake</string>
<string name="start_mit_vordefinierter_db">Start mit vordefinierter DB</string> <string name="start_mit_vordefinierter_db">Start mit vordefinierter DB</string>
<string name="start_mit_leeren_db">Start mit Leeren DB</string> <string name="start_mit_leeren_db">Start mit Leeren DB</string>
<string name="weitermachen_buttonreset">Weitermachen - Buttonreset</string> <string name="weitermachen_buttonreset">Weitermachen - Buttonreset</string>
</resources> </resources>