public override void ViewDidLoad()
        {
            base.ViewDidLoad ();
            btnBeginCheckIn.BackgroundColor = new UIColor(new CoreGraphics.CGColor(0.1f,0.1f,0.1f));
            btnBeginCheckIn.Layer.CornerRadius = 1;
            btnBeginCheckIn.TouchUpInside += (object sender, EventArgs e) => {
                var locSvc = new ROMPLocation ();
                myFacilities = locSvc.GetLocations (sessionKey, groupID);
                string geofenceAnnounce = "Geofences Active At The Following Locations:\n";
                foreach (FacilityCoordinates fc in myFacilities) {
                    geofenceAnnounce += fc.LocationName + "\n";
                    var region = new CLCircularRegion (new CLLocationCoordinate2D (fc.Latitude, fc.Longitude), 50.0f, fc.LocationID.ToString());
                    geoMan.StartMonitoringRegion (region, locSvc, sessionKey, fc.LocationID, fc.LocationName);
                }
                UIAlertView _alert = new UIAlertView ("Monitoring Locations", geofenceAnnounce, null, "Ok", null);
                _alert.Show ();
                btnBeginCheckIn.Hidden = true;
                lblInfo.Text = "A record that you have checked-in will be made in the log of your education activity for this ROMP rotation when this device enters a 100m radius surrounding the facility of your ROMP rotation.";
            };

            btnExit.BackgroundColor = new UIColor(new CoreGraphics.CGColor(0.9f,0.9f,0.9f));
            btnExit.Layer.CornerRadius = 1;
            btnExit.TouchUpInside += (object sender, EventArgs e) => {
                Environment.Exit(0);
            };
        }
Пример #2
0
        public override void ViewDidLoad()
        {
            base.ViewDidLoad ();
            txtPassword.SecureTextEntry = true;
            NSUserDefaults userSettings = NSUserDefaults.StandardUserDefaults;
            string storedUser = userSettings.StringForKey ("StoredUser");
            string storedPass = userSettings.StringForKey ("StoredPass");

            if (storedUser != null) {
                txtUsername.Text = storedUser;
                txtPassword.Text = storedPass;
                cbStoreUser.SetState (true, false);
            }
            btnLogin.BackgroundColor = new UIColor(new CoreGraphics.CGColor(0.9f,0.9f,0.9f));
            btnLogin.Layer.CornerRadius = 1;
            btnLogin.Layer.BorderWidth = 1.0f;
            btnLogin.TouchUpInside += (object sender, EventArgs e) => {
                if (string.IsNullOrEmpty(txtPassword.Text) || string.IsNullOrEmpty(txtUsername.Text)) {
                    new UIAlertView ("Error", "Please Provide a Username and Password.", null, "Ok", null).Show();
                } else {
                    try {
                        var locSvc = new ROMPLocation();
                        var loginResp = new LoginResponse();
                        loginResp = locSvc.LearnerLogin(txtUsername.Text, txtPassword.Text);
                        if (loginResp.Success) {
                            if (cbStoreUser.On) {
                                userSettings.SetString(txtUsername.Text, "StoredUser");
                                userSettings.SetString(txtPassword.Text, "StoredPass");
                            } else {
                                userSettings.SetString("", "StoredUser");
                                userSettings.SetString("", "StoredPass");
                            }
                            if (loginResp.GroupID <= 2) {
                                this.chooseModeScreen = this.Storyboard.InstantiateViewController("ChooseModeViewController") as ChooseModeViewController;
                                this.chooseModeScreen.sessionKey = loginResp.SessionKey;
                                this.chooseModeScreen.groupID = loginResp.GroupID;
                                this.chooseModeScreen.userID = loginResp.UserID;
                                this.NavigationController.PushViewController(this.chooseModeScreen, true);
                            } else {
                                this.checkInScreen = this.Storyboard.InstantiateViewController("CheckInViewController") as CheckInViewController;
                                this.checkInScreen.sessionKey = loginResp.SessionKey;
                                this.checkInScreen.groupID = loginResp.GroupID;
                                this.checkInScreen.userID = loginResp.UserID;
                                this.NavigationController.PushViewController(this.checkInScreen, true);
                            }
                        } else {
                            new UIAlertView ("Login Failed", "Login Failed. Please Try Again.", null, "Ok", null).Show();
                        }
                    } catch (Exception ex) {
                        new UIAlertView ("Error", ex.Message, null, "Ok", null).Show();
                        System.Diagnostics.Debug.Write(ex.Message);
                    }
                }
            };
        }
Пример #3
0
		// We need to perform a lot of checks to make sure location data and region monitoring are available and enabled.
		// For simplicity, we're logging errors in the console.

		public void StartMonitoringRegion (CLCircularRegion region, ROMPLocation rompLoc, string sessionKey, int locationID, string locationName)
		{
			if (CLLocationManager.LocationServicesEnabled) {

				if (CLLocationManager.Status != CLAuthorizationStatus.Denied) {

					if (CLLocationManager.IsMonitoringAvailable (typeof(CLCircularRegion))) {

						//LocMgr.DesiredAccuracy = 1;

						FenceMgr.DesiredAccuracy = CLLocation.AccuracyNearestTenMeters;


						if (UIDevice.CurrentDevice.CheckSystemVersion(8, 0))
						{
							FenceMgr.RequestAlwaysAuthorization ();
						}

						var settings = UIUserNotificationSettings.GetSettingsForTypes(UIUserNotificationType.Alert | UIUserNotificationType.Badge, null);
						UIApplication.SharedApplication.RegisterUserNotificationSettings (settings);

						FenceMgr.RegionEntered += (o, e) => {
							rompLoc.CheckIn(sessionKey, locationID);
							Console.WriteLine ("Just entered " + e.Region.ToString ());
							UILocalNotification notification = new UILocalNotification();
							DateTime date = DateTime.Now.AddSeconds(5.0);
							date = date.ToLocalTime();
							NSDate nsDate = (NSDate)DateTime.SpecifyKind(date, DateTimeKind.Utc);
							notification.FireDate = nsDate;
							notification.AlertAction = "Check In";
							notification.AlertBody = "Successfully Checked Into " + locationName;
							UIApplication.SharedApplication.ScheduleLocalNotification(notification);
							RegionEntered (this, new RegionChangedEventArgs ((CLCircularRegion)e.Region));
						};

						FenceMgr.RegionLeft += (o, e) => {
							rompLoc.CheckOut(sessionKey, locationID);
							Console.WriteLine ("Just left " + e.Region.ToString ());
							UILocalNotification notification = new UILocalNotification();
							DateTime date = DateTime.Now.AddSeconds(5.0);
							date = date.ToLocalTime();
							NSDate nsDate = (NSDate)DateTime.SpecifyKind(date, DateTimeKind.Utc);
							notification.FireDate = nsDate;
							notification.AlertAction = "Check Out";
							notification.AlertBody = "Successfully Checked Out Of " + locationName;
							UIApplication.SharedApplication.ScheduleLocalNotification(notification);
							RegionLeft (this, new RegionChangedEventArgs ((CLCircularRegion)e.Region));
						};

						FenceMgr.DidStartMonitoringForRegion += (o, e) => {
							Console.WriteLine ("Now monitoring region {0}", e.Region.ToString ());
						};

						FenceMgr.StartMonitoring (region);

					} else {
						Console.WriteLine ("This app requires region monitoring, which is unavailable on this device");
					}

				} else {
					Console.WriteLine ("App is not authorized to use location data");
				}

				// Get some output from our manager in case of failure
				FenceMgr.Failed += (o, e) => {
					Console.WriteLine (e.Error);
				}; 

			} else {

				//Let the user know that they need to enable LocationServices
				Console.WriteLine ("Location services not enabled, please enable this in your Settings");

			}
		}
Пример #4
0
        public override void ViewDidLoad()
        {
            base.ViewDidLoad ();
            var locSvc = new ROMPLocation ();
            myFacilities = locSvc.GetLocations (sessionKey, groupID);
            locMan = new CLLocationManager ();

            if (myFacilities.Count () > 0) {
                if (!CLLocationManager.LocationServicesEnabled) {
                    UIAlertView _error = new UIAlertView ("Error", "Location services not enabled, please enable this in your Settings.", null, "Ok", null);
                    _error.Show ();
                } else if (CLLocationManager.Status == CLAuthorizationStatus.Denied) {
                    UIAlertView _error = new UIAlertView ("Error", "App is not authorized to use location data.", null, "Ok", null);
                    _error.Show ();
                } else {
                    //locMan.LocationUpdated += LocationChanged;
                    locMan.DesiredAccuracy = CLLocation.AccuracyNearestTenMeters;
                    if (UIDevice.CurrentDevice.CheckSystemVersion (6, 0)) {
                        locMan.LocationsUpdated += (object sender, CLLocationsUpdatedEventArgs e) => {
                            UpdateLocation (e.Locations [e.Locations.Length - 1]);
                        };
                    } else {
                        #pragma warning disable 618
                        // this won't be called on iOS 6 (deprecated)
                        locMan.UpdatedLocation += (object sender, CLLocationUpdatedEventArgs e) => {
                            UpdateLocation (e.NewLocation);
                        };
                        #pragma warning restore 618
                    }

                    if (UIDevice.CurrentDevice.CheckSystemVersion(8, 0))
                    {
                        locMan.RequestAlwaysAuthorization ();
                    }

                    if (CLLocationManager.LocationServicesEnabled)
                        locMan.StartUpdatingLocation ();
                    if (CLLocationManager.HeadingAvailable)
                        locMan.StartUpdatingHeading ();
                }
                btnCheckIn.BackgroundColor = new UIColor(new CoreGraphics.CGColor(0.9f,0.9f,0.9f));
                btnCheckIn.Layer.CornerRadius = 1;
                btnCheckIn.TouchUpInside += (object sender, EventArgs e) => {
                    if (currentLocation != null) {
                        if (groupID <= 2) {
                            string absResult = "You Are Not Within A Specified Zone.";
                            string absTitle = "Error";
                            if (btnCheckIn.Title (UIControlState.Normal) == "Check In") {
                                foreach (FacilityCoordinates fc in myFacilities) {
                                    var fenceLat = fc.Latitude;
                                    var fenceLon = fc.Longitude;
                                    var R = 6371; // Radius of the earth in km
                                    var dLat = deg2rad (currentLocation.Coordinate.Latitude - fenceLat);  // deg2rad below
                                    var dLon = deg2rad (currentLocation.Coordinate.Longitude - fenceLon);
                                    var a =
                                        Math.Sin (dLat / 2) * Math.Sin (dLat / 2) +
                                        Math.Cos (deg2rad (fenceLat)) * Math.Cos (deg2rad (currentLocation.Coordinate.Latitude)) *
                                        Math.Sin (dLon / 2) * Math.Sin (dLon / 2);
                                    var c = 2 * Math.Atan2 (Math.Sqrt (a), Math.Sqrt (1 - a));
                                    var d = R * c;
                                    if (d <= 0.25) {
                                        string result = locSvc.CheckIn (sessionKey, fc.LocationID);
                                        if (result == "Success") {
                                            absTitle = "Success";
                                            absResult = "Check In Successful";
                                            btnCheckIn.SetTitle ("CHECK OUT", UIControlState.Normal);
                                            break;
                                        } else {
                                            absTitle = "Error";
                                            absResult = "An Unexpected Error Occurred. Try Again";
                                        }
                                    }
                                }
                            } else if (btnCheckIn.Title (UIControlState.Normal) == "Check Out") {
                                string result = locSvc.CheckOutWithoutLocation (sessionKey);
                                if (result == "Success") {
                                    absTitle = "Success";
                                    absResult = "Check Out Successful";
                                    btnCheckIn.SetTitle ("CHECK IN", UIControlState.Normal);
                                } else {
                                    absTitle = "Error";
                                    absResult = "An Unexpected Error Occurred. Try Again";
                                }
                            }
                            UIAlertView _error = new UIAlertView (absTitle, absResult, null, "Ok", null);
                            _error.Show ();
                        } else if (groupID > 2 && groupID <= 7) {
                            string absResult = "";
                            string absTitle = "";
                            if (btnCheckIn.Title (UIControlState.Normal) == "Check In") {
                                string result = locSvc.CheckInWithLocation (sessionKey, -1, currentLocation.Coordinate.Latitude, currentLocation.Coordinate.Longitude);
                                if (result == "Success") {
                                    absTitle = "Success";
                                    absResult = "Check In Successful";
                                    btnCheckIn.SetTitle ("CHECK OUT", UIControlState.Normal);
                                } else {
                                    absTitle = "Error";
                                    absResult = "An Unexpected Error Occurred. Try Again";
                                }
                            } else if (btnCheckIn.Title (UIControlState.Normal) == "Check Out") {
                                string result = locSvc.CheckOutWithoutLocation (sessionKey);
                                if (result == "Success") {
                                    absTitle = "Success";
                                    absResult = "Check In Successful";
                                    btnCheckIn.SetTitle ("CHECK IN", UIControlState.Normal);
                                } else {
                                    absTitle = "Error";
                                    absResult = "An Unexpected Error Occurred. Try Again";
                                }
                            }
                            UIAlertView _error = new UIAlertView (absTitle, absResult, null, "Ok", null);
                            _error.Show ();
                        } else if (groupID == 8) {
                            var fenceLat = 48.46003187;
                            var fenceLon = -89.18908003;
                            var R = 6371; // Radius of the earth in km
                            var dLat = deg2rad (currentLocation.Coordinate.Latitude - fenceLat);  // deg2rad below
                            var dLon = deg2rad (currentLocation.Coordinate.Longitude - fenceLon);
                            var a =
                                Math.Sin (dLat / 2) * Math.Sin (dLat / 2) +
                                Math.Cos (deg2rad (fenceLat)) * Math.Cos (deg2rad (currentLocation.Coordinate.Latitude)) *
                                Math.Sin (dLon / 2) * Math.Sin (dLon / 2);
                            var c = 2 * Math.Atan2 (Math.Sqrt (a), Math.Sqrt (1 - a));
                            var d = R * c;
                            string absResult = d.ToString ();
                            UIAlertView _error = new UIAlertView ("Check In", absResult, null, "Ok", null);
                            _error.Show ();
                        }
                    }
                };
            } else {
                btnCheckIn.Hidden = true;
                lblText.Text = "You have no locations to check in to. Please start the application during a rotation to properly utilize the functionality. Thank you.";
            }
            btnExit.BackgroundColor = new UIColor(new CoreGraphics.CGColor(0.9f,0.9f,0.9f));
            btnExit.Layer.CornerRadius = 1;
            btnExit.TouchUpInside += (object sender, EventArgs e) => {
                Environment.Exit(0);
            };
        }