Ejemplo n.º 1
0
        private void ActionStartPause(object sender, EventArgs e)
        {
            if (!_locationManager.IsProviderEnabled(LocationManager.GpsProvider))
            {
                ShowMessageBox(null, Constants.MSG_GPS_DISABLED);
                return;
            }

            if (pState == PRACTICE_STATE.ready)
            {
                StartTimer();

                btnStartPause.SetBackgroundResource(Resource.Drawable.resume_inactive);
                btnStop.Visibility = ViewStates.Visible;


                _locationManager.RequestLocationUpdates(LocationManager.GpsProvider, 2000, 1, this);

                pState = PRACTICE_STATE.playing;

                try
                {
                    var      name = MemberModel.firstname + " " + MemberModel.lastname;
                    var      loc  = String.Format("{0},{1}", _currentLocation.Latitude, _currentLocation.Longitude);
                    DateTime dt   = DateTime.Now;
                    dist = contextPref.GetFloat("dist", 0f);
                    var country = MemberModel.country;

                    svc.updateMomgoData(name, loc, dt, true, AppSettings.DeviceUDID, 0f, true, AppSettings.UserID, country, dist, true, gainAlt, true, _currentLocation.Bearing, true, 1, true, pType.ToString(), Constants.SPEC_GROUP_TYPE);
                }
                catch (Exception err)
                {
                    //Toast.MakeText(this, err.ToString(), ToastLength.Long).Show();
                }
            }
            else if (pState == PRACTICE_STATE.playing)
            {
                btnStartPause.SetBackgroundResource(Resource.Drawable.resume_active);
                btnStop.Visibility = ViewStates.Visible;

                _locationManager.RemoveUpdates(this);

                pState = PRACTICE_STATE.pause;
            }
            else if (pState == PRACTICE_STATE.pause)
            {
                btnStartPause.SetBackgroundResource(Resource.Drawable.resume_inactive);
                btnStop.Visibility = ViewStates.Visible;

                _locationManager.RequestLocationUpdates(LocationManager.GpsProvider, 2000, 1, this);

                pState = PRACTICE_STATE.playing;
            }
        }
        partial void ActionStartPause(UIButton sender)
        {
            if (pState == PRACTICE_STATE.ready)
            {
                StartTimer();

                btnStartPause.SetBackgroundImage(UIImage.FromFile("icon_pause.png"), UIControlState.Normal);
                btnStop.Hidden = false;

                LocationHelper.StartLocationManager();
                LocationHelper.LocationUpdated += LocationUpdated;

                pState = PRACTICE_STATE.playing;

                try
                {
                    var name     = MemberModel.firstname + " " + MemberModel.lastname;
                    var location = _lastLocation.Coordinate.Latitude.ToString() + "," + _lastLocation.Coordinate.Longitude.ToString();
                    var speed    = float.Parse(_lastLocation.Speed.ToString());
                    var alt      = float.Parse(NSUserDefaults.StandardUserDefaults.DoubleForKey("lastAltitude").ToString());
                    var bearing  = float.Parse(_lastLocation.Course.ToString());

                    System.Threading.ThreadPool.QueueUserWorkItem(delegate
                    {
                        meServ.updateMomgoData(name, location, _dt, true, AppSettings.DeviceUDID, speed, true, AppSettings.UserID, MemberModel.country, currdistance, true, alt, true, bearing, true, 1, true, pType.ToString(), PortableLibrary.Constants.SPEC_GROUP_TYPE);
                    });
                }
                catch
                {
                }
            }
            else if (pState == PRACTICE_STATE.playing)
            {
                btnStartPause.SetBackgroundImage(UIImage.FromFile("icon_resume.png"), UIControlState.Normal);
                btnStop.Hidden = false;

                LocationHelper.StopLocationManager();

                pState = PRACTICE_STATE.pause;
            }
            else if (pState == PRACTICE_STATE.pause)
            {
                btnStartPause.SetBackgroundImage(UIImage.FromFile("icon_pause.png"), UIControlState.Normal);
                btnStop.Hidden = false;

                LocationHelper.StartLocationManager();
                LocationHelper.LocationUpdated += LocationUpdated;

                pState = PRACTICE_STATE.playing;
            }
        }