/// <summary> /// Gets default GPS setting data if it is there /// </summary> /// <returns>GPSSetting or null</returns> public async Task <GPSSetting> GetSetting() { var settingsStore = new GPSSettingStore(); GPSSetting setting = await settingsStore.GetAsync(); return(setting); }
/// <summary> /// /// </summary> public async Task UpdateSettingAsync() { GPSSetting setting = new GPSSetting(); setting.Mode = SelectedMode; setting.Destination = GPSDestination; await gpsSettingStore.UpdateAsync(setting); SavedDest = setting.Destination; SavedMode = setting.Mode; }
/// <summary> /// Gets the first text direction using the current GPS Location and /// settings passed in /// </summary> /// <param name="settings">the settings for where you want to go</param> /// <returns>the first direction in the list</returns> private async Task <string> GetFirstDirection(GPSSetting settings) { try { //make destination string with '+' for spaces string dest = settings.Destination; dest = dest.Replace(" ", "+"); Rootobject directions = await GetDirectionsAsync(dest, settings.Mode); Route firstRoute = directions.routes[0]; //this is where the steps can be found Leg getLeg = firstRoute.legs[0]; //get first step Step firstStep = getLeg.steps[0]; //get next direction string string nextDirection = firstStep.html_instructions; //reference: https://stackoverflow.com/questions/787932/using-c-sharp-regular-expressions-to-remove-html-tags //From user: Daniel Brückner and edited by verdesmarald //This handles most cases for HTML tags but not all as described in the link String result = Regex.Replace(nextDirection, @"<[^>]*>", String.Empty); //add spaces to fix the no spaces between sentences cause by previous regex result = Regex.Replace(result, @"Continue", " Continue"); result = Regex.Replace(result, @"Destination", " Destination"); result = Regex.Replace(result, @"Toll", " Toll"); result = Regex.Replace(result, @"Pass", " Pass"); result = Regex.Replace(result, @"Entering", " Entering"); result = Regex.Replace(result, @"Restricted", " Restricted"); //replace edge cases result = Regex.Replace(result, @"&nbsq;", " "); //assumption is that this text is being read out loud //replace things that the text to sound reader doesn't understand result = result.Replace("N", "North"); result = result.Replace("E", "East"); result = result.Replace("S", "South"); result = result.Replace("W", "West"); result = result.Replace("/", " "); return(result); } catch (Exception e) { return("Could not get direction. Please check internet connection and try again"); } }
/// <summary> /// Begins the listening for messages, and signals from the signal app /// </summary> public void StartListening() { SubscribeGeneralMessage(Gestures.UP); SubscribeGeneralMessage(Gestures.DOWN); SubscribeGeneralMessage(Gestures.LEFT); SubscribeGeneralMessage(Gestures.RIGHT); IMusicManager musicManager = new SpotifyManager(); actionHandler.RegisterMusicManager(musicManager); MessagingCenter.Subscribe <SettingsViewModel>(this, Gestures.SPOTIFY, async message => { if (!actionHandler.HasAuthenticatedMusicManager) { MessagingCenter.Subscribe <SpotifyLoginMessage>(this, "LoginSuccess", message => { if (!actionHandler.HasAuthenticatedMusicManager) { actionHandler.UpdateMusicManagerAuthentication(true); MessagingCenter.Send(new SpotifyLoginMessage("RegistrationSuccess", message.HasPremium), "RegistrationSuccess"); } }); await musicManager.Init(); } }); MessagingCenter.Subscribe <DNDPermissionMessage>(this, "DNDAdded", message => { if (!notificationManager.IsNotificationPolicyAccessGranted) { Intent intent = new Intent(Android.Provider.Settings.ActionNotificationPolicyAccessSettings); StartActivity(intent); } else { MessagingCenter.Send(new DNDPermissionMessage(), "DNDGranted"); } }); MessagingCenter.Subscribe <string>(this, "GPSRoute", async message => { GPSManager gpsManager = new GPSManager(); GPSHandler handler = new GPSHandler(); GPSSetting setting = await handler.GetSetting(); Rootobject root = await gpsManager.GetDirectionsAsync(setting.Destination, setting.Mode); if (root.status.Equals("NOT_FOUND")) { MessagingCenter.Send <string>("", "Unsuccessful"); return; } MessagingCenter.Send <string, Rootobject>("", "GetRoute", root); }); }
/// <summary> /// Gets the Next direction in the list and returns it by gettin the settings stored /// in the phone and getting the first direction /// </summary> /// <returns></returns> public async Task <string> GetNextDirectionAsync() { //get GPSInfo saved to phone GPSHandler handler = new GPSHandler(); GPSSetting settings = await handler.GetSetting(); if (settings == null) { return("please add a destination and choose a transportation mode on the GPS settings page."); } //use GPSInfo to get directions string getDirection = await GetFirstDirection(settings); //return what the app needs to say return(getDirection); }
/// <summary> /// /// </summary> /// <returns></returns> private async Task InitSettingsAsync() { GPSSetting setting; try { setting = await gpsSettingStore.GetAsync(); } catch (System.Collections.Generic.KeyNotFoundException) { setting = new GPSSetting() { Destination = "", Mode = "" }; } SavedMode = setting.Mode; SavedDest = setting.Destination; SelectedMode = setting.Mode; GPSDestination = setting.Destination; }