From 02fafec88fc1f1dfea9c36fd9dbc9d4bc5f11aca Mon Sep 17 00:00:00 2001 From: ed Date: Thu, 24 Jun 2021 14:17:40 +0200 Subject: [PATCH] Detection App --- .gitignore | 15 ++ .idea/.gitignore | 3 + .idea/compiler.xml | 6 + .idea/gradle.xml | 21 ++ .idea/jarRepositories.xml | 25 +++ .idea/misc.xml | 9 + .idea/runConfigurations.xml | 10 + README.md | 0 app/.gitignore | 1 + app/build.gradle | 41 ++++ app/proguard-rules.pro | 21 ++ .../detection/ExampleInstrumentedTest.java | 26 +++ app/src/debug/res/values/google_maps_api.xml | 3 + app/src/main/AndroidManifest.xml | 46 ++++ .../detection/EarthquakeLocation.java | 83 +++++++ .../de/edotzlaff/detection/MainActivity.java | 206 ++++++++++++++++++ .../drawable-v24/ic_launcher_foreground.xml | 30 +++ .../res/drawable/ic_launcher_background.xml | 170 +++++++++++++++ .../layout/activity_earthquake_location.xml | 27 +++ app/src/main/res/layout/activity_main.xml | 65 ++++++ .../res/mipmap-anydpi-v26/ic_launcher.xml | 5 + .../mipmap-anydpi-v26/ic_launcher_round.xml | 5 + app/src/main/res/mipmap-hdpi/ic_launcher.png | Bin 0 -> 3593 bytes .../res/mipmap-hdpi/ic_launcher_round.png | Bin 0 -> 5339 bytes app/src/main/res/mipmap-mdpi/ic_launcher.png | Bin 0 -> 2636 bytes .../res/mipmap-mdpi/ic_launcher_round.png | Bin 0 -> 3388 bytes app/src/main/res/mipmap-xhdpi/ic_launcher.png | Bin 0 -> 4926 bytes .../res/mipmap-xhdpi/ic_launcher_round.png | Bin 0 -> 7472 bytes .../main/res/mipmap-xxhdpi/ic_launcher.png | Bin 0 -> 7909 bytes .../res/mipmap-xxhdpi/ic_launcher_round.png | Bin 0 -> 11873 bytes .../main/res/mipmap-xxxhdpi/ic_launcher.png | Bin 0 -> 10652 bytes .../res/mipmap-xxxhdpi/ic_launcher_round.png | Bin 0 -> 16570 bytes app/src/main/res/values-night/themes.xml | 16 ++ app/src/main/res/values/colors.xml | 10 + app/src/main/res/values/strings.xml | 4 + app/src/main/res/values/themes.xml | 16 ++ .../release/res/values/google_maps_api.xml | 20 ++ .../edotzlaff/detection/ExampleUnitTest.java | 17 ++ build.gradle | 24 ++ gradle.properties | 19 ++ gradle/wrapper/gradle-wrapper.jar | Bin 0 -> 54329 bytes gradle/wrapper/gradle-wrapper.properties | 6 + gradlew | 172 +++++++++++++++ gradlew.bat | 84 +++++++ settings.gradle | 2 + 45 files changed, 1208 insertions(+) create mode 100644 .gitignore create mode 100644 .idea/.gitignore create mode 100644 .idea/compiler.xml create mode 100644 .idea/gradle.xml create mode 100644 .idea/jarRepositories.xml create mode 100644 .idea/misc.xml create mode 100644 .idea/runConfigurations.xml create mode 100644 README.md create mode 100644 app/.gitignore create mode 100644 app/build.gradle create mode 100644 app/proguard-rules.pro create mode 100644 app/src/androidTest/java/de/edotzlaff/detection/ExampleInstrumentedTest.java create mode 100644 app/src/debug/res/values/google_maps_api.xml create mode 100644 app/src/main/AndroidManifest.xml create mode 100644 app/src/main/java/de/edotzlaff/detection/EarthquakeLocation.java create mode 100644 app/src/main/java/de/edotzlaff/detection/MainActivity.java create mode 100644 app/src/main/res/drawable-v24/ic_launcher_foreground.xml create mode 100644 app/src/main/res/drawable/ic_launcher_background.xml create mode 100644 app/src/main/res/layout/activity_earthquake_location.xml create mode 100644 app/src/main/res/layout/activity_main.xml create mode 100644 app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml create mode 100644 app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml create mode 100644 app/src/main/res/mipmap-hdpi/ic_launcher.png create mode 100644 app/src/main/res/mipmap-hdpi/ic_launcher_round.png create mode 100644 app/src/main/res/mipmap-mdpi/ic_launcher.png create mode 100644 app/src/main/res/mipmap-mdpi/ic_launcher_round.png create mode 100644 app/src/main/res/mipmap-xhdpi/ic_launcher.png create mode 100644 app/src/main/res/mipmap-xhdpi/ic_launcher_round.png create mode 100644 app/src/main/res/mipmap-xxhdpi/ic_launcher.png create mode 100644 app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png create mode 100644 app/src/main/res/mipmap-xxxhdpi/ic_launcher.png create mode 100644 app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png create mode 100644 app/src/main/res/values-night/themes.xml create mode 100644 app/src/main/res/values/colors.xml create mode 100644 app/src/main/res/values/strings.xml create mode 100644 app/src/main/res/values/themes.xml create mode 100644 app/src/release/res/values/google_maps_api.xml create mode 100644 app/src/test/java/de/edotzlaff/detection/ExampleUnitTest.java create mode 100644 build.gradle create mode 100644 gradle.properties create mode 100644 gradle/wrapper/gradle-wrapper.jar create mode 100644 gradle/wrapper/gradle-wrapper.properties create mode 100644 gradlew create mode 100644 gradlew.bat create mode 100644 settings.gradle diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..aa724b7 --- /dev/null +++ b/.gitignore @@ -0,0 +1,15 @@ +*.iml +.gradle +/local.properties +/.idea/caches +/.idea/libraries +/.idea/modules.xml +/.idea/workspace.xml +/.idea/navEditor.xml +/.idea/assetWizardSettings.xml +.DS_Store +/build +/captures +.externalNativeBuild +.cxx +local.properties diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..26d3352 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,3 @@ +# Default ignored files +/shelf/ +/workspace.xml diff --git a/.idea/compiler.xml b/.idea/compiler.xml new file mode 100644 index 0000000..fb7f4a8 --- /dev/null +++ b/.idea/compiler.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/gradle.xml b/.idea/gradle.xml new file mode 100644 index 0000000..ac6b0ae --- /dev/null +++ b/.idea/gradle.xml @@ -0,0 +1,21 @@ + + + + + + + \ No newline at end of file diff --git a/.idea/jarRepositories.xml b/.idea/jarRepositories.xml new file mode 100644 index 0000000..a5f05cd --- /dev/null +++ b/.idea/jarRepositories.xml @@ -0,0 +1,25 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..860da66 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,9 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/runConfigurations.xml b/.idea/runConfigurations.xml new file mode 100644 index 0000000..797acea --- /dev/null +++ b/.idea/runConfigurations.xml @@ -0,0 +1,10 @@ + + + + + + \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..e69de29 diff --git a/app/.gitignore b/app/.gitignore new file mode 100644 index 0000000..42afabf --- /dev/null +++ b/app/.gitignore @@ -0,0 +1 @@ +/build \ No newline at end of file diff --git a/app/build.gradle b/app/build.gradle new file mode 100644 index 0000000..e976838 --- /dev/null +++ b/app/build.gradle @@ -0,0 +1,41 @@ +plugins { + id 'com.android.application' +} + +android { + compileSdkVersion 30 + buildToolsVersion "30.0.3" + + defaultConfig { + applicationId "de.edotzlaff.detection" + minSdkVersion 23 + targetSdkVersion 30 + versionCode 1 + versionName "1.0" + + testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" + } + + buildTypes { + release { + minifyEnabled false + proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' + } + } + compileOptions { + sourceCompatibility JavaVersion.VERSION_1_8 + targetCompatibility JavaVersion.VERSION_1_8 + } +} + +dependencies { + + implementation 'androidx.appcompat:appcompat: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' + testImplementation 'junit:junit:4.+' + androidTestImplementation 'androidx.test.ext:junit:1.1.2' + implementation "com.google.android.gms:play-services-location:15.0.1" //Important to find the location from the device + androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0' +} \ No newline at end of file diff --git a/app/proguard-rules.pro b/app/proguard-rules.pro new file mode 100644 index 0000000..481bb43 --- /dev/null +++ b/app/proguard-rules.pro @@ -0,0 +1,21 @@ +# Add project specific ProGuard rules here. +# You can control the set of applied configuration files using the +# proguardFiles setting in build.gradle. +# +# For more details, see +# http://developer.android.com/guide/developing/tools/proguard.html + +# If your project uses WebView with JS, uncomment the following +# and specify the fully qualified class name to the JavaScript interface +# class: +#-keepclassmembers class fqcn.of.javascript.interface.for.webview { +# public *; +#} + +# Uncomment this to preserve the line number information for +# debugging stack traces. +#-keepattributes SourceFile,LineNumberTable + +# If you keep the line number information, uncomment this to +# hide the original source file name. +#-renamesourcefileattribute SourceFile \ No newline at end of file diff --git a/app/src/androidTest/java/de/edotzlaff/detection/ExampleInstrumentedTest.java b/app/src/androidTest/java/de/edotzlaff/detection/ExampleInstrumentedTest.java new file mode 100644 index 0000000..c5b1f5e --- /dev/null +++ b/app/src/androidTest/java/de/edotzlaff/detection/ExampleInstrumentedTest.java @@ -0,0 +1,26 @@ +package de.edotzlaff.detection; + +import android.content.Context; + +import androidx.test.platform.app.InstrumentationRegistry; +import androidx.test.ext.junit.runners.AndroidJUnit4; + +import org.junit.Test; +import org.junit.runner.RunWith; + +import static org.junit.Assert.*; + +/** + * Instrumented test, which will execute on an Android device. + * + * @see Testing documentation + */ +@RunWith(AndroidJUnit4.class) +public class ExampleInstrumentedTest { + @Test + public void useAppContext() { + // Context of the app under test. + Context appContext = InstrumentationRegistry.getInstrumentation().getTargetContext(); + assertEquals("de.edotzlaff.detection", appContext.getPackageName()); + } +} \ No newline at end of file diff --git a/app/src/debug/res/values/google_maps_api.xml b/app/src/debug/res/values/google_maps_api.xml new file mode 100644 index 0000000..4014bf2 --- /dev/null +++ b/app/src/debug/res/values/google_maps_api.xml @@ -0,0 +1,3 @@ + + AIzaSyCCnjanFAzxuH91tD206IjaAU4_ymSgug0 + \ No newline at end of file diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml new file mode 100644 index 0000000..c4a7c9b --- /dev/null +++ b/app/src/main/AndroidManifest.xml @@ -0,0 +1,46 @@ + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/java/de/edotzlaff/detection/EarthquakeLocation.java b/app/src/main/java/de/edotzlaff/detection/EarthquakeLocation.java new file mode 100644 index 0000000..794b4ba --- /dev/null +++ b/app/src/main/java/de/edotzlaff/detection/EarthquakeLocation.java @@ -0,0 +1,83 @@ +package de.edotzlaff.detection; + +import androidx.fragment.app.FragmentActivity; + +import android.os.Bundle; + +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.BitmapDescriptorFactory; +import com.google.android.gms.maps.model.LatLng; +import com.google.android.gms.maps.model.MarkerOptions; + +public class EarthquakeLocation extends FragmentActivity implements OnMapReadyCallback { + + private GoogleMap mMap; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_earthquake_location); + // 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); + } + + //########################################################################################################################################################################## + //################################################################## vvv DB Code vvv ##################################################################################### + + //TODO Aron + + //################################################################## ^^^^ DB Code ^^^^ ################################################################################### + //########################################################################################################################################################################## + + + + //########################################################################################################################################################################## + //################################################################## vvv Calculate Epicenter vvv ######################################################################### + + //TODO Jan + + //################################################################## ^^^^ Calculate Epicenter ^^^^ ####################################################################### + //########################################################################################################################################################################## + + + //########################################################################################################################################################################## + //################################################################## vvv Maps Code vvv ################################################################################### + + @Override + public void onMapReady(GoogleMap googleMap) { + mMap = googleMap; + + //TODO Aron: Daten aus DB in die jeweiligen Devices einsetzten + //aus DB für Device 1 long lat + LatLng divice1 = new LatLng(-34, 152); + mMap.addMarker(new MarkerOptions().position(divice1).title("Device 1").icon(BitmapDescriptorFactory + .defaultMarker(BitmapDescriptorFactory.HUE_GREEN))); + + //aus DB für Device 2 long lat + LatLng divice2 = new LatLng(-33, 152); + mMap.addMarker(new MarkerOptions().position(divice2).title("Device 2").icon(BitmapDescriptorFactory + .defaultMarker(BitmapDescriptorFactory.HUE_GREEN))); + + //aus DB für Device 3 long lat + LatLng divice3 = new LatLng(-34, 150); + mMap.addMarker(new MarkerOptions().position(divice3).title("Device 3").icon(BitmapDescriptorFactory + .defaultMarker(BitmapDescriptorFactory.HUE_GREEN))); + + //man könnten noch eine IF Abfrage einbauen falls es 4 Devices gibt + + // Add a marker in Epicenter + LatLng epicenter = new LatLng(-34, 151); + mMap.addMarker(new MarkerOptions().position(epicenter).title("Epicenter")); + mMap.moveCamera(CameraUpdateFactory.newLatLng(epicenter)); + } + + //################################################################## ^^^^ Maps Code ^^^^ ################################################################################# + //########################################################################################################################################################################## + + +} \ No newline at end of file diff --git a/app/src/main/java/de/edotzlaff/detection/MainActivity.java b/app/src/main/java/de/edotzlaff/detection/MainActivity.java new file mode 100644 index 0000000..6e33c72 --- /dev/null +++ b/app/src/main/java/de/edotzlaff/detection/MainActivity.java @@ -0,0 +1,206 @@ +package de.edotzlaff.detection; + +import androidx.annotation.NonNull; +import androidx.appcompat.app.AppCompatActivity; +import androidx.core.app.ActivityCompat; +import androidx.core.content.ContextCompat; + +import android.Manifest; +import android.app.Dialog; +import android.content.Intent; +import android.content.pm.PackageManager; +import android.location.Location; +import android.os.Bundle; +import android.util.Log; +import android.view.View; +import android.widget.Button; +import android.widget.TextView; +import android.widget.Toast; + +import com.google.android.gms.common.ConnectionResult; +import com.google.android.gms.common.GoogleApiAvailability; +import com.google.android.gms.location.FusedLocationProviderClient; +import com.google.android.gms.location.LocationServices; +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.tasks.OnCompleteListener; +import com.google.android.gms.tasks.Task; + +import org.w3c.dom.Text; + +import java.util.Calendar; + +public class MainActivity extends AppCompatActivity { + + private static final String TAG = "MainActivity"; + private static final int ERROR_DIALOG_REQUEST = 9001; + + 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; + + Long currentTime; + Location currentLocation; + // private DatabaseReference mDatenbank; + private double breitengrad; + private double laengengrad; + private boolean useOwnGPS = true; + private int indexID = 1; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_main); + + if (isServiceOK()){ + init(); + } + + //Detection funktion here + + getLocationPermission(); + + //DB function here + + + } + + //########################################################################################################################################################################## + //################################################################## vvv Detect Vibration vvv ############################################################################ + + //TODO Böbbi + + //################################################################## ^^^^ Detect Vibration ^^^^ ########################################################################## + //########################################################################################################################################################################## + + + //########################################################################################################################################################################## + //################################################################## vvv Get Location from Device vvv #################################################################### + + private void getLocationPermission() { + String[] permissions = {Manifest.permission.ACCESS_FINE_LOCATION}; + if (ContextCompat.checkSelfPermission(this.getApplicationContext(), FINE_LOCATION) == PackageManager.PERMISSION_GRANTED) { + mLocationPermissionsGranted = true; + getDeviceLocation(); + } else { + ActivityCompat.requestPermissions(this, permissions, LOCATION_PERMISSION_REQUEST_CODE); + } + } + + 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(); + if(useOwnGPS) + { + breitengrad = currentLocation.getLatitude(); + laengengrad = currentLocation.getLongitude(); + + } + currentLocation.setLatitude(breitengrad); + currentLocation.setLongitude(laengengrad); + setText(); + } + else{ + Toast.makeText(MainActivity.this, "Current Location unavailable", Toast.LENGTH_SHORT).show(); + } + } + }); + } + }catch (SecurityException e){ + Log.e(TAG,"Device Location not found" + e.getMessage()); + } + } + //################################################################## ^^^^ Get Location from Device ^^^^ ################################################################## + //########################################################################################################################################################################## + + + //########################################################################################################################################################################## + //################################################################## vvv DB Code vvv ##################################################################################### + + //TODO Aron + + //################################################################## ^^^^ DB Code ^^^^ ################################################################################### + //########################################################################################################################################################################## + + + + //########################################################################################################################################################################## + //################################################################## vvv Set Text of Device 1/2/3 on MainActivity vvv #################################################### + + private void setText(){ + TextView txtDevice1 = (TextView) findViewById(R.id.txtdevice1); + TextView txtDevice2 = (TextView) findViewById(R.id.txtdevice2); + TextView txtDevice3 = (TextView) findViewById(R.id.txtdevice3); + TextView txtDevice4 = (TextView) findViewById(R.id.txtdevice4); + + + txtDevice1.setText("Device 1"+"\n"+"Time Stamp: "+ Calendar.getInstance().getTimeInMillis()+"\n"+"Latitude: "+breitengrad+"\n"+ "Longitude: "+ laengengrad+"\n"); + + txtDevice2.setText("Device 2"+"\n"+"Time Stamp: "+ Calendar.getInstance().getTimeInMillis()+"\n"+"Latitude: "+breitengrad+"\n"+ "Longitude: "+ laengengrad+"\n"); + + txtDevice3.setText("Device 3"+"\n"+"Time Stamp: "+ Calendar.getInstance().getTimeInMillis()+"\n"+"Latitude: "+breitengrad+"\n"+ "Longitude: "+ laengengrad+"\n"); + + txtDevice4.setText("Device 4"+"\n"+"Time Stamp: "+ Calendar.getInstance().getTimeInMillis()+"\n"+"Latitude: "+breitengrad+"\n"+ "Longitude: "+ laengengrad+"\n"); + + } + + //################################################################## ^^^^ Set Text of Device 1/2/3 on MainActivity ^^^^ ################################################## + //########################################################################################################################################################################## + + + + //########################################################################################################################################################################## + //################################################################## vvv Maps Code vvv ################################################################################### + + 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; + } + + private void init() { + + Button btnEarthquake = (Button) findViewById(R.id.btnEarthquakeLocation); + btnEarthquake.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + Intent intent = new Intent(MainActivity.this, EarthquakeLocation.class); + startActivity(intent); + } + }); + + } + + + //################################################################## ^^^^ Maps Code ^^^^ ################################################################## + //########################################################################################################################################################### + + +} \ No newline at end of file diff --git a/app/src/main/res/drawable-v24/ic_launcher_foreground.xml b/app/src/main/res/drawable-v24/ic_launcher_foreground.xml new file mode 100644 index 0000000..2b068d1 --- /dev/null +++ b/app/src/main/res/drawable-v24/ic_launcher_foreground.xml @@ -0,0 +1,30 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/drawable/ic_launcher_background.xml b/app/src/main/res/drawable/ic_launcher_background.xml new file mode 100644 index 0000000..07d5da9 --- /dev/null +++ b/app/src/main/res/drawable/ic_launcher_background.xml @@ -0,0 +1,170 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/app/src/main/res/layout/activity_earthquake_location.xml b/app/src/main/res/layout/activity_earthquake_location.xml new file mode 100644 index 0000000..24c5f32 --- /dev/null +++ b/app/src/main/res/layout/activity_earthquake_location.xml @@ -0,0 +1,27 @@ + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml new file mode 100644 index 0000000..16188ad --- /dev/null +++ b/app/src/main/res/layout/activity_main.xml @@ -0,0 +1,65 @@ + + + + + + + + + + + +