@ -2,9 +2,14 @@ package ru.visionlab.femdemo;
import androidx.appcompat.app.AppCompatActivity ;
import androidx.core.app.ActivityCompat ;
import androidx.core.app.NotificationCompat ;
import android.app.ActivityManager ;
import android.app.AlertDialog ;
import android.app.Notification ;
import android.app.NotificationChannel ;
import android.app.NotificationManager ;
import android.app.PendingIntent ;
import android.app.ProgressDialog ;
import android.content.Context ;
import android.content.DialogInterface ;
@ -14,6 +19,7 @@ import android.graphics.Color;
import android.graphics.drawable.ColorDrawable ;
import android.location.Location ;
import android.location.LocationManager ;
import android.os.Build ;
import android.os.Bundle ;
import android.os.Handler ;
import android.provider.Settings ;
@ -81,14 +87,14 @@ public class CheckInActivity extends AppCompatActivity {
startService ( new Intent ( CheckInActivity . this , MyLocationService . class ) ) ;
progressDialog . dismiss ( ) ; * /
btnCheckIn . setVisibility ( View . INVISIBLE ) ;
}
} ) ;
btncheckOut = findViewById ( R . id . btncheckOut ) ;
btncheckOut . setVisibility ( View . INVISIBLE ) ;
btncheckOut . setOnClickListener ( new View . OnClickListener ( ) {
@Override
@ -96,6 +102,7 @@ public class CheckInActivity extends AppCompatActivity {
Toast . makeText ( CheckInActivity . this , "Stopping service" , Toast . LENGTH_LONG ) . show ( ) ;
stopService ( new Intent ( CheckInActivity . this , MyLocationService . class ) ) ;
btnCheckIn . setVisibility ( View . VISIBLE ) ;
btncheckOut . setVisibility ( View . INVISIBLE ) ;
}
} ) ;
@ -260,11 +267,11 @@ public class CheckInActivity extends AppCompatActivity {
double lat = LocationNetwork . getLatitude ( ) ;
double longi = LocationNetwork . getLongitude ( ) ;
/ * double newLat = 22 . 5135 ;
double newLong = 88 . 4029 ; * /
double newLat = 22 . 5118 ;
double newLong = 88 . 4001 ;
double newLat = 22 . 5150 ;
double newLong = 88 . 3930 ;
/ * double newLat = 22 . 5150 ;
double newLong = 88 . 3930 ; * /
float [ ] results = new float [ 1 ] ;
Location . distanceBetween ( lat , longi , newLat , newLong , results ) ;
@ -305,9 +312,11 @@ public class CheckInActivity extends AppCompatActivity {
}
public void moreThanFour ( ) {
stopService ( new Intent ( CheckInActivity . this , MyLocationService . class ) ) ;
btncheckOut . setClickable ( false ) ;
new SweetAlertDialog ( this , SweetAlertDialog . WARNING_TYPE )
. setTitleText ( "Are you sure you are near location? " )
. setTitleText ( "Stopping service as you are not in location " )
. setContentText ( "Please be in your precise location" )
. setConfirmText ( "OK" ) . setConfirmText ( "OK" ) . setConfirmClickListener ( new SweetAlertDialog . OnSweetClickListener ( ) {
@Override
@ -318,6 +327,49 @@ public class CheckInActivity extends AppCompatActivity {
. show ( ) ;
}
private void addNotification ( ) {
System . out . println ( "Inside addNotification" ) ;
NotificationManager mNotificationManager ;
NotificationCompat . Builder mBuilder =
new NotificationCompat . Builder ( getApplicationContext ( ) , "notify_001" ) ;
Intent ii = new Intent ( getApplicationContext ( ) , CheckInActivity . class ) ;
PendingIntent pendingIntent = PendingIntent . getActivity ( this , 0 , ii , PendingIntent . FLAG_IMMUTABLE ) ;
NotificationCompat . BigTextStyle bigText = new NotificationCompat . BigTextStyle ( ) ;
bigText . setBigContentTitle ( "Service started " ) ;
bigText . setSummaryText ( "Location getting tracked " ) ;
mBuilder . setContentIntent ( pendingIntent ) ;
mBuilder . setSmallIcon ( R . mipmap . ic_launcher ) ;
mBuilder . setContentTitle ( "Service started" ) ;
mBuilder . setContentText ( "Location getting tracked" ) ;
mBuilder . setPriority ( Notification . PRIORITY_MAX ) ;
mBuilder . setStyle ( bigText ) ;
mNotificationManager =
( NotificationManager ) getApplicationContext ( ) . getSystemService ( Context . NOTIFICATION_SERVICE ) ;
/ / = = = Removed some obsoletes
if ( Build . VERSION . SDK_INT > = Build . VERSION_CODES . O )
{
String channelId = "Your_channel_id" ;
NotificationChannel channel = new NotificationChannel (
channelId ,
"Channel human readable title" ,
NotificationManager . IMPORTANCE_HIGH ) ;
mNotificationManager . createNotificationChannel ( channel ) ;
mBuilder . setChannelId ( channelId ) ;
}
mNotificationManager . notify ( 0 , mBuilder . build ( ) ) ;
System . out . println ( "Inside add notific" ) ;
}
public void lessThanFour ( ) {
progressDialog = new ProgressDialog ( CheckInActivity . this ) ;
progressDialog . setTitle ( "" ) ;
@ -325,10 +377,13 @@ public class CheckInActivity extends AppCompatActivity {
progressDialog . show ( ) ;
addNotification ( ) ;
startService ( new Intent ( CheckInActivity . this , MyLocationService . class ) ) ;
progressDialog . dismiss ( ) ;
btnCheckIn . setVisibility ( View . INVISIBLE ) ;
btncheckOut . setVisibility ( View . VISIBLE ) ;
new SweetAlertDialog ( this , SweetAlertDialog . SUCCESS_TYPE )
. setTitleText ( "You are currently near location" )
. setContentText ( "Attendance can be captured now" )