public override void Initilaize()
        {
            ResourceContext context = ResourceContext.GetForCurrentView();

            context.Reset();
            base.Initilaize();
        }
Example #2
0
 private void UpdateTrigger()
 {
     try
     {
         var qualifiers = ResourceContext.GetForCurrentView().QualifierValues;
         if (qualifiers.ContainsKey("DeviceFamily") && qualifiers["DeviceFamily"] == "Mobile")
         {
             if (UIViewSettings.GetForCurrentView().UserInteractionMode == UserInteractionMode.Mouse ||
                 ProjectionManager.ProjectionDisplayAvailable)
             {
                 SetActive(this.IsInDesktopMode);
                 IsActive = this.IsInDesktopMode;
             }
             else
             {
                 SetActive(!this.IsInDesktopMode);
                 IsActive = !this.IsInDesktopMode;
             }
         }
         else if (qualifiers.ContainsKey("DeviceFamily") && qualifiers["DeviceFamily"] == "Desktop")
         {
             SetActive(this.IsInDesktopMode);
             IsActive = this.IsInDesktopMode;
         }
     }
     catch (Exception ex)
     {
         Debug.WriteLine("Trigger Update: {0}", ex.Message);
     }
 }
Example #3
0
        /// <summary>
        /// Updates Application Language, Geographic Region and Speech Language
        /// </summary>
        /// <param name="languageTag"></param>
        /// <param name="automatic">default: true, will fallback to nearest region enabled on image </param>
        /// <returns></returns>
        public string UpdateLanguageByTag(string languageTag)
        {
            var currentLang = ApplicationLanguages.PrimaryLanguageOverride;

            if (currentLang != languageTag && Language.IsWellFormed(languageTag))
            {
                SetLanguageEntites(languageTag);

                // Do this twice because in Release mode, once isn't enough
                // to change the current CultureInfo (changing the WaitOne delay
                // doesn't help).
                for (int i = 0; i < 2; i++)
                {
                    // Refresh the resources in new language
                    ResourceContext.GetForCurrentView().Reset();
                    ResourceContext.GetForViewIndependentUse().Reset();

                    // Where seems to be some delay between when this is reset and when
                    // we can start re-evaluating the resources.  Without a pause, sometimes
                    // the first resource remains the previous language.
                    new System.Threading.ManualResetEvent(false).WaitOne(100);
                }

                OnPropertyChanged("Item[]");
                return(languageTag);
            }

            return(currentLang);
        }
Example #4
0
        public static void SwitchLanguage(Languages language)
        {
            var currentCulture = "en-US";

            switch (language)
            {
            case Languages.English:
                currentCulture = "en-US";
                break;

            case Languages.Japanese:
                currentCulture = "ja-JP";
                break;

            case Languages.French:
                currentCulture = "fr-FR";
                break;
            }
            var culture = new CultureInfo(currentCulture);

            Windows.Globalization.ApplicationLanguages.PrimaryLanguageOverride = culture.Name;
            CultureInfo.DefaultThreadCurrentCulture   = culture;
            CultureInfo.DefaultThreadCurrentUICulture = culture;
            ResourceContext.GetForCurrentView().Reset();
        }
Example #5
0
        /// <summary>
        /// Upon entering the scenario, ensure that we have permissions to use the Microphone. This may entail popping up
        /// a dialog to the user on Desktop systems. Only enable functionality once we've gained that permission in order to
        /// prevent errors from occurring when using the SpeechRecognizer. If speech is not a primary input mechanism, developers
        /// should consider disabling appropriate parts of the UI if the user does not have a recording device, or does not allow
        /// audio input.
        /// </summary>
        /// <param name="e">Unused navigation parameters</param>
        protected async override void OnNavigatedTo(NavigationEventArgs e)
        {
            // Keep track of the UI thread dispatcher, as speech events will come in on a separate thread.
            dispatcher = CoreWindow.GetForCurrentThread().Dispatcher;

            // Prompt the user for permission to access the microphone. This request will only happen
            // once, it will not re-prompt if the user rejects the permission.
            bool permissionGained = await AudioCapturePermissions.RequestMicrophonePermission();

            if (permissionGained)
            {
                // Initialize resource map to retrieve localized speech strings.
                Language speechLanguage = SpeechRecognizer.SystemSpeechLanguage;
                string   langTag        = speechLanguage.LanguageTag;
                speechContext           = ResourceContext.GetForCurrentView();
                speechContext.Languages = new string[] { langTag };

                speechResourceMap = ResourceManager.Current.MainResourceMap.GetSubtree("LocalizationSpeechResources");

                PopulateLanguageDropdown();
                await InitializeRecognizer(SpeechRecognizer.SystemSpeechLanguage);

                TurnRecognizer1();
            }
            else
            {
                this.resultTextBlock.Visibility = Visibility.Visible;
                this.resultTextBlock.Text       = "Permission to access capture resources was not given by the user, reset the application setting in Settings->Privacy->Microphone.";
                cbLanguageSelection.IsEnabled   = false;
                //luis
            }
        }
Example #6
0
        public void Refresh(object param)
        {
            this.loggingService.WriteLine();

            try
            {
                var context = this.Frame.DataContext;
                ResourceContext.GetForCurrentView().Reset();

                this.Frame.Navigate(this.CurrentPageType, param, new SuppressNavigationTransitionInfo());
                this.Frame.DataContext = context;
            }
            catch (Exception)
            {
                if (this.Frame.CanGoBack)
                {
                    this.Frame.GoBack();
                }
                else if (this.Frame.CanGoForward)
                {
                    this.Frame.GoForward();
                }
                else
                {
                    (this.Frame.Content as Page)?.UpdateLayout();
                }
            }
        }
Example #7
0
        private async void Frame_Navigated(object sender, NavigationEventArgs e)
        {
            if (e != null)
            {
                var vm             = NavigationService.GetNameOfRegisteredPage(e.SourcePageType);
                var navigationItem = PrimaryItems?.FirstOrDefault(i => i.ViewModelName == vm);
                if (navigationItem == null)
                {
                    navigationItem = SecondaryItems?.FirstOrDefault(i => i.ViewModelName == vm);
                }

                if (navigationItem != null)
                {
                    ChangeSelected(_lastSelectedItem, navigationItem);
                    _lastSelectedItem = navigationItem;
                }

                //Sentence 초기화
                var init = Singleton <SentenceHelper> .Instance;

                //마이크로 폰 권한 체크
                bool permissionGained = await AudioCapturePermissions.RequestMicrophonePermission();

                if (permissionGained)
                {
                    var speechLanguage = SpeechRecognizer.SystemSpeechLanguage;
                    var langTag        = speechLanguage.LanguageTag;
                    var speechContext  = ResourceContext.GetForCurrentView();
                    speechContext.Languages = new[] { langTag };
                }
            }
        }
Example #8
0
        public async Task showMsg()
        {
            /*
             * I got some of the following code about the content dialog boxes from here
             * http://www.reflectionit.nl/blog/2015/windows-10-xaml-tips-messagedialog-and-contentdialog
             */

            //using localisation to retrieve strings that will be displayed in the end round/game message

            ResourceCandidate rc;

            rc = ResourceManager.Current.MainResourceMap.GetValue("Resources/ok",
                                                                  ResourceContext.GetForCurrentView());
            string ok      = rc.ValueAsString;
            var    message = new ContentDialog()
            {
                Title             = status + "\n" + App.usrName + ": " + pl.CurrScr + " AI: " + en.CurrScr,
                PrimaryButtonText = ok,
            };

            rc = ResourceManager.Current.MainResourceMap.GetValue("Resources/newGm",
                                                                  ResourceContext.GetForCurrentView());
            string newGame = rc.ValueAsString;

            //if the message asks for a new game, the user is given an extra option
            //they can select cancel, which will return them to the main menu
            if (status.Equals(newGame))
            {
                rc = ResourceManager.Current.MainResourceMap.GetValue("Resources/cancel",
                                                                      ResourceContext.GetForCurrentView());
                string cancel = rc.ValueAsString;
                //secondary button added to message dialog
                message.SecondaryButtonText = cancel;
                //store which button was pressed
                var result = await message.ShowAsync();

                //if user wants another game, reset and start a new game
                if (result == ContentDialogResult.Primary)
                {
                    resetScrCircles();
                    en.hardReset();
                    pl.hardReset();
                    newFrme();
                }
                //otherwise return user to main page
                else if (result == ContentDialogResult.Secondary)
                {
                    //navigate to home page
                    Frame.Navigate(typeof(MainPage));
                }
            }
            else
            {
                //show message normally if not end of game
                //await feedback and start a new round
                await message.ShowAsync();

                newFrme();
            }
        }
Example #9
0
        SpeechRecognizer InitializeRecognizer()
        {
            try
            {
                var language = SpeechRecognizer.SystemSpeechLanguage;

                _speechContext           = ResourceContext.GetForCurrentView();
                _speechContext.Languages = new string[] { language.LanguageTag };

                _speechRecognizer = new SpeechRecognizer(language);
                _speechRecognizer.StateChanged += OnSpeechRecognizerStateChanged;
            }
            catch (Exception ex)
            {
                if ((uint)ex.HResult == RecognizerNotFoundHResult)
                {
                    Debug.WriteLine("SpeechManager: The speech language pack for selected language isn't installed.");
                }
                else
                {
                    Debug.WriteLine(ex.ToString());
                }
            }

            return(_speechRecognizer);
        }
Example #10
0
        /// <summary>
        /// Gets the localized version of the string, associated with the specified key.
        /// </summary>
        public string GetString(string key)
        {
            string            localizedString;
            ResourceCandidate match;

            // 1. StringLoader is with highest priority
            if (this.stringLoader != null)
            {
                localizedString = this.stringLoader.GetString(key);
                if (!string.IsNullOrEmpty(localizedString))
                {
                    return(localizedString);
                }
            }

            // 2. Local resource map is second.
            if (this.userResourceMap != null)
            {
                match = this.userResourceMap.GetValue(key, ResourceContext.GetForCurrentView());
                if (match != null)
                {
                    localizedString = match.ValueAsString;
                    if (!string.IsNullOrEmpty(localizedString))
                    {
                        return(localizedString);
                    }
                }
            }

            // 3. Global ResourceMap is next
            if (globalResourceMap != null)
            {
                match = globalResourceMap.GetValue(key, ResourceContext.GetForCurrentView());
                if (match != null)
                {
                    localizedString = match.ValueAsString;
                    if (!string.IsNullOrEmpty(localizedString))
                    {
                        return(localizedString);
                    }
                }
            }

            // 4. The default ResourceMap is last
            if (this.defaultResourceMap != null)
            {
                match = this.defaultResourceMap.GetValue(key, ResourceContext.GetForCurrentView());
                if (match != null)
                {
                    localizedString = match.ValueAsString;
                    if (!string.IsNullOrEmpty(localizedString))
                    {
                        return(localizedString);
                    }
                }
            }

            Debug.Assert(false, string.Format("No entry found for key '{0}'.", key));
            return(string.Empty);
        }
Example #11
0
        protected async override void OnNavigatedTo(NavigationEventArgs e)
        {
            dispatcher = CoreWindow.GetForCurrentThread().Dispatcher;
            bool permissionGained = await AudioCapturePermissions.RequestMicrophonePermission();

            if (permissionGained)
            {
                // btnContinuousRecognize.IsEnabled = true;
                speechContext     = ResourceContext.GetForCurrentView();
                speechResourceMap = ResourceManager.Current.MainResourceMap.GetSubtree("LocalizationSpeechResources");
                play(question.Text);
            }
            else
            {
                this.resultTextBlock.Visibility  = Visibility.Visible;
                this.resultTextBlock.Text        = "Permission to access capture resources was not given by the user, reset the application setting in Settings->Privacy->Microphone.";
                btnContinuousRecognize.IsEnabled = false;
            }


            var parameters = (addProductMaterial.ProductParams)e.Parameter;

            textBlock2.Text = parameters.Path;
            textBlock.Text  = parameters.Name;
            textBlock1.Text = parameters.Category;
            textBlock3.Text = parameters.Material;
        }
Example #12
0
        private void ShowText()
        {
            ResourceContext defaultContextForCurrentView = ResourceContext.GetForCurrentView();
            ResourceMap     stringResourcesResourceMap   = ResourceManager.Current.MainResourceMap.GetSubtree("Resources");

            Scenario8MessageTextBlock.Text = stringResourcesResourceMap.GetValue("string1", defaultContextForCurrentView).ValueAsString;
        }
        public override async Task OnNavigatedToAsync(object parameter, NavigationMode mode, IDictionary <string, object> state)
        {
            if (Items.Count > 0 && SelectedItem != null)
            {
                return;
            }

            var response = await ProtoService.GetLanguagesAsync();

            if (response.IsSucceeded)
            {
                Items.ReplaceWith(response.Result.OrderBy(x => x.NativeName));

                var context = ResourceContext.GetForCurrentView();
                if (context.Languages.Count > 0)
                {
                    var key     = context.Languages[0];
                    var already = Items.FirstOrDefault(x => key.StartsWith(x.LangCode, StringComparison.OrdinalIgnoreCase));
                    if (already != null)
                    {
                        SelectedItem = already;
                    }
                }
            }
        }
        public static string ReadValue(string key)
        {
            ResourceContext defaultContextForCurrentView = ResourceContext.GetForCurrentView();
            ResourceMap     stringResourcesResourceMap   = ResourceManager.Current.MainResourceMap.GetSubtree("Resources");

            return(stringResourcesResourceMap.GetValue(key, defaultContextForCurrentView).ValueAsString);
        }
        public SwitchLanguageView()
        {
            this.InitializeComponent();
            _defaultContextForCurrentView = ResourceContext.GetForCurrentView();

            _defaultContextForCurrentView.QualifierValues.MapChanged += async(s, m) =>
            {
                await this.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
                {
                    var currentLanguage = ResourceManager.Current.MainResourceMap.GetValue("Resources/CurrentLanguage", _defaultContextForCurrentView).ValueAsString;
                    var message         = ResourceManager.Current.MainResourceMap.GetValue("OtherResources/Message", _defaultContextForCurrentView).ValueAsString;
                    MessageForSwitchLanguageElement.Text = message + currentLanguage;
                });
            };

            foreach (var languageTag in ApplicationLanguages.Languages)
            {
                AddItemForLanguageTag(languageTag);
            }

            LanguageListView.Items.Add(new ListViewItem {
                Content = "——————", Tag = "-"
            });

            foreach (var languageTag in ApplicationLanguages.ManifestLanguages)
            {
                AddItemForLanguageTag(languageTag);
            }

            LanguageListView.SelectionChanged += LanguageListView_SelectionChanged;
        }
 protected void Init(string resourceKey, HandlerProc handler, CoreDispatcher dispatcher, ResourceContext context = null)
 {
     ResourceKey = resourceKey;
     Handler     = handler ?? throw new ArgumentNullException(nameof(handler));
     Dispatcher  = dispatcher ?? throw new ArgumentNullException(nameof(dispatcher));
     Context     = context ?? ResourceContext.GetForCurrentView();
 }
        private async void ChangeExecute(LanguagePackInfo info)
        {
            IsLoading = true;

            var response = await _localeService.SetLanguageAsync(info, true);

            if (response is Ok)
            {
                //ApplicationLanguages.PrimaryLanguageOverride = info.Id;
                //ResourceContext.GetForCurrentView().Reset();
                //ResourceContext.GetForViewIndependentUse().Reset();

                //TLWindowContext.GetForCurrentView().NavigationServices.Remove(NavigationService);
                //BootStrapper.Current.NavigationService.Reset();

                foreach (var window in WindowContext.ActiveWrappers)
                {
                    window.Dispatcher.Dispatch(() =>
                    {
                        ResourceContext.GetForCurrentView().Reset();
                        ResourceContext.GetForViewIndependentUse().Reset();

                        if (window.Content is RootPage root)
                        {
                            window.Dispatcher.Dispatch(() =>
                            {
                                root.UpdateComponent();
                            });
                        }
                    });
                }
            }

            IsLoading = false;
        }
        /// <summary>
        /// Initializes a new instance of the AppShell, sets the static 'Current' reference,
        /// adds callbacks for Back requests and changes in the SplitView's DisplayMode, and
        /// provide the nav menu list with the data to display.
        /// </summary>
        public AppShell()
        {
            this.InitializeComponent();
            resourceContextForCurrentView = ResourceContext.GetForCurrentView();
            InitializeLeftBarMenu();

            this.Loaded += (sender, args) =>
            {
                Current = this;

                this.TogglePaneButton.Focus(FocusState.Programmatic);
            };

            this.RootSplitView.RegisterPropertyChangedCallback(
                SplitView.DisplayModeProperty,
                (s, a) =>
            {
                // Ensure that we update the reported size of the TogglePaneButton when the SplitView's
                // DisplayMode changes.
                this.CheckTogglePaneButtonSizeChanged();
            });

            SystemNavigationManager.GetForCurrentView().BackRequested += SystemNavigationManager_BackRequested;

            NavMenuList.ItemsSource = navlist;
            CheckThemeSettings();
        }
Example #19
0
        /// <summary>
        /// When activating the scenario, ensure we have permission from the user to access their microphone, and
        /// provide an appropriate path for the user to enable access to the microphone if they haven't
        /// given explicit permission for it.
        /// </summary>
        /// <param name="e">The navigation event details</param>
        protected async override void OnNavigatedTo(NavigationEventArgs e)
        {
            // Save the UI thread dispatcher to allow speech status messages to be shown on the UI.
            dispatcher = CoreWindow.GetForCurrentThread().Dispatcher;

            bool permissionGained = await AudioCapturePermissions.RequestMicrophonePermission();

            if (permissionGained)
            {
                // Enable the recognition buttons.
                btnRecognizeWithUI.IsEnabled    = true;
                btnRecognizeWithoutUI.IsEnabled = true;

                Language speechLanguage = SpeechRecognizer.SystemSpeechLanguage;
                string   langTag        = speechLanguage.LanguageTag;
                speechContext           = ResourceContext.GetForCurrentView();
                speechContext.Languages = new string[] { langTag };

                speechResourceMap = ResourceManager.Current.MainResourceMap.GetSubtree("LocalizationSpeechResources");

                PopulateLanguageDropdown();
                await InitializeRecognizer(SpeechRecognizer.SystemSpeechLanguage);
            }
            else
            {
                resultTextBlock.Visibility      = Visibility.Visible;
                resultTextBlock.Text            = "Permission to access capture resources was not given by the user; please set the application setting in Settings->Privacy->Microphone.";
                btnRecognizeWithUI.IsEnabled    = false;
                btnRecognizeWithoutUI.IsEnabled = false;
                cbLanguageSelection.IsEnabled   = false;
            }
        }
Example #20
0
        public static void ChangeLanguageResources(string targetLanguage, SettingsFlyout targtControl)
        {
            CultureInfo cul = new CultureInfo(targetLanguage);
            RegionInfo  reg = new RegionInfo(targetLanguage);

            if (cul == CultureInfo.InvariantCulture)
            {
                return;
            }

            var  qualifierValues = ResourceContext.GetForCurrentView().Clone().QualifierValues;
            Task t = new Task(() =>
            {
                string text = "";
                if (targtControl != null)
                {
                    text = GetResourceString(targtControl.Name + ".Title");
                    if (string.IsNullOrEmpty(text))
                    {
                        text = GetResourceString(targtControl.Name + "Title");
                    }
                    targtControl.Title = text;
                    setChildrenResource(targtControl);
                }
            });

            qualifierValues.MapChanged += (s, e) =>
            {
                t.RunSynchronously();
            };
            ApplicationLanguages.PrimaryLanguageOverride = targetLanguage;
        }
Example #21
0
        /// <inheritdoc />
        protected override async Task InvokeOtherUriSchemeAsync(ILoadingContext <TSource> context, LoadingPipeDelegate <TSource> next, Uri uri, CancellationToken cancellationToken = default)
        {
            var scheme = uri.Scheme;

            if (string.Equals(scheme, "ms-appx", StringComparison.OrdinalIgnoreCase) ||
                string.Equals(scheme, "ms-appdata", StringComparison.OrdinalIgnoreCase))
            {
                var file = await StorageFile.GetFileFromApplicationUriAsync(uri);

                context.Current = await file.OpenStreamForReadAsync();
                await next(context, cancellationToken);
            }
            else if (string.Equals(scheme, "ms-resource", StringComparison.OrdinalIgnoreCase))
            {
                var resourceManager = ResourceManager.Current;
                var resourceContext = ResourceContext.GetForCurrentView();
                var candidate       = resourceManager.MainResourceMap.GetValue(uri.LocalPath, resourceContext);
                if (candidate != null && candidate.IsMatch)
                {
                    var file = await candidate.GetValueAsFileAsync();

                    context.Current = file.OpenStreamForReadAsync();
                    await next(context, cancellationToken);
                }
            }
            else
            {
                throw new NotSupportedException();
            }
        }
Example #22
0
        public object Convert(object value, Type targetType, object parameter, string language)
        {
            try
            {
                string _deviceFamily;
                Double resta;

                var qualifiers = ResourceContext.GetForCurrentView().QualifierValues;
                _deviceFamily = qualifiers.First(q => q.Key.Equals("DeviceFamily")).Value;

                if (_deviceFamily.Equals("Mobile"))
                {
                    resta = System.Convert.ToDouble(parameter) - 80;
                }
                else
                {
                    resta = System.Convert.ToDouble(parameter);
                }

                double val = System.Convert.ToDouble(value) - resta;
                return(val);
            }
            catch
            {
                return("300");
            }
        }
Example #23
0
        /// <summary>
        /// This is the click handler for the 'Scenario9Button_Show' button.  You would replace this with your own handler
        /// if you have a button or buttons on this page.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Scenario9Button_Show_Click(object sender, RoutedEventArgs e)
        {
            Button b = sender as Button;

            if (b != null)
            {
                // A langauge override will be set on the default context for the current view.
                // When navigating between different scenarios in this sample, the content for each
                // scenario is loaded into a host page that remains constant. The view (meaning, the
                // CoreWindow) remains the same, and so it is the same default context that's in use.
                // Thus, an override set here can impact behavior in other scenarios.
                //
                // However, the description for the scenario may give the impression that a value
                // being set is local to this scenario. Also, when entering this scenario, the combo
                // box always gets set to the first item, which can add to the confusion. To avoid
                // confusion when using this sample, the override that gets set here will be cleared
                // when the user navigates away from this scenario (in the OnNavigatedFrom event
                // handler). In a real app, whether and when to clear an override will depend on
                // the desired behaviour and the design of the app.

                var context = ResourceContext.GetForCurrentView();

                var selectedLanguage = Scenario9ComboBox.SelectedValue;
                if (selectedLanguage != null)
                {
                    var lang = new List <string>();
                    lang.Add(selectedLanguage.ToString());
                    context.Languages = lang;
                    var resourceStringMap = ResourceManager.Current.MainResourceMap.GetSubtree("Resources");
                    this.Scenario9TextBlock.Text = resourceStringMap.GetValue("string1", context).ValueAsString;
                }
            }
        }
        /// <summary>
        /// Upon entering the scenario, ensure that we have permissions to use the Microphone. This may entail popping up
        /// a dialog to the user on Desktop systems. Only enable functionality once we've gained that permission in order to
        /// prevent errors from occurring when using the SpeechRecognizer. If speech is not a primary input mechanism, developers
        /// should consider disabling appropriate parts of the UI if the user does not have a recording device, or does not allow
        /// audio input.
        /// </summary>
        /// <param name="e">Unused navigation parameters</param>
        protected async override void OnNavigatedTo(NavigationEventArgs e)
        {
            rootPage = MainPage.Current;

            // Keep track of the UI thread dispatcher, as speech events will come in on a separate thread.
            dispatcher = CoreWindow.GetForCurrentThread().Dispatcher;

            // Prompt the user for permission to access the microphone. This request will only happen
            // once, it will not re-prompt if the user rejects the permission.
            bool permissionGained = await AudioCapturePermissions.RequestMicrophonePermission();

            if (permissionGained)
            {
                btnContinuousRecognize.IsEnabled = true;
            }
            else
            {
                resultTextBlock.Text = "Permission to access capture resources was not given by the user, reset the application setting in Settings->Privacy->Microphone.";
            }


            Language speechLanguage = SpeechRecognizer.SystemSpeechLanguage;
            string   langTag        = speechLanguage.LanguageTag;

            speechContext           = ResourceContext.GetForCurrentView();
            speechContext.Languages = new string[] { langTag };

            speechResourceMap = ResourceManager.Current.MainResourceMap.GetSubtree("LocalizationSpeechResources");

            PopulateLanguageDropdown();

            // Initialize the recognizer. Since the recognizer is disposed on scenario exit, we need to make sure we re-initialize it on scenario
            // entrance, as the xaml page may not get destroyed between openings of the scenario.
            await InitializeRecognizer(SpeechRecognizer.SystemSpeechLanguage);
        }
Example #25
0
        public InstanceTabsView()
        {
            this.InitializeComponent();
            ApplicationView.PreferredLaunchWindowingMode = ApplicationViewWindowingMode.Auto;
            var CoreTitleBar = CoreApplication.GetCurrentView().TitleBar;

            CoreTitleBar.ExtendViewIntoTitleBar = true;
            tabView = TabStrip;

            var flowDirectionSetting = ResourceContext.GetForCurrentView().QualifierValues["LayoutDirection"];

            if (flowDirectionSetting == "RTL")
            {
                FlowDirection = FlowDirection.RightToLeft;
            }

            App.AppSettings             = new SettingsViewModel();
            App.InteractionViewModel    = new InteractionViewModel();
            App.SidebarPinnedController = new SidebarPinnedController();

            // Turn on Navigation Cache
            this.NavigationCacheMode = NavigationCacheMode.Enabled;

            Window.Current.SizeChanged += Current_SizeChanged;
            Current_SizeChanged(null, null);

            Helpers.ThemeHelper.Initialize();
        }
        private void InitializeRecognizer()
        {
            try
            {
                // Initialize resource map to retrieve localized speech strings.
                Language speechLanguage = SpeechRecognizer.SystemSpeechLanguage;
                string   langTag        = speechLanguage.LanguageTag;
                _speechContext           = ResourceContext.GetForCurrentView();
                _speechContext.Languages = new string[] { langTag };

                // Create the speech recognizer instance.
                _speechRecognizer = new SpeechRecognizer(SpeechRecognizer.SystemSpeechLanguage);

                // Be aware of state changes in the speech recognizer instance.
                _speechRecognizer.StateChanged += SpeechRecognizer_StateChanged;
            }
            catch (Exception ex)
            {
                if ((uint)ex.HResult == RecognizerNotFoundHResult)
                {
                    Debug.WriteLine("SpeechManager: The speech language pack for selected language isn't installed.");
                }
                else
                {
                    Debug.WriteLine(ex.ToString());
                }
            }
        }
Example #27
0
        protected async override void OnNavigatedTo(NavigationEventArgs e)
        {
            dispatcher = CoreWindow.GetForCurrentThread().Dispatcher;
            try {
                await intializeCamera();
            }
            catch (Exception ex)
            {
                var messageDialog = new Windows.UI.Popups.MessageDialog(ex.Message, "Exception");
                await messageDialog.ShowAsync();
            }
            string welcome = "Welcome to the add product page. To capture a photo of your product, say capture";


            bool permissionGained = await AudioCapturePermissions.RequestMicrophonePermission();

            if (permissionGained)
            {
                btnContinuousRecognize.IsEnabled = true;
                speechContext     = ResourceContext.GetForCurrentView();
                speechResourceMap = ResourceManager.Current.MainResourceMap.GetSubtree("LocalizationSpeechResources");
                play(welcome);
            }
            else
            {
                this.resultTextBlock.Visibility  = Visibility.Visible;
                this.resultTextBlock.Text        = "Permission to access capture resources was not given by the user, reset the application setting in Settings->Privacy->Microphone.";
                btnContinuousRecognize.IsEnabled = false;
            }
        }
        private async void PlayTTS(string message)
        {
            speechContext           = ResourceContext.GetForCurrentView();
            speechContext.Languages = new string[] { SpeechSynthesizer.DefaultVoice.Language };
            synthesizer             = new SpeechSynthesizer();
            var voices = SpeechSynthesizer.AllVoices;

            VoiceInformation currentVoice = synthesizer.Voice;
            VoiceInformation voice        = null;

            foreach (VoiceInformation item in voices.OrderBy(p => p.Language))
            {
                string tag = item.Language;
                if (tag.Equals(ResourceHelper.GetSpeechLanguageTag()) && item.Gender == VoiceGender.Female)
                {
                    voice = item;
                    break;
                }
            }
            if (null != voice)
            {
                synthesizer.Voice = voice;
                SpeechSynthesisStream synthesisStream = await synthesizer.SynthesizeTextToStreamAsync(message);

                media.AutoPlay = true;
                media.SetSource(synthesisStream, synthesisStream.ContentType);
                media.Play();
            }
            else
            {
                timer.Start();
            }
        }
Example #29
0
        /// <summary>
        /// Override default assembly dependent localization for the control
        /// with another culture supported by the application and the library.
        /// </summary>
        private void OverrideLanguage()
        {
            var context           = ResourceContext.GetForCurrentView();
            var originalLanguages = context.Languages;

            context.Languages = new List <string> {
                GetLanguageOverride(this)
            };



            SetFeedbackBody(this, ResourceLoader.GetString("FeedbackBody"));
            SetFeedbackMessage1(this, string.Format(ResourceLoader.GetString("FeedbackMessage1"), GetApplicationName()));
            SetFeedbackNo(this, ResourceLoader.GetString("FeedbackNo"));
            SetFeedbackSubject(this, string.Format(ResourceLoader.GetString("FeedbackSubject"), GetApplicationName()));
            SetFeedbackTitle(this, ResourceLoader.GetString("FeedbackTitle"));
            SetFeedbackYes(this, ResourceLoader.GetString("FeedbackYes"));
            SetRatingMessage1(this, ResourceLoader.GetString("RatingMessage1"));
            SetRatingMessage2(this, ResourceLoader.GetString("RatingMessage2"));
            SetRatingNo(this, ResourceLoader.GetString("RatingNo"));
            SetRatingTitle(this, string.Format(ResourceLoader.GetString("RatingTitle"), GetApplicationName()));
            SetRatingYes(this, ResourceLoader.GetString("RatingYes"));

            context.Languages = originalLanguages;
        }
Example #30
0
        void SendTileNotificationScaledImage_Click(object sender, RoutedEventArgs e)
        {
            string scale;

            ResourceContext.GetForCurrentView().QualifierValues.TryGetValue("Scale", out scale);

            ITileSquare310x310Image square310x310TileContent = TileContentFactory.CreateTileSquare310x310Image();

            square310x310TileContent.Image.Src = "ms-appx:///images/purpleSquare310x310.png";
            square310x310TileContent.Image.Alt = "Purple square";

            ITileWide310x150SmallImageAndText03 wide310x150TileContent = TileContentFactory.CreateTileWide310x150SmallImageAndText03();

            wide310x150TileContent.TextBodyWrap.Text = "blueWide310x150.png in the xml is actually blueWide310x150.scale-" + scale + ".png";
            wide310x150TileContent.Image.Src         = "ms-appx:///images/blueWide310x150.png";
            wide310x150TileContent.Image.Alt         = "Blue wide";

            ITileSquare150x150Image square150x150TileContent = TileContentFactory.CreateTileSquare150x150Image();

            square150x150TileContent.Image.Src = "ms-appx:///images/graySquare150x150.png";
            square150x150TileContent.Image.Alt = "Gray square";

            wide310x150TileContent.Square150x150Content = square150x150TileContent;
            square310x310TileContent.Wide310x150Content = wide310x150TileContent;

            TileUpdateManager.CreateTileUpdaterForApplication().Update(square310x310TileContent.CreateNotification());

            OutputTextBlock.Text = MainPage.PrettyPrint(square310x310TileContent.GetContent());
        }