EventPage.xaml.cs CampusAppWP8::Pages::Events::EventPage CampusAppWP8::Pages::Events Windows::Phone::Speech::Synthesis //----------------------------------------------------------------------------- //<copyrightfile="EventPage.xaml.cs"company="BTU/IIT"> //Companycopyrighttag. //</copyright> //<author>fiedlchr</author> //<sience>03.05.2013</sience> //----------------------------------------------------------------------------- namespaceCampusAppWP8.Pages.Events { usingSystem; usingSystem.Collections.Generic; usingSystem.Linq; usingSystem.Windows; usingSystem.Windows.Controls; usingSystem.Windows.Navigation; usingCampusAppWP8.Resources; usingCampusAppWP8.Utility; usingMicrosoft.Phone.Controls; usingMicrosoft.Phone.Shell; usingWindows.Phone.Speech.Synthesis; usingCampusAppWPortalLib8.Model.RSS; publicpartialclassEventPage:PhoneApplicationPage { #regionMethod privateboolisSourceSet=false; privateintlastSelectedIndex=-1; privateboolisNewInstance=false; privateSpeechSynthesizersynth=null; privatevolatileboolisInSpeech=false; #endregion #regionConstructor publicEventPage() { this.InitializeComponent(); ApplicationBarIconButtonlinkBtn=newApplicationBarIconButton(); linkBtn.IconUri=newUri(Icons.Link,UriKind.Relative); linkBtn.Text=AppResources.NewsLinkBtn; linkBtn.Click+=newEventHandler(this.EventLink_Click); ApplicationBar.Buttons.Add(linkBtn); ApplicationBarIconButtonttsBtn=newApplicationBarIconButton(); ttsBtn.IconUri=newUri(Icons.TextToSpeech,UriKind.Relative); ttsBtn.Text=AppResources.TextToSpeech_Btn; ttsBtn.Click+=newEventHandler(this.EventTextToSpeech_Click); ApplicationBar.Buttons.Add(ttsBtn); this.isNewInstance=true; this.synth=newSpeechSynthesizer(); this.isInSpeech=false; } #endregion #regionMethod #regionprotected protectedoverridevoidOnNavigatedTo(NavigationEventArgse) { base.OnNavigatedTo(e); this.progressBar.Visibility=Visibility.Visible; if(this.isNewInstance) { if((EventIndexPage.GetEventFeed()==null)||(EventIndexPage.GetEventFeed().GetModel()==null)) { RSSViewModeltempModel=null; if((tempModel=App.LoadFromIsolatedStorage<RSSViewModel>(Constants.IsolatedStorage_EventRSSModel))!=null) { if(EventIndexPage.GetEventFeed()==null) { EventIndexPage.Feed=newFeed.Events.EventFeed(false); } EventIndexPage.Feed.Model=tempModel; this.isSourceSet=false; } } this.isNewInstance=false; } //SetpivotitemSource if(this.isSourceSet==false) { this.EventPivot.ItemsSource=EventIndexPage.GetEventFeed().Model.Channel[0].Item; this.isSourceSet=true; } stringpivotIndex=string.Empty; //Navigatetotheselectedpivotitem if(NavigationContext.QueryString.TryGetValue(Constants.ParamPivotIndex,outpivotIndex)) { intpivotIndexInt=int.Parse(pivotIndex); //iftheindexisintherangeofthearray if((pivotIndexInt>=0)&&(pivotIndexInt<EventIndexPage.GetEventFeed().Model.Channel[0].Item.Count())) { EventPivot.SelectedIndex=pivotIndexInt; } else { stringo=string.Empty; foreach(KeyValuePair<string,string>kvpinNavigationContext.QueryString) { o+=string.Format("Key={0},Value={1}",kvp.Key,kvp.Value)+"\n"; } MessageBox.Show("ERROR:pivotIndexoutofrange!!!("+o+")"); } } this.progressBar.Visibility=Visibility.Collapsed; } protectedoverridevoidOnNavigatedFrom(NavigationEventArgse) { base.OnNavigatedFrom(e); if(e.NavigationMode!=System.Windows.Navigation.NavigationMode.Back) { App.SaveToIsolatedStorage<RSSViewModel>(Constants.IsolatedStorage_EventRSSModel,EventIndexPage.GetEventFeed().GetModel()); } if(this.synth!=null) { this.synth.CancelAll(); } } #endregion #regionprivate privatevoidOnPivotSelectionChange(objectsender,SelectionChangedEventArgse) { intselIndex=(senderasPivot).SelectedIndex; if(this.lastSelectedIndex>-1) { Utilities.SetElementVisibility(this.EventPivot,"EventParentGrid","EventWebBrowser",Visibility.Collapsed,this.lastSelectedIndex); Utilities.SetElementVisibility(this.EventPivot,"EventParentGrid","EventTextGrid",Visibility.Visible,this.lastSelectedIndex); } this.lastSelectedIndex=selIndex; } privatevoidEventLink_Click(objectsender,EventArgse) { if(Visibility.Visible==Utilities.GetElementVisibility(this.EventPivot,"EventParentGrid","EventTextGrid",this.EventPivot.SelectedIndex)) { Utilities.SetElementVisibility(this.EventPivot,"EventParentGrid","EventTextGrid",Visibility.Collapsed,this.EventPivot.SelectedIndex); Utilities.SetElementVisibility(this.EventPivot,"EventParentGrid","EventWebBrowser",Visibility.Visible,this.EventPivot.SelectedIndex); } else { Utilities.SetElementVisibility(this.EventPivot,"EventParentGrid","EventWebBrowser",Visibility.Collapsed,this.EventPivot.SelectedIndex); Utilities.SetElementVisibility(this.EventPivot,"EventParentGrid","EventTextGrid",Visibility.Visible,this.EventPivot.SelectedIndex); } } privateasyncvoidEventTextToSpeech_Click(objectsender,EventArgse) { if(this.synth!=null&&this.isInSpeech==false) { stringssmlPrompt="<speakversion=\"1.0\""; ssmlPrompt+="xmlns=\"http://www.w3.org/2001/10/synthesis\"xml:lang=\"de-DE\">"; ssmlPrompt+=EventIndexPage.GetEventFeed().GetModel().Channel[0].Item[this.EventPivot.SelectedIndex].Text; ssmlPrompt+="</speak>"; this.isInSpeech=true; try { awaitthis.synth.SpeakSsmlAsync(ssmlPrompt); } catch(Exception) { } this.isInSpeech=false; } } #endregion #endregion } }