|
|
|
|
|
|
|
|
package de.edotzlaff.schockwelle;
|
|
|
package de.edotzlaff.schockwelle;
|
|
|
|
|
|
|
|
|
import androidx.annotation.NonNull;
|
|
|
import androidx.annotation.NonNull;
|
|
|
import androidx.annotation.RequiresApi;
|
|
|
|
|
|
import androidx.appcompat.app.AppCompatActivity;
|
|
|
|
|
|
import androidx.fragment.app.FragmentActivity;
|
|
|
import androidx.fragment.app.FragmentActivity;
|
|
|
|
|
|
|
|
|
import android.app.ActionBar;
|
|
|
|
|
|
import android.app.Dialog;
|
|
|
import android.app.Dialog;
|
|
|
import android.content.Intent;
|
|
|
import android.content.Intent;
|
|
|
import android.hardware.Sensor;
|
|
|
|
|
|
import android.net.wifi.WifiManager;
|
|
|
|
|
|
import android.os.Build;
|
|
|
|
|
|
import android.os.Bundle;
|
|
|
import android.os.Bundle;
|
|
|
import android.provider.Settings;
|
|
|
|
|
|
import android.util.Log;
|
|
|
import android.util.Log;
|
|
|
import android.view.View;
|
|
|
import android.view.View;
|
|
|
import android.widget.Button;
|
|
|
import android.widget.Button;
|
|
|
import android.widget.Toast;
|
|
|
import android.widget.Toast;
|
|
|
|
|
|
|
|
|
import com.google.android.gms.common.ConnectionResult;
|
|
|
import com.google.android.gms.common.ConnectionResult;
|
|
|
import com.google.android.gms.common.GoogleApiAvailability;
|
|
|
import com.google.android.gms.common.GoogleApiAvailability;
|
|
|
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.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 java.time.LocalDateTime;
|
|
|
|
|
|
import java.time.format.DateTimeFormatter;
|
|
|
|
|
|
import java.util.Calendar;
|
|
|
|
|
|
|
|
|
|
|
|
public class MainActivity extends FragmentActivity {
|
|
|
public class MainActivity extends FragmentActivity {
|
|
|
|
|
|
|
|
|
private static final String TAG = "MainActivity";
|
|
|
private static final String TAG = "MainActivity";
|
|
|
private static final int ERROR_DIALOG_REQUEST = 9001;
|
|
|
private static final int ERROR_DIALOG_REQUEST = 9001;
|
|
|
private DatabaseReference mDatenbank;
|
|
|
private DatabaseReference mDatenbank;
|
|
|
String android_id;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
@Override
|
|
|
protected void onCreate(Bundle savedInstanceState) {
|
|
|
protected void onCreate(Bundle savedInstanceState) {
|
|
|
|
|
|
|
|
|
return false;
|
|
|
return false;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
@RequiresApi(api = Build.VERSION_CODES.O)
|
|
|
|
|
|
public void deviceInitDataBase()
|
|
|
public void deviceInitDataBase()
|
|
|
{
|
|
|
{
|
|
|
mDatenbank = FirebaseDatabase.getInstance().getReference();
|
|
|
mDatenbank = FirebaseDatabase.getInstance().getReference();
|
|
|
|
|
|
|
|
|
mDatenbank.child("overviewnodes").child("IDG4").setValue(d4);
|
|
|
mDatenbank.child("overviewnodes").child("IDG4").setValue(d4);
|
|
|
mDatenbank.child("overviewnodes").child("IDG5").setValue(d4);
|
|
|
mDatenbank.child("overviewnodes").child("IDG5").setValue(d4);
|
|
|
mDatenbank.child("overviewnodes").child("IDG5").setValue(d5);
|
|
|
mDatenbank.child("overviewnodes").child("IDG5").setValue(d5);
|
|
|
//Nürnberg HBF: 49.4474136331757, 11.082661293035727
|
|
|
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
//Datenbank auslesen OHNE Listener. D.h. es werden Daten (snapshot) ausgelesen und kein Listener hinterlegt.
|
|
|
|
|
|
//Sollten sich danach Daten zu einem beliebigen Zeitpunkt in der DB ändern, wird die Funktion "onDataChange" NICHT erneut ausgelöst.
|
|
|
|
|
|
public void getDataBaseValuesNoListener()
|
|
|
public void getDataBaseValuesNoListener()
|
|
|
{
|
|
|
{
|
|
|
mDatenbank = FirebaseDatabase.getInstance().getReference();
|
|
|
mDatenbank = FirebaseDatabase.getInstance().getReference();
|
|
|
|
|
|
|
|
|
mDatenbank = FirebaseDatabase.getInstance().getReference().child("overviewnodes");
|
|
|
mDatenbank = FirebaseDatabase.getInstance().getReference().child("overviewnodes");
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
|
//Datenbank auslesen MIT Listener. D.h. es werden Daten (snapshot) ausgelesen und gleichzeitig ein Listener hinterlegt.
|
|
|
|
|
|
//Sollten sich danach Daten zu einem beliebigen Zeitpunkt in der DB ändern, wird die Funktion "onDataChange" erneut ausgelöst und wieder Daten (snapshot) ausgelesen.
|
|
|
|
|
|
public void getDataBaseValuesListener()
|
|
|
|
|
|
{
|
|
|
|
|
|
mDatenbank = FirebaseDatabase.getInstance().getReference();
|
|
|
|
|
|
mDatenbank.addValueEventListener(new ValueEventListener() {
|
|
|
|
|
|
@Override
|
|
|
|
|
|
public void onDataChange(@NonNull DataSnapshot snapshot) {
|
|
|
|
|
|
//testProcess(snapshot); //Daten - Snapshot, Übergabe an Methode processDataBaseValues
|
|
|
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
|
|
|
public void onCancelled(@NonNull DatabaseError error) {
|
|
|
|
|
|
getDataBaseFailure(error);
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
|
public void getDataBaseFailure (DatabaseError error)
|
|
|
|
|
|
{
|
|
|
|
|
|
System.out.println("Fehler");
|
|
|
|
|
|
Log.w("Datenbankfehler", error.toException());
|
|
|
|
|
|
}
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
|
@RequiresApi(api = Build.VERSION_CODES.O)
|
|
|
|
|
|
public void processDataBaseValues (DataSnapshot data)
|
|
|
|
|
|
{
|
|
|
|
|
|
for (int i = 1; i<=4; i++) //Für alle IDG 1-4 werden Werte ausgegeben
|
|
|
|
|
|
{
|
|
|
|
|
|
//####### Auslesen für String-Werte #######:
|
|
|
|
|
|
String ipAdresse = data.child("overviewnodes").child("IDG" + i).child("ip").getValue().toString();
|
|
|
|
|
|
|
|
|
|
|
|
//####### Auslesen für boolean-Werte #######:
|
|
|
|
|
|
String vibrationString = data.child("overviewnodes").child("IDG" + i).child("vibration").getValue().toString();
|
|
|
|
|
|
boolean vibration;
|
|
|
|
|
|
if(vibrationString == "true"){
|
|
|
|
|
|
vibration = true;
|
|
|
|
|
|
}else{
|
|
|
|
|
|
vibration = false;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//####### Auslesen für double-Werte #######:
|
|
|
|
|
|
String breitengradString = data.child("overviewnodes").child("IDG" + i).child("breitengrad").getValue().toString();
|
|
|
|
|
|
String laengengradString = data.child("overviewnodes").child("IDG" + i).child("laengengrad").getValue().toString();
|
|
|
|
|
|
double breitengrad = Double.parseDouble(breitengradString);
|
|
|
|
|
|
double laengengrad = Double.parseDouble(laengengradString);
|
|
|
|
|
|
|
|
|
|
|
|
//####### Auslesen für long-Werte #######:
|
|
|
|
|
|
String timestampString = data.child("overviewnodes").child("IDG" + i).child("timestamp").getValue().toString();
|
|
|
|
|
|
long timestamp = Long.parseLong(timestampString);
|
|
|
|
|
|
|
|
|
|
|
|
//####### Auslesen für ing-Werte #######:
|
|
|
|
|
|
String amplitudeString = data.child("overviewnodes").child("IDG" + i).child("amplitude").getValue().toString();
|
|
|
|
|
|
int amplitude = Integer.parseInt(amplitudeString);
|
|
|
|
|
|
|
|
|
|
|
|
//####### Auslesen für LocalDateTime#######:
|
|
|
|
|
|
String localdatetimeString = data.child("overviewnodes").child("IDG" + i).child("localdatetime").getValue().toString();
|
|
|
|
|
|
DateTimeFormatter formatter = DateTimeFormatter.ISO_DATE_TIME;
|
|
|
|
|
|
LocalDateTime localdatetime = LocalDateTime.parse(localdatetimeString, formatter);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
*/ |
|
|
|