|
|
|
|
|
|
|
|
package de.edotzlaff.schockwelle; |
|
|
|
|
|
|
|
|
|
|
|
import androidx.annotation.NonNull; |
|
|
|
|
|
import androidx.annotation.RequiresApi; |
|
|
|
|
|
import androidx.appcompat.app.AppCompatActivity; |
|
|
|
|
|
import androidx.fragment.app.FragmentActivity; |
|
|
|
|
|
|
|
|
|
|
|
import android.app.ActionBar; |
|
|
|
|
|
import android.app.Dialog; |
|
|
|
|
|
import android.content.Intent; |
|
|
|
|
|
import android.hardware.Sensor; |
|
|
|
|
|
import android.os.Build; |
|
|
|
|
|
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.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.format.DateTimeFormatter; |
|
|
|
|
|
import java.util.Calendar; |
|
|
|
|
|
|
|
|
|
|
|
public class MainActivity extends FragmentActivity { |
|
|
|
|
|
|
|
|
|
|
|
private static final String TAG = "MainActivity"; |
|
|
|
|
|
private static final int ERROR_DIALOG_REQUEST = 9001; |
|
|
|
|
|
private DatabaseReference mDatenbank; |
|
|
|
|
|
String android_id; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
protected void onCreate(Bundle savedInstanceState) { |
|
|
|
|
|
super.onCreate(savedInstanceState); |
|
|
|
|
|
setContentView(R.layout.activity_main); |
|
|
|
|
|
|
|
|
|
|
|
if (isServiceOK()){ |
|
|
|
|
|
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(false); |
|
|
|
|
|
btnEarthquake.setOnClickListener(new View.OnClickListener() { |
|
|
|
|
|
@Override |
|
|
|
|
|
public void onClick(View v) { |
|
|
|
|
|
Intent intent = new Intent(MainActivity.this, EarthquakeMapsActivity.class); |
|
|
|
|
|
btnEarthquake.setEnabled(false); |
|
|
|
|
|
btnSensor.setEnabled(false); |
|
|
|
|
|
startActivity(intent); |
|
|
|
|
|
} |
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
btnSensor.setEnabled(false); |
|
|
|
|
|
btnSensor.setOnClickListener(new View.OnClickListener() { |
|
|
|
|
|
@Override |
|
|
|
|
|
public void onClick(View v) { |
|
|
|
|
|
Intent intent = new Intent(MainActivity.this, SensorMapsActivity.class); |
|
|
|
|
|
btnSensor.setEnabled(false); |
|
|
|
|
|
btnEarthquake.setEnabled(false); |
|
|
|
|
|
startActivity(intent); |
|
|
|
|
|
} |
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
btnMuster.setOnClickListener(new View.OnClickListener() { |
|
|
|
|
|
@Override |
|
|
|
|
|
public void onClick(View v) { |
|
|
|
|
|
btnEarthquake.setEnabled(true); |
|
|
|
|
|
btnSensor.setEnabled(true); |
|
|
|
|
|
btnLeer.setEnabled(false); |
|
|
|
|
|
btnMuster.setEnabled(false); |
|
|
|
|
|
btnReset.setEnabled(true); |
|
|
|
|
|
deviceInitDataBase(); |
|
|
|
|
|
} |
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
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(false); |
|
|
|
|
|
datenBankLeeren(); |
|
|
|
|
|
} |
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
btnReset.setEnabled(false); |
|
|
|
|
|
btnReset.setOnClickListener(new View.OnClickListener() { |
|
|
|
|
|
@Override |
|
|
|
|
|
public void onClick(View v) { |
|
|
|
|
|
getDataBaseValuesNoListener(); |
|
|
|
|
|
btnEarthquake.setEnabled(true); |
|
|
|
|
|
btnSensor.setEnabled(true); |
|
|
|
|
|
btnMuster.setEnabled(true); |
|
|
|
|
|
btnLeer.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("10.00.00.000", false, Calendar.getInstance().getTimeInMillis(), 52.51624237821577, 13.37683380067744, 1000, LocalDateTime.now().toString(), ""); //Berlin 52.51624237821577, 13.37683380067744 |
|
|
|
|
|
Devices d2 = new Devices("20.00.00.000", false, Calendar.getInstance().getTimeInMillis(), 48.7560280895443, 11.425157702952347, 200, LocalDateTime.now().toString(),""); //Ingolstadt 48.7560280895443, 11.425157702952347 |
|
|
|
|
|
Devices d3 = new Devices("30.00.00.000", false, Calendar.getInstance().getTimeInMillis(), 48.16958655466396, 11.617418429524394, 30, LocalDateTime.now().toString(),""); //München 48.16958655466396, 11.617418429524394 |
|
|
|
|
|
Devices d4 = new Devices("40.00.00.000", false, Calendar.getInstance().getTimeInMillis(), 45.55620112204013, 12.342516140205387, 4, LocalDateTime.now().toString(),""); //Venedig 45.55620112204013, 12.342516140205387 |
|
|
|
|
|
mDatenbank.child("overviewAronTestetInDiesemAbschnitt").child("IDG1").setValue(d1); |
|
|
|
|
|
mDatenbank.child("overviewAronTestetInDiesemAbschnitt").child("IDG2").setValue(d2); |
|
|
|
|
|
mDatenbank.child("overviewAronTestetInDiesemAbschnitt").child("IDG3").setValue(d3); |
|
|
|
|
|
mDatenbank.child("overviewAronTestetInDiesemAbschnitt").child("IDG4").setValue(d4); |
|
|
|
|
|
|
|
|
|
|
|
//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() |
|
|
|
|
|
{ |
|
|
|
|
|
mDatenbank = FirebaseDatabase.getInstance().getReference(); |
|
|
|
|
|
mDatenbank.child("overviewAronTestetInDiesemAbschnitt").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<=4; i++) |
|
|
|
|
|
{ |
|
|
|
|
|
mDatenbank.child("overviewAronTestetInDiesemAbschnitt").child("IDG" + i).child("ip").setValue(""); |
|
|
|
|
|
mDatenbank.child("overviewAronTestetInDiesemAbschnitt").child("IDG" + i).child("vibration").setValue(false); |
|
|
|
|
|
mDatenbank.child("overviewAronTestetInDiesemAbschnitt").child("IDG" + i).child("timestamp").setValue(""); |
|
|
|
|
|
mDatenbank.child("overviewAronTestetInDiesemAbschnitt").child("IDG" + i).child("breitengrad").setValue(""); |
|
|
|
|
|
mDatenbank.child("overviewAronTestetInDiesemAbschnitt").child("IDG" + i).child("laengengrad").setValue(""); |
|
|
|
|
|
mDatenbank.child("overviewAronTestetInDiesemAbschnitt").child("IDG" + i).child("amplitude").setValue(""); |
|
|
|
|
|
mDatenbank.child("overviewAronTestetInDiesemAbschnitt").child("IDG" + i).child("localdatetime").setValue(""); |
|
|
|
|
|
mDatenbank.child("overviewAronTestetInDiesemAbschnitt").child("IDG" + i).child("androidid").setValue(""); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public void testProcess(DataSnapshot data) |
|
|
|
|
|
{ |
|
|
|
|
|
mDatenbank = FirebaseDatabase.getInstance().getReference().child("overviewAronTestetInDiesemAbschnitt"); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* |
|
|
|
|
|
//Datenbank auslesen MIT Listener. D.h. es werden Daten (snapshot) ausgelesen und gleichzeitig ein Listener hinterlegt. |
|
|
|
|
|
//Sollten sich danach Daten zu einem beliebigen Zeitpunkt in der DB ändern, wird die Funktion "onDataChange" erneut ausgelöst und wieder Daten (snapshot) ausgelesen. |
|
|
|
|
|
public void getDataBaseValuesListener() |
|
|
|
|
|
{ |
|
|
|
|
|
mDatenbank = FirebaseDatabase.getInstance().getReference(); |
|
|
|
|
|
mDatenbank.addValueEventListener(new ValueEventListener() { |
|
|
|
|
|
@Override |
|
|
|
|
|
public void onDataChange(@NonNull DataSnapshot snapshot) { |
|
|
|
|
|
//testProcess(snapshot); //Daten - Snapshot, Übergabe an Methode processDataBaseValues |
|
|
|
|
|
} |
|
|
|
|
|
@Override |
|
|
|
|
|
public void onCancelled(@NonNull DatabaseError error) { |
|
|
|
|
|
getDataBaseFailure(error); |
|
|
|
|
|
} |
|
|
|
|
|
}); |
|
|
|
|
|
} |
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
|
|
|
|
/* |
|
|
|
|
|
public void getDataBaseFailure (DatabaseError error) |
|
|
|
|
|
{ |
|
|
|
|
|
System.out.println("Fehler"); |
|
|
|
|
|
Log.w("Datenbankfehler", error.toException()); |
|
|
|
|
|
} |
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
|
|
|
|
/* |
|
|
|
|
|
@RequiresApi(api = Build.VERSION_CODES.O) |
|
|
|
|
|
public void processDataBaseValues (DataSnapshot data) |
|
|
|
|
|
{ |
|
|
|
|
|
for (int i = 1; i<=4; i++) //Für alle IDG 1-4 werden Werte ausgegeben |
|
|
|
|
|
{ |
|
|
|
|
|
//####### Auslesen für String-Werte #######: |
|
|
|
|
|
String ipAdresse = data.child("overviewAronTestetInDiesemAbschnitt").child("IDG" + i).child("ip").getValue().toString(); |
|
|
|
|
|
|
|
|
|
|
|
//####### Auslesen für boolean-Werte #######: |
|
|
|
|
|
String vibrationString = data.child("overviewAronTestetInDiesemAbschnitt").child("IDG" + i).child("vibration").getValue().toString(); |
|
|
|
|
|
boolean vibration; |
|
|
|
|
|
if(vibrationString == "true"){ |
|
|
|
|
|
vibration = true; |
|
|
|
|
|
}else{ |
|
|
|
|
|
vibration = false; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
//####### Auslesen für double-Werte #######: |
|
|
|
|
|
String breitengradString = data.child("overviewAronTestetInDiesemAbschnitt").child("IDG" + i).child("breitengrad").getValue().toString(); |
|
|
|
|
|
String laengengradString = data.child("overviewAronTestetInDiesemAbschnitt").child("IDG" + i).child("laengengrad").getValue().toString(); |
|
|
|
|
|
double breitengrad = Double.parseDouble(breitengradString); |
|
|
|
|
|
double laengengrad = Double.parseDouble(laengengradString); |
|
|
|
|
|
|
|
|
|
|
|
//####### Auslesen für long-Werte #######: |
|
|
|
|
|
String timestampString = data.child("overviewAronTestetInDiesemAbschnitt").child("IDG" + i).child("timestamp").getValue().toString(); |
|
|
|
|
|
long timestamp = Long.parseLong(timestampString); |
|
|
|
|
|
|
|
|
|
|
|
//####### Auslesen für ing-Werte #######: |
|
|
|
|
|
String amplitudeString = data.child("overviewAronTestetInDiesemAbschnitt").child("IDG" + i).child("amplitude").getValue().toString(); |
|
|
|
|
|
int amplitude = Integer.parseInt(amplitudeString); |
|
|
|
|
|
|
|
|
|
|
|
//####### Auslesen für LocalDateTime#######: |
|
|
|
|
|
String localdatetimeString = data.child("overviewAronTestetInDiesemAbschnitt").child("IDG" + i).child("localdatetime").getValue().toString(); |
|
|
|
|
|
DateTimeFormatter formatter = DateTimeFormatter.ISO_DATE_TIME; |
|
|
|
|
|
LocalDateTime localdatetime = LocalDateTime.parse(localdatetimeString, formatter); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
package de.edotzlaff.schockwelle;
|
|
|
|
|
|
|
|
|
|
|
|
import androidx.annotation.NonNull;
|
|
|
|
|
|
import androidx.annotation.RequiresApi;
|
|
|
|
|
|
import androidx.appcompat.app.AppCompatActivity;
|
|
|
|
|
|
import androidx.fragment.app.FragmentActivity;
|
|
|
|
|
|
|
|
|
|
|
|
import android.app.ActionBar;
|
|
|
|
|
|
import android.app.Dialog;
|
|
|
|
|
|
import android.content.Intent;
|
|
|
|
|
|
import android.hardware.Sensor;
|
|
|
|
|
|
import android.os.Build;
|
|
|
|
|
|
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.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.format.DateTimeFormatter;
|
|
|
|
|
|
import java.util.Calendar;
|
|
|
|
|
|
|
|
|
|
|
|
public class MainActivity extends FragmentActivity {
|
|
|
|
|
|
|
|
|
|
|
|
private static final String TAG = "MainActivity";
|
|
|
|
|
|
private static final int ERROR_DIALOG_REQUEST = 9001;
|
|
|
|
|
|
private DatabaseReference mDatenbank;
|
|
|
|
|
|
String android_id;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
protected void onCreate(Bundle savedInstanceState) {
|
|
|
|
|
|
super.onCreate(savedInstanceState);
|
|
|
|
|
|
setContentView(R.layout.activity_main);
|
|
|
|
|
|
|
|
|
|
|
|
if (isServiceOK()){
|
|
|
|
|
|
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(false);
|
|
|
|
|
|
btnEarthquake.setOnClickListener(new View.OnClickListener() {
|
|
|
|
|
|
@Override
|
|
|
|
|
|
public void onClick(View v) {
|
|
|
|
|
|
Intent intent = new Intent(MainActivity.this, EarthquakeMapsActivity.class);
|
|
|
|
|
|
btnEarthquake.setEnabled(false);
|
|
|
|
|
|
btnSensor.setEnabled(false);
|
|
|
|
|
|
startActivity(intent);
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
btnSensor.setEnabled(false);
|
|
|
|
|
|
btnSensor.setOnClickListener(new View.OnClickListener() {
|
|
|
|
|
|
@Override
|
|
|
|
|
|
public void onClick(View v) {
|
|
|
|
|
|
Intent intent = new Intent(MainActivity.this, SensorMapsActivity.class);
|
|
|
|
|
|
btnSensor.setEnabled(false);
|
|
|
|
|
|
btnEarthquake.setEnabled(false);
|
|
|
|
|
|
startActivity(intent);
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
btnMuster.setOnClickListener(new View.OnClickListener() {
|
|
|
|
|
|
@Override
|
|
|
|
|
|
public void onClick(View v) {
|
|
|
|
|
|
btnEarthquake.setEnabled(true);
|
|
|
|
|
|
btnSensor.setEnabled(true);
|
|
|
|
|
|
btnLeer.setEnabled(false);
|
|
|
|
|
|
btnMuster.setEnabled(false);
|
|
|
|
|
|
btnReset.setEnabled(true);
|
|
|
|
|
|
deviceInitDataBase();
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
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(false);
|
|
|
|
|
|
datenBankLeeren();
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
btnReset.setEnabled(false);
|
|
|
|
|
|
btnReset.setOnClickListener(new View.OnClickListener() {
|
|
|
|
|
|
@Override
|
|
|
|
|
|
public void onClick(View v) {
|
|
|
|
|
|
getDataBaseValuesNoListener();
|
|
|
|
|
|
btnEarthquake.setEnabled(true);
|
|
|
|
|
|
btnSensor.setEnabled(true);
|
|
|
|
|
|
btnMuster.setEnabled(true);
|
|
|
|
|
|
btnLeer.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("10.00.00.000", false, Calendar.getInstance().getTimeInMillis(), 52.51624237821577, 13.37683380067744, 1000, LocalDateTime.now().toString(), ""); //Berlin 52.51624237821577, 13.37683380067744
|
|
|
|
|
|
Devices d2 = new Devices("20.00.00.000", false, Calendar.getInstance().getTimeInMillis(), 48.7560280895443, 11.425157702952347, 200, LocalDateTime.now().toString(),""); //Ingolstadt 48.7560280895443, 11.425157702952347
|
|
|
|
|
|
Devices d3 = new Devices("30.00.00.000", false, Calendar.getInstance().getTimeInMillis(), 48.16958655466396, 11.617418429524394, 30, LocalDateTime.now().toString(),""); //München 48.16958655466396, 11.617418429524394
|
|
|
|
|
|
Devices d4 = new Devices("40.00.00.000", false, Calendar.getInstance().getTimeInMillis(), 45.55620112204013, 12.342516140205387, 4, LocalDateTime.now().toString(),""); //Venedig 45.55620112204013, 12.342516140205387
|
|
|
|
|
|
mDatenbank.child("overviewAronTestetInDiesemAbschnitt").child("IDG1").setValue(d1);
|
|
|
|
|
|
mDatenbank.child("overviewAronTestetInDiesemAbschnitt").child("IDG2").setValue(d2);
|
|
|
|
|
|
mDatenbank.child("overviewAronTestetInDiesemAbschnitt").child("IDG3").setValue(d3);
|
|
|
|
|
|
mDatenbank.child("overviewAronTestetInDiesemAbschnitt").child("IDG4").setValue(d4);
|
|
|
|
|
|
|
|
|
|
|
|
//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()
|
|
|
|
|
|
{
|
|
|
|
|
|
mDatenbank = FirebaseDatabase.getInstance().getReference();
|
|
|
|
|
|
mDatenbank.child("overviewAronTestetInDiesemAbschnitt").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<=4; i++)
|
|
|
|
|
|
{
|
|
|
|
|
|
mDatenbank.child("overviewAronTestetInDiesemAbschnitt").child("IDG" + i).child("ip").setValue("");
|
|
|
|
|
|
mDatenbank.child("overviewAronTestetInDiesemAbschnitt").child("IDG" + i).child("vibration").setValue(false);
|
|
|
|
|
|
mDatenbank.child("overviewAronTestetInDiesemAbschnitt").child("IDG" + i).child("timestamp").setValue("");
|
|
|
|
|
|
mDatenbank.child("overviewAronTestetInDiesemAbschnitt").child("IDG" + i).child("breitengrad").setValue("");
|
|
|
|
|
|
mDatenbank.child("overviewAronTestetInDiesemAbschnitt").child("IDG" + i).child("laengengrad").setValue("");
|
|
|
|
|
|
mDatenbank.child("overviewAronTestetInDiesemAbschnitt").child("IDG" + i).child("amplitude").setValue("");
|
|
|
|
|
|
mDatenbank.child("overviewAronTestetInDiesemAbschnitt").child("IDG" + i).child("localdatetime").setValue("");
|
|
|
|
|
|
mDatenbank.child("overviewAronTestetInDiesemAbschnitt").child("IDG" + i).child("androidid").setValue("");
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void testProcess(DataSnapshot data)
|
|
|
|
|
|
{
|
|
|
|
|
|
mDatenbank = FirebaseDatabase.getInstance().getReference().child("overviewAronTestetInDiesemAbschnitt");
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
|
//Datenbank auslesen MIT Listener. D.h. es werden Daten (snapshot) ausgelesen und gleichzeitig ein Listener hinterlegt.
|
|
|
|
|
|
//Sollten sich danach Daten zu einem beliebigen Zeitpunkt in der DB ändern, wird die Funktion "onDataChange" erneut ausgelöst und wieder Daten (snapshot) ausgelesen.
|
|
|
|
|
|
public void getDataBaseValuesListener()
|
|
|
|
|
|
{
|
|
|
|
|
|
mDatenbank = FirebaseDatabase.getInstance().getReference();
|
|
|
|
|
|
mDatenbank.addValueEventListener(new ValueEventListener() {
|
|
|
|
|
|
@Override
|
|
|
|
|
|
public void onDataChange(@NonNull DataSnapshot snapshot) {
|
|
|
|
|
|
//testProcess(snapshot); //Daten - Snapshot, Übergabe an Methode processDataBaseValues
|
|
|
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
|
|
|
public void onCancelled(@NonNull DatabaseError error) {
|
|
|
|
|
|
getDataBaseFailure(error);
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
|
public void getDataBaseFailure (DatabaseError error)
|
|
|
|
|
|
{
|
|
|
|
|
|
System.out.println("Fehler");
|
|
|
|
|
|
Log.w("Datenbankfehler", error.toException());
|
|
|
|
|
|
}
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
|
@RequiresApi(api = Build.VERSION_CODES.O)
|
|
|
|
|
|
public void processDataBaseValues (DataSnapshot data)
|
|
|
|
|
|
{
|
|
|
|
|
|
for (int i = 1; i<=4; i++) //Für alle IDG 1-4 werden Werte ausgegeben
|
|
|
|
|
|
{
|
|
|
|
|
|
//####### Auslesen für String-Werte #######:
|
|
|
|
|
|
String ipAdresse = data.child("overviewAronTestetInDiesemAbschnitt").child("IDG" + i).child("ip").getValue().toString();
|
|
|
|
|
|
|
|
|
|
|
|
//####### Auslesen für boolean-Werte #######:
|
|
|
|
|
|
String vibrationString = data.child("overviewAronTestetInDiesemAbschnitt").child("IDG" + i).child("vibration").getValue().toString();
|
|
|
|
|
|
boolean vibration;
|
|
|
|
|
|
if(vibrationString == "true"){
|
|
|
|
|
|
vibration = true;
|
|
|
|
|
|
}else{
|
|
|
|
|
|
vibration = false;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//####### Auslesen für double-Werte #######:
|
|
|
|
|
|
String breitengradString = data.child("overviewAronTestetInDiesemAbschnitt").child("IDG" + i).child("breitengrad").getValue().toString();
|
|
|
|
|
|
String laengengradString = data.child("overviewAronTestetInDiesemAbschnitt").child("IDG" + i).child("laengengrad").getValue().toString();
|
|
|
|
|
|
double breitengrad = Double.parseDouble(breitengradString);
|
|
|
|
|
|
double laengengrad = Double.parseDouble(laengengradString);
|
|
|
|
|
|
|
|
|
|
|
|
//####### Auslesen für long-Werte #######:
|
|
|
|
|
|
String timestampString = data.child("overviewAronTestetInDiesemAbschnitt").child("IDG" + i).child("timestamp").getValue().toString();
|
|
|
|
|
|
long timestamp = Long.parseLong(timestampString);
|
|
|
|
|
|
|
|
|
|
|
|
//####### Auslesen für ing-Werte #######:
|
|
|
|
|
|
String amplitudeString = data.child("overviewAronTestetInDiesemAbschnitt").child("IDG" + i).child("amplitude").getValue().toString();
|
|
|
|
|
|
int amplitude = Integer.parseInt(amplitudeString);
|
|
|
|
|
|
|
|
|
|
|
|
//####### Auslesen für LocalDateTime#######:
|
|
|
|
|
|
String localdatetimeString = data.child("overviewAronTestetInDiesemAbschnitt").child("IDG" + i).child("localdatetime").getValue().toString();
|
|
|
|
|
|
DateTimeFormatter formatter = DateTimeFormatter.ISO_DATE_TIME;
|
|
|
|
|
|
LocalDateTime localdatetime = LocalDateTime.parse(localdatetimeString, formatter);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
*/ |
|
|
*/ |