From ef5153765f332fd9df59a5d6457df8c0ddffb5b6 Mon Sep 17 00:00:00 2001 From: Apalak Dutta Date: Wed, 21 Jun 2023 18:33:12 +0530 Subject: [PATCH] Displayed dialog for distance from location --- .../example_bestshot/example/app/build.gradle | 1 + .../example/app/src/main/AndroidManifest.xml | 9 +- .../ru/visionlab/femdemo/CheckInActivity.java | 210 +++++++++++++---- .../femdemo/login/LoginActivity.java | 7 + .../femdemo/login/LoginActivityNew.java | 3 +- .../femdemo/views/EmployeeActivity.java | 221 ++++++++++++++++++ .../src/main/res/layout/activity_checkin.xml | 2 +- .../src/main/res/layout/activity_employee.xml | 45 ++++ .../src/main/res/layout/activity_login.xml | 23 ++ 9 files changed, 466 insertions(+), 55 deletions(-) create mode 100644 examples/example_bestshot/example/app/src/main/java/ru/visionlab/femdemo/views/EmployeeActivity.java create mode 100644 examples/example_bestshot/example/app/src/main/res/layout/activity_employee.xml diff --git a/examples/example_bestshot/example/app/build.gradle b/examples/example_bestshot/example/app/build.gradle index a55d981..8b8567c 100644 --- a/examples/example_bestshot/example/app/build.gradle +++ b/examples/example_bestshot/example/app/build.gradle @@ -172,6 +172,7 @@ dependencies { implementation 'com.trello:rxlifecycle-components:1.0' implementation 'androidx.legacy:legacy-support-v4:1.0.0' implementation 'com.google.android.material:material:1.0.0' + implementation 'com.github.f0ris.sweetalert:library:1.5.1' diff --git a/examples/example_bestshot/example/app/src/main/AndroidManifest.xml b/examples/example_bestshot/example/app/src/main/AndroidManifest.xml index e7805d4..a130d2a 100644 --- a/examples/example_bestshot/example/app/src/main/AndroidManifest.xml +++ b/examples/example_bestshot/example/app/src/main/AndroidManifest.xml @@ -1,5 +1,6 @@ - + @@ -22,7 +23,11 @@ android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:supportsRtl="true" - android:theme="@style/AppTheme"> + android:theme="@style/AppTheme" + tools:replace="android:icon,android:allowBackup"> + diff --git a/examples/example_bestshot/example/app/src/main/java/ru/visionlab/femdemo/CheckInActivity.java b/examples/example_bestshot/example/app/src/main/java/ru/visionlab/femdemo/CheckInActivity.java index 83286ec..54a0e10 100644 --- a/examples/example_bestshot/example/app/src/main/java/ru/visionlab/femdemo/CheckInActivity.java +++ b/examples/example_bestshot/example/app/src/main/java/ru/visionlab/femdemo/CheckInActivity.java @@ -1,13 +1,19 @@ package ru.visionlab.femdemo; 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.MenuItem; @@ -19,16 +25,24 @@ import android.widget.PopupMenu; import android.widget.TextView; import android.widget.Toast; +import cn.pedant.SweetAlert.SweetAlertDialog; import ru.visionlab.femdemo.login.LoginActivity; import ru.visionlab.femdemo.register.RegisterActivityNew; +import ru.visionlab.femdemo.views.EmployeeActivity; public class CheckInActivity extends AppCompatActivity { + private static final int REQUEST_LOCATION=1; + ImageView logout; ImageView menu; AlertDialog dialogBuilder; + Button btnCheckIn; + + LocationManager locationManager; + String latitude,longitude; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); @@ -36,6 +50,19 @@ public class CheckInActivity extends AppCompatActivity { 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(); + + } + }); + + logout.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { @@ -58,19 +85,11 @@ public class CheckInActivity extends AppCompatActivity { public void onClick(View view) { Intent intent = new Intent(CheckInActivity.this, LoginActivity.class); 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) @@ -87,59 +106,148 @@ public class CheckInActivity extends AppCompatActivity { params.horizontalMargin = -100; 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() { + + + + } + + 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(View view) { + 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(); + + 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;*/ + + double newLat = 22.5150; + double newLong = 88.3930; + + 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(); + } + - // 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() { + } + + 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").setConfirmText("OK").setConfirmClickListener(new SweetAlertDialog.OnSweetClickListener() { @Override - public void onClick(DialogInterface dialog, int which) { - Intent intent = new Intent(CheckInActivity.this, LoginActivity.class); - startActivity(intent); + public void onClick(SweetAlertDialog sDialog) { + sDialog.dismissWithAnimation(); } - }); + }) + .show(); + } - // show the alert dialog - AlertDialog alertDialog = builder.create(); - alertDialog.show(); - alertDialog.getWindow().setLayout(800,400); - alertDialog.getWindow().setGravity(Gravity.TOP); - *//*PopupMenu popupMenu = new PopupMenu(CheckInActivity.this, menu); - popupMenu.getMenuInflater().inflate(R.menu.navigation_menu, popupMenu.getMenu()); - popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() { + public void lessThanFour(){ + 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 boolean onMenuItemClick(MenuItem menuItem) { - // Toast message on menu item clicked - Toast.makeText(CheckInActivity.this, "You Clicked " + menuItem.getTitle(), Toast.LENGTH_SHORT).show(); - return true; + public void onClick(SweetAlertDialog sDialog) { + sDialog.dismissWithAnimation(); } - }); - // Showing the popup menu - popupMenu.show();*//* - } - });*/ + }) + .show(); } diff --git a/examples/example_bestshot/example/app/src/main/java/ru/visionlab/femdemo/login/LoginActivity.java b/examples/example_bestshot/example/app/src/main/java/ru/visionlab/femdemo/login/LoginActivity.java index 7587df0..3f01f82 100644 --- a/examples/example_bestshot/example/app/src/main/java/ru/visionlab/femdemo/login/LoginActivity.java +++ b/examples/example_bestshot/example/app/src/main/java/ru/visionlab/femdemo/login/LoginActivity.java @@ -7,6 +7,7 @@ import android.hardware.Camera; import android.os.Bundle; import androidx.annotation.Nullable; +import androidx.appcompat.widget.LinearLayoutCompat; import android.text.Editable; import android.text.TextUtils; @@ -76,6 +77,8 @@ public class LoginActivity extends BaseActivity { Button login_new; Button reg_new; + LinearLayoutCompat lay_licence_verify; + @Override protected void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); @@ -85,6 +88,8 @@ public class LoginActivity extends BaseActivity { //login = findViewById(R.id.login); register = findViewById(R.id.register); + lay_licence_verify = findViewById(R.id.lay_licence_verify); + login_new = findViewById(R.id.login_new); login_new.setOnClickListener(new View.OnClickListener() { @@ -160,10 +165,12 @@ public class LoginActivity extends BaseActivity { } case 0: { Log.d(TAG, "Face engine were succesfully created " + getFilesDir() + "/vl/data"); + lay_licence_verify.setVisibility(View.VISIBLE); break; } case 1: { Toast.makeText(this, "License Verification failed!", Toast.LENGTH_LONG).show(); + lay_licence_verify.setVisibility(View.VISIBLE); break; } case 2: { diff --git a/examples/example_bestshot/example/app/src/main/java/ru/visionlab/femdemo/login/LoginActivityNew.java b/examples/example_bestshot/example/app/src/main/java/ru/visionlab/femdemo/login/LoginActivityNew.java index c3ce6c5..1c3d0ab 100644 --- a/examples/example_bestshot/example/app/src/main/java/ru/visionlab/femdemo/login/LoginActivityNew.java +++ b/examples/example_bestshot/example/app/src/main/java/ru/visionlab/femdemo/login/LoginActivityNew.java @@ -69,7 +69,8 @@ public class LoginActivityNew extends AppCompatActivity { isAllFieldsChecked = CheckAllFields(); if(isAllFieldsChecked) { // 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); } diff --git a/examples/example_bestshot/example/app/src/main/java/ru/visionlab/femdemo/views/EmployeeActivity.java b/examples/example_bestshot/example/app/src/main/java/ru/visionlab/femdemo/views/EmployeeActivity.java new file mode 100644 index 0000000..15f12a8 --- /dev/null +++ b/examples/example_bestshot/example/app/src/main/java/ru/visionlab/femdemo/views/EmployeeActivity.java @@ -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(); + } +} \ No newline at end of file diff --git a/examples/example_bestshot/example/app/src/main/res/layout/activity_checkin.xml b/examples/example_bestshot/example/app/src/main/res/layout/activity_checkin.xml index c1d6a27..5cc489b 100644 --- a/examples/example_bestshot/example/app/src/main/res/layout/activity_checkin.xml +++ b/examples/example_bestshot/example/app/src/main/res/layout/activity_checkin.xml @@ -45,7 +45,7 @@