예제 #1
0
        private async void OnCoordinateDetectionCurrentButtonClicked(object sender, EventArgs e)
        {
            Debug.WriteLine("Testing coordinate current detection.");
            Location location = await LocationDetails.GetCurrentLocation();

            if (location == null)
            {
                return;
            }
            await CoordinateDetection(location);
        }
예제 #2
0
        private async void OnPlaceTypeDetectionSearchButtonClicked(object sender, EventArgs e)
        {
            Debug.WriteLine("Testing place type search detection.");
            Location location = await LocationDetails.GetLocationFromUser();

            if (location == null)
            {
                return;
            }
            await PlaceTypeDetection(location);
        }
예제 #3
0
        private async Task PlaceTypeDetection(Location location)
        {
            PlaceTypeItem foundPTI = await LocationDetails.GetNearbyPlaceTypeItem(location);

            if (foundPTI == null)
            {
                await DisplayAlert("Place Type Detection Results", $"No place types were found near ({location.Latitude}, {location.Longitude}).", "OK");
            }
            else
            {
                await DisplayAlert("Place Type Detection Results", $"The place type named \"{foundPTI.Name}\" was found near ({location.Latitude}, {location.Longitude}).", "OK");
            }
        }
예제 #4
0
        async void OnGetCurrentLocationButtonClicked(object sender, EventArgs e)
        {
            UpdateGettingLocation(true);

            Location currentLocation = await LocationDetails.GetCurrentLocation();

            if (currentLocation != null)
            {
                latitudeEntry.Text  = currentLocation.Latitude.ToString();
                longitudeEntry.Text = currentLocation.Longitude.ToString();
            }

            UpdateGettingLocation(false);
        }
예제 #5
0
파일: Database.cs 프로젝트: JonaLaw/Digyl
        public async Task <CoordinateItem> QueryCoordinatesAsync(Location at)
        {
            // this is not optimal, it should be replaced by a custom sqlite function
            List <CoordinateItem> coordinateItems = await _database.Table <CoordinateItem>().Where(c => c.IsOn).ToListAsync();

            foreach (CoordinateItem item in coordinateItems)
            {
                if (LocationDetails.IsInLocation(at, item))
                {
                    return(item);
                }
            }

            return(null);
            //return await _database.Table<CoordinateItem>().Where(c => c.IsOn &&
            //(Location.CalculateDistance(at, c.Latitude, c.Longitude, DistanceUnits.Kilometers) <= c.Radius)).FirstOrDefaultAsync();
        }
예제 #6
0
        private async Task TriggerAlert(PlaceTypeItem item, bool action)
        {
            Debug.WriteLine($"Triggered Alter for {item.Name}, {action}");
            int id = await LocationDetails.AddHistoryItem(item, action);

            string notifTitle;
            string notifText;

            if (action)
            {
                notifTitle = $"{Constants.actionEnter} {Constants.placeTypeName}: {item.NameReadable}";
                notifText  = $"Reminder to {item.OnEnterReminder}";
            }
            else
            {
                notifTitle = $"{Constants.actionExit} {Constants.placeTypeName}: {item.NameReadable}";
                notifText  = $"Reminder to {item.OnExitReminder}";
            }

            locationDependencyService.UpdateNotification(notifTitle, notifText, id);
        }
예제 #7
0
        async void OnViewInMapButtonClicked(object sender, EventArgs e)
        {
            if (!await LocationDetails.ValidateCoordinates(latitudeEntry.Text, longitudeEntry.Text))
            {
                return;
            }

            Location         location = new Location(double.Parse(latitudeEntry.Text), double.Parse(longitudeEntry.Text));
            MapLaunchOptions options  = new MapLaunchOptions {
                Name = nameEntry.Text
            };

            try
            {
                await Map.OpenAsync(location, options);
            }
            catch
            {
                // No map application available to open
                await DisplayAlert("View On Map Failure", "There is no map application available to open.", "OK");
            }
        }
예제 #8
0
        async void OnAddHistoryButtonClicked(object sender, EventArgs e)
        {
            Button         aButton        = sender as Button;
            CoordinateItem coordinateItem = aButton.BindingContext as CoordinateItem;

            string action;

            if (coordinateItem.OnEnter)
            {
                if (coordinateItem.OnExit)
                {
                    action = await DisplayActionSheet("Adding manual history activity, select the movement type.", "Cancel", null, Constants.actionEnter, Constants.actionExit);
                }
                else
                {
                    action = await DisplayActionSheet("Adding manual history activity, select the movement type.", "Cancel", null, Constants.actionEnter);
                }
            }
            else if (coordinateItem.OnExit)
            {
                action = await DisplayActionSheet("Adding manual history activity, select the movement type.", "Cancel", null, Constants.actionExit);
            }
            else
            {
                throw new System.ArgumentException("All coordinate Items must have an on enter and/or an on exit reminder.", "coordinateItem.OnEnter, coordinateItem.OnExit");
            }

            if (action == null || action.Equals("Cancel"))
            {
                return;
            }

            LocationDetails.AddHistoryItem(coordinateItem, action);

            //await DisplayAlert("History Item added", $"A history item for {coordinateItem.Name} was created.", "OK");
        }
예제 #9
0
        /*public async void StartLocationHandler()
         * {
         *
         * }*/

        public async Task UpdateLocation(double latitude, double longitude)
        {
            Location newLocation = new Location(latitude, longitude);

            Debug.WriteLine($"Updated location: ({latitude}, {longitude})");

            if (App.Settings.CoordinateTrackingEnabled)
            {
                if (trackedCoordinateItem != null)
                {
                    if (!LocationDetails.IsInLocation(newLocation, trackedCoordinateItem))
                    {
                        if (trackedCoordinateItem.OnExit)
                        {
                            _ = TriggerAlert(trackedCoordinateItem, false);
                        }
                        trackedCoordinateItem = null;
                    }
                    return;
                }

                CoordinateItem foundCoordinateItem = await App.Database.QueryCoordinatesAsync(newLocation);

                if (foundCoordinateItem != null)
                {
                    trackedCoordinateItem = foundCoordinateItem;
                    if (trackedCoordinateItem.OnEnter)
                    {
                        _ = TriggerAlert(trackedCoordinateItem, true);
                    }
                    return;
                }
            }

            /*else
             * {
             *  trackedCoordinateItem = null;
             * }*/

            if (App.Settings.PlaceTrackingEnabled)
            {
                if (trackedPlaceTypeItem != null)
                {
                    if (!LocationDetails.IsInLocation(newLocation, startLocation, App.Settings.PlaceTypeLeaveRadius))
                    {
                        List <string> foundPlaceTypes = await LocationDetails.GetNearbyPlaceTypes(newLocation);

                        if (foundPlaceTypes.Exists(x => x.Equals(trackedPlaceTypeItem.Name)))
                        {
                            startLocation = newLocation;
                        }
                        else
                        {
                            if (trackedPlaceTypeItem.OnExit)
                            {
                                _ = TriggerAlert(trackedPlaceTypeItem, false);
                            }
                            trackedPlaceTypeItem = null;
                        }
                    }
                    return;
                }
                else
                {
                    List <string> foundPlaceTypes = await LocationDetails.GetNearbyPlaceTypes(newLocation);

                    if (foundPlaceTypes.Any())
                    {
                        PlaceTypeItem foundPlaceTypeItem = await App.Database.QueryPlaceTypes(foundPlaceTypes);

                        if (foundPlaceTypeItem != null)
                        {
                            trackedPlaceTypeItem = foundPlaceTypeItem;
                            if (trackedPlaceTypeItem.OnEnter)
                            {
                                _ = TriggerAlert(trackedPlaceTypeItem, true);
                            }
                            startLocation = newLocation;
                            return;
                        }
                    }
                }
            }

            /*else
             * {
             *  trackedPlaceTypeItem = null;
             * }*/
        }
예제 #10
0
        async void OnAddButtonClicked(object sender, EventArgs e)
        {
            if (string.IsNullOrWhiteSpace(nameEntry.Text))
            {
                await DisplayAlert("Incomplete Name Entry", "A name entry is required.", "OK");

                return;
            }

            if (string.IsNullOrWhiteSpace(latitudeEntry.Text) || string.IsNullOrWhiteSpace(longitudeEntry.Text))
            {
                await DisplayAlert("Incomplete Latitude or Longitude Entry", "Both a Latitude and Longitude entry is required.", "OK");

                return;
            }

            if (!await LocationDetails.ValidateCoordinates(latitudeEntry.Text, longitudeEntry.Text))
            {
                return;
            }

            // radius
            if (string.IsNullOrWhiteSpace(radiusEntry.Text))
            {
                await DisplayAlert("Incomplete Radius Entry", "A radius entry is required.", "OK");

                return;
            }

            try
            {
                int.Parse(radiusEntry.Text);
            }
            catch
            {
                await DisplayAlert("Invalid Radius Entry", "The radius entry must be a whole number.", "OK");

                return;
            }

            //seconds

            /*if (string.IsNullOrWhiteSpace(secondsEntry.Text))
             * {
             *  await DisplayAlert("Incomplete Seconds Entry", "A seconds entry is required.", "OK");
             *  return;
             * }
             *
             * try
             * {
             *  int.Parse(secondsEntry.Text);
             * }
             * catch
             * {
             *  await DisplayAlert("Invalid Seconds Entry", "The seconds entry must be a whole number.", "OK");
             *  return;
             * }*/

            // reminders
            if (onEnterPicker.SelectedIndex == -1 && onExitPicker.SelectedIndex == -1)
            {
                await DisplayAlert("Incomplete Reminders", "At least one reminder needs to be chosen.", "OK");

                return;
            }

            string onEnterReminder = "";

            if (onEnterPicker.SelectedIndex != -1)
            {
                onEnterReminder = onEnterPicker.SelectedItem.ToString();
            }

            string onExitReminder = "";

            if (onExitPicker.SelectedIndex != -1)
            {
                onExitReminder = onExitPicker.SelectedItem.ToString();
            }

            try
            {
                if (editingItem != null)
                {
                    editingItem.Name      = nameEntry.Text;
                    editingItem.Latitude  = double.Parse(latitudeEntry.Text);
                    editingItem.Longitude = double.Parse(longitudeEntry.Text);
                    editingItem.Radius    = int.Parse(radiusEntry.Text);
                    //editingItem.Seconds = int.Parse(secondsEntry.Text);
                    editingItem.OnEnter         = onEnterPicker.SelectedIndex != -1;
                    editingItem.OnExit          = onExitPicker.SelectedIndex != -1;
                    editingItem.OnEnterReminder = onEnterReminder;
                    editingItem.OnExitReminder  = onExitReminder;
                }
                else
                {
                    editingItem = new CoordinateItem
                    {
                        Name      = nameEntry.Text,
                        Latitude  = double.Parse(latitudeEntry.Text),
                        Longitude = double.Parse(longitudeEntry.Text),
                        Radius    = int.Parse(radiusEntry.Text),
                        //Seconds = int.Parse(secondsEntry.Text),
                        Seconds         = 0,
                        OnEnter         = onEnterPicker.SelectedIndex != -1,
                        OnExit          = onExitPicker.SelectedIndex != -1,
                        OnEnterReminder = onEnterReminder,
                        OnExitReminder  = onExitReminder,
                        IsOn            = false
                    };
                }
            }
            catch
            {
                await DisplayAlert("Invalid Entry", "An entry field contains invalid characters.", "OK");

                return;
            }

            await App.Database.SaveCoordinateAsync(editingItem);

            await Navigation.PopAsync();
        }