From c67434d25c26c094d88c5d04d3e1c3a9174ae392 Mon Sep 17 00:00:00 2001 From: Apalak Dutta Date: Mon, 25 Sep 2023 15:28:42 +0530 Subject: [PATCH] 25-09-2023 15:25 --- .../femdemo/ApprovalListActivity.java | 8 +- .../ru/visionlab/femdemo/CheckInActivity.java | 208 +++++++++++++++--- .../femdemo/PermissionRequestActivity.java | 63 +++++- .../ru/visionlab/femdemo/Splashactivity.java | 2 +- .../femdemo/login/LoginActivityNew.java | 79 +++++++ 5 files changed, 322 insertions(+), 38 deletions(-) diff --git a/examples/example_bestshot/example/app/src/main/java/ru/visionlab/femdemo/ApprovalListActivity.java b/examples/example_bestshot/example/app/src/main/java/ru/visionlab/femdemo/ApprovalListActivity.java index 68c4071..7ffec2e 100644 --- a/examples/example_bestshot/example/app/src/main/java/ru/visionlab/femdemo/ApprovalListActivity.java +++ b/examples/example_bestshot/example/app/src/main/java/ru/visionlab/femdemo/ApprovalListActivity.java @@ -4,6 +4,7 @@ import androidx.appcompat.app.AppCompatActivity; import android.app.ProgressDialog; import android.content.Intent; +import android.content.SharedPreferences; import android.os.Bundle; import android.view.View; import android.widget.AdapterView; @@ -36,12 +37,17 @@ public class ApprovalListActivity extends AppCompatActivity { ListView lv; ArrayList> arrayList; + String Employeeid; + @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); //setContentView(R.layout.activity_approval_list); setContentView(R.layout.activity_approval_new_list); + SharedPreferences shared = getSharedPreferences("MyPrefs", MODE_PRIVATE); + Employeeid = shared.getString("Employeeid", ""); + back = findViewById(R.id.back); back.setOnClickListener(new View.OnClickListener() { @Override @@ -77,7 +83,7 @@ public class ApprovalListActivity extends AppCompatActivity { public void PermissionApprovalList(){ final ProgressDialog loading = ProgressDialog.show(ApprovalListActivity.this, "Fetching information", "Please wait ", false, false); - String url= "http://43.242.212.92:7001/api/lgt/PermissionApprovallist?ApproverID=27256"; + String url= "http://43.242.212.92:7001/api/lgt/PermissionApprovallist?ApproverID="+ Employeeid; StringRequest stringRequest=new StringRequest(Request.Method.GET, url, new com.android.volley.Response.Listener() { @Override public void onResponse(String response) { diff --git a/examples/example_bestshot/example/app/src/main/java/ru/visionlab/femdemo/CheckInActivity.java b/examples/example_bestshot/example/app/src/main/java/ru/visionlab/femdemo/CheckInActivity.java index 96608f3..499d4d9 100644 --- a/examples/example_bestshot/example/app/src/main/java/ru/visionlab/femdemo/CheckInActivity.java +++ b/examples/example_bestshot/example/app/src/main/java/ru/visionlab/femdemo/CheckInActivity.java @@ -90,6 +90,12 @@ public class CheckInActivity extends AppCompatActivity { boolean _approverstatus; + String Employeeid,LocName,Latitude,Longitude,Limit; + + String currentLat,currentlong; + + boolean is_out_of_location; + @@ -132,8 +138,19 @@ public class CheckInActivity extends AppCompatActivity { System.out.println("Current date and time " + currentDateAndTime); SharedPreferences shared = getSharedPreferences("MyPrefs", MODE_PRIVATE); - String loginFromShare = shared.getString("login", ""); - String Descriptor = shared.getString("Descriptor", ""); + Employeeid = shared.getString("Employeeid", ""); + + + + + currentLat = shared.getString("Lattitude", ""); + currentlong = shared.getString("Longitude", ""); + + + System.out.println("Value ofcurrentLat currentLatn "+ currentLat + " "+ currentlong); + + + @@ -214,7 +231,7 @@ public class CheckInActivity extends AppCompatActivity { TextView username = view.findViewById(R.id.username); - username.setText(loginFromShare); + username.setText(Employeeid); TextView request = view.findViewById(R.id.request); @@ -252,6 +269,7 @@ public class CheckInActivity extends AppCompatActivity { emergency.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { + emergencySos(); } }); @@ -492,6 +510,8 @@ public class CheckInActivity extends AppCompatActivity { public void emergencySos(){ final ProgressDialog loading = ProgressDialog.show(CheckInActivity.this, "Authenticating", "Please wait ", false, false); + System.out.println("Emergency sos "); + String url= "http://43.242.212.92:7001/api/lgt/EmargencySOS"; StringRequest stringRequest=new StringRequest(Request.Method.POST, url, new com.android.volley.Response.Listener() { @Override @@ -504,6 +524,7 @@ public class CheckInActivity extends AppCompatActivity { } try { valueEmer = jsonObject.getString("_statusMessage"); + System.out.println("Emergency sos on response"); } catch (JSONException e) { throw new RuntimeException(e); } @@ -527,8 +548,8 @@ public class CheckInActivity extends AppCompatActivity { protected Map getParams() { Map params = new HashMap(); - params.put("employeeid", "29034"); - params.put("userid", "skumar"); + params.put("employeeid", Employeeid); + params.put("userid", "101"); return params; @@ -616,10 +637,10 @@ public class CheckInActivity extends AppCompatActivity { protected Map getParams() { Map params = new HashMap(); - params.put("employeeid", "101"); - params.put("location", "loca1"); - params.put("latitude", "10.235"); - params.put("longitude", "55.666"); + params.put("employeeid", Employeeid); + params.put("location", LocName); + params.put("latitude", currentLat); + params.put("longitude", currentlong); params.put("checkintime", currentDateAndTime); params.put("locStateDevice", "1"); params.put("locStateApp", "1"); @@ -630,6 +651,8 @@ public class CheckInActivity extends AppCompatActivity { params.put("spoofingEnb", "0"); params.put("providerNetTime", "10/07/2023 12:10:05"); + System.out.println("value of parms "+params); + return params; } }; @@ -686,10 +709,10 @@ public class CheckInActivity extends AppCompatActivity { protected Map getParams() { Map params = new HashMap(); - params.put("employeeid", "29034"); - params.put("location", "loca1"); - params.put("latitude", "10.235"); - params.put("longitude", "55.666"); + params.put("employeeid", Employeeid); + params.put("location", LocName); + params.put("latitude", Latitude); + params.put("longitude", Longitude); params.put("checkouttime", currentDateAndTime); params.put("locStateDevice", "1"); params.put("locStateApp", "1"); @@ -707,7 +730,7 @@ public class CheckInActivity extends AppCompatActivity { } public void targetLocationListFromCheckIn(){ final ProgressDialog loading = ProgressDialog.show(CheckInActivity.this, "Checking location", "Please wait while checking", false, false); - String url= "http://43.242.212.92:7001/api/lgt/EmployeeLocation?employeeid=29034"; + String url= "http://43.242.212.92:7001/api/lgt/EmployeeLocation?employeeid=" + Employeeid; StringRequest stringRequest=new StringRequest(Request.Method.GET, url, new com.android.volley.Response.Listener() { @Override public void onResponse(String response) { @@ -716,13 +739,97 @@ public class CheckInActivity extends AppCompatActivity { try { JSONObject jsonObject=new JSONObject(response); JSONArray jsonArray=jsonObject.getJSONArray("_lstEmployee_Location"); - /*for(int i=0;i() { @Override public void onResponse(String response) { @@ -793,13 +901,52 @@ public class CheckInActivity extends AppCompatActivity { try { JSONObject jsonObject=new JSONObject(response); JSONArray jsonArray=jsonObject.getJSONArray("_lstEmployee_Location"); - /*for(int i=0;i getParams() { Map params = new HashMap(); - params.put("employeeid", "101"); - params.put("eleavetype", "P"); + params.put("employeeid", Employeeid); + params.put("eleavetype", permission_code); params.put("datedaytype", "Today"); - params.put("fromtime", "13:22"); - params.put("totime", "15:22"); + params.put("fromtime", textTimeFrom.getText().toString()); + params.put("totime", textTimeTo.getText().toString()); params.put("reason", remarks); params.put("attachment", ""); params.put("userid", "a"); + params.put("@LDate1", ""); + if(permission_code.equals("O")){ + params.put("startdate", fromDate); + params.put("enddate", toDate); + } + else { + params.put("startdate", ""); + params.put("enddate", ""); + } + System.out.println("params in permission "+params); return params; } }; @@ -361,6 +395,23 @@ public class PermissionRequestActivity extends AppCompatActivity { public void onResponse(String response) { Toast.makeText(PermissionRequestActivity.this, "Response successful2", Toast.LENGTH_SHORT).show(); + try { + JSONArray jsonArray = new JSONArray(response); + for (int i = 0;i< jsonArray.length();i++){ + JSONObject jb1=jsonArray.getJSONObject(i); + permission_code=jb1.getString("Permission_code"); + if(permission_code.equals("P")) + { + permission_code="P"; + } + else { + permission_code="O"; + } + } + + } catch (JSONException e) { + throw new RuntimeException(e); + } loading.dismiss(); } diff --git a/examples/example_bestshot/example/app/src/main/java/ru/visionlab/femdemo/Splashactivity.java b/examples/example_bestshot/example/app/src/main/java/ru/visionlab/femdemo/Splashactivity.java index 21e0e57..6a90ccf 100644 --- a/examples/example_bestshot/example/app/src/main/java/ru/visionlab/femdemo/Splashactivity.java +++ b/examples/example_bestshot/example/app/src/main/java/ru/visionlab/femdemo/Splashactivity.java @@ -39,7 +39,7 @@ public class Splashactivity extends AppCompatActivity { finish(); } else { - final Intent intent = new Intent(Splashactivity.this, CheckInActivity.class); + final Intent intent = new Intent(Splashactivity.this, LoginActivity.class); intent.putExtra("FromRegister", true); intent.putExtra("checkinButtonFromRegister", true); startActivity(intent); diff --git a/examples/example_bestshot/example/app/src/main/java/ru/visionlab/femdemo/login/LoginActivityNew.java b/examples/example_bestshot/example/app/src/main/java/ru/visionlab/femdemo/login/LoginActivityNew.java index 57f07b2..9c70ed4 100644 --- a/examples/example_bestshot/example/app/src/main/java/ru/visionlab/femdemo/login/LoginActivityNew.java +++ b/examples/example_bestshot/example/app/src/main/java/ru/visionlab/femdemo/login/LoginActivityNew.java @@ -4,6 +4,7 @@ import androidx.appcompat.app.AppCompatActivity; import androidx.core.app.ActivityCompat; import androidx.core.content.ContextCompat; +import android.Manifest; import android.app.AlertDialog; import android.app.ProgressDialog; import android.content.Context; @@ -12,7 +13,9 @@ import android.content.Intent; import android.content.SharedPreferences; import android.content.pm.PackageManager; import android.location.Location; +import android.location.LocationManager; import android.os.Bundle; +import android.provider.Settings; import android.util.Log; import android.view.View; import android.widget.Button; @@ -32,6 +35,10 @@ import com.android.volley.toolbox.JsonObjectRequest; import com.android.volley.toolbox.StringRequest; import com.android.volley.toolbox.Volley; import com.google.android.gms.location.FusedLocationProviderClient; +import com.google.android.gms.location.LocationCallback; +import com.google.android.gms.location.LocationRequest; +import com.google.android.gms.location.LocationResult; +import com.google.android.gms.location.LocationServices; import com.google.android.gms.tasks.OnSuccessListener; import org.json.JSONArray; @@ -92,6 +99,10 @@ public class LoginActivityNew extends AppCompatActivity { SharedPreferences sharedpreferences; String empIdShared=""; + private static final int REQUEST_LOCATION = 1; + LocationManager locationManager; + String latitude, longitude; + @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); @@ -118,6 +129,37 @@ public class LoginActivityNew extends AppCompatActivity { if(login == null || login.equals("")){ Toast.makeText(LoginActivityNew.this,"Please register before logging in ",Toast.LENGTH_SHORT).show(); } + + if (ContextCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED) { + // You have permission to access the location. + LocationRequest locationRequest = LocationRequest.create() + .setInterval(10000) // Update location every 10 seconds + .setFastestInterval(5000) // Get updates faster if available + .setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY); + + FusedLocationProviderClient fusedLocationClient = LocationServices.getFusedLocationProviderClient(this); + + fusedLocationClient.requestLocationUpdates(locationRequest, new LocationCallback() { + @Override + public void onLocationResult(LocationResult locationResult) { + Location location = locationResult.getLastLocation(); // Use the location data + String curLat = String.valueOf(location.getLatitude()); + String curLong = String.valueOf(location.getLongitude()); + + System.out.println("Value of lat and long "+ location.getLatitude() + " " + location.getLongitude()); + + SharedPreferences.Editor editor = shared.edit(); + editor.putString("Lattitude",curLat); + editor.putString("Longitude",curLong); + editor.commit(); + } + }, null); + } else { + // You need to request permission from the user. + ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.ACCESS_FINE_LOCATION}, LOCATION_PERMISSION_REQUEST_CODE); + } + + createRetrofit(); empId = edt_empId.getText().toString().trim(); @@ -193,6 +235,43 @@ public class LoginActivityNew extends AppCompatActivity { jsonPlaceHolderApi=retrofit.create(JsonPlaceHolderApi.class); } + private void OnGPS() { + final AlertDialog.Builder builder = new AlertDialog.Builder(this); + builder.setMessage("Enable GPS").setCancelable(false).setPositiveButton("Yes", new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + startActivity(new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS)); + } + }).setNegativeButton("No", new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + dialog.cancel(); + } + }); + final AlertDialog alertDialog = builder.create(); + alertDialog.show(); + } + private void getLocation() { + if (ActivityCompat.checkSelfPermission( + LoginActivityNew.this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission( + LoginActivityNew.this, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) { + ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.ACCESS_FINE_LOCATION}, REQUEST_LOCATION); + } else { + Location locationGPS = locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER); + if (locationGPS != null) { + double lat = locationGPS.getLatitude(); + double longi = locationGPS.getLongitude(); + latitude = String.valueOf(lat); + longitude = String.valueOf(longi); + + System.out.println("my lattitude and longitude "+ latitude +" "+longitude); + + } else { + Toast.makeText(LoginActivityNew.this, "Unable to find location.", Toast.LENGTH_SHORT).show(); + } + } + } + private void requestLocationUpdates() { if (ActivityCompat.checkSelfPermission(this, android.Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, android.Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) { // TODO: Consider calling