Compare commits

..
1 Commits
Author SHA1 Message Date
ed ea351e5789 First version map, Localication of device with blue dot 2021-06-11 00:13:19 +02:00
31 changed files with 279 additions and 2196 deletions

No files matched your search

Generated
-1
View File
@@ -1 +0,0 @@
Schockwelle
+1 -1
View File
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<project version="4"> <project version="4">
<component name="CompilerConfiguration"> <component name="CompilerConfiguration">
<bytecodeTargetLevel target="11" /> <bytecodeTargetLevel target="1.8" />
</component> </component>
</project> </project>
-1
View File
@@ -1,6 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<project version="4"> <project version="4">
<component name="GradleMigrationSettings" migrationVersion="1" />
<component name="GradleSettings"> <component name="GradleSettings">
<option name="linkedExternalProjectsSettings"> <option name="linkedExternalProjectsSettings">
<GradleProjectSettings> <GradleProjectSettings>
+1 -1
View File
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<project version="4"> <project version="4">
<component name="ProjectRootManager" version="2" languageLevel="JDK_11" default="true" project-jdk-name="1.8" project-jdk-type="JavaSDK"> <component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" default="true" project-jdk-name="1.8" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/build/classes" /> <output url="file://$PROJECT_DIR$/build/classes" />
</component> </component>
<component name="ProjectType"> <component name="ProjectType">
-10
View File
@@ -1,10 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="RunConfigurationProducerService">
<option name="ignoredProducers">
<set>
<option value="com.android.tools.idea.compose.preview.runconfiguration.ComposePreviewRunConfigurationProducer" />
</set>
</option>
</component>
</project>
Generated
-6
View File
@@ -1,6 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" />
</component>
</project>
+5 -9
View File
@@ -1,6 +1,5 @@
plugins { plugins {
id 'com.android.application' id 'com.android.application'
id 'com.google.gms.google-services'
} }
android { android {
@@ -8,8 +7,8 @@ android {
buildToolsVersion "30.0.3" buildToolsVersion "30.0.3"
defaultConfig { defaultConfig {
applicationId "de.edotzlaff.schockwelle" applicationId "de.edotzlaff.maps0123"
minSdkVersion 23 minSdkVersion 24
targetSdkVersion 30 targetSdkVersion 30
versionCode 1 versionCode 1
versionName "1.0" versionName "1.0"
@@ -31,15 +30,12 @@ android {
dependencies { dependencies {
implementation 'androidx.appcompat:appcompat:1.3.0' implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'com.google.android.material:material:1.3.0' implementation 'com.google.android.material:material:1.3.0'
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
implementation 'com.google.android.gms:play-services-maps:17.0.1' implementation 'com.google.android.gms:play-services-maps:17.0.1'
implementation 'com.google.firebase:firebase-database:20.0.0' implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
implementation 'com.google.firebase:firebase-functions:20.0.0'
testImplementation 'junit:junit:4.+' testImplementation 'junit:junit:4.+'
androidTestImplementation 'androidx.test.ext:junit:1.1.2' androidTestImplementation 'androidx.test.ext:junit:1.1.2'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0' androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
implementation "com.google.android.gms:play-services-location:15.0.1" //Important to find the location from the device implementation "com.google.android.gms:play-services-location:15.0.1" //Import to find the location from the device
implementation platform('com.google.firebase:firebase-bom:28.1.0')
} }
-40
View File
@@ -1,40 +0,0 @@
{
"project_info": {
"project_number": "957720376634",
"firebase_url": "https://schockwelle-mdt5-g1-default-rtdb.europe-west1.firebasedatabase.app",
"project_id": "schockwelle-mdt5-g1",
"storage_bucket": "schockwelle-mdt5-g1.appspot.com"
},
"client": [
{
"client_info": {
"mobilesdk_app_id": "1:957720376634:android:fdc03f689ff71b2f70cc03",
"android_client_info": {
"package_name": "de.edotzlaff.schockwelle"
}
},
"oauth_client": [
{
"client_id": "957720376634-gvj86hvfrnt5npvqfbsb8lnu77fgaumh.apps.googleusercontent.com",
"client_type": 3
}
],
"api_key": [
{
"current_key": "AIzaSyDNnG6F_VIzKbu4r7QBqsUZ3z6ELFbgyuc"
}
],
"services": {
"appinvite_service": {
"other_platform_oauth_client": [
{
"client_id": "957720376634-gvj86hvfrnt5npvqfbsb8lnu77fgaumh.apps.googleusercontent.com",
"client_type": 3
}
]
}
}
}
],
"configuration_version": "1"
}
@@ -1,4 +1,4 @@
package de.edotzlaff.schockwelle; package de.edotzlaff.maps0123;
import android.content.Context; import android.content.Context;
@@ -21,6 +21,6 @@ public class ExampleInstrumentedTest {
public void useAppContext() { public void useAppContext() {
// Context of the app under test. // Context of the app under test.
Context appContext = InstrumentationRegistry.getInstrumentation().getTargetContext(); Context appContext = InstrumentationRegistry.getInstrumentation().getTargetContext();
assertEquals("de.edotzlaff.schockwelle", appContext.getPackageName()); assertEquals("de.edotzlaff.maps0123", appContext.getPackageName());
} }
} }
@@ -1,4 +1,24 @@
<resources> <resources>
<!--
TODO: Before you run your application, you need a Google Maps API key.
To get one, follow this link, follow the directions and press "Create" at the end:
https://console.developers.google.com/flows/enableapi?apiid=maps_android_backend&keyType=CLIENT_SIDE_ANDROID&r=D2:BC:D8:1A:07:E8:86:EC:AB:EC:EC:EF:CB:1B:C0:A6:B7:FB:69:56%3Bde.edotzlaff.maps0123
You can also add your credentials to an existing key, using these values:
Package name:
de.edotzlaff.maps0123
SHA-1 certificate fingerprint:
D2:BC:D8:1A:07:E8:86:EC:AB:EC:EC:EF:CB:1B:C0:A6:B7:FB:69:56
Alternatively, follow the directions here:
https://developers.google.com/maps/documentation/android/start#get-key
Once you have your key (it starts with "AIza"), replace the "google_maps_key"
string in this file.
-->
<string name="google_maps_key" templateMergeStrategy="preserve" translatable="false">AIzaSyCCnjanFAzxuH91tD206IjaAU4_ymSgug0</string> <string name="google_maps_key" templateMergeStrategy="preserve" translatable="false">AIzaSyCCnjanFAzxuH91tD206IjaAU4_ymSgug0</string>
</resources> </resources>
+8 -20
View File
@@ -1,26 +1,20 @@
<?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.maps0123">
<!--
The ACCESS_COARSE/FINE_LOCATION permissions are not required to use
Google Maps Android API v2, but you must specify either coarse or fine
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" />
<application <application
android:allowBackup="true" android:allowBackup="true"
android:icon="@mipmap/schockicon" android:icon="@mipmap/ic_launcher"
android:label="@string/app_name" android:label="@string/app_name"
android:roundIcon="@mipmap/schockicon" android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true" android:supportsRtl="true"
android:theme="@style/Theme.Schockwelle"> android:theme="@style/Theme.Maps0123">
<activity android:name=".map"></activity>
<!-- <!--
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").
@@ -34,12 +28,8 @@
android:value="@string/google_maps_key" /> android:value="@string/google_maps_key" />
<activity <activity
android:name=".SensorMapsActivity" android:name=".MapsActivity"
android:label="@string/title_activity_sensor_maps"></activity> android:label="@string/title_activity_maps">
<activity
android:name=".EarthquakeMapsActivity"
android:label="@string/title_activity_earthquake_maps"/>
<activity android:name=".MainActivity">
<intent-filter> <intent-filter>
<action android:name="android.intent.action.MAIN" /> <action android:name="android.intent.action.MAIN" />
@@ -49,5 +39,3 @@
</application> </application>
</manifest> </manifest>
<!--android:parentActivityName=".MainActivity"-->
@@ -0,0 +1,69 @@
package de.edotzlaff.maps0123;
import androidx.fragment.app.FragmentActivity;
import android.app.Dialog;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;
import com.google.android.gms.common.ConnectionResult;
import com.google.android.gms.common.GoogleApiAvailability;
import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.OnMapReadyCallback;
import com.google.android.gms.maps.SupportMapFragment;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.MarkerOptions;
public class MapsActivity extends FragmentActivity {
private static final String TAG = "MainActivity";
private static final int ERROR_DIALOG_REQUEST = 9001;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_map); //IMPORTANT: MapsActivity führt zur activity_map.xml (nicht zur activity_maps)
if (isServiceOK()){
init();
}
}
private void init(){
Button btnMap = (Button) findViewById(R.id.btnMap);
btnMap.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(MapsActivity.this, map.class);
startActivity(intent);
}
});
}
public boolean isServiceOK(){
Log.d(TAG, "isServicesOK(): checking google services version");
int available = GoogleApiAvailability.getInstance().isGooglePlayServicesAvailable(MapsActivity.this);
if (available== ConnectionResult.SUCCESS){
Log.d(TAG,"isServicesOK: Google Play Services is working");
return true;
}
else if (GoogleApiAvailability.getInstance().isUserResolvableError(available)){
Log.d(TAG, "isServicesOK(): an error occured but we can fix it");
Dialog dialog = GoogleApiAvailability.getInstance().getErrorDialog(MapsActivity.this, available, ERROR_DIALOG_REQUEST);
dialog.show();
}
else {
Toast.makeText(this, "You can`t make map request", Toast.LENGTH_SHORT).show();
}
return false;
}
}
@@ -0,0 +1,131 @@
package de.edotzlaff.maps0123;
import android.Manifest;
import android.content.pm.PackageManager;
import android.location.Location;
import android.os.Bundle;
import android.util.Log;
import android.widget.Toast;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.app.ActivityCompat;
import androidx.core.content.ContextCompat;
import com.google.android.gms.location.FusedLocationProviderClient;
import com.google.android.gms.location.LocationServices;
import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.OnMapReadyCallback;
import com.google.android.gms.maps.SupportMapFragment;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.MarkerOptions;
import com.google.android.gms.tasks.OnCompleteListener;
import com.google.android.gms.tasks.Task;
public class map extends AppCompatActivity implements OnMapReadyCallback {
private static final String TAG = "MainActivity";
private static final String FINE_LOCATION = Manifest.permission.ACCESS_FINE_LOCATION;
private static final int LOCATION_PERMISSION_REQUEST_CODE = 1234;
//vars
private Boolean mLocationPermissionsGranted = false;
private GoogleMap mMap;
private FusedLocationProviderClient mFusedLocationProviderClient;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_maps);
getLocationPermission();
}
private void getLocationPermission() {
String[] permissions = {Manifest.permission.ACCESS_FINE_LOCATION};
if (ContextCompat.checkSelfPermission(this.getApplicationContext(), FINE_LOCATION) == PackageManager.PERMISSION_GRANTED) {
mLocationPermissionsGranted = true;
initMap();
} else {
ActivityCompat.requestPermissions(this, permissions, LOCATION_PERMISSION_REQUEST_CODE);
}
}
@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
mLocationPermissionsGranted = false;
switch (requestCode) {
case LOCATION_PERMISSION_REQUEST_CODE: {
if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
mLocationPermissionsGranted = true;
//initalize or map
initMap();
}
}
}
}
private void initMap() {
SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map);
mapFragment.getMapAsync(this);
}
public void onMapReady(GoogleMap googleMap) {
Toast.makeText(this, "Map is ready", Toast.LENGTH_SHORT).show();
mMap = googleMap;
if (mLocationPermissionsGranted) {
getDeviceLocation();
if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION)
!= PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this,
Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
return;
}
mMap.setMyLocationEnabled(true);
}
// Add a marker in Sydney and move the camera
//LatLng sydney = new LatLng(-50, 151);
//mMap.addMarker(new MarkerOptions().position(sydney).title("Marker in Sydney"));
//mMap.moveCamera(CameraUpdateFactory.newLatLng(sydney));
}
private void getDeviceLocation(){
mFusedLocationProviderClient = LocationServices.getFusedLocationProviderClient(this);
try {
if (mLocationPermissionsGranted){
final Task location = mFusedLocationProviderClient.getLastLocation();
location.addOnCompleteListener(new OnCompleteListener() {
@Override
public void onComplete(@NonNull Task task) {
if (task.isSuccessful()){
Location currentLocation = (Location) task.getResult();
moveCamera(new LatLng(currentLocation.getLatitude(), currentLocation.getLongitude()),15f);
}
else{
Toast.makeText(map.this, "Current Location unavailable", Toast.LENGTH_SHORT).show();
}
}
});
}
}catch (SecurityException e){
Log.e(TAG,"Device Location not found" + e.getMessage());
}
}
private void moveCamera(LatLng latlng, float zoom){
Log.d(TAG,"Latitude: "+latlng.latitude+"Longitude: "+latlng.longitude);
mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(latlng, zoom));
}
}
@@ -1,664 +0,0 @@
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,114 +0,0 @@
package de.edotzlaff.schockwelle;
import java.time.LocalDateTime;
public class Devices {
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;
public Devices() {
}
public Devices(String a_androidid, String b_localdatetime, String c_ip, double d_breitengrad, double e_laengengrad, boolean f_nativegps, boolean g_vibration, long h_timestamp, int i_amplitude, 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 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;
}
}
@@ -1,355 +0,0 @@
package de.edotzlaff.schockwelle;
import android.Manifest;
import android.app.ActionBar;
import android.content.Context;
import android.content.pm.PackageManager;
import android.hardware.Sensor;
import android.hardware.SensorEvent;
import android.hardware.SensorEventListener;
import android.hardware.SensorManager;
import android.location.Location;
import android.net.wifi.WifiManager;
import android.os.Build;
import android.os.Bundle;
import android.os.CountDownTimer;
import android.os.SystemClock;
import android.provider.ContactsContract;
import android.provider.Settings;
import android.util.Log;
import android.widget.TextView;
import android.widget.Toast;
import androidx.annotation.NonNull;
import androidx.annotation.RequiresApi;
import androidx.core.app.ActivityCompat;
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.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.OnMapReadyCallback;
import com.google.android.gms.maps.SupportMapFragment;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.MarkerOptions;
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;
import java.util.Date;
import java.util.Objects;
public class EarthquakeMapsActivity extends FragmentActivity implements OnMapReadyCallback {
private static final String TAG = "MainActivity";
private static final String FINE_LOCATION = Manifest.permission.ACCESS_FINE_LOCATION;
private static final int LOCATION_PERMISSION_REQUEST_CODE = 1234;
private Boolean mLocationPermissionsGranted = false;
private GoogleMap mMap;
private FusedLocationProviderClient mFusedLocationProviderClient;
Datenbank db = new Datenbank();
Long currentTime;
Location currentLocation;
private DatabaseReference mDatenbank;
private double breitengrad;
private double laengengrad;
private boolean useOwnGPS;
private int indexID = 1;
//##########################################################################################################################################################################
//################################################################## vvv ShakeParameter vvv ##############################################################################
private SensorManager mSensorManager;
private static final float mUpperThreshold = 10.5f; // für Emulator auf 1.5 setzen TODO Aron
private static final float mLowerThreshold = 5.5f; // für Emulator auf 0.5 setzen TODO Aron
//private static final float mUpperThreshold = 10.5f; // für Emulator auf 1.5 setzen TODO Aron
//private static final float mLowerThreshold = 5.5f; // für Emulator auf 0.5 setzen TODO Aron
private static final long mShakeDetectionLockTimeMicroSeconds = 10000;
private float mAccel;
private float mAccelCurrent;
private float mAccelLast;
private boolean mShakeDetectionIsActive = false;
private boolean mShakeDetected = false;
private boolean allowShakeEvent = true;
//################################################################## ^^^^ ShakeParameter ^^^^ ############################################################################
//##########################################################################################################################################################################
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_earthquake_maps);
//Database Init
db.setMyWaveSpeed(500);
db.setMyAndroidID(Settings.Secure.getString(this.getContentResolver(), Settings.Secure.ANDROID_ID));
WifiManager wm = (WifiManager) getApplicationContext().getSystemService(WIFI_SERVICE);
int ip = wm.getConnectionInfo().getIpAddress();
db.setMyIPadress(String.format("%d.%d.%d.%d",(ip & 0xff),(ip >> 8 & 0xff),(ip >> 16 & 0xff), (ip >> 24 & 0xff)));
db.getDatafromDBnoListener();
db.getDataBaseValuesWithListener();
sensorManagementInit();
getLocationPermission();
}
//#####################################################################################################################################################################
//################################################################## vvv ShakeCode vvv ##############################################################################
private void sensorManagementInit()
{
TextView txtEarthquake = (TextView) findViewById(R.id.txtEarthquake);
mSensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE);
Objects.requireNonNull(mSensorManager).registerListener(mSensorListener, mSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER), SensorManager.SENSOR_DELAY_NORMAL);
mAccel = 1f;
mAccelCurrent = SensorManager.GRAVITY_EARTH;
mAccelLast = SensorManager.GRAVITY_EARTH;
mShakeDetectionIsActive = true;
mShakeDetected = false;
}
private CountDownTimer mLockTimer = new CountDownTimer(mShakeDetectionLockTimeMicroSeconds, 1000)
{
public void onTick(long millisUntilFinished) {
((TextView) findViewById(R.id.txtEarthquake)).setText("Earthquake started! Detection locked for " + millisUntilFinished / 1000 + " s");
}
public void onFinish() {
mShakeDetectionIsActive = true;
mShakeDetected = false;
Toast.makeText(getApplicationContext(), "Shake Detection unlocked", Toast.LENGTH_SHORT).show();
( (TextView) findViewById(R.id.txtEarthquake)).setText("Shake your Smartphone for an Earthquake");
}
};
private final SensorEventListener mSensorListener = new SensorEventListener() {
@Override
public void onSensorChanged(SensorEvent event) {
float x = event.values[0];
float y = event.values[1];
float z = event.values[2];
mAccelLast = mAccelCurrent;
mAccelCurrent = (float) Math.sqrt((double) (x * x + y * y + z * z));
float delta = mAccelCurrent - mAccelLast;
mAccel = mAccel * 0.9f + delta;
// Log.d(TAG,"mAccel: "+ mAccel);
if (mShakeDetectionIsActive) {
if(Math.abs(mAccel) > mUpperThreshold) {
new CountDownTimer(50, 10) {
public void onTick(long millisUntilFinished) {
if (Math.abs(mAccel) > mUpperThreshold) {
mShakeDetectionIsActive = false;
} else if (Math.abs(mAccel) < mLowerThreshold) {
mShakeDetectionIsActive = true;
this.cancel();
}
}
@RequiresApi(api = Build.VERSION_CODES.O)
public void onFinish() {
if (Math.abs(mAccel) > mUpperThreshold) {
mShakeDetectionIsActive = false;
mShakeDetected = true;
Toast.makeText(getApplicationContext(), "Shake event detected", Toast.LENGTH_SHORT).show();
writeEarthquakeToDatabase(); //TODO Aron
mLockTimer.start();
} else {
mShakeDetectionIsActive = true;
mShakeDetected = false;
}
}
}.start();
}
}
}
@Override
public void onAccuracyChanged(Sensor sensor, int accuracy) {
}
};
@Override
protected void onResume() {
mSensorManager.registerListener(mSensorListener, mSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER), SensorManager.SENSOR_DELAY_NORMAL);
super.onResume();
}
@Override
protected void onPause() {
mSensorManager.unregisterListener(mSensorListener);
super.onPause();
}
//################################################################## ^^^^ ShakeCode ^^^^ ############################################################################
//#####################################################################################################################################################################
//#####################################################################################################################################################################
//################################################################## vvv GPS Code vvv ###############################################################################
private void getLocationPermission() {
String[] permissions = {Manifest.permission.ACCESS_FINE_LOCATION};
if (ContextCompat.checkSelfPermission(this.getApplicationContext(), FINE_LOCATION) == PackageManager.PERMISSION_GRANTED) {
mLocationPermissionsGranted = true;
initMap();
} else {
ActivityCompat.requestPermissions(this, permissions, LOCATION_PERMISSION_REQUEST_CODE);
}
}
@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
mLocationPermissionsGranted = false;
switch (requestCode) {
case LOCATION_PERMISSION_REQUEST_CODE: {
if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
mLocationPermissionsGranted = true;
initMap(); //initalize or map
}
}
}
}
private void initMap() {
SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map);
mapFragment.getMapAsync(this);
}
@Override
public void onMapReady(GoogleMap googleMap) {
Toast.makeText(this, "Map is ready", Toast.LENGTH_SHORT).show();
mMap = googleMap;
if (mLocationPermissionsGranted) {
getDeviceLocation();
if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION)
!= PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this,
Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
return;
}
mMap.setMyLocationEnabled(true);
}
//TODO @ Eddy: Ich denke diesen Code brauchst du auch, oder? :D
//Add a marker in Sydney and move the camera
//LatLng sydney = new LatLng(-34, 151);
//mMap.addMarker(new MarkerOptions().position(sydney).title("Marker in Sydney"));
//mMap.moveCamera(CameraUpdateFactory.newLatLng(sydney));
}
private void getDeviceLocation(){
mFusedLocationProviderClient = LocationServices.getFusedLocationProviderClient(this);
try {
if (mLocationPermissionsGranted){
final Task location = mFusedLocationProviderClient.getLastLocation();
location.addOnCompleteListener(new OnCompleteListener() {
@Override
public void onComplete(@NonNull Task task) {
if (task.isSuccessful()){
currentLocation = (Location) task.getResult();
System.out.println(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>" + db.getNativeGPScaseInDB());
if(db.getNativeGPScaseInDB())
{
System.out.println("---Eigene GPS Daten werden verwendet");
breitengrad = currentLocation.getLatitude();
laengengrad = currentLocation.getLongitude();
db.setShakeBreitengrad(breitengrad);
db.setShakeLaengengrad(laengengrad);
}
/*
if(useOwnGPS) //TODO Aron
{
breitengrad = currentLocation.getLatitude();
laengengrad = currentLocation.getLongitude();
}
*/
currentLocation.setLatitude(breitengrad);
currentLocation.setLongitude(laengengrad);
moveCamera(new LatLng(currentLocation.getLatitude(), currentLocation.getLongitude()),15f);
}
else{
Toast.makeText(EarthquakeMapsActivity.this, "Current Location unavailable", Toast.LENGTH_SHORT).show();
}
}
});
}
}catch (SecurityException e){
Log.e(TAG,"Device Location not found" + e.getMessage());
}
}
private void moveCamera(LatLng latlng, float zoom){
Log.d(TAG,"Latitude: "+latlng.latitude+"Longitude: "+latlng.longitude);
mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(latlng, zoom));
}
//################################################################## ^^^^ GPS Code ^^^^ #############################################################################
//#####################################################################################################################################################################
//#####################################################################################################################################################################
//################################################################## vvv Datenbank Code vvv #########################################################################
@RequiresApi(api = Build.VERSION_CODES.O)
private void writeEarthquakeToDatabase()
{
boolean nativeGPS;
if(db.getNativeGPScaseInDB())
{
nativeGPS = true;
}else{
nativeGPS = false;
}
///Evtl löschen und localDateTimeMod mit LocalDateTime.now(ZoneOffset.UTC).toString() ersetzen...
String localDateTimeMod;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
localDateTimeMod = LocalDateTime.now(ZoneOffset.UTC).toString();
} else
{
localDateTimeMod = LocalDateTime.now(ZoneOffset.UTC).toString();
}
for(int i=1; i<=db.getAmountOfIDGs(); i++)
{
if(!db.getStatusIFAndroidIDexistsInDB(db.getMyAndroidID()))
{
//Wenn eigenen androidID nicht in DB existiert
Devices d1 = new Devices();
d1 = new Devices(db.getMyAndroidID(),
localDateTimeMod,
db.getMyIPadress(),
breitengrad,
laengengrad,
nativeGPS,
true,
Calendar.getInstance().getTimeInMillis(),
1000,
db.getMyWaveSpeed());
db.setIDGtoDevice(i,d1);
break;
}else{
Toast.makeText(getApplicationContext(), "Gerät ist bereits in DB eingetragen!", Toast.LENGTH_SHORT).show();
break;
}
}
}
}
@@ -1,197 +0,0 @@
package de.edotzlaff.schockwelle;
import androidx.annotation.NonNull;
import androidx.fragment.app.FragmentActivity;
import android.app.Dialog;
import android.content.Intent;
import android.net.wifi.WifiManager;
import android.os.Bundle;
import android.provider.Settings;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;
import com.google.android.gms.common.ConnectionResult;
import com.google.android.gms.common.GoogleApiAvailability;
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.DatabaseReference;
import com.google.firebase.database.FirebaseDatabase;
public class MainActivity extends FragmentActivity {
private static final String TAG = "MainActivity";
private static final int ERROR_DIALOG_REQUEST = 9001;
private DatabaseReference mDatenbank;
Datenbank db = new Datenbank();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
if (isServiceOK()){
//Für Dantenbank
db.setMyWaveSpeed(500);
db.setMyAndroidID(Settings.Secure.getString(this.getContentResolver(), Settings.Secure.ANDROID_ID));
WifiManager wm = (WifiManager) getApplicationContext().getSystemService(WIFI_SERVICE);
int ip = wm.getConnectionInfo().getIpAddress();
db.setMyIPadress(String.format("%d.%d.%d.%d",(ip & 0xff),(ip >> 8 & 0xff),(ip >> 16 & 0xff), (ip >> 24 & 0xff)));
db.getDatafromDBnoListener();
init();
}
}
private void init(){
Button btnEarthquake = (Button) findViewById(R.id.btnEarthquake);
Button btnSensor = (Button) findViewById(R.id.btnSensor);
Button btnMuster = (Button) findViewById(R.id.buttonDatenBankMuster);
Button btnLeer = (Button) findViewById(R.id.buttonDatenBankLeeren);
Button btnReset = (Button) findViewById(R.id.buttonReset);
btnEarthquake.setEnabled(true);
btnEarthquake.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(MainActivity.this, EarthquakeMapsActivity.class);
btnEarthquake.setEnabled(true);
btnSensor.setEnabled(true);
startActivity(intent);
}
});
btnSensor.setEnabled(true);
btnSensor.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(MainActivity.this, SensorMapsActivity.class);
btnSensor.setEnabled(true);
btnEarthquake.setEnabled(true);
startActivity(intent);
}
});
btnMuster.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
btnEarthquake.setEnabled(true);
btnSensor.setEnabled(true);
btnLeer.setEnabled(true);
btnMuster.setEnabled(true);
btnReset.setEnabled(true);
db.setNonNativeCaseInDB();
//deviceInitDataBase(); //TODO: ARON
}
});
btnLeer.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
btnEarthquake.setEnabled(true);
btnSensor.setEnabled(true);
btnMuster.setEnabled(false);
btnReset.setEnabled(true);
btnLeer.setEnabled(true);
//datenBankLeeren(); //TODO: ARON
db.setEmptyDataInDBcompletlyForNativeUse();
System.out.println(db.getCommand());
}
});
btnReset.setEnabled(true);
btnReset.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
//getDataBaseValuesNoListener(); //TODO ARON
btnMuster.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);
if (available== ConnectionResult.SUCCESS){
Log.d(TAG,"isServicesOK: Google Play Services is working");
return true;
}
else if (GoogleApiAvailability.getInstance().isUserResolvableError(available)){
Log.d(TAG, "isServicesOK(): an error occured but we can fix it");
Dialog dialog = GoogleApiAvailability.getInstance().getErrorDialog(MainActivity.this, available, ERROR_DIALOG_REQUEST);
dialog.show();
}
else {
Toast.makeText(this, "You can`t make map request", Toast.LENGTH_SHORT).show();
}
return false;
}
public void deviceInitDataBase()
{
mDatenbank = FirebaseDatabase.getInstance().getReference();
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("overviewnodes").child("IDG1").setValue(d1);
mDatenbank.child("overviewnodes").child("IDG2").setValue(d2);
mDatenbank.child("overviewnodes").child("IDG3").setValue(d3);
mDatenbank.child("overviewnodes").child("IDG4").setValue(d4);
mDatenbank.child("overviewnodes").child("IDG5").setValue(d4);
mDatenbank.child("overviewnodes").child("IDG5").setValue(d5);
}
public void getDataBaseValuesNoListener()
{
mDatenbank = FirebaseDatabase.getInstance().getReference();
mDatenbank.child("overviewnodes").get().addOnCompleteListener(new OnCompleteListener<DataSnapshot>() {
@Override
public void onComplete(@NonNull Task<DataSnapshot> task) {
if (!task.isSuccessful()) {
System.out.println("Error getting data: " + task.getException());
}
else {
testProcess(task.getResult());
}
}
});
}
public void datenBankLeeren()
{
mDatenbank = FirebaseDatabase.getInstance().getReference();
for (int i = 1; i<=5; i++)
{
mDatenbank.child("overviewnodes").child("IDG" + i).child("a_androidid").setValue("");
mDatenbank.child("overviewnodes").child("IDG" + i).child("b_localdatetime").setValue("");
mDatenbank.child("overviewnodes").child("IDG" + i).child("c_ip").setValue("");
mDatenbank.child("overviewnodes").child("IDG" + i).child("d_breitengrad").setValue("");
mDatenbank.child("overviewnodes").child("IDG" + i).child("e_laengengrad").setValue("");
mDatenbank.child("overviewnodes").child("IDG" + i).child("f_nativegps").setValue(true);
mDatenbank.child("overviewnodes").child("IDG" + i).child("g_vibration").setValue(false);
mDatenbank.child("overviewnodes").child("IDG" + i).child("h_timestamp").setValue("");
mDatenbank.child("overviewnodes").child("IDG" + i).child("i_amplitude").setValue("");
}
}
public void testProcess(DataSnapshot data)
{
mDatenbank = FirebaseDatabase.getInstance().getReference().child("overviewnodes");
}
}
@@ -1,659 +0,0 @@
package de.edotzlaff.schockwelle;
import android.Manifest;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.location.Location;
import android.net.wifi.WifiManager;
import android.os.Build;
import android.os.Bundle;
import android.os.CountDownTimer;
import android.os.VibrationEffect;
import android.os.Vibrator;
import android.provider.Settings;
import android.util.Log;
import android.widget.TextView;
import android.widget.Toast;
import androidx.annotation.NonNull;
import androidx.annotation.RequiresApi;
import androidx.core.app.ActivityCompat;
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.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.OnMapReadyCallback;
import com.google.android.gms.maps.SupportMapFragment;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.MarkerOptions;
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;
import java.util.Date;
public class SensorMapsActivity extends FragmentActivity implements OnMapReadyCallback {
private static final String TAG = "MainActivity";
private static final String FINE_LOCATION = Manifest.permission.ACCESS_FINE_LOCATION;
private static final int LOCATION_PERMISSION_REQUEST_CODE = 1234;
private static final double EARTHQUAKE_VELOCITY = 1; // 1 Meter pro Sekunde Erdbebengeschwindigkeit
Datenbank db = new Datenbank();
//vars
private Boolean mLocationPermissionsGranted = false;
private GoogleMap mMap;
private FusedLocationProviderClient mFusedLocationProviderClient;
//Date currentTime;
Location currentLocation;
Long currentTime;
private double breitengrad;
private double laengengrad;
private double sensorGPSbreitengrad;
private double sensorGPSlaengengrad;
private boolean useOwnGPS;
private boolean takeGPSfromDB = true;
private boolean tookOwnGPS = false;
private boolean globalShit = true;
private boolean permissionToWriteToDataBase = true;
private DataSnapshot datenBankSnapShot;
boolean vibrationTrigger = true;
boolean grabGPSandID = true;
private DatabaseReference mDatenbank;
private String breitengradQuellVibration;
private String laengengradQuellVibration;
private Boolean mDeviceCanVibrate = false;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_sensor_maps);
//Database Init
db.setMyWaveSpeed(500);
db.setMyAndroidID(Settings.Secure.getString(this.getContentResolver(), Settings.Secure.ANDROID_ID));
WifiManager wm = (WifiManager) getApplicationContext().getSystemService(WIFI_SERVICE);
int ip = wm.getConnectionInfo().getIpAddress();
db.setMyIPadress(String.format("%d.%d.%d.%d",(ip & 0xff),(ip >> 8 & 0xff),(ip >> 16 & 0xff), (ip >> 24 & 0xff)));
/*
db.getDatafromDBnoListener();
db.getDataBaseValuesWithListener();
*/
getDataBaseValuesWithListener();
TextView tv= (TextView) findViewById(R.id.txtSensor);
getLocationPermission(); //Zuerst werden die aktuellen Standortdaten ermittelt
getVibrationAbility();
}
//#####################################################################################################################################################################
//################################################################## vvv ShakeCode vvv ##############################################################################
private void getVibrationAbility()
{
// Get instance of Vibrator from current Context
Vibrator v = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);
// Output yes if can vibrate, no otherwise
if (v.hasVibrator()) {
Log.v("Can Vibrate", "YES");
// Log.v("Can Control Amplitude", v.hasAmplitudeControl() ? "YES" : "NO");
mDeviceCanVibrate = true;
}
else
{
Log.v("Can Vibrate", "NO");
mDeviceCanVibrate = false;
}
}
private void setVibrationTimer(long msDelay, int duration, int amplitude, int index)
{
new CountDownTimer(msDelay, 1000) {
public void onTick(long millisUntilFinished) {
((TextView) findViewById(R.id.txtSensor)).setText("Earthquake hits in " + millisUntilFinished / 1000 + " s");
}
@RequiresApi(api = Build.VERSION_CODES.O)
public void onFinish() {
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 in DB geschrieben
setVibrationInDataBase(index); //TODO Aron
}
}.start();
}
public void performVibration(int duration, int amplitude) {
if(!mDeviceCanVibrate)
return;
Vibrator v = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);
if (Build.VERSION.SDK_INT >= 26) {
if(amplitude > 255 || amplitude < 1)
amplitude = VibrationEffect.DEFAULT_AMPLITUDE;
if(duration == 0)
{
v.cancel(); //stop vibration if still running
Toast.makeText(this, "Vibration has been stopped", Toast.LENGTH_SHORT).show();
return;
}
//Toast.makeText(this, "Ampl: " + amplitude + ", Dur: " + duration, Toast.LENGTH_SHORT).show();
v.vibrate(VibrationEffect.createOneShot(duration,amplitude));
} else {
if(duration == 0)
{
v.cancel(); //stop vibration if still running
return;
}
v.vibrate(duration);
}
}
//################################################################## ^^^^ ShakeCode ^^^^ ############################################################################
//#####################################################################################################################################################################
//#####################################################################################################################################################################
//################################################################## vvv GPS Code vvv ###############################################################################
private void getLocationPermission() {
String[] permissions = {Manifest.permission.ACCESS_FINE_LOCATION};
if (ContextCompat.checkSelfPermission(this.getApplicationContext(), FINE_LOCATION) == PackageManager.PERMISSION_GRANTED) {
mLocationPermissionsGranted = true;
initMap();
} else {
ActivityCompat.requestPermissions(this, permissions, LOCATION_PERMISSION_REQUEST_CODE);
}
}
@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
mLocationPermissionsGranted = false;
switch (requestCode) {
case LOCATION_PERMISSION_REQUEST_CODE: {
if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
mLocationPermissionsGranted = true;
//initalize or map
initMap();
}
}
}
}
void initMap(){
// Obtain the SupportMapFragment and get notified when the map is ready to be used.
SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager()
.findFragmentById(R.id.map);
mapFragment.getMapAsync(this);
}
@Override
public void onMapReady(GoogleMap googleMap) {
Toast.makeText(this, "Map is ready", Toast.LENGTH_SHORT).show();
mMap = googleMap;
if (mLocationPermissionsGranted) {
getDeviceLocation();
if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION)
!= PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this,
Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
return;
}
mMap.setMyLocationEnabled(true);
}
//TODO @ Eddy: Ich denke diesen Code brauchst du noch, oder? :D
//Add a marker in Sydney and move the camera
//LatLng sydney = new LatLng(-34, 151);
//mMap.addMarker(new MarkerOptions().position(sydney).title("Marker in Sydney"));
//mMap.moveCamera(CameraUpdateFactory.newLatLng(sydney));
}
private void getDeviceLocation(){
mFusedLocationProviderClient = LocationServices.getFusedLocationProviderClient(this);
try {
if (mLocationPermissionsGranted){
final Task location = mFusedLocationProviderClient.getLastLocation();
location.addOnCompleteListener(new OnCompleteListener() {
@Override
public void onComplete(@NonNull Task task) {
if (task.isSuccessful()){
currentLocation = (Location) task.getResult();
currentTime = Calendar.getInstance().getTimeInMillis();
/*
if(!db.getNativeGPScaseInDB())
{
System.out.println("---Fremde GPS Daten werden verwendet");
currentLocation.setLatitude(breitengrad);
currentLocation.setLongitude(laengengrad);
}
*/
if (!useOwnGPS)
{
currentLocation.setLatitude(breitengrad);
currentLocation.setLongitude(laengengrad);
}
//Toast.makeText(SensorMapsActivity.this, currentTime.toString(), Toast.LENGTH_SHORT).show();
moveCamera(new LatLng(currentLocation.getLatitude(), currentLocation.getLongitude()),15f);
}
else{
Toast.makeText(SensorMapsActivity.this, "Current Location unavailable", Toast.LENGTH_SHORT).show();
}
}
});
}
}catch (SecurityException e){
Log.e(TAG,"Device Location not found" + e.getMessage());
}
}
private void moveCamera(LatLng latlng, float zoom){
Log.d(TAG,"Latitude: "+latlng.latitude+"Longitude: "+latlng.longitude);
mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(latlng, zoom));
}
//################################################################## ^^^^ GPS Code ^^^^ #############################################################################
//#####################################################################################################################################################################
//#####################################################################################################################################################################
//################################################################## vvv DB Code vvv ###############################################################################
//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 getDataBaseValuesWithListener()
{
mDatenbank = FirebaseDatabase.getInstance().getReference();
mDatenbank.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot snapshot) {
processDataBaseUpdate(snapshot);
datenBankSnapShot = snapshot;
}
@Override
public void onCancelled(@NonNull DatabaseError error) {
getDataBaseFailure(error);
}
});
}
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; f++)
{
if((!analyzeIfAnroidIdIsEmpty(data,f) && !analyzeForOwnAndroidID(data,f) && analyzeForStateOfVibration(data,f) && analyzeForExisitingGPSvalues(data,f) && permissionToWriteToDataBase))
{
System.out.println("Index: " + f + ": Eintrittskriterien erfüllt.");
//Nehme Quelle GPS Daten
String breitengradString = data.child("overviewnodes").child("IDG" + f).child("d_breitengrad").getValue().toString();
String laengengradString = data.child("overviewnodes").child("IDG" + f).child("e_laengengrad").getValue().toString();
breitengradQuellVibration = breitengradString;
laengengradQuellVibration = laengengradString;
f=1;
if(analyzeForOwnAndroidID(data,f))
{
System.out.println("Index: " + f + ": Eigene ID vorhanden.");
if (!analyzeForStateOfVibration(data,f))
{
System.out.println("Index: " + f + ": Vibration is false.");
if(analyzeForExisitingGPSvalues(data,f) && permissionToWriteToDataBase)
{
//System.out.println("Index: " + f + ": Beide GPS Daten vorhanden. Ich reserviere mir diesen Platz und schreibe hier demnächst rein.");
//hier sofort ID eintragen
//mDatenbank = FirebaseDatabase.getInstance().getReference();
//mDatenbank.child("overviewnodes").child("IDG" + f).child("a_androidid").setValue(getandroidid());
float distanceToEarthquake;
distanceToEarthquake = distance(currentLocation.getLatitude(), currentLocation.getLongitude(), Double.parseDouble(breitengradQuellVibration), Double.parseDouble(laengengradQuellVibration));
long wellenAusbreitungsGeschwindigkeit = (long) db.getMyWaveSpeed(); //Meter die Sekunde
long delayInSeconds = (long) distanceToEarthquake/wellenAusbreitungsGeschwindigkeit; //s
long delayInMilliSeconds = delayInSeconds*1000;
setVibrationTimer(delayInMilliSeconds,1500,255,f);
permissionToWriteToDataBase = false;
break;
}
else{
System.out.println("Index: " + f + ": Habe keine GPS Daten");
}
}else{
System.out.println("Index: " + f + ": Meine Vibration ist bereits true.");
break;
}
}
else
{
System.out.println("Index: " + f + ": Eigene ID nicht vorhanden");
for(f = f; f<=indexMax; f++)
{
if((analyzeIfAnroidIdIsEmpty(data,f) || analyzeForOwnAndroidID(data,f)) && permissionToWriteToDataBase)
{
//System.out.println("Index: " + f + ": Diese Slot war leer oder es ist meine eigene ID. Ich schreibe hier rein");
//mDatenbank = FirebaseDatabase.getInstance().getReference();
//mDatenbank.child("overviewnodes").child("IDG" + f).child("a_androidid").setValue(getandroidid());
float distanceToEarthquake;
distanceToEarthquake = distance(currentLocation.getLatitude(), currentLocation.getLongitude(), Double.parseDouble(breitengradQuellVibration), Double.parseDouble(laengengradQuellVibration));
long wellenAusbreitungsGeschwindigkeit = (long) db.getMyWaveSpeed(); //Meter die Sekunde
long delayInSeconds = (long) distanceToEarthquake/wellenAusbreitungsGeschwindigkeit; //s
long delayInMilliSeconds = delayInSeconds*1000;
setVibrationTimer(delayInMilliSeconds,1500,255,f);
permissionToWriteToDataBase = false;
break;
}
if(f == indexMax && !analyzeIfAnroidIdIsEmpty(data,f))
{
System.out.println(">>>Index " + f + " >>>Konnte keine freien Slot finden");
}
}
}
}
}
}
public boolean analyzeForUseOfOwnGPS(DataSnapshot data)
{
String nativeGPSString;
boolean nativeGPS;
int amountNativeGPSisTrue = 0;
int indexMax = (int) data.child("overviewnodes").getChildrenCount();
for (int i = 1; i <= indexMax; i++)
{
nativeGPSString = data.child("overviewnodes").child("IDG" + i).child("f_nativegps").getValue().toString();
if(nativeGPSString.equals("true"))
{
amountNativeGPSisTrue++;
}else
{
amountNativeGPSisTrue--;
}
}
if(amountNativeGPSisTrue == indexMax)
{
nativeGPS = true;
}else{
nativeGPS = false;
}
return nativeGPS;
}
public boolean analyzeIfAnroidIdIsEmpty(DataSnapshot data, int k)
{
String androidid;
int indexMax = (int) data.child("overviewnodes").getChildrenCount();
boolean androididempty = false;
for (int i = k; i <= k; i++)
{
androidid = data.child("overviewnodes").child("IDG" + i).child("a_androidid").getValue().toString();
if(androidid.isEmpty())
{
androididempty = true;
}else
{
androididempty = false;
}
}
return androididempty;
}
public boolean analyzeForOwnAndroidID(DataSnapshot data, int k)
{
String androididString;
boolean ownAndroidID = false;
int indexMax = (int) data.child("overviewnodes").getChildrenCount();
for (int i = k; i <= k; i++)
{
androididString = data.child("overviewnodes").child("IDG" + i).child("a_androidid").getValue().toString();
if(androididString.equals(getandroidid()))
{
ownAndroidID = true;
}else
{
ownAndroidID = false;
}
}
return ownAndroidID;
}
public boolean analyzeForStateOfVibration(DataSnapshot data, int k)
{
String vibrationString;
boolean stateOfVibration = false;
int indexMax = (int) data.child("overviewnodes").getChildrenCount();
for (int i = k; i <= k; i++)
{
vibrationString = data.child("overviewnodes").child("IDG" + i).child("g_vibration").getValue().toString();
if(vibrationString.equals("true"))
{
stateOfVibration = true;
}else
{
stateOfVibration = false;
}
}
return stateOfVibration;
}
public boolean analyzeForExisitingGPSvalues(DataSnapshot data, int k)
{
String breitengradString;
String laengengradString;
boolean bothGPSvaluesExist = false;
int indexMax = (int) data.child("overviewnodes").getChildrenCount();
for (int i = k; i <= k; i++)
{
breitengradString = data.child("overviewnodes").child("IDG" + i).child("d_breitengrad").getValue().toString();
laengengradString = data.child("overviewnodes").child("IDG" + i).child("e_laengengrad").getValue().toString();
if(!breitengradString.isEmpty() && !laengengradString.isEmpty())
{
bothGPSvaluesExist = true;
}else
{
bothGPSvaluesExist = false;
}
}
return bothGPSvaluesExist;
}
public void allocateIDtoDatabaseSlot(int k)
{
mDatenbank = FirebaseDatabase.getInstance().getReference();
mDatenbank.child("overviewnodes").child("IDG" + k).child("a_androidid").setValue(getandroidid());
}
@RequiresApi(api = Build.VERSION_CODES.O)
public void setVibrationInDataBase(int k)
{
System.out.println("Es wird versucht in DB zu schreiben....");
for(k =k; k<=datenBankSnapShot.child("overviewnodes").getChildrenCount();k++)
{
System.out.println("Index...." + k);
System.out.println("analyzeIfAnroidIdIsEmpty(datenBankSnapShot,k)" + k + "___" + analyzeIfAnroidIdIsEmpty(datenBankSnapShot,k));
System.out.println("analyzeForOwnAndroidID(datenBankSnapShot,k)" + k + "___" + analyzeForOwnAndroidID(datenBankSnapShot,k));
System.out.println("analyzeForStateOfVibration(datenBankSnapShot,k)" + k + "___" + analyzeForStateOfVibration(datenBankSnapShot,k));
//Wenn Leer ODER eigene ID und Vibration = false;
if((analyzeIfAnroidIdIsEmpty(datenBankSnapShot,k) || analyzeForOwnAndroidID(datenBankSnapShot,k) && !analyzeForStateOfVibration(datenBankSnapShot,k) ))
{
System.out.println("Android ID war leer oder es war eigene ID mit Vibration = false. SChreibe in DB...... " + k);
//Reinschreieben
mDatenbank = FirebaseDatabase.getInstance().getReference();
mDatenbank.child("overviewnodes").child("IDG" + k).child("a_androidid").setValue(getandroidid());
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
//mDatenbank.child("overviewnodes").child("IDG" + k).child("b_localdatetime").setValue(LocalDateTime.now().toString());
mDatenbank.child("overviewnodes").child("IDG" + k).child("b_localdatetime").setValue(LocalDateTime.now(ZoneOffset.UTC).toString());
}
mDatenbank.child("overviewnodes").child("IDG" + k).child("c_ip").setValue(getDeviceIpAdress());
if (useOwnGPS)
{
mDatenbank.child("overviewnodes").child("IDG" + k).child("f_nativegps").setValue(true);
mDatenbank.child("overviewnodes").child("IDG" + k).child("d_breitengrad").setValue(currentLocation.getLatitude()); //aktueller Breitengrad
mDatenbank.child("overviewnodes").child("IDG" + k).child("e_laengengrad").setValue(currentLocation.getLongitude()); //aktueller Längergrad
}else{
mDatenbank.child("overviewnodes").child("IDG" + k).child("d_breitengrad").setValue(breitengrad); //aktueller Breitengrad
mDatenbank.child("overviewnodes").child("IDG" + k).child("e_laengengrad").setValue(laengengrad); //aktueller Längergrad
mDatenbank.child("overviewnodes").child("IDG" + k).child("f_nativegps").setValue(false);
}
mDatenbank.child("overviewnodes").child("IDG" + k).child("g_vibration").setValue(true);
mDatenbank.child("overviewnodes").child("IDG" + k).child("h_timestamp").setValue(Calendar.getInstance().getTimeInMillis()); //aktueller Zeitstempel wird in Datenbank eingetragen
mDatenbank.child("overviewnodes").child("IDG" + k).child("i_amplitude").setValue(1000);
mDatenbank.child("overviewnodes").child("IDG" + k).child("w_wellengeschwindigkeit").setValue(db.getMyWaveSpeed());
break;
}else
{
System.out.println("Erhöhe Index weil nicht durchgekommen" + k);
//k erhöhen solange leerer Slot ist oder abbruch weil zu voll
if(k ==(int) datenBankSnapShot.child("overviewnodes").getChildrenCount())
{
System.out.println("Kein freier Slot mehr vorhanden");
break;
}
}
}
}
public String getDeviceIpAdress ()
{
WifiManager wm = (WifiManager) getApplicationContext().getSystemService(WIFI_SERVICE);
int ip = wm.getConnectionInfo().getIpAddress();
String ipAddress = String.format("%d.%d.%d.%d",(ip & 0xff),(ip >> 8 & 0xff),(ip >> 16 & 0xff), (ip >> 24 & 0xff));
return ipAddress;
}
public String getandroidid ()
{
return Settings.Secure.getString(this.getContentResolver(), Settings.Secure.ANDROID_ID);
}
public void getDataBaseFailure (DatabaseError error)
{
System.out.println("Fehler");
Log.w("Datenbankfehler", error.toException());
}
private float distance(double currentlatitude, double currentlongitude, double originLat, double originLon) {
float[] results = new float[1];
Location.distanceBetween(currentlatitude, currentlongitude, originLat, originLon, results);
float distanceInMeters = results[0];
return distanceInMeters;
}
//################################################################## ^^^^ DB Code ^^^^ #############################################################################
//#####################################################################################################################################################################
//TODO @Patrick: Ist backupVonAltemCode noch relevanter Code wenn Viration und das Schreiben in die Datenbank passt und synchron abläuft? Falls nichts relevant, können wir das ja löschen ;)
public void backupVonAltemCode (DataSnapshot data)
{
/*
//####### Auslesen für boolean-Werte #######:
int i = 1;
String vibrationString = data.child("overviewnodes").child("IDG").child("vibration").getValue().toString();
String amplitudeString = data.child("overviewnodes").child("IDG").child("amplitude").getValue().toString();
boolean vibration;
if(vibrationString.equals("true")){
vibration = true;
}else{
vibration = false;
}
int amplitude = Integer.parseInt(amplitudeString);
// Workaround beseiteigen: hier wird immer davon ausgegangen, dass auslösendes Gerät die ID 1 besitzt
if(vibration == true && i == 1)
{
float distance = distance(currentLocation.getLatitude(), currentLocation.getLongitude(),breitengrad,laengengrad);
long delay = getTimeStampDifference(distance);
setVibrationTimer(delay,1000,amplitude);
}
*/
}
//TODO @Patrick: Ist getTimeStampDifference noch relevanter Code wenn Viration und das Schreiben in die Datenbank passt und synchron abläuft? Falls nichts relevant, können wir das ja löschen ;)
private long getTimeStampDifference(float distance)
{
long diff= 0;
if (distance>0)
{
diff = (long)Math.round(1/(EARTHQUAKE_VELOCITY/distance));
}
return diff;
}
}
@@ -1,28 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".EarthquakeMapsActivity"
android:paddingTop="?attr/actionBarSize">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/shake_your_smartphone_for_a_earthquake"
android:layout_centerHorizontal="true"
android:id="@+id/txtEarthquake"/>
<androidx.fragment.app.FragmentContainerView xmlns:map="http://schemas.android.com/apk/res-auto"
android:layout_below="@+id/txtEarthquake"
android:id="@+id/map"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="50dp"
tools:context=".EarthquakeMapsActivity" />
</RelativeLayout>
-52
View File
@@ -1,52 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/btnEarthquake"
android:text="@string/generate_earthquake"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/btnSensor"
android:text="@string/be_a_sensor"
android:layout_centerHorizontal="true"
android:layout_below="@id/btnEarthquake"/>
<Button
android:id="@+id/buttonDatenBankMuster"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/btnSensor"
android:layout_centerHorizontal="true"
android:layout_marginTop="50dp"
android:text="@string/start_mit_vordefinierter_db" />
<Button
android:id="@+id/buttonDatenBankLeeren"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/buttonDatenBankMuster"
android:layout_centerHorizontal="true"
android:text="@string/start_mit_leeren_db" />
<Button
android:id="@+id/buttonReset"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/buttonDatenBankLeeren"
android:layout_centerHorizontal="true"
android:text="@string/weitermachen_buttonreset" />
</RelativeLayout>
+15
View File
@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".map">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Map"
android:id="@+id/btnMap"/>
</androidx.constraintlayout.widget.ConstraintLayout>
@@ -1,27 +1,16 @@
<?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: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">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Timer till vibration"
android:layout_centerHorizontal="true"
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: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=".MapsActivity" />
</RelativeLayout> </RelativeLayout>
Binary file not shown.

Before

Width:  |  Height:  |  Size: 91 KiB

+1 -1
View File
@@ -1,6 +1,6 @@
<resources xmlns:tools="http://schemas.android.com/tools"> <resources xmlns:tools="http://schemas.android.com/tools">
<!-- Base application theme. --> <!-- Base application theme. -->
<style name="Theme.Schockwelle" parent="Theme.MaterialComponents.DayNight.DarkActionBar"> <style name="Theme.Maps0123" parent="Theme.MaterialComponents.DayNight.DarkActionBar">
<!-- Primary brand color. --> <!-- Primary brand color. -->
<item name="colorPrimary">@color/purple_200</item> <item name="colorPrimary">@color/purple_200</item>
<item name="colorPrimaryVariant">@color/purple_700</item> <item name="colorPrimaryVariant">@color/purple_700</item>
+2 -15
View File
@@ -1,17 +1,4 @@
<resources> <resources>
<string name="app_name">Schockwelle</string> <string name="app_name">maps0123</string>
<string name="title_activity_earthquake_maps">Map</string> <string name="title_activity_maps">Map</string>
<string name="title_activity_sensor_maps">Map</string>
<string name="be_a_sensor">Be a Sensor</string>
<string name="generate_earthquake">Generate Earthquake</string>
<string name="buttontest">ButtonTest</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">Mit voller DB starten</string>
<string name="universalertestbutton">UniversalerTestButton</string>
<string name="weitermachen">Weitermachen</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_leeren_db">Start mit Leeren DB</string>
<string name="weitermachen_buttonreset">Weitermachen - Buttonreset</string>
</resources> </resources>
+1 -1
View File
@@ -1,6 +1,6 @@
<resources xmlns:tools="http://schemas.android.com/tools"> <resources xmlns:tools="http://schemas.android.com/tools">
<!-- Base application theme. --> <!-- Base application theme. -->
<style name="Theme.Schockwelle" parent="Theme.MaterialComponents.DayNight.DarkActionBar"> <style name="Theme.Maps0123" parent="Theme.MaterialComponents.DayNight.DarkActionBar">
<!-- Primary brand color. --> <!-- Primary brand color. -->
<item name="colorPrimary">@color/purple_500</item> <item name="colorPrimary">@color/purple_500</item>
<item name="colorPrimaryVariant">@color/purple_700</item> <item name="colorPrimaryVariant">@color/purple_700</item>
@@ -1,4 +1,20 @@
<resources> <resources>
<!--
TODO: Before you release your application, you need a Google Maps API key.
To do this, you can either add your release key credentials to your existing
key, or create a new key.
Note that this file specifies the API key for the release build target.
If you have previously set up a key for the debug target with the debug signing certificate,
you will also need to set up a key for your release certificate.
Follow the directions here:
https://developers.google.com/maps/documentation/android/signup
Once you have your key (it starts with "AIza"), replace the "google_maps_key"
string in this file.
-->
<string name="google_maps_key" templateMergeStrategy="preserve" translatable="false">YOUR_KEY_HERE</string> <string name="google_maps_key" templateMergeStrategy="preserve" translatable="false">YOUR_KEY_HERE</string>
</resources> </resources>
@@ -1,4 +1,4 @@
package de.edotzlaff.schockwelle; package de.edotzlaff.maps0123;
import org.junit.Test; import org.junit.Test;
+1 -2
View File
@@ -5,8 +5,7 @@ buildscript {
jcenter() jcenter()
} }
dependencies { dependencies {
classpath 'com.android.tools.build:gradle:4.2.1' classpath "com.android.tools.build:gradle:4.1.3"
classpath 'com.google.gms:google-services:4.3.8'
// NOTE: Do not place your application dependencies here; they belong // NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files // in the individual module build.gradle files
+2 -2
View File
@@ -1,6 +1,6 @@
#Thu Jun 17 12:39:35 CEST 2021 #Thu Jun 10 16:33:45 CEST 2021
distributionBase=GRADLE_USER_HOME distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.7.1-all.zip distributionUrl=https\://services.gradle.org/distributions/gradle-6.5-bin.zip
+1 -1
View File
@@ -1,2 +1,2 @@
include ':app' include ':app'
rootProject.name = "Schockwelle" rootProject.name = "maps0123"