Esempio n. 1
0
        private async void PhoneApplicationPage_Loaded(object sender, RoutedEventArgs e)
        {
            // Update current dispatcher
            Util.CurrentDispatcher = this.Dispatcher;

            if (startup)
            {
                startup = false;

                // Setup system tray
                SystemTray.SetProgressIndicator(this, ProgressIndicatorHelper.Instance.PI);
                SystemTray.Opacity         = 0;
                SystemTray.IsVisible       = true;
                SystemTray.ForegroundColor = Colors.Black;

                // Get Permissions
                if (LocationTracker.GetPermission())
                {
                    // Find location
                    ProgressIndicatorHelper.Instance.Push(LoadingEnum.Location);
                    LocationTracker.RetrieveLocation();
                }

                // Setup speech recognition
                await VoiceHelper.InitializeSpeech();
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Update fields of VM from the location
        /// </summary>
        /// <param name="location"></param>
        public void UpdateFromLocation()
        {
            // Rezoom map
            if (TrackingPage.CurrentInstance.ReZoomMap)
            {
                TrackingPage.CurrentInstance.CenterAndZoom();
            }

            // Update speed tracker
            this.SpeedTracker.AddPosition(LocationTracker.Location);
            if (!this.ManualEnabled)
            {
                this.NotifyPropertyChanged("Threshold");
                this.NotifyPropertyChanged("ThresholdString");
            }

            // Notify properties
            this.NotifyPropertyChanged("MyLocation");
            this.NotifyPropertyChanged("DistanceLeft");
            this.NotifyPropertyChanged("DistanceString");
            this.NotifyPropertyChanged("EstimatedTimeString");
            this.NotifyPropertyChanged("AverageSpeedString");

            // Raise alarm
            if (this.DistanceLeft.MetersToMiles() <= this.Threshold)
            {
                LocationTracker.StopTracking();
                //MessageBox.Show("Your stop is coming up soon!", "Non-final alarm", MessageBoxButton.OK);
                AlarmHandler.Instance.TriggerAlarm(this.Context);
            }

            this.NotifyPropertyChanged("LeftButtonText");
        }
Esempio n. 3
0
        protected override async void OnNavigatedTo(NavigationEventArgs e)
        {
            base.OnNavigatedTo(e);

            // Update current dispatcher
            Util.CurrentDispatcher = this.Dispatcher;

            if (this.startup)
            {
                // Initialize progress bar
                this.InitializeProgress();

                // Setup ViewModel
                string route_id;
                string route_name;
                if (this.NavigationContext.QueryString.TryGetValue("route_id", out route_id))
                {
                    this.ViewModel = new StopResultVM(AppSettings.KnownRoutes.Value[route_id]);
                    await InitializeFromViewModel();
                }
                else if (this.NavigationContext.QueryString.TryGetValue(VoiceHelper.RouteNumPhraseList, out route_name))
                {
                    ProgressIndicatorHelper.Instance.Push(LoadingEnum.Routes);
                    BusRoute br = await TransitInfo.SearchForRoute(route_name);

                    ProgressIndicatorHelper.Instance.Remove(LoadingEnum.Routes);
                    if (LocationTracker.GetPermission())
                    {
                        LocationTracker.RetrieveLocation();
                    }
                    if (br != null)
                    {
                        this.ViewModel = new StopResultVM(br);
                        await InitializeFromViewModel();
                    }
                    else
                    {
                        MessageBox.Show(string.Format("Could not find route {0}.", route_name),
                                        "No matches", MessageBoxButton.OK);
                    }
                }
            }
        }
Esempio n. 4
0
        /// <summary>
        /// Finish initialization after setting the viewmodel
        /// </summary>
        private void InitializeFromViewModel()
        {
            this.DataContext = this.ViewModel;

            // Initialize progress bar
            InitializeProgress();

            // Get location if necessary
            if (LocationTracker.Location == null && LocationTracker.GetPermission())
            {
                ProgressIndicatorHelper.Instance.Push(LoadingEnum.Location);
                LocationTracker.RetrieveLocation();
            }

            // Update recent stops
            RecentStopsQueue.Push(ViewModel.Context);

            // Preven further initialization
            this.startup = false;
        }
Esempio n. 5
0
        /// <summary>
        /// Respond to clicks on the awesome appbar
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void AppBarButton_Click(object sender, RoutedEventArgs e)
        {
            Button btn = sender as Button;

            switch (btn.Content.ToString())
            {
            case TrackingVM.BtnPinToStart:
                BusStop.PinToStart(this.ViewModel.Context);
                break;

            case TrackingVM.BtnStartTracking:
                if (LocationTracker.GetPermission())
                {
                    this.ViewModel.BeginGeofence();
                }
                break;

            case TrackingVM.BtnStopTracking:
                this.ViewModel.StopGeofence();
                break;
            }
        }
Esempio n. 6
0
        /// <summary>
        /// Search the text in the route box
        /// </summary>
        /// <returns></returns>
        private async Task SearchRoutes()
        {
            this.Focus();

            // Blank route
            if (this.RouteSearchBox.Text == EmptyTextBox ||
                string.IsNullOrWhiteSpace(this.RouteSearchBox.Text))
            {
                MessageBox.Show("Please enter the number of a bus route in your area.",
                                "No input", MessageBoxButton.OK);
                return;
            }

            ProgressIndicatorHelper.Instance.Push(LoadingEnum.Routes);
            BusRoute br = await TransitInfo.SearchForRoute(this.RouteSearchBox.Text);

            if (br == null && !AppSettings.LocationConsent.Value && LocationTracker.GetPermission())
            {
                br = await TransitInfo.SearchForRoute(this.RouteSearchBox.Text);
            }
            ProgressIndicatorHelper.Instance.Remove(LoadingEnum.Routes);
            if (br == null)
            {
                TransitLoader.InternetAvailable();
                MessageBox.Show(string.Format("Could not find route {0}.", this.RouteSearchBox.Text),
                                "No matches", MessageBoxButton.OK);
                return;
            }

            this.RouteSearchBox.Text = "";
            if (this.SpacingPanel.Height == spacerMaxHeight)
            {
                this.SetSearchBarVisibility(Visibility.Collapsed);
            }
            NavigationService.Navigate(new Uri(
                                           string.Format("/Pages/StopResultPage.xaml?route_id={0}", br.Id),
                                           UriKind.Relative));
            //NavigationService.Navigate(new Uri("/Pages/StopResultPage.xaml", UriKind.Relative));
        }
Esempio n. 7
0
 /// <summary>
 /// Stop the geofencing.
 /// This should only be called in foreground.
 /// </summary>
 public void StopGeofence()
 {
     LocationTracker.StopTracking();
     this.NotifyLeftButton();
     AlarmHandler.Instance.ClearAlarms();
 }
Esempio n. 8
0
 /// <summary>
 /// Initialize all controls for geofencing.
 /// This should only be called in foreground.
 /// </summary>
 public void BeginGeofence()
 {
     LocationTracker.StartTracking();
     this.NotifyLeftButton();
     AlarmHandler.Instance.PrepareAlarm(this.Context);
 }