/// <summary> /// Initializes a new instance of the <see cref="SensusUI.ProximityTriggersPage"/> class. /// </summary> /// <param name="proximityProbe">Proximity probe to display triggers for.</param> public ProximityTriggersPage(IPointsOfInterestProximityProbe proximityProbe) { Title = "Proximity Triggers"; ListView triggerList = new ListView(); triggerList.ItemTemplate = new DataTemplate(typeof(TextCell)); triggerList.ItemTemplate.SetBinding(TextCell.TextProperty, new Binding(".", stringFormat: "{0}")); triggerList.ItemsSource = proximityProbe.Triggers; triggerList.ItemTapped += async(o, e) => { if (triggerList.SelectedItem == null) { return; } PointOfInterestProximityTrigger selectedTrigger = triggerList.SelectedItem as PointOfInterestProximityTrigger; string selectedAction = await DisplayActionSheet(selectedTrigger.ToString(), "Cancel", null, "Delete"); if (selectedAction == "Delete") { if (await DisplayAlert("Delete " + selectedTrigger + "?", "This action cannot be undone.", "Delete", "Cancel")) { proximityProbe.Triggers.Remove(selectedTrigger); triggerList.SelectedItem = null; // reset manually since it isn't done automatically UiBoundSensusServiceHelper.Get(true).SaveAsync(); } } }; Content = triggerList; ToolbarItems.Add(new ToolbarItem(null, "plus.png", async() => { if (UiBoundSensusServiceHelper.Get(true).PointsOfInterest.Union(proximityProbe.Protocol.PointsOfInterest).Count() > 0) { await Navigation.PushAsync(new AddProximityTriggerPage(proximityProbe)); } else { UiBoundSensusServiceHelper.Get(true).FlashNotificationAsync("You must define points of interest before adding triggers."); } })); }
/// <summary> /// Initializes a new instance of the <see cref="SensusUI.ProximityTriggersPage"/> class. /// </summary> /// <param name="proximityProbe">Proximity probe to display triggers for.</param> public ProximityTriggersPage(IPointsOfInterestProximityProbe proximityProbe) { Title = "Proximity Triggers"; ListView triggerList = new ListView(); triggerList.ItemTemplate = new DataTemplate(typeof(TextCell)); triggerList.ItemTemplate.SetBinding(TextCell.TextProperty, new Binding(".", stringFormat: "{0}")); triggerList.ItemsSource = proximityProbe.Triggers; triggerList.ItemTapped += async (o, e) => { if (triggerList.SelectedItem == null) return; PointOfInterestProximityTrigger selectedTrigger = triggerList.SelectedItem as PointOfInterestProximityTrigger; string selectedAction = await DisplayActionSheet(selectedTrigger.ToString(), "Cancel", null, "Delete"); if (selectedAction == "Delete") { if (await DisplayAlert("Delete " + selectedTrigger + "?", "This action cannot be undone.", "Delete", "Cancel")) { proximityProbe.Triggers.Remove(selectedTrigger); triggerList.SelectedItem = null; // reset manually since it isn't done automatically SensusServiceHelper.Get().SaveAsync(); } } }; Content = triggerList; ToolbarItems.Add(new ToolbarItem(null, "plus.png", async () => { if (SensusServiceHelper.Get().PointsOfInterest.Union(proximityProbe.Protocol.PointsOfInterest).Count() > 0) await Navigation.PushAsync(new AddProximityTriggerPage(proximityProbe)); else SensusServiceHelper.Get().FlashNotificationAsync("You must define points of interest before adding triggers."); })); }
/// <summary> /// Initializes a new instance of the <see cref="AddProximityTriggerPage"/> class. /// </summary> /// <param name="proximityProbe">Proximity probe to add trigger to.</param> public AddProximityTriggerPage(IPointsOfInterestProximityProbe proximityProbe) { _proximityProbe = proximityProbe; Title = "Add Trigger"; List <PointOfInterest> pointsOfInterest = SensusServiceHelper.Get().PointsOfInterest.Union(_proximityProbe.Protocol.PointsOfInterest).ToList(); if (pointsOfInterest.Count == 0) { Content = new Label { Text = "No points of interest defined. Please define one or more before creating triggers.", FontSize = 20 }; return; } StackLayout contentLayout = new StackLayout { Orientation = StackOrientation.Vertical, VerticalOptions = LayoutOptions.FillAndExpand }; #region point of interest Label pointOfInterestLabel = new Label { Text = "POI:", FontSize = 20 }; Picker pointOfInterestPicker = new Picker { Title = "Select POI", HorizontalOptions = LayoutOptions.FillAndExpand }; foreach (string poiDesc in pointsOfInterest.Select(poi => poi.ToString())) { pointOfInterestPicker.Items.Add(poiDesc); } pointOfInterestPicker.SelectedIndexChanged += (o, e) => { if (pointOfInterestPicker.SelectedIndex < 0) { _pointOfInterestName = _pointOfInterestType = null; } else { PointOfInterest poi = pointsOfInterest[pointOfInterestPicker.SelectedIndex]; _pointOfInterestName = poi.Name; _pointOfInterestType = poi.Type; } }; contentLayout.Children.Add(new StackLayout { Orientation = StackOrientation.Horizontal, HorizontalOptions = LayoutOptions.FillAndExpand, Children = { pointOfInterestLabel, pointOfInterestPicker } }); #endregion #region distance threshold Label distanceThresholdLabel = new Label { Text = "Distance Threshold (Meters):", FontSize = 20 }; Entry distanceThresholdEntry = new Entry { HorizontalOptions = LayoutOptions.FillAndExpand, Keyboard = Keyboard.Numeric }; distanceThresholdEntry.TextChanged += async(o, e) => { if (!double.TryParse(distanceThresholdEntry.Text, out _distanceThresholdMeters)) { _distanceThresholdMeters = -1; } else if (_distanceThresholdMeters < GpsReceiver.Get().MinimumDistanceThreshold) { await SensusServiceHelper.Get().FlashNotificationAsync("Distance threshold must be at least " + GpsReceiver.Get().MinimumDistanceThreshold + "."); } }; contentLayout.Children.Add(new StackLayout { Orientation = StackOrientation.Horizontal, HorizontalOptions = LayoutOptions.FillAndExpand, Children = { distanceThresholdLabel, distanceThresholdEntry } }); #endregion #region threshold direction Label thresholdDirectionLabel = new Label { Text = "Threshold Direction:", FontSize = 20 }; ProximityThresholdDirection[] thresholdDirections = new ProximityThresholdDirection[] { ProximityThresholdDirection.Within, ProximityThresholdDirection.Outside }; Picker thresholdDirectionPicker = new Picker { Title = "Select Threshold Direction", HorizontalOptions = LayoutOptions.FillAndExpand }; foreach (ProximityThresholdDirection thresholdDirection in thresholdDirections) { thresholdDirectionPicker.Items.Add(thresholdDirection.ToString()); } thresholdDirectionPicker.SelectedIndexChanged += (o, e) => { if (thresholdDirectionPicker.SelectedIndex < 0) { _thresholdDirection = ProximityThresholdDirection.Within; } else { _thresholdDirection = thresholdDirections[thresholdDirectionPicker.SelectedIndex]; } }; contentLayout.Children.Add(new StackLayout { Orientation = StackOrientation.Horizontal, HorizontalOptions = LayoutOptions.FillAndExpand, Children = { thresholdDirectionLabel, thresholdDirectionPicker } }); #endregion Button okButton = new Button { Text = "OK", FontSize = 20 }; okButton.Clicked += async(o, e) => { try { _proximityProbe.Triggers.Add(new PointOfInterestProximityTrigger(_pointOfInterestName, _pointOfInterestType, _distanceThresholdMeters, _thresholdDirection)); await Navigation.PopAsync(); } catch (Exception ex) { string message = "Failed to add trigger: " + ex.Message; await SensusServiceHelper.Get().FlashNotificationAsync(message); SensusServiceHelper.Get().Logger.Log(message, LoggingLevel.Normal, GetType()); } }; contentLayout.Children.Add(okButton); Content = new ScrollView { Content = contentLayout }; }
/// <summary> /// Initializes a new instance of the <see cref="SensusUI.AddProximityTriggerPage"/> class. /// </summary> /// <param name="proximityProbe">Proximity probe to add trigger to.</param> public AddProximityTriggerPage(IPointsOfInterestProximityProbe proximityProbe) { _proximityProbe = proximityProbe; Title = "Add Trigger"; List<PointOfInterest> pointsOfInterest = UiBoundSensusServiceHelper.Get(true).PointsOfInterest.Union(_proximityProbe.Protocol.PointsOfInterest).ToList(); if (pointsOfInterest.Count == 0) { Content = new Label { Text = "No points of interest defined. Please define one or more before creating triggers.", FontSize = 20 }; return; } StackLayout contentLayout = new StackLayout { Orientation = StackOrientation.Vertical, VerticalOptions = LayoutOptions.FillAndExpand }; #region point of interest Label pointOfInterestLabel = new Label { Text = "POI:", FontSize = 20 }; Picker pointOfInterestPicker = new Picker { Title = "Select POI", HorizontalOptions = LayoutOptions.FillAndExpand }; foreach (string poiDesc in pointsOfInterest.Select(poi => poi.ToString())) pointOfInterestPicker.Items.Add(poiDesc); pointOfInterestPicker.SelectedIndexChanged += (o, e) => { if (pointOfInterestPicker.SelectedIndex < 0) _pointOfInterestName = _pointOfInterestType = null; else { PointOfInterest poi = pointsOfInterest[pointOfInterestPicker.SelectedIndex]; _pointOfInterestName = poi.Name; _pointOfInterestType = poi.Type; } }; contentLayout.Children.Add(new StackLayout { Orientation = StackOrientation.Horizontal, HorizontalOptions = LayoutOptions.FillAndExpand, Children = { pointOfInterestLabel, pointOfInterestPicker } }); #endregion #region distance threshold Label distanceThresholdLabel = new Label { Text = "Distance Threshold (Meters):", FontSize = 20 }; Entry distanceThresholdEntry = new Entry { HorizontalOptions = LayoutOptions.FillAndExpand, Keyboard = Keyboard.Numeric }; distanceThresholdEntry.TextChanged += (o, e) => { if (!double.TryParse(distanceThresholdEntry.Text, out _distanceThresholdMeters)) _distanceThresholdMeters = -1; else if (_distanceThresholdMeters < GpsReceiver.Get().MinimumDistanceThreshold) UiBoundSensusServiceHelper.Get(true).FlashNotificationAsync("Distance threshold must be at least " + GpsReceiver.Get().MinimumDistanceThreshold + "."); }; contentLayout.Children.Add(new StackLayout { Orientation = StackOrientation.Horizontal, HorizontalOptions = LayoutOptions.FillAndExpand, Children = { distanceThresholdLabel, distanceThresholdEntry } }); #endregion #region threshold direction Label thresholdDirectionLabel = new Label { Text = "Threshold Direction:", FontSize = 20 }; ProximityThresholdDirection[] thresholdDirections = new ProximityThresholdDirection[]{ ProximityThresholdDirection.Within, ProximityThresholdDirection.Outside }; Picker thresholdDirectionPicker = new Picker { Title = "Select Threshold Direction", HorizontalOptions = LayoutOptions.FillAndExpand }; foreach (ProximityThresholdDirection thresholdDirection in thresholdDirections) thresholdDirectionPicker.Items.Add(thresholdDirection.ToString()); thresholdDirectionPicker.SelectedIndexChanged += (o, e) => { if (thresholdDirectionPicker.SelectedIndex < 0) _thresholdDirection = ProximityThresholdDirection.Within; else _thresholdDirection = thresholdDirections[thresholdDirectionPicker.SelectedIndex]; }; contentLayout.Children.Add(new StackLayout { Orientation = StackOrientation.Horizontal, HorizontalOptions = LayoutOptions.FillAndExpand, Children = { thresholdDirectionLabel, thresholdDirectionPicker } }); #endregion Button okButton = new Button { Text = "OK", FontSize = 20 }; okButton.Clicked += async (o, e) => { try { _proximityProbe.Triggers.Add(new PointOfInterestProximityTrigger(_pointOfInterestName, _pointOfInterestType, _distanceThresholdMeters, _thresholdDirection)); UiBoundSensusServiceHelper.Get(true).SaveAsync(); await Navigation.PopAsync(); } catch (Exception ex) { string message = "Failed to add trigger: " + ex.Message; UiBoundSensusServiceHelper.Get(true).FlashNotificationAsync(message); UiBoundSensusServiceHelper.Get(true).Logger.Log(message, LoggingLevel.Normal, GetType()); } }; contentLayout.Children.Add(okButton); Content = new ScrollView { Content = contentLayout }; }