コード例 #1
0
        protected override void OnCreate(Bundle bundle)
        {
            RequestWindowFeature(WindowFeatures.NoTitle);
            base.OnCreate (bundle);
            SetContentView (Resource.Layout.ChooseMode);
            try {
                string sessionKey = Intent.GetStringExtra ("SessionKey");
                int groupID = Intent.GetIntExtra ("GroupID", 0);
                int userID = Intent.GetIntExtra ("UserID", 0);
                var locSvc = new ROMPLocation ();
                Button button = FindViewById<Button> (Resource.Id.btnChoose);
                CheckBox cbpassive = FindViewById<CheckBox> (Resource.Id.cbPassive);
                CheckBox cbactive = FindViewById<CheckBox> (Resource.Id.cbActive);

                cbpassive.Click += (o, e) => {
                    if (cbactive.Checked) {
                        cbactive.Checked = false;
                    }
                };

                cbactive.Click += (o, e) => {
                    if (cbpassive.Checked) {
                        cbpassive.Checked = false;
                    }
                };

                button.Click += delegate {
                    if (cbactive.Checked) {
                        var nextActivity = new Intent(this, typeof(CheckInActivity));
                        nextActivity.PutExtra("SessionKey", sessionKey);
                        nextActivity.PutExtra("GroupID", groupID);
                        nextActivity.PutExtra("UserID", userID);
                        StartActivity(nextActivity);
                        Finish();
                    } else if (cbpassive.Checked) {
                        var nextActivity = new Intent(this, typeof(CheckInPassiveActivity));
                        nextActivity.PutExtra("SessionKey", sessionKey);
                        nextActivity.PutExtra("GroupID", groupID);
                        nextActivity.PutExtra("UserID", userID);
                        StartActivity(nextActivity);
                        Finish();
                    } else {
                        string errmsg = "Please choose a check in method before proceeding.";
                        var myHandler = new Handler();
                        myHandler.Post(() => {
                            Toast.MakeText(this, errmsg, ToastLength.Short).Show();
                        });
                    }
                };
            } catch (Exception e) {
                var myHandler = new Handler();
                myHandler.Post(() => {
                    Android.Widget.Toast.MakeText(this, e.Message, Android.Widget.ToastLength.Long).Show();
                });
                System.Diagnostics.Debug.Write (e.Message);
            }
        }
コード例 #2
0
 public void btnCheckIn_OnClick(object sender, EventArgs eventArgs)
 {
     try
     {
         if (_currentLocation == null) {
             var myHandler = new Handler ();
             myHandler.Post (() => {
                 Toast.MakeText (this, "Determining Location, Wait One Moment and Try Again.", ToastLength.Long).Show ();
             });
             return;
         } else {
             if (groupID <= 2) {
                 string absResult = "You Are Not Within A Specified Zone.";
                 Button button = FindViewById<Button>(Resource.Id.btnCheckIn);
                 if (button.Text == "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.Latitude - fenceLat);  // deg2rad below
                         var dLon = deg2rad(_currentLocation.Longitude - fenceLon);
                         var a =
                             Math.Sin(dLat/2) * Math.Sin(dLat/2) +
                             Math.Cos(deg2rad(fenceLat)) * Math.Cos(deg2rad(_currentLocation.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) {
                             var locSvc = new ROMPLocation ();
                             string result = locSvc.CheckIn(sessionKey, fc.LocationID);
                             if (result == "Success"){
                                 absResult = "Check In Successful";
                                 button.Text = "Check Out";
                             } else {
                                 absResult = "An Unexpected Error Occurred. Try Again";
                             }
                         }
                     }
                 } else if (button.Text == "Check Out") {
                     var locSvc = new ROMPLocation ();
                     string result = locSvc.CheckOutWithoutLocation(sessionKey);
                     if (result == "Success"){
                         absResult = "Check Out Successful";
                         button.Text = "Check In";
                     } else {
                         absResult = "An Unexpected Error Occurred. Try Again";
                     }
                 }
                 var myHandler = new Handler ();
                 myHandler.Post (() => {
                     Toast.MakeText (this, absResult, ToastLength.Long).Show ();
                 });
             } else if (groupID > 2 && groupID <= 7) {
                 string absResult;
                 Button button = FindViewById<Button>(Resource.Id.btnCheckIn);
                 if (button.Text == "Check In") {
                     var locSvc = new ROMPLocation ();
                     string result = locSvc.CheckInWithLocation(sessionKey, -1, _currentLocation.Latitude, _currentLocation.Longitude);
                     if (result == "Success"){
                         absResult = "Check In Successful";
                         button.Text = "Check Out";
                     } else {
                         absResult = "An Unexpected Error Occurred. Try Again";
                     }
                     var myHandler = new Handler ();
                     myHandler.Post (() => {
                         Toast.MakeText (this, absResult, ToastLength.Long).Show ();
                     });
                 } else if (button.Text == "Check Out") {
                     var locSvc = new ROMPLocation ();
                     string result = locSvc.CheckOutWithoutLocation(sessionKey);
                     if (result == "Success"){
                         absResult = "Check Out Successful";
                         button.Text = "Check In";
                     } else {
                         absResult = "An Unexpected Error Occurred. Try Again";
                     }
                     var myHandler = new Handler ();
                     myHandler.Post (() => {
                         Toast.MakeText (this, absResult, ToastLength.Long).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.Latitude - fenceLat);  // deg2rad below
                 var dLon = deg2rad(_currentLocation.Longitude - fenceLon);
                 var a =
                     Math.Sin(dLat/2) * Math.Sin(dLat/2) +
                     Math.Cos(deg2rad(fenceLat)) * Math.Cos(deg2rad(_currentLocation.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;
                 //double distance = 60 * 1.1515 * Math.Acos(Math.Sin(Math.PI * _currentLocation.Latitude / 180) * Math.Sin(Math.PI * 48.46003187 / 180) + Math.Cos(Math.PI * _currentLocation.Latitude / 180) * Math.Cos(Math.PI * 48.46003187 / 180) * Math.Cos((_currentLocation.Longitude - -89.18908003) * Math.PI / 180)  * 180 / Math.PI );
                 var myHandler = new Handler ();
                 string absResult = d.ToString();
                 myHandler.Post (() => {
                     Toast.MakeText (this, absResult, ToastLength.Long).Show ();
                 });
             }
         }
     } catch (Exception e) {
         var myHandler = new Handler();
         myHandler.Post(() => {
             Android.Widget.Toast.MakeText(this, e.Message, Android.Widget.ToastLength.Long).Show();
         });
     }
 }
コード例 #3
0
 protected override void OnCreate(Bundle bundle)
 {
     RequestWindowFeature(WindowFeatures.NoTitle);
     base.OnCreate (bundle);
     SetContentView (Resource.Layout.Main);
     mSharedPreferences = this.GetSharedPreferences ("CheckInPrefs", FileCreationMode.Private);
     string storedUser = mSharedPreferences.GetString ("StoredUser", "NONE");
     string storedPass = mSharedPreferences.GetString ("StoredPass", "NONE");
     if (!storedUser.Equals("NONE") || !storedPass.Equals("NONE")) {
         FindViewById<EditText>(Resource.Id.txtUsername).SetText(storedUser, TextView.BufferType.Normal);
         FindViewById<EditText>(Resource.Id.txtPassword).SetText(storedPass, TextView.BufferType.Normal);
         FindViewById<CheckBox>(Resource.Id.cbStoreUser).Checked = true;
     }
     FindViewById<CheckBox>(Resource.Id.cbStoreUser).CheckedChange += delegate {
         ISharedPreferencesEditor cbeditor = mSharedPreferences.Edit ();
         cbeditor.Remove("StoredUser");
         cbeditor.Remove("StoredPass");
         cbeditor.Commit();
     };
     Button button = FindViewById<Button> (Resource.Id.btnLogin);
     button.Click += delegate {
         TextView txtPassword = FindViewById<TextView> (Resource.Id.txtPassword);
         TextView txtUsername = FindViewById<TextView> (Resource.Id.txtUsername);
         if (string.IsNullOrEmpty(txtPassword.Text) || string.IsNullOrEmpty(txtUsername.Text)) {
             var myHandler = new Handler();
             myHandler.Post(() => {
                 Android.Widget.Toast.MakeText(this, "Please Provide a Username and Password.", Android.Widget.ToastLength.Long).Show();
             });
         } else {
             try {
                 var locSvc = new ROMPLocation();
                 var loginResp = new LoginResponse();
                 loginResp = locSvc.LearnerLogin(txtUsername.Text, txtPassword.Text);
                 if (loginResp.Success) {
                     CheckBox rememberMe = FindViewById<CheckBox> (Resource.Id.cbStoreUser);
                     ISharedPreferencesEditor editor = mSharedPreferences.Edit ();
                     if (rememberMe.Checked) {
                         editor.PutString("StoredUser", txtUsername.Text);
                         editor.PutString("StoredPass", txtPassword.Text);
                     } else {
                         editor.Remove("StoredUser");
                     }
                     editor.Commit();
                     if (loginResp.GroupID <= 2) {
                         var nextActivity = new Intent(this, typeof(ChooseModeActivity));
                         nextActivity.PutExtra("SessionKey", loginResp.SessionKey);
                         nextActivity.PutExtra("GroupID", loginResp.GroupID);
                         nextActivity.PutExtra("UserID", loginResp.UserID);
                         StartActivity(nextActivity);
                         Finish();
                     } else {
                         var nextActivity = new Intent(this, typeof(CheckInActivity));
                         nextActivity.PutExtra("SessionKey", loginResp.SessionKey);
                         nextActivity.PutExtra("GroupID", loginResp.GroupID);
                         nextActivity.PutExtra("UserID", loginResp.UserID);
                         StartActivity(nextActivity);
                         Finish();
                     }
                 } else {
                     var myHandler = new Handler();
                     myHandler.Post(() => {
                         Android.Widget.Toast.MakeText(this, "Login Failed. Please Try Again.", Android.Widget.ToastLength.Long).Show();
                     });
                 }
             } catch (Exception e) {
                 var myHandler = new Handler();
                 myHandler.Post(() => {
                     Android.Widget.Toast.MakeText(this, e.Message, Android.Widget.ToastLength.Long).Show();
                 });
                 System.Diagnostics.Debug.Write(e.Message);
             }
         }
     };
 }
コード例 #4
0
 protected override void OnCreate(Bundle bundle)
 {
     RequestWindowFeature(WindowFeatures.NoTitle);
     base.OnCreate (bundle);
     SetContentView (Resource.Layout.CheckIn);
     FindViewById<TextView> (Resource.Id.btnCheckIn).Enabled = false;
     sessionKey = Intent.GetStringExtra ("SessionKey");
     groupID = Intent.GetIntExtra ("GroupID", 0);
     userID = Intent.GetIntExtra ("UserID", 0);
     var locSvc = new ROMPLocation ();
     //myFacilities[] = new FacilityCoordinates();
     myFacilities = locSvc.GetLocations (sessionKey, groupID);
     FindViewById<Button> (Resource.Id.btnCloseA).Click += btnCloseA_OnClick;
     if (myFacilities.Count () > 0) {
         FindViewById<Button> (Resource.Id.btnCheckIn).Click += btnCheckIn_OnClick;
         InitializeLocationManager();
     } else {
         FindViewById<Button> (Resource.Id.btnCheckIn).Visibility = ViewStates.Invisible;
         FindViewById<TextView> (Resource.Id.lblText).Text = "You have no locations to check in to. Please start the application during a rotation to properly utilize the functionality. Thank you.";
     }
 }
コード例 #5
0
 protected override void OnCreate(Bundle bundle)
 {
     RequestWindowFeature (WindowFeatures.NoTitle);
     base.OnCreate (bundle);
     SetContentView (Resource.Layout.CheckInPassive);
     mGeoIntentUp = (PendingIntent.GetService (this, 0,
         new Intent (this, Java.Lang.Class.FromType(typeof(GeofenceTransitionsIntentService))),
         PendingIntentFlags.NoCreate) != null);
     if (mGeoIntentUp) {
         geofenceRequestIntent = PendingIntent.GetService (this, 0,
             new Intent (this, Java.Lang.Class.FromType (typeof(GeofenceTransitionsIntentService))),
             PendingIntentFlags.UpdateCurrent);
         FindViewById<Button>(Resource.Id.btnBegin).Visibility = ViewStates.Invisible;
         FindViewById<TextView> (Resource.Id.lblConfirm).SetText ("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 1km radius surrounding the facility of your ROMP rotation.", TextView.BufferType.Normal);
     } else {
         geofenceList = new List<IGeofence> ();
         geofenceRequestIntent = null;
         string sessionKey = Intent.GetStringExtra ("SessionKey");
         int groupID = Intent.GetIntExtra ("GroupID", 0);
         int userID = Intent.GetIntExtra ("UserID", 0);
         if (sessionKey != "") {
             mSharedPreferences = this.GetSharedPreferences ("CheckInPrefs", FileCreationMode.Private);
             ISharedPreferencesEditor editor = mSharedPreferences.Edit ();
             editor.PutString ("SessionKey", sessionKey);
             editor.Commit ();
         }
         var locSvc = new ROMPLocation ();
         FindViewById<Button> (Resource.Id.btnCloseP).Click += btnCloseP_OnClick;
         myFacilities = locSvc.GetLocations (sessionKey, groupID);
         if (myFacilities.Count () > 0) {
             connectedGeofences = new List<ROMPGeofence> ();
             CreateGeofences ();
             FindViewById<Button> (Resource.Id.btnBegin).Click += BeginGeofencing;
             BuildGoogleApiClient ();
         } else {
             FindViewById<Button> (Resource.Id.btnBegin).Visibility = ViewStates.Invisible;
             FindViewById<TextView> (Resource.Id.lblConfirm).Text = "You have no locations to check in to. Please start the application during a rotation to properly utilize the functionality. Thank you.";
         }
     }
 }