Compare commits

...

5 Commits

Author SHA1 Message Date
1540c289c8 Bug fixes 2023-06-28 11:43:08 +05:30
c459dc9a8d If service is on check out is visible if not check in is visible . (Done)
Check in will be invisible only if inside location or else not . (Done)

Service and location tracking notification is only active when the user is within 400 metres of the precise location . Service , notification and the check out button will not work when the user is outside 400 metres to the precise location . (Done)
2023-06-27 18:02:50 +05:30
24dc3f6a9b 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 .
2023-06-26 21:45:35 +05:30
7366fc3c64 Implemented notification , progress dialog after entering radius of a given location in the Luna application . 2023-06-23 20:39:32 +05:30
ef5153765f Displayed dialog for distance from location 2023-06-21 18:33:12 +05:30
12 changed files with 996 additions and 62 deletions

View File

@ -172,6 +172,7 @@ dependencies {
implementation 'com.trello:rxlifecycle-components:1.0' implementation 'com.trello:rxlifecycle-components:1.0'
implementation 'androidx.legacy:legacy-support-v4:1.0.0' implementation 'androidx.legacy:legacy-support-v4:1.0.0'
implementation 'com.google.android.material:material:1.0.0' implementation 'com.google.android.material:material:1.0.0'
implementation 'com.github.f0ris.sweetalert:library:1.5.1'

View File

@ -1,5 +1,6 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"> <manifest xmlns:tools="http://schemas.android.com/tools"
xmlns:android="http://schemas.android.com/apk/res/android">
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" /> <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
@ -16,13 +17,19 @@
<uses-feature android:name="android.hardware.camera.autofocus" /> <uses-feature android:name="android.hardware.camera.autofocus" />
<uses-feature android:name="android.hardware.camera.flash" /> <uses-feature android:name="android.hardware.camera.flash" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE"/>
<application <application
android:name=".App" android:name=".App"
android:allowBackup="false" android:allowBackup="false"
android:icon="@mipmap/ic_launcher" android:icon="@mipmap/ic_launcher"
android:label="@string/app_name" android:label="@string/app_name"
android:supportsRtl="true" android:supportsRtl="true"
android:theme="@style/AppTheme"> android:theme="@style/AppTheme"
tools:replace="android:icon,android:allowBackup">
<activity
android:name=".views.EmployeeActivity"
android:exported="false" />
<activity <activity
android:name=".register.SavePhotoActivity" android:name=".register.SavePhotoActivity"
android:exported="false" /> android:exported="false" />
@ -68,6 +75,7 @@
<activity <activity
android:name=".authentication.AuthSuccessActivity" android:name=".authentication.AuthSuccessActivity"
android:screenOrientation="portrait" /> android:screenOrientation="portrait" />
<service android:name="ru.Service.MyLocationService"/>
</application> </application>
</manifest> </manifest>

View File

@ -0,0 +1,357 @@
package ru.Service;
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.app.Service;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.location.Location;
import android.location.LocationManager;
import android.os.Build;
import android.os.Handler;
import android.os.IBinder;
import android.provider.Settings;
import android.widget.Toast;
import androidx.annotation.Nullable;
import androidx.core.app.ActivityCompat;
import androidx.core.app.NotificationCompat;
import ru.visionlab.femdemo.CheckInActivity;
import ru.visionlab.femdemo.R;
public class MyLocationService extends Service {
LocationManager locationManager;
private static final int REQUEST_LOCATION = 1;
String latitude, longitude;
ProgressDialog progressDialog;
Handler handler = new Handler();
Runnable runnable;
int delay = 10000;
@Override
// execution of service will start
// on calling this method
public int onStartCommand(Intent intent, int flags, int startId) {
System.out.println("Inside my location service");
locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
//addNotification();
trackGPS();
// returns the status
// of the program
return START_STICKY;
}
private void trackGPS() {
handler.postDelayed(runnable = new Runnable() {
public void run() {
System.out.println("Inside handler");
/*Intent intent = new Intent(MainActivity.this,MyLocationService.class);
startService(intent);*/
/*if (!locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)) {
OnGPS();
} else {
getLocation();
}*/
locationNotification();
Toast.makeText(getApplicationContext(),"You are currently near location",Toast.LENGTH_LONG).show();
}
}, delay);
handler.postDelayed(runnable, delay);
}
@Override
// execution of the service will
// stop on calling this method
public void onDestroy() {
handler.removeCallbacks(runnable);
super.onDestroy();
}
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");
/*NotificationCompat.Builder builder =
new NotificationCompat.Builder(this)
.setSmallIcon(R.drawable.ic_launcher_background)
.setContentTitle("Notifications Example")
.setContentText("This is a test notification")
.setPriority(NotificationCompat.PRIORITY_DEFAULT);
Intent notificationIntent = new Intent(this, MainActivity.class);
PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent,
PendingIntent.FLAG_IMMUTABLE);
builder.setContentIntent(contentIntent);
// Add as notification
NotificationManager manager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
manager.notify(0, builder.build());*/
}
private void locationNotification() {
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("Location notification");
bigText.setSummaryText("Entered location perimeter");
mBuilder.setContentIntent(pendingIntent);
mBuilder.setSmallIcon(R.mipmap.ic_launcher);
mBuilder.setContentTitle("Location notification");
mBuilder.setContentText("Entered location perimeter");
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 location notification");
/*NotificationCompat.Builder builder =
new NotificationCompat.Builder(this)
.setSmallIcon(R.drawable.ic_launcher_background)
.setContentTitle("Notifications Example")
.setContentText("This is a test notification")
.setPriority(NotificationCompat.PRIORITY_DEFAULT);
Intent notificationIntent = new Intent(this, MainActivity.class);
PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent,
PendingIntent.FLAG_IMMUTABLE);
builder.setContentIntent(contentIntent);
// Add as notification
NotificationManager manager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
manager.notify(0, builder.build());*/
}
private void getLocation() {
//Check Permissions again
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
// ActivityCompat#requestPermissions
// here to request the missing permissions, and then overriding
// public void onRequestPermissionsResult(int requestCode, String[] permissions,
// int[] grantResults)
// to handle the case where the user grants the permission. See the documentation
// for ActivityCompat#requestPermissions for more details.
return;
}
Location LocationGps = locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);
Location LocationNetwork=locationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
Location LocationPassive=locationManager.getLastKnownLocation(LocationManager.PASSIVE_PROVIDER);
if (LocationGps !=null)
{
double lat=LocationGps.getLatitude();
double longi=LocationGps.getLongitude();
double newLat = 22.5747;
double newLong = 88.4338;
/*double newLat = 22.5796;
double newLong = 88.4383;*/
float[] results = new float[1];
Location.distanceBetween(lat,longi,newLat,newLong,results);
float distance = results[0];
Toast.makeText(this,String.valueOf(distance)+" metres from location",Toast.LENGTH_LONG).show();
if(distance > 400){
Toast.makeText(this,"You are outside location range",Toast.LENGTH_LONG).show();
System.out.println("You are outside location range");
System.out.println("Position 1 ");
//moreThanFour();
}
else{
Toast.makeText(this,"You are inside location range",Toast.LENGTH_LONG).show();
locationNotification();
System.out.println("You are inside location range");
System.out.println("Position 2 ");
//lessThanFour();
}
latitude=String.valueOf(lat);
longitude=String.valueOf(longi);
latitude=String.valueOf(lat);
longitude=String.valueOf(longi);
System.out.println("Inside getLocation");
}
else if (LocationNetwork !=null)
{
System.out.println("Position 3 ");
double lat=LocationNetwork.getLatitude();
double longi=LocationNetwork.getLongitude();
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);
float distance = results[0];
Toast.makeText(this,String.valueOf(distance)+" metres from location",Toast.LENGTH_LONG).show();
if(distance > 400){
Toast.makeText(this,"You are outside location range",Toast.LENGTH_LONG).show();
System.out.println("You are outside location range");
//moreThanFour();
}
else{
Toast.makeText(this,"You are inside location range",Toast.LENGTH_LONG).show();
System.out.println("You are inside location range");
//lessThanFour();
}
latitude=String.valueOf(lat);
longitude=String.valueOf(longi);
latitude=String.valueOf(lat);
longitude=String.valueOf(longi);
}
else if (LocationPassive !=null)
{
double lat=LocationPassive.getLatitude();
double longi=LocationPassive.getLongitude();
latitude=String.valueOf(lat);
longitude=String.valueOf(longi);
}
else
{
// Toast.makeText(this, "Can't Get Your Location", Toast.LENGTH_SHORT).show();
double lat=LocationNetwork.getLatitude();
double longi=LocationNetwork.getLongitude();
double newLat = 22.5747;
double newLong = 88.4338;
float[] results = new float[1];
Location.distanceBetween(lat,longi,newLat,newLong,results);
float distance = results[0];
Toast.makeText(this,String.valueOf(distance)+" metres from location",Toast.LENGTH_LONG).show();
if(distance > 400){
Toast.makeText(this,"You are outside location range",Toast.LENGTH_LONG).show();
System.out.println("You are outside location range");
//moreThanFour();
}
else{
Toast.makeText(this,"You are inside location range",Toast.LENGTH_LONG).show();
System.out.println("You are inside location range");
//lessThanFour();
}
}
//Thats All Run Your App
}
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();
System.out.println("Inside OnGPS");
}
@Nullable
@Override
public IBinder onBind(Intent intent) {
return null;
}
}

View File

@ -0,0 +1,6 @@
package ru.visionlab.constant;
public class LatLong {
public static final double newLat= 22.5118;
public static final double newLong= 88.4001;
}

View File

@ -3,4 +3,5 @@ package ru.visionlab.constant;
public class Url { public class Url {
public static final String Base_url= "https://reqres.in/api/"; public static final String Base_url= "https://reqres.in/api/";
} }

View File

@ -1,13 +1,28 @@
package ru.visionlab.femdemo; package ru.visionlab.femdemo;
import androidx.appcompat.app.AppCompatActivity; 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.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; import android.content.DialogInterface;
import android.content.Intent; import android.content.Intent;
import android.content.pm.PackageManager;
import android.graphics.Color; import android.graphics.Color;
import android.graphics.drawable.ColorDrawable; import android.graphics.drawable.ColorDrawable;
import android.location.Location;
import android.location.LocationManager;
import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
import android.os.Handler;
import android.provider.Settings;
import android.view.Gravity; import android.view.Gravity;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.MenuItem; import android.view.MenuItem;
@ -19,16 +34,34 @@ import android.widget.PopupMenu;
import android.widget.TextView; import android.widget.TextView;
import android.widget.Toast; import android.widget.Toast;
import cn.pedant.SweetAlert.SweetAlertDialog;
import ru.Service.MyLocationService;
import ru.visionlab.constant.LatLong;
import ru.visionlab.femdemo.login.LoginActivity; import ru.visionlab.femdemo.login.LoginActivity;
import ru.visionlab.femdemo.register.RegisterActivityNew; import ru.visionlab.femdemo.register.RegisterActivityNew;
import ru.visionlab.femdemo.views.EmployeeActivity;
public class CheckInActivity extends AppCompatActivity { public class CheckInActivity extends AppCompatActivity {
private static final int REQUEST_LOCATION=1;
ImageView logout; ImageView logout;
ImageView menu; ImageView menu;
AlertDialog dialogBuilder; AlertDialog dialogBuilder;
Button btnCheckIn,btncheckOut;
LocationManager locationManager;
String latitude,longitude;
ProgressDialog progressDialog;
Handler handler = new Handler();
Runnable runnable;
int delay = 10000;
float distance;
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
@ -36,11 +69,68 @@ public class CheckInActivity extends AppCompatActivity {
logout = findViewById(R.id.logout); logout = findViewById(R.id.logout);
btnCheckIn = findViewById(R.id.btnCheckIn);
btnCheckIn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
/*Intent intent = new Intent(CheckInActivity.this, EmployeeActivity.class);
startActivity(intent);*/
location();
/*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();*/
}
});
btncheckOut = findViewById(R.id.btncheckOut);
btncheckOut.setVisibility(View.INVISIBLE);
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);
btncheckOut.setVisibility(View.INVISIBLE);
}
});
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);
}
} }
}); });
@ -58,19 +148,11 @@ public class CheckInActivity extends AppCompatActivity {
public void onClick(View view) { public void onClick(View view) {
Intent intent = new Intent(CheckInActivity.this, LoginActivity.class); Intent intent = new Intent(CheckInActivity.this, LoginActivity.class);
startActivity(intent); startActivity(intent);
} }
}); });
/*Button btn_confirm = view.findViewById(R.id.btn_confirm);
Button btn_cancel = view.findViewById(R.id.btn_cancel);
TextView txt_title = view.findViewById(R.id.txt_title);
TextView txt_content = view.findViewById(R.id.txt_content);
btn_cancel.setVisibility(View.GONE);
btn_confirm.setText("OK");
txt_title.setText("WARNING");
txt_content.setText("This job is not active. Please synchronize to get the latest data, then contact your coordinator if needed.");*/
final AlertDialog alertDialog = new AlertDialog.Builder(CheckInActivity.this) final AlertDialog alertDialog = new AlertDialog.Builder(CheckInActivity.this)
@ -87,59 +169,232 @@ public class CheckInActivity extends AppCompatActivity {
params.horizontalMargin = -100; params.horizontalMargin = -100;
alertDialog.getWindow().setAttributes(params); alertDialog.getWindow().setAttributes(params);
/*btn_confirm.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
alertDialog.cancel();
}
});
btn_cancel.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
alertDialog.cancel();
}
});*/
} }
}); });
/*menu.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
// instance of alert dialog to build alert dialog
AlertDialog.Builder builder = new AlertDialog.Builder(CheckInActivity.this);
builder.setIcon(R.drawable.andrew);
builder.setTitle("Andrew Bahl");
// builder.setMessage("Bottom Alert dialog");
// set the neutral button to do some actions
builder.setNeutralButton("Logout", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Intent intent = new Intent(CheckInActivity.this, LoginActivity.class);
startActivity(intent);
}
});
// show the alert dialog }
AlertDialog alertDialog = builder.create();
alertDialog.show(); private boolean isMyServiceRunning(Class<?> serviceClass) {
alertDialog.getWindow().setLayout(800,400); ActivityManager manager = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
alertDialog.getWindow().setGravity(Gravity.TOP); for (ActivityManager.RunningServiceInfo service : manager.getRunningServices(Integer.MAX_VALUE)) {
*//*PopupMenu popupMenu = new PopupMenu(CheckInActivity.this, menu); if (serviceClass.getName().equals(service.service.getClassName())) {
popupMenu.getMenuInflater().inflate(R.menu.navigation_menu, popupMenu.getMenu()); return true;
popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem menuItem) {
// Toast message on menu item clicked
Toast.makeText(CheckInActivity.this, "You Clicked " + menuItem.getTitle(), Toast.LENGTH_SHORT).show();
return true;
}
});
// Showing the popup menu
popupMenu.show();*//*
} }
});*/ }
return false;
}
public void location(){
locationManager=(LocationManager) getSystemService(Context.LOCATION_SERVICE);
//Check gps is enable or not
if (!locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)) {
//Write Function To enable gps
OnGPS();
}
else
{
//GPS is already On then
getLocation();
}
}
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() {
//Check Permissions again
if (ActivityCompat.checkSelfPermission(CheckInActivity.this,android.Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(CheckInActivity.this,
android.Manifest.permission.ACCESS_FINE_LOCATION) !=PackageManager.PERMISSION_GRANTED)
{
ActivityCompat.requestPermissions(this,new String[]
{android.Manifest.permission.ACCESS_FINE_LOCATION}, REQUEST_LOCATION);
}
else
{
Location LocationGps= locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);
Location LocationNetwork=locationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
Location LocationPassive=locationManager.getLastKnownLocation(LocationManager.PASSIVE_PROVIDER);
if (LocationGps !=null)
{
double lat=LocationGps.getLatitude();
double longi=LocationGps.getLongitude();
float[] results = new float[1];
Location.distanceBetween(lat,longi,LatLong.newLat,LatLong.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");
// showLocationTxt.setText("Your Location:"+"\n"+"Latitude= "+latitude+"\n"+"Longitude= "+longitude);
}
else if (LocationNetwork !=null)
{
double lat=LocationNetwork.getLatitude();
double longi=LocationNetwork.getLongitude();
float[] results = new float[1];
Location.distanceBetween(lat,longi, LatLong.newLat,LatLong.newLong,results);
float distance = results[0];
Toast.makeText(this,String.valueOf(distance)+" metres from location",Toast.LENGTH_LONG).show();
if(distance > 400){
moreThanFour();
}
else{
lessThanFour();
}
latitude=String.valueOf(lat);
longitude=String.valueOf(longi);
System.out.println("Position 2");
// showLocationTxt.setText("Your Location:"+"\n"+"Latitude= "+latitude+"\n"+"Longitude= "+longitude);
}
else if (LocationPassive !=null)
{
double lat=LocationPassive.getLatitude();
double longi=LocationPassive.getLongitude();
latitude=String.valueOf(lat);
longitude=String.valueOf(longi);
System.out.println("Position 3");
// showLocationTxt.setText("Your Location:"+"\n"+"Latitude= "+latitude+"\n"+"Longitude= "+longitude);
}
else
{
Toast.makeText(this, "Can't Get Your Location", Toast.LENGTH_SHORT).show();
}
}
}
public void moreThanFour(){
stopService(new Intent(CheckInActivity.this, MyLocationService.class));
btncheckOut.setClickable(false);
new SweetAlertDialog(this, SweetAlertDialog.WARNING_TYPE)
.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
public void onClick(SweetAlertDialog sDialog) {
sDialog.dismissWithAnimation();
}
})
.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("");
progressDialog.setMessage("Loading this Content, please wait!");
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")
.setConfirmText("OK").setConfirmClickListener(new SweetAlertDialog.OnSweetClickListener() {
@Override
public void onClick(SweetAlertDialog sDialog) {
sDialog.dismissWithAnimation();
}
})
.show();
}
@Override
public void onBackPressed () {
Toast.makeText(CheckInActivity.this,"Ongoing process . Please logout to go back.",Toast.LENGTH_LONG).show();
} }

View File

@ -7,6 +7,7 @@ import android.hardware.Camera;
import android.os.Bundle; import android.os.Bundle;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import androidx.appcompat.widget.LinearLayoutCompat;
import android.text.Editable; import android.text.Editable;
import android.text.TextUtils; import android.text.TextUtils;
@ -76,6 +77,10 @@ public class LoginActivity extends BaseActivity {
Button login_new; Button login_new;
Button reg_new; Button reg_new;
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);
@ -85,6 +90,8 @@ public class LoginActivity extends BaseActivity {
//login = findViewById(R.id.login); //login = findViewById(R.id.login);
register = findViewById(R.id.register); register = findViewById(R.id.register);
lay_licence_verify = findViewById(R.id.lay_licence_verify);
login_new = findViewById(R.id.login_new); login_new = findViewById(R.id.login_new);
login_new.setOnClickListener(new View.OnClickListener() { login_new.setOnClickListener(new View.OnClickListener() {
@ -160,10 +167,12 @@ public class LoginActivity extends BaseActivity {
} }
case 0: { case 0: {
Log.d(TAG, "Face engine were succesfully created " + getFilesDir() + "/vl/data"); Log.d(TAG, "Face engine were succesfully created " + getFilesDir() + "/vl/data");
lay_licence_verify.setVisibility(View.VISIBLE);
break; break;
} }
case 1: { case 1: {
Toast.makeText(this, "License Verification failed!", Toast.LENGTH_LONG).show(); Toast.makeText(this, "License Verification failed!", Toast.LENGTH_LONG).show();
lay_licence_verify.setVisibility(View.VISIBLE);
break; break;
} }
case 2: { case 2: {
@ -458,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();
} }
} }

View File

@ -69,7 +69,8 @@ public class LoginActivityNew extends AppCompatActivity {
isAllFieldsChecked = CheckAllFields(); isAllFieldsChecked = CheckAllFields();
if(isAllFieldsChecked) { if(isAllFieldsChecked) {
// login(); // login();
Intent intent = new Intent(LoginActivityNew.this, AuthenticationActivity.class); //Intent intent = new Intent(LoginActivityNew.this, AuthenticationActivity.class);
Intent intent = new Intent(LoginActivityNew.this, CheckInActivity.class);
startActivity(intent); startActivity(intent);
} }

View File

@ -0,0 +1,221 @@
package ru.visionlab.femdemo.views;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.app.ActivityCompat;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.location.Location;
import android.location.LocationManager;
import android.os.Bundle;
import android.provider.Settings;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;
import cn.pedant.SweetAlert.SweetAlertDialog;
import ru.visionlab.femdemo.CheckInActivity;
import ru.visionlab.femdemo.R;
import ru.visionlab.femdemo.login.LoginActivity;
public class EmployeeActivity extends AppCompatActivity {
private static final int REQUEST_LOCATION=1;
TextView showLocationTxt;
LocationManager locationManager;
String latitude,longitude;
ImageView logout;
ImageView menu;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_employee);
ActivityCompat.requestPermissions(this,new String[]
{android.Manifest.permission.ACCESS_FINE_LOCATION}, REQUEST_LOCATION);
showLocationTxt=findViewById(R.id.show_location);
logout = findViewById(R.id.logout);
locationManager=(LocationManager) getSystemService(Context.LOCATION_SERVICE);
//Check gps is enable or not
if (!locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER))
{
//Write Function To enable gps
OnGPS();
}
else
{
//GPS is already On then
getLocation();
}
logout.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent intent = new Intent(EmployeeActivity.this, LoginActivity.class);
startActivity(intent);
}
});
menu = findViewById(R.id.menu);
menu.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
LayoutInflater inflater = LayoutInflater.from(getApplicationContext());
view = inflater.inflate(R.layout.layout, null);
TextView popup_log_out = view.findViewById(R.id.popup_log_out);
popup_log_out.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent intent = new Intent(EmployeeActivity.this, LoginActivity.class);
startActivity(intent);
}
});
final AlertDialog alertDialog = new AlertDialog.Builder(EmployeeActivity.this)
.setView(view)
.create();
alertDialog.show();
alertDialog.getWindow().setLayout(600,460);
alertDialog.getWindow().setGravity(Gravity.TOP|Gravity.LEFT);
alertDialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
WindowManager.LayoutParams params = alertDialog.getWindow().getAttributes();
alertDialog.setCanceledOnTouchOutside(true);
params.horizontalMargin = -100;
alertDialog.getWindow().setAttributes(params);
}
});
}
private void getLocation() {
//Check Permissions again
if (ActivityCompat.checkSelfPermission(EmployeeActivity.this,android.Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(EmployeeActivity.this,
android.Manifest.permission.ACCESS_FINE_LOCATION) !=PackageManager.PERMISSION_GRANTED)
{
ActivityCompat.requestPermissions(this,new String[]
{android.Manifest.permission.ACCESS_FINE_LOCATION}, REQUEST_LOCATION);
}
else
{
Location LocationGps= locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);
Location LocationNetwork=locationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
Location LocationPassive=locationManager.getLastKnownLocation(LocationManager.PASSIVE_PROVIDER);
if (LocationGps !=null)
{
double lat=LocationGps.getLatitude();
double longi=LocationGps.getLongitude();
latitude=String.valueOf(lat);
longitude=String.valueOf(longi);
System.out.println("Position 1");
showLocationTxt.setText("Your Location:"+"\n"+"Latitude= "+latitude+"\n"+"Longitude= "+longitude);
}
else if (LocationNetwork !=null)
{
double lat=LocationNetwork.getLatitude();
double longi=LocationNetwork.getLongitude();
double newLat = 22.5135;
double newLong = 88.4029;
float[] results = new float[1];
Location.distanceBetween(lat,longi,newLat,newLong,results);
float distance = results[0];
Toast.makeText(this,String.valueOf(distance)+" metres from location",Toast.LENGTH_LONG).show();
if(distance > 400){
moreThanFour();
}
else{
lessThanFour();
}
latitude=String.valueOf(lat);
longitude=String.valueOf(longi);
System.out.println("Position 2");
showLocationTxt.setText("Your Location:"+"\n"+"Latitude= "+latitude+"\n"+"Longitude= "+longitude);
}
else if (LocationPassive !=null)
{
double lat=LocationPassive.getLatitude();
double longi=LocationPassive.getLongitude();
latitude=String.valueOf(lat);
longitude=String.valueOf(longi);
System.out.println("Position 3");
showLocationTxt.setText("Your Location:"+"\n"+"Latitude= "+latitude+"\n"+"Longitude= "+longitude);
}
else
{
Toast.makeText(this, "Can't Get Your Location", Toast.LENGTH_SHORT).show();
}
}
}
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();
}
public void moreThanFour(){
new SweetAlertDialog(this, SweetAlertDialog.WARNING_TYPE)
.setTitleText("Are you sure you are near location?")
.setContentText("Please be in your precise location")
.setConfirmText("OK").show();
}
public void lessThanFour(){
new SweetAlertDialog(this, SweetAlertDialog.SUCCESS_TYPE)
.setTitleText("You are currently near location")
.setContentText("Attendance can be captured now")
.setConfirmText("OK").show();
}
}

View File

@ -45,7 +45,7 @@
</RelativeLayout> </RelativeLayout>
<Button <Button
android:id="@+id/btnLogin" android:id="@+id/btnCheckIn"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginTop="40dp" android:layout_marginTop="40dp"
@ -60,6 +60,7 @@
android:gravity="center"/> android:gravity="center"/>
<Button <Button
android:id="@+id/btncheckOut"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginTop="20dp" android:layout_marginTop="20dp"

View File

@ -0,0 +1,45 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.appcompat.widget.LinearLayoutCompat
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".views.EmployeeActivity"
android:orientation="vertical">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="15dp">
<ImageView
android:id="@+id/menu"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerInParent="true"
android:background="@drawable/menu" />
<ImageView
android:id="@+id/logout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerInParent="true"
android:background="@drawable/back" />
</RelativeLayout>
<TextView
android:id="@+id/show_location"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Location"
android:textSize="20sp"
android:gravity="center_horizontal"
android:layout_marginTop="50dp"
/>
</androidx.appcompat.widget.LinearLayoutCompat>

View File

@ -16,6 +16,8 @@
android:focusableInTouchMode="true" android:focusableInTouchMode="true"
android:scrollbars="none"> android:scrollbars="none">
<LinearLayout <LinearLayout
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
@ -39,6 +41,27 @@
/> />
</RelativeLayout> </RelativeLayout>
<androidx.appcompat.widget.LinearLayoutCompat
android:id="@+id/lay_licence_verify"
android:layout_width="match_parent"
android:layout_height="48dp"
android:orientation="vertical"
android:background="#FF2E2E"
android:visibility="gone">
<TextView
android:layout_width="wrap_content"
android:layout_height="48dp"
android:text="Please complete licence verification"
android:textStyle="bold"
android:textColor="@color/white"
android:layout_gravity="center"
android:gravity="center_vertical"
/>
</androidx.appcompat.widget.LinearLayoutCompat>
<RelativeLayout <RelativeLayout
android:layout_width="350px" android:layout_width="350px"
android:layout_height="350px" android:layout_height="350px"