Dateien hochladen nach „app/src/main/java/de/edotzlaff/schockwelle“

This commit is contained in:
Aron Abdulajev 2021-06-20 19:27:36 +00:00
parent 903664503a
commit d7addc222d

View File

@ -1,418 +1,418 @@
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.core.app.ActivityCompat;
import androidx.core.content.ContextCompat; import androidx.core.content.ContextCompat;
import androidx.fragment.app.FragmentActivity; import androidx.fragment.app.FragmentActivity;
import com.google.android.gms.location.FusedLocationProviderClient; import com.google.android.gms.location.FusedLocationProviderClient;
import com.google.android.gms.location.LocationServices; import com.google.android.gms.location.LocationServices;
import com.google.android.gms.maps.CameraUpdateFactory; import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap; import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.OnMapReadyCallback; import com.google.android.gms.maps.OnMapReadyCallback;
import com.google.android.gms.maps.SupportMapFragment; import com.google.android.gms.maps.SupportMapFragment;
import com.google.android.gms.maps.model.LatLng; import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.MarkerOptions; import com.google.android.gms.maps.model.MarkerOptions;
import com.google.android.gms.tasks.OnCompleteListener; import com.google.android.gms.tasks.OnCompleteListener;
import com.google.android.gms.tasks.Task; import com.google.android.gms.tasks.Task;
import com.google.firebase.database.DataSnapshot; import com.google.firebase.database.DataSnapshot;
import com.google.firebase.database.DatabaseError; import com.google.firebase.database.DatabaseError;
import com.google.firebase.database.DatabaseReference; import com.google.firebase.database.DatabaseReference;
import com.google.firebase.database.FirebaseDatabase; import com.google.firebase.database.FirebaseDatabase;
import com.google.firebase.database.ValueEventListener; import com.google.firebase.database.ValueEventListener;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.util.Calendar; import java.util.Calendar;
import java.util.Date; import java.util.Date;
import java.util.Objects; import java.util.Objects;
public class EarthquakeMapsActivity extends FragmentActivity implements OnMapReadyCallback { public class EarthquakeMapsActivity extends FragmentActivity implements OnMapReadyCallback {
private static final String TAG = "MainActivity"; private static final String TAG = "MainActivity";
private static final String FINE_LOCATION = Manifest.permission.ACCESS_FINE_LOCATION; private static final String FINE_LOCATION = Manifest.permission.ACCESS_FINE_LOCATION;
private static final int LOCATION_PERMISSION_REQUEST_CODE = 1234; private static final int LOCATION_PERMISSION_REQUEST_CODE = 1234;
private Boolean mLocationPermissionsGranted = false; private Boolean mLocationPermissionsGranted = false;
private GoogleMap mMap; private GoogleMap mMap;
private FusedLocationProviderClient mFusedLocationProviderClient; private FusedLocationProviderClient mFusedLocationProviderClient;
Long currentTime; Long currentTime;
Location currentLocation; Location currentLocation;
private DatabaseReference mDatenbank; private DatabaseReference mDatenbank;
private double breitengrad; private double breitengrad;
private double laengengrad; private double laengengrad;
private boolean useOwnGPS; private boolean useOwnGPS;
private int indexID = 1; private int indexID = 1;
//########################################################################################################################################################################## //##########################################################################################################################################################################
//################################################################## vvv ShakeParameter vvv ############################################################################## //################################################################## vvv ShakeParameter vvv ##############################################################################
private SensorManager mSensorManager; private SensorManager mSensorManager;
private static final float mUpperThreshold = 10.5f; // für Emulator auf 1.5 setzen private static final float mUpperThreshold = 10.5f; // für Emulator auf 1.5 setzen
private static final float mLowerThreshold = 5.5f; // für Emulator auf 0.5 setzen private static final float mLowerThreshold = 5.5f; // für Emulator auf 0.5 setzen
private static final long mShakeDetectionLockTimeMicroSeconds = 10000; private static final long mShakeDetectionLockTimeMicroSeconds = 10000;
private float mAccel; private float mAccel;
private float mAccelCurrent; private float mAccelCurrent;
private float mAccelLast; private float mAccelLast;
private boolean mShakeDetectionIsActive = false; private boolean mShakeDetectionIsActive = false;
private boolean mShakeDetected = false; private boolean mShakeDetected = false;
//private boolean allowShakeEvent = true; //private boolean allowShakeEvent = true;
//################################################################## ^^^^ ShakeParameter ^^^^ ############################################################################ //################################################################## ^^^^ ShakeParameter ^^^^ ############################################################################
//########################################################################################################################################################################## //##########################################################################################################################################################################
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
setContentView(R.layout.activity_earthquake_maps); setContentView(R.layout.activity_earthquake_maps);
getDataBaseValuesNoListener(); getDataBaseValuesNoListener();
sensorManagementInit(); sensorManagementInit();
getLocationPermission(); getLocationPermission();
} }
//##################################################################################################################################################################### //#####################################################################################################################################################################
//################################################################## vvv ShakeCode vvv ############################################################################## //################################################################## vvv ShakeCode vvv ##############################################################################
private void sensorManagementInit() private void sensorManagementInit()
{ {
TextView txtEarthquake = (TextView) findViewById(R.id.txtEarthquake); TextView txtEarthquake = (TextView) findViewById(R.id.txtEarthquake);
mSensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE); mSensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE);
Objects.requireNonNull(mSensorManager).registerListener(mSensorListener, mSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER), SensorManager.SENSOR_DELAY_NORMAL); Objects.requireNonNull(mSensorManager).registerListener(mSensorListener, mSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER), SensorManager.SENSOR_DELAY_NORMAL);
mAccel = 1f; mAccel = 1f;
mAccelCurrent = SensorManager.GRAVITY_EARTH; mAccelCurrent = SensorManager.GRAVITY_EARTH;
mAccelLast = SensorManager.GRAVITY_EARTH; mAccelLast = SensorManager.GRAVITY_EARTH;
mShakeDetectionIsActive = true; mShakeDetectionIsActive = true;
mShakeDetected = false; mShakeDetected = false;
} }
private CountDownTimer mLockTimer = new CountDownTimer(mShakeDetectionLockTimeMicroSeconds, 1000) private CountDownTimer mLockTimer = new CountDownTimer(mShakeDetectionLockTimeMicroSeconds, 1000)
{ {
public void onTick(long millisUntilFinished) { public void onTick(long millisUntilFinished) {
((TextView) findViewById(R.id.txtEarthquake)).setText("Earthquake started! Detection locked for " + millisUntilFinished / 1000 + " s"); ((TextView) findViewById(R.id.txtEarthquake)).setText("Earthquake started! Detection locked for " + millisUntilFinished / 1000 + " s");
} }
public void onFinish() { public void onFinish() {
mShakeDetectionIsActive = true; mShakeDetectionIsActive = true;
mShakeDetected = false; mShakeDetected = false;
Toast.makeText(getApplicationContext(), "Shake Detection unlocked", Toast.LENGTH_SHORT).show(); Toast.makeText(getApplicationContext(), "Shake Detection unlocked", Toast.LENGTH_SHORT).show();
( (TextView) findViewById(R.id.txtEarthquake)).setText("Shake your Smartphone for an Earthquake"); ( (TextView) findViewById(R.id.txtEarthquake)).setText("Shake your Smartphone for an Earthquake");
} }
}; };
private final SensorEventListener mSensorListener = new SensorEventListener() { private final SensorEventListener mSensorListener = new SensorEventListener() {
@Override @Override
public void onSensorChanged(SensorEvent event) { public void onSensorChanged(SensorEvent event) {
float x = event.values[0]; float x = event.values[0];
float y = event.values[1]; float y = event.values[1];
float z = event.values[2]; float z = event.values[2];
mAccelLast = mAccelCurrent; mAccelLast = mAccelCurrent;
mAccelCurrent = (float) Math.sqrt((double) (x * x + y * y + z * z)); mAccelCurrent = (float) Math.sqrt((double) (x * x + y * y + z * z));
float delta = mAccelCurrent - mAccelLast; float delta = mAccelCurrent - mAccelLast;
mAccel = mAccel * 0.9f + delta; mAccel = mAccel * 0.9f + delta;
// Log.d(TAG,"mAccel: "+ mAccel); // Log.d(TAG,"mAccel: "+ mAccel);
if (mShakeDetectionIsActive) { if (mShakeDetectionIsActive) {
if(Math.abs(mAccel) > mUpperThreshold) { if(Math.abs(mAccel) > mUpperThreshold) {
new CountDownTimer(50, 10) { new CountDownTimer(50, 10) {
public void onTick(long millisUntilFinished) { public void onTick(long millisUntilFinished) {
if (Math.abs(mAccel) > mUpperThreshold) { if (Math.abs(mAccel) > mUpperThreshold) {
mShakeDetectionIsActive = false; mShakeDetectionIsActive = false;
} else if (Math.abs(mAccel) < mLowerThreshold) { } else if (Math.abs(mAccel) < mLowerThreshold) {
mShakeDetectionIsActive = true; mShakeDetectionIsActive = true;
this.cancel(); this.cancel();
} }
} }
public void onFinish() { public void onFinish() {
if (Math.abs(mAccel) > mUpperThreshold) { if (Math.abs(mAccel) > mUpperThreshold) {
mShakeDetectionIsActive = false; mShakeDetectionIsActive = false;
mShakeDetected = true; mShakeDetected = true;
Toast.makeText(getApplicationContext(), "Shake event detected", Toast.LENGTH_SHORT).show(); Toast.makeText(getApplicationContext(), "Shake event detected", Toast.LENGTH_SHORT).show();
writeEarthquakeToDatabase(); writeEarthquakeToDatabase();
mLockTimer.start(); mLockTimer.start();
} else { } else {
mShakeDetectionIsActive = true; mShakeDetectionIsActive = true;
mShakeDetected = false; mShakeDetected = false;
} }
} }
}.start(); }.start();
} }
} }
} }
@Override @Override
public void onAccuracyChanged(Sensor sensor, int accuracy) { public void onAccuracyChanged(Sensor sensor, int accuracy) {
} }
}; };
private void writeEarthquakeToDatabase() private void writeEarthquakeToDatabase()
{ {
setDataBaseValues(); setDataBaseValues();
} }
@Override @Override
protected void onResume() { protected void onResume() {
mSensorManager.registerListener(mSensorListener, mSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER), mSensorManager.registerListener(mSensorListener, mSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER),
SensorManager.SENSOR_DELAY_NORMAL); SensorManager.SENSOR_DELAY_NORMAL);
super.onResume(); super.onResume();
} }
@Override @Override
protected void onPause() { protected void onPause() {
mSensorManager.unregisterListener(mSensorListener); mSensorManager.unregisterListener(mSensorListener);
super.onPause(); super.onPause();
} }
//################################################################## ^^^^ ShakeCode ^^^^ ############################################################################ //################################################################## ^^^^ ShakeCode ^^^^ ############################################################################
//##################################################################################################################################################################### //#####################################################################################################################################################################
//##################################################################################################################################################################### //#####################################################################################################################################################################
//################################################################## vvv GPS Code vvv ############################################################################### //################################################################## vvv GPS Code vvv ###############################################################################
private void getLocationPermission() { private void getLocationPermission() {
String[] permissions = {Manifest.permission.ACCESS_FINE_LOCATION}; String[] permissions = {Manifest.permission.ACCESS_FINE_LOCATION};
if (ContextCompat.checkSelfPermission(this.getApplicationContext(), FINE_LOCATION) == PackageManager.PERMISSION_GRANTED) { if (ContextCompat.checkSelfPermission(this.getApplicationContext(), FINE_LOCATION) == PackageManager.PERMISSION_GRANTED) {
mLocationPermissionsGranted = true; mLocationPermissionsGranted = true;
initMap(); initMap();
} else { } else {
ActivityCompat.requestPermissions(this, permissions, LOCATION_PERMISSION_REQUEST_CODE); ActivityCompat.requestPermissions(this, permissions, LOCATION_PERMISSION_REQUEST_CODE);
} }
} }
@Override @Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) { public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults); super.onRequestPermissionsResult(requestCode, permissions, grantResults);
mLocationPermissionsGranted = false; mLocationPermissionsGranted = false;
switch (requestCode) { switch (requestCode) {
case LOCATION_PERMISSION_REQUEST_CODE: { case LOCATION_PERMISSION_REQUEST_CODE: {
if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) { if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
mLocationPermissionsGranted = true; mLocationPermissionsGranted = true;
initMap(); //initalize or map initMap(); //initalize or map
} }
} }
} }
} }
private void initMap() { private void initMap() {
SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map); SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map);
mapFragment.getMapAsync(this); mapFragment.getMapAsync(this);
} }
@Override @Override
public void onMapReady(GoogleMap googleMap) { public void onMapReady(GoogleMap googleMap) {
Toast.makeText(this, "Map is ready", Toast.LENGTH_SHORT).show(); Toast.makeText(this, "Map is ready", Toast.LENGTH_SHORT).show();
mMap = googleMap; mMap = googleMap;
if (mLocationPermissionsGranted) { if (mLocationPermissionsGranted) {
getDeviceLocation(); getDeviceLocation();
if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION)
!= PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this,
Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) { Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
return; return;
} }
mMap.setMyLocationEnabled(true); mMap.setMyLocationEnabled(true);
} }
// Add a marker in Sydney and move the camera // Add a marker in Sydney and move the camera
//LatLng sydney = new LatLng(-34, 151); //LatLng sydney = new LatLng(-34, 151);
//mMap.addMarker(new MarkerOptions().position(sydney).title("Marker in Sydney")); //mMap.addMarker(new MarkerOptions().position(sydney).title("Marker in Sydney"));
//mMap.moveCamera(CameraUpdateFactory.newLatLng(sydney)); //mMap.moveCamera(CameraUpdateFactory.newLatLng(sydney));
} }
private void getDeviceLocation(){ private void getDeviceLocation(){
mFusedLocationProviderClient = LocationServices.getFusedLocationProviderClient(this); mFusedLocationProviderClient = LocationServices.getFusedLocationProviderClient(this);
try { try {
if (mLocationPermissionsGranted){ if (mLocationPermissionsGranted){
final Task location = mFusedLocationProviderClient.getLastLocation(); final Task location = mFusedLocationProviderClient.getLastLocation();
location.addOnCompleteListener(new OnCompleteListener() { location.addOnCompleteListener(new OnCompleteListener() {
@Override @Override
public void onComplete(@NonNull Task task) { public void onComplete(@NonNull Task task) {
if (task.isSuccessful()){ if (task.isSuccessful()){
currentLocation = (Location) task.getResult(); currentLocation = (Location) task.getResult();
//currentTime = Calendar.getInstance().getTimeInMillis(); //verschoben in setDataBaseValues //currentTime = Calendar.getInstance().getTimeInMillis(); //verschoben in setDataBaseValues
//Toast.makeText(EarthquakeMapsActivity.this, currentTime.toString(), Toast.LENGTH_SHORT).show(); //verschoben in setDataBaseValues //Toast.makeText(EarthquakeMapsActivity.this, currentTime.toString(), Toast.LENGTH_SHORT).show(); //verschoben in setDataBaseValues
if(useOwnGPS) if(useOwnGPS)
{ {
breitengrad = currentLocation.getLatitude(); breitengrad = currentLocation.getLatitude();
laengengrad = currentLocation.getLongitude(); laengengrad = currentLocation.getLongitude();
} }
currentLocation.setLatitude(breitengrad); currentLocation.setLatitude(breitengrad);
currentLocation.setLongitude(laengengrad); currentLocation.setLongitude(laengengrad);
moveCamera(new LatLng(currentLocation.getLatitude(), currentLocation.getLongitude()),15f); moveCamera(new LatLng(currentLocation.getLatitude(), currentLocation.getLongitude()),15f);
//setDataBaseValues(); //Wurde verschoben zu Methode writeEarthquakeToDatabase //setDataBaseValues(); //Wurde verschoben zu Methode writeEarthquakeToDatabase
} }
else{ else{
Toast.makeText(EarthquakeMapsActivity.this, "Current Location unavailable", Toast.LENGTH_SHORT).show(); Toast.makeText(EarthquakeMapsActivity.this, "Current Location unavailable", Toast.LENGTH_SHORT).show();
} }
} }
}); });
} }
}catch (SecurityException e){ }catch (SecurityException e){
Log.e(TAG,"Device Location not found" + e.getMessage()); Log.e(TAG,"Device Location not found" + e.getMessage());
} }
} }
private void moveCamera(LatLng latlng, float zoom){ private void moveCamera(LatLng latlng, float zoom){
Log.d(TAG,"Latitude: "+latlng.latitude+"Longitude: "+latlng.longitude); Log.d(TAG,"Latitude: "+latlng.latitude+"Longitude: "+latlng.longitude);
mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(latlng, zoom)); mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(latlng, zoom));
} }
//################################################################## ^^^^ GPS Code ^^^^ ############################################################################# //################################################################## ^^^^ GPS Code ^^^^ #############################################################################
//##################################################################################################################################################################### //#####################################################################################################################################################################
//##################################################################################################################################################################### //#####################################################################################################################################################################
//################################################################## vvv Datenbank Code vvv ######################################################################### //################################################################## vvv Datenbank Code vvv #########################################################################
public void getDataBaseValuesNoListener() public void getDataBaseValuesNoListener()
{ {
mDatenbank = FirebaseDatabase.getInstance().getReference(); mDatenbank = FirebaseDatabase.getInstance().getReference();
mDatenbank.child("overviewAronTestetInDiesemAbschnitt").get().addOnCompleteListener(new OnCompleteListener<DataSnapshot>() { mDatenbank.child("overviewAronTestetInDiesemAbschnitt").get().addOnCompleteListener(new OnCompleteListener<DataSnapshot>() {
@Override @Override
public void onComplete(@NonNull Task<DataSnapshot> task) { public void onComplete(@NonNull Task<DataSnapshot> task) {
if (!task.isSuccessful()) { if (!task.isSuccessful()) {
System.out.println("Datenbankfehler in getDataBaseValuesNoListener"); System.out.println("Datenbankfehler in getDataBaseValuesNoListener");
System.out.println("Error getting data: " + task.getException()); System.out.println("Error getting data: " + task.getException());
} }
else { else {
processDataBaseValues(task.getResult()); processDataBaseValues(task.getResult());
} }
} }
}); });
} }
public void processDataBaseValues (DataSnapshot data) public void processDataBaseValues (DataSnapshot data)
{ {
processDeviceIndex(data); processDeviceIndex(data);
processLocation(data); processLocation(data);
//processMessageDisplay(data); //processMessageDisplay(data);
} }
public void processDeviceIndex(DataSnapshot data) public void processDeviceIndex(DataSnapshot data)
{ {
for (int i = 1; i<=4; i++) for (int i = 1; i<=4; i++)
{ {
String androidid = data.child("IDG" + i).child("androidid").getValue().toString(); String androidid = data.child("IDG" + i).child("androidid").getValue().toString();
if(androidid.isEmpty()) if(androidid.isEmpty())
{ {
indexID = i; indexID = i;
break; break;
}else }else
{ {
continue; continue;
} }
} }
} }
public void processLocation(DataSnapshot data) public void processLocation(DataSnapshot data)
{ {
String breitengradString = data.child("IDG" + indexID).child("breitengrad").getValue().toString(); String breitengradString = data.child("IDG" + indexID).child("breitengrad").getValue().toString();
String laengengradString = data.child("IDG" + indexID).child("laengengrad").getValue().toString(); String laengengradString = data.child("IDG" + indexID).child("laengengrad").getValue().toString();
if(breitengradString.isEmpty() || laengengradString.isEmpty()) if(breitengradString.isEmpty() || laengengradString.isEmpty())
{ {
useOwnGPS = true; useOwnGPS = true;
}else{ }else{
useOwnGPS = false; useOwnGPS = false;
breitengrad = Double.parseDouble(breitengradString); breitengrad = Double.parseDouble(breitengradString);
laengengrad = Double.parseDouble(laengengradString); laengengrad = Double.parseDouble(laengengradString);
} }
} }
/* /*
public void processMessageDisplay(DataSnapshot data) public void processMessageDisplay(DataSnapshot data)
{ {
String vibrationString; String vibrationString;
String androidid; String androidid;
for (int i = 1; i<=4; i++) for (int i = 1; i<=4; i++)
{ {
androidid = data.child("overviewAronTestetInDiesemAbschnitt").child("IDG" + i).child("androidid").getValue().toString(); androidid = data.child("overviewAronTestetInDiesemAbschnitt").child("IDG" + i).child("androidid").getValue().toString();
vibrationString = data.child("overviewAronTestetInDiesemAbschnitt").child("IDG" + i).child("vibration").getValue().toString(); vibrationString = data.child("overviewAronTestetInDiesemAbschnitt").child("IDG" + i).child("vibration").getValue().toString();
if((!androidid.isEmpty()) && vibrationString.equals("true")) if((!androidid.isEmpty()) && vibrationString.equals("true"))
{ {
allowShakeEvent = false; allowShakeEvent = false;
} }
} }
} }
*/ */
public String getandroidid () public String getandroidid ()
{ {
return Settings.Secure.getString(this.getContentResolver(), Settings.Secure.ANDROID_ID); return Settings.Secure.getString(this.getContentResolver(), Settings.Secure.ANDROID_ID);
} }
public String getDeviceIpAdress () public String getDeviceIpAdress ()
{ {
WifiManager wm = (WifiManager) getApplicationContext().getSystemService(WIFI_SERVICE); WifiManager wm = (WifiManager) getApplicationContext().getSystemService(WIFI_SERVICE);
int ip = wm.getConnectionInfo().getIpAddress(); int ip = wm.getConnectionInfo().getIpAddress();
String ipAddress = String.format("%d.%d.%d.%d",(ip & 0xff),(ip >> 8 & 0xff),(ip >> 16 & 0xff), (ip >> 24 & 0xff)); String ipAddress = String.format("%d.%d.%d.%d",(ip & 0xff),(ip >> 8 & 0xff),(ip >> 16 & 0xff), (ip >> 24 & 0xff));
return ipAddress; return ipAddress;
} }
public void setDataBaseValues() public void setDataBaseValues()
{ {
mDatenbank = FirebaseDatabase.getInstance().getReference(); mDatenbank = FirebaseDatabase.getInstance().getReference();
mDatenbank.child("overviewAronTestetInDiesemAbschnitt").child("IDG" + indexID).child("ip").setValue(getDeviceIpAdress()); 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("vibration").setValue(true);
mDatenbank.child("overviewAronTestetInDiesemAbschnitt").child("IDG" + indexID).child("timestamp").setValue(Calendar.getInstance().getTimeInMillis()); mDatenbank.child("overviewAronTestetInDiesemAbschnitt").child("IDG" + indexID).child("timestamp").setValue(Calendar.getInstance().getTimeInMillis());
currentTime = Calendar.getInstance().getTimeInMillis(); currentTime = Calendar.getInstance().getTimeInMillis();
Toast.makeText(EarthquakeMapsActivity.this, currentTime.toString(), Toast.LENGTH_SHORT).show(); 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("breitengrad").setValue(breitengrad);
mDatenbank.child("overviewAronTestetInDiesemAbschnitt").child("IDG" + indexID).child("laengengrad").setValue(laengengrad); mDatenbank.child("overviewAronTestetInDiesemAbschnitt").child("IDG" + indexID).child("laengengrad").setValue(laengengrad);
mDatenbank.child("overviewAronTestetInDiesemAbschnitt").child("IDG" + indexID).child("amplitude").setValue(1001); mDatenbank.child("overviewAronTestetInDiesemAbschnitt").child("IDG" + indexID).child("amplitude").setValue(1001);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { 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("localdatetime").setValue(LocalDateTime.now().toString());
} }
mDatenbank.child("overviewAronTestetInDiesemAbschnitt").child("IDG" + indexID).child("androidid").setValue(getandroidid()); mDatenbank.child("overviewAronTestetInDiesemAbschnitt").child("IDG" + indexID).child("androidid").setValue(getandroidid());
} }
//################################################################## ^^^^ Datenbank Code ^^^^ ############################################################################# //################################################################## ^^^^ Datenbank Code ^^^^ #############################################################################
//########################################################################################################################################################################### //###########################################################################################################################################################################
} }
//Evtl. Redundanter Code //Evtl. Redundanter Code
/* /*
public void getDataBaseValues() public void getDataBaseValues()
{ {
mDatenbank = FirebaseDatabase.getInstance().getReference(); mDatenbank = FirebaseDatabase.getInstance().getReference();
mDatenbank.addValueEventListener(new ValueEventListener() { mDatenbank.addValueEventListener(new ValueEventListener() {
@Override @Override
public void onDataChange(@NonNull DataSnapshot snapshot) { public void onDataChange(@NonNull DataSnapshot snapshot) {
processDataBaseValues(snapshot); //Daten Snapshot, Übergabe an processDataBaseValues processDataBaseValues(snapshot); //Daten Snapshot, Übergabe an processDataBaseValues
} }
@Override @Override
public void onCancelled(@NonNull DatabaseError error) { public void onCancelled(@NonNull DatabaseError error) {
getDataBaseFailure(error); getDataBaseFailure(error);
} }
}); });
} }
public void getDataBaseFailure (DatabaseError error) public void getDataBaseFailure (DatabaseError error)
{ {
System.out.println("Datenbankfehler in gerDataBaseFailure"); System.out.println("Datenbankfehler in gerDataBaseFailure");
Log.w("Datenbankfehler", error.toException()); Log.w("Datenbankfehler", error.toException());
} }
*/ */