@ -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" )