protected override async void OnActivityResult(int requestCode, [GeneratedEnum] Result resultCode, Intent data)
        {
            base.OnActivityResult(requestCode, resultCode, data);
            switch (requestCode)
            {
            case 100:

                if (resultCode == Result.Ok && data != null)
                {
                    Intent         mIntent = new Intent(this, typeof(ConfirmedCookingActivityViaSpeech));
                    IList <string> mResult = data.GetStringArrayListExtra(RecognizerIntent.ExtraResults);
                    System.Diagnostics.Debug.WriteLine(mResult[0]);
                    string           command     = mResult[0];
                    Classifier       mClassifier = new Classifier(command);
                    ClassifiedResult mResp       = mClassifier.Classify();
                    switch (mResp.Type)
                    {
                    case VoiceCommandType.BOOK_ME_CHEAPEST_CAB_FROM_X_TO_Y:
                        string recs = mResp.GetData("source");
                        if (!recs.Equals(""))
                        {
                            mSourceAddress = recs;
                        }
                        mDestinationAddress = mResp.GetData("destination");
                        error = "Booking Cheapest cab from " + mSourceAddress + "to" + mDestinationAddress;
                        speakUp();
                        mIntent.PutExtra("mSource", mSourceAddress);
                        mIntent.PutExtra("mDestination", mDestinationAddress);
                        StartActivity(mIntent);
                        break;

                    case VoiceCommandType.BOOK_TO_CUSTOM_LOCATION:
                        mDestinationAddress = mResp.GetData("location");
                        mIntent.PutExtra("mSource", mSourceAddress);
                        mIntent.PutExtra("mDestinationAddress", mDestinationAddress);
                        StartActivity(mIntent);
                        break;


                    case VoiceCommandType.BOOK_ME_A_CAB_FROM_X_TO_Y:
                    {
                        CabsAPI api         = new CabsAPI();
                        string  source      = mResp.GetData("source");
                        string  destination = mResp.GetData("destination");
                        mLoadingDialog.Show();
                        PlacesResponse mResposneSource = await api.GetPlaceLocation(source, token);

                        PlacesResponse mResponseDest = await api.GetPlaceLocation(destination, token);

                        if (mResposneSource.Code == ResponseCode.SUCCESS && mResponseDest.Code == ResponseCode.SUCCESS)
                        {
                            string             msource = mResposneSource.Location.Latitude + "," + mResposneSource.Location.Longitude;
                            string             mDest   = mResponseDest.Location.Latitude + "," + mResponseDest.Location.Longitude;
                            ReverseGeoResposne mResSrc = await api.GetReverseCodingResultlatlng(token, msource);

                            ReverseGeoResposne mResDest = await api.GetReverseCodingResultlatlng(token, mDest);

                            if (mResSrc.Code == ResponseCode.SUCCESS && mResDest.Code == ResponseCode.SUCCESS)
                            {
                                error = "Booking cab from " + source + "to" + destination;
                                speakUp();
                                mLoadingDialog.Dismiss();
                                mSourceAddress      = mResSrc.FormattedAddress;
                                mDestinationAddress = mResDest.FormattedAddress;
                                mIntent.PutExtra("mSource", mSourceAddress);
                                mIntent.PutExtra("mDestination", mDestinationAddress);
                                StartActivity(mIntent);
                            }
                            else
                            {
                                error = "Google maps error";
                                speakUp();
                                return;
                            }
                        }
                        else
                        {
                            error = "These places are not there in your notebook";
                            speakUp();
                            return;
                        }
                        break;
                    }

                    case VoiceCommandType.INVALID_COMMAND:
                        error = "Invalid Commmand Please try again";
                        speakUp();
                        break;
                    }
                }

                break;
            }
        }
예제 #2
0
        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);
                    }
                }
            }
        }
예제 #3
0
        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);
        }