From 437a401a5dd868c546a700be8a49b2b53974eb8c Mon Sep 17 00:00:00 2001 From: ed Date: Mon, 14 Jun 2021 23:28:27 +0200 Subject: [PATCH] Schockwellen App Prototyp --- .gitignore | 15 ++ .idea/.gitignore | 3 + .idea/compiler.xml | 6 + .idea/gradle.xml | 22 +++ .idea/jarRepositories.xml | 25 +++ .idea/misc.xml | 9 + .idea/vcs.xml | 6 + app/.gitignore | 1 + app/build.gradle | 41 +++++ app/proguard-rules.pro | 21 +++ .../schockwelle/ExampleInstrumentedTest.java | 26 +++ app/src/debug/res/values/google_maps_api.xml | 4 + app/src/main/AndroidManifest.xml | 49 +++++ .../schockwelle/EarthquakeMapsActivity.java | 135 ++++++++++++++ .../edotzlaff/schockwelle/MainActivity.java | 78 ++++++++ .../schockwelle/SensorMapsActivity.java | 68 +++++++ .../drawable-v24/ic_launcher_foreground.xml | 30 +++ .../res/drawable/ic_launcher_background.xml | 170 +++++++++++++++++ .../res/layout/activity_earthquake_maps.xml | 28 +++ app/src/main/res/layout/activity_main.xml | 26 +++ .../main/res/layout/activity_sensor_maps.xml | 27 +++ .../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 | 5 + app/src/main/res/values/themes.xml | 16 ++ .../release/res/values/google_maps_api.xml | 4 + .../schockwelle/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 + 46 files changed, 1175 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/vcs.xml 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/schockwelle/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/schockwelle/EarthquakeMapsActivity.java create mode 100644 app/src/main/java/de/edotzlaff/schockwelle/MainActivity.java create mode 100644 app/src/main/java/de/edotzlaff/schockwelle/SensorMapsActivity.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_maps.xml create mode 100644 app/src/main/res/layout/activity_main.xml create mode 100644 app/src/main/res/layout/activity_sensor_maps.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/schockwelle/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..61a9130 --- /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..23a89bb --- /dev/null +++ b/.idea/gradle.xml @@ -0,0 +1,22 @@ + + + + + + + \ 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..d5d35ec --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,9 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..94a25f7 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file 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..96e92cd --- /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.schockwelle" + 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' + androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0' + implementation "com.google.android.gms:play-services-location:15.0.1" //Important to find the location from the device +} \ 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/schockwelle/ExampleInstrumentedTest.java b/app/src/androidTest/java/de/edotzlaff/schockwelle/ExampleInstrumentedTest.java new file mode 100644 index 0000000..65335a6 --- /dev/null +++ b/app/src/androidTest/java/de/edotzlaff/schockwelle/ExampleInstrumentedTest.java @@ -0,0 +1,26 @@ +package de.edotzlaff.schockwelle; + +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.schockwelle", 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..1d8f9b1 --- /dev/null +++ b/app/src/debug/res/values/google_maps_api.xml @@ -0,0 +1,4 @@ + + + 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..869dd28 --- /dev/null +++ b/app/src/main/AndroidManifest.xml @@ -0,0 +1,49 @@ + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/java/de/edotzlaff/schockwelle/EarthquakeMapsActivity.java b/app/src/main/java/de/edotzlaff/schockwelle/EarthquakeMapsActivity.java new file mode 100644 index 0000000..dc96b88 --- /dev/null +++ b/app/src/main/java/de/edotzlaff/schockwelle/EarthquakeMapsActivity.java @@ -0,0 +1,135 @@ +package de.edotzlaff.schockwelle; + +import android.Manifest; +import android.content.pm.PackageManager; +import android.location.Location; +import android.os.Bundle; +import android.util.Log; +import android.widget.Toast; + +import androidx.annotation.NonNull; +import androidx.core.app.ActivityCompat; +import androidx.core.content.ContextCompat; +import androidx.fragment.app.FragmentActivity; + +import com.google.android.gms.location.FusedLocationProviderClient; +import com.google.android.gms.location.LocationServices; +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.LatLng; +import com.google.android.gms.maps.model.MarkerOptions; +import com.google.android.gms.tasks.OnCompleteListener; +import com.google.android.gms.tasks.Task; + +public class EarthquakeMapsActivity extends FragmentActivity implements OnMapReadyCallback { + + private static final String TAG = "MainActivity"; + private static final String FINE_LOCATION = Manifest.permission.ACCESS_FINE_LOCATION; + private static final int LOCATION_PERMISSION_REQUEST_CODE = 1234; + + //vars + private Boolean mLocationPermissionsGranted = false; + private GoogleMap mMap; + private FusedLocationProviderClient mFusedLocationProviderClient; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_earthquake_maps); + + getLocationPermission(); + } + + private void getLocationPermission() { + String[] permissions = {Manifest.permission.ACCESS_FINE_LOCATION}; + if (ContextCompat.checkSelfPermission(this.getApplicationContext(), FINE_LOCATION) == PackageManager.PERMISSION_GRANTED) { + mLocationPermissionsGranted = true; + initMap(); + } else { + ActivityCompat.requestPermissions(this, permissions, LOCATION_PERMISSION_REQUEST_CODE); + } + } + + @Override + public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) { + super.onRequestPermissionsResult(requestCode, permissions, grantResults); + mLocationPermissionsGranted = false; + + switch (requestCode) { + case LOCATION_PERMISSION_REQUEST_CODE: { + if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) { + mLocationPermissionsGranted = true; + //initalize or map + initMap(); + } + } + } + } + + + private void initMap() { + SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map); + mapFragment.getMapAsync(this); + } + + @Override + public void onMapReady(GoogleMap googleMap) { + Toast.makeText(this, "Map is ready", Toast.LENGTH_SHORT).show(); + mMap = googleMap; + + if (mLocationPermissionsGranted) { + getDeviceLocation(); + + if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) + != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, + Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) { + + return; + } + mMap.setMyLocationEnabled(true); + } + + // Add a marker in Sydney and move the camera + //LatLng sydney = new LatLng(-34, 151); + //mMap.addMarker(new MarkerOptions().position(sydney).title("Marker in Sydney")); + //mMap.moveCamera(CameraUpdateFactory.newLatLng(sydney)); + } + + 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()){ + + Location currentLocation = (Location) task.getResult(); //TODO Aron hier erhält die Anwendung die GPS Positionen + moveCamera(new LatLng(currentLocation.getLatitude(), currentLocation.getLongitude()),15f); + + } + else{ + Toast.makeText(EarthquakeMapsActivity.this, "Current Location unavailable", Toast.LENGTH_SHORT).show(); + } + } + }); + } + }catch (SecurityException e){ + Log.e(TAG,"Device Location not found" + e.getMessage()); + } + } + + private void moveCamera(LatLng latlng, float zoom){ + Log.d(TAG,"Latitude: "+latlng.latitude+"Longitude: "+latlng.longitude); + mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(latlng, zoom)); + } + + + //TODO Aron Daten an DB senden +} \ No newline at end of file diff --git a/app/src/main/java/de/edotzlaff/schockwelle/MainActivity.java b/app/src/main/java/de/edotzlaff/schockwelle/MainActivity.java new file mode 100644 index 0000000..6bd9b55 --- /dev/null +++ b/app/src/main/java/de/edotzlaff/schockwelle/MainActivity.java @@ -0,0 +1,78 @@ +package de.edotzlaff.schockwelle; + +import androidx.appcompat.app.AppCompatActivity; +import androidx.fragment.app.FragmentActivity; + +import android.app.Dialog; +import android.content.Intent; +import android.hardware.Sensor; +import android.os.Bundle; +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; + +public class MainActivity extends FragmentActivity { + + private static final String TAG = "MainActivity"; + private static final int ERROR_DIALOG_REQUEST = 9001; + + + + @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); + btnEarthquake.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + Intent intent = new Intent(MainActivity.this, EarthquakeMapsActivity.class); + startActivity(intent); + } + }); + + Button btnSensor = (Button) findViewById(R.id.btnSensor); + btnSensor.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + Intent intent = new Intent(MainActivity.this, SensorMapsActivity.class); + startActivity(intent); + } + }); + + + } + + + 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; + } +} \ No newline at end of file diff --git a/app/src/main/java/de/edotzlaff/schockwelle/SensorMapsActivity.java b/app/src/main/java/de/edotzlaff/schockwelle/SensorMapsActivity.java new file mode 100644 index 0000000..769ffae --- /dev/null +++ b/app/src/main/java/de/edotzlaff/schockwelle/SensorMapsActivity.java @@ -0,0 +1,68 @@ +package de.edotzlaff.schockwelle; + +import androidx.fragment.app.FragmentActivity; + +import android.location.Location; +import android.os.Bundle; +import android.widget.TextView; + +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.LatLng; +import com.google.android.gms.maps.model.MarkerOptions; + +import org.w3c.dom.Text; + +public class SensorMapsActivity extends FragmentActivity implements OnMapReadyCallback { + + private GoogleMap mMap; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_sensor_maps); + + TextView tv= (TextView) findViewById(R.id.txtSensor); + + initMap(); + + } + + void initMap(){ + // 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); + } + + @Override + public void onMapReady(GoogleMap googleMap) { + mMap = googleMap; + + // Add a marker in Sydney and move the camera + LatLng sydney = new LatLng(-34, 151); + mMap.addMarker(new MarkerOptions().position(sydney).title("Marker in Sydney")); + mMap.moveCamera(CameraUpdateFactory.newLatLng(sydney)); + + + + } + + //TODO Aron Daten von DB abfragen + //TODO Edward Distanz zwischen zwei Punkten berechnen + //TODO Edward Dauer für Timer berechnen bis Smartphone vibriert + /* + private float distance(double currentlatitude, double currentlongitude, double originLat, double originLon) { + + float[] results = new float[1]; + Location.distanceBetween(currentlatitude, currentlongitude, -34, 151, results); + float distanceInMeters = results[0]; + + return distanceInMeters; + } +*/ + + +} \ 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_maps.xml b/app/src/main/res/layout/activity_earthquake_maps.xml new file mode 100644 index 0000000..671a642 --- /dev/null +++ b/app/src/main/res/layout/activity_earthquake_maps.xml @@ -0,0 +1,28 @@ + + + + + + + + + \ 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..94270dc --- /dev/null +++ b/app/src/main/res/layout/activity_main.xml @@ -0,0 +1,26 @@ + + + + +