public async Task RefreshView(int refreshType) { if (!IsInternet()) { await new MessageDialog("Seems you are not connected to the Internet").ShowAsync(); return; } else { List <Cab> refreshed = new List <Cab>(); if (refreshType == REFRESH_SURGE) { CabsResponse res = await _cabsApi.GetNearbyCabs(_startLat, _startLng, _token); if (res.Code == ResponseCode.SUCCESS) { refreshed = res.Cabs; } } else if (refreshType == REFRESH_ESTIMATE) { PriceEstimateResponse res = await _cabsApi.GetEstimate(_token, _startLat, _startLng, _endLat, _endLng); if (res.Code == ResponseCode.SUCCESS) { foreach (var estimate in res.Estimates) { Cab cab = new Cab(); cab.Provider = estimate.Provider; cab.Eta = estimate.Eta; cab.ImageURL = estimate.ImageURL; cab.Type = estimate.Type; cab.Time = estimate.CurrentEstimate.Time; cab.Distance = estimate.CurrentEstimate.Distance; cab.FareData = estimate.CurrentEstimate.FareData; cab.FareData.Surge = estimate.CurrentEstimate.LowRange + "-" + estimate.CurrentEstimate.HighRange; refreshed.Add(cab); } } } Cabs = refreshed; } }
private async void mDestinationTextBoxClicked(object sender, AdapterView.ItemClickEventArgs e) { dest = destinationSuggestionsAdapter.GetObjectAt(e.Position); System.Diagnostics.Debug.Write(dest); autoDestinationBox.Text = destinationSuggestionsAdapter.GetObjectAt(e.Position); if (msourceRecieved != null && dest != null) { GeoResponse mResponseGetDestlatlng = await api.GeoCodingResult(token, dest); dlat = mResponseGetDestlatlng.Position.Latitude; dlng = mResponseGetDestlatlng.Position.Longitude; setDestinationMarker(dest); mLoadingDialog.Show(); PriceEstimateResponse mRes = await api.GetEstimate(token, slat, slng, dlat, dlng); mCabsEst = mRes.Estimates; CabRecyclerAdapterWithDestination mAdapter = new CabRecyclerAdapterWithDestination(Application.Context, mCabsEst, mActivity); mAdapter.ItemClick1 += Item_Click_New; mRecyclerView.SetAdapter(mAdapter); mLoadingDialog.Dismiss(); } }
private async Task SendCompletionMessageForBookFromXtoY(string source, string destination) { string gettingCabsFromXtoY = "Getting Details of your " + source + " and " + destination; await ShowProgressScreen(gettingCabsFromXtoY); CabsAPI api = new CabsAPI(); string token = Windows.Storage.ApplicationData.Current.LocalSettings.Values["Token"].ToString(); string loadingCabsFromXtoY = "Loading Details of cabs from " + source + " and " + destination; await ShowProgressScreen(loadingCabsFromXtoY); PlacesResponse sResponse = await api.GetPlaceLocation(source.ToLower(), token); PlacesResponse dResponse = await api.GetPlaceLocation(destination.ToLower(), token); //ReadSpeech(new MediaElement(), sResponse.Location.Latitude + " ok " + dResponse.Location.Longitude); PriceEstimateResponse pRespone = await api.GetEstimate(token, sResponse.Location.Latitude, sResponse.Location.Longitude, dResponse.Location.Latitude, dResponse.Location.Longitude); var userMessage = new VoiceCommandUserMessage(); var cabTiles = new List <VoiceCommandContentTile>(); List <CabEstimate> cabsAvaialble = pRespone.Estimates; CabEstimate cabSelected; if (cabsAvaialble == null) { string foundNoCabs = "Sorry No Cabs Found"; userMessage.DisplayMessage = foundNoCabs; userMessage.SpokenMessage = foundNoCabs; } else { string message = "Ok! I have found the following Cabs for you"; userMessage.DisplayMessage = message; userMessage.SpokenMessage = message; cabSelected = await AvailableList(cabsAvaialble, "Which cab do you want to book?", "Book the selected cab?"); var userPrompt = new VoiceCommandUserMessage(); VoiceCommandResponse response; string BookCabToDestination = "Booking " + cabSelected.Provider + " with " + cabSelected.Type + " from " + source + " to " + destination + " arriving in " + cabSelected.Eta + " with " + cabSelected.CurrentEstimate.LowRange + " to " + cabSelected.CurrentEstimate.HighRange + " cost estimation"; userPrompt.DisplayMessage = userPrompt.SpokenMessage = BookCabToDestination; var userReprompt = new VoiceCommandUserMessage(); string confirmBookCabToDestination = "Confirm booking"; userReprompt.DisplayMessage = userReprompt.SpokenMessage = confirmBookCabToDestination; response = VoiceCommandResponse.CreateResponseForPrompt(userPrompt, userReprompt); var voiceCommandConfirmation = await voiceServiceConnection.RequestConfirmationAsync(response); if (voiceCommandConfirmation != null) { if (voiceCommandConfirmation.Confirmed == true) { string BookingCabToDestination = "Booking cab"; await ShowProgressScreen(BookingCabToDestination); BookingDetailsResponse booking = await api.BookCab(token, sResponse.Location.Latitude, sResponse.Location.Longitude); var userMessage1 = new VoiceCommandUserMessage(); string BookCabInformation = "Cab booked. your cab driver " + booking.BookingData.DriverDetails.Name + "will be arriving shortly."; //Vehicle number :"+ booking.BookingData.VehicleDetails.License_Plate; userMessage.DisplayMessage = userMessage.SpokenMessage = BookCabInformation; var cabShow = new VoiceCommandContentTile(); cabShow.ContentTileType = VoiceCommandContentTileType.TitleWithText; cabShow.Title = cabSelected.Type; cabShow.TextLine1 = "ETA : " + cabSelected.Eta; cabShow.TextLine2 = "Estimated Fare: " + cabSelected.CurrentEstimate.LowRange + "-" + cabSelected.CurrentEstimate.HighRange; cabShow.TextLine3 = "Call driver at " + booking.BookingData.DriverDetails.Phone_Number; cabTiles.Add(cabShow); userMessage1.DisplayMessage = userMessage1.SpokenMessage = BookCabInformation; response = VoiceCommandResponse.CreateResponse(userMessage1, cabTiles); await voiceServiceConnection.ReportSuccessAsync(response); } else { userMessage = new VoiceCommandUserMessage(); string BookingCabToDestination = "Cancelling cab request..."; await ShowProgressScreen(BookingCabToDestination); string keepingTripToDestination = "Cancelled."; userMessage.DisplayMessage = userMessage.SpokenMessage = keepingTripToDestination; response = VoiceCommandResponse.CreateResponse(userMessage); await voiceServiceConnection.ReportSuccessAsync(response); } } } }
private async Task SendCompletionMessageForCostEstimate(string source, string destination) { string slat, slng, dlat, dlng, token, mDisplay; slat = slng = dlng = dlat = null; var mUserMessage = new VoiceCommandUserMessage(); var mUserPrompt = new VoiceCommandUserMessage(); VoiceCommandResponse mResponseError; VoiceCommandContentTile mCabTile = new VoiceCommandContentTile(); CabsAPI mCabsApi = new CabsAPI(); GeoResponse mGeoResp; List <VoiceCommandContentTile> mCabTiles = new List <VoiceCommandContentTile>(); token = Windows.Storage.ApplicationData.Current.LocalSettings.Values["Token"].ToString(); if (destination.Equals("")) { await ShowProgressScreen("Insufficient Info"); mDisplay = "Sorry no destination provided Please enter a valid destination"; mUserMessage.DisplayMessage = mUserMessage.SpokenMessage = mDisplay; mResponseError = VoiceCommandResponse.CreateResponse(mUserMessage); } else { mGeoResp = await mCabsApi.GeoCodingResult(token, destination); if (mGeoResp.Code == ResponseCode.SUCCESS) { dlat = mGeoResp.Position.Latitude; dlng = mGeoResp.Position.Longitude; } else { mDisplay = "Destination not found"; mUserMessage.DisplayMessage = mUserMessage.SpokenMessage = mDisplay; mResponseError = VoiceCommandResponse.CreateResponse(mUserMessage); await voiceServiceConnection.ReportFailureAsync(mResponseError); } } mGeoResp = await mCabsApi.GeoCodingResult(token, source); if (mGeoResp.Code == ResponseCode.SUCCESS) { slat = mGeoResp.Position.Latitude; slng = mGeoResp.Position.Longitude; } else { mDisplay = "Source not found"; mUserMessage.DisplayMessage = mUserMessage.SpokenMessage = mDisplay; mResponseError = VoiceCommandResponse.CreateResponse(mUserMessage); await voiceServiceConnection.ReportFailureAsync(mResponseError); } string EstimatingCabsFromXtoY = "Getting cost Details from " + source + " to " + destination; await ShowProgressScreen(EstimatingCabsFromXtoY); CabsAPI api = new CabsAPI(); string loadingCabsFromXtoY = "Loading Details of cabs from " + source + " to " + destination; await ShowProgressScreen(loadingCabsFromXtoY); GeoResponse sResponse = await api.GeoCodingResult(token, source); GeoResponse dResponse = await api.GeoCodingResult(token, destination); PriceEstimateResponse pResponse = await api.GetEstimate(token, slat, slng, dlat, dlng); var userMessage = new VoiceCommandUserMessage(); var cabTiles = new List <VoiceCommandContentTile>(); List <CabEstimate> cabsAvaialble = pResponse.Estimates; CabEstimate cabSelected; if (cabsAvaialble == null) { string foundNoCabs = "Sorry No Cabs Found"; userMessage.DisplayMessage = foundNoCabs; userMessage.SpokenMessage = foundNoCabs; } else { string message = "Ok! I have found the following Cabs for you"; userMessage.DisplayMessage = message; userMessage.SpokenMessage = message; cabSelected = await AvailableList(cabsAvaialble, "Which cab do you want to book?", "Book the selected cab?"); var userPrompt = new VoiceCommandUserMessage(); VoiceCommandResponse response; string BookCabToDestination = "Booking " + cabSelected.Provider + " with " + cabSelected.Type + " from " + source + " to " + destination + " arriving in " + cabSelected.Eta + " with " + cabSelected.CurrentEstimate.LowRange + " to " + cabSelected.CurrentEstimate.HighRange + " cost estimation"; userPrompt.DisplayMessage = userPrompt.SpokenMessage = BookCabToDestination; var userReprompt = new VoiceCommandUserMessage(); string confirmBookCabToDestination = "Confirm booking"; userReprompt.DisplayMessage = userReprompt.SpokenMessage = confirmBookCabToDestination; response = VoiceCommandResponse.CreateResponseForPrompt(userPrompt, userReprompt, cabTiles); var voiceCommandConfirmation = await voiceServiceConnection.RequestConfirmationAsync(response); if (voiceCommandConfirmation != null) { if (voiceCommandConfirmation.Confirmed == true) { BookingDetailsResponse booking = await api.BookCab(token, sResponse.Position.Latitude, sResponse.Position.Longitude); string BookingCabToDestination = "Booking cab"; await ShowProgressScreen(BookingCabToDestination); var cabShow = new VoiceCommandContentTile(); cabShow.ContentTileType = VoiceCommandContentTileType.TitleWith68x68IconAndText; if (cabSelected.Provider.Equals("UBER")) { cabShow.Image = await StorageFile.GetFileFromApplicationUriAsync(new Uri("ms-appx:///ContosoCabs.VoiceCommandService/img/uber.png")); } else { cabShow.Image = await StorageFile.GetFileFromApplicationUriAsync(new Uri("ms-appx:///ContosoCabs.VoiceCommandService/img/ola.png")); } cabShow.Title = cabSelected.Type; cabShow.TextLine1 = "ETA : " + cabSelected.Eta; cabShow.TextLine2 = "Estimated Fare: " + cabSelected.CurrentEstimate.LowRange + "-" + cabSelected.CurrentEstimate.HighRange; cabShow.TextLine3 = "Call driver at " + booking.BookingData.DriverDetails.Phone_Number; cabTiles.Add(cabShow); var userMessage1 = new VoiceCommandUserMessage(); string BookCabInformation = "Cab booked. your cab driver " + booking.BookingData.DriverDetails.Name + "will be arriving shortly."; //Vehicle number :"+ booking.BookingData.VehicleDetails.License_Plate userMessage.DisplayMessage = userMessage.SpokenMessage = BookCabInformation; userMessage1.DisplayMessage = userMessage1.SpokenMessage = BookCabInformation; response = VoiceCommandResponse.CreateResponse(userMessage1, cabTiles); await voiceServiceConnection.ReportSuccessAsync(response); } else { userMessage = new VoiceCommandUserMessage(); string BookingCabToDestination = "Cancelling cab request..."; await ShowProgressScreen(BookingCabToDestination); string keepingTripToDestination = "Cancelled."; userMessage.DisplayMessage = userMessage.SpokenMessage = keepingTripToDestination; response = VoiceCommandResponse.CreateResponse(userMessage); await voiceServiceConnection.ReportSuccessAsync(response); } } } }
private async Task SendCompletionMessageForBookToCustomLocation(string location) { string slat, dlat, slng, dlng; GeoResponse locationResponse; string gettingCabsToDesiredLocation = "Getting Details of " + location; await ShowProgressScreen(gettingCabsToDesiredLocation); CabsAPI api = new CabsAPI(); string token = Windows.Storage.ApplicationData.Current.LocalSettings.Values["Token"].ToString(); string loadingCabsToDesiredLocation = "Loading Details of cabs to " + location; await ShowProgressScreen(loadingCabsToDesiredLocation); Geolocator locator = new Geolocator(); var userMessage1 = new VoiceCommandUserMessage(); locator.DesiredAccuracyInMeters = 50; var position = await locator.GetGeopositionAsync(); slat = position.Coordinate.Point.Position.Latitude.ToString(); slng = position.Coordinate.Point.Position.Longitude.ToString(); string latlng1 = slat + "," + slng; ReverseGeoResposne reverse = await api.GetReverseCodingResultlatlng(token, latlng1); locationResponse = await api.GeoCodingResult(token, location); dlat = locationResponse.Position.Latitude; dlng = locationResponse.Position.Longitude; PriceEstimateResponse Responseprice = await api.GetEstimate(token, slat, slng, dlat, dlng); List <CabEstimate> desiredList = Responseprice.Estimates; var sortedCabs = desiredList.OrderBy(o => o.CurrentEstimate.HighRange); var userMessage = new VoiceCommandUserMessage(); var cabTiles = new List <VoiceCommandContentTile>(); if (desiredList == null) { string foundNoCabs = "Sorry No Cabs Found"; userMessage.DisplayMessage = foundNoCabs; userMessage.SpokenMessage = foundNoCabs; } else { string message = "Ok! I have found the Best Cab for you"; userMessage.DisplayMessage = message; userMessage.SpokenMessage = message; var cabsNeeded = desiredList[0]; var cabShow = new VoiceCommandContentTile(); cabShow.ContentTileType = VoiceCommandContentTileType.TitleWith68x68IconAndText; if (cabsNeeded.Provider.Equals("UBER")) { cabShow.Image = await StorageFile.GetFileFromApplicationUriAsync(new Uri("ms-appx:///ContosoCabs.VoiceCommandService/img/uber.png")); } else { cabShow.Image = await StorageFile.GetFileFromApplicationUriAsync(new Uri("ms-appx:///ContosoCabs.VoiceCommandService/img/ola.png")); } cabShow.AppContext = cabsNeeded; cabShow.Title = cabsNeeded.Provider; cabShow.TextLine1 = cabsNeeded.Type; cabShow.TextLine2 = "ETA : " + cabsNeeded.Eta; cabShow.TextLine3 = "Estimated Fare: " + cabsNeeded.CurrentEstimate.LowRange + "-" + cabsNeeded.CurrentEstimate.HighRange; cabTiles.Add(cabShow); var userPrompt = new VoiceCommandUserMessage(); VoiceCommandResponse response1; string source; try { source = reverse.FormattedAddress.Substring(0, reverse.FormattedAddress.IndexOf(", Hyderabad")); } catch { source = reverse.FormattedAddress; } string BookCabToDestination = "Booking " + cabsNeeded.Provider + " with " + cabsNeeded.Type + " from " + source + " to " + location + " arriving in " + cabsNeeded.Eta + cabsNeeded.CurrentEstimate.LowRange + " to " + cabsNeeded.CurrentEstimate.HighRange + " cost estimation"; userPrompt.DisplayMessage = userPrompt.SpokenMessage = BookCabToDestination; var userReprompt = new VoiceCommandUserMessage(); string confirmBookCabToDestination = "confirm booking"; userReprompt.DisplayMessage = userReprompt.SpokenMessage = confirmBookCabToDestination; response1 = VoiceCommandResponse.CreateResponseForPrompt(userPrompt, userReprompt, cabTiles); var voiceCommandConfirmation = await voiceServiceConnection.RequestConfirmationAsync(response1); if (voiceCommandConfirmation != null) { if (voiceCommandConfirmation.Confirmed == true) { BookingDetailsResponse booking = await api.BookCab(token, slat, slng); string BookCabInformation = "Cab booked. your cab driver " + booking.BookingData.DriverDetails.Name + " will be arriving shortly."; userMessage1 = new VoiceCommandUserMessage(); //userPrompt.DisplayMessage = userPrompt.SpokenMessage = BookCabInformation; userMessage.DisplayMessage = userMessage.SpokenMessage = BookCabInformation; userMessage1.DisplayMessage = userMessage1.SpokenMessage = BookCabInformation; var response = VoiceCommandResponse.CreateResponse(userMessage1, cabTiles); await voiceServiceConnection.ReportSuccessAsync(response); } else { userMessage = new VoiceCommandUserMessage(); string BookingCabToDestination = "Cancelling cab request..."; await ShowProgressScreen(BookingCabToDestination); string keepingTripToDestination = "Cancelled."; userMessage.DisplayMessage = userMessage.SpokenMessage = keepingTripToDestination; response1 = VoiceCommandResponse.CreateResponse(userMessage); await voiceServiceConnection.ReportSuccessAsync(response1); } } } }
protected async override void OnNavigatedTo(NavigationEventArgs e) { base.OnNavigatedTo(e); if (!IsInternet()) { await new MessageDialog("Seems you are not connected to the Internet").ShowAsync(); return; } else { progress.IsActive = true; speechRecognition = e.Parameter as SpeechRecognitionResult; mSource = this.SemanticInterpretation("source", speechRecognition); mDestination = this.SemanticInterpretation("destination", speechRecognition); MyMap.MapServiceToken = "YP9WTSzOHUo0dbahsH8J~J-K6u01dT98SF4uCCKpiwA~AnGaYM6yJxoLF1tGHEIXHFskGfwSRJTr1S5aO1dB-TCXjQ1ZX0xEWgeYslbC3Fov"; Geolocator locator = new Geolocator(); locator.DesiredAccuracyInMeters = 50; var position = await locator.GetGeopositionAsync(); await MyMap.TrySetViewAsync(position.Coordinate.Point, 10D); progress.IsActive = false; // mySlider.Value = 13; CabsAPI api = new CabsAPI(); GeoResponse sResponse = await api.GeoCodingResult(Token, mSource); GeoResponse dResponse = await api.GeoCodingResult(Token, mDestination); if (sResponse.Code == ResponseCode.SUCCESS) { if (dResponse.Code == ResponseCode.SUCCESS) { AddMapIcon(Convert.ToDouble(sResponse.Position.Latitude), Convert.ToDouble(sResponse.Position.Longitude), mSource); AddMapIcon(Convert.ToDouble(dResponse.Position.Latitude), Convert.ToDouble(dResponse.Position.Longitude), mDestination); MapPolyline polyline = new MapPolyline(); var coordinates = new List <BasicGeoposition>(); var routeClient = new RouteClient(); coordinates = await routeClient.route(mSource, mDestination); polyline.StrokeColor = Windows.UI.Color.FromArgb(128, 255, 0, 0); polyline.StrokeThickness = 5; polyline.Path = new Geopath(coordinates); MyMap.MapElements.Add(polyline); SrcBox.Text = mSource; DestBox.Text = mDestination; PriceEstimateResponse pResponse = await api.GetEstimate(Token, sResponse.Position.Latitude, sResponse.Position.Longitude, dResponse.Position.Latitude, dResponse.Position.Longitude); if (pResponse.Code == ResponseCode.SUCCESS) { CabsListView.ItemsSource = pResponse.Estimates; ReadSpeech(new MediaElement(), "Showing Estimated cab fare from" + mSource + "to" + mDestination); } else { await new MessageDialog("Error in estimating cabs").ShowAsync(); return; } } else { await new MessageDialog("Destination not found").ShowAsync(); return; } } else { await new MessageDialog("Source not found").ShowAsync(); return; } } }
protected override async void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); if (!isOnline()) { mErrorDialog.Show(); } else { CabsAPI api = new CabsAPI(); SetContentView(Resource.Layout.activity_confirmed_booking); Drawable upArrow = Resources.GetDrawable(Resource.Drawable.abc_ic_ab_back_mtrl_am_alpha); upArrow.SetColorFilter(Resources.GetColor(Resource.Color.white), PorterDuff.Mode.SrcAtop); sourcestring = Intent.GetStringExtra("mSource"); deststring = Intent.GetStringExtra("mDestination"); mSharedPreferences = GetSharedPreferences(Constants.MY_PREF, 0); SupportActionBar.SetHomeAsUpIndicator(upArrow); SupportActionBar.SetDisplayHomeAsUpEnabled(true); token = mSharedPreferences.GetString("token", " "); mLoadingDialog = new LoadingDialog(this, Resource.Drawable.main); mLoadingDialog.SetCancelable(false); Window window = mLoadingDialog.Window; window.SetLayout(WindowManagerLayoutParams.MatchParent, WindowManagerLayoutParams.MatchParent); window.SetBackgroundDrawable(new ColorDrawable(Resources.GetColor(Resource.Color.trans))); SpannableString s = new SpannableString("Successfully Booked"); typeface = Typeface.CreateFromAsset(this.Assets, "JosefinSans-SemiBold.ttf"); s.SetSpan(new TypefaceSpan("Amaranth-Regular.ttf"), 0, s.Length(), SpanTypes.ExclusiveExclusive); s.SetSpan(new ForegroundColorSpan(this.Resources.GetColor(Resource.Color.title)), 0, s.Length(), SpanTypes.ExclusiveExclusive); this.TitleFormatted = s; mSource = FindViewById <TextView>(Resource.Id.sourcetext); mDest = FindViewById <TextView>(Resource.Id.destinationtext); eta = FindViewById <TextView>(Resource.Id.eta); dist = FindViewById <TextView>(Resource.Id.dist); price = FindViewById <TextView>(Resource.Id.price); etatext = FindViewById <TextView>(Resource.Id.etavalue); disttext = FindViewById <TextView>(Resource.Id.distvalue); pricetext = FindViewById <TextView>(Resource.Id.pricevalue); drivertext = FindViewById <TextView>(Resource.Id.drivername); cartype = FindViewById <TextView>(Resource.Id.cartype); carnumber = FindViewById <TextView>(Resource.Id.carnumber); mProvider = FindViewById <ImageView>(Resource.Id.cabprovider); mDriver = FindViewById <ImageView>(Resource.Id.driverimage); mPhone = FindViewById <ImageView>(Resource.Id.phoneimage); mPhone.SetOnClickListener(this); mSource.SetTypeface(typeface, TypefaceStyle.Normal); mDest.SetTypeface(typeface, TypefaceStyle.Normal); eta.SetTypeface(typeface, TypefaceStyle.Normal); etatext.SetTypeface(typeface, TypefaceStyle.Normal); price.SetTypeface(typeface, TypefaceStyle.Normal); pricetext.SetTypeface(typeface, TypefaceStyle.Normal); dist.SetTypeface(typeface, TypefaceStyle.Normal); disttext.SetTypeface(typeface, TypefaceStyle.Normal); drivertext.SetTypeface(typeface, TypefaceStyle.Normal); cartype.SetTypeface(typeface, TypefaceStyle.Normal); carnumber.SetTypeface(typeface, TypefaceStyle.Normal); mSource.Text = sourcestring.ToUpperInvariant(); mDest.Text = deststring.ToUpperInvariant(); mLoadingDialog.Show(); GeoResponse mResponse1 = await api.GeoCodingResult(token, sourcestring); GeoResponse mResponse2 = await api.GeoCodingResult(token, deststring); if (mResponse1.Code == ResponseCode.SUCCESS && mResponse2.Code == ResponseCode.SUCCESS) { slat = mResponse1.Position.Latitude.ToString(); slng = mResponse1.Position.Longitude.ToString(); dlat = mResponse2.Position.Latitude.ToString(); dlng = mResponse2.Position.Longitude.ToString(); PriceEstimateResponse mCabsResponse = await api.GetEstimate(token, slat, slng, dlat, dlng); if (mCabsResponse.Code == ResponseCode.SUCCESS) { BookingDetailsResponse mResBooking = await api.BookCab(token, slat, slng); if (mResBooking.Code == ResponseCode.SUCCESS) { mLoadingDialog.Dismiss(); mCabs = mCabsResponse.Estimates; etatext.Text = mCabs[0].Eta; disttext.Text = mCabs[0].CurrentEstimate.Distance; pricetext.Text = mCabs[0].CurrentEstimate.LowRange + "-" + mCabs[0].CurrentEstimate.HighRange; error = "Successfully booked " + mCabs[0].Type; speakUp(); if (mCabs[0].Provider.Equals("uber", StringComparison.InvariantCultureIgnoreCase)) { mProvider.SetImageResource(Resource.Drawable.uber); } else { mProvider.SetImageResource(Resource.Drawable.ola); } if (mCabs[0].Provider.Equals("Uber", StringComparison.InvariantCultureIgnoreCase)) { drivertext.Text = mResBooking.BookingData.DriverDetails.Name; cartype.Text = mResBooking.BookingData.VehicleDetails.Make + " " + mResBooking.BookingData.VehicleDetails.Model; carnumber.Text = mResBooking.BookingData.VehicleDetails.License_Plate; ImageLoader.Instance.DisplayImage(mResBooking.BookingData.DriverDetails.Picture_Url, mDriver); phonenumber = mResBooking.BookingData.DriverDetails.Phone_Number; } else { phonenumber = "8110020055"; } } else { } } else { mLoadingDialog.Dismiss(); Toast.MakeText(Application.Context, "Error", ToastLength.Short).Show(); return; } sourcepos = new LatLng(Convert.ToDouble(slat), Convert.ToDouble(slng)); destpos = new LatLng(Convert.ToDouble(dlat), Convert.ToDouble(dlng)); setupGoogleMap(); } else { mLoadingDialog.Dismiss(); Toast.MakeText(Application.Context, "Wrong Address", ToastLength.Short).Show(); return; } } }
private async Task <Arguments> ToCustomLocation(VoiceCommandActivatedEventArgs voiceCommandArgs) { string slat, dlat, slng, dlng, desiredLocation, token; GeoResponse locationResponse; CabsAPI api = new CabsAPI(); var localSettings = Windows.Storage.ApplicationData.Current.LocalSettings; token = localSettings.Values["Token"].ToString(); IReadOnlyList <string> voiceCommandPhrases; if (voiceCommandArgs.Result.SemanticInterpretation.Properties.TryGetValue("location", out voiceCommandPhrases)) { desiredLocation = voiceCommandPhrases.First(); } else { desiredLocation = ""; } Geolocator locator = new Geolocator(); locator.DesiredAccuracyInMeters = 50; var position = await locator.GetGeopositionAsync(); slat = position.Coordinate.Point.Position.Latitude.ToString(); slng = position.Coordinate.Point.Position.Longitude.ToString(); string source; ReverseGeoResposne current = await api.GetReverseCodingResultlatlng(token, position.Coordinate.Point.Position.Latitude.ToString() + "," + position.Coordinate.Point.Position.Longitude.ToString()); try { source = current.FormattedAddress.Substring(0, current.FormattedAddress.IndexOf(", Hyderabad")); } catch { source = current.FormattedAddress; } ReadSpeech(new MediaElement(), source); ReadSpeech(new MediaElement(), desiredLocation); locationResponse = await api.GeoCodingResult(token, desiredLocation); if (locationResponse.Code == ResponseCode.SUCCESS) { dlat = locationResponse.Position.Latitude; dlng = locationResponse.Position.Longitude; PriceEstimateResponse mResponseprice = await api.GetEstimate(token, slat, slng, dlat, dlng); if (mResponseprice.Code == ResponseCode.SUCCESS) { List <CabEstimate> desiredList = mResponseprice.Estimates; var sortedCabs = desiredList.OrderBy(o => o.CurrentEstimate.HighRange); Dictionary <string, object> Parameters = new Dictionary <string, object>(); Parameters.Add("location", desiredLocation); Parameters.Add("source", source); Parameters.Add("list", desiredList); Arguments data = new Arguments(null); data.AddType(VoiceCommandType.IF_FROM_APP, true); data.AddType(VoiceCommandType.BOOK_TO_CUSTOM_LOCATION, true); data.Values = Parameters; return(data); } else { await new MessageDialog("Errors fetching estimates").ShowAsync(); return(null); } } else { await new MessageDialog("Errors fetching cordinates").ShowAsync(); return(null); } }
private async Task <Arguments> ProcessBookCheapest(VoiceCommandActivatedEventArgs voiceCommandArgs) { string slat, dlat, slng, dlng, mSource, mDestination, token; GeoResponse mResponse; CabsAPI api = new CabsAPI(); var localSettings = Windows.Storage.ApplicationData.Current.LocalSettings; token = localSettings.Values["Token"].ToString(); IReadOnlyList <string> voiceCommandPhrases; if (voiceCommandArgs.Result.SemanticInterpretation.Properties.TryGetValue("source", out voiceCommandPhrases)) { mSource = voiceCommandPhrases.First(); } else { mSource = ""; } if (voiceCommandArgs.Result.SemanticInterpretation.Properties.TryGetValue("destination", out voiceCommandPhrases)) { mDestination = voiceCommandPhrases.First(); } else { mDestination = ""; } if (mSource == "") { Geolocator locator = new Geolocator(); locator.DesiredAccuracyInMeters = 50; var position = await locator.GetGeopositionAsync(); slat = position.Coordinate.Point.Position.Latitude.ToString(); slng = position.Coordinate.Point.Position.Longitude.ToString(); ReverseGeoResposne mRevResponse = await api.GetReverseCodingResultlatlng(token, position.Coordinate.Point.Position.Latitude.ToString() + "," + position.Coordinate.Point.Position.Longitude.ToString()); //mSource = mRevResponse.FormattedAddress; try { mSource = mRevResponse.FormattedAddress.Substring(0, mRevResponse.FormattedAddress.IndexOf(", Hyderabad")); } catch { mSource = mRevResponse.FormattedAddress; } System.Diagnostics.Debug.WriteLine("source is" + mSource); } else { mResponse = await api.GeoCodingResult(token, mSource); if (mResponse.Code == ResponseCode.SUCCESS) { slat = mResponse.Position.Latitude; slng = mResponse.Position.Longitude; } else { await new MessageDialog("Errors fetching source cordinates").ShowAsync(); return(null); } } if (mDestination == "") { await new MessageDialog("No Destination provided").ShowAsync(); return(null); } else { mResponse = await api.GeoCodingResult(token, mDestination); if (mResponse.Code == ResponseCode.SUCCESS) { dlat = mResponse.Position.Latitude; dlng = mResponse.Position.Longitude; PriceEstimateResponse mResponseprice = await api.GetEstimate(token, slat, slng, dlat, dlng); if (mResponseprice.Code == ResponseCode.SUCCESS) { List <CabEstimate> mList = mResponseprice.Estimates; //var sortedCabs = mList.OrderBy(o => o.AverageEstimate); Dictionary <string, object> Parameters = new Dictionary <string, object>(); Parameters.Add("source", mSource); Parameters.Add("destination", mDestination); Parameters.Add("list", mList); Arguments data = new Arguments(null); data.AddType(VoiceCommandType.IF_FROM_APP, true); data.AddType(VoiceCommandType.BOOK_CHEAPEST_TO_DEST, true); data.AddType(VoiceCommandType.BOOK_ME_CHEAPEST_CAB_FROM_X_TO_Y, true); data.Values = Parameters; return(data); } else { await new MessageDialog("Error fetching estimaates").ShowAsync(); return(null); } } else { await new MessageDialog("Error retrieving Destination cordinates").ShowAsync(); return(null); } } }
protected async override void OnNavigatedTo(NavigationEventArgs e) { base.OnNavigatedTo(e); if (!IsInternet()) { await new MessageDialog("Seems you are not connected to the Internet").ShowAsync(); return; } else { progress.IsActive = true; MyMap.MapServiceToken = "YP9WTSzOHUo0dbahsH8J~J-K6u01dT98SF4uCCKpiwA~AnGaYM6yJxoLF1tGHEIXHFskGfwSRJTr1S5aO1dB-TCXjQ1ZX0xEWgeYslbC3Fov"; Geolocator locator = new Geolocator(); locator.DesiredAccuracyInMeters = 50; var position = await locator.GetGeopositionAsync(); await MyMap.TrySetViewAsync(position.Coordinate.Point, 17D); progress.IsActive = false; mySlider.Value = 13; Arguments args = e.Parameter as Arguments; Dictionary <string, object> Parameters = args.Values; if (args.GetType(VoiceCommandType.NO_VOICE)) { mSource = Parameters["source"].ToString(); mDestination = Parameters["destination"].ToString(); CabsAPI api = new CabsAPI(); GeoResponse sResponse = await api.GeoCodingResult(Token, mSource); GeoResponse dResponse = await api.GeoCodingResult(Token, mDestination); if (sResponse.Code == ResponseCode.SUCCESS && dResponse.Code == ResponseCode.SUCCESS) { AddMapIcon(Convert.ToDouble(sResponse.Position.Latitude), Convert.ToDouble(sResponse.Position.Longitude), mSource); AddMapIcon(Convert.ToDouble(dResponse.Position.Latitude), Convert.ToDouble(dResponse.Position.Longitude), mDestination); } else { await new MessageDialog("Error retrieving Geopositions!").ShowAsync(); return; } MapPolyline polyline = new MapPolyline(); var coordinates = new List <BasicGeoposition>(); var routeClient = new RouteClient(); coordinates = await routeClient.route(mSource, mDestination); polyline.StrokeColor = Windows.UI.Color.FromArgb(128, 255, 0, 0); polyline.StrokeThickness = 5; polyline.Path = new Geopath(coordinates); MyMap.MapElements.Add(polyline); SrcBox.Text = mSource; DestBox.Text = mDestination; PriceEstimateResponse pResponse = await api.GetEstimate(Token, Parameters["slat"].ToString(), Parameters["slng"].ToString(), Parameters["dlat"].ToString(), Parameters["dlng"].ToString()); if (pResponse.Code == ResponseCode.SUCCESS) { CabsListView.ItemsSource = pResponse.Estimates; // ReadSpeech(new MediaElement(), "Showing Estimated cab fare from" + mSource + "to" + mDestination); } } } }
protected async override void OnNavigatedTo(NavigationEventArgs e) { base.OnNavigatedTo(e); ShowLoader(true); { if (!IsInternet()) { await new MessageDialog("Seems you are not connected to the Internet").ShowAsync(); return; } else { MyMap.MapServiceToken = "YP9WTSzOHUo0dbahsH8J~J-K6u01dT98SF4uCCKpiwA~AnGaYM6yJxoLF1tGHEIXHFskGfwSRJTr1S5aO1dB-TCXjQ1ZX0xEWgeYslbC3Fov"; Geolocator locator = new Geolocator(); locator.DesiredAccuracyInMeters = 50; var position = await locator.GetGeopositionAsync(); await MyMap.TrySetViewAsync(position.Coordinate.Point, 10D); //mySlider.Value = 13; Arguments args = e.Parameter as Arguments; if (args.GetType(VoiceCommandType.BOOK_CHEAPEST_TO_DEST)) { string source = args.Values["source"].ToString(); string destination = args.Values["destination"].ToString(); CabsAPI api = new CabsAPI(); string token = Windows.Storage.ApplicationData.Current.LocalSettings.Values["Token"].ToString(); GeoResponse sResponse = await api.GeoCodingResult(token, source.ToLower()); GeoResponse dResponse = await api.GeoCodingResult(token, destination.ToLower()); if (dResponse.Code == ResponseCode.SUCCESS) { if (sResponse.Code == ResponseCode.SUCCESS) { Addroute(sResponse, dResponse, source, destination); Dictionary <string, object> Parameters = args.Values; List <CabEstimate> mCabs = new List <CabEstimate>(); mCabs = Parameters["list"] as List <CabEstimate>; ETAData.Text = mCabs[0].Eta; PriceData.Text = mCabs[0].CurrentEstimate.LowRange + "-" + mCabs[0].CurrentEstimate.HighRange; DistanceData.Text = mCabs[0].CurrentEstimate.Distance; TimeData.Text = mCabs[0].CurrentEstimate.Time; if (Parameters["source"] != null) { if (Parameters["source"].ToString() == null) { SrcBox.Text = "Microsoft Building 1 ".ToUpperInvariant(); } else { SrcBox.Text = Parameters["source"].ToString().ToUpperInvariant(); } } if (Parameters["destination"] != null) { DestBox.Text = Parameters["destination"].ToString().ToUpperInvariant(); } } else { await new MessageDialog("Error retrieving Geoposition").ShowAsync(); return; } } else { await new MessageDialog("Destiantion not found.").ShowAsync(); return; } } else if (args.GetType(VoiceCommandType.NO_VOICE)) { Dictionary <string, object> Parameters = args.Values; string source = Parameters["source"].ToString(); string destination = Parameters["destination"].ToString(); CabsAPI apiCus = new CabsAPI(); string tokenCus = Windows.Storage.ApplicationData.Current.LocalSettings.Values["Token"].ToString(); GeoResponse sResponse = await apiCus.GeoCodingResult(tokenCus, source.ToLower()); GeoResponse dResponse = await apiCus.GeoCodingResult(tokenCus, destination.ToLower()); Addroute(sResponse, dResponse, source, destination); ETAData.Text = Parameters["eta"].ToString(); PriceData.Text = Parameters["price"].ToString(); DistanceData.Text = Parameters["distance"].ToString(); TimeData.Text = Parameters["time"].ToString(); SrcBox.Text = Parameters["source"].ToString().ToUpperInvariant(); DestBox.Text = Parameters["destination"].ToString().ToUpperInvariant(); } else if (args.GetType(VoiceCommandType.BOOK_TO_CUSTOM_LOCATION)) { string source = args.Values["source"].ToString(); string destination = args.Values["location"].ToString(); CabsAPI apiCus = new CabsAPI(); string tokenCus = Windows.Storage.ApplicationData.Current.LocalSettings.Values["Token"].ToString(); GeoResponse sResponse = await apiCus.GeoCodingResult(tokenCus, source.ToLower()); GeoResponse dResponse = await apiCus.GeoCodingResult(tokenCus, destination.ToLower()); if (sResponse.Code == ResponseCode.SUCCESS) { if (dResponse.Code == ResponseCode.SUCCESS) { Addroute(sResponse, dResponse, source, destination); Dictionary <string, object> Parameters = args.Values; List <CabEstimate> DesiredCabs = new List <CabEstimate>(); DesiredCabs = Parameters["list"] as List <CabEstimate>; ETAData.Text = DesiredCabs[0].Eta; PriceData.Text = DesiredCabs[0].CurrentEstimate.LowRange + "-" + DesiredCabs[0].CurrentEstimate.HighRange; DistanceData.Text = DesiredCabs[0].CurrentEstimate.Distance; TimeData.Text = DesiredCabs[0].CurrentEstimate.Time; SrcBox.Text = "Microsoft Building 1 Gachibowli Hyderabad".ToUpperInvariant(); if (Parameters["location"] != null) { DestBox.Text = Parameters["location"].ToString().ToUpperInvariant(); } } else { await new MessageDialog("Destination not found.").ShowAsync(); return; } } else { await new MessageDialog("Error retrieving Geoposition").ShowAsync(); return; } } else if (args.GetType(VoiceCommandType.BOOK_ME_A_CAB_FROM_X_TO_Y)) { string source = args.Values["source"].ToString(); string destination = args.Values["destination"].ToString(); CabsAPI api = new CabsAPI(); string token = Windows.Storage.ApplicationData.Current.LocalSettings.Values["Token"].ToString(); PlacesResponse sResponse = await api.GetPlaceLocation(source.ToLower(), token); PlacesResponse dResponse = await api.GetPlaceLocation(destination.ToLower(), token); if (sResponse.Code == ResponseCode.SUCCESS) { if (dResponse.Code == ResponseCode.SUCCESS) { Addroute(sResponse, dResponse, source, destination); //AddMapIcon(Convert.ToDouble(sResponse.Location.Latitude), Convert.ToDouble(sResponse.Location.Longitude), source); //AddMapIcon(Convert.ToDouble(dResponse.Location.Latitude), Convert.ToDouble(dResponse.Location.Longitude), destination); //MapPolyline polyline = new MapPolyline(); //var coordinates = new List<BasicGeoposition>(); //var routeClient = new RouteClient(); //string sourceLoc = sResponse.Location.Latitude + "," + sResponse.Location.Longitude; //string destinationLoc = dResponse.Location.Latitude + "," + dResponse.Location.Longitude; //coordinates = await routeClient.route(sourceLoc, destinationLoc); //polyline.StrokeColor = Windows.UI.Color.FromArgb(128, 255, 0, 0); //polyline.StrokeThickness = 5; //polyline.Path = new Geopath(coordinates); //MyMap.MapElements.Add(polyline); //ReadSpeech(new MediaElement(), sResponse.Location.Latitude + " ok " + dResponse.Location.Longitude); PriceEstimateResponse pRespone = await api.GetEstimate(token, sResponse.Location.Latitude, sResponse.Location.Longitude, dResponse.Location.Latitude, dResponse.Location.Longitude); //ReadSpeech(new MediaElement(), pRespone.Estimates.First().Provider); SrcBox.Text = source; DestBox.Text = destination; //AddMapIcon(sResponse.Location.Latitude,) if (pRespone.Code == ResponseCode.SUCCESS) { ETAData.Text = pRespone.Estimates[1].Eta; PriceData.Text = pRespone.Estimates[1].CurrentEstimate.LowRange + "-" + pRespone.Estimates[1].CurrentEstimate.HighRange; DistanceData.Text = pRespone.Estimates[1].CurrentEstimate.Distance; TimeData.Text = pRespone.Estimates[1].CurrentEstimate.Time; } else { await new MessageDialog("Error in estimating prices").ShowAsync(); return; } } else { await new MessageDialog("Destination not found").ShowAsync(); return; } } else { await new MessageDialog("Error retrieving Geoposition").ShowAsync(); return; } } else if (args.GetType(VoiceCommandType.ESTIMATE_FROM)) { string source = args.Values["source"].ToString(); string destination = args.Values["destination"].ToString(); CabsAPI apiCus = new CabsAPI(); string token = Windows.Storage.ApplicationData.Current.LocalSettings.Values["Token"].ToString(); GeoResponse sResponse = await apiCus.GeoCodingResult(token, source.ToLower()); GeoResponse dResponse = await apiCus.GeoCodingResult(token, destination.ToLower()); Addroute(sResponse, dResponse, source, destination); Arguments eArgs = args as Arguments; SrcBox.Text = source; DestBox.Text = destination; ETAData.Text = eArgs.Values["eta"].ToString(); PriceData.Text = eArgs.Values["low"].ToString() + "-" + eArgs.Values["high"].ToString(); DistanceData.Text = eArgs.Values["distance"].ToString(); TimeData.Text = eArgs.Values["time"].ToString(); } } } ShowLoader(false); }