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; usingSystem.Windows.Media; publicpartialclassEventPage:PhoneApplicationPage { #regionMemeber privateboolisSourceSet=false; 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); if(this.Orientation.Equals(PageOrientation.Landscape)||this.Orientation.Equals(PageOrientation.LandscapeLeft)||this.Orientation.Equals(PageOrientation.LandscapeRight)) { ApplicationBar.Mode=Microsoft.Phone.Shell.ApplicationBarMode.Default; } this.DefHeader.ProgressVisibility=Visibility.Visible; if(this.isNewInstance) { if((EventIndexPage.GetEventFeed()==null)||(EventIndexPage.GetEventFeed().Model==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.DefHeader.ProgressVisibility=Visibility.Collapsed; } protectedoverridevoidOnNavigatedFrom(NavigationEventArgse) { base.OnNavigatedFrom(e); if(e.NavigationMode!=System.Windows.Navigation.NavigationMode.Back) { App.SaveToIsolatedStorage<RSSViewModel>(Constants.IsolatedStorage_EventRSSModel,EventIndexPage.GetEventFeed().Model); } if(this.synth!=null) { this.synth.CancelAll(); } } #endregion #regionprivate privatevoidOnPivotSelectionChange(objectsender,SelectionChangedEventArgse) { if(e.RemovedItems.Count>0) { RSSModellast=e.RemovedItems[0]asRSSModel; if(last!=null&&last.TextVisibility==false) { last.TextVisibility=true; } } } privatevoidEventLink_Click(objectsender,EventArgse) { RSSModelcur=this.EventPivot.SelectedItemasRSSModel; this.EventPivot.UpdateLayout(); if(cur!=null) { cur.TextVisibility=(cur.TextVisibility)?false:true; } } 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().Model.Channel[0].Item[this.EventPivot.SelectedIndex].Text; ssmlPrompt+="</speak>"; this.isInSpeech=true; try { awaitthis.synth.SpeakSsmlAsync(ssmlPrompt); } catch(Exception) { } this.isInSpeech=false; } } #endregion #endregion } }