diff --git a/app/build.gradle b/app/build.gradle index 018a550..edc36a5 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -54,6 +54,7 @@ dependencies { implementation 'androidx.constraintlayout:constraintlayout:2.0.4' implementation 'com.google.firebase:firebase-auth:19.3.1' implementation 'com.google.firebase:firebase-messaging:21.0.0' + implementation 'com.google.android.gms:play-services-maps:17.0.0' testImplementation 'junit:junit:4.+' androidTestImplementation 'androidx.test.ext:junit:1.1.2' androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0' 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..4c57392 --- /dev/null +++ b/app/src/debug/res/values/google_maps_api.xml @@ -0,0 +1,24 @@ + + + AIzaSyBC5wcRatVjF7pZ8jvEUl8sfau5bK0v0cI + \ No newline at end of file diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index f367d3b..879a1e2 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -3,9 +3,15 @@ xmlns:tools="http://schemas.android.com/tools" package="com.example.services"> + + - - + + - + + + + + + - - + + - - - - @@ -43,14 +62,14 @@ - + + - - diff --git a/app/src/main/java/com/example/services/CallWorkerActivity.kt b/app/src/main/java/com/example/services/CallWorkerActivity.kt index 496973c..6505148 100644 --- a/app/src/main/java/com/example/services/CallWorkerActivity.kt +++ b/app/src/main/java/com/example/services/CallWorkerActivity.kt @@ -15,6 +15,7 @@ import com.google.firebase.database.FirebaseDatabase import com.squareup.picasso.Picasso import kotlinx.android.synthetic.main.activity_call_worker.* import java.util.* +import com.example.services.MapsActivity class CallWorkerActivity : AppCompatActivity() { override fun onCreate(savedInstanceState: Bundle?) { @@ -27,7 +28,12 @@ class CallWorkerActivity : AppCompatActivity() { }else{ Picasso.get().load(user.profileImgURL).into(user_pic) } + user_city.setOnClickListener { + var intent=Intent(this,MapsActivity::class.java) + startActivity(intent) + + } worker_phone_call.setOnClickListener{ makeCall(user.phone) } diff --git a/app/src/main/java/com/example/services/MapsActivity.kt b/app/src/main/java/com/example/services/MapsActivity.kt new file mode 100644 index 0000000..685c55f --- /dev/null +++ b/app/src/main/java/com/example/services/MapsActivity.kt @@ -0,0 +1,150 @@ +package com.example.services + +import android.Manifest +import android.content.Context +import android.content.pm.PackageManager +import android.location.Location +import android.location.LocationListener +import android.location.LocationManager +import android.os.Build +import androidx.appcompat.app.AppCompatActivity +import android.os.Bundle +import android.widget.Toast +import androidx.core.app.ActivityCompat + +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 +import java.lang.Exception + +class MapsActivity : AppCompatActivity(), OnMapReadyCallback { + + private lateinit var mMap: GoogleMap + + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + setContentView(R.layout.activity_maps) + // 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) + getuserlocation() + } + + /** + * Manipulates the map once available. + * This callback is triggered when the map is ready to be used. + * This is where we can add markers or lines, add listeners or move the camera. In this case, + * we just add a marker near Sydney, Australia. + * If Google Play services is not installed on the device, the user will be prompted to install + * it inside the SupportMapFragment. This method will only be triggered once the user has + * installed Google Play services and returned to the app. + */ + override fun onMapReady(googleMap: GoogleMap) { + mMap = googleMap + + // Add a marker in Sydney and move the camera + + } + + + fun getuserlocation(){ + Toast.makeText(this,"PermissionGranted", Toast.LENGTH_LONG).show() + Toast.makeText(this,"Loading Real Time Location",Toast.LENGTH_LONG).show() + var mylocation=MylocationListner() + var locationmanger= getSystemService(Context.LOCATION_SERVICE) as LocationManager + + + if (ActivityCompat.checkSelfPermission( + this, + Manifest.permission.ACCESS_FINE_LOCATION + ) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission( + this, + Manifest.permission.ACCESS_COARSE_LOCATION + ) != PackageManager.PERMISSION_GRANTED) { + // TODO: Consider calling + // ActivityCompat#requestPermissions + // here to request the missing permissions, and then overriding + // public void onRequestPermissionsResult(int requestCode, String[] permissions, + // int[] grantResults) + // to handle the case where the user grants the permission. See the documentation + // for ActivityCompat#requestPermissions for more details. + return + } + locationmanger.requestLocationUpdates(LocationManager.GPS_PROVIDER,3,3f,mylocation) + var myth=myThread() + myth.start() + } + + + /** + * Manipulates the map once available. + * This callback is triggered when the map is ready to be used. + * This is where we can add markers or lines, add listeners or move the camera. In this case, + * we just add a marker near Sydney, Australia. + * If Google Play services is not installed on the device, the user will be prompted to install + * it inside the SupportMapFragment. This method will only be triggered once the user has + * installed Google Play services and returned to the app. + */ + + var local: Location?=null + inner class MylocationListner: LocationListener { + + + constructor(){ + local= Location("Start") + local!!.latitude=0.0 + local!!.longitude=0.0 + + } + + + override fun onLocationChanged(location: Location) { + + local=location + + } + + } + var oldlocation: Location?=null + inner class myThread:Thread{ + constructor():super(){ + oldlocation= Location("Start") + oldlocation!!.latitude=0.0 + oldlocation!!.longitude=0.0 + } + + override fun run() { + while (true){ + try { + + if(oldlocation!!.distanceTo(local)==0f){ + continue + } + oldlocation=local + runOnUiThread(){ + mMap.clear() + + var jhansi = LatLng(local!!.latitude, local!!.longitude) + mMap!!.addMarker( + MarkerOptions() + .position(jhansi) + .snippet("your location") + .title("me") + + ) + mMap.moveCamera (CameraUpdateFactory.newLatLngZoom(jhansi, 16f)) + + } + Thread.sleep(1000) + } + catch (ex: Exception){} + } + } + } + +} \ No newline at end of file diff --git a/app/src/main/java/com/example/services/signInRegister/SignInActivity.kt b/app/src/main/java/com/example/services/signInRegister/SignInActivity.kt index 1133c3b..ec4e2d2 100644 --- a/app/src/main/java/com/example/services/signInRegister/SignInActivity.kt +++ b/app/src/main/java/com/example/services/signInRegister/SignInActivity.kt @@ -1,7 +1,12 @@ package com.example.services.signInRegister +import android.Manifest +import android.content.Context import android.content.Intent +import android.content.pm.PackageManager import android.graphics.Typeface.BOLD +import android.location.LocationManager +import android.os.Build import android.os.Bundle import android.text.Spannable import android.text.SpannableString @@ -15,6 +20,7 @@ import android.widget.Button import android.widget.EditText import android.widget.Toast import androidx.appcompat.app.AppCompatActivity +import androidx.core.app.ActivityCompat import com.example.services.R import com.example.services.shared.GetCurrentUser import com.google.firebase.auth.FirebaseAuth @@ -50,8 +56,61 @@ class SignInActivity : AppCompatActivity() { string.setSpan(click, 23, 30, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); textView6.text = string; textView6.movementMethod = LinkMovementMethod.getInstance(); + checkPermission() + } + var Accesslocation=0 + fun checkPermission(){ + if(Build.VERSION.SDK_INT>=23){ + if (ActivityCompat.checkSelfPermission(this,android.Manifest.permission.ACCESS_FINE_LOCATION)!= PackageManager.PERMISSION_GRANTED){ + requestPermissions(arrayOf(android.Manifest.permission.ACCESS_FINE_LOCATION),Accesslocation) + return + } + } + getuserlocation() + + + } + fun getuserlocation(){ + Toast.makeText(this,"PermissionGranted", Toast.LENGTH_LONG).show() + + + + if (ActivityCompat.checkSelfPermission( + this, + Manifest.permission.ACCESS_FINE_LOCATION + ) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission( + this, + Manifest.permission.ACCESS_COARSE_LOCATION + ) != PackageManager.PERMISSION_GRANTED) { + // TODO: Consider calling + // ActivityCompat#requestPermissions + // here to request the missing permissions, and then overriding + // public void onRequestPermissionsResult(int requestCode, String[] permissions, + // int[] grantResults) + // to handle the case where the user grants the permission. See the documentation + // for ActivityCompat#requestPermissions for more details. + return + } + } + override fun onRequestPermissionsResult( + requestCode: Int, + permissions: Array, + grantResults: IntArray + ) { + when(requestCode){ + Accesslocation->{ + if (grantResults[0]== PackageManager.PERMISSION_GRANTED){ + getuserlocation() + } + else{ + Toast.makeText(this,"User Location Access On", Toast.LENGTH_LONG).show() + } + } + } + super.onRequestPermissionsResult(requestCode, permissions, grantResults) + } private fun performLogin(){ val email = findViewById(R.id.email_login).text val password = findViewById(R.id.password_login).text @@ -70,6 +129,5 @@ class SignInActivity : AppCompatActivity() { Toast.makeText(this, "Login Failed", Toast.LENGTH_LONG).show(); } } - } diff --git a/app/src/main/res/layout/activity_maps.xml b/app/src/main/res/layout/activity_maps.xml new file mode 100644 index 0000000..ec352fc --- /dev/null +++ b/app/src/main/res/layout/activity_maps.xml @@ -0,0 +1,9 @@ + + \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index e14bb0c..99275d5 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -14,4 +14,5 @@ Specialist Expert + Map \ No newline at end of file diff --git a/app/src/release/res/values/google_maps_api.xml b/app/src/release/res/values/google_maps_api.xml new file mode 100644 index 0000000..3abf930 --- /dev/null +++ b/app/src/release/res/values/google_maps_api.xml @@ -0,0 +1,20 @@ + + + AIzaSyBC5wcRatVjF7pZ8jvEUl8sfau5bK0v0cI + \ No newline at end of file