On pressing the logout button ,the app is checking whether location service is running or not .
On pressing the Check in button it disappears and reappears when the check out button is pressed . On pressing the back button on the login activity the app exits . Service starting only when the Check in button is pressed . Check out button cannot be pressed outside range .
This commit is contained in:
parent
7366fc3c64
commit
24dc3f6a9b
@ -65,11 +65,13 @@ public class MyLocationService extends Service {
|
||||
/*Intent intent = new Intent(MainActivity.this,MyLocationService.class);
|
||||
startService(intent);*/
|
||||
|
||||
if (!locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)) {
|
||||
/*if (!locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)) {
|
||||
OnGPS();
|
||||
} else {
|
||||
getLocation();
|
||||
}
|
||||
}*/
|
||||
|
||||
Toast.makeText(getApplicationContext(),"You are currently near location",Toast.LENGTH_LONG).show();
|
||||
|
||||
}
|
||||
}, delay);
|
||||
@ -220,11 +222,11 @@ public class MyLocationService extends Service {
|
||||
{
|
||||
double lat=LocationGps.getLatitude();
|
||||
double longi=LocationGps.getLongitude();
|
||||
/*double newLat = 22.5747;
|
||||
double newLong = 88.4338;*/
|
||||
double newLat = 22.5747;
|
||||
double newLong = 88.4338;
|
||||
|
||||
double newLat = 22.5796;
|
||||
double newLong = 88.4383;
|
||||
/*double newLat = 22.5796;
|
||||
double newLong = 88.4383;*/
|
||||
|
||||
float[] results = new float[1];
|
||||
Location.distanceBetween(lat,longi,newLat,newLong,results);
|
||||
@ -261,6 +263,8 @@ public class MyLocationService extends Service {
|
||||
|
||||
double newLat = 22.5747;
|
||||
double newLong = 88.4338;
|
||||
/*double newLat = 22.5135;
|
||||
double newLong = 88.4029;*/
|
||||
|
||||
float[] results = new float[1];
|
||||
Location.distanceBetween(lat,longi,newLat,newLong,results);
|
||||
|
@ -3,6 +3,7 @@ package ru.visionlab.femdemo;
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
import androidx.core.app.ActivityCompat;
|
||||
|
||||
import android.app.ActivityManager;
|
||||
import android.app.AlertDialog;
|
||||
import android.app.ProgressDialog;
|
||||
import android.content.Context;
|
||||
@ -52,6 +53,8 @@ public class CheckInActivity extends AppCompatActivity {
|
||||
Handler handler = new Handler();
|
||||
Runnable runnable;
|
||||
int delay = 10000;
|
||||
|
||||
float distance;
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
@ -66,26 +69,33 @@ public class CheckInActivity extends AppCompatActivity {
|
||||
/*Intent intent = new Intent(CheckInActivity.this, EmployeeActivity.class);
|
||||
startActivity(intent);*/
|
||||
|
||||
//location();
|
||||
location();
|
||||
|
||||
progressDialog = new ProgressDialog(CheckInActivity.this);
|
||||
/*progressDialog = new ProgressDialog(CheckInActivity.this);
|
||||
progressDialog.setTitle("");
|
||||
progressDialog.setMessage("Loading this Content, please wait!");
|
||||
progressDialog.show();
|
||||
|
||||
location();
|
||||
|
||||
startService(new Intent(CheckInActivity.this, MyLocationService.class));
|
||||
progressDialog.dismiss();
|
||||
progressDialog.dismiss();*/
|
||||
|
||||
btnCheckIn.setVisibility(View.INVISIBLE);
|
||||
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
btncheckOut = findViewById(R.id.btncheckOut);
|
||||
|
||||
|
||||
btncheckOut.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
Toast.makeText(CheckInActivity.this,"Stopping service",Toast.LENGTH_LONG).show();
|
||||
stopService(new Intent(CheckInActivity.this, MyLocationService.class));
|
||||
btnCheckIn.setVisibility(View.VISIBLE);
|
||||
}
|
||||
});
|
||||
|
||||
@ -93,8 +103,26 @@ public class CheckInActivity extends AppCompatActivity {
|
||||
logout.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
Intent intent = new Intent(CheckInActivity.this, LoginActivity.class);
|
||||
startActivity(intent);
|
||||
|
||||
|
||||
if (isMyServiceRunning(MyLocationService.class)){
|
||||
new SweetAlertDialog(CheckInActivity.this, SweetAlertDialog.WARNING_TYPE)
|
||||
.setTitleText("Location service is running in the background")
|
||||
.setContentText("Please stop the service to logout")
|
||||
.setConfirmText("OK").setConfirmText("OK").setConfirmClickListener(new SweetAlertDialog.OnSweetClickListener() {
|
||||
@Override
|
||||
public void onClick(SweetAlertDialog sDialog) {
|
||||
sDialog.dismissWithAnimation();
|
||||
}
|
||||
})
|
||||
.show();
|
||||
}
|
||||
else {
|
||||
Toast.makeText(CheckInActivity.this,"Logging out",Toast.LENGTH_LONG).show();
|
||||
Intent intent = new Intent(CheckInActivity.this, LoginActivity.class);
|
||||
startActivity(intent);
|
||||
}
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
@ -141,6 +169,16 @@ public class CheckInActivity extends AppCompatActivity {
|
||||
|
||||
}
|
||||
|
||||
private boolean isMyServiceRunning(Class<?> serviceClass) {
|
||||
ActivityManager manager = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
|
||||
for (ActivityManager.RunningServiceInfo service : manager.getRunningServices(Integer.MAX_VALUE)) {
|
||||
if (serviceClass.getName().equals(service.service.getClassName())) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public void location(){
|
||||
locationManager=(LocationManager) getSystemService(Context.LOCATION_SERVICE);
|
||||
//Check gps is enable or not
|
||||
@ -198,6 +236,20 @@ public class CheckInActivity extends AppCompatActivity {
|
||||
double lat=LocationGps.getLatitude();
|
||||
double longi=LocationGps.getLongitude();
|
||||
|
||||
double newLat = 22.5150;
|
||||
double newLong = 88.3930;
|
||||
|
||||
float[] results = new float[1];
|
||||
Location.distanceBetween(lat,longi,newLat,newLong,results);
|
||||
distance = results[0];
|
||||
Toast.makeText(this,String.valueOf(distance)+" metres from location",Toast.LENGTH_SHORT).show();
|
||||
if(distance > 400){
|
||||
moreThanFour();
|
||||
}
|
||||
else{
|
||||
lessThanFour();
|
||||
}
|
||||
|
||||
latitude=String.valueOf(lat);
|
||||
longitude=String.valueOf(longi);
|
||||
System.out.println("Position 1");
|
||||
@ -222,6 +274,7 @@ public class CheckInActivity extends AppCompatActivity {
|
||||
moreThanFour();
|
||||
}
|
||||
else{
|
||||
|
||||
lessThanFour();
|
||||
}
|
||||
latitude=String.valueOf(lat);
|
||||
@ -252,6 +305,7 @@ public class CheckInActivity extends AppCompatActivity {
|
||||
}
|
||||
|
||||
public void moreThanFour(){
|
||||
btncheckOut.setClickable(false);
|
||||
new SweetAlertDialog(this, SweetAlertDialog.WARNING_TYPE)
|
||||
.setTitleText("Are you sure you are near location?")
|
||||
.setContentText("Please be in your precise location")
|
||||
@ -265,6 +319,16 @@ public class CheckInActivity extends AppCompatActivity {
|
||||
}
|
||||
|
||||
public void lessThanFour(){
|
||||
progressDialog = new ProgressDialog(CheckInActivity.this);
|
||||
progressDialog.setTitle("");
|
||||
progressDialog.setMessage("Loading this Content, please wait!");
|
||||
progressDialog.show();
|
||||
|
||||
|
||||
|
||||
startService(new Intent(CheckInActivity.this, MyLocationService.class));
|
||||
progressDialog.dismiss();
|
||||
|
||||
new SweetAlertDialog(this, SweetAlertDialog.SUCCESS_TYPE)
|
||||
.setTitleText("You are currently near location")
|
||||
.setContentText("Attendance can be captured now")
|
||||
|
@ -79,6 +79,8 @@ public class LoginActivity extends BaseActivity {
|
||||
|
||||
LinearLayoutCompat lay_licence_verify;
|
||||
|
||||
private long pressedTime;
|
||||
|
||||
@Override
|
||||
protected void onCreate(@Nullable Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
@ -465,6 +467,12 @@ public class LoginActivity extends BaseActivity {
|
||||
|
||||
@Override
|
||||
public void onBackPressed () {
|
||||
|
||||
if (pressedTime + 2000 > System.currentTimeMillis()) {
|
||||
super.onBackPressed();
|
||||
finish();
|
||||
} else {
|
||||
Toast.makeText(getBaseContext(), "Press back again to exit", Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
pressedTime = System.currentTimeMillis();
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user