|
|
@ -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(); |
|
|
|
} |
|
|
|
|
|
|
|
|