public async void OTP_Click(object sender, RoutedEventArgs e)
        {
            if (!IsInternet())
            {
                await new MessageDialog("Seems you are not connected to the Internet").ShowAsync();
                return;
            }
            else
            {
                progress.IsActive = true;
                CabsAPI     api         = new CabsAPI();
                OtpResponse otpResponse = await api.GetOTP(_mobile);

                if (otpResponse.Code == ResponseCode.SUCCESS)
                {
                    progress.IsActive = false;
                    otpGot            = otpResponse.Otp;
                }
                else
                {
                    await new MessageDialog("Server error!").ShowAsync();
                    return;
                }
            }
        }
        private async void Forgot_Click(object sender, EventArgs e)
        {
            if (mobile.Text.Equals("") || mobile.Text.Length != 10)
            {
                Toast.MakeText(ApplicationContext, "Please enter a 10 digit mobile number", ToastLength.Short).Show();
                return;
            }
            else
            {
                mLoadingDialog.Show();
                CabsAPI     api      = new CabsAPI();
                OtpResponse response = await api.GetOTP(mobile.Text);

                if (response.Code == ResponseCode.SUCCESS)
                {
                    mLoadingDialog.Dismiss();
                    otpRecieved = response.Otp;
                    showOtpDialog();
                }
                else
                {
                }
            }
            //    FragmentTransaction tra = FragmentManager.BeginTransaction();
            //    ForgotPasswordFragment dia = new ForgotPasswordFragment();
            //    dia.Show(tra, "dialog");
            //    dia.marg += Dia_marg;
        }
 public CabsListViewModel(string startLng, string startLat, string token)
 {
     _startLng = startLng;
     _startLat = startLat;
     _token    = token;
     _cabsApi  = new CabsAPI();
 }
        public async void OnClick(View v)
        {
            InputMethodManager inputManager = (InputMethodManager)GetSystemService(InputMethodService);

            inputManager.HideSoftInputFromWindow(CurrentFocus.WindowToken, 0);
            if (newPassword.Text.Length < 6 || confirmNewPassword.Text.Length < 6)
            {
                Toast.MakeText(ApplicationContext, "The password should be atleast 6 digits in length", ToastLength.Short).Show();
                return;
            }
            else
            {
                if (valid())
                {
                    mProgressbar.Visibility = ViewStates.Visible;
                    string      mobile   = Intent.GetStringExtra("mobile");
                    string      password = newPassword.Text;
                    CabsAPI     api      = new CabsAPI();
                    OtpResponse response = await api.ResetPassword(mobile, password);

                    if (response.Code == ResponseCode.SUCCESS)
                    {
                        mProgressbar.Visibility = ViewStates.Gone;
                        Toast.MakeText(ApplicationContext, "Password Reset Successful", ToastLength.Short).Show();
                        StartActivity(new Intent(this, typeof(SignInActivity)));
                        Finish();
                    }
                    else
                    {
                        Toast.MakeText(ApplicationContext, "Server Error!", ToastLength.Short).Show();
                        return;
                    }
                }
            }
        }
Exemple #5
0
        private async void SearchDestinationBox_TextChanged(AutoSuggestBox sender, AutoSuggestBoxTextChangedEventArgs args)
        {
            if (!IsInternet())
            {
                await new MessageDialog("Seems you are not connected to the Internet").ShowAsync();
                return;
            }
            else
            {
                if (args.Reason == AutoSuggestionBoxTextChangeReason.UserInput)
                {
                    DestinationSuggestions.Clear();
                    CabsAPI        api            = new CabsAPI();
                    SearchResponse searchResponse = await api.GetSuggestions(sender.Text, Token);

                    if (searchResponse.Code == ResponseCode.SUCCESS)
                    {
                        List <String> suggestions = searchResponse.Suggestions.Select(su => su.Text).ToList();
                        if (suggestions.Count == 0)
                        {
                            SearchDestinationBox.ItemsSource = new string[] { "No Results" };
                        }
                        else
                        {
                            DestinationSuggestions           = new ObservableCollection <string>(suggestions);
                            SearchDestinationBox.ItemsSource = suggestions;
                        }
                    }
                    else
                    {
                        SearchDestinationBox.ItemsSource = new string[] { "Auto complete not available" };
                    }
                }
            }
        }
Exemple #6
0
        private async void SearchDestinationBox_SuggestionChosen(AutoSuggestBox sender, AutoSuggestBoxSuggestionChosenEventArgs args)
        {
            if (!IsInternet())
            {
                await new MessageDialog("Seems you are not connected to the Internet").ShowAsync();
                return;
            }
            else
            {
                _destination = args.SelectedItem.ToString();
                CabsAPI     api = new CabsAPI();
                GeoResponse location;
                var         localSettings = Windows.Storage.ApplicationData.Current.LocalSettings;
                token    = localSettings.Values["Token"].ToString();
                location = await api.GeoCodingResult(token, args.SelectedItem.ToString());

                if (location.Code == ResponseCode.SUCCESS)
                {
                    dlat = location.Position.Latitude;
                    dlng = location.Position.Longitude;
                    AddMapIcon(double.Parse(dlat), double.Parse(dlng));
                    _cabsView.SetLatLng(dlat, dlng);
                    ShowLoader(true);
                    await _cabsView.RefreshView(CabsListViewModel.REFRESH_ESTIMATE);

                    CabsListView.ItemsSource = _cabsView.Cabs;
                    ShowLoader(false);
                }
                else
                {
                    await new MessageDialog("Error retrieving Geoposition").ShowAsync();
                    return;
                }
            }
        }
 public ProviderWebViewClient(WebViewAccountsActivity webViewAccountsActivity, string token)
 {
     this.webViewAccountsActivity = webViewAccountsActivity;
     this.token       = token;
     mSharePreference = webViewAccountsActivity.GetSharedPreferences(Constants.MY_PREF, 0);
     mEditor          = mSharePreference.Edit();
     mCabsApi         = new CabsAPI();
 }
Exemple #8
0
        private async void Button_Click_1(object sender, RoutedEventArgs e)
        {
            if (!IsInternet())
            {
                await new MessageDialog("Seems you are not connected to the Internet").ShowAsync();
                return;
            }
            else
            {
                string passtext, cnfpasstext;
                passtext    = New.Password;
                cnfpasstext = ConfirmNew.Password;
                if (!checkEmpty(passtext, "New Password"))
                {
                    await new MessageDialog("New password field cannot be empty").ShowAsync();
                    return;
                }
                else if (!checkEmpty(cnfpasstext, "Phone number"))
                {
                    await new MessageDialog("Confirm password field cannot be empty").ShowAsync();
                    return;
                }
                else if (!checkPassValidity(passtext, cnfpasstext))
                {
                    await new MessageDialog("Passwords do not match").ShowAsync();
                    return;
                }
                else if (!isPassValid(passtext))
                {
                    await new MessageDialog("Password must be of atleast 6 digits").ShowAsync();
                    return;
                }
                else
                {
                    progress.IsActive = true;
                    CabsAPI     api      = new CabsAPI();
                    OtpResponse response = await api.ResetPassword(mobilenew, ConfirmNew.Password);

                    if (response.Code == ResponseCode.SUCCESS)
                    {
                        progress.IsActive = false;
                        await new MessageDialog("Password changed successfully").ShowAsync();
                        Frame.Navigate(typeof(CabsPage));
                    }
                    else
                    {
                        progress.IsActive = false;
                        await new MessageDialog("Unable to update. Try again later").ShowAsync();
                    }
                }
            }
        }
        private async void Button_Click_1(object sender, RoutedEventArgs e)
        {
            if (!IsInternet())
            {
                await new MessageDialog("Seems you are not connected to the Internet").ShowAsync();
                return;
            }
            else
            {
                if (UsernameBx.Text.Equals("") || PasswordBx.Password.Equals(""))
                {
                    await new MessageDialog("Please fill all the fields").ShowAsync();
                }
                else
                {
                    progress.IsActive = true;
                    CabsAPI        api             = new CabsAPI();
                    SignInResponse mSignInResponse = await api.LoginUser(UsernameBx.Text, PasswordBx.Password);

                    if (mSignInResponse.Code == ResponseCode.SUCCESS)
                    {
                        // save the session data
                        progress.IsActive = false;
                        var localSettings = Windows.Storage.ApplicationData.Current.LocalSettings;
                        localSettings.Values["LoggedIn"] = true;
                        localSettings.Values["Token"]    = mSignInResponse.Token;
                        localSettings.Values["Email"]    = mSignInResponse.Data.Email;
                        localSettings.Values["Mobile"]   = mSignInResponse.Data.Mobile;
                        localSettings.Values["Name"]     = mSignInResponse.Data.Name;
                        Frame.Navigate(typeof(Navigation.NavigationPage), speechRecognition);
                    }
                    else if (mSignInResponse.Code == ResponseCode.MYSQL_FIELDS_MISMATCH)
                    {
                        progress.IsActive = false;
                        await new MessageDialog("Password is incorrect. Try Again").ShowAsync();
                    }
                    else if (mSignInResponse.Code == ResponseCode.MYSQL_NO_SUCH_VALUE)
                    {
                        progress.IsActive = false;
                        await new MessageDialog("Account not found. Would you like to register?").ShowAsync();
                        Frame.Navigate(typeof(SignUpPage));
                    }
                    else
                    {
                        progress.IsActive = false;
                        await new MessageDialog("Unfortunately, we can not sign you in at this time").ShowAsync();
                    }
                }
            }
        }
Exemple #10
0
        private async void SearchSourceBox_SuggestionChosen(AutoSuggestBox sender, AutoSuggestBoxSuggestionChosenEventArgs args)
        {
            if (!IsInternet())
            {
                await new MessageDialog("Seems you are not connected to the Internet").ShowAsync();
                return;
            }
            else
            {
                _source           = args.SelectedItem.ToString();
                flag              = 1;
                progress.IsActive = true;
                //string dlat, dlng, token;
                var localSettings = Windows.Storage.ApplicationData.Current.LocalSettings;
                token = localSettings.Values["Token"].ToString();
                GeoResponse location;
                CabsAPI     api = new CabsAPI();
                location = await api.GeoCodingResult(token, args.SelectedItem.ToString());

                if (location.Code == ResponseCode.SUCCESS)
                {
                    slat = location.Position.Latitude;
                    slng = location.Position.Longitude;
                    BasicGeoposition curPos = new BasicGeoposition();
                    curPos.Latitude  = double.Parse(slat);
                    curPos.Longitude = double.Parse(slng);
                    await MyMap.TrySetViewAsync(new Geopoint(curPos), 17D);

                    AddMapIcon(double.Parse(slat), double.Parse(slng));
                    CabsResponse response = await api.GetNearbyCabs(slat, slng, Token);

                    if (response.Code == ResponseCode.SUCCESS)
                    {
                        progress.IsActive        = false;
                        CabsListView.ItemsSource = response.Cabs;
                    }
                    else
                    {
                        await new MessageDialog("Error fetching nearby cabs").ShowAsync();
                        return;
                    }
                }
                else
                {
                    await new MessageDialog("Error retrieving Geoposition coordinates").ShowAsync();
                    return;
                }
            }
        }
        private async void Signin_Click(object sender, EventArgs e)
        {
            InputMethodManager inputManager = (InputMethodManager)GetSystemService(InputMethodService);

            inputManager.HideSoftInputFromWindow(CurrentFocus.WindowToken, 0);
            string phonenum = mobile.Text;
            string pass     = password.Text;

            if (pass.Length > 5)
            {
                if (phonenum.Length == 10)
                {
                    mLoadingDialog.Show();
                    CabsAPI        api      = new CabsAPI();
                    SignInResponse response = await api.LoginUser(phonenum, pass);

                    if (response.Code == ResponseCode.SUCCESS)
                    {
                        mLoadingDialog.Dismiss();
                        mEditor.PutString("email", response.Data.Email);
                        mEditor.PutString("mobile", response.Data.Mobile);
                        mEditor.PutString("name", response.Data.Name);
                        mEditor.PutString("token", response.Token);
                        mEditor.PutBoolean("isLoggedIn", true);
                        mEditor.Apply();
                        StartActivity(new Intent(this, typeof(GettingStartedActivity)));
                        Finish();
                    }
                    else
                    {
                        mLoadingDialog.Dismiss();
                        Toast.MakeText(this, "Incorrect Credentials", ToastLength.Short).Show();
                        return;
                    }
                }
                else
                {
                    Toast.MakeText(this, "Phone number must be of 10 digits", ToastLength.Short).Show();
                    return;
                }
            }
            else
            {
                Toast.MakeText(this, "Password must have atleast 6 digits", ToastLength.Short).Show();
                return;
            }
        }
        public async Task <List <string> > GetSuggestions(string input)
        {
            CabsAPI        api            = new CabsAPI();
            string         token          = mContext.GetSharedPreferences(Constants.MY_PREF, 0).GetString("token", " ");
            SearchResponse searchResponse = await api.GetSuggestions(input, token);

            //return new SuggestionCursor(constraint);
            if (searchResponse.Code == ResponseCode.SUCCESS)
            {
                List <string> suggestions = searchResponse.Suggestions.Select(su => su.Text).ToList();
                mSuggestions = suggestions;
                return(suggestions);
            }
            else
            {
                List <string> su = new List <string>();
                mSuggestions = su;
                su.Add("No results");
                return(su);
            }
        }
        async void WebViewControl_ScriptNotify(object sender, NotifyEventArgs e)
        {
            // Be sure to verify the source of the message when performing actions with the data.
            // As webview can be navigated, you need to check that the message is coming from a page/code
            // that you trust.

            string            code     = e.Value;
            string            token    = Windows.Storage.ApplicationData.Current.LocalSettings.Values["Token"].ToString();
            CabsAPI           api      = new CabsAPI();
            SendTokenResponse response = await api.SendToken(token, code);

            if (response.Code == ResponseCode.SUCCESS)
            {
                Frame.BackStack.Clear();
                Frame.Navigate(typeof(Navigation.NavigationPage), "OPEN_PROFILE");
            }
            else
            {
                await new MessageDialog("Cannot Authenticate your account now. Try again later").ShowAsync();
                Frame.BackStack.Clear();
                Frame.Navigate(typeof(Navigation.NavigationPage), "OPEN_PROFILE");
            }
        }
Exemple #14
0
        private async void ConfirmBooking(object sender, RoutedEventArgs e)
        {
            Geolocator locator  = new Geolocator();
            var        position = await locator.GetGeopositionAsync();

            CabsAPI api   = new CabsAPI();
            string  token = Windows.Storage.ApplicationData.Current.LocalSettings.Values["Token"].ToString();
            BookingDetailsResponse booking = await api.BookCab(token, position.Coordinate.Point.Position.Latitude.ToString(), position.Coordinate.Point.Position.Longitude.ToString());

            if (booking.Code == ResponseCode.SUCCESS)
            {
                var drivername    = booking.BookingData.DriverDetails.Name;
                var drivercontact = booking.BookingData.DriverDetails.Phone_Number;
                var driverpic     = booking.BookingData.DriverDetails.Picture_Url;
                var carmake       = booking.BookingData.VehicleDetails.Make;
                var carmodel      = booking.BookingData.VehicleDetails.Model;
                var carnumber     = booking.BookingData.VehicleDetails.License_Plate;
                Dictionary <string, object> Parameters = new Dictionary <string, object>();
                Parameters.Add("time", TimeData.Text);
                Parameters.Add("price", PriceData.Text);
                Parameters.Add("distance", DistanceData.Text);
                Parameters.Add("driverName", drivername);
                Parameters.Add("driverContact", drivercontact);
                Parameters.Add("driverPic", driverpic);
                Parameters.Add("carMake", carmake);
                Parameters.Add("carModel", carmodel);
                Parameters.Add("carNumber", carnumber);
                Parameters.Add("source", SrcBox.Text);
                Parameters.Add("destination", DestBox.Text);
                Frame.Navigate(typeof(Home.CabBookingDetails), Parameters);
            }
            else
            {
                await new MessageDialog("Error retrieving Driver Info").ShowAsync();
                return;
            }
        }
Exemple #15
0
        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);
                    }
                }
            }
        }
Exemple #16
0
        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);
                    }
                }
            }
        }
Exemple #17
0
        public async void Run(IBackgroundTaskInstance taskInstance)
        {
            serviceDeferral = taskInstance.GetDeferral();
            var    userMessage1 = new VoiceCommandUserMessage();
            string book;

            taskInstance.Canceled += OnTaskCanceled;
            var triggerDetails = taskInstance.TriggerDetails as AppServiceTriggerDetails;

            if (triggerDetails != null)
            {
                try
                {
                    voiceServiceConnection = VoiceCommandServiceConnection.FromAppServiceTriggerDetails(triggerDetails);
                    voiceServiceConnection.VoiceCommandCompleted += OnVoiceCommandCompleted;
                    VoiceCommand voiceCommand = await voiceServiceConnection.GetVoiceCommandAsync();

                    switch (voiceCommand.CommandName)
                    {
                    case "bookFromXToY":
                        try
                        {
                            string source      = voiceCommand.SpeechRecognitionResult.SemanticInterpretation.Properties["bookFromX"].FirstOrDefault();
                            string destination = voiceCommand.SpeechRecognitionResult.SemanticInterpretation.Properties["bookFromY"].FirstOrDefault();
                            await SendCompletionMessageForBookFromXtoY(source, destination);
                        }
                        catch
                        {
                            userMessage1 = new VoiceCommandUserMessage();
                            book         = "Please give proper saved places";
                            userMessage1.DisplayMessage = userMessage1.SpokenMessage = book;
                            var response = VoiceCommandResponse.CreateResponse(userMessage1);
                            await voiceServiceConnection.ReportSuccessAsync(response);
                        }
                        break;

                    case "costEstimate":
                        try
                        {
                            string sourceCost      = voiceCommand.SpeechRecognitionResult.SemanticInterpretation.Properties["source"].First();
                            string destinationCost = voiceCommand.SpeechRecognitionResult.SemanticInterpretation.Properties["destination"].First();
                            await SendCompletionMessageForCostEstimate(sourceCost, destinationCost);
                        }
                        catch
                        {
                            userMessage1 = new VoiceCommandUserMessage();
                            book         = "Please give proper source and destination";
                            userMessage1.DisplayMessage = userMessage1.SpokenMessage = book;
                            var response = VoiceCommandResponse.CreateResponse(userMessage1);
                            await voiceServiceConnection.ReportSuccessAsync(response);
                        }
                        break;

                    case "costEstimateCustom":
                        //try
                        //{
                        string     destinationCost1 = voiceCommand.SpeechRecognitionResult.SemanticInterpretation.Properties["destination"].First();
                        string     slat, slng, token;
                        Geolocator locator = new Geolocator();
                        locator.DesiredAccuracyInMeters = 50;
                        var mPosition = await locator.GetGeopositionAsync();

                        slat  = mPosition.Coordinate.Point.Position.Latitude.ToString();
                        slng  = mPosition.Coordinate.Point.Position.Longitude.ToString();
                        token = Windows.Storage.ApplicationData.Current.LocalSettings.Values["Token"].ToString();
                        CabsAPI            api     = new CabsAPI();
                        ReverseGeoResposne current = await api.GetReverseCodingResultlatlng(token, slat + "," + slng);

                        string source1;
                        try
                        {
                            source1 = current.FormattedAddress.Substring(0, current.FormattedAddress.IndexOf(", Hyderabad"));
                        }
                        catch
                        {
                            source1 = current.FormattedAddress;
                        }
                        await SendCompletionMessageForCostEstimate(source1, destinationCost1);


                        //catch (Exception e)
                        //{
                        //    userMessage1 = new VoiceCommandUserMessage();
                        //    book = "please give proper Destination";
                        //    userMessage1.DisplayMessage = userMessage1.SpokenMessage = book;
                        //    var response = VoiceCommandResponse.CreateResponse(userMessage1);
                        //    await voiceServiceConnection.ReportSuccessAsync(response);
                        //}
                        break;

                    case "toCustomLocation":
                        try
                        {
                            string location = voiceCommand.SpeechRecognitionResult.SemanticInterpretation.Properties["location"].FirstOrDefault();
                            await SendCompletionMessageForBookToCustomLocation(location);
                        }
                        catch (Exception e)
                        {
                            userMessage1 = new VoiceCommandUserMessage();
                            book         = "Please give proper Destination";
                            userMessage1.DisplayMessage = userMessage1.SpokenMessage = book;
                            var response = VoiceCommandResponse.CreateResponse(userMessage1);
                            await voiceServiceConnection.ReportSuccessAsync(response);
                        }
                        break;

                    case "bookcheapest":
                        string mSource;
                        IReadOnlyList <string> voicecommandphrase;
                        if (voiceCommand.SpeechRecognitionResult.SemanticInterpretation.Properties.TryGetValue("source", out voicecommandphrase))
                        {
                            mSource = voicecommandphrase.First();
                        }
                        else
                        {
                            mSource = "";
                        }
                        string mDest = voiceCommand.SpeechRecognitionResult.SemanticInterpretation.Properties["destination"].FirstOrDefault();
                        await SendCompletionMessageForBookCheapestFromXtoY(mSource, mDest);

                        break;

                    default:
                        LaunchAppInForeground();
                        break;
                    }
                }
                catch (Exception ex)
                {
                    System.Diagnostics.Debug.WriteLine("Handling Voice Command failed " + ex.ToString());
                }
            }
        }
Exemple #18
0
        private async Task SendCompletionMessageForBookCheapestFromXtoY(string mSource, string mDest)
        {
            string slat, slng, dlat, dlng, token, mDisplay;

            slat = slng = dlng = dlat = null;
            var mUserMessage = new VoiceCommandUserMessage();
            var mUserPrompt = new VoiceCommandUserMessage();
            VoiceCommandResponse    mResponseError, mResponseSuccess, mResponseUserPrompt;
            VoiceCommandContentTile mCabTile = new VoiceCommandContentTile();
            CabsAPI                        mCabsApi = new CabsAPI();
            GeoResponse                    mGeoResp;
            Geolocator                     mLocator;
            ReverseGeoResposne             mRevGeoResp;
            PriceEstimateResponse          mPriceEstResp;
            BookingDetailsResponse         mBookingDetailsResp;
            CabEstimate                    mCabToDisplay;
            List <CabEstimate>             mCabEstimate;
            List <VoiceCommandContentTile> mCabTiles = new List <VoiceCommandContentTile>();

            token = Windows.Storage.ApplicationData.Current.LocalSettings.Values["Token"].ToString();
            if (mDest.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, mDest);

                if (mGeoResp.Code == ResponseCode.SUCCESS)
                {
                    dlat = mGeoResp.Position.Latitude;
                    dlng = mGeoResp.Position.Longitude;
                }
                else
                {
                    mDisplay = "Plese enter proper Destination";
                    mUserMessage.DisplayMessage = mUserMessage.SpokenMessage = mDisplay;
                    mResponseError = VoiceCommandResponse.CreateResponse(mUserMessage);
                    await voiceServiceConnection.ReportFailureAsync(mResponseError);
                }
            }
            if (mSource.Equals(""))
            {
                mLocator = new Geolocator();
                mLocator.DesiredAccuracyInMeters = 50;
                var mPosition = await mLocator.GetGeopositionAsync();

                slat        = mPosition.Coordinate.Point.Position.Latitude.ToString();
                slng        = mPosition.Coordinate.Point.Position.Longitude.ToString();
                mRevGeoResp = await mCabsApi.GetReverseCodingResultlatlng(token, slat + "," + slng);

                if (mRevGeoResp.Code == ResponseCode.SUCCESS)
                {
                    try
                    {
                        mSource = mRevGeoResp.FormattedAddress.Substring(0, mRevGeoResp.FormattedAddress.IndexOf(", Hyderabad"));
                    }
                    catch
                    {
                        mSource = mRevGeoResp.FormattedAddress;
                    }
                }
                else
                {
                    mDisplay = "Source not found with current location";
                    mUserMessage.DisplayMessage = mUserMessage.SpokenMessage = mDisplay;
                    mResponseError = VoiceCommandResponse.CreateResponse(mUserMessage);
                    await voiceServiceConnection.ReportFailureAsync(mResponseError);
                }
            }
            else
            {
                mGeoResp = await mCabsApi.GeoCodingResult(token, mSource);

                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);
                }
            }
            if (slat != "" && slng != "" && dlat != "" && dlng != "")
            {
                mDisplay = "Looking for best cab providers from " + mSource.ToUpperInvariant() + " to " + mDest.ToUpperInvariant();
                await ShowProgressScreen(mDisplay);

                mDisplay = "Booking cheapest cab from " + mSource.ToUpperInvariant() + " to " + mDest.ToUpperInvariant();
                await ShowProgressScreen(mDisplay);

                mPriceEstResp = await mCabsApi.GetEstimate(token, slat, slng, dlat, dlng);

                if (mPriceEstResp.Code == ResponseCode.SUCCESS)
                {
                    mCabEstimate = mPriceEstResp.Estimates;
                    if (mCabEstimate.Count != 0)
                    {
                        string mDisplay1 = "Ok I have found the cheapest cab for you. Shall i book it?";
                        mUserPrompt.DisplayMessage = mUserPrompt.SpokenMessage = mDisplay1;
                        mDisplay = "Shall i book it";
                        mUserMessage.DisplayMessage = mUserMessage.SpokenMessage = mDisplay;
                        mCabTile.ContentTileType    = VoiceCommandContentTileType.TitleWith68x68IconAndText;

                        mCabToDisplay = mCabEstimate[0];
                        if (mCabToDisplay.Provider.Equals("UBER"))
                        {
                            mCabTile.Image = await StorageFile.GetFileFromApplicationUriAsync(new Uri("ms-appx:///ContosoCabs.VoiceCommandService/img/uber.png"));
                        }
                        else
                        {
                            mCabTile.Image = await StorageFile.GetFileFromApplicationUriAsync(new Uri("ms-appx:///ContosoCabs.VoiceCommandService/img/ola.png"));
                        }

                        mCabTile.Title     = mCabToDisplay.Provider;
                        mCabTile.TextLine1 = "Type : " + mCabToDisplay.Type;
                        mCabTile.TextLine2 = "ETA : " + mCabToDisplay.Eta;
                        mCabTile.TextLine3 = "Estimated Fare : " + mCabToDisplay.CurrentEstimate.LowRange + "-" + mCabToDisplay.CurrentEstimate.HighRange;
                        mCabTiles.Add(mCabTile);
                        mResponseUserPrompt = VoiceCommandResponse.CreateResponseForPrompt(mUserPrompt, mUserMessage, mCabTiles);
                        var voiceCommandConfirmation = await voiceServiceConnection.RequestConfirmationAsync(mResponseUserPrompt);

                        if (voiceCommandConfirmation.Confirmed)
                        {
                            mBookingDetailsResp = await mCabsApi.BookCab(token, slat, slng);

                            mDisplay = "Successfully booked." + mCabToDisplay.Type + " Your cab driver " + mBookingDetailsResp.BookingData.DriverDetails.Name + " will be arriving in " + mCabToDisplay.Eta;
                            mUserMessage.DisplayMessage = mUserMessage.SpokenMessage = mDisplay;
                            mResponseSuccess            = VoiceCommandResponse.CreateResponse(mUserMessage, mCabTiles);
                            await voiceServiceConnection.ReportSuccessAsync(mResponseSuccess);
                        }
                        else
                        {
                            var    userMessage             = new VoiceCommandUserMessage();
                            string BookingCabToDestination = "Cancelling cab request...";
                            await ShowProgressScreen(BookingCabToDestination);

                            string keepingTripToDestination = "Cancelled.";
                            userMessage.DisplayMessage = userMessage.SpokenMessage = keepingTripToDestination;
                            var response1 = VoiceCommandResponse.CreateResponse(userMessage);
                            await voiceServiceConnection.ReportSuccessAsync(response1);
                        }
                    }
                    else
                    {
                        mDisplay = "Sorry there are no cabs available right now";
                        mUserMessage.DisplayMessage = mUserMessage.SpokenMessage = mDisplay;
                        mResponseError = VoiceCommandResponse.CreateResponse(mUserMessage);
                        await voiceServiceConnection.ReportFailureAsync(mResponseError);
                    }
                }
            }
        }
        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;
            }
        }
        private async void Signup_Click(object sender, RoutedEventArgs e)
        {
            //Validation of entries in the fields
            if (!IsInternet())
            {
                await new MessageDialog("Seems you are not connected to the Internet").ShowAsync();
                return;
            }
            else
            {
                string nametext, mobiletext, emailtext, passtext, cnfpasstext;
                nametext    = UsernameBox.Text;
                mobiletext  = ContactNumberBox.Text;
                emailtext   = EmailidBox.Text;
                passtext    = PasswordBox.Password;
                cnfpasstext = ConfirmPasswordBox.Password;
                if (!checkEmpty(nametext, "Name"))
                {
                    await new MessageDialog("Name field cannot be empty").ShowAsync();
                    return;
                }
                else if (!checkEmpty(mobiletext, "Phone number"))
                {
                    await new MessageDialog("Phone field cannot be empty").ShowAsync();
                    return;
                }
                else if (!checkEmpty(emailtext, "Email"))
                {
                    await new MessageDialog("Email field cannot be empty").ShowAsync();
                    return;
                }
                else if (!checkEmpty(passtext, "Password"))
                {
                    await new MessageDialog("Password field cannot be empty").ShowAsync();
                    return;
                }
                else if (!checkEmpty(cnfpasstext, "Confirm Password"))
                {
                    await new MessageDialog("Confirm Password field cannot be empty").ShowAsync();
                    return;
                }
                else
                {
                    if (!isNameVaid(nametext))
                    {
                        await new MessageDialog("Please enter a valid Name").ShowAsync();
                        return;
                    }
                    else if (!isPassValid(passtext))
                    {
                        await new MessageDialog("Password must contain at least 6 characters").ShowAsync();
                        return;
                    }
                    else if (!isEmailValid(emailtext))
                    {
                        await new MessageDialog("Please enter a valid email").ShowAsync();
                        return;
                    }
                    else if (!isMobileValid(mobiletext))
                    {
                        await new MessageDialog("Please enter a valid 10 digit mobile number").ShowAsync();
                        return;
                    }
                    else if (!checkPassValidity(passtext, cnfpasstext))
                    {
                        await new MessageDialog("Passwords do not match").ShowAsync();
                        return;
                    }
                    else if (!areTermsAccepted())
                    {
                        await new MessageDialog("You have to accept our T&C").ShowAsync();
                        return;
                    }
                    else
                    {
                        progress.IsActive = true;
                        CabsAPI        api      = new CabsAPI();
                        SignupResponse response = await api.RegisterUser(UsernameBox.Text, EmailidBox.Text, ContactNumberBox.Text, PasswordBox.Password);

                        if (response.Code == ResponseCode.SUCCESS)
                        {
                            progress.IsActive = false;
                            var localSettings = Windows.Storage.ApplicationData.Current.LocalSettings;
                            localSettings.Values["LoggedIn"] = true;
                            localSettings.Values["Token"]    = response.Token;
                            localSettings.Values["Email"]    = EmailidBox.Text;
                            localSettings.Values["Mobile"]   = ContactNumberBox.Text;
                            localSettings.Values["Name"]     = UsernameBox.Text;
                            Frame.Navigate(typeof(Navigation.NavigationPage), speechRecognition);
                        }
                        else if (response.Code == ResponseCode.MYSQL_DUPLICATES)
                        {
                            progress.IsActive = false;
                            await new MessageDialog("Email or Contact Number already exists. Please try again").ShowAsync();
                        }
                    }
                }
            }
        }
        protected override async void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);
            if (!isOnline())
            {
                mErrorDialog.Show();
            }
            else
            {
                SetContentView(Resource.Layout.activity_confirm_details);
                Drawable upArrow = Resources.GetDrawable(Resource.Drawable.abc_ic_ab_back_mtrl_am_alpha);
                upArrow.SetColorFilter(Resources.GetColor(Resource.Color.white), PorterDuff.Mode.SrcAtop);
                eta                = Intent.GetStringExtra("eta");
                high               = Intent.GetStringExtra("high");
                low                = Intent.GetStringExtra("low");
                time               = Intent.GetStringExtra("time");
                sourcestring       = Intent.GetStringExtra("source");
                type               = Intent.GetStringExtra("type");
                deststring         = Intent.GetStringExtra("destination");
                provider           = Intent.GetStringExtra("provider");
                capacity           = Intent.GetStringExtra("capacity");
                distance           = Intent.GetStringExtra("distance");
                fare               = Intent.GetStringExtra("fare");
                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("Confirm Booking");
                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;
                mCardView           = FindViewById <CardView>(Resource.Id.mapsviewcard);
                mConfirmButton      = FindViewById <Button>(Resource.Id.btn_request);
                if (provider.Equals("ola", StringComparison.InvariantCultureIgnoreCase))
                {
                    mConfirmButton.SetBackgroundColor(Resources.GetColor(Resource.Color.greenola));
                    mConfirmButton.SetTextColor(Resources.GetColor(Resource.Color.black));
                }
                else
                {
                    mConfirmButton.SetBackgroundColor(Resources.GetColor(Resource.Color.black));
                }
                mSource    = FindViewById <TextView>(Resource.Id.sourcetext);
                mDest      = FindViewById <TextView>(Resource.Id.destinationtext);
                etaText    = FindViewById <TextView>(Resource.Id.etatext);
                etaValue   = FindViewById <TextView>(Resource.Id.etavalue);
                distText   = FindViewById <TextView>(Resource.Id.disttext);
                distValue  = FindViewById <TextView>(Resource.Id.distvalue);
                priceText  = FindViewById <TextView>(Resource.Id.pricetext);
                priceVlaue = FindViewById <TextView>(Resource.Id.pricevalue);
                timeText   = FindViewById <TextView>(Resource.Id.timetext);
                timeValue  = FindViewById <TextView>(Resource.Id.timevalue);
                mConfirmButton.SetTypeface(typeface, TypefaceStyle.Normal);
                mSource.SetTypeface(typeface, TypefaceStyle.Normal);
                mDest.SetTypeface(typeface, TypefaceStyle.Normal);
                etaText.SetTypeface(typeface, TypefaceStyle.Normal);
                etaValue.SetTypeface(typeface, TypefaceStyle.Normal);
                distText.SetTypeface(typeface, TypefaceStyle.Normal);
                distValue.SetTypeface(typeface, TypefaceStyle.Normal);
                priceText.SetTypeface(typeface, TypefaceStyle.Normal);
                priceVlaue.SetTypeface(typeface, TypefaceStyle.Normal);
                timeText.SetTypeface(typeface, TypefaceStyle.Normal);
                timeValue.SetTypeface(typeface, TypefaceStyle.Normal);
                mSource.Text        = sourcestring;
                mDest.Text          = deststring;
                etaValue.Text       = eta;
                distValue.Text      = distance;
                priceVlaue.Text     = low + "-" + high;
                timeValue.Text      = time;
                mConfirmButton.Text = "REQUEST " + type;
                sourcestring        = mSource.Text;
                deststring          = mDest.Text;
                CabsAPI api = new CabsAPI();
                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)
                {
                    mLoadingDialog.Dismiss();
                    slat = mResponse1.Position.Latitude.ToString();
                    slng = mResponse1.Position.Longitude.ToString();
                    dlat = mResponse2.Position.Latitude.ToString();
                    dlng = mResponse2.Position.Longitude.ToString();
                }
                sourcepos = new LatLng(Convert.ToDouble(slat), Convert.ToDouble(slng));
                destpos   = new LatLng(Convert.ToDouble(dlat), Convert.ToDouble(dlng));
                mConfirmButton.SetOnClickListener(this);
                setupGoogleMap();
            }
        }
        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;
                }
            }
        }
Exemple #23
0
        public async void init(View rootView)
        {
            if (!isOnline())
            {
                mErrorDialog.Show();
                return;
            }
            api            = new CabsAPI();
            mLoadingDialog = new LoadingDialog(mActivity, 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("Home");

            typeface = Typeface.CreateFromAsset(mActivity.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);
            mActivity.TitleFormatted = s;
            mSharedPreference        = mActivity.GetSharedPreferences(Constants.MY_PREF, 0);
            token = mSharedPreference.GetString("token", " ");
            if (mActivity.Intent.GetStringExtra("source") != null)
            {
                msourceRecieved = mActivity.Intent.GetStringExtra("source");
            }
            else
            {
                msourceRecieved = mSharedPreference.GetString("source", "1,ISB Rd,Gachibowli");
            }
            autoSourceBox                 = rootView.FindViewById <AppCompatAutoCompleteTextView>(Resource.Id.sourceauto);
            autoSourceBox.Text            = msourceRecieved;
            sourceSuggestionsAdapter      = new SearchSuggestionsAdapter(mActivity);
            autoSourceBox.Adapter         = sourceSuggestionsAdapter;
            destinationSuggestionsAdapter = new SearchSuggestionsAdapter(mActivity);
            autoSourceBox.ItemClick      += mSourceTextBoxClicked;
            autoDestinationBox            = rootView.FindViewById <AppCompatAutoCompleteTextView>(Resource.Id.destinationauto);
            autoDestinationBox.Adapter    = destinationSuggestionsAdapter;
            autoDestinationBox.ItemClick += mDestinationTextBoxClicked;
            mLoadingDialog.Show();
            mRecyclerView = rootView.FindViewById <RecyclerView>(Resource.Id.cabrecycler);
            LinearLayoutManager linearLayoutManager = new LinearLayoutManager(Application.Context);

            mRecyclerView.SetLayoutManager(linearLayoutManager);
            mRecyclerView.AddItemDecoration(new VerticalSpaceItemDecoration(VERTICAL_ITEM_SPACE));
            LayoutInflater inflater    = (LayoutInflater)Activity.GetSystemService(Context.LayoutInflaterService);
            View           Childlayout = inflater.Inflate(Resource.Layout.fragment_google_maps, null);

            if (msourceRecieved != null)
            {
                GeoResponse mResponseGetSourcelatlng = await api.GeoCodingResult(token, msourceRecieved);

                slat         = mResponseGetSourcelatlng.Position.Latitude;
                slng         = mResponseGetSourcelatlng.Position.Longitude;
                hasSourceSet = false;
                setSourceMarker(msourceRecieved);
            }
            CabsResponse response = await api.GetNearbyCabs(slat, slng, Constants.AUTH_TOKEN);

            if (response.Code == ResponseCode.SUCCESS)
            {
                mCabs               = response.Cabs;
                mAdapter            = new CabRecyclerAdapter(Application.Context, mCabs, mActivity);
                mAdapter.ItemClick += OnItemClick;
                mRecyclerView.SetAdapter(mAdapter);
                mLoadingDialog.Dismiss();
            }
        }
Exemple #24
0
        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 override async void OnCreate(Bundle savedInstanceState)
        {
            if (!isOnline())
            {
                mErrorDialog.Show();
            }
            else
            {
                for (int i = 0; i < 2; i++)
                {
                    mOptions[i] = new MarkerOptions();
                }
                base.OnCreate(savedInstanceState);
                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);
                etaval             = Intent.GetStringExtra("eta");
                high               = Intent.GetStringExtra("high");
                low                = Intent.GetStringExtra("low");
                time               = Intent.GetStringExtra("time");
                sourcestring       = Intent.GetStringExtra("source");
                type               = Intent.GetStringExtra("type");
                deststring         = Intent.GetStringExtra("destination");
                provider           = Intent.GetStringExtra("provider");
                capacity           = Intent.GetStringExtra("capacity");
                distance           = Intent.GetStringExtra("distance");
                fare               = Intent.GetStringExtra("fare");
                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();
                etatext.Text   = etaval;
                disttext.Text  = distance;
                pricetext.Text = low + "-" + high;
                if (provider.Equals("Uber", StringComparison.InvariantCultureIgnoreCase))
                {
                    mProvider.SetImageResource(Resource.Drawable.uber);
                }
                else
                {
                    mProvider.SetImageResource(Resource.Drawable.ola);
                }
                mcab = new CabsAPI();
                mLoadingDialog.Show();
                GeoResponse mResponse1 = await mcab.GeoCodingResult(token, sourcestring);

                GeoResponse mResponse2 = await mcab.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();
                    BookingDetailsResponse mResBooking = await mcab.BookCab(token, slat, slng);

                    if (mResBooking.Code == ResponseCode.SUCCESS)
                    {
                        mLoadingDialog.Dismiss();
                        if (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);
                            phonenumner = mResBooking.BookingData.DriverDetails.Phone_Number;
                        }
                        else
                        {
                            phonenumner = "8110020055";
                        }
                    }
                    else
                    {
                    }
                }
                sourcepos = new LatLng(Convert.ToDouble(slat), Convert.ToDouble(slng));
                destpos   = new LatLng(Convert.ToDouble(dlat), Convert.ToDouble(dlng));
                setupGoogleMap();
            }
        }
Exemple #26
0
        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);
            }
        }
Exemple #27
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);
                    }
                }
            }
        }
        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);
                    }
                }
            }
        }
Exemple #29
0
        private async void Signupbtn_Click(object sender, EventArgs e)
        {
            string             nametext, mobiletext, emailtext, passtext, cnfpasstext;
            InputMethodManager inputManager = (InputMethodManager)GetSystemService(InputMethodService);

            inputManager.HideSoftInputFromWindow(CurrentFocus.WindowToken, 0);
            nametext    = name.Text;
            mobiletext  = mobile.Text;
            emailtext   = email.Text;
            passtext    = password.Text;
            cnfpasstext = conpass.Text;
            if (!checkEmpty(nametext, "Name"))
            {
                return;
            }
            else if (!checkEmpty(mobiletext, "Phone number"))
            {
                return;
            }
            else if (!checkEmpty(emailtext, "Email"))
            {
                return;
            }
            else if (!checkEmpty(passtext, "Password"))
            {
                return;
            }
            else if (!checkEmpty(cnfpasstext, "Confirm Password"))
            {
                return;
            }
            else
            {
                if (isNameVaid(nametext) && isMobileValid(mobiletext) && isEmailValid(emailtext) && areTermsAccepted() && isPassValid(passtext) && checkPassValidity(passtext, cnfpasstext))
                {
                    mLoadingDialog.Show();
                    CabsAPI        api      = new CabsAPI();
                    SignupResponse response = await api.RegisterUser(nametext, emailtext, mobiletext, passtext);

                    if (response.Code == Utils.ResponseCode.SUCCESS)
                    {
                        mLoadingDialog.Dismiss();
                        mEditor.PutString("email", emailtext);
                        mEditor.PutString("mobile", mobiletext);
                        mEditor.PutString("name", nametext);
                        mEditor.PutString("token", response.Token);
                        mEditor.PutBoolean("isLoggedIn", true);
                        mEditor.Apply();
                        mTextToSpeech = new TextToSpeech(this, this, "com.google.android.tts");
                        //  new TextToSpeech(con, this, "com.google.android.tts");
                        lang = Java.Util.Locale.Default;
                        //setting language , pitch and speed rate to the voice
                        mTextToSpeech.SetLanguage(lang);
                        mTextToSpeech.SetPitch(1f);
                        mTextToSpeech.SetSpeechRate(1f);
                        mContext = signupbtn.Context;
                        mTextToSpeech.Speak(mSucLog, QueueMode.Flush, null, null);
                        StartActivity(new Intent(this, typeof(NavigationActivity)));

                        Finish();
                    }
                    else if (response.Code == Utils.ResponseCode.MYSQL_DUPLICATES)
                    {
                        mLoadingDialog.Dismiss();
                        Toast.MakeText(this, "User with same number is already present", ToastLength.Short).Show();
                        mobile.Text = "";
                    }
                    else
                    {
                        mLoadingDialog.Dismiss();
                        Toast.MakeText(this, "Server Error Try Again!", ToastLength.Short).Show();
                    }
                }
            }
        }
        private async void init(View view)
        {
            if (!isOnline())
            {
                mErrorDialog.Show();
            }
            else
            {
                mLoadingDialog = new LoadingDialog(navigationActivity, Resource.Drawable.main);
                mLoadingDialog.SetCancelable(false);
                Window window = mLoadingDialog.Window;
                mCabsApi = new CabsAPI();
                window.SetLayout(WindowManagerLayoutParams.MatchParent, WindowManagerLayoutParams.MatchParent);
                window.SetBackgroundDrawable(new ColorDrawable(Resources.GetColor(Resource.Color.trans)));
                phone              = view.FindViewById <TextView>(Resource.Id.phonetobeset);
                phonetext          = view.FindViewById <TextView>(Resource.Id.disp1);
                email              = view.FindViewById <TextView>(Resource.Id.emailtobeset);
                emailtext          = view.FindViewById <TextView>(Resource.Id.disp2);
                invite             = view.FindViewById <TextView>(Resource.Id.inv);
                contosomoney       = view.FindViewById <TextView>(Resource.Id.contosomoney);
                moneyamnt          = view.FindViewById <TextView>(Resource.Id.price);
                mbutton            = view.FindViewById <Button>(Resource.Id.logout);
                dispcontact        = view.FindViewById <TextView>(Resource.Id.dispcontact);
                mIdtext1           = view.FindViewById <TextView>(Resource.Id.idtext1);
                mIdtext2           = view.FindViewById <TextView>(Resource.Id.idtext2);
                mAddAccount        = view.FindViewById <Button>(Resource.Id.addAcount);
                mLinear1           = view.FindViewById <LinearLayout>(Resource.Id.linear1);
                mLinear2           = view.FindViewById <LinearLayout>(Resource.Id.linear2);
                mLinearempty       = view.FindViewById <LinearLayout>(Resource.Id.whenempty);
                mSharedPreferences = Activity.GetSharedPreferences(Constants.MY_PREF, 0);
                namerec            = mSharedPreferences.GetString("name", " ");
                mobilerec          = mSharedPreferences.GetString("mobile", " ");
                emailrec           = mSharedPreferences.GetString("email", " ");
                token              = mSharedPreferences.GetString("token", " ");
                email.Text         = emailrec;
                phone.Text         = mobilerec;
                namerec           += " ";
                if (!mSharedPreferences.GetBoolean("hasAccounts", false))
                {
                    mLinear1.Visibility     = ViewStates.Visible;
                    mLinear2.Visibility     = ViewStates.Visible;
                    mIdtext1.Text           = "Not Authorized";
                    mIdtext2.Text           = "Not Authorized";
                    mLinearempty.Visibility = ViewStates.Gone;
                }
                else
                {
                    mLinearempty.Visibility = ViewStates.Gone;
                    mLinear2.Visibility     = ViewStates.Visible;
                    mLinear1.Visibility     = ViewStates.Visible;
                    mLoadingDialog.Show();
                    mIdtext2.Text = "Not Authorized";
                    mIdtext1.Text = "Not Authorized";
                    UserResponse mRes = await mCabsApi.GetProfile(token);

                    System.Diagnostics.Debug.WriteLine("In profile resp code " + mRes.Code);
                    if (mRes.Code == ResponseCode.SUCCESS)
                    {
                        mLoadingDialog.Dismiss();
                        mIdtext1.Text = mRes.User.Accounts.Count > 0 ? "Connected" : "Not Authorized";
                    }
                }
                SpannableString s = new SpannableString(namerec.Substring(0, namerec.IndexOf(' ')));
                typeface = Typeface.CreateFromAsset(navigationActivity.Assets, "JosefinSans-SemiBold.ttf");
                s.SetSpan(new TypefaceSpan("Amaranth-Regular.ttf"), 0, s.Length(), SpanTypes.ExclusiveExclusive);
                s.SetSpan(new ForegroundColorSpan(navigationActivity.Resources.GetColor(Resource.Color.title)), 0, s.Length(), SpanTypes.ExclusiveExclusive);
                navigationActivity.TitleFormatted = s;
                phone.SetTypeface(typeface, TypefaceStyle.Normal);
                phonetext.SetTypeface(typeface, TypefaceStyle.Normal);
                email.SetTypeface(typeface, TypefaceStyle.Normal);
                emailtext.SetTypeface(typeface, TypefaceStyle.Normal);
                invite.SetTypeface(typeface, TypefaceStyle.Normal);
                mbutton.SetTypeface(typeface, TypefaceStyle.Normal);
                contosomoney.SetTypeface(typeface, TypefaceStyle.Normal);
                dispcontact.SetTypeface(typeface, TypefaceStyle.Normal);
                mAddAccount.SetTypeface(typeface, TypefaceStyle.Normal);
                mAddAccount.SetOnClickListener(this);
                invite.SetOnClickListener(this);
                mbutton.SetOnClickListener(this);
            }
        }