|
|
|
|
|
|
|
|
package de.edotzlaff.schockwelle; |
|
|
package de.edotzlaff.schockwelle; |
|
|
|
|
|
|
|
|
import android.Manifest; |
|
|
import android.Manifest; |
|
|
|
|
|
import android.content.Context; |
|
|
import android.content.pm.PackageManager; |
|
|
import android.content.pm.PackageManager; |
|
|
import android.location.Location; |
|
|
import android.location.Location; |
|
|
|
|
|
import android.os.Build; |
|
|
import android.os.Bundle; |
|
|
import android.os.Bundle; |
|
|
|
|
|
import android.os.CountDownTimer; |
|
|
|
|
|
import android.os.VibrationEffect; |
|
|
|
|
|
import android.os.Vibrator; |
|
|
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.annotation.RequiresApi; |
|
|
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; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private DatabaseReference mDatenbank; |
|
|
private DatabaseReference mDatenbank; |
|
|
|
|
|
|
|
|
|
|
|
//Vibration |
|
|
|
|
|
private Boolean mDeviceCanVibrate = false; |
|
|
|
|
|
|
|
|
@Override |
|
|
@Override |
|
|
protected void onCreate(Bundle savedInstanceState) { |
|
|
protected void onCreate(Bundle savedInstanceState) { |
|
|
super.onCreate(savedInstanceState); |
|
|
super.onCreate(savedInstanceState); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
getDataBaseValues(); // Hier werden die Daten von der DB abgefragt //TODO Edward: Geht wieder :D |
|
|
getDataBaseValues(); // Hier werden die Daten von der DB abgefragt //TODO Edward: Geht wieder :D |
|
|
|
|
|
|
|
|
|
|
|
getVibrationAbility(); |
|
|
//distance(currentLocation.getLatitude(), currentLocation.getLongitude(),breitengrad,laengengrad); //Übergabe zur Berechnung der Distanz zwischen Auslöser und aktuellem Standort |
|
|
//distance(currentLocation.getLatitude(), currentLocation.getLongitude(),breitengrad,laengengrad); //Übergabe zur Berechnung der Distanz zwischen Auslöser und aktuellem Standort |
|
|
|
|
|
|
|
|
//TODO Patrick: die Funktion distance gibt Meter zurück, könntest Du das mit dem Zeitstempel und der Berechnung bis zur Vibration machen? |
|
|
//TODO Patrick: die Funktion distance gibt Meter zurück, könntest Du das mit dem Zeitstempel und der Berechnung bis zur Vibration machen? |
|
|
|
|
|
setVibrationTimer(10000,1000,255); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
private void getLocationPermission() { |
|
|
private void getLocationPermission() { |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 long getTimeStampDifference(Date vibrationTime) |
|
|
|
|
|
{ |
|
|
|
|
|
long diff= 0; |
|
|
|
|
|
//TODO Zeitdifferenz in Millisekunden zwischen aktuellen Uhrzeit und Vibratonszeitstempel berechnen |
|
|
|
|
|
return diff; |
|
|
|
|
|
} |
|
|
|
|
|
private void setVibrationTimer(long msDelay, int duration, int amplitude) |
|
|
|
|
|
{ |
|
|
|
|
|
|
|
|
|
|
|
new CountDownTimer(msDelay, 1000) { |
|
|
|
|
|
public void onTick(long millisUntilFinished) { |
|
|
|
|
|
((TextView) findViewById(R.id.txtSensor)).setText("Earthquake hits in " + millisUntilFinished / 1000 + " s"); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
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"); |
|
|
|
|
|
} |
|
|
|
|
|
}.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(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); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
@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); |