commit e44294bfced8d043acbe46e7d89530eb7fb42a81 Author: BRNSystems Date: Mon May 31 19:54:09 2021 +0200 Initial commit diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..fecd10e --- /dev/null +++ b/.gitignore @@ -0,0 +1,16 @@ +*.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 +/app/src/debug/res/values/google_maps_api.xml 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/.name b/.idea/.name new file mode 100644 index 0000000..843f922 --- /dev/null +++ b/.idea/.name @@ -0,0 +1 @@ +GPS Game \ No newline at end of file diff --git a/.idea/codeStyles/Project.xml b/.idea/codeStyles/Project.xml new file mode 100644 index 0000000..7643783 --- /dev/null +++ b/.idea/codeStyles/Project.xml @@ -0,0 +1,123 @@ + + + + + + + + + + \ No newline at end of file diff --git a/.idea/codeStyles/codeStyleConfig.xml b/.idea/codeStyles/codeStyleConfig.xml new file mode 100644 index 0000000..79ee123 --- /dev/null +++ b/.idea/codeStyles/codeStyleConfig.xml @@ -0,0 +1,5 @@ + + + + \ No newline at end of file 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/discord.xml b/.idea/discord.xml new file mode 100644 index 0000000..cd711a0 --- /dev/null +++ b/.idea/discord.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..5cd135a --- /dev/null +++ b/.idea/gradle.xml @@ -0,0 +1,20 @@ + + + + + + + \ No newline at end of file diff --git a/.idea/jarRepositories.xml b/.idea/jarRepositories.xml new file mode 100644 index 0000000..0380d8d --- /dev/null +++ b/.idea/jarRepositories.xml @@ -0,0 +1,30 @@ + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..6199cc2 --- /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/.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..f88ec47 --- /dev/null +++ b/app/build.gradle @@ -0,0 +1,51 @@ +plugins { + id 'com.android.application' + id 'kotlin-android' +} + +android { + compileSdkVersion 30 + buildToolsVersion "30.0.3" + + defaultConfig { + applicationId "systems.brn.gpsgame1" + minSdkVersion 19 + 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 + } + kotlinOptions { + jvmTarget = '1.8' + } + buildFeatures { + viewBinding true + } +} + +dependencies { + + implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version" + implementation 'androidx.core:core-ktx:1.5.0' + implementation 'androidx.appcompat:appcompat:1.3.0' + implementation 'com.google.android.material:material:1.3.0' + implementation 'com.google.android.gms:play-services-maps:17.0.1' + implementation 'androidx.constraintlayout:constraintlayout:2.0.4' + implementation 'com.google.android.gms:play-services-location:18.0.0' + implementation 'com.squareup.okhttp3:okhttp:5.0.0-alpha.2' + testImplementation 'junit:junit:4.13.2' + androidTestImplementation 'androidx.test.ext:junit:1.1.2' + 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/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml new file mode 100644 index 0000000..ddcbc0e --- /dev/null +++ b/app/src/main/AndroidManifest.xml @@ -0,0 +1,56 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/java/systems/brn/gpsgame1/LoginActivity.kt b/app/src/main/java/systems/brn/gpsgame1/LoginActivity.kt new file mode 100644 index 0000000..d08c11b --- /dev/null +++ b/app/src/main/java/systems/brn/gpsgame1/LoginActivity.kt @@ -0,0 +1,49 @@ +package systems.brn.gpsgame1 + +import android.content.Context +import android.content.Intent +import android.content.SharedPreferences +import android.os.Bundle +import android.widget.Button +import android.widget.EditText +import android.widget.Toast +import androidx.appcompat.app.AppCompatActivity +import okhttp3.ConnectionSpec +import okhttp3.OkHttpClient +import okhttp3.Request +import okhttp3.Response +import java.net.URL + + +class LoginActivity : AppCompatActivity() { + private lateinit var sharedPreferences: SharedPreferences + private val sharedPrefFile = "MyConfig" + private val url: String = "http://10.10.10.52/checklogin.php" + private var client = OkHttpClient.Builder().connectionSpecs(listOf(ConnectionSpec.MODERN_TLS, ConnectionSpec.COMPATIBLE_TLS)).build() + private val request = Request.Builder().url(URL(url)).build() + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + setContentView(R.layout.activity_login) + sharedPreferences = this.getSharedPreferences(sharedPrefFile, Context.MODE_PRIVATE) + val mBtnLogin = this.findViewById(R.id.signin) as Button + mBtnLogin.setOnClickListener { + val email = findViewById(R.id.email) + val password = findViewById(R.id.password) + with(sharedPreferences.edit()) { + putString("email", email.text.toString()) + putString("password", password.text.toString()) + putInt("configured", 1) + apply() + } + val response: Response = client.newCall(request).execute() + val stringresponse: String? = response.body?.string() + if (stringresponse == "OK") { + Toast.makeText(this, "Permission granted, run the main app", Toast.LENGTH_LONG).show() + val intent = Intent(this, MapsActivity::class.java) + startActivity(intent) + } else { + Toast.makeText(this, "Login failed", Toast.LENGTH_LONG).show() + } + } + } +} \ No newline at end of file diff --git a/app/src/main/java/systems/brn/gpsgame1/MapsActivity.kt b/app/src/main/java/systems/brn/gpsgame1/MapsActivity.kt new file mode 100644 index 0000000..6265649 --- /dev/null +++ b/app/src/main/java/systems/brn/gpsgame1/MapsActivity.kt @@ -0,0 +1,170 @@ +@file:Suppress("NULLABILITY_MISMATCH_BASED_ON_JAVA_ANNOTATIONS") + +package systems.brn.gpsgame1 + +import android.Manifest +import android.content.Context +import android.content.Intent +import android.content.SharedPreferences +import android.content.pm.PackageManager +import android.location.Location +import android.os.Build +import android.os.Bundle +import android.os.Looper +import android.widget.Toast +import androidx.appcompat.app.AppCompatActivity +import androidx.core.app.ActivityCompat +import com.google.android.gms.location.* +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.* +import okhttp3.ConnectionSpec +import okhttp3.OkHttpClient +import systems.brn.gpsgame1.databinding.ActivityMapsBinding + + +class MapsActivity : AppCompatActivity(), OnMapReadyCallback { + private val sharedPrefFile = "MyConfig" + private var mFusedLocationProviderClient: FusedLocationProviderClient? = null + private val interval: Long = 2000 + private val fastestinterval: Long = 1000 + private lateinit var mLastLocation: Location + private lateinit var mLocationRequest: LocationRequest + private lateinit var mymarker: Marker + private lateinit var mycircle: Circle + private val requestpermissionslocation = 10 + private lateinit var mMap: GoogleMap + private lateinit var binding: ActivityMapsBinding + private var firsttime = true + private lateinit var sharedPreferences: SharedPreferences + private var client = OkHttpClient.Builder().connectionSpecs(listOf(ConnectionSpec.MODERN_TLS, ConnectionSpec.COMPATIBLE_TLS)).build() + private fun checkPermissionForLocation(context: Context): Boolean { + return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { + + if (context.checkSelfPermission(Manifest.permission.ACCESS_FINE_LOCATION) == + PackageManager.PERMISSION_GRANTED){ + true + }else{ + // Show the permission request + ActivityCompat.requestPermissions(this, arrayOf(Manifest.permission.ACCESS_FINE_LOCATION), requestpermissionslocation) + false + } + } else { + true + } + } + + + private fun loginerror(){ + val intent = Intent(this, MapsActivity::class.java) + startActivity(intent) + } + + private fun startLocationUpdates() { + + // Create the location request to start receiving updates + + mLocationRequest.priority = LocationRequest.PRIORITY_HIGH_ACCURACY + mLocationRequest.interval = interval + mLocationRequest.fastestInterval = fastestinterval + + // Create LocationSettingsRequest object using location request + val builder = LocationSettingsRequest.Builder() + builder.addLocationRequest(mLocationRequest) + val locationSettingsRequest = builder.build() + + val settingsClient = LocationServices.getSettingsClient(this) + settingsClient.checkLocationSettings(locationSettingsRequest) + + mFusedLocationProviderClient = LocationServices.getFusedLocationProviderClient(this) + // new Google API SDK v11 uses getFusedLocationProviderClient(this) + if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) { + + + return + } + mFusedLocationProviderClient!!.requestLocationUpdates(mLocationRequest, mLocationCallback, + Looper.myLooper()) + } + + + private fun center(){ + mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(LatLng(mLastLocation.latitude, mLastLocation.longitude), 18.0f)) + } + + fun onLocationChanged(location: Location) { + // New location has now been determined + + mLastLocation = location + try { + mymarker.remove() + } + catch (e: Exception){ } + try { + mycircle.remove() + } + catch (e: Exception){ } + try { + mymarker = mMap.addMarker(MarkerOptions().position(LatLng(mLastLocation.latitude, mLastLocation.longitude)).title("My Position").icon(BitmapDescriptorFactory.fromResource(R.drawable.smiley))) + if (firsttime){ + center() + firsttime = false + } + mycircle = mMap.addCircle(CircleOptions().center(LatLng(mLastLocation.latitude, mLastLocation.longitude)).radius(mLastLocation.accuracy.toDouble()).strokeColor(R.color.BLUE).fillColor(R.color.LIGHTBLUE)) + } + catch (e: SecurityException){ + e.printStackTrace() + } + // You can now create a LatLng Object for use with maps + } + + private val mLocationCallback = object : LocationCallback() { + override fun onLocationResult(locationResult: LocationResult) { + // do work here + onLocationChanged(locationResult.lastLocation) + } + } + + override fun onRequestPermissionsResult(requestCode: Int, permissions: Array, grantResults: IntArray) { + super.onRequestPermissionsResult(requestCode, permissions, grantResults) + if (requestCode == requestpermissionslocation) { + if (grantResults[0] == PackageManager.PERMISSION_GRANTED) { + //We have to add startlocationUpdate() method later instead of Toast + Toast.makeText(this,"Permission granted",Toast.LENGTH_SHORT).show() + } + } + } + + private fun dologin(){ + val configured = sharedPreferences.getInt("configured", 0) + if (configured == 0){ + loginerror() + } + } + + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + binding = ActivityMapsBinding.inflate(layoutInflater) + setContentView(binding.root) + sharedPreferences = this.getSharedPreferences(sharedPrefFile, Context.MODE_PRIVATE) + dologin() + // Obtain the SupportMapFragment and get notified when the map is ready to be used. + val mapFragment = supportFragmentManager.findFragmentById(R.id.map) as SupportMapFragment + mapFragment.getMapAsync(this) + } + + override fun onMapReady(googleMap: GoogleMap) { + mMap = googleMap + mLocationRequest = LocationRequest.create().apply { + interval = interval + fastestInterval = fastestinterval + priority = LocationRequest.PRIORITY_HIGH_ACCURACY + maxWaitTime = 100 + } + checkPermissionForLocation(this) + startLocationUpdates() + } + +} \ No newline at end of file diff --git a/app/src/main/res/drawable-v24/aimer.png b/app/src/main/res/drawable-v24/aimer.png new file mode 100644 index 0000000..c5aa725 Binary files /dev/null and b/app/src/main/res/drawable-v24/aimer.png differ 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-v24/smiley.png b/app/src/main/res/drawable-v24/smiley.png new file mode 100644 index 0000000..21b4a6e Binary files /dev/null and b/app/src/main/res/drawable-v24/smiley.png differ 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_login.xml b/app/src/main/res/layout/activity_login.xml new file mode 100644 index 0000000..3f102a6 --- /dev/null +++ b/app/src/main/res/layout/activity_login.xml @@ -0,0 +1,54 @@ + + + + + + + +