Browse Source

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 .
master
Apalak Dutta 1 year ago
parent
commit
24dc3f6a9b
3 changed files with 88 additions and 12 deletions
  1. +10
    -6
      examples/example_bestshot/example/app/src/main/java/ru/Service/MyLocationService.java
  2. +69
    -5
      examples/example_bestshot/example/app/src/main/java/ru/visionlab/femdemo/CheckInActivity.java
  3. +9
    -1
      examples/example_bestshot/example/app/src/main/java/ru/visionlab/femdemo/login/LoginActivity.java

+ 10
- 6
examples/example_bestshot/example/app/src/main/java/ru/Service/MyLocationService.java View File

@ -65,11 +65,13 @@ public class MyLocationService extends Service {
/*Intent intent = new Intent(MainActivity.this,MyLocationService.class); /*Intent intent = new Intent(MainActivity.this,MyLocationService.class);
startService(intent);*/ startService(intent);*/
if (!locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)) {
/*if (!locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)) {
OnGPS(); OnGPS();
} else { } else {
getLocation(); getLocation();
}
}*/
Toast.makeText(getApplicationContext(),"You are currently near location",Toast.LENGTH_LONG).show();
} }
}, delay); }, delay);
@ -220,11 +222,11 @@ public class MyLocationService extends Service {
{ {
double lat=LocationGps.getLatitude(); double lat=LocationGps.getLatitude();
double longi=LocationGps.getLongitude(); 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]; float[] results = new float[1];
Location.distanceBetween(lat,longi,newLat,newLong,results); Location.distanceBetween(lat,longi,newLat,newLong,results);
@ -261,6 +263,8 @@ public class MyLocationService extends Service {
double newLat = 22.5747; double newLat = 22.5747;
double newLong = 88.4338; double newLong = 88.4338;
/*double newLat = 22.5135;
double newLong = 88.4029;*/
float[] results = new float[1]; float[] results = new float[1];
Location.distanceBetween(lat,longi,newLat,newLong,results); Location.distanceBetween(lat,longi,newLat,newLong,results);


+ 69
- 5
examples/example_bestshot/example/app/src/main/java/ru/visionlab/femdemo/CheckInActivity.java View File

@ -3,6 +3,7 @@ package ru.visionlab.femdemo;
import androidx.appcompat.app.AppCompatActivity; import androidx.appcompat.app.AppCompatActivity;
import androidx.core.app.ActivityCompat; import androidx.core.app.ActivityCompat;
import android.app.ActivityManager;
import android.app.AlertDialog; import android.app.AlertDialog;
import android.app.ProgressDialog; import android.app.ProgressDialog;
import android.content.Context; import android.content.Context;
@ -52,6 +53,8 @@ public class CheckInActivity extends AppCompatActivity {
Handler handler = new Handler(); Handler handler = new Handler();
Runnable runnable; Runnable runnable;
int delay = 10000; int delay = 10000;
float distance;
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
@ -66,26 +69,33 @@ public class CheckInActivity extends AppCompatActivity {
/*Intent intent = new Intent(CheckInActivity.this, EmployeeActivity.class); /*Intent intent = new Intent(CheckInActivity.this, EmployeeActivity.class);
startActivity(intent);*/ startActivity(intent);*/
//location();
location();
progressDialog = new ProgressDialog(CheckInActivity.this);
/*progressDialog = new ProgressDialog(CheckInActivity.this);
progressDialog.setTitle(""); progressDialog.setTitle("");
progressDialog.setMessage("Loading this Content, please wait!"); progressDialog.setMessage("Loading this Content, please wait!");
progressDialog.show(); progressDialog.show();
location();
startService(new Intent(CheckInActivity.this, MyLocationService.class)); startService(new Intent(CheckInActivity.this, MyLocationService.class));
progressDialog.dismiss();
progressDialog.dismiss();*/
btnCheckIn.setVisibility(View.INVISIBLE);
} }
}); });
btncheckOut = findViewById(R.id.btncheckOut); btncheckOut = findViewById(R.id.btncheckOut);
btncheckOut.setOnClickListener(new View.OnClickListener() { btncheckOut.setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View view) { public void onClick(View view) {
Toast.makeText(CheckInActivity.this,"Stopping service",Toast.LENGTH_LONG).show(); Toast.makeText(CheckInActivity.this,"Stopping service",Toast.LENGTH_LONG).show();
stopService(new Intent(CheckInActivity.this, MyLocationService.class)); 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() { logout.setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View view) { 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(){ public void location(){
locationManager=(LocationManager) getSystemService(Context.LOCATION_SERVICE); locationManager=(LocationManager) getSystemService(Context.LOCATION_SERVICE);
//Check gps is enable or not //Check gps is enable or not
@ -198,6 +236,20 @@ public class CheckInActivity extends AppCompatActivity {
double lat=LocationGps.getLatitude(); double lat=LocationGps.getLatitude();
double longi=LocationGps.getLongitude(); 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); latitude=String.valueOf(lat);
longitude=String.valueOf(longi); longitude=String.valueOf(longi);
System.out.println("Position 1"); System.out.println("Position 1");
@ -222,6 +274,7 @@ public class CheckInActivity extends AppCompatActivity {
moreThanFour(); moreThanFour();
} }
else{ else{
lessThanFour(); lessThanFour();
} }
latitude=String.valueOf(lat); latitude=String.valueOf(lat);
@ -252,6 +305,7 @@ public class CheckInActivity extends AppCompatActivity {
} }
public void moreThanFour(){ public void moreThanFour(){
btncheckOut.setClickable(false);
new SweetAlertDialog(this, SweetAlertDialog.WARNING_TYPE) new SweetAlertDialog(this, SweetAlertDialog.WARNING_TYPE)
.setTitleText("Are you sure you are near location?") .setTitleText("Are you sure you are near location?")
.setContentText("Please be in your precise location") .setContentText("Please be in your precise location")
@ -265,6 +319,16 @@ public class CheckInActivity extends AppCompatActivity {
} }
public void lessThanFour(){ 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) new SweetAlertDialog(this, SweetAlertDialog.SUCCESS_TYPE)
.setTitleText("You are currently near location") .setTitleText("You are currently near location")
.setContentText("Attendance can be captured now") .setContentText("Attendance can be captured now")


+ 9
- 1
examples/example_bestshot/example/app/src/main/java/ru/visionlab/femdemo/login/LoginActivity.java View File

@ -79,6 +79,8 @@ public class LoginActivity extends BaseActivity {
LinearLayoutCompat lay_licence_verify; LinearLayoutCompat lay_licence_verify;
private long pressedTime;
@Override @Override
protected void onCreate(@Nullable Bundle savedInstanceState) { protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
@ -465,6 +467,12 @@ public class LoginActivity extends BaseActivity {
@Override @Override
public void onBackPressed () { 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…
Cancel
Save