예제 #1
0
		/// <summary>
		/// Handles the <see cref="E:PositionChanged" /> event.
		/// </summary>
		/// <param name="e">The <see cref="PositionEventArgs"/> instance containing the event data.</param>
		private void OnPositionChanged(PositionEventArgs e)
		{
			var changed = PositionChanged;
			if (changed != null)
			{
				changed(this, e);
			}
		}
예제 #2
0
        /// <summary>
        ///     Handles the <see cref="E:ListenerPositionChanged" /> event.
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="e">The <see cref="PositionEventArgs" /> instance containing the event data.</param>
        private void OnListenerPositionChanged(object sender, PositionEventArgs e)
        {
            if (!IsListening)             // ignore anything that might come in afterwards
            {
                return;
            }

            lock (_positionSync)
            {
                _lastPosition = e.Position;

                var changed = PositionChanged;
                if (changed != null)
                {
                    changed(this, e);
                }
            }
        }
예제 #3
0
		private void OnPositionChanged(object sender, PositionEventArgs e)
		{
		}
예제 #4
0
		/// <summary>
		/// Handles the <see cref="E:PositionChanged" /> event.
		/// </summary>
		/// <param name="sender">The sender.</param>
		/// <param name="e">The <see cref="PositionEventArgs"/> instance containing the event data.</param>
		private void OnPositionChanged(object sender, PositionEventArgs e)
		{
			lastKnownPosition = e.Position;
			ShowPosition (e.Position);
		}
예제 #5
0
		/// <summary>
		/// Handles the <see cref="E:PositionChanged" /> event.
		/// </summary>
		/// <param name="e">The <see cref="PositionEventArgs"/> instance containing the event data.</param>
		private void OnPositionChanged(PositionEventArgs e)
		{
			var changed = PositionChanged;
			if (changed != null)
			{
				changed(this, e);
			}
		}
예제 #6
0
		/// <summary>
		///     Handles the <see cref="E:ListenerPositionChanged" /> event.
		/// </summary>
		/// <param name="sender">The sender.</param>
		/// <param name="e">The <see cref="PositionEventArgs" /> instance containing the event data.</param>
		private void OnListenerPositionChanged(object sender, PositionEventArgs e)
		{
			if (!IsListening) // ignore anything that might come in afterwards
			{
				return;
			}

			lock (_positionSync)
			{
				_lastPosition = e.Position;

				var changed = PositionChanged;
				if (changed != null)
				{
					changed(this, e);
				}
			}
		}
		void OnPositionChanged (object sender, PositionEventArgs e) {
			var position = e.Position;
			string message = string.Format ("Latitude: {0} | Longitude: {1}", position.Latitude, position.Longitude);

			Debug.WriteLine (message);
		}
예제 #8
0
 /// <summary>
 /// Raises the position changed event.
 /// </summary>
 /// <param name="sender">Sender is the event source.</param>
 /// <param name="eventPos">E the event data. If there is no event data, this parameter will be null.</param>
 private async void OnPositionChanged(object sender, PositionEventArgs eventPos)
 {
     try
     {
         CurrentGamePosition = new Core.Models.Position(new Core.Models.LatLon(eventPos.Position.Latitude, eventPos.Position.Longitude));
         if (FirstGamePosition == null)
         {
             FirstGamePosition = CurrentGamePosition;
         }
     }
     catch (Exception ex)
     {
         var text = ex.Message;
     }
 }
예제 #9
0
파일: Main.xaml.cs 프로젝트: 0rupp/XToggl
		/// <summary>
		/// Handles the <see cref="E:PositionChanged" /> event.
		/// </summary>
		/// <param name="sender">The sender.</param>
		/// <param name="e">The <see cref="PositionEventArgs"/> instance containing the event data.</param>
		private async void OnPositionChanged(object sender, PositionEventArgs e)
		{
			if (_linkedGpsPositions == null)
				return;
			
			foreach (GpsPosition position in _linkedGpsPositions) {

				double distanceInKm = GeoCoordinates.DistanceTo (position.Latitude, position.Longitude, e.Position.Latitude, e.Position.Longitude);
				if (distanceInKm < 0.1) { // closer than 100 meters
					var linkedProject = _projects.FirstOrDefault (p => p.Id.GetValueOrDefault () == position.ProjectId); // try load from cache
					if (linkedProject == null) { // try load from api
						linkedProject = App.Toggl.Project.Get (position.ProjectId); 
					}
					if(linkedProject != null ) { // might still be null, when it has been deleted

						bool alreadyRunning = _selectedProject != null && _selectedProject.Id.GetValueOrDefault () == linkedProject.Id.Value;
						if (alreadyRunning)
							return;

						var task = await DisplayAlert("XToggl GPS", "You entered an area linked to '" + linkedProject.Name + "'. Do you want to start time tracking for this project?", "Yes", "No");			
						if (task) {				
							StartTimeMeasurementForProject (linkedProject);
						} else {
							await App.Notificator.Notify (ToastNotificationType.Info, "XToggl", "Time tracking not started", TimeSpan.FromSeconds (1.0), null);
						}
					}
				}
			}
		}
        /// <summary>
        /// Method that handles change in positions from the gps signal
        /// </summary>
        public void PositionChanged(object sender, PositionEventArgs e)
        {
            IsBusy = true;
            if (_locator != null)
            {
                _locator.GetPositionAsync(timeout: Definitions.MinIntervalTimeout, cancelToken: this._cancelSource.Token, includeHeading: false)
                    .ContinueWith(t =>
                    {
                        IsBusy = false;
                        if (t.IsFaulted)
                        {
                            GpsNotAvailable();
                            //PositionStatus = ((GeolocationException)t.Exception.InnerException).Error.ToString();
                        }
                        else if (t.IsCanceled)
                            PositionStatus = "Canceled";
                        else
                        {
                            if (t.Result.Accuracy < 100)
                            {
                                GpsIsAvailable();
                            }
                            else
                            {
                                GpsNotAvailable();
                                return;
                            }
                            
                            if (_trackChanges)
                            {
                                if (_firstRun)
                                {
                                    _positionLatitude = t.Result.Latitude;
                                    _positionLongitude = t.Result.Longitude;
                                    _firstRun = false;
                                    return;
                                }

                                var testDistance = Math.Round(GpsCalculator.Distance(_positionLatitude, _positionLongitude, t.Result.Latitude, t.Result.Longitude, 'K'), 3);

                                // Check after resuming.  
                                if (_doTestCheck)
                                {
                                    // If the user moved more than 200 meters. Resuming is not allowed.
                                    if (testDistance > 0.2)
                                    {
                                        _trackChanges = false;
                                        _pause = !_pause;
                                        _locator.StopListening();
                                        PauseDistanceTooBig(testDistance);
                                        return;
                                    }
                                    _doTestCheck = false;
                                }
                            
                                // Discard if distance is below 10 meters
                                if (t.Result.Accuracy != null)
                                {
                                    SetAccuracy(t.Result.Accuracy);
                                    if (testDistance < t.Result.Accuracy/1000)
                                        return;
                                }
                                else
                                {
                                    // default accuracy
                                    if (testDistance < 0.01)
                                        return;
                                }                                

                                SetAccuracy(t.Result.Accuracy);
                                TraveledDistance = testDistance;
                                _positionLatitude = t.Result.Latitude;
                                _positionLongitude = t.Result.Longitude;
                                PositionStatus = t.Result.Timestamp.ToString("HH:mm:ss");
                                Definitions.Route.GPSCoordinates.Add(new GPSCoordinate
                                {
                                    Latitude = t.Result.Latitude.ToString("#.######", CultureInfo.InvariantCulture),
                                    Longitude = t.Result.Longitude.ToString("#.######", CultureInfo.InvariantCulture),
                                });
                            }
                        }

                    });
            }
        }