25-09-2023 15:25
This commit is contained in:
parent
480edeb18c
commit
c67434d25c
@ -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<HashMap<String,String>> 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<String>() {
|
||||
@Override
|
||||
public void onResponse(String response) {
|
||||
|
@ -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<String>() {
|
||||
@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<String, String> getParams() {
|
||||
Map<String, String> params = new HashMap<String, String>();
|
||||
|
||||
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<String, String> getParams() {
|
||||
Map<String, String> params = new HashMap<String, String>();
|
||||
|
||||
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<String, String> getParams() {
|
||||
Map<String, String> params = new HashMap<String, String>();
|
||||
|
||||
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<String>() {
|
||||
@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<jsonArray.length();i++){
|
||||
for(int i=0;i<jsonArray.length();i++){
|
||||
JSONObject jb1=jsonArray.getJSONObject(i);
|
||||
targetLat1=jb1.getString("Latitude");
|
||||
|
||||
LocName = jb1.getString("LocName");
|
||||
Latitude = jb1.getString("Latitude");
|
||||
Longitude = jb1.getString("Longitude");
|
||||
Limit = jb1.getString("Limit");
|
||||
|
||||
Location current = new Location("");
|
||||
current.setLatitude(Double.parseDouble(Latitude));
|
||||
current.setLongitude(Double.parseDouble(Longitude));
|
||||
|
||||
if(Latitude.equals("22.5807° N")){
|
||||
Latitude = "22.5807";
|
||||
|
||||
}
|
||||
if(Longitude.equals("88.4363° E")){
|
||||
Longitude = "88.4363";
|
||||
}
|
||||
|
||||
Location target = new Location("");
|
||||
target.setLatitude(Double.parseDouble(Latitude));
|
||||
target.setLongitude(Double.parseDouble(Longitude));
|
||||
|
||||
float distance = current.distanceTo(target);
|
||||
|
||||
System.out.println("Value of distance " + distance);
|
||||
|
||||
|
||||
|
||||
if(distance <= Float.valueOf(Limit)){
|
||||
Toast.makeText(CheckInActivity.this, "Attendance ready to be captured", Toast.LENGTH_SHORT).show();
|
||||
checkIn();
|
||||
break;
|
||||
|
||||
}
|
||||
else {
|
||||
|
||||
Toast.makeText(CheckInActivity.this, "You are out of range!Please get back to location", Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/*if(currentLat.equals(Latitude) || currentlong.equals(Longitude)){
|
||||
|
||||
if(Latitude.equals("22.5807° N")){
|
||||
Latitude = "22.5807";
|
||||
|
||||
}
|
||||
if(Longitude.equals("88.4363° E")){
|
||||
Longitude = "88.4363";
|
||||
}
|
||||
|
||||
Location target = new Location("");
|
||||
target.setLatitude(Double.parseDouble(Latitude));
|
||||
target.setLongitude(Double.parseDouble(Longitude));
|
||||
|
||||
float distance = current.distanceTo(target);
|
||||
|
||||
System.out.println("Value of distance " + distance);
|
||||
|
||||
|
||||
|
||||
if(distance <= Float.valueOf(Limit)){
|
||||
Toast.makeText(CheckInActivity.this, "Attendance ready to be captured", Toast.LENGTH_SHORT).show();
|
||||
checkIn();
|
||||
break;
|
||||
|
||||
}
|
||||
else {
|
||||
|
||||
// Toast.makeText(CheckInActivity.this, "You are out of range!Please get back to location", Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
else {
|
||||
Toast.makeText(CheckInActivity.this, "You are out of range!Please get back to location", Toast.LENGTH_SHORT).show();
|
||||
// is_out_of_location = true;
|
||||
}*/
|
||||
|
||||
|
||||
}
|
||||
|
||||
/* if(is_out_of_location){
|
||||
Toast.makeText(CheckInActivity.this, "You are out of range!Please get back to location", Toast.LENGTH_SHORT).show();
|
||||
}*/
|
||||
JSONObject jb1=jsonArray.getJSONObject(0);
|
||||
/*JSONObject jb1=jsonArray.getJSONObject(0);
|
||||
targetLat1= jb1.getString("Latitude");
|
||||
targetLon1 = jb1.getString("Longitude");
|
||||
|
||||
@ -750,18 +857,19 @@ public class CheckInActivity extends AppCompatActivity {
|
||||
|
||||
Toast.makeText(CheckInActivity.this, "Attendance ready to be captured", Toast.LENGTH_SHORT).show();
|
||||
checkIn();
|
||||
/*Intent intent = new Intent(CheckInActivity.this, RegisterActivity.class);
|
||||
*//*Intent intent = new Intent(CheckInActivity.this, RegisterActivity.class);
|
||||
intent.putExtra("FromLoginPage",true);
|
||||
startActivity(intent);*/
|
||||
startActivity(intent);*//*
|
||||
|
||||
}
|
||||
}*/
|
||||
|
||||
} catch (JSONException e) {
|
||||
}
|
||||
catch (JSONException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
loading.dismiss();
|
||||
Toast.makeText(CheckInActivity.this, "Data added to API", Toast.LENGTH_SHORT).show();
|
||||
//Toast.makeText(CheckInActivity.this, "Data added to API", Toast.LENGTH_SHORT).show();
|
||||
|
||||
|
||||
|
||||
@ -784,7 +892,7 @@ public class CheckInActivity extends AppCompatActivity {
|
||||
|
||||
public void targetLocationListFromCheckOut(){
|
||||
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<String>() {
|
||||
@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<jsonArray.length();i++){
|
||||
for(int i=0;i<jsonArray.length();i++){
|
||||
JSONObject jb1=jsonArray.getJSONObject(i);
|
||||
targetLat1=jb1.getString("Latitude");
|
||||
|
||||
LocName = jb1.getString("LocName");
|
||||
Latitude = jb1.getString("Latitude");
|
||||
Longitude = jb1.getString("Longitude");
|
||||
Limit = jb1.getString("Limit");
|
||||
|
||||
if(Latitude.equals("22.5807° N")){
|
||||
Latitude = "22.5807";
|
||||
|
||||
}
|
||||
if(Longitude.equals("88.4363° E")){
|
||||
Longitude = "88.4363";
|
||||
}
|
||||
|
||||
Location current = new Location("");
|
||||
current.setLatitude(Double.parseDouble(Latitude));
|
||||
current.setLongitude(Double.parseDouble(Longitude));
|
||||
|
||||
|
||||
|
||||
Location target = new Location("");
|
||||
target.setLatitude(Double.parseDouble(Latitude));
|
||||
target.setLongitude(Double.parseDouble(Longitude));
|
||||
|
||||
float distance = current.distanceTo(target);
|
||||
|
||||
System.out.println("Value of distance " + distance);
|
||||
|
||||
if(distance <= Float.valueOf(Limit)){
|
||||
Toast.makeText(CheckInActivity.this, "Attendance ready to be captured", Toast.LENGTH_SHORT).show();
|
||||
checkOut();
|
||||
}
|
||||
else {
|
||||
Toast.makeText(CheckInActivity.this, "You are out of range!Please get back to location", Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
/* if(is_out_of_location){
|
||||
Toast.makeText(CheckInActivity.this, "You are out of range!Please get back to location", Toast.LENGTH_SHORT).show();
|
||||
}*/
|
||||
JSONObject jb1=jsonArray.getJSONObject(0);
|
||||
/*JSONObject jb1=jsonArray.getJSONObject(0);
|
||||
targetLat1= jb1.getString("Latitude");
|
||||
targetLon1 = jb1.getString("Longitude");
|
||||
|
||||
@ -826,19 +973,20 @@ public class CheckInActivity extends AppCompatActivity {
|
||||
else{
|
||||
|
||||
Toast.makeText(CheckInActivity.this, "Attendance ready to be captured", Toast.LENGTH_SHORT).show();
|
||||
checkOut();
|
||||
/*Intent intent = new Intent(CheckInActivity.this, RegisterActivity.class);
|
||||
checkIn();
|
||||
*//*Intent intent = new Intent(CheckInActivity.this, RegisterActivity.class);
|
||||
intent.putExtra("FromLoginPage",true);
|
||||
startActivity(intent);*/
|
||||
startActivity(intent);*//*
|
||||
|
||||
}
|
||||
}*/
|
||||
|
||||
} catch (JSONException e) {
|
||||
}
|
||||
catch (JSONException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
loading.dismiss();
|
||||
Toast.makeText(CheckInActivity.this, "Data added to API", Toast.LENGTH_SHORT).show();
|
||||
// Toast.makeText(CheckInActivity.this, "Data added to API", Toast.LENGTH_SHORT).show();
|
||||
|
||||
|
||||
}
|
||||
|
@ -5,6 +5,7 @@ import androidx.appcompat.app.AppCompatActivity;
|
||||
import android.app.ProgressDialog;
|
||||
import android.app.TimePickerDialog;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.os.Bundle;
|
||||
import android.view.View;
|
||||
import android.widget.AdapterView;
|
||||
@ -42,14 +43,17 @@ public class PermissionRequestActivity extends AppCompatActivity {
|
||||
EditText edtRemarks;
|
||||
String remarks="";
|
||||
LinearLayout timePickerFrom,timePickerTo;
|
||||
private int mDay, mHour, mMinute;
|
||||
private int mDayFrom,mMonthFrom,mMonthTo,mYearFrom,mYearTo,mDayTo, mHour, mMinute;
|
||||
TextView textTimeFrom,textTimeTo;
|
||||
|
||||
LinearLayout linearLayout1;
|
||||
|
||||
Spinner spinner;
|
||||
|
||||
String permission_type;
|
||||
String permission_type,permission_code;
|
||||
|
||||
String Employeeid,Permission_code_o,Permission_code_p;
|
||||
String fromDate,toDate,fromTime,toTime;
|
||||
|
||||
|
||||
@Override
|
||||
@ -58,6 +62,10 @@ public class PermissionRequestActivity extends AppCompatActivity {
|
||||
setContentView(R.layout.activity_permission_request);
|
||||
linearLayout1 = findViewById(R.id.linearLayout1);
|
||||
|
||||
SharedPreferences shared = getSharedPreferences("MyPrefs", MODE_PRIVATE);
|
||||
|
||||
Employeeid = shared.getString("Employeeid", "");
|
||||
|
||||
IsELeaveApprover();
|
||||
//PermissionInsert();
|
||||
PermissionApprovalList();
|
||||
@ -123,6 +131,10 @@ public class PermissionRequestActivity extends AppCompatActivity {
|
||||
final Calendar c = Calendar.getInstance();
|
||||
mHour = c.get(Calendar.HOUR_OF_DAY);
|
||||
mMinute = c.get(Calendar.MINUTE);
|
||||
mDayFrom = c.get(Calendar.DATE);
|
||||
mMonthFrom = c.get(Calendar.MONTH);
|
||||
mYearFrom = c.get(Calendar.YEAR);
|
||||
|
||||
|
||||
// Launch Time Picker Dialog
|
||||
TimePickerDialog timePickerDialog = new TimePickerDialog(PermissionRequestActivity.this,
|
||||
@ -138,6 +150,9 @@ public class PermissionRequestActivity extends AppCompatActivity {
|
||||
}
|
||||
}, mHour, mMinute, false);
|
||||
timePickerDialog.show();
|
||||
fromTime = mHour+ ":" + mMinute;
|
||||
fromDate = mDayFrom + "/" + (mMonthFrom+1)+"/"+mYearFrom;
|
||||
System.out.println("date from "+fromDate + " "+ fromTime);
|
||||
}
|
||||
});
|
||||
timePickerTo = findViewById(R.id.timePickerTo);
|
||||
@ -148,6 +163,9 @@ public class PermissionRequestActivity extends AppCompatActivity {
|
||||
final Calendar c = Calendar.getInstance();
|
||||
mHour = c.get(Calendar.HOUR_OF_DAY);
|
||||
mMinute = c.get(Calendar.MINUTE);
|
||||
mDayTo = c.get(Calendar.DATE);
|
||||
mMonthTo = c.get(Calendar.MONTH);
|
||||
mYearTo = c.get(Calendar.YEAR);
|
||||
|
||||
// Launch Time Picker Dialog
|
||||
TimePickerDialog timePickerDialog = new TimePickerDialog(PermissionRequestActivity.this,
|
||||
@ -163,6 +181,12 @@ public class PermissionRequestActivity extends AppCompatActivity {
|
||||
}
|
||||
}, mHour, mMinute, false);
|
||||
timePickerDialog.show();
|
||||
|
||||
toDate = mDayTo + "/" + (mMonthTo+1)+"/"+mYearTo;
|
||||
|
||||
|
||||
|
||||
System.out.println("date to "+mDayTo);
|
||||
}
|
||||
});
|
||||
|
||||
@ -210,16 +234,26 @@ public class PermissionRequestActivity extends AppCompatActivity {
|
||||
protected Map<String, String> getParams() {
|
||||
Map<String, String> params = new HashMap<String, String>();
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user